-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathengine.py
executable file
·102 lines (83 loc) · 2.4 KB
/
engine.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
# -*- coding:utf-8 -*-
#!/usr/bin/env python3
#Description: wukong exploit
#Author: Bing
#DateTime: 2017-05-10 23:08:39
import gevent, time, os, imp, socket, psutil
from multiprocessing import Process
from gevent import monkey; monkey.patch_all()
from utils.func import *
def launcher(poc_file, target):
taskid = target["scan_taskid"]
host = target["scan_target"]
model = target["model"]
plugin_name = target["plugin_name"]
plugin_file = target["plugin_file"]
program_log({
"taskid" : taskid,
"model" : model,
"plugin_name" : plugin_name,
"status" : 1,
"info" : "poc running"
})
try:
poc_class = imp.load_source('wk', poc_file )
t = poc_class.wk(target = target)
t.exploit()
result = t.result
program_result(taskid, host, model, plugin_name, result)
program_log({
"taskid" : taskid,
"model" : model,
"plugin_name" : plugin_name,
"status" : 2,
"info" : "poc finishing"
})
except Exception as e:
message = e.__str__()
program_log({
"taskid" : taskid,
"model" : model,
"plugin_name" : plugin_name,
"status" : 3,
"info" : message
})
def custom_scan(scan_model, num = 5):
while True:
scan_que = get_task("{0}".format(scan_model), num)
if len(scan_que) > 0 :
jobs = []
for target in scan_que:
taskid = target["scan_taskid"]
model = target["model"]
plugin_name = target["plugin_name"]
plugins = target["plugin_file"].split('-')[1]
poc_file = get_poc_path(plugins)
if poc_file :
jobs.append(gevent.spawn(launcher, poc_file, target))
else:
program_log({
"taskid" : taskid,
"model" : model,
"plugin_name" : plugin_name,
"status" : 3,
"info" : "no poc"
})
gevent.joinall(jobs)
else:
system_log({ "status" : 1, "model" : "{0}".format(scan_model), "info" : "waitting task"})
time.sleep(5)
if __name__ == '__main__':
print( 'Run task %s (%s)...' % ("wk scanner engine", os.getpid()) )
start = time.time()
#开启多个服务模块
func_list = [("third", 200,), ("brute", 200,), ("poc", 200,)]
work = []
for poc_args in func_list :
p = Process(target = custom_scan, args=poc_args )
p.start()
work.append(p)
for job in work:
job.join()
end = time.time()
print( 'Task %s runs %0.2f seconds.' % ("wk scanner engine", (end - start)) )