mitmproxy抓包

cooolr 于 2022-03-30 发布
import urllib3
import logging
import requests
from mitmproxy import http

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(message)s")

def request(flow: http.HTTPFlow) -> None:
    proxy = "http://172.31.237.32:7890"
    headers = {}
    try:
        r = requests.get(flow.request.pretty_url, headers=dict(flow.request.headers), proxies={"http":proxy, "https":proxy}, verify=False)
        for key,value in r.headers.items():
            headers[key.encode()] = value.encode()
    except Exception as e:
        logging.error(e)
    flow.response = http.HTTPResponse.make(r.status_code, r.content, headers.items())
import json
from mitmproxy import http

def response(flow: http.HTTPFlow) -> None:
    if "search/notes?" in flow.request.url:
        notes_list = json.loads(flow.response.text)["data"]["notes"]
proxy = ("127.0.0.1", 7890)
flow.live.change_upstream_proxy_server(proxy)