|« What the world thinks of techies||Adding custom fields codes to a Word document »|
Building redir (redir.c) from patched sourcesJune 22nd, 2010
There is a really handy utility for Un*x called: redir (redir.c). It is a user level program that does port redirection. It’s really handy if you want a quick and dirty way of making traffic on one port on your machine point to another port on another machine. I’ve used this technique to by-pass firewalls and bounce traffic through places it’s not supposed to go.
I could have used iptables or ipchains, but these require root access which you might not have. Under Un*x you need root privileges to open a port numbered less than 1000 but most of the time you are re-routing normal application services like Oracle Forms and jInitiator which opens a gazillion ports to various machines to do application server stuff.
Also using iptables or ipchains is so final, not to mention fiddly to set up! Besides another reason to use redir is that the program can be modified to allow you to watch or collect the traffic, which could be infinitely more useful
Unfortunately, redir is no longer in a standard distro so it has to be built from scratch. The program itself hasn’t changed for about 10 years so it is only available in source and patched source. I’m going to describe below how to download, patch and build the redir application.
- Create a working folder and go into it.
- Go to http://redir.sourcearchive.com/ and find the latest version.
- At the time of writing this article the latest version is 2.2.1-9. Download those components.
- Check the integrity of the downloads with md5sum and compare them against the values listed in the *.dsc file
md5sum redir_2.2.1-9.diff.gz redir_2.2.1.orig.tar.gz
- Uncompress the sources.
tar -xvzf redir_2.2.1.orig.tar.gz
- The first patch expects the files to be in different places, so shift things around a little to make it match up, don’t worry about the mv/subdirectory warning.
mv redir-2.2.1 redir-2.2.1.orig
mv redir-2.2.1.orig/* redir-2.2.1.orig/debian
- Now apply the patch.
patch -p0 -i redir_2.2.1-9.diff
- There’s no dpatch on Plesk so we will have to apply the patches by hand using the normal patch command. Change to the main source folder.
- The patches must be applied in order so list them out and build a patch script.
ls patches/[0-9][0-9]_* | sed ’s/^/patch -i &/’ > do.patch
- Then run them all.
- Now that we have applied all the patches, we must clean and build.
Now we’ll test it. The following command listens to port 12345 and relays all connections to port 22 (on the same machine). So by talking to port 12345 we are actually talking to our SSH service listening on port 22.
- Launch the port redirector service in the background.
./redir –lport=12345 –cport=22 &
- Connect to the service.
ssh -D 12345 localhost
- Log in and then log out.
- Kill service.
Feedback awaiting moderation
This post has 1 feedback awaiting moderation...