Search code examples
pythonproxywebsocketmitmproxy

How to ignore all websocket connections with mitmproxy?


At the moment, mitmproxy doesn't seem to be able to handle websocket connections.

How can I just pass these on so that clients can still connect with a websocket server?

Here's my current command:

./mitmproxy --anticache -s injectScripts.py

Specifically, in my case, I'd currently like clients using my proxy to be able to play games on agar.io, which uses a websocket connection to communicate with a (for our purposes, random) server which hosts the game.

Examples of game-hosting servers which agar.io connects to: ws://151.80.96.51:1515, ws://37.187.171.110:1523, ws://37.187.163.130:1518.

I've already tried using mitmproxy's Ignore Domains feature (both from the command line and from within the program), as well as their recommended TCP Proxy feature. This was the pattern I tried using:

./mitmproxy --anticache -s injectScripts.py --ignore ^agar.io$

But this just stops agar.io from loading at all (grey background, correct document title but that's it).

I think that because the client is connecting to different servers (not ws://agar.io) I can't use a simple domain ignore, but I may be wrong.


While at the moment I'm only interested in agar.io, it would be nice to have a solution for all websocket servers.

So, in short, how can I allow clients to connect to ws servers?


Solution

  • If you are using mitmproxy 0.15+, passing --raw-tcp should do the job. This puts all non-HTTP traffic into TCP mode automatically.