-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathasnpepper.py
121 lines (96 loc) · 4.64 KB
/
asnpepper.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
#!/usr/bin/python3
from argparse import RawTextHelpFormatter
from operator import ne
from threading import Thread
import argparse, sys
from xmlrpc.client import boolean
### include lib/utils, lib/tests ###
sys.path.insert(1, 'lib/utils')
sys.path.insert(1, 'lib/tests')
#####################################
import cidr_parse, cidr_getter, git_scanner, port_scan, file_manager, plogger
def main(org,name):
cidr_html = cidr_getter.Getter.get_bgp(org)
cidr_list = cidr_parse.Parse.extract_cidr_list(cidr_html)
org_list = cidr_parse.Parse.extract_org_list(cidr_html)
result = []
full_network = []
for cidr in cidr_list:
if cidr not in result:
result.append(cidr)
for cidr_final,org_name in zip(result,org_list):
print(cidr_final,org_name)
if args.parse_cidr:
network = cidr_parse.Parse.parse_cidr(cidr_final, do_print=can_log_network())
data = ''
for i in network:
data = data + str(i) + '\n'
full_network.append(i)
output(name, data)
else:
output(name,cidr_final)
if not can_log_network():
process_module(full_network)
def main_verify(org,name,input_list):
if input_list:
list = cidr_parse.Parse.input_thread(input_list)
for org in list:
try:
Thread(target=main,args=(org,name)).start()
except KeyboardInterrupt:
print('[!]Execution Canceled ...')
exit(0)
else:
main(org,name)
def can_log_network():
return not args.test_git and not (args.test_web is not None)
def process_module(network_range):
network = []
for i in network_range:
network.append(str(i))
if args.test_git:
plogger.PepperLogger.log_info('Initializing Git Exposed Scan in CIDRs. Threads: %s, IPs: %s' % (str(args.threads), str(len(network))))
def callback_scan(ip, port):
git_scanner.GitScanner.Wrapper.scan([ip], ['http://'], show_fp=args.show_fp)
git_scanner.GitScanner.Wrapper.scan([ip], ['https://'], show_fp=args.show_fp)
port_scan.Scanner.Wrapper.scan_ips_with_custom_callback(network, 80, callback_scan, args.threads)
pass
if args.test_web is not None:
plogger.PepperLogger.log_info('Initializing Web Server Scan in CIDRs. Threads: %s, IPs: %s, Ports: %s' % (str(args.threads), str(len(network)),args.test_web))
ports = args.test_web.split(",")
for port in ports:
port_scan.Scanner.Wrapper.scan_ips(network, int(port), args.threads)
pass
def output(name,cidr_final):
if name is not None:
file_manager.FileManager.write(name, cidr_final, end='\n')
def msg():
banner = '''
) ( ( (
( /( ( ( ` ) ))\ ` ) ` ) ))\ )(
)(_)) )\ )\ ) /(/( /((_)/(/( /(/( /((_)(()\
((_)_ ((_) _(_/( ((_)_\ (_)) ((_)_\ ((_)_\ (_)) ((_)
/ _` |(_-<| ' \))| '_ \)/ -_)| '_ \)| '_ \)/ -_) | '_|
\__,_|/__/|_||_| | .__/ \___|| .__/ | .__/ \___| |_|
|_| |_| |_| v.1.0
'''
return banner
def init():
global args
parser = argparse.ArgumentParser(description=msg(), formatter_class=RawTextHelpFormatter, usage="python asnpepper.py -o org --output output.txt")
parser.add_argument('-o','--org', dest='org', action='store', type=str, help='insert an organization')
parser.add_argument('-O','--output', dest='output_file', action='store', type=str, help="file to save CIDR's")
parser.add_argument('-si', '--show-ip', dest='parse_cidr', help='convert cidrs to network IPs range', default=False, action=argparse.BooleanOptionalAction)
parser.add_argument('--test-git', dest='test_git', help='test IPs containing git exposed (in dev)', default=False, action=argparse.BooleanOptionalAction)
parser.add_argument('--test-port', dest='test_web', action='store', type=str, help="test IPs containing port (in dev)")
parser.add_argument('-sfp', dest='show_fp', help='show false positive in git scanner', default=False, action=argparse.BooleanOptionalAction)
parser.add_argument('-t','--threads', dest='threads', action='store', default=1000, type=int, help="Threads for --test-git or --test-port")
parser.add_argument('-iL','--input-list', dest='input_list', action='store', type=str, help='insert list with organization names')
args=parser.parse_args()
if args.test_web or args.test_git:
args.parse_cidr = True
if not args.org and not args.input_list:
parser.print_help()
sys.exit(0)
main_verify(args.org,args.output_file,args.input_list)
init()