Repository navigation
Expand file tree
/
Copy pathmultiScan.py
More file actions
92 lines (82 loc) · 2.68 KB
/
Copy pathmultiScan.py
File metadata and controls
92 lines (82 loc) · 2.68 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
import threading
import sys
import os
from oneforall import OneForAll
from config.log import logger
from datetime import datetime
class MyThread(threading.Thread):
def __init__( self, targets: list, outputPath: str):
self.targets = targets
self.outputPath = outputPath
threading.Thread.__init__( self )
def oneforall(self, domain):
global fileLock
# 1. 关闭控制台打印信息
sys.stdout = open(os.devnull, 'w')
sys.stderr = open(os.devnull, 'w')
logger.remove(handler_id=None)
# 2. 开始扫描子域名
test = OneForAll(target=domain)
test.dns = True
test.brute = True
test.req = True
test.run()
datas = test.datas
# 3. 保存扫描结果
fileLock.acquire()
with open(self.outputPath, "a+") as f:
tmp = set()
f.write(f"# {domain} 子域名收集结果: \n")
for data in datas:
subdomain = data.get('subdomain')
if data.get('alive'):
if subdomain not in tmp:
tmp.add(subdomain)
f.write(subdomain+'\n')
fileLock.release()
# 4. 打开控制台输出信息
sys.stdout = sys.__stdout__
sys.stdout = sys.__stderr__
def run(self):
global targetsLock
while self.targets:
print(f"剩余 {len(self.targets)} 个未扫描域名")
target = None
targetsLock.acquire()
if self.targets:
target = self.targets.pop()
targetsLock.release()
if target:
self.oneforall(target)
if "__main__" == __name__:
targetsLock = threading.Lock()
fileLock = threading.Lock()
ThreadList = []
Targets = None
# 线程数
ThreadNum = 16
# 扫描的开始时间
startTime = datetime.now()
# 待扫描的域名
targetsPath = "targets.txt"
# 扫描结果的输出文件
outputPath = "results.txt"
try:
# 获取扫描目标
with open(targetsPath, "r") as fp:
Targets = fp.read().split('\n')
# print(Targets)
# 创建多线程扫描任务
for i in range(ThreadNum):
t = MyThread(Targets, outputPath)
ThreadList.append(t)
for t in ThreadList:
t.start()
for t in ThreadList:
t.join()
except Exception:
pass
finally:
sys.stdout = sys.__stdout__
sys.stdout = sys.__stderr__
print(f"运行时间 {(datetime.now()-startTime).seconds} 秒")