赞
踩
可以对接Python对请求进行处理① 先准备一个py文件如scripts.py:如对请求的改写,定义了一个request()方法,参数为flow(HTTPFlow对象),通过flow.request属性即可获取到当前的请求对象,然后打印输出了请求的请求头,如将请求头的User-Agent修改成了MitmProxy
#scripts.py文件
def request(flow):
flow.request.headers['User-Agent'] = 'MitmProxy'
print(flow.request.headers)
② cmd输入mitmdump -s scripts.py,即指定脚本scripts.py来处理截获的数据;mitmdump -w 文件名(把截获的数据保存到文件中);mitmdump -p 8099 (指定监听端口)
mitmdump -s scripts.py -p 8080
③ scripts.py脚本执行效果:在浏览器和手机分别打开http://httpbin.org/get


mitmdump有专门的日志输出功能,可以设定不同级别以不同颜色输出结果,我们把scripts.py脚本修改成如下内容。主要调用了ctx模块的log功能(warning级别最高)
from mitmproxy import ctx
def request(flow):
flow.request.headers['User-Agent'] = 'MitmProxy'
ctx.log.info(str(flow.request.headers)) # 白色
ctx.log.warn(str(flow.request.headers)) # 黄色
ctx.log.error(str(flow.reuquest.headers)) # 红色
warning级别最高,如控制台打印如下

from mitmproxy import ctx
def request(flow):
request = flow.request
# 如修改url
flow.request.url = 'https:..httpbin.org/get'
info = ctx.log.info
info(str(request.headers))
info(str(request.cookies))
info(request.host)
info(request.method)
info(str(request.port))
info(request.scheme)

from mitmproxy import ctx
def response(flow):
response = flow.response
info = ctx.log.info
info(str(response.status_code))
info(str(response.headers))
info(str(response.cookies))
info(str(response.text))

mitmdump -s scripts.py捕获拦截存储等Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。