What is the equivalent of libmproxy in the new mitmproxy?
Asked Answered
O

2

6

I finally upgraded my Python version from 2.7 to 3.6.1 and with that also upgraded my mitmproxy from the old and good v0.16 to the newest version.

I used to work with libmproxy in order to manipulate the requests that were diverted through the proxy with this syntax:

from netlib.http import decoded
from libmproxy import controller, proxy
from libmproxy.proxy.server import ProxyServer

class StickyMaster(controller.Master):
    def __init__(self, server):
        controller.Master.__init__(self, server)
        self.stickyhosts = {}

    def run(self):
        try:
            return controller.Master.run(self)
        except KeyboardInterrupt:
            self.shutdown()

    def handle_request(self, flow):
        flow.reply()

    def handle_response(self, flow):
        with decoded(flow.response):
            <DO SOMETHING>
        flow.reply()

config = proxy.ProxyConfig(port=8081)
server = ProxyServer(config)
m = StickyMaster(server)
m.run()

I understood that in the new version the syntax is totally different and I can't find a relevant documentation with an example of how to do that right.

Can anybody share with me an example of a basic code such as I wrote above of the newest version?

Otherworld answered 27/4, 2017 at 8:8 Comment(1)
Did you find a solution not to use addons?Refection
S
1

There is no official equivalence, they have abandoned the use of the proxy through a library without the use of commands and additional/external applications.

Sarcenet answered 11/6, 2018 at 1:25 Comment(0)
W
0

We have deprecated the "libmproxy subclassing" approach with a more flexible implementation of addons. In fact, most of mitmproxy's core features are implemented as addons themselves. So the short answer is: Write an addon!

We provide an introduction to addon development at http://docs.mitmproxy.org/en/stable/scripting/overview.html. For code examples, you should also take a look at https://github.com/mitmproxy/mitmproxy/tree/master/examples/simple.

Willner answered 27/4, 2017 at 16:27 Comment(2)
An addon canot satisface all requirements, by example into large python project and automate the bind a proxy server. "Write an addon" is not a valid response, it is not a equivalent, the answer is out of context of the question.Sarcenet
I'm disappointed with this answer. The "libmproxy subclassing" approach allowed for embedding some mitm functionality into my own applications, where as the "Write an addon!" approach would force me to embed the functionality into mitmproxy, and then faff around the subprocess module to control mitm dump or something. The "short answer" comes across as somewhere between "f*#& off" and "All of your apps are belonging to us". "Write an addon!" dismisses rather than answers the question.Radiancy

© 2022 - 2024 — McMap. All rights reserved.