-
Notifications
You must be signed in to change notification settings - Fork 83
/
tasks.py
executable file
·126 lines (98 loc) · 4.21 KB
/
tasks.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
#!/usr/bin/env python
# encoding: utf-8
# tasks.py
# email: ringzero@0x557.org
'''
Thorns Project 分布式任务控制脚本
tasks
-- nmap_dispath # nmap 扫描调度函数
-- hydra_dispath # hydra 暴力破解调度函数
-- medusa_dispath # medusa 暴力破解调度函数
worker run()
--workdir=/home/thorns
'''
import subprocess
from celery import Celery, platforms
# 初始化芹菜对象
app = Celery()
# 允许celery以root权限启动
platforms.C_FORCE_ROOT = True
# 修改celery的全局配置
app.conf.update(
CELERY_IMPORTS = ("tasks", ),
BROKER_URL = 'redis://127.0.0.1:6379/0',
CELERY_RESULT_BACKEND = 'db+mysql://root:123456@127.0.0.1:3306/wscan',
CELERY_TASK_SERIALIZER='json',
CELERY_RESULT_SERIALIZER='json',
CELERY_TIMEZONE='Asia/Shanghai',
CELERY_ENABLE_UTC=True,
CELERY_REDIS_MAX_CONNECTIONS=5000, # Redis 最大连接数
BROKER_TRANSPORT_OPTIONS = {'visibility_timeout': 3600}, # 如果任务没有在 可见性超时 内确认接收,任务会被重新委派给另一个Worker并执行 默认1 hour.
# BROKER_TRANSPORT_OPTIONS = {'fanout_prefix': True}, # 设置一个传输选项来给消息加上前缀
CELERY_ROUTES = {
'tasks.port_dispath':{
'queue':'port'
}
}
)
# 失败任务重启休眠时间300秒,最大重试次数5次
# @app.task(bind=True, default_retry_delay=300, max_retries=5)
@app.task
def nmap_dispath(targets, taskid=None):
# nmap环境参数配置
run_script_path = '/home/liet/code/git/doom'
if taskid == None:
cmdline = 'python wyportmap.py %s' % targets
else:
cmdline = 'python wyportmap.py %s %s' % (targets, taskid)
nmap_proc = subprocess.Popen(cmdline,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
process_output = nmap_proc.stdout.readlines()
return process_output
@app.task
def hydra_dispath(targets, protocol, userdic, passdic, taskid=None):
# 命令执行环境参数配置
run_script_path = '/home/doom/script/hydra'
run_env = '{"LD_LIBRARY_PATH": "/home/doom/libs/"}'
if taskid == None:
cmdline = 'python hydra.py %s %s %s %s' % (target, protocol, userdic, passdic)
else:
cmdline = 'python hydra.py %s %s %s %s %s' % (target, protocol, userdic, passdic, taskid)
nmap_proc = subprocess.Popen(cmdline,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE,cwd=run_script_path,env=run_env)
process_output = nmap_proc.stdout.readlines()
return process_output
@app.task
def port_dispath(address, service, taskid = None):
# 命令执行环境参数配置
run_script_path = '/home/liet/code/git/doom'
#run_env = '{"LD_LIBRARY_PATH": "/home/liet/code/git/doom"}'
if taskid == None:
cmdline = 'python port_check.py %s %s' % (address, service)
else:
cmdline = 'python port_check.py %s %s %s' % (address, service, taskid)
cmd_proc = subprocess.Popen(cmdline,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
process_output = cmd_proc.stdout.readlines()
return process_output
@app.task
def permission_dispath(request, taskid=None):
# 命令执行环境参数配置
run_script_path = '/home/liet/code/git/doom'
#run_env = '{"LD_LIBRARY_PATH": "/home/liet/code/git/doom"}'
if taskid == None:
cmdline = 'python permission_check.py %s' % (request)
else:
cmdline = 'python permission_check.py %s' % (request)
permission_proc = subprocess.Popen(cmdline,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
process_output = permission_proc.stdout.readlines()
return process_output
@app.task
def sqli_dispath(request, taskid=None):
# 命令执行环境参数配置
run_script_path = '/home/liet/code/git/doom'
#run_env = '{"LD_LIBRARY_PATH": "/home/liet/code/git/doom"}'
if taskid == None:
cmdline = 'python sqli_check.py %s' % (request)
else:
cmdline = 'python sqli_check.py %s' % (request)
permission_proc = subprocess.Popen(cmdline,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
process_output = permission_proc.stdout.readlines()
return process_output