10 changed files with 78 additions and 47 deletions
@ -1,37 +1,33 @@ |
|||
import os |
|||
import shlex |
|||
import re |
|||
from tools.ToolBase import ToolBase |
|||
|
|||
class HydraTool(ToolBase): |
|||
def validate_instruction(self, instruction): |
|||
timeout = 0 |
|||
#hydra过滤 |
|||
#hydra -L emails.txt -P passwords.txt pop3://haitutech.cn 像这样针对邮箱爆破,邮箱名不是用户名,需要特殊处理 |
|||
# 分割指令为参数列表 |
|||
cmd_parts = shlex.split(instruction) |
|||
new_cmd = [] |
|||
# 获取当前程序所在目录 |
|||
current_path = os.path.dirname(os.path.realpath(__file__)) |
|||
#new_pass_path = os.path.join(current_path, "payload", "passwords") |
|||
#hydra过滤 需要判断指令中添加字典文件存不存在 |
|||
match_p = re.search(r'-P\s+([^\s]+)', instruction) |
|||
match_l = re.search(r'-L\s+([^\s]+)', instruction) |
|||
if match_p: |
|||
str_p = match_p.group(1) |
|||
#判断文件是否存在 |
|||
if not os.path.exists(str_p): #文件不存在要替换 |
|||
new_pass_path = os.path.join(current_path, "../payload", "passwords") |
|||
instruction = instruction.replace(str_p,new_pass_path) |
|||
if match_l: |
|||
str_l = match_l.group(1) |
|||
#判断文件是否存在 |
|||
if not os.path.exists(str_l): |
|||
new_user_path = os.path.join(current_path, "../payload", "users") |
|||
instruction = instruction.replace(str_l, new_user_path) |
|||
|
|||
i = 0 |
|||
while i < len(cmd_parts): |
|||
part = cmd_parts[i] |
|||
new_cmd.append(part) |
|||
# 检测到-P参数 |
|||
if part == "-P" and i + 1 < len(cmd_parts): #密码 |
|||
# 替换下一参数为指定路径 |
|||
new_cmd.append(new_pass_path) |
|||
i += 1 # 跳过原路径参数 |
|||
elif part == "-L" and i + 1 < len(cmd_parts): #用户名 |
|||
# 替换下一参数为指定路径 |
|||
new_cmd.append(new_user_path) |
|||
i += 1 # 跳过原路径参数 |
|||
i += 1 |
|||
if "-l" in instruction or "-p" in instruction: |
|||
if "-f" not in instruction: |
|||
instruction = instruction + " -f" #当是单密码,或单用户名时,使用成功即停止模式 |
|||
|
|||
return " ".join(shlex.quote(p) for p in new_cmd),timeout |
|||
return instruction,timeout |
|||
|
|||
def analyze_result(self, result,instruction,stderr,stdout): |
|||
#返回结果 |
|||
|
@ -0,0 +1,11 @@ |
|||
from tools.ToolBase import ToolBase |
|||
|
|||
class SmbclientTool(ToolBase): |
|||
def validate_instruction(self, instruction): |
|||
#指令过滤 |
|||
timeout = 0 |
|||
return instruction,timeout |
|||
|
|||
def analyze_result(self, result,instruction,stderr,stdout): |
|||
#指令结果分析 |
|||
return result |
Loading…
Reference in new issue