-
Notifications
You must be signed in to change notification settings - Fork 1
/
n3tool
executable file
·649 lines (587 loc) · 18.9 KB
/
n3tool
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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
#!/bin/python3
# network Enumerating tool
from threading import Thread
from sys import argv
from wordlist import *
import time
import os
import threading
import signal
try:
import requests
except:
print(f"[!] requests not installed.\n Run 'pip3 install requests', After installing 'python3-pip' package manager(apt install python3-pip)")
# Names
NAME = "n3tool"
URL = ''
ErrNo = 0
Help = ''
Out_file = f"{time.strftime('%b%d_%H%M%S')}"
time_ev = 0.05
Subdomain_enum = False
Uri_enm = False
Spidering = False
Spidering_all = False
Pinging = False
Method_deduct = False
Out_put = False
No_color = False
Quiet = False
# Colors
R="\u001b[31m"
Y="\u001b[33m"
G="\u001b[32m"
N="\u001b[0m"
P="\u001b[35m"
B="\u001b[34m"
W="\u001b[1m"
S="\u001b[36m"
U="\u001b[4m"
# Help statement
HELP=f"""{W}{U}N3tool{N} (Network Enumetaing Toolkid)
{W}{U}Usage{N}: {NAME} [arg] <target>
{W}{U}Arguments{N}:
-d --dirs Files and directory enumeration [Broutforcing]
{S}{NAME} --dirs https://demo.com/ -w wl.txt{N}
-e --sub-domain Subdomain enumeration [Broutforcing]
{S}{NAME} --sub-domain target.com -w wl.txt{N}
-m --method Scan for alowed methods
-c --check Print status of the target
-o --output Dump output to the file
-s --spider Spidering for header
-S --spider-all Spidering for header and get body to
output file
-w --wordlist <WORDLIST> Specify wordlist to broutforce
-t --time <SECONDS> pause the scaning time (Denote by seconds) FW-evation
{S}{NAME} --dirs --time 0.5 https://demo.com{N}
pause the scanning for every 1/2 second
--no-color Ignore colors
-q --quiet Start without banner, and don't show status.
{W}{U}Examples{N}:
directory Enumeration:
{NAME} --dirs --wordlist wordlist.txt https://example.com/
sub-domain Enumeration:
{NAME} --sub-domain --wordlist wordlist.txt example.com
----------------------------------------------------------------------------------------
{W}{U}Author{N}: Madhava {W}@{N}RED-5-CRACKERS {W}@{N}Black-widow-z
{W}{U}Issues{N}: https://github.com/Madhava-mng/NetworkEnumeratingKid/issues
{W}{U}Contact{N}: https://t.me/BlackWidowzIntrR5c
If you have any issues Please report at {W}https://red5cracker.wordpress.com/contact/{N}
----------------------------------------------------------------------------------------
"""
HELP_oneline = f"""{G}Usage{N}: {NAME} [arg] <target>\nuse '--help' for more info."""
# Argumenst_taken
tmp_list = []
arg_list =[
'-e', '--sub-domain',
'-w', '--wordlist',
'-d', '--dirs',
'-s', '--spider',
'-S', '--spider-all',
'-c', '--check',
'-m', '--method',
'-h', '--help',
'-o', '--output',
'-t', '--time',
'--no-color',
'-q', '--quiet'
]
tmp_list.append(argv[0])
for i in range(len(argv)):
if argv[i][0] == '-':
if argv[i] in arg_list:
if argv[i] in ("-e","--sub-domain"):
Subdomain_enum = True
tmp_list.append(argv[i])
elif argv[i] in ("-w","--wordlist"):
try:
_tmp_file = argv[i+1]
tmp_list.append(argv[i+1])
tmp_list.append(argv[i])
try:
f = open(_tmp_file,"r")
_tmp_ = f.read()
wordlist = _tmp_.split("\n")
wordlist_dir = wordlist[::]
except:
ErrNo = 2
except:
ErrNo = 1
elif argv[i] in ("-d", "--dirs"):
Uri_enm = True
tmp_list.append(argv[i])
elif argv[i] in ("-s", "--spider"):
Spidering = True
tmp_list.append(argv[i])
elif argv[i] in ("-S", "--spider-all"):
Spidering = True
Spidering_all = True
tmp_list.append(argv[i])
elif argv[i] in ("-h", "--help"):
print(HELP)
tmp_list.append(argv[i])
raise SystemExit
elif argv[i] in ("-c", "--check"):
Pinging = True
tmp_list.append(argv[i])
elif argv[i] in ("-m", "--method"):
Method_deduct = True
tmp_list.append(argv[i])
elif argv[i] in ("-o", "--output"):
try:
Out_put = True
Out_file = argv[i+1]
tmp_list.append(argv[i])
tmp_list.append(argv[i+1])
except:
ErrNo = 3
elif argv[i] in ('-t', '--time'):
try:
try:
time_ev = float(argv[i+1])
except:
tmp_invalied = str(argv[i+1])
ErrNo = 5
if time_ev < 0:
ErrNo = 5 # less than
tmp_list.append(argv[i])
tmp_list.append(argv[i+1])
except:
ErrNo = 4 # time not specified
elif argv[i] in ('--no-color'):
No_color = True
tmp_list.append(argv[i])
elif argv[i] in ('--quiet', '-q'):
Quiet = True
tmp_list.append(argv[i])
else:
print(f"[{R}Error{N}][{Y}InvaliedArgument{N}][ {argv[i]} ]")
raise SystemExit
for i in range(len(argv)):
if argv[i] not in tmp_list:
URL = argv[i]
# find target
if URL == "":
if len(argv) == 1:
print(f"{HELP_oneline}")
else:
print(f"[{R}Error{N}][{Y}TargetRequired{N}][ {B}Eg:{N} {NAME} [arg] http://demo.com/{N} ]\n{G}run{N}: '{NAME} --help' for more info. ")
ErrNo = 6
# Errors
def _errors_(ErrNo):
if ErrNo == 1:
print(f"[{R}Error{N}][{Y}FileNotSpecifyed{N}][ {B}Eg{N}: {NAME} -d http://demo.com {G}-w <Wordlist.txt>{N} ]")
if ErrNo == 2:
print(f"[{R}Error{N}][{Y}FileNotFound{N}][ {_tmp_file} ]")
if ErrNo == 3:
print(f"[{R}Error{N}][{Y}FileNotSpecifyed{N}][ {B}Eg{N}: {NAME} -d http://demo.com {G}-o <file_name.txt>{N} ]")
if ErrNo == 4:
print(f"[{R}Error{N}][{Y}TimeNotSpecified{N}][ {B}Eg{N}: {NAME} -d http://demo.com {G}-t <seconds>{N} ]")
if ErrNo == 5:
print(f"[{R}Error{N}][{Y}InvaliedSecond{N}][ {tmp_invalied} ]")
# URL checkout
if len(URL) > 3:
if URL[:4] != 'http':
URL='http://'+URL
if URL[-1] != "/":
URL = URL
# Percentage
def percent(count,Length):
per = str((count*100)//Length)+"%"
return per
# Ignoretion from headder
def Ignor_header():
_Ignore_ = (
'Alt-Svc',
'Set-Cookie',
'expect-ct',
'content-security-policy',
'Content-Security-Policy',
'Timing-Allow-Origin')
return _Ignore_
# sub-domain-enumeration
def _url_checker(Itered_url,
contant,
Out_file = Out_file,
Out_put= Out_put,
time_ev = time_ev ,
Len_ = len(URL)+16,
No_color = No_color,
Quiet = Quiet
):
try:
contant_=requests.get(f"{Itered_url}")
if contant_.status_code != 404:
if Out_put:
Out_file=open(Out_file, "a")
Out_file.write(f"{Itered_url}\n")
Out_file.close()
if contant_.status_code == 200:
if No_color:
C="\u001b[0m"
else:
C="\u001b[32;1m"
else:
if No_color:
C="\u001b[0m"
else:
C="\u001b[31;1m"
width=int(os.get_terminal_size()[0])+26
a =f"[{P}{time.strftime(f'%H:%M:%S')}{N}][{C}{contant_.status_code}{N}] {G}{Itered_url:<{Len_}}{N} ==> {S}{contant_.headers['Server'].strip()}{N}"
if Quiet:
print(f"{G}{Itered_url}{N}")
else:
if No_color:
print(f"{a:<{width}} ")
else:
print(f"{a:<{width}} ")
contant_.close()
return 0
except KeyboardInterrupt:
exit()
except:
pass
def _sub_domain(
URL = URL,
List_domains = tuple(wordlist),
time_ev = time_ev,
Quiet = Quiet
):
count = 1
ids = []
a=""
LEN = 0
_Dict_=[]
if URL[-1] == "/":
URL = URL[:len(URL)-1]
try:
check = requests.get(URL)
if check.status_code == 200:
_Dict_ = check.headers
check.close()
except:
print(f"[{R}Error{N}][UrlNotFound][ {G}Reason{N}: Unable to ping {Y}{URL}{N} ]")
raise SystemExit
if Quiet:
pass
else:
print(f"{sub_enum_banner}\r",end = '')
for i in _Dict_:
if len(i) > LEN:
LEN=len(i)
print(f"{'-'*47}")
for i in _Dict_:
if i not in Ignor_header():
print(f"{W}{i:{LEN}} :{N} {_Dict_[i]}")
print(f"{'-'*47}\n")
for i in range(len(URL)):
if URL[i] == "/":
if URL[i+1] == "/":
val1 = URL[:i+2]
val2 = URL[i+2:]
Len = len(List_domains)
Len_ = len(str(Len))
for i in List_domains:
try:
if i != "":
url = val1+i.strip()+"."+val2
try:
i=Thread(
target = _url_checker,
args = (url,i,)
)
i.start()
except:
raise SystemExit
try:
_id = i.native_id
ids.append(_id)
except:
pass
width=int(os.get_terminal_size()[0])-12
back_len = f"Time: {time_ev} Threads: {threading.activeCount():^3} Remaining: {Len-count:^{Len_}} {count:>{Len_}}/{Len:<{Len_}} ]{N}"
if Quiet:
pass
else:
print(f"{W}[{P}{time.strftime('%H:%M:%S')}{N}{W}][ {percent(count, Len):4}{back_len:>{width}}\r",end="")
count+=1
time.sleep(time_ev/2)
except:
raise SystemExit
time.sleep(5)
if threading.activeCount() > 3:
for i in range(threading.activeCount()+1):
time.sleep(0.5)
print(f"{a:<{width}} ")
for i in ids:
try:
os.kill(
i,
signal.SIGKILL
)
except:
pass
else:
print(f"{a:<{width}} ")
exit()
# Directory enumeration
def _checking_for_uri(
URL, Name,
Out_file = Out_file,
Out_put= Out_put,
No_color = No_color,
Quiet = Quiet
):
try:
a = requests.head(URL)
Code = a.status_code
Size = a.headers.get("Content-Length")
if int(Size) > 1024*1024:
Size=str(Size/1024)+"M"
elif int(Size) > 1024:
Size=str(Size/1024)+"K"
if Code != 404:
if Size == None:
Size='None'
if Code == 200:
C=f'{W}{G}'
elif Code < 400:
C=f'{W}{B}'
if str(Code)[0] == "3":
URL+="/"
else:
C=f'{W}{R}'
if Out_put:
if Code < 500:
Out_file = open(Out_file, "a")
Out_file.write(f"{URL}\n")
Out_file.close()
if Quiet:
print(f"{G}{URL}{N}")
else:
width=int(os.get_terminal_size()[0])+35
A = f"[{P}{time.strftime(f'%H:%M:%S')}{N}][{C}{Code}{N}] {B}Size{N}: {Size} ==> {G}{URL}{N}"
if No_color:
print(f"{A:<{width}} ")
else:
print(f"{A:<{width}} ")
a.close()
except:
raise SystemExit
def _dir_(
URL = URL,
URI = tuple(wordlist_dir),
time_ev = time_ev,
Quiet = Quiet
):
count = 1
URI+="doc/", "icon/", "robote.txt"
Len = len(URI)
if URL[-1] != "/":
URL = URL+"/"
try:
a = requests.get(URL)
_Dict_ = a.headers
LEN = 0
if Quiet:
pass
else:
print(f"{dir_enum_banner}\r", end='')
for i in _Dict_:
if len(i) > LEN:
LEN=len(i)
print(f"{'-'*47}")
for i in _Dict_:
if i not in Ignor_header():
print(f"{W}{i:{LEN}} :{N} {_Dict_[i]}")
print(f"{'-'*47}\n")
a.close()
except:
print(f"[{R}Error{N}][UrlNotFound][ {G}Reason{N}: Unable to ping {Y}{URL}{N} ]")
raise SystemExit
try:
for _uri_ in URI:
if _uri_ != "" and _uri_[0] != '#':
url = URL+_uri_.strip()
_uri__ = Thread(target = _checking_for_uri ,args = (url,_uri_,))
_uri__.start()
width=int(os.get_terminal_size()[0])-12
back_len=f"Time: {time_ev} Threads: {threading.activeCount():^3} Remaining: {Len-count:^{len(str(Len))}} {count:>{len(str(Len))}}/{Len} ]{N}"
if Quiet:
pass
else:
print(f"{W}[{P}{time.strftime('%H:%M:%S')}{N}{W}][ {percent(count, Len):4}{back_len:>{width}}\r",end="")
count+=1
time.sleep(time_ev)
a=f""
while threading.activeCount() > 1:
pass
print(f"{a:<{width}} ")
except:
raise SystemExit
# Spidering
def Spider(
URL = URL,
Spidering_all = Spidering_all
):
try:
a = requests.get(URL)
_Dict_ = a.headers
print(f"[{P}{time.strftime(f'%H:%M:%S')}{N}][{B}GET{N}][{G}{a.status_code}{N}][{Y}{URL}{N}]")
LEN = 0
for i in _Dict_:
if len(i) > LEN:
LEN=len(i)
print(f"{'-'*48}")
for i in _Dict_:
if i not in Ignor_header():
print(f"{W}{i:{LEN}} :{N} {_Dict_[i]}")
print(f"{'-'*48}")
except:
print(f"[{R}Error{N}][UrlNotFound][ {G}Reason{N}: Unable to ping {Y}{URL}{N} ]")
Spidering_all = False
try:
Tmp_list=[]
for i in _Dict_['Set-Cookie'].split(";"):
if i not in Tmp_list:
print(f"[{G}Cookie-Info{N}] {i}")
Tmp_list.append(i)
except:
pass
try:
for i in _Dict_['Alt-Svc'].split(";"):
print(f"[{G}Alt-Svc{N}]{i}")
except:
pass
try:
for i in _Dict_['expect-ct'].split(";"):
print(f"[{G}except-ct{N}]{i}")
except:
pass
try:
for i in _Dict_['Timing-Allow-Origin'].split(";"):
print(f"[{G}Timing-Allow-Origin{N}] {i}")
except:
pass
try:
for i in _Dict_['content-security-policy'].split(";"):
print(f"[{G}SecurityPolicy{N}] {i}")
except:
pass
if Spidering_all:
print(f'[{G}Body{N}][ {P}File{N}: {Y}{Out_file}.html{N} ]')
f = open(f"{Out_file}.html",'w')
f.write(a.text)
f.close()
# Pinging
def Ping(URL=URL):
try:
a=requests.get(URL)
print(f"[{P}{time.strftime(f'%H:%M:%S')}{N}][{B}GET{N}][{G}Success{N}][{S}{a.status_code}{N}][{Y}{URL}{N}]\a")
a.close()
except:
print(f"[{P}{time.strftime(f'%H:%M:%S')}{N}][{B}GET{N}][{R}Failed{N} ][{R}404{N}][{Y}{URL}{N}]")
# Method deduction
def Method(
URL=URL,
time_ev = time_ev
):
tmp_list = []
METHOD = [
"GET",
"HEAD",
"POST",
"PUT",
"DELETE",
"CONNECT",
"TRACE",
"PATCH",
"OPTIONS"
]
def check_method(
URL,
Method_,
tmp_list = tmp_list
):
try:
a=requests.request(
Method_,
URL )
if a.status_code == 200:
col = f'{G}{W}'
per = "Allowed"
tmp_list.append(Method_)
else:
col = f'{R}'
per = "NotAllowed"
print(f"[{P}{time.strftime(f'%H:%M:%S')}{N}][{Y}{Method_:^7}{N}][{col}{a.status_code}{N}][{B}{URL}{N}][{col}{per:^10}{N}]")
except:
print(f"[{R}Error{N}][UrlNotFound][ {G}Reason{N}: Unable to ping {Y}{URL}{N} ]")
raise SystemExit
for i in METHOD:
try:
time.sleep(time_ev)
t = Thread(
target=check_method,
args=(URL,i,) )
t.start()
except KeyboardInterrupt:
raise SystemExit
except:
pass
while threading.activeCount() != 1:
pass
print(f"\n{G}Allowed{N}:",end = "")
for i in tmp_list:
print(f" {i}",end = "")
print(".")
# No color
if No_color:
(R, Y, G, N, P, B, W, S) = (
"\u001b[0m",
"\u001b[0m",
"\u001b[0m",
"\u001b[0m",
"\u001b[0m",
"\u001b[0m",
"\u001b[1m",
"\u001b[0m")
# Banners
# if Quiet:
dir_enum_banner = ''
# else:
# dir_enum_banner = ("\n"*(os.get_terminal_size()[1]-7))+"""
# 888 d8b .d8888b.
# 888 Y8P d88P Y88b
# 888 .d88P
# .d88888 888 888d888 8888" 88888b. 888 888 88888b.d88b.
# d88" 888 888 888P" "Y8b. 888 "88b 888 888 888 "888 "88b
# 888 888 888 888 888 888 888 888 888 888 888 888 888
# Y88b 888 888 888 Y88b d88P 888 888 Y88b 888 888 888 888
# "Y88888 888 888 "Y8888P" 888 888 "Y88888 888 888 888"""
# if Quiet:
sub_enum_banner = ''
# else:
# sub_enum_banner = ("\n"*(os.get_terminal_size()[1]-10))+"""
# 888888888 8888888b. .d8888b.
# 888 888 "Y88b d88P Y88b
# 888 888 888 .d88P
# 8888888b. 888 888 8888" 88888b. 888 888 88888b.d88b.
# "Y88b 888 888 "Y8b. 888 "88b 888 888 888 "888 "88b
# 888 888 888 888 888 888 888 888 888 888 888 888
# Y88b d88P 888 .d88P Y88b d88P 888 888 Y88b 888 888 888 888
# "Y8888P" 8888888P" "Y8888P" 888 888 "Y88888 888 888 888"""
# start functions
if ErrNo != 0:
_errors_(ErrNo)
raise SystemExit
if Pinging:
Ping()
if Spidering:
Spider()
if Subdomain_enum:
_sub_domain()
if Uri_enm:
_dir_()
if Method_deduct:
Method()