首页 > 解决方案 > 带有 https 的 Python mitmproxy

问题描述

我正在尝试使用 python 创建一个 mitmproxy 脚本,以将请求从一台主机重定向到另一台主机。我在 http 上取得了一些成功,但在 https 上却做不到。我在文档或任何地方都找不到。我的意思是,我会接受使用其他选项或库来做到这一点,但我不想使用完整的应用程序,比如下载 xampp 或其他 apache 服务器。

from mitmproxy.options import Options
from mitmproxy.proxy.config import ProxyConfig
from mitmproxy.proxy.server import ProxyServer
from mitmproxy.tools.dump import DumpMaster
import os, sys, re, datetime, json

class Addon(object):
def __init__(self):
    pass

def request(self, flow):
    # examine request here
    if flow.request.host == 'testserver.net':
        flow.request.host = 'mynewserver.com'
        print('New try ---> Bypassing.')

def response(self, flow):
    # examine response here
    pass


if __name__ == "__main__":

options = Options(listen_host='0.0.0.0', listen_port=8080, certs=['*=mitmproxy.pem'])
m = DumpMaster(options, with_termlog=False, with_dumper=False)
config = ProxyConfig(options)

m.server = ProxyServer(config)
m.addons.add(Addon())

try:
    print('Redirection active.')
    m.run()
except KeyboardInterrupt:
    m.shutdown()

标签: pythonpython-3.xmitmproxy

解决方案


推荐阅读