好用的mitmproxy代理抓包

安装证书

浏览器输入 `mitm.it`

下载证书有时候打不开,可能是起的服务卡死了,回车下命令行,再再网页刷新下载证书就可以了。
mitmweb

使用python来操作抓到的包

此功能才是mitmproxy真正强大的地方,查看文章使用mitmproxy + python 做拦截代理后半部分。
mitmweb -s addons.py

Chrome浏览器代理设置

好用的mitmproxy代理抓包_第1张图片

打开的话,记得保存点一下
好用的mitmproxy代理抓包_第2张图片

官方示例

修改request的请求host
添加请求header
添加响应header

修改返回body为json格式

from mitmproxy import ctx
from mitmproxy import http
import json
class Counter:
    def __init__(self):
        self.num = 0

    def request(self, flow: http.HTTPFlow):
        ctx.log.info("orgin url is: %s" % flow.request.url)
        body = {"a": "b"}
        if flow.request.pretty_url == "https://api.merckuwifi.net/v3/homes":
            flow.response = http.HTTPResponse.make(
                200,  # (optional) status code
                json.dumps(body),  # 这里需要转化为str后才能发送
                {"Content-Type": "application/json"}  # (optional) headers
         )

addons = [Counter()]

startwith

if flow.request.pretty_url.startswith("https://noc.merckuwifi.net/api/statistics/routers/trend"):
        ......

正则匹配url

参考资料

  1. App爬虫神器mitmproxy和mitmdump的使用
  2. 安装
  3. 官方文档
  4. 官方示例
  5. 这里有一点写界面的
  6. 使用mitmproxy + python 做拦截代理

你可能感兴趣的:(好用的mitmproxy代理抓包)