Search code examples
pythonwindowspacketpython-sockets

Catch received packets before Windows processes them


I'm trying to catch packets that I receive on Windows 10, before Windows could process them, and modify them.

How actually I can do it?

Some thoughts -

  1. Create windows network adapter, that will be connected like: ( my real network adapter - new adapter - internet )
  2. Get response to some opened socket, receive there packet, decrypt it, and then somehow make google chrome process it.

to catch packets on this new adapter, modify them, and then send them to real network adapter.

A little bit more info:

Im creating a vpn server ( proxy + encrypted payload )

So, on client , i catch all my trafic "on a fly" modifying them ( encrypt payload ), send it to server, server decrypts packet, and sends it to internet, receives response, encrypts it, and sends it back. The client receives - (for example simple http html response) with encrypted payload. And before windows network stack will receive this packet to process it, i need to decrypt it.


Solution

  • So, found out the answer.

    To achieve, what i was trying to do you can use Pydivert - https://pypi.org/project/pydivert/ Using it, you can stop inbound and outbound packets and modify them, before they will be processed by Windows network stack.