forked from Cl0udG0d/HXnineTails
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscan.py
More file actions
220 lines (190 loc) · 7.69 KB
/
scan.py
File metadata and controls
220 lines (190 loc) · 7.69 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
import hashlib
from crawlergo import crawlergoMain
from Xray import pppXray
import config
import sys
import getopt
import base
from ServerJiang.jiangMain import SendNotice
'''
扫描控制主函数
参数:
url
格式如:https://www.baidu.com
扫描联动工具:
JS方面:
JSfinder
漏洞扫描:
360 0Kee-Team 的 crawlergo动态爬虫 -> Xray高级版
C段:
自写C段扫描函数
'''
from concurrent.futures import ThreadPoolExecutor, wait, ALL_COMPLETED
def threadPoolDetailScan(temp_url, current_filename):
pppXray.xrayScan(temp_url, current_filename)
base.transferJSFinder(temp_url, current_filename)
base.transferCScan(temp_url, current_filename)
return
def threadPoolScan(req_pool, filename, target):
print("req_pool num is {}".format(len(req_pool)))
thread = ThreadPoolExecutor(max_workers=config.ThreadNum)
i = 0
all_task = []
while len(req_pool) != 0:
# 将 req_pool 里的URL依次弹出并扫描
temp_url = req_pool.pop()
current_filename = hashlib.md5(temp_url.encode("utf-8")).hexdigest()
# 调用 xray 进行扫描并保存
# pppXray.xrayScan(temp_url, current_filename)
i += 1
one_t = thread.submit(pppXray.xrayScan, temp_url, current_filename)
all_task.append(one_t)
if i == 5 or len(req_pool) == 0:
i = 0
wait(all_task, return_when=ALL_COMPLETED)
all_task = []
base.mergeReport(filename)
SendNotice("{} 花溪九尾扫描完毕".format(target))
def pppFoxScan(filename):
print("Start pppFoxScan,filename is {}".format(filename))
try:
with open(filename, 'r') as f:
lines = f.readlines()
for line in lines:
target = line.strip()
target = base.addHttpHeader(target)
config.ppp_queue.put(target)
except Exception as e:
print(e)
pass
while not config.ppp_queue.empty():
current_target = config.ppp_queue.get()
# 对搜集到的目标挨个进行扫描
currentfilename=hashlib.md5(current_target.encode("utf-8")).hexdigest()
if base.checkBlackList(current_target):
req_pool = crawlergoMain.crawlergoGet(current_target)
req_pool.add(current_target)
# 对目标网址使用 crawlergoGet 页面URL动态爬取,保存在 req_pool 集合里
threadPoolScan(req_pool, currentfilename, current_target)
print("pppFoxScan End~")
return
'''
oneFoxScan(target)函数
针对某一目标网址进行扫描而非对某一资产下的网址进行扫描,输入案例: www.baidu.com
扫描流程: 输入URL正确性检查+crawlergo+xray
'''
def oneFoxScan(target):
if base.checkBlackList(target):
target = base.addHttpHeader(target)
filename = hashlib.md5(target.encode("utf-8")).hexdigest()
print("Start foxScan {}\nfilename : {}\n".format(target, filename))
req_pool = crawlergoMain.crawlergoGet(target)
# 对目标网址使用 crawlergoGet 页面URL动态爬取,保存在 req_pool 集合里
req_pool.add(target)
threadPoolScan(req_pool, filename, target)
print("InPuT T4rGet {} Sc3n EnD#".format(target))
return
'''
花溪九尾主函数
foxScan(target) 函数
参数:
target 待扫描的URL 示例:baidu.com
作用:
对输入的目标进行子域名收集 -> 存储去重 -> crawlergo动态爬虫 -> Xray高级版漏洞扫描
输出:
对应阶段性结果都会保存在save 文件夹下对应的目录里面
'''
def foxScan(target):
filename = hashlib.md5(target.encode("utf-8")).hexdigest()
print("Start attsrc foxScan {}\nfilename : {}\n".format(target, filename))
base.subScan(target, filename)
# 进行子域名搜集
while not config.target_queue.empty():
current_target = config.target_queue.get()
if base.checkBlackList(current_target):
# 对搜集到的目标挨个进行扫描
req_pool = crawlergoMain.crawlergoGet(current_target)
req_pool.add(current_target)
# 对目标网址使用 crawlergoGet 页面URL动态爬取,保存在 req_pool 集合里
threadPoolScan(req_pool, filename, target)
print("InPuT T4rGet {} Sc3n EnD#".format(target))
return
'''
foxScanDetail(target)
对于输入SRC进行详细的信息搜集+扫描
耗时很长+为防止遗漏搜集了部分重复信息(不建议使用
作用:
-> JS敏感信息提取
对输入的目标进行子域名收集 -> 存储去重 -> crawlergo动态爬虫 -> Xray高级版漏洞扫描
-> C段信息收集
输出:
对应阶段性结果都会保存在save 文件夹下对应的目录里面
'''
def foxScanDetail(target):
thread = ThreadPoolExecutor(config.ThreadNum)
filename = hashlib.md5(target.encode("utf-8")).hexdigest()
print("Start attsrc foxScan {}\nfilename : {}\n".format(target, filename))
base.subScan(target, filename)
# 进行子域名搜集
while not config.target_queue.empty():
current_target = config.target_queue.get()
# 对搜集到的目标挨个进行扫描
if base.checkBlackList(current_target):
req_pool = crawlergoMain.crawlergoGet(current_target)
req_pool.add(current_target)
i = 0
all_task = []
while len(req_pool) != 0:
# 将 req_pool 里的URL依次弹出并扫描
temp_url = req_pool.pop()
current_filename = hashlib.md5(temp_url.encode("utf-8")).hexdigest()
i += 1
one_t = thread.submit(threadPoolDetailScan, temp_url, current_filename)
all_task.append(one_t)
if i == 5 or len(req_pool) == 0:
i = 0
wait(all_task, return_when=ALL_COMPLETED)
all_task = []
print("InPuT T4rGet {} Sc3n EnD#".format(target))
return
'''
单元测试代码
支持三个攻击参数:
1,-a --attone 对单个URL,只进行crawlergo动态爬虫+xray扫描 例如 百度官网 输入 https://www.baidu.com
2,-s --attsrc 对SRC资产,进行信息搜集+crawlergo+xray , 例如 百度SRC 输入 baidu.com
3,-d --attdetail 对SRC资产,进行信息搜集+crawlergo+xray+C段信息搜集+js敏感信息搜集 , 例如 百度SRC 输入 baidu.com
'''
def main(argv):
config.logo()
base.init()
try:
opts, args = getopt.getopt(argv, "ha:s:d:r:t:c",
["help", "attone=", "attsrc=", "attdetail=", "readppp=", "thread=", "clean"])
except getopt.GetoptError:
config.scanHelp()
sys.exit(2)
for opt, arg in opts:
target = arg
filename = arg
if opt in ("-h", "--help"):
config.scanHelp()
sys.exit()
elif opt in ("-t", "--thread"):
config.ThreadNum = int(arg)
elif opt in ("-a", "--attone"):
oneFoxScan(target)
elif opt in ("-s", "--attsrc"):
foxScan(target)
elif opt in ("-d", "--attdetail"):
foxScanDetail(target)
elif opt in ("-r", "--readppp"):
pppFoxScan(filename)
elif opt in ("-c", "--clean"):
config.delModel()
sys.exit()
else:
config.scanHelp()
sys.exit()
return
if __name__ == '__main__':
main(sys.argv[1:])