python - 带有 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()
解决方案
推荐阅读
- javascript - 如何从 getDataRange() 中排除标题行?
- java - 如何创建一个接受字符和字符串并返回该字符在字符串中的索引的函数
- sql - SQL - 搜索大型数据集的快速方法
- sql-server - 为什么某些 DATABASE_ROLE_MEMBER_CHANGE_GROUP 审计事件会触发,而其他则不会?
- azure - 无法将调试器从 VS 2017 附加到 Azure App Service for Web App Bot
- ruby - 我们可以通过铲子方法将项目和数量添加到列表中并在类之外调用该列表吗?
- c - 使用 free() 会破坏 C 中的 char 数组数据
- unit-testing - 如何测试 GenServer 重启行为?
- python - argparse 采用 int & string?
- terraform - 如何使 terraform 跳过破坏资源?