8
8
from threading import Thread
9
9
from modules import service_detection ,os_detection
10
10
from progress .bar import ChargingBar
11
+ from colorama import Fore
11
12
import rpycolors
12
13
13
14
old_print = print
14
15
print = rpycolors .Console ().print
15
16
17
+ white = Fore .WHITE
18
+ black = Fore .BLACK
19
+ red = Fore .RED
20
+ reset = Fore .RESET
21
+ blue = Fore .BLUE
22
+ cyan = Fore .CYAN
23
+ yellow = Fore .YELLOW
24
+ green = Fore .GREEN
25
+ magenta = Fore .MAGENTA
26
+
27
+ OPEN_PORT = 80
28
+
16
29
logging .getLogger ("scapy.runtime" ).setLevel (logging .ERROR )
17
30
31
+
18
32
clear = lambda :os .system ('cls' if os .name == 'nt' else 'clear' )
19
33
20
- __version__ = "v1.1.2 "
34
+ __version__ = "v1.1.3 "
21
35
22
- def print_figlet ():
36
+ def print_figlet (sleep = True ):
23
37
clear ()
24
38
print (textwrap .dedent (
25
39
f'''
@@ -38,10 +52,11 @@ def print_figlet():
38
52
'''
39
53
))
40
54
41
- try :
42
- time .sleep (4.5 )
43
- except KeyboardInterrupt :
44
- pass
55
+ if sleep :
56
+ try :
57
+ time .sleep (4.5 )
58
+ except KeyboardInterrupt :
59
+ pass
45
60
46
61
class Scanner :
47
62
def __init__ (self ,target = None ,my_ip = None ,protocol = None ,timeout = 5 ,interface = None ):
@@ -120,15 +135,15 @@ def handle_port_response(self,ports_saved,response,port):
120
135
open_or_filtered = ports_saved ['open/filtered' ]
121
136
122
137
if response [port ] == "Closed" :
123
- print (f"[[red]-[/red]] Port: { port } - Closed" )
138
+ logging . warning (f"Port: { port } - Closed" )
124
139
elif response [port ] == "Open" :
125
- print (f"[[green]+[/green]] Port: { port } - Open" )
140
+ logging . info (f"Port: { port } - Open" )
126
141
open_ports .append (port )
127
142
elif response [port ] == "Filtered" :
128
- print (f"[[cyan]*[/cyan]] Port: { port } - Filtered" )
143
+ logging . warning (f"Port: { port } - Filtered" )
129
144
filtered_ports .append (port )
130
145
elif response [port ] == "Open/Filtered" :
131
- print (f"[[green]+[/green]] Port: { port } - Open/Filtered" )
146
+ logging . info (f"Port: { port } - Open/Filtered" )
132
147
open_or_filtered .append (port )
133
148
else :
134
149
pass
@@ -139,8 +154,8 @@ def handle_port_response(self,ports_saved,response,port):
139
154
open_or_filtered
140
155
)
141
156
142
- def common_scan (self ,stealth = None ):
143
- print_figlet ()
157
+ def common_scan (self ,stealth = None , sv = None ):
158
+ # print_figlet()
144
159
145
160
if not self .protocol :
146
161
protocol = "TCP"
@@ -153,12 +168,12 @@ def common_scan(self,stealth=None):
153
168
open_or_filtered = []
154
169
155
170
if stealth :
156
- print ( "[[cyan]*[/cyan]] Starting - Stealth TCP Port Scan\n " )
171
+ logging . info ( " Starting - Stealth TCP Port Scan\n " )
157
172
else :
158
173
if protocol == "TCP" :
159
- print ( "[[cyan]*[/cyan]] Starting - TCP Connect Port Scan\n " )
174
+ logging . info ( " Starting - TCP Connect Port Scan\n " )
160
175
elif protocol == "UDP" :
161
- print ( "[[cyan]*[/cyan]] Starting - UDP Port Scan\n " )
176
+ logging . info ( " Starting - UDP Port Scan\n " )
162
177
else :
163
178
pass
164
179
@@ -178,16 +193,17 @@ def common_scan(self,stealth=None):
178
193
if open_ports or filtered_ports or open_or_filtered :
179
194
total = len (open_ports ) + len (filtered_ports ) + len (open_or_filtered )
180
195
181
- print (f"\n [[green]+[/green]]Founded { total } ports!" )
196
+ print ("" )
197
+ logging .info (f"Founded { total } ports!" )
182
198
183
199
for port in open_ports :
184
- print (f"[[green]+[/green]] Port: { port } - Open" )
200
+ logging . info (f"Port: { port } - Open" )
185
201
for port in filtered_ports :
186
- print (f"[[/cyan]*[/cyan]] Port: { port } - Filtered" )
202
+ logging . warning (f"Port: { port } - Filtered" )
187
203
for port in open_or_filtered :
188
- print (f"[[green]+[/green]] Port: { port } - Open/Filtered" )
204
+ logging . info (f"Port: { port } - Open/Filtered" )
189
205
190
- def range_scan (self ,start ,end = None ,stealth = None ):
206
+ def range_scan (self ,start ,end = None ,stealth = None , sv = None ):
191
207
open_ports = []
192
208
filtered_ports = []
193
209
open_or_filtered = []
@@ -196,13 +212,13 @@ def range_scan(self,start,end=None,stealth=None):
196
212
if not protocol :
197
213
protocol = "TCP"
198
214
199
- print_figlet ()
215
+ # print_figlet()
200
216
if protocol == "TCP" and stealth :
201
- print ( "[[cyan]*[/cyan]] Starting - TCP Stealth Port Scan\n " )
217
+ logging . info ( " Starting - TCP Stealth Port Scan\n " )
202
218
elif protocol == "TCP" and not stealth :
203
- print ( "[[cyan]*[/cyan]] Starting - TCP Connect Port Scan\n " )
219
+ logging . info ( " Starting - TCP Connect Port Scan\n " )
204
220
elif protocol == "UDP" :
205
- print ( "[[cyan]*[/cyan]] Starting - UDP Port Scan\n " )
221
+ logging . info ( " Starting - UDP Port Scan\n " )
206
222
else :
207
223
pass
208
224
@@ -222,15 +238,15 @@ def range_scan(self,start,end=None,stealth=None):
222
238
if open_ports or filtered_ports or open_or_filtered :
223
239
total = len (open_ports ) + len (filtered_ports ) + len (open_or_filtered )
224
240
225
- print_figlet ()
226
- print (f"[[green]+[/green]] Founded { total } ports!" )
241
+ # print_figlet()
242
+ logging . info (f"Founded { total } ports!" )
227
243
228
244
for port in open_ports :
229
- print (f"[[green]+[/green]] Port: { port } - Open" )
245
+ logging . info (f"Port: { port } - Open" )
230
246
for port in filtered_ports :
231
- print (f"[[cyan]*[/cyan]] Port: { port } - Filtered" )
247
+ logging . warning (f"Port: { port } - Filtered" )
232
248
for port in open_or_filtered :
233
- print (f"[[green]+[/green]] Port: { port } - Open/Filtered" )
249
+ logging . info (f"Port: { port } - Open/Filtered" )
234
250
else :
235
251
scan = self .port_scan (stealth )
236
252
@@ -246,25 +262,24 @@ def range_scan(self,start,end=None,stealth=None):
246
262
if open_ports or filtered_ports or open_or_filtered :
247
263
total = len (open_ports ) + len (filtered_ports ) + len (open_or_filtered )
248
264
249
- print_figlet ()
250
- print (f"[[green]+[/green]] Founded { total } ports!" )
265
+ # print_figlet()
266
+ logging . info (f"Founded { total } ports!" )
251
267
252
268
for port in open_ports :
253
- print (f"[[green]+[/green]] Port: { port } - Open" )
269
+ logging . info (f"Port: { port } - Open" )
254
270
for port in filtered_ports :
255
- print (f"[[cyan]*[/cyan]] Port: { port } - Filtered" )
271
+ logging . debug (f"Port: { port } - Filtered" )
256
272
for port in open_or_filtered :
257
- print (f"[[green]+[/green]] Port: { port } - Open/Filtered" )
273
+ logging . info (f"Port: { port } - Open/Filtered" )
258
274
259
275
def os_scan (self ):
260
- print_figlet ()
261
-
262
276
target_os = os_detection .scan (self .target )
263
277
264
278
if target_os :
265
- print (f"[[green]+[/green]]Target OS: { target_os } " )
279
+ print ("" )
280
+ logging .info (f"Target OS: { target_os } " )
266
281
else :
267
- print ("[[red]-[/red]]Error when scanning OS" )
282
+ logging . warning ("[[red]-[/red]]Error when scanning OS" )
268
283
269
284
def send_icmp (self ,target , result , index ):
270
285
# print(f"[+]Sending ICMP request to {target}")
@@ -280,16 +295,16 @@ def discover_net(self,ip_range=24):
280
295
protocol = self .protocol
281
296
base_ip = self .my_ip
282
297
283
- print_figlet ()
298
+ # print_figlet()
284
299
285
300
if not protocol :
286
301
protocol = "ICMP"
287
302
else :
288
303
if protocol != "ICMP" :
289
- print (f"[[red]![/red]] Warning: { protocol } is not supported by discover_net function! Changed to ICMP" )
304
+ logging . warning (f"Warning: { protocol } is not supported by discover_net function! Changed to ICMP" )
290
305
291
306
if protocol == "ICMP" :
292
- print ( "[[red]+[/red]] Starting - Discover Hosts Scan" )
307
+ logging . info ( " Starting - Discover Hosts Scan" )
293
308
294
309
base_ip = base_ip .split ('.' )
295
310
base_ip = f"{ str (base_ip [0 ])} .{ str (base_ip [1 ])} .{ str (base_ip [2 ])} .0/{ str (ip_range )} "
@@ -317,15 +332,16 @@ def discover_net(self,ip_range=24):
317
332
hosts_found = [i for i in results if i is not None ]
318
333
319
334
if not hosts_found :
320
- print ('[[red]-[/red]]Not found any host' )
335
+ logging . warn ('[[red]-[/red]]Not found any host' )
321
336
else :
322
- print (f'\n [[green]+[/green]]{ len (hosts_found )} hosts founded' )
337
+ print ("" )
338
+ logging .info (f'{ len (hosts_found )} hosts founded' )
323
339
for host in hosts_found :
324
- print (f'[[green]+[/green]] Host found: { host } ' )
340
+ logging . info (f'Host found: { host } ' )
325
341
326
342
return True
327
343
else :
328
- print ("[[red]-[/red]]Invalid protocol for this scan" )
344
+ logging . critical ("[[red]-[/red]]Invalid protocol for this scan" )
329
345
330
346
return False
331
347
@@ -335,21 +351,39 @@ def arguments():
335
351
parser .add_argument ('-sC' ,"--scan-common" ,help = "Scan common ports" ,action = "count" )
336
352
parser .add_argument ('-sA' ,"--scan-all" ,help = "Scan all ports" ,action = "count" )
337
353
parser .add_argument ('-sO' ,"--scan-os" ,help = "Scan OS" ,action = "count" )
338
- parser .add_argument ('-sP' ,"--scan-port" ,help = "Scan defined port" ,nargs = '+' ,type = int )
354
+ parser .add_argument ('-sP' ,"--scan-port" ,help = "Scan defined port" )
355
+ parser .add_argument ('-sV' ,"--scan-service" ,help = "Try to detect service running" )
339
356
parser .add_argument ('-d' ,"--discover" ,help = "Discover hosts in the network" ,action = "count" )
340
357
parser .add_argument ('-p' ,"--protocol" ,help = "Protocol to use in the scans. ICMP,UDP,TCP." ,type = str ,choices = ['ICMP' ,'UDP' ,'TCP' ],default = None )
341
358
parser .add_argument ('-i' ,"--interface" ,help = "Interface to use" ,default = None )
342
359
parser .add_argument ('-t' ,"--timeout" ,help = "Timeout to each request" ,default = 5 ,type = int )
343
360
parser .add_argument ('-st' ,"--stealth" ,help = "Use Stealth scan method (TCP)" ,action = "count" )
361
+ parser .add_argument ('-v' ,"--verbose" ,action = "count" )
344
362
parser .add_argument ('Target' ,nargs = '?' ,default = None )
345
363
346
364
args = parser .parse_args ()
347
365
366
+ if not args .discover and not args .Target :
367
+ sys .exit (parser .print_help ())
368
+
369
+ if not args .scan_common and not args .scan_all and not args .scan_os and not args .scan_port and not args .discover :
370
+ sys .exit (parser .print_help ())
371
+
348
372
return (args , parser )
349
373
350
374
if __name__ == '__main__' :
351
375
args , parser = arguments ()
352
376
377
+ del logging .root .handlers [:]
378
+
379
+ logging .addLevelName (logging .CRITICAL , f"[{ red } !!{ reset } ]" )
380
+ logging .addLevelName (logging .WARNING , f"[{ red } !{ reset } ]" )
381
+ logging .addLevelName (logging .INFO , f"[{ cyan } *{ reset } ]" )
382
+ logging .addLevelName (logging .DEBUG , f"[{ cyan } **{ reset } ]" )
383
+ logging .basicConfig (format = "%(levelname)s%(message)s" , level = logging .DEBUG if args .verbose else logging .INFO )
384
+
385
+ print_figlet ()
386
+
353
387
s = socket .socket (socket .AF_INET , socket .SOCK_DGRAM )
354
388
s .connect (("8.8.8.8" ,80 ))
355
389
ip = s .getsockname ()[0 ]
@@ -358,35 +392,22 @@ def arguments():
358
392
scanner = Scanner (target = args .Target ,my_ip = ip ,protocol = args .protocol ,timeout = args .timeout ,interface = args .interface )
359
393
360
394
if args .scan_common :
361
- if not args .Target :
362
- sys .exit (parser .print_help ())
363
-
364
- scanner .common_scan (stealth = args .stealth )
395
+ scanner .common_scan (stealth = args .stealth ,sv = args .scan_service )
365
396
366
397
elif args .scan_all :
367
- if not args .Target :
368
- sys .exit (parser .print_help ())
369
-
370
- scanner .range_scan (start = 0 ,end = 65535 ,stealth = args .stealth )
371
-
372
- elif args .scan_os :
373
- if not args .Target :
374
- sys .exit (parser .print_help ())
375
-
376
- scanner .os_scan ()
398
+ scanner .range_scan (start = 0 ,end = 65535 ,stealth = args .stealth ,sv = args .scan_service )
377
399
378
400
elif args .scan_port :
379
- if not args .Target :
380
- sys .exit (parser .print_help ())
381
-
382
401
try :
383
- scanner .range_scan (start = args .scan_port [0 ],end = args .scan_port [1 ],stealth = args .stealth )
402
+ scanner .range_scan (start = int ( args .scan_port . split ( ',' ) [0 ]) ,end = int ( args .scan_port . split ( ',' ) [1 ]) ,stealth = args .stealth , sv = args . scan_service )
384
403
except :
385
- scanner .range_scan (start = args .scan_port ,stealth = args .stealth )
404
+ scanner .range_scan (start = args .scan_port ,stealth = args .stealth , sv = args . scan_service )
386
405
387
406
elif args .discover :
388
407
scanner .discover_net ()
389
408
390
409
else :
391
410
parser .print_help ()
392
411
412
+ if args .scan_os :
413
+ scanner .os_scan ()
0 commit comments