Skip to content

Commit

Permalink
修改默认请求头配置
Browse files Browse the repository at this point in the history
  • Loading branch information
winezer0 committed Aug 3, 2023
1 parent bc08b0e commit f7b5dc3
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 26 deletions.
23 changes: 15 additions & 8 deletions libs/lib_args/input_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

from libs.lib_args.input_basic import extract_heads
from libs.lib_file_operate.file_path import get_sub_dirs
from libs.lib_log_print.logger_printer import output, LOG_ERROR
from libs.lib_log_print.logger_printer import *
from libs.lib_args.input_const import *
from libs.lib_requests.requests_const import HTTP_USER_AGENTS
from libs.lib_requests.requests_utils import random_useragent, random_x_forwarded_for
from libs.lib_requests.requests_utils import random_ua, random_xff


def args_parser(config_dict):
Expand Down Expand Up @@ -153,12 +153,19 @@ def config_dict_handle(config_dict):
update_dict[GB_DICT_RULE_SCAN] = config_dict[GB_DICT_RULE_SCAN]

# HTTP 头设置
config_dict[GB_REQ_HEADERS] = {
'User-Agent': random_useragent(HTTP_USER_AGENTS, config_dict[GB_RANDOM_UA]),
'X_FORWARDED_FOR': random_x_forwarded_for(config_dict[GB_RANDOM_XFF]),
'Accept-Encoding': ''
}
update_dict[GB_REQ_HEADERS] = config_dict[GB_REQ_HEADERS]
update_headers = {}

if config_dict[GB_RANDOM_UA]:
update_headers['User-Agent'] = random_ua()

if config_dict[GB_RANDOM_XFF]:
tmp = config_dict[GB_RANDOM_XFF]
update_headers['X-Forwarded-For'] = tmp if isinstance(tmp, str) else random_xff()

if update_headers:
# setdefault方法可用于设置字典中的键值对,如果键不存在,则添加该键。以下是一个简化的示例:
config_dict.setdefault(GB_REQ_HEADERS, {}).update(update_headers)
update_dict.setdefault(GB_REQ_HEADERS, {}).update(update_headers)
return update_dict


Expand Down
20 changes: 7 additions & 13 deletions libs/lib_requests/requests_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,16 @@ def random_str(length=12, num=False, char=False, capital=False, symbol=False, do


# 随机生成User-Agent
def random_useragent(user_agents, condition=False):
if condition:
return random.choice(user_agents)
else:
return user_agents[0]
def random_ua():
return random.choice(HTTP_USER_AGENTS)


# 随机X-Forwarded-For,动态IP
def random_x_forwarded_for(condition=False):
if condition:
return '%d.%d.%d.%d' % (random.randint(1, 254),
random.randint(1, 254),
random.randint(1, 254),
random.randint(1, 254))
else:
return '127.0.0.1'
def random_xff():
return '%d.%d.%d.%d' % (random.randint(1, 254),
random.randint(1, 254),
random.randint(1, 254),
random.randint(1, 254))


# 访问结果处理
Expand Down
2 changes: 1 addition & 1 deletion setting_com.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def init_common(config):
config[GB_RUN_TIME] = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())
##################################################################
# 版本号配置
config[GB_VERSION] = "Ver 0.6.3 2023-07-31 12:30"
config[GB_VERSION] = "Ver 0.6.4 2023-08-03 12:30"
##################################################################
# 是否显示DEBUG级别信息,默认False
config[GB_DEBUG_FLAG] = False
Expand Down
22 changes: 18 additions & 4 deletions setting_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def init_custom(config):
config[GB_TASK_CHUNK_SIZE] = config[GB_THREADS_COUNT]
##################################################################
# 默认请求方法
config[GB_REQ_METHOD] = "head" # 使用get等方法需要进行全下载,会卡顿
config[GB_REQ_METHOD] = "HEAD" # 使用get等方法需要进行全下载,会卡顿
# 默认请求数据
config[GB_REQ_BODY] = None
# 对外请求代理
Expand All @@ -30,9 +30,7 @@ def init_custom(config):
# "https": "https://192.168.88.1:8080",
# "http": "socks5://192.168.88.1:1080",
}
# 默认请求头配置
config[GB_REQ_HEADERS] = {}
##################################################################

# 采用流模式访问 流模式能够解决大文件读取问题
config[GB_STREAM_MODE] = True
# 是否开启https服务器的证书校验
Expand All @@ -44,6 +42,22 @@ def init_custom(config):
# 访问没有结果时,自动重试的最大次数
config[GB_RETRY_TIMES] = 3
##################################################################
# 默认请求头配置
config[GB_REQ_HEADERS] = {
# 'Host': 'testphp.vulnweb.com', # 默认会自动添加请求HOST
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9',
'Cache-Control': 'max-age=0',
'Content-Type': 'application/x-www-form-urlencoded',
# 'Origin': 'http://www.baidu.com/', # 默认会自动添加请求URL
# 'Referer': 'http://www.baidu.com/', # 默认会自动添加请求URL
# 'Upgrade-Insecure-Requests': '1',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 Edg/115.0.1901.188',
'Transfer-Encoding': 'identity', # 多个请求头综合影响响应头CL的获取
'Connection': 'close',
}
##################################################################
# 是否自动根据URL设置动态HOST头
config[GB_DYNA_REQ_HOST] = True
# 是否自动根据URL设置动态refer头
Expand Down

0 comments on commit f7b5dc3

Please sign in to comment.