-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNucleiAPI.py
62 lines (48 loc) · 1.58 KB
/
NucleiAPI.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
# -*- coding: utf-8 -*-
"""
@Tine: 2023/8/27 16:27
@Author: muddlelife
@File: NucleiAPI
@Description: Ncueli API调用
"""
import subprocess
import datetime
def time_stamp():
"""时间戳"""
current_datetime = datetime.datetime.now()
return current_datetime.strftime("%Y-%m-%d %H:%M:%S")
def parse_data(process):
stdout, stderr = process.communicate()
result = []
try:
info = stdout.decode().split('\n')[0:-1]
for i in info:
tmp = i[1:]
a = tmp.split('] [')
b = a[2].split('] ')
item = {
"vulnerability": a[0],
"severity": b[0],
"poc_url": b[-1]
}
result.append(item)
except Exception as e:
print(e)
return result
class NucleiAPI:
"""封装NucleiAPI"""
def __init__(self):
self.startup = 'nuclei -duc -stream -silent -nc'
def scan(self, url, template_id):
"""指定模版ID进行扫描"""
result = {'url': url, 'template_id': template_id}
process = subprocess.Popen('{} -u {} -id {}'.format(self.startup, url, template_id), shell=True,
stdout=subprocess.PIPE, close_fds=True, stdin=subprocess.PIPE,
stderr=subprocess.PIPE)
scan_result = parse_data(process)
result['data'] = scan_result
result['time_stamp'] = time_stamp()
return result
if __name__ == '__main__':
result = NucleiAPI().scan('http://106.52.50.243:8000', 'kingdee-k3cloud-arbitrary-file-read')
print(result)