Routing all packages through my program?

I want to create an application that directs all network traffic (not just HTTP) through my application. Basically, I want all traffic to be transferred to my application (they should never reach the actual goal, my application should handle this), which, in turn, will be redirected to the server; the same goes for input, just the opposite (server β†’ application β†’ program that wants to get an answer). Are there libraries (or similar materials) that will facilitate the creation of the application? I am looking for something that I can use with Python or Java, but if it is really necessary, I can learn another language.

+4
source share
4 answers

What you want to use is a packet capture library, you can e pcap or its implementation or bindings in python or java.

However, such things are usually implemented at a low level, ideally using C. Here is a tutorial Tutorial

EDIT: in the light of your comments, you definitely want to take a look at netfilter hooks

While you're on it, you can also take a look at netfilter hooks

+4
source

Take a look at Jpcap .

+1
source

If you want to route only tcp traffic, it's really simple using streams and sockets . You must listen on a different port for each server you want to reach. Either in Java or Python, you need to create a "socket" for each port that you want to listen to.

For each new connection, you create a new connection to the server and create two new threads to handle this connection, one stream will read everything from the client and send it to the server. Another will read everything from the server and send it to the client. When either end of the connection closes it, you close the other and terminate both threads.

+1
source

If you do this on Linux, you should consider using a TUN / TAP device, which is a very convenient tool for intercepting network traffic for user processing. Here is the basic tutorial if you are unfamiliar http://backreference.org/2010/03/26/tuntap-interface-tutorial/

0
source

Source: https://habr.com/ru/post/1390289/


All Articles