Skip to content

Commit

Permalink
v0.5.2
Browse files Browse the repository at this point in the history
1、新增命中结果动态排除功能。自动排除相同响应的命中结果
2、重新设计命令行参数与全局变量的关系。
3、修复http代理错误的问题(burpsuite代理情况下错误)。不管是https还是http网站,都使用http代理。
  • Loading branch information
winezer0 committed Jun 30, 2023
1 parent b40d4ea commit 1ef6b7e
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 61 deletions.
8 changes: 7 additions & 1 deletion DynaScan.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ def dyna_scan_controller(target_urls, paths_dict, config_dict):

# 统计本目标的总访问错误次数
access_fail_count = 0

# 记录已命中结果的特征信息,用于过滤已命中的结果
hit_info_hash_list = []

# 循环多线程请求操作
for sub_task_index, sub_task_list in enumerate(brute_task_list):
output(f"[*] 任务进度 {sub_task_index + 1}/{len(brute_task_list)}", level=LOG_INFO)
Expand Down Expand Up @@ -294,7 +298,9 @@ def dyna_scan_controller(target_urls, paths_dict, config_dict):
exclude_status_list=config_dict[GB_EXCLUDE_STATUS],
exclude_title_regexp=config_dict[GB_EXCLUDE_REGEXP],
max_error_num=config_dict[GB_MAX_ERROR_NUM],
hit_saving_field=HTTP_CONST_SIGN
hit_saving_field=HTTP_CONST_SIGN,
hit_info_exclude=config_dict[GB_HIT_INFO_EXCLUDE],
hit_info_hash_list=hit_info_hash_list
)

# 写入命中结果
Expand Down
4 changes: 3 additions & 1 deletion libs/input_const.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
GB_MAX_URL_NUM = "GB_MAX_URL_NUM"
GB_MAX_ERROR_NUM = "GB_MAX_ERROR_NUM"

# HTTP请求相关
# 命中结果动态排除开关
GB_HIT_INFO_EXCLUDE = "GB_HIT_INFO_EXCLUDE"

# HTTP请求相关
GB_DEFAULT_PROTO = "GB_DEFAULT_PROTO"

GB_PROXIES = "GB_PROXIES"
Expand Down
4 changes: 2 additions & 2 deletions libs/lib_requests/requests_plus.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import time
import urllib
from binascii import b2a_hex
from urllib.parse import urlparse
from urllib.parse import urlparse, urljoin

