-
Notifications
You must be signed in to change notification settings - Fork 517
/
AngelSword.py
executable file
·434 lines (399 loc) · 17.1 KB
/
AngelSword.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
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#Author: Lucifer
#Prog: Main
#date: changeby 2017-8-21
import os
import re
import io
import sys
import time
import requests
import warnings
from termcolor import cprint
from urllib.parse import urlparse
from information.informationmain import *
from cms.cmsmain import *
try:
from pocdb import pocdb_pocs
except Exception as e:
print(e)
from industrial.industrialmain import *
from system.systemmain import *
from hardware.hardwaremain import *
from multiprocessing import Pool
from multiprocessing.dummy import Pool as ThreadPool
warnings.filterwarnings("ignore")
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
SEARCH_HISTORY = dict()
#版本号
VERSION = 'v2.0'
FLAGLET = '''
/ \ _ __ __ _ ___| / ___|_ _____ _ __ __| |
/ _ \ | '_ \ / _` |/ _ \ \___ \ \ /\ / / _ \| '__/ _` |
/ ___ \| | | | (_| | __/ |___) \ V V / (_) | | | (_| |
/_/ \_\_| |_|\__, |\___|_|____/ \_/\_/ \___/|_| \__,_|
|___/
'''
threads_num = 10
#并行任务池
#cmspool = ThreadPool()
cmspool = ThreadPool(threads_num)
#industrialpool = ThreadPool()
industrialpool = ThreadPool(threads_num)
#systempool = ThreadPool()
systempool = ThreadPool(threads_num)
#hardwarepool = ThreadPool()
hardwarepool = ThreadPool(threads_num)
#informationpool = ThreadPool()
informationpool = ThreadPool(threads_num)
def split_string(strLine):
pattern = r"[a-z_]+BaseVerify"
return str(re.findall(pattern, strLine)).replace("_BaseVerify", "").replace("['","").replace("']","")
def informationprint(informationname):
msg = ">>>Scanning information vulns.."
sys.stdout.write(msg+informationname+" "*(len(msg)+10)+"\r")
sys.stdout.flush()
time.sleep(0.5)
def informationcheck(informationpoc):
informationpoc.run()
def informationpoc_check(informationurl):
poc_class = pocdb_pocs(informationurl)
poc_dict = poc_class.informationpocdict
cprint(">>>Information漏洞扫描URL: "+informationurl+"\t可用POC个数["+str(len(poc_dict))+"]", "magenta")
informationpool.map(informationprint, poc_dict.keys())
print("\r")
results = informationpool.map(informationcheck, poc_dict.values())
informationpool.close()
informationpool.join()
def cmsprint(cmsname):
msg = ">>>Scanning cms vulns.."
sys.stdout.write(msg+cmsname+" "*(len(msg)+10)+"\r")
sys.stdout.flush()
time.sleep(0.5)
def cmscheck(cmspoc):
cmspoc.run()
def cmspoc_check(cmsurl):
poc_class = pocdb_pocs(cmsurl)
poc_dict = poc_class.cmspocdict
cprint(">>>CMS漏洞扫描URL: "+cmsurl+"\t可用POC个数["+str(len(poc_dict))+"]", "magenta")
cmspool.map(cmsprint, poc_dict.keys())
print("\r")
results = cmspool.map(cmscheck, poc_dict.values())
cmspool.close()
cmspool.join()
def industrialprint(industrialname):
msg = ">>>Scanning industrial vulns.."
sys.stdout.write(msg+industrialname+" "*len(msg)+"\r")
sys.stdout.flush()
time.sleep(0.5)
def industrialcheck(industrialpoc):
industrialpoc.run()
def industrial_check(industrialurl):
poc_class = pocdb_pocs(industrialurl)
poc_dict = poc_class.industrialpocdict
cprint(">>>工控漏洞扫描URL: "+industrialurl+"\t可用POC个数["+str(len(poc_dict))+"]", "magenta")
industrialpool.map(industrialprint, poc_dict.keys())
print("\r")
results = industrialpool.map(industrialcheck, poc_dict.values())
industrialpool.close()
industrialpool.join()
def systemprint(systemname):
msg = ">>>Scanning system vulns.."
sys.stdout.write(msg+systemname+" "*len(msg)+"\r")
sys.stdout.flush()
time.sleep(0.5)
def systemcheck(systempoc):
systempoc.run()
def system_check(systemurl):
poc_class = pocdb_pocs(systemurl)
poc_dict = poc_class.systempocdict
cprint(">>>System漏洞扫描URL: "+systemurl+"\t可用POC个数["+str(len(poc_dict))+"]", "magenta")
systempool.map(systemprint, poc_dict.keys())
print("\r")
results = systempool.map(systemcheck, poc_dict.values())
systempool.close()
systempool.join()
def hardwareprint(hardwarename):
msg = ">>>Scanning hardware vulns.."
sys.stdout.write(msg+hardwarename+" "*len(msg)+"\r")
sys.stdout.flush()
time.sleep(0.5)
def hardwarecheck(hardwarepoc):
hardwarepoc.run()
def hardware_check(hardwareurl):
poc_class = pocdb_pocs(hardwareurl)
poc_dict = poc_class.hardwarepocdict
cprint(">>>Hardware漏洞扫描URL: "+hardwareurl+"\t可用POC个数["+str(len(poc_dict))+"]", "magenta")
hardwarepool.map(hardwareprint, poc_dict.keys())
print("\r")
results = hardwarepool.map(hardwarecheck, poc_dict.values())
hardwarepool.close()
hardwarepool.join()
def AngelSwordMain(checkurl):
try:
reqt = requests.get(checkurl, timeout=10, verify=False)
#执行information漏洞poc检查
informationpoc_check(checkurl)
#执行cms漏洞poc检查
cmspoc_check(checkurl)
#执行工控漏洞poc检查
industrial_check(checkurl)
#执行系统漏洞poc检查
system_check(checkurl)
#执行硬件漏洞poc检查
hardware_check(checkurl)
except Exception as e:
print(e)
cprint(">>>>>>>>>超时", "cyan")
if __name__ == '__main__':
usage=FLAGLET+'''
%s
天使之剑,指哪打哪!
opt:
---------------------------------------------------
-h Get help
-t Target
-u Url
-l List avalible pocs
-s Search poc key words
-m Use poc module
-f Load urls file
-r With range
-e Edit Poc file(if have parameter '-m')
-v List scanner verbose
-c Checksum and clear
---------------------------------------------------
Usage: python3 AngelSword.py -u http://www.example.com 对url执行所有poc检测(暴力)
1.python3 AngelSword.py -l 列出所有poc
2.python3 AngelSword.py -s live800 搜索出live800的相关poc
3.python3 AngelSword.py -m live800_downlog_filedownload -t http://www.example.com 单一目标执行live800 download任意文件下载漏洞检测
4.python3 AngelSword.py -m live800_downlog_filedownload -f vuln.txt 对vuln.txt中的所有url执行live800 downlog任意文件下载漏洞检测
6.python3 AngelSword.py -r all -t http://www.example.com 对搜索出来的poc进行指定范围批量测试。 使用前需要利用-s搜索。
7.python3 AngelSword.py -m live800_downlog_filedownload -e 调用系统中的vim编辑poc文件
8.python3 AngelSword.py -v 显示静态统计
9.python3 AngelSword.py -c poc路径校验
'''%VERSION
if len(sys.argv) < 2 or sys.argv[1]=="-h":
cprint(usage, "cyan")
elif sys.argv[1] == "-l":
#列出CMS POC名称
pocclass = pocdb_pocs('')
cmsclass = pocclass.cmspocdict
print("\t\t\tCMS POC")
for cms in cmsclass:
print("|"+cms+"\t|\t"+split_string(str(cmsclass.get(cms).__str__)))
print("|-------------------------------------------------------------------------------------------------------------|")
print("\r")
#列出industrial POC名称
pocclass = pocdb_pocs('')
industrialclass = pocclass.industrialpocdict
print("\t\t\tIndustrial POC")
for industrial in industrialclass:
print("|"+industrial+"\t|\t"+split_string(str(industrialclass.get(industrial).__str__)))
print("|-------------------------------------------------------------------------------------------------------------|")
print("\r")
#列出SYSTEM POC名称
pocclass = pocdb_pocs('')
systemclass = pocclass.systempocdict
print("\t\t\tSYSTEM POC")
for system in systemclass:
print("|"+system+"\t|\t"+split_string(str(systemclass.get(system).__str__)))
print("|-------------------------------------------------------------------------------------------------------------|")
print("\r")
#列出HARDWARE POC名称
pocclass = pocdb_pocs('')
hardwareclass = pocclass.hardwarepocdict
print("\t\t\tHARDWARE POC")
for hardware in hardwareclass:
print("|"+hardware+"\t|\t"+split_string(str(hardwareclass.get(hardware).__str__)))
print("|-------------------------------------------------------------------------------------------------------------|")
print("\r")
elif sys.argv[1] == "-s" and sys.argv[2]:
keywords = sys.argv[2].strip()
count = 0
cprint("搜索结果: ", "green")
with open("pocdb.py", "r", encoding='utf-8') as f:
for line in f.readlines():
line = line.strip()
if line.find(keywords) is not -1:
count += 1
line = line.split(":")
linename = line[0].rstrip('"').lstrip('"')
linepoc = line[1].replace("_BaseVerify(url),", "")
searchstr = "["+str(count)+"]漏洞名: "+linename+"=======>"+linepoc
cprint(searchstr, "yellow")
SEARCH_HISTORY[str(count)] = linepoc
if os.path.exists(".history") is True:
os.remove(".history")
f = open(".history", "a")
for key, value in SEARCH_HISTORY.items():
stringLine = key + "|" + value + "\r\n"
f.write(stringLine)
elif sys.argv[1] == "-m" and sys.argv[3] == "-f":
#合并漏洞字典
poc_class = pocdb_pocs("")
alldict = dict()
tmpdict = poc_class.informationpocdict.copy()
alldict.update(tmpdict)
tmpdict = poc_class.cmspocdict.copy()
alldict.update(tmpdict)
tmpdict = poc_class.systempocdict.copy()
alldict.update(tmpdict)
tmpdict = poc_class.industrialpocdict.copy()
alldict.update(tmpdict)
tmpdict = poc_class.hardwarepocdict.copy()
alldict.update(tmpdict)
for keyword in alldict.values():
if keyword.__str__().find(sys.argv[2].strip()) is not -1:
break
cprint(FLAGLET, "cyan")
sys.stdout.write("\033[1;35m[+] 加载poc: ["+keyword.__module__+"]\033[0m\n")
statistic_count = 0
filepath = sys.argv[4].strip()
allcount = len(open(filepath,'rU').readlines())
with open(filepath) as f:
for line in f.readlines():
statistic_count += 1
line = line.strip()
sys.stdout.write("\033[1;35m[+] 发送payload..\033[0m\n")
sys.stdout.write("\033[1;35m[+] 正在攻击.."+line+"\033[0m\n")
keyword.url = line
keyword.run()
print("[*] 攻击进度: [", end="")
sys.stdout.write(str(statistic_count))
cprint("/"+str(allcount)+"]"+"\r")
sys.stdout.flush()
elif sys.argv[1] == "-u" and sys.argv[2]:
AngelSwordMain(sys.argv[2])
elif sys.argv[1] == "-m" and sys.argv[3] == "-t":
target = sys.argv[4].strip()
poc_class = pocdb_pocs(target)
alldict = dict()
tmpdict = poc_class.informationpocdict.copy()
alldict.update(tmpdict)
tmpdict = poc_class.cmspocdict.copy()
alldict.update(tmpdict)
tmpdict = poc_class.systempocdict.copy()
alldict.update(tmpdict)
tmpdict = poc_class.industrialpocdict.copy()
alldict.update(tmpdict)
tmpdict = poc_class.hardwarepocdict.copy()
alldict.update(tmpdict)
for keyword in alldict.values():
if keyword.__str__().find(sys.argv[2].strip()) is not -1:
break
cprint(FLAGLET, "cyan")
sys.stdout.write("\033[1;35m[+] 加载poc: ["+keyword.__module__+"]\033[0m\n")
sys.stdout.write("\033[1;35m[+] 发送payload..\033[0m\n")
sys.stdout.write("\033[1;35m[+] 正在攻击.."+target+"\033[0m\n")
sys.stdout.flush()
keyword.run()
elif sys.argv[1] == "-r" and sys.argv[3] == "-t":
rangedict = dict()
with open (".history") as f:
for line in f.readlines():
line = line.strip()
rangedict[line.split("|")[0]] = line.split("|")[1]
if sys.argv[2] == "all":
poclist = list()
target = sys.argv[4].strip()
poc_class = pocdb_pocs(target)
alldict = dict()
tmpdict = poc_class.informationpocdict.copy()
alldict.update(tmpdict)
tmpdict = poc_class.cmspocdict.copy()
alldict.update(tmpdict)
tmpdict = poc_class.systempocdict.copy()
alldict.update(tmpdict)
tmpdict = poc_class.industrialpocdict.copy()
alldict.update(tmpdict)
tmpdict = poc_class.hardwarepocdict.copy()
alldict.update(tmpdict)
cprint(FLAGLET, "cyan")
for key, value in rangedict.items():
poclist.append(value)
for pocfuck in poclist:
for keyword in alldict.values():
if keyword.__str__().find(pocfuck) is not -1:
break
sys.stdout.write("\033[1;35m[+] 加载poc: ["+keyword.__module__+"]\033[0m\n")
sys.stdout.write("\033[1;35m[+] 发送payload..\033[0m\n")
sys.stdout.write("\033[1;35m[+] 正在攻击.."+target+"\033[0m\n")
sys.stdout.flush()
keyword.run()
else:
pass
elif sys.argv[1] == "-m" and sys.argv[3] == "-e":
targetfile = sys.argv[2].strip()
targetfile = targetfile.replace("_BaseVerify","")
#收集扫描文件路径
tmppath = list()
fullpath = list()
curpath = os.getcwd()
for dirpath, dirnames, filenames in os.walk(curpath):
for file in filenames:
if "__pycache__" not in dirpath and "__init__" not in file and ".pyc" not in file:
tmppath = os.path.join(dirpath, file)
if tmppath.strip() not in fullpath:
fullpath.append(tmppath)
for selectpath in fullpath:
if targetfile in selectpath:
break
ret = os.system("vim "+selectpath)
if ret == 0:
cprint("文件:"+targetfile+"======>编辑成功!", "green")
else:
cprint("文件:"+targetfile+"======>编辑失败!", "red")
elif sys.argv[1] == "-v":
poc_class = pocdb_pocs("")
informationpocs = len(poc_class.informationpocdict)
cmspocs = len(poc_class.cmspocdict)
systempocs = len(poc_class.systempocdict)
industrialpocs = len(poc_class.industrialpocdict)
hardwarepocs = len(poc_class.hardwarepocdict)
total = cmspocs + systempocs + industrialpocs + hardwarepocs + informationpocs
flag = FLAGLET+'''
%s
漏洞poc统计
'''%VERSION
cprint(flag, "green")
cprint("|-------------------------------------|","green")
cprint("| Information漏洞POC个数: "+str(informationpocs), "green")
cprint("| CMS漏洞POC个数: "+str(cmspocs), "green")
cprint("| SYSTEM漏洞POC个数: "+str(systempocs), "green")
cprint("| Industrial漏洞POC个数: "+str(industrialpocs), "green")
cprint("| HardWare漏洞POC个数: "+str(hardwarepocs), "green")
cprint("| 总漏洞POC个数: "+str(total), "green")
cprint("| 扫描器线程个数: "+str(threads_num), "green")
cprint("|-------------------------------------|","green")
elif sys.argv[1] == "-c":
os.system('find ../AngelSword -type d -name "*pycache*" | xargs rm -rvf > /dev/null')
os.system('find ../AngelSword -type f -name "*pyc*" | xargs rm -rvf > /dev/null')
fullpoc = list()
tmppath = list()
fullpath = list()
curpath = os.getcwd()
for dirpath, dirnames, filenames in os.walk(curpath):
for file in filenames:
if "__pycache__" not in dirpath and "__init__" not in file and ".pyc" not in file and "DS_Store" not in file and ".txt" not in file and ".xml" not in file and "AngelSword.py" not in file and "pocdb.py" not in file and "main.py" not in file:
tmppath = os.path.join(dirpath, file)
if tmppath.strip() not in fullpath:
fullpath.append(tmppath)
with open("pocdb.py") as f:
for line in f.readlines():
line = line.strip()
if line.find("BaseVerify") is not -1:
line = line.split(":")
linepoc = line[1].replace("_BaseVerify(url),", "")
fullpoc.append(linepoc)
cprint(">>>执行poc路径校验判断...", "cyan")
for singlepoc in fullpoc:
for singlepath in fullpath:
if singlepoc in singlepath:
fullpath.remove(singlepath)
for tmppath in fullpath:
if ".git" not in tmppath:
cprint("[-]"+tmppath, "red")
else:
AngelSwordMain(sys.argv[1])