Forge and replay single TCP packets with mitmproxy

874 Views Asked by At

I discovered mitmproxy and would like to use it to simulate a replay attack.

The application uses MTProto on top of TCP, and I would like to replay entire MTProto messages.

My idea:

  1. Route traffic from client to server over a proxy
  2. Sniff all TCP packets
  3. Replay single TCP packets

The last part is the difficult part. The forged TCP packet must

  • increase the sequence number,
  • recompute the checksum

in order to get accepted.

I tried to use mitmproxy for this, but I only found out how to copy the entire flow, but not single packets.

Is it possible to achieve my goal with mitmproxy? If so, how to forge a single packet? Otherwise: Are there better tools for this attack?

1

There are 1 best solutions below

0
Theova On

The following add-on does the job for me solution (similar in spirit to Susanka):

class Replayer:
    def __init__(self):
        self.num = 0
        self.saved = None

    def tcp_message(self, flow):
        message = flow.messages[-1]
        if len(str(message)) > 700:
            if self.saved is None:
                self.saved = message.content
            else:
                message.content = self.saved
                self.saved = None


addons = [
    Replayer()
]