ffalcinelli / pydivert

A Python binding for WinDivert driver
GNU Lesser General Public License v3.0
207 stars 36 forks source link

changing GET request in tcp packet #25

Closed newfeeling closed 7 years ago

newfeeling commented 7 years ago

I'm trying to change simple GET request with pydivert (WinDivert for python)

What i seem to encounter is problem with packet lenght. when i rewrite url so it has same amount or less of letters it works: ie. GET /?a=asdf => GET /?a=z

But when i add more letters to the request, browser loops and ends up without showing anything

Below is example code i use

filter = "true and tcp.PayloadLength > 0" with Handle(filter=filter) as handle:

while True:

    packet = handle.receive()

    if packet.payload[0:3]=="GET":
        packet.payload=packet.payload.replace("GET /?a=asdf","GET /?a=gfdsazzz")
    handle.send(packet)

and

<?php echo $_GET['a']; ?> Is there somewhere a MAX packet size setted. If yes then how to increase it?

If that would be a hint for you then if i will print all packets in console then i clearly see that request was responded by server because see packet.payload with gfdsazzz

newfeeling commented 7 years ago

if any PayloadLength changed , the packet send will faild or no respond .

how can I fix it?

ffalcinelli commented 7 years ago

Since you're changing the payload, the whole packet length is changing too, so you should adjust the total packet length property of ip header accordingly. You should also recalculate checksums. Anyway, for this kind of changes I recommend you to redirect the traffic to your own proxy server (just a piece of software written by yourself listening on a socket) and then operate all the changes you want there, otherwise you would worry about sequence numbers, ack, and of course fragmentation due to MTU (which is the MAX packet size you were referring, and it's something that depends on the underlying network layer).