Bridging Networks in Pure Python
Every now and then I find myself in a situation where the tools at hand are inappropriate, impeded, or impotent for the task at hand. Whether I am on a machine with insufficient privileges, behind a vindictive NAT, or under the opression of significant egress filtering, from time to time I find myself needing to bridge networks in order to get my work done.
There are various ways to do this, the most popular usually involves either netcat or socat. When these tools are unavailable, I usually resort to a different technique which can be executed purely in Python. What follows are two snippets that I use to route traffic as I see fit.
The first snippent is from my bridge server. This will run on a machine I control, on a port that I am able to access, both from my target server and from the client.
From there, we build a reverse connection from the target server. This will connect our target service to the bridge we previously built.
In the theorhetical example above, pointing a MySQL client at the bridge server's port 8080 will route us to the MySQL database running on the bridge client's local network. A simple demonstration of a otherwise difficult task; this technique has helped me out in a number of different situations.
I hope you find this as useful as I do,
Motoma
comments powered by Disqus