Repository navigation
Expand file tree
/
Copy pathEternalBlueScanner.py
More file actions
328 lines (326 loc) · 14.5 KB
/
Copy pathEternalBlueScanner.py
File metadata and controls
328 lines (326 loc) · 14.5 KB
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import time
import random
import os
import socket
import sys
import requests
import multiprocessing as mp
from termcolor import colored
from colorama import init, Fore, Style
import nmap
init(autoreset=True)
# ========================= GLOBAL =========================
logo = '''
'########'########'########'########:'##::: ##:::'###:::'##::::::'########:'##::::::'##::::'##'########:
##.....:... ##..::##.....::##.... ##:###:: ##::'## ##:::##:::::::##.... ##:##:::::::##:::: ##:##.....::
##::::::::: ##::::##:::::::##:::: ##:####: ##:'##:. ##::##:::::::##:::: ##:##:::::::##:::: ##:##:::::::
######::::: ##::::######:::########::## ## ##'##:::. ##:##:::::::########::##:::::::##:::: ##:######:::
##...:::::: ##::::##...::::##.. ##:::##. ####:#########:##:::::::##.... ##:##:::::::##:::: ##:##...::::
##::::::::: ##::::##:::::::##::. ##::##:. ###:##.... ##:##:::::::##:::: ##:##:::::::##:::: ##:##:::::::
########::: ##::::########:##:::. ##:##::. ##:##:::: ##:########:########::########. #######::########:
:::::::::::::::::::'######::'######::::'###:::'##::::##'##:::.##'########'########::::::::::::::::::::::
::::::::::::::::::'##... ##'##... ##::'## ##:::###:: ##:###:: ##:##.....::##.... ##:::::::::::::::::::::
:::::::::::::::::::##:::..::##:::..::'##:. ##::####: ##:####: ##:##:::::::##:::: ##:::::::::::::::::::::
::::::::::::::::::. ######::##::::::'##:::. ##:## ## ##:## ## ##:######:::########::::::::::::::::::::::
:::::::::::::::::::..... ##:##:::::::#########:##. ####:##. ####:##...::::##.. ##:::::::::::::::::::::::
::::::::::::::::::'##::: ##:##::: ##:##.... ##:##:. ###:##:. ###:##:::::::##::. ##::::::::::::::::::::::
::::::::::::::::::. ######:. ######::##:::: ##:##::. ##:##::. ##:########:##:::. ##:::::::::::::::::::::
:::::::::::::::::::......:::......::..:::::..:..::::..:..::::..:........:..:::::..::::::::::::::::::::::
Coded By SourceCode347
'''
EternalBlue_Vulnerabilities = "EternalBlue_Vulnerabilities.txt"
def filecreator(file_name):
if not os.path.exists(file_name):
with open(file_name, "w", encoding="utf-8") as f:
f.write("")
filecreator(EternalBlue_Vulnerabilities)
r_args=['-d','--disable','-p','--processes','-h','--help']
printChecking=True
processes=mp.cpu_count()
for arg in range(0,len(sys.argv)):
if sys.argv[arg-1]=="-d" or sys.argv[arg-1]=="--disable":
printChecking=False
if sys.argv[arg-1]=="-p" or sys.argv[arg-1]=="--processes":
processes=int(sys.argv[arg])
if sys.argv[arg-1]=="-h" or sys.argv[arg-1]=="--help":
print(colored(logo, "green"))
help = '''
+------------------+------------------------------------------+-------------+
| Argument | Info | Default |
+------------------+------------------------------------------+-------------+
| -h , --help | Printing Help Of Arguments | NULL |
+------------------+------------------------------------------+-------------+
| -d , --disable | Disable Printing Of Checking A Random IP | True |
+------------------+------------------------------------------+-------------+
| -p , --processes | Integer Of Processes (eg. -p 64) | CPU Threads |
+------------------+------------------------------------------+-------------+
+------------------+--------------------------------------------------------+
| Example Command | python EternalBlueScanner.py -d -p 64 |
+---------------------------------------------------------------------------+
'''
print(Fore.GREEN +f"{help}")
sys.exit()
# ====================== FUNCTIONS ======================
def get_random_ip():
while True:
start=random.randint(0,255)
if start!=127:
return f"{start}.{random.randint(0,255)}.{random.randint(0,255)}.{random.randint(0,255)}"
def check_eternalblue(ip: str) -> dict:
result = {
"ip": ip,
"port_open": False,
"vulnerable": False,
"status": "Unknown",
"details": ""
}
try:
socket.inet_aton(ip)
nm = nmap.PortScanner()
print(Fore.CYAN + f"[*] Scanning {ip} for EternalBlue (MS17-010)...")
nm.scan(ip, '445', arguments='-Pn --script smb-vuln-ms17-010 -T4')
if ip not in nm.all_hosts():
result["status"] = "Host not reachable"
return result
host = nm[ip]
if '445' in host['tcp'] and host['tcp'][445]['state'] == 'open':
result["port_open"] = True
else:
result["status"] = "Port 445 closed or filtered"
return result
if 'script' in host and 'smb-vuln-ms17-010' in host['script']:
script_output = host['script']['smb-vuln-ms17-010']
result["details"] = script_output
if "VULNERABLE" in script_output or "State: VULNERABLE" in script_output:
result["vulnerable"] = True
result["status"] = "VULNERABLE to EternalBlue (MS17-010)"
elif "NOT VULNERABLE" in script_output or "State: NOT VULNERABLE" in script_output:
result["vulnerable"] = False
result["status"] = "NOT vulnerable"
else:
result["status"] = "Unknown (check details)"
else:
result["status"] = "Script did not return results"
return result
except nmap.PortScannerError as e:
result["status"] = f"Nmap error: {e}"
return result
except Exception as e:
result["status"] = f"Error: {e}"
return result
def check_sambacry(ip: str) -> dict:
result = {
"ip": ip,
"port_open": False,
"vulnerable": False,
"status": "Unknown",
"details": ""
}
try:
socket.inet_aton(ip)
nm = nmap.PortScanner()
print(Fore.CYAN + f"[*] Scanning {ip} for SambaCry (CVE-2017-7494)...")
nm.scan(ip, '445', arguments='-Pn --script smb-vuln-cve-2017-7494 -T4')
if ip not in nm.all_hosts():
result["status"] = "Host not reachable"
return result
host = nm[ip]
if '445' in host['tcp'] and host['tcp'][445]['state'] == 'open':
result["port_open"] = True
else:
result["status"] = "Port 445 closed or filtered"
return result
if 'script' in host and 'smb-vuln-cve-2017-7494' in host['script']:
script_output = host['script']['smb-vuln-cve-2017-7494']
result["details"] = script_output
if "VULNERABLE" in script_output or "State: VULNERABLE" in script_output:
result["vulnerable"] = True
result["status"] = "VULNERABLE to SambaCry (CVE-2017-7494)"
elif "NOT VULNERABLE" in script_output or "State: NOT VULNERABLE" in script_output:
result["vulnerable"] = False
result["status"] = "NOT vulnerable"
else:
result["status"] = "Unknown (check details)"
else:
result["status"] = "Script did not return results"
return result
except nmap.PortScannerError as e:
result["status"] = f"Nmap error: {e}"
return result
except Exception as e:
result["status"] = f"Error: {e}"
return result
def check_doublepulsar(ip: str) -> dict:
result = {
"ip": ip,
"port_open": False,
"vulnerable": False,
"status": "Unknown",
"details": ""
}
try:
socket.inet_aton(ip)
nm = nmap.PortScanner()
print(Fore.CYAN + f"[*] Scanning {ip} for DoublePulsar...")
nm.scan(ip, '445', arguments='-Pn --script smb-double-pulsar-backdoor -T4')
if ip not in nm.all_hosts():
result["status"] = "Host not reachable"
return result
host = nm[ip]
if '445' in host['tcp'] and host['tcp'][445]['state'] == 'open':
result["port_open"] = True
else:
result["status"] = "Port 445 closed or filtered"
return result
if 'script' in host and 'smb-double-pulsar-backdoor' in host['script']:
script_output = host['script']['smb-double-pulsar-backdoor']
result["details"] = script_output
if "VULNERABLE" in script_output or "State: VULNERABLE" in script_output:
result["vulnerable"] = True
result["status"] = "VULNERABLE to DoublePulsar"
elif "NOT VULNERABLE" in script_output or "State: NOT VULNERABLE" in script_output:
result["vulnerable"] = False
result["status"] = "NOT vulnerable"
else:
result["status"] = "Unknown (check details)"
else:
result["status"] = "Script did not return results"
return result
except nmap.PortScannerError as e:
result["status"] = f"Nmap error: {e}"
return result
except Exception as e:
result["status"] = f"Error: {e}"
return result
def check_webexec(ip: str) -> dict:
result = {
"ip": ip,
"port_open": False,
"vulnerable": False,
"status": "Unknown",
"details": ""
}
try:
socket.inet_aton(ip)
nm = nmap.PortScanner()
print(Fore.CYAN + f"[*] Scanning {ip} for WebExec...")
nm.scan(ip, '445', arguments='-Pn --script smb-vuln-webexec -T4')
if ip not in nm.all_hosts():
result["status"] = "Host not reachable"
return result
host = nm[ip]
if '445' in host['tcp'] and host['tcp'][445]['state'] == 'open':
result["port_open"] = True
else:
result["status"] = "Port 445 closed or filtered"
return result
if 'script' in host and 'smb-vuln-webexec' in host['script']:
script_output = host['script']['smb-vuln-webexec']
result["details"] = script_output
if "VULNERABLE" in script_output or "State: VULNERABLE" in script_output:
result["vulnerable"] = True
result["status"] = "VULNERABLE to WebExec"
elif "NOT VULNERABLE" in script_output or "State: NOT VULNERABLE" in script_output:
result["vulnerable"] = False
result["status"] = "NOT vulnerable"
else:
result["status"] = "Unknown (check details)"
else:
result["status"] = "Script did not return results"
return result
except nmap.PortScannerError as e:
result["status"] = f"Nmap error: {e}"
return result
except Exception as e:
result["status"] = f"Error: {e}"
return result
class PortSpider:
def __init__(self, start_url, max_depth=1, delay=0.3):
self.start_url = start_url
self.max_depth = max_depth
self.delay = delay
self.session = requests.Session()
self.session.headers.update({
"User-Agent": "Mozilla/5.0 (compatible; PortResearchBot/2.0;)"
})
def crawl(self, ip):
try:
if printChecking==True:
print(Fore.CYAN + f"[+] Checking: {ip}")
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(5)
result = sock.connect_ex((ip, 445))
if result == 0:
print(Fore.YELLOW + f"[+] Port 445 OPEN on {ip}")
res = check_eternalblue(ip)
if res["vulnerable"]==True:
print(Fore.GREEN + f"✅ Target IP : {ip} is Vulnerable to EternalBlue Exploit (!)")
self.saveurl(ip+" : EternalBlue")
else:
print(Fore.RED + f"[-] Target IP : {ip} is Not Vulnerable to EternalBlue Exploit (!)")
res = check_sambacry(ip)
if res["vulnerable"]==True:
print(Fore.GREEN + f"✅ Target IP : {ip} is Vulnerable to SambaCry Exploit (!)")
self.saveurl(ip+" : SambaCry")
else:
print(Fore.RED + f"[-] Target IP : {ip} is Not Vulnerable to SambaCry Exploit (!)")
res = check_doublepulsar(ip)
if res["vulnerable"]==True:
print(Fore.GREEN + f"✅ Target IP : {ip} is Vulnerable to DoublePulsar Exploit (!)")
self.saveurl(ip+" : DoublePulsar")
else:
print(Fore.RED + f"[-] Target IP : {ip} is Not Vulnerable to DoublePulsar Exploit (!)")
res = check_webexec(ip)
if res["vulnerable"]==True:
print(Fore.GREEN + f"✅ Target IP : {ip} is Vulnerable to WebExec Exploit (!)")
self.saveurl(ip+" : WebExec")
else:
print(Fore.RED + f"[-] Target IP : {ip} is Not Vulnerable to WebExec Exploit (!)")
sock.close()
except Exception as e:
pass
finally:
time.sleep(self.delay)
def saveurl(self, ip):
try:
with open(EternalBlue_Vulnerabilities, "r", encoding="utf-8") as f:
if ip in f.read():
return
with open(EternalBlue_Vulnerabilities, "a", encoding="utf-8") as f:
f.write(ip + "\n")
except:
pass
# ====================== WORKER ======================
def worker(worker_id):
#print(Fore.GREEN + f"[Process {worker_id}] Started")
spider = PortSpider(None, max_depth=1, delay=0.3)
while True:
target = get_random_ip()
spider.crawl(target)
# ====================== MAIN ======================
if __name__ == "__main__":
print(colored(logo, "green"))
time.sleep(5)
num_processes = processes
print(Fore.GREEN + f"🚀 Starting {num_processes} Processes")
print(Fore.YELLOW + "[+] Press Ctrl+C to stop...\n")
time.sleep(2)
processes = []
for i in range(num_processes):
p = mp.Process(
target=worker,
args=(i+1,),
name=f"PortSpider-{i+1}",
daemon=True
)
p.start()
processes.append(p)
time.sleep(0.1)
print(Fore.GREEN + f"✅ All {num_processes} processes are running!")
try:
while True:
time.sleep(10)
except KeyboardInterrupt:
print(Fore.RED + "\n\nStopping all processes...")