Skip to content

Commit

Permalink
Update Hunting-Rabbit-DirScanner.py
Browse files Browse the repository at this point in the history
修复Bug,新增记录txt
  • Loading branch information
langsasec authored May 14, 2024
1 parent ee40838 commit 48018a8
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions Hunting-Rabbit-DirScanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import argparse
import random
import sys
import threading
import time

Expand All @@ -27,14 +28,15 @@ def read_dir(url, dict_name):
for file_path in file_paths:
with open(file_path, 'r', encoding='utf-8') as f:
lines = f.readlines()
print(lines)
if url is not None:
words.extend([url + "/" + x.strip() for x in lines])
else:
dict_name = dict_name.split(',')
for name in dict_name:
with open(f"dict/{name}.txt", 'r', encoding="utf-8") as f:
lines = f.readlines()
if url is not None:
if url:
words.extend([url + "/" + x.strip() for x in lines])
return set(words)

Expand Down Expand Up @@ -120,17 +122,18 @@ def Random_UserAgents():

def execute_threads(thread_num, worker):
threads = []
for i in range(thread_num):
t = threading.Thread(target=worker, args=(i,))
t.daemon = True # 设置线程为守护线程,当主线程退出时,所有守护线程会立即停止
threads.append(t)
t.start()
stop_event = threading.Event()
try:
while True:
time.sleep(1)
for i in range(thread_num):
t = threading.Thread(target=worker, args=(i, stop_event,))
threads.append(t)
t.start()
except KeyboardInterrupt:
print('Ctrl+C pressed. Terminating all child threads, Please wait...')
pass
stop_event.set()
finally:
for t in threads:
t.join() # 等待所有线程结束


def dir_scan(url, use_random_ua, timeout, status_code_filter="200"):
Expand All @@ -144,6 +147,8 @@ def dir_scan(url, use_random_ua, timeout, status_code_filter="200"):
if line:
key, value = line.split(': ', 1)
headers[key] = value
else:
pass
if use_random_ua:
headers["User-Agent"] = Random_UserAgents()
else:
Expand Down Expand Up @@ -173,6 +178,7 @@ def scan_log(name, result):
name = name.replace("://", "-")
name = name.replace("/", "-")
log_file = f"log/{name}.html"
result_file = f"log/{name}.txt"
template_str = """
<!DOCTYPE html>
<html>
Expand Down Expand Up @@ -357,6 +363,10 @@ def scan_log(name, result):
template = Template(template_str)
output = template.render(result=result)

with open(result_file, 'w', encoding='utf-8') as f:
for i in result:
f.write(i[0]+'\n')

with open(log_file, 'w', encoding='utf-8') as f:
f.write(output)

Expand Down Expand Up @@ -386,18 +396,18 @@ def scan_log(name, result):
result = []


def worker(i):
while words:
def worker(i, stop_event):
while words and not stop_event.is_set():
word = words.pop()
info = dir_scan(word, use_random_ua, timeout, status_code_filter)
if info is None:
pass
else:
if info:
result.append(info)
else:
pass


execute_threads(thread_num, worker)
if result == []:
if not result:
print("[-] No result!")
else:
scan_log(url, result)
Expand Down

0 comments on commit 48018a8

Please sign in to comment.