import chardet
import requests
Expand Down Expand Up @@ -60,7 +60,7 @@ def requests_plus(req_url,

# 需要动态添加refer字段
if add_refer_header:
req_headers["Referer"] = req_url
req_headers["Referer"] = urljoin(req_url, "./")

# 设置需要接受的参数的默认值 #如果返回结果是默认值,说明程序异常没有获取到
resp_status = HTTP_DEFAULT_RESP_DICT[HTTP_RESP_STATUS] # 响应状态码 赋值默认值 NUM_MINUS
Expand Down
60 changes: 54 additions & 6 deletions libs/lib_requests/requests_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# 获得随机字符串
import copy
import hashlib
import random
import re

Expand Down Expand Up @@ -82,12 +83,45 @@ def analysis_dict_same_keys(result_dict_list, default_value_dict, filter_ignore_
output(f"[*] 所有DICT [{key}] 值 [{value}] 相等 且不为默认或空值 [{default_value_dict[key]}]")
same_key_value_dict[key] = value
else:
output(f"[-] 所有DICT [{key}] 值 [{value}] 相等 但是默认或空值 [{default_value_dict[key]}]", level=LOG_DEBUG)
output(f"[-] 所有DICT [{key}] 值 [{value}] 相等 但是默认或空值 [{default_value_dict[key]}]",
level=LOG_DEBUG)
else:
output(f"[!] 存在未预期的键{key},该键不在默认值字典[{list(default_value_dict.keys())}]内!!!", level=LOG_ERROR)
return same_key_value_dict


def calc_dict_info_hash(resp_dict):
# 固化响应结果的hash特征
# output(f"[*] calc_dict_info_hash: {resp_dict}", level=LOG_ERROR)
# return str(resp_dict)

# 对字典的键值对进行排序
sorted_items = sorted(resp_dict.items())
# 创建 哈希对象
hash_object = hashlib.md5()
# 更新哈希对象的输入数据
hash_object.update(str(sorted_items).encode())
# 计算哈希值
hash_value = hash_object.hexdigest()
return hash_value


def copy_dict_remove_keys(resp_dict, remove_keys=None):
# 移除响应字典中和URL相关的选项, 仅保留响应部分
# {'HTTP_REQ_URL': 'https://www.baidu.com/home.rar', # 需要排除
# 'HTTP_CONST_SIGN': 'https://www.baidu.com/home.rar', # 需要排除
# 'HTTP_RESP_REDIRECT_URL': 'HTTP_RAW_REDIRECT_URL'} # 可选排除
# 保留原始dict数据
copy_resp_dict = copy.copy(resp_dict)
if remove_keys is None:
remove_keys = [HTTP_REQ_URL, HTTP_CONST_SIGN]
for remove_key in remove_keys:
# copy_resp_dict[remove_key] = "" # 清空指定键的值
copy_resp_dict.pop(remove_key, "") # 删除指定键并返回其对应的值 # 删除不存在的键时,指定默认值,不会引发异常
# output(f"[*] 新的字典键数量:{len(copy_resp_dict.keys())}, 原始字典键数量:{len(resp_dict.keys())}", level=LOG_DEBUG)
return copy_resp_dict


# 访问结果处理
def access_result_handle(result_dict_list,
dynamic_exclude_dict=None,
Expand All @@ -100,12 +134,17 @@ def access_result_handle(result_dict_list,
max_error_num=None,
history_field=HTTP_CONST_SIGN,
hit_saving_field=HTTP_CONST_SIGN,
):
hit_info_exclude=False,
hit_info_hash_list=None):
# 兼容旧版本 记录已命中结果的特征信息,用于过滤已命中的结果
if hit_info_hash_list is None:
hit_info_hash_list = []

# 错误结果超出阈值
should_stop_run = False

# 访问失败的结果 # 就是除去URL和SING之外都是默认值
access_fail_resp_dict = copy.copy(HTTP_DEFAULT_RESP_DICT)
access_fail_resp_dict = copy_dict_remove_keys(HTTP_DEFAULT_RESP_DICT)

# 本次扫描的所有命中结果 默认保存的是 请求响应的 CONST_SIGN 属性
hit_result_list = []
Expand All @@ -116,10 +155,8 @@ def access_result_handle(result_dict_list,
IGNORE_RESP = False

# 判断请求是否错误(排除url和const_sign)
access_fail_resp_dict[HTTP_CONST_SIGN] = access_resp_dict[HTTP_CONST_SIGN]
access_fail_resp_dict[HTTP_REQ_URL] = access_resp_dict[HTTP_REQ_URL]
# 字典可以直接使用 == 运算符进行比较,要求 字典中的键必须是可哈希的(即不可变类型)
if not IGNORE_RESP and access_resp_dict == access_fail_resp_dict:
if not IGNORE_RESP and access_fail_resp_dict == copy_dict_remove_keys(access_resp_dict):
access_fail_count += 1
IGNORE_RESP = True

Expand All @@ -145,6 +182,16 @@ def access_result_handle(result_dict_list,
else:
IGNORE_RESP = True

# 计算结果hash并判断是否是已命中结果
if hit_info_exclude and not IGNORE_RESP:
hit_info_hash = calc_dict_info_hash(copy_dict_remove_keys(access_resp_dict))
if hit_info_hash in hit_info_hash_list:
output(f"[!] 忽略命中 [{hit_info_hash}] <--> {access_resp_dict[HTTP_REQ_URL]}", level=LOG_ERROR)
IGNORE_RESP = True
else:
# output(f"[!] 保留命中 [{hit_info_hash}]", level=LOG_INFO)
hit_info_hash_list.append(hit_info_hash)

# 写入结果格式
result_format = "\"%s\"," * len(access_resp_dict.keys()) + "\n"
# 当前需要保存和显示的字段
Expand All @@ -153,6 +200,7 @@ def access_result_handle(result_dict_list,
key_order_list = list(access_resp_dict.keys())
key_order_list.sort() # 按字母排序
access_resp_values = tuple([access_resp_dict[key] for key in key_order_list])

if IGNORE_RESP:
# 写入结果表头
write_title(ignore_file, result_format % tuple(key_order_list), encoding="utf-8", new_line=True, mode="a+")
Expand Down
Loading

0 comments on commit 1ef6b7e

Please sign in to comment.