Access Network When Everything Else is Blocked Using ptunnel

Ptunnel is an application that allows you to reliably tunnel TCP connections to a remote host using ICMP echo request and reply packets, commonly known as ping requests and replies. At first glance, this might seem like a rather useless thing to do, but it can actually come in handy in some cases. The following example illustrates the main motivation in creating ptunnel:

Setting: You’re on the go, and stumble across an open wireless network. The network gives you an IP address, but won’t let you send TCP or UDP packets out to the rest of the internet, for instance to check your mail. What to do? By chance, you discover that the network will allow you to ping any computer on the rest of the internet. With ptunnel, you can utilize this feature to check your mail, or do other things that require TCP.

Ptunnel Features

Ptunnel is not a feature-rich tool by any means, but it does what it advertises. So here is what it can do:

Tunnel TCP using ICMP echo request and reply packets
Connections are reliable (lost packets are resent as necessary)
Handles multiple connections
Acceptable bandwidth (150 kb/s downstream and about 50 kb/s upstream are the currently measured maximas for one tunnel, but with tweaking this can be improved further)
Authentication, to prevent just anyone from using your proxy

Install Ptunnel in Debian

First you need to edit /etc/apt/sources.list file

#vi /etc/apt/sources.list

add the following lines

deb binary/
deb-src source/

Update the source list using the following command

#apt-get update

Install ptunnel using the following command

#apt-get install ptunnel

Using ptunnel


./ptunnel -p [proxy address] -lp [listen port] -da [destination address] -dp [destination port] [-c network device] [-v verbosity] [-f logfile] [-u] [-x password]


./ptunnel [-c network device] [-v verbosity] [-f logfile] [-u] [-x password]

The -p switch sets the address of the host on which the proxy is running. A quick test to see if the proxy will work is simply to try pinging this host – if you get replies, you should be able to make the tunnel work.

The -lp, -da and -dp switches set the local listening port, destination address and destination port. For instance, to tunnel ssh connections from the client machine via a proxy running on to the computer, the following command line would be used:

sudo ./ptunnel -p -lp 8000 -da -dp 22

An ssh connection to can now be established as follows:

ssh -p 8000 localhost

If ssh complains about potential man-in-the-middle attacks, simply remove the offending key from the known_hosts file. The warning/error is expected if you have previously ssh’d to your local computer (i.e., ssh localhost), or you have used ptunnel to forward ssh connections to different hosts.

Of course, for all of this to work, you need to start the proxy on your proxy-computer (we’ll call it here). Doing this is very simple:

sudo ./ptunnel

If you find that the proxy isn’t working, you will need to enable packet capturing on the main network device. Currently this device is assumed to be an ethernet-device (i.e., ethernet or wireless). Packet capturing is enabled by giving the -c switch, and supplying the device name to capture packets on (for instance eth0 or en1). The same goes for the client. On versions of Mac OS X prior to 10.4 (Tiger), packet capturing must always be enabled (both for proxy and client), as resent packets won’t be received otherwise.

To protect yourself from others using your proxy, you can protect access to it with a password using the -x switch. The password is never sent in the clear, but keep in mind that it may be visible from tools like top or ps, which can display the command line used to start an application.

Finally, the -u switch will attempt to run the proxy in unprivileged mode (i.e., no need for root access), and the -v switch controls the amount of output from ptunnel. -1 indicates no output, 0 shows errors only, 1 shows info messages, 2 gives more output, 3 provides even more output, level 4 displays debug info and level 5 displays absolutely everything, including the nasty details of sends and receives. The -f switch allows output to be saved to a logfile.

Sponsored Link

3 thoughts on “Access Network When Everything Else is Blocked Using ptunnel

Leave a comment

Your email address will not be published. Required fields are marked *