Setting second proxy for libmproxy

Hello, I’m trying to set up libmproxy (it’s easier to debug and it’s better for my purpose) with a second proxy server

initiation code looks like:

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):
    if in_scope(flow):
        proceed_request(flow)
        print flow.request.content
        print flow

    if FAIL_REPORT_URL not in flow.request.url:
        flow.reply()
    else:
        print "EVIL REQUEST"
        print flow

def handle_response(self, flow):
    in_scope(flow)
    flow.reply()

config = proxy.ProxyConfig(port=8084, mode=“upstream”, upstream_server=“192.168.0.99:8085”)
server = ProxyServer(config)
m = StickyMaster(server)
m.run()

and I’m getting such error:

mitmproxy has crashed!
Please lodge a bug report at: https://github.com/mitmproxy/mitmproxy
Traceback (most recent call last):
File “/usr/lib/python2.7/dist-packages/libmproxy/proxy/server.py”, line 110, in handle
self.establish_server_connection()
File “/usr/lib/python2.7/dist-packages/libmproxy/proxy/server.py”, line 208, in establish_server_connection
self.server_conn.connect()
File “/usr/lib/python2.7/dist-packages/libmproxy/proxy/connection.py”, line 148, in connect
tcp.TCPClient.connect(self)
File “/usr/lib/python2.7/dist-packages/netlib/tcp.py”, line 538, in connect
connection.connect(self.address())
File “/usr/lib/python2.7/socket.py”, line 224, in meth
return getattr(self._sock,name)(*args)
TypeError: getsockaddrarg() takes exactly 2 arguments (15 given)

Could you please explain how should i start libMProxy for using custom scripts with another proxy server?
Thanks for help.

Hi,

It looks like you are using a very outdated version of mitmproxy. You should update! :slight_smile:

Thx, i’ve updated mitm proxy, had some problems with system.

Would be great if you could help me with these questions:

  1. I’ve tried to find in code methods where events callback from inline scripts (from this documentation https://mitmproxy.org/doc/scripting/inlinescripts.html are called), to import them and use, and i didn’t find.
    Could you please help me to do it? I mean something like import request from somewhere so it would be called on event.

  2. Could you please also advise what method to import to override proxy start and configure it from script, like stickyMaster from old version?

Thank you.

See here. To be clear, this is quite nontrivial Python code.

May I ask what’s your use case for this? We’re currently in the process of adding a better support for config files.

This is still krockssb, but i forgot account.

Thank you for answering first question, I’ll try it once more with a right place now.[quote=“mhils, post:4, topic:414”]
May I ask what’s your use case for this? We’re currently in the process of adding a better support for config files.
[/quote]

Main idea is to set few proxies with different separate tasks independent from each other, e.g. auth, traffic modifying, traffic analyse, etc. And also something like a burpsuite for easy viewing and work.

So i’m trying to find out how to work with to of these things (settings, and callbacks) from one place in code, so simplifying. For now, i couldn’t handled it.