python - 向 python 添加功能原始请求
问题描述
目前我正在尝试向此代码添加功能以将 HTTP 请求导出为输出文本文件中的原始请求,原始 python 文件
import json
import requests
import arjun.core.config as mem
from arjun.core.utils import populate
from arjun.core.utils import create_query_string
def json_export(result):
"""
exports result to a file in JSON format
"""
with open(mem.var['json_file'], 'w+', encoding='utf8') as json_output:
json.dump(result, json_output, sort_keys=True, indent=4)
def burp_export(result):
"""
exports results to Burp Suite by sending request to Burp proxy
"""
proxies = {
'http': 'http://' + mem.var['burp_port'],
'https': 'http://' + mem.var['burp_port']
}
for url, data in result.items():
if data['method'] == 'GET':
requests.get(url, params=populate(data['params']), headers=data['headers'], proxies=proxies, verify=False)
elif data['method'] == 'POST':
requests.post(url, data=populate(data['params']), headers=data['headers'], proxies=proxies, verify=False)
elif data['method'] == 'JSON':
requests.post(url, json=populate(data['params']), headers=data['headers'], proxies=proxies, verify=False)
def text_export(result):
"""
exports results to a text file, one url per line
"""
with open(mem.var['text_file'], 'w+', encoding='utf8') as text_file:
for url, data in result.items():
clean_url = url.lstrip('/')
if data['method'] == 'JSON':
text_file.write(clean_url + '\t' + json.dumps(populate(data['params'])) + '\n')
else:
query_string = create_query_string(data['params'])
if '?' in clean_url:
query_string = query_string.replace('?', '&', 1)
if data['method'] == 'GET':
text_file.write(clean_url + query_string + '\n')
elif data['method'] == 'POST':
text_file.write(clean_url + '\t' + query_string + '\n')
def exporter(result):
"""
main exporter function that calls other export functions
"""
if mem.var['json_file']:
json_export(result)
if mem.var['text_file']:
text_export(result)
if mem.var['burp_port']:
burp_export(result)
我已评论text_file.write(clean_url + '\t' + query_string + '\n')
并将其替换为
print('{}\n{}\r\n{}\r\n\r\n{}'.format(
result.method + ' ' + result.url,
'\r\n'.join('{}: {}'.format(k, v) for k, v in result.headers.items()),
result.body,
))
将 POST 请求输出增强为原始但我缺少一些错误。任何帮助!
顺便说一句,还有另一个文件作为参数蛮力
解决方案
推荐阅读
- bots - 假装那个电报机器人正在打字?
- woocommerce - WooCommerce 管理员中缺少产品图片
- apache-spark - Spark Hive:临时表在会话中消失
- python - 将 groupby() 的结果放回新的数据框列
- javascript - 从 HTML 周选择器中提取日期
- asynchronous - 如何使托管 bean 等待用户输入 - JSF
- typescript - 导出的枚举/常量在同一文件中未定义
- python - 周期性边界条件下的凸包
- mysql - 如何根据日期时间字段确定的数据子集汇总 MySQL 表中的一些数据?
- vba - 打开 Word 文档时忽略“外部”错误