python - Mitmproxy使用python加载和卸载脚本

标签 python concurrency proxy mitmproxy libmproxy

我正在按照 Mitmproxy github examples 中的建议运行代理:

from libmproxy import proxy, flow

class MitmProxy(flow.FlowMaster):
    def run(self):
        try:
            flow.FlowMaster.run(self)
        except KeyboardInterrupt:
            self.shutdown()

  
    def handle_request(self, r):
        f = flow.FlowMaster.handle_request(self, r)

        if f:
            r.reply()
        return f

    def handle_response(self, r):
        f = flow.FlowMaster.handle_response(self, r)
 
        if f:
            r.reply()
        return f



config = proxy.ProxyConfig(
    cacert = os.path.expanduser("~/.ssl/mitmproxy.pem")
)
state = flow.State()
server = proxy.ProxyServer(config, 8083)
m = MitmProxy(server, state)
try:
    m.run()
except Exception, e:
    print e.message
    m.shutdown()

我想处理每个请求/响应而不阻塞其他请求/响应, 为此,我需要使用并发装饰器和脚本

我的问题是:如何向在此配置中运行的代理加载和卸载脚本?

最佳答案

您可以使用并发模式加载脚本。
这是一个example对于这种用法

我更喜欢在流级别实现 mitmproxy 逻辑。
您可以使用此代码

def handle_response(self, r):
    reply = f.response.reply
        f.response.reply = controller.DummyReply()
        if hasattr(reply, "q"):
            f.response.reply.q = reply.q
        def run(): 
            pass
        threading.Thread(target=run)

关于python - Mitmproxy使用python加载和卸载脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24156723/

相关文章:

python - 如何在子进程 Popen 中引用工作区中的文件?

python - 在Python中将十六进制字符串转换为十六进制数字而不损失精度

java - 线程转储显示不正确的线程状态

java - 在 Java 6 中实现多生产者/消费者模式的最佳方式

apache - mod_rewrite 不作为内部代理工作

Python 多处理 : How do I keep it within the specified function?

python - 从包含某些关键字的列表中删除多个字符串元素

multithreading - 为什么 ManualResetEvent 无法在使用 Silverlight 4 的此同步调用中工作?

ruby - 如何从 Watir-Webdriver 更改 Opera 的代理设置?

python - 在 python 脚本中使用代理后面的 git