mitmdump

- -q:屏蔽mitmdump默认的控制台日志,只显示自己脚本中的
- -s:入口脚本文件
- -p:更改端口,默认为8080
- 修改脚本文件时,不用重启也会生效
针对 HTTP 生命周期的事件
- 请求:def request(self, flow: mitmproxy.http.HTTPFlow):
- 响应:def response(self, flow: mitmproxy.http.HTTPFlow):
- 其它:
- def http_connect(self, flow: mitmproxy.http.HTTPFlow):
- def requestheaders(self, flow: mitmproxy.http.HTTPFlow):
- def responseheaders(self, flow: mitmproxy.http.HTTPFlow):
- def error(self, flow: mitmproxy.http.HTTPFlow):
请求:def request(flow:flow)
- flow.request.headers
- 获取所有头信息,包含Host、User-Agent、Content-type等字段
- flow.request.url
- 完整的请求地址,包含域名及请求参数,但是不包含放在body里面的请求参数
- flow.request.host
- flow.request.method
- flow.request.scheme
- flow.request.path
- flow.request.get_text()
- 请求中body的内容,有一些http会把请求参数放在body里面,可通过此方法获取,返回字典类型
- flow.request.get_content()
- 结果如flow.request.get_text(),返回bytes类型
- flow.request.raw_content
- 结果如flow.request.get_content(),返回bytes类型
- flow.request.urlencoded_form
- MultiDictView,content-type:application/x-www-form-urlencoded的请求参数,不包含url直接带的键值参数
- flow.request.multipart_form
- MultiDictView,content-type:multipart/form-data
- flow.request.query
- 返回MultiDictView类型的数据,URL的键值参数
- flow.request.query.get('wd')
- flow.request.query.keys()
- flow.request.query.set_all(key,[value])
from mitmproxy.http import flow
def request(flow:flow):
if 'https://www.baidu.com' in flow.request.url:
print(list(flow.request.query.keys()))
flow.request.query.set_all('wd',['python'])
print(flow.request.query.get('wd'))
响应:def response(flow: flow)
- flow.response.status_code
- flow.response.text
- flow.response.content
- flow.response.get_text()
- flow.response.set_text()
- flow.response = flow.response.make(404)
from mitmproxy.http import flow
import json
import re
def response(flow: flow):
targetUrl = 'https://g.alicdn.com/AWSC/uab/122.js'
if targetUrl in flow.request.url:
taobao_js =flow.response.get_text()
taobao_js = taobao_js.replace('!function(){function','!function (){Object.defineProperties(navigator,{webdriver: {get: () => false}})function')
flow.response.set_text(taobao_js)
print('已修改')
if 'https://s.taobao.com/search' in flow.request.url:
start = flow.response.text.strip().index('{')
end = -2
print(json.loads(flow.response.text.strip()[start: end])['mods']['itemlist']['data']['auctions'])
if 'https://www.aqistudy.cn/historydata/monthdata.php' in flow.request.url:
js = flow.response.text
js = re.sub(r'endebug.*?}\);','',js,flags=re.S)
flow.response.set_text(js)
print('已正常')
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· AI与.NET技术实操系列(六):基于图像分类模型对图像进行分类