Tuesday, February 19, 2019

Proxy Transparent Forwarding packets?

So I’ve got a question. I’m working on a TCP proxy right now. What is expected is that:

  • General: A host will send tcp packets to said proxy and the proxy then forwards it to its intended destination.

  • Point: when the proxy gets traffic from a host, an action needs to be triggered (this I have done already, but with hard coded IPs)

I’m using sockets in Python so socket AF_INET, SOCK_STREAM. What I don’t understand is how the proxy gets the packets IF the packets are destined for their real destination address? If an unknowing host sends packets out to their destination say 1.3, how would the proxy pick up / get those packets and then forward them to 1.3 on behalf of the host? If the packet’s destination was 1.3, how would a proxy who’s source is 1.1 get those packets??

Right now I have a basic tcp client/server and the proxy server.

What I want to do is from the client, send tcp packets to the server without the client having knowledge of the proxy. If I want to go to a web server hosted on the client on a port, I just type in the ip:port of the server. The proxy gets that traffic and forwards it to the server.

What I have right now is send the data to the proxy and then have the proxy hardcoded to send to the server. In my example above I have the client connecting to a port on the proxy, and the proxy sends the data to the web server. All destination IPs are hard coded.

So in that example, what if there’s 2 web servers (A & B)? If I have a host trying to connect to Server A and I send that data to the proxy’s addresses, how does the proxy know if the data is destined for Webserver A or B? (Since the dst address coming from the client is that of the webserver?) the goal is to have the client just type in the address of webserver A (packets dst of webserver A), that data being sent to the proxy, and the proxy sending it to webserver A.

(note: this is for ALL tcp traffic, not just web traffic)

TLDR; How does a proxy receive packets that are not initially destined for it and then forward them to their real destination?

Also: if anyone knows how to do this in python or an easy enough process I’d love to hear it!

Thanks for the help!



No comments:

Post a Comment