mitmproxy使用

安装

1
pip install mitmproxy

安装完就用 mitmproxymitmdumpmitmweb 三个命令可以使用

mitmproxy 主要是以控制台的方式交互

mitmdump 主要是以命令行的方式交互

mitmweb 以web形式交互

使用

以mitmweb 使用为例,浏览器会打开8081端口,程序监听端口5000

1
mitmweb -p 5000

start标签下

search是搜索 highlight高这 intercept拦截(这个写可以加断点

加完断点后可以画笔修改请求和响应

运行浏览器

进到浏览器目录

1
**chrome.exe --proxy-server=127.0.0.1:8080 --ignore-certificate-errors**

使用代码控制

1
mitmweb -p 5000 -s test.py

test.py (修改请求和响应)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from mitmproxy import ctx

class Counter(object):
def __init__(self) -> None:
self.num = 0

def request(self, flow):
# self.num = self.num + 1
# ctx.log.info("{} flows".format(str(self.num)))
if flow.request.host != "www.baidu.com":
return
# 修改查询参数
flow.request.query.set_all("wd", ["最帅的人"])



def response(self, flow):
# self.num = self.num + 1
# flow.response.headers["count"] = str(self.num)
text = flow.response.get_text()
text = text.replace("最帅的人","最帅的人 xxxx")
flow.response.set_text(text)
addons = [
Counter()
]
作者

建指所向

发布于

2021-12-24

更新于

2023-11-07

许可协议