import mitmproxy.http from mitmproxy import ctx from mitmproxy import flowfilter import json class Interceptor: def __init__(self): # 添加网址过滤器 self.filter = flowfilter.parse("~u https://httpbin.org") def request(self, flow: mitmproxy.http.HTTPFlow): if flowfilter.match(self.filter, flow): ctx.log.info("match request") # 替换搜索词 flow.request.query["wd"] = "富婆通讯录" def response(self, flow: mitmproxy.http.HTTPFlow): if flowfilter.match(self.filter, flow): ctx.log.info("match response") # 添加/修改headers flow.response.headers["md5"] = "00112233445566778899AABBCCDDEEFF" # flow.response.content = bytes("想啥呢",encoding='utf8') data = flow.response.text js = json.loads(data) js['data'] = 'test' flow.response.text = json.dumps(js) # # def request(flow: http.HTTPFlow) -> None: # if flow.request.method == "CONNECT": # # If the decision is done by domain, one could also modify the server address here. # # We do it after CONNECT here to have the request data available as well. # return # client_ip = flow.client_conn.address[0] # if 'ip.cn' in flow.request.url: # ctx.log.info(flow.request.url) # proxy = ("localhost", 8888) # else: # proxy = ("localhost", 3800) # # 这里配置二级代理的ip地址和端口 # if flow.live: # flow.live.change_upstream_proxy_server(proxy) addons = [ Interceptor() ]
mitmproxy拦截接口
最新推荐文章于 2024-07-23 16:23:28 发布