Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Routing all packets through my program?

I want to build an application that routes all network traffic (not just HTTP) through my application. Basically, what I want is all the traffic to be given to my application (they should never reach the actual target, my application should handle this), which will in turn be forwarded to a server; same goes for input, just reversed (server -> application -> program which wants an answer). Are there any libraries (or similar stuff) that would make creating the application easier? I'm looking for something that I can use from Python or Java, but if it's really needed, I can learn another language.

like image 784
Bogdacutu Avatar asked Jan 10 '12 18:01

Bogdacutu


3 Answers

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

However things like these are ussually implemented at the low level ideally using C, Here is a tutorial Tutorial

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

While you are at it you also might want to take a look at netfilter hooks

like image 65
anijhaw Avatar answered Nov 14 '22 21:11

anijhaw


Have a look at Jpcap.

like image 23
mindas Avatar answered Nov 14 '22 21:11

mindas


If you want to route only tcp traffic is actually kind of simple using threads and sockets. You should listen in a different port for every server you want to reach. Either in Java or Python you have to create a "socket" for every port you want to listen in.

For every new connection you create a new connection to the server and create two new threads to handle that connection, one thread will be reading everything from the client and sending it to the server. The other will be reading everything from the server and sending it to the client. When any end of the connection closes it, you close the other and end both threads.

like image 1
pmoleri Avatar answered Nov 14 '22 21:11

pmoleri