3

I inspect a HTTPS WebSocket traffic with Mitmproxy. Currently I can read/edit WS messages with:

class Intercept:
    def websocket_message(self, flow):
        print(flow.messages[-1])

def start():
    return Intercept()

.. as attached script to Mitmproxy.

How do I push/inject my own message to the client? Not edit existing one, but add a new message.

Alexey
  • 2,582
  • 3
  • 13
  • 31

1 Answers1

1

You can do this with inject.websocket:

from mitmproxy import ctx

class Intercept:
    def websocket_message(self, flow):
        print(flow.messages[-1])
        to_client = True
        ctx.master.commands.call("inject.websocket", flow, to_client, b"Hello World!", True)

def start():
    return Intercept()

There are more examples in the documentation.

HellaMad
  • 5,294
  • 6
  • 31
  • 53