-
Notifications
You must be signed in to change notification settings - Fork 48
/
scan.py
170 lines (155 loc) · 5.2 KB
/
scan.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
# -*- encoding:utf-8 -*-
import threading
import time
import os,sys
import Module.fofa
import Module.yaml
import Module.fofareptile
import queue
import platform
import random
class scan(threading.Thread):
def __init__(self,q=None):
threading.Thread.__init__(self)
self.q = q
#调用scan_config里面的配置
scan_config = Module.yaml.full_load(open('scan_config.yaml','rb'))
self.domain_scan = scan_config['global']['scan_domain_name']
self.reptile = scan_config['global']['fofareptile']
if self.reptile:
self.fofacookie = scan_config['fofa']['Fofa_Cookie']
#[xray]
self.file_path = scan_config['xray']['file_path']
self.xray_file_path = scan_config['xray']['xray_file_path']
self.input_file_type = scan_config['xray']['input_file_type']
self.xray_plugins = scan_config['xray']['xray_plugins']
if self.xray_plugins == None:
self.xray_plugins = "xss,dirscan,xxe,upload,jsonp,brute-force,cmd-injection,crlf-injection,phantasm,sqldet"
if self.xray_file_path == None:
if platform.system()=="Windows": # 判断操作系统
self.xray_file_path = 'xray_windows_amd64.exe'
else:
self.xray_file_path = './xray_linux_amd64'
if self.input_file_type == None:
self.input_file_type = 'html'
if self.file_path == None:
self.file_path ='./'+self.input_file_type
if not os.path.exists(self.input_file_type):
os.makedirs(self.input_file_type)
#[fofa]
self.fofa_email = scan_config['fofa']['Fofa_email']
self.fofa_key = scan_config['fofa']['Fofa_key']
self.syntax = scan_config['fofa']['fofaQuerysyntax']
if self.fofa_email == None or self.fofa_key == None:
print('error: fofa_email 或者 fofa_key 没有输入')
sys.exit()
def xray(self,url):
#xray配置
if self.input_file_type == 'text':
file_path = self.file_path+"/"+str(int(time.time()))+'.txt'
else:
file_path = self.file_path+"/"+str(int(time.time()))+'.'+self.input_file_type
os.system('%s webscan --plugins %s --basic-crawler %s --%s-output %s'%(self.xray_file_path,self.xray_plugins,url,self.input_file_type,file_path))
def Fofa(self,count=None):
#fofa扫描
syntax=''
if self.reptile:
for value in self.syntax:
syntax+=value+','
domain = Module.fofareptile.fofascan(self.fofacookie,syntax)
return domain
else:
urllist=[]
value = ''
for key in self.syntax:
value+=key+','
email = self.fofa_email
key = self.fofa_key
search = Module.fofa.FofaAPI(email, key)
if search.get_data('%s'%(value),count)['results']==[]:
print("The fofa scan result is empty, end ")
sys.exit()
try:
for host in search.get_data('%s'%(value),count)['results']:
if self.domain_scan:
if self.getdomain(host)!=None:
urllist.append(self.getdomain(host))
else:
urllist.append(self.geturl(host))
return urllist
except:
print("Response error! Please try crawler mode!")
sys.exit()
def geturl(self,value): #优化url
value =value.strip()
if value[:4] == 'http':
url=value
else:
url='http://'+value
return url
def getdomain(self,value): #过滤出域名
url = value.strip()
if url[:7] == 'http://' or url[:8] == 'https://':
urls = url[url.index('//')+2:]
if ':' in urls:
urls = urls[:urls.index(':')]
value = urls.replace('.','')
try:
int(value)
except:
return url
def run(self):
if self.reptile:
while 1:
urllist = self.Fofa()
for url in urllist:
if self.domain_scan:
if self.getdomain(url)==None:continue
else:url = self.getdomain(url)
else:url = self.geturl(url)
self.xray(url)
else:
while not self.q.empty():
url_list = q.get()
for url in url_list:self.xray(url)
if __name__=='__main__':
print("""
\033[1;36m
___ ___ .______ ___ ____ ____ _______ ______ _______ ___
\ \ / / | _ \ / \ \ \ / / | ____| / __ \ | ____| / \
\ V / | |_) | / ^ \ \ \/ / | |__ | | | | | |__ / ^ \
> < | / / /_\ \ \_ _/ | __| | | | | | __| / /_\ \
/ . \ | |\ \----./ _____ \ | | | | | `--' | | | / _____ \
/__/ \__\ | _| `._____/__/ \__\ |__| |__| \______/ |__| /__/ \__\
\033[0m
""")
threads=[]
count=1
scan_config = Module.yaml.full_load(open('scan_config.yaml','rb'))
thread_count =scan_config['global']['threads']
info='\033[1;34m[INFO]\033[0m'
error='\033[1;31m[ERROR]\033[0m'
conn_info = '\033[1;32m[INFO]\033[0m'
print('{} Threads size is {}'.format(info,thread_count))
if scan_config['global']['scan_domain_name']:
print('{} Scan domain name is ON'.format(info))
if scan_config['global']['fofareptile']:
print('{} fofareptile is ON'.format(info))
else:
user_info = Module.fofa.FofaAPI(scan_config['fofa']['Fofa_email'],scan_config['fofa']['Fofa_key'])
if user_info.get_user_is_vip():
print(error,user_info.get_user_is_vip())
sys.exit()
else:
print('{} Fofa API successfully connected'.format(conn_info))
print('{} Start running XrayFofa'.format(info))
q = queue.Queue()
for i in range(thread_count):
q.put(scan().Fofa(count))
count+=1
for i in range(thread_count):
threads.append(scan(q))
for thread in threads:
thread.start()
for thread in threads:
thread.join()