Coder Social home page Coder Social logo

utoni / ptunnel-ng Goto Github PK

View Code? Open in Web Editor NEW
357.0 9.0 66.0 733 KB

Tunnel TCP connections through ICMP.

License: BSD 3-Clause "New" or "Revised" License

Makefile 0.93% Shell 2.52% M4 3.84% C 79.60% Roff 3.45% HTML 9.50% Dockerfile 0.15%
tunnel icmp ptunnel pingtunnel icmptunnel ping ptunnel-ng

ptunnel-ng's Introduction

Coverity Status Total alerts Codacy Badge GitHub issues GitHub license Gitter chat Packaging status

PingTunnel-[N]ew[G]eneration Read Me

What is ptunnel-ng?

Ptunnel-NG is a bugfixed and refactored version of Ptunnel with some additional
features e.g. change the magic value without recompiling.

What is 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.

Simple usage

Opens a SSH over ICMP tunnel to a remote.

Server:

sudo ptunnel-ng

Client:

sudo ptunnel-ng -p[Server-IP/NAME] -l2222

ssh -p2222 -luser 127.0.0.1

Restricted usage

Opens a SSH over ICMP tunnel to a remote but restricts destination IP/Port for tunnel clients. 10.0.3.1 is the machine your SSH daemon listens on. This can be a virtual machine, container or (.*).

Server:

sudo ptunnel-ng -r10.0.3.1 -R22

Client:

sudo ptunnel-ng -p[Server-IP/NAME] -l2222 -r10.0.3.1 -R22

ssh -p2222 -luser 127.0.0.1

Reverse shell usage

Opens a SSH over ICMP tunnel to a remote and creates a reverse tunnel on same but restricts destination IP/Port for tunnel clients. 10.0.3.1 is the machine your SSH daemon listens on. This can be a virtual machine, container or (.*).

Server:

sudo ptunnel-ng -r10.0.3.1 -R22

Client:

sudo ./src/ptunnel-ng -p[Server-IP/NAME] -l2222 -r10.0.3.1 -R22

ssh -R 127.0.0.1:22222 127.0.0.1 -p2222

Server:

ssh -p22222 -luser 127.0.0.1

How does it work?

ICMP Packet structure

Ptunnel Packet Structure

Ptunnel program setup

Ptunnel Setup

Contact details

The ptunnel-ng fork was done by Toni Uhlig:
   <[email protected]>
You can contact the author of ptunnel, Daniel Stoedle, here:
   <[email protected]>
The official ptunnel website is located here:
   <http://www.cs.uit.no/~daniels/PingTunnel/>

Dependencies

Required: pthread
Optional: pcap, selinux

Compiling

Either run "./autogen.sh" for a fully automatic build or run it manually with:
    "./configure && make"

You should end up with a binary called ptunnel-ng.
This serves as both the client and proxy. You can
optionally install it using "make install".
To compile the Windows binary. You will need mingw installed.
If you want pcap support you will need the WinPcap library as well.
WinPcap is available here:
  <http://www.winpcap.org/install/bin/WpdPack_4_0_2.zip>

REMEMBER: ptunnel-ng might not work on Windows without WinPcap!

Running

Ptunnel works best when starting as root, and usually requires starting as root.
Common ptunnel-ng options:

Proxy(Server):
	./ptunnel-ng -r<destination address> -R<destination port> -v <loglevel>
	             -P<password> -u<user> -g<group>

Forwarder(Client):
	./ptunnel-ng -p <address> -l <listen port> -r<destination address>
	             -R<destination port> -v <loglevel>
	             -P<password> -u<user> -g<group>

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.
If pinging works but you are not able to establish a tunnel, you should play
around with the -m switch and change the magic value. A IDS/IPS or Firwall
might try to fool you.

The -l, -r and -R 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 proxy.pingtunnel.com to the computer
login.domain.com, the following command line would be used:

sudo ./ptunnel-ng -p proxy.pingtunnel.com -l 8000 -r login.domain.com -R 22

An ssh connection to login.domain.com 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-ng 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 proxy.pingtunnel.com here). Doing this is very
simple:

sudo ./ptunnel-ng

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 -L 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 -P 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-ng. -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 -o switch allows output to be saved to a logfile.

Security features: Please see the ptunnel-ng man-page for instructions.

Supported operating systems

Ptunnel supports most operating systems with libpcap, the usual POSIX functions
and a BSD sockets compatible API. In particular, it has been tested on Linux
Fedora Core 2 and Mac OS X 10.3.6 and above. As of version 0.7, ptunnel-ng can also
be compiled on Windows, courtesy of Mike Miller, assuming mingw and WinPcap is
installed.

TODOs

- refactoring
- libsodium integration

Credits and contributors

Daniel Stoedle et al.

License

Ping Tunnel NG is Copyright (c) 2017-2019, Toni Uhlig <[email protected]>,
All rights reserved. Ping Tunnel NG is licensed under the
BSD License. Please see the COPYING file for details.

ptunnel-ng's People

Contributors

ehaupt avatar elnerd avatar emreoyun avatar masaq- avatar oofnikj avatar utoni avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ptunnel-ng's Issues

Binary?

For Windows?
Where to download?

Reverse SSH possible?

Hello, I've stumbled across your enhanced version and it looks good thanks! I was wonder if there is a way to do a reverse ssh tunnel via this tool?

I want to be able to reach the system behind the firewall that only allows icmp.

Thanks so much!

Centos 7

Im having a hard time getting this to run on fedora or centos. are there other dependencies that i need to get this to work?

/dev/random does not have enough enthropy

In my VPS, the pt_random call in utils.c fails with "FATAL: Read only 2 bytes (wanted 4 bytes)". The server handles this as a fatal error and dies. This is due to read call not blocking and returning earlier.

This is a problem, because in VPS and other low-enthropy devices such as routers, this means anybody can issue a DoS by opening connections and crashing it due to lack of enthropy.

I see two possible solutions:

  • Changing from using the Unix read call into fread which is blocking.
  • Making /dev/urandom the default, so users don't see their servers suddenly aborting

I would probably prefer the second, since:

  • A 4-byte integer can't be considered by any means cryptographically safe, and thus for non-crypto /dev/urandom would do fine.
  • By not blocking, server should be snappier and prevent DoS by emptying the random enthropy pool

Cryptographic issues

FYI, in case you want to know, I've been glazing through the current cryptography a tiny bit, and I've found at least the following issues:

  1. Data is not authenticated, thus you can use somebody else's session after he has authenticated with the proxy.
  2. The forwader does not validate the server. This means you can use a MitM to get a session to the proxy. This could be fixed by doing a three-way authentication in which the client also requests sends the server a challange and checks it after having authenticated itself.
  3. The forwarder can be used as an oracle: since the client does not add any random value to the challange, a MitM could get the password hashed with any salt the attacker could want, and use that for authenticating itself against the real server.
  4. The password is not properly derivated using a password-stretching function. Bruteforcing a MD5, or even a SHA512-hashed password is relatively easy and quick.

For 1 you could add an IV to every packet, and then HMAC-ing the data. For 2 and 3, I'd recommend to get some ideas from existing private-key authentication sequences, such as the three-way authentication Mifare Ultralight C NFC tags use (see 7.5.5). For 4, I'd recommend using PBKDF2, scrypt, Argon, or another well-known password-stretching functions.

Doing cryptography is really hard, and having a false sense of security is even worse than having no security at all. Thus in my opinion, I would recommend that you remove all existing authentication, and lock down the functionality to forwarding to a fixed service, and let it handle all the authentication+encryption. This would be the easiest route for you.

If you want to keep the ability to connect to several services, you may want instead to add an IP whitelist (such as only letting connecting to ocserv, SSH, OpenVPN, etc... and let them do the crypto)

Compiler warning of undefined behaviour: pointer arithmetics on null pointers

When building ptunnel-ng on macOS 12.3.1/x86_64, there are warnings output:

./autogen.sh
[…]
[…]
test -z "" || rm -f
rm -f *.o
make[1]: Nothing to be done for `clean-am'.
-> make -j4 all
Making all in src
/Applications/Xcode.app/Contents/Developer/usr/bin/make  all-am
  CC       ptunnel_ng-options.o
  CC       ptunnel_ng-challenge.o
  CC       ptunnel_ng-md5.o
  CC       ptunnel_ng-utils.o
md5.c:164:18: warning: performing pointer subtraction with a null pointer has undefined behavior [-Wnull-pointer-subtraction]
            if (!((data - (const md5_byte_t *)0) & 3)) {
                        ^ ~~~~~~~~~~~~~~~~~~~~~
  CC       ptunnel_ng-pkt.o
  CC       ptunnel_ng-pdesc.o
1 warning generated.
  CC       ptunnel_ng-ptunnel.o
  CCLD     ptunnel-ng
make[1]: Nothing to be done for `all-am'.

Compiler:

configure:3992: checking for C compiler version
configure:4001: gcc --version >&5
Apple clang version 13.1.6 (clang-1316.0.21.2.3)
Target: x86_64-apple-darwin21.4.0
Thread model: posix

Investigate/Fix Cryptographic issues

As mentioned by @cdpxe in #16:
Some important points has to be investigated and fixed (see: https://onlinelibrary.wiley.com/doi/full/10.1002/sec.1471):

  1. Sniffing of header/payload: The payload is usually SSH/VPN/stunnel based and encrypted. But it is still possible to do a payload or timing analysis to detect the encapsulated protocol. Also the header is not encrypted and therefor can leak important data to middleboxes.
  2. Man-in-the-middle attack: Data send/recv is neither authenticated nor integrity checked - header/payload data can be modified ad libitum. The client/server has no chance to discover such cases.

latest autogen.sh not working

└─# ./autogen.sh
++ pwd

  • OLD_WD=/home/halfluke/Downloads/ptunnel-ng
    ++ dirname ./autogen.sh
  • NEW_WD=.
  • cd .
  • autoreconf -fi
    ./autogen.sh: line 10: autoreconf: command not found
  • aclocal
    ./autogen.sh: line 11: aclocal: command not found
  • autoheader
    ./autogen.sh: line 12: autoheader: command not found
  • automake --force-missing --add-missing
    ./autogen.sh: line 13: automake: command not found
  • autoconf
    ./autogen.sh: line 14: autoconf: command not found
  • cd /home/halfluke/Downloads/ptunnel-ng
  • ./configure
    ./autogen.sh: line 19: ./configure: No such file or directory

The one from src under Releases works instead. No more configure in the latest git, everything moved to Docker only?

Reconnect about every minute

Thanks for this great piece of software.
I'm using the reverse SSH Tunnel solution. It works great. However about every minute connection closes and gets re-established. Any idea whats wrong here? The server runs an a Amazon AWS free contingent machine.

debug1: remote forward success for: listen 0.0.0.0:11111, connect 127.0.0.1:22
debug1: All remote forwarding requests processed
debug1: channel 0: free: port listener, nchannels 1
Connection to 127.0.0.1 closed by remote host.
Transferred: sent 2376, received 2224 bytes, in 24.8 seconds
Bytes per second: sent 95.8, received 89.7
debug1: Exit status -1
debug1: remote forward success for: listen 0.0.0.0:11111, connect 127.0.0.1:22
debug1: All remote forwarding requests processed
Bad packet length 1660391029.
ssh_dispatch_run_fatal: Connection to 127.0.0.1 port 2222: Connection corrupted
debug1: All remote forwarding requests processed
Bad packet length 141349867.
ssh_dispatch_run_fatal: Connection to 127.0.0.1 port 2222: Connection corrupted
debug1: remote forward success for: listen 0.0.0.0:11111, connect 127.0.0.1:22
debug1: All remote forwarding requests processed
Timeout, server 127.0.0.1 not responding.

-L --libpcap (default: eth0)

needs an option to enumerate Windows WinPcap devices.
like the original ptunnel

(c) 2004-2005 Daniel Stoedle, [email protected]
[inf]: HINT: start ptunnel with "-h" parameter to view help and Windows WinPcap devices

Example: use the Windows device \Device\NPF_{86AAB447-88AE-404D-86CB-D7E7A909B9BE}:

Infinitely hangs with "Resending packet"

Fresh install, both server and client are running Gentoo. This issue occurs in both Stoedle's original ptunnel and ptunnel-ng.

Client command line: sudo src/ptunnel-ng -p <ADDRESS_WITH_PTUNNEL> -r<ADDRESS_WITH_SSH> -R<PORT> -l8000 -v4

Server command line: src/ptunnel-ng -v4

Client log:

[inf]: Starting ptunnel-ng 1.31.                                                                                                                       
[inf]: (c) 2004-2011 Daniel Stoedle, <[email protected]>                                                                                               
[inf]: (c) 2017      Toni Uhlig,     <[email protected]>                                                                                         
[inf]: Security features by Sebastien Raveau, <[email protected]>                                                                              
[inf]: Relaying packets from incoming TCP streams.                                                                                                     
[dbg]: Destination at danne.site:3446                                                                                                                  
[dbg]: Listen for incoming connections at 0.0.0.0:8000                                                                                                 
[dbg]: Starting forwarder..                                                                                                                            
[vbs]: Proxy IP address: 45.33.77.119                                                                                                                  
[inf]: Incoming connection.                                                                                                                            
[evt]: No running proxy thread - starting it.                                                                                                          
[dbg]: [dbg]: Adding proxy desc to run loop. Type is user. Will create socket: No                                                                      
Starting ping proxy..                                                                                                                                  
[dbg]: Attempting to create privileged ICMP raw socket..                                                                                               
[inf]: Ping proxy is listening in privileged mode.                                                                                                     
[inf]: Dropping privileges now.                                                                                                                        
[vbs]: Sending proxy request.                                                                                                                          
[dbg]: Resending packet with seq-no 0.                                                                                                                 
[dbg]: Resending packet with seq-no 0.                                                                                                                 
[dbg]: Resending packet with seq-no 0.                                                                                                                 
[dbg]: Resending packet with seq-no 0.                                                                                                                 
[dbg]: Resending packet with seq-no 0.                                                                                                                 
[dbg]: Resending packet with seq-no 0.                                                                                                                 
[dbg]: Resending packet with seq-no 0.                                                                                                                 
[dbg]: Resending packet with seq-no 0.                                                                                                                 
[dbg]: Resending packet with seq-no 0.                                                                                                                 
[dbg]: Resending packet with seq-no 0.                                                                                                                 
[dbg]: Resending packet with seq-no 0.                                                                                                                 
[dbg]: Resending packet with seq-no 0.                                                                                                                 
[dbg]: Resending packet with seq-no 0.                                                                                                                 
[dbg]: Resending packet with seq-no 0.

Server log:

[inf]: Starting ptunnel-ng 1.31.                
[inf]: (c) 2004-2011 Daniel Stoedle, <[email protected]>
[inf]: (c) 2017      Toni Uhlig,     <[email protected]>
[inf]: Security features by Sebastien Raveau, <[email protected]>
[inf]: Forwarding incoming ping packets over TCP.
[dbg]: Destination at 127.0.0.1:22              
[dbg]: Starting ping proxy..                    
[dbg]: Attempting to create privileged ICMP raw socket..
[inf]: Ping proxy is listening in privileged mode.
[inf]: Dropping privileges now.                 
[inf]: Incoming tunnel request from 104.230.254.210.
[inf]: Starting new session to 173.255.212.191:3446 with ID 24348
[dbg]: Adding proxy desc to run loop. Type is proxy. Will create socket: Yes
[dbg]: Received ack-series starting at seq 65535
[err]: Dropping duplicate proxy session request.
[dbg]: Received ack-series starting at seq 65535
[dbg]: Resending packet with seq-no 0.          
[dbg]: Received ack-series starting at seq 65535
[err]: Dropping duplicate proxy session request.
[dbg]: Received ack-series starting at seq 65535
[dbg]: Received ack-series starting at seq 65535                               
[dbg]: Resending packet with seq-no 0.          
[dbg]: Received ack-series starting at seq 65535
[err]: Dropping duplicate proxy session request.    
[dbg]: Received ack-series starting at seq 65535                 
[dbg]: Resending packet with seq-no 0.                                      
[dbg]: Received ack-series starting at seq 65535
[err]: Dropping duplicate proxy session request.
[dbg]: Received ack-series starting at seq 65535
[dbg]: Received ack-series starting at seq 65535
[dbg]: Resending packet with seq-no 0.
[dbg]: Received ack-series starting at seq 65535
[err]: Dropping duplicate proxy session request.
[dbg]: Received ack-series starting at seq 65535
[dbg]: Resending packet with seq-no 0.
[dbg]: Received ack-series starting at seq 65535
[err]: Dropping duplicate proxy session request.
[dbg]: Received ack-series starting at seq 65535
[dbg]: Received ack-series starting at seq 65535
[dbg]: Resending packet with seq-no 0.
[dbg]: Received ack-series starting at seq 65535
[err]: Dropping duplicate proxy session request.
[dbg]: Received ack-series starting at seq 65535
[dbg]: Resending packet with seq-no 0.
[dbg]: Received ack-series starting at seq 65535
[err]: Dropping duplicate proxy session request.
[dbg]: Received ack-series starting at seq 65535
[dbg]: Received ack-series starting at seq 65535
[dbg]: Resending packet with seq-no 0.

Ask for help of compiling.

when I was entering the command "./configure.ac", I got this error:
./configure.ac: line 1: syntax error near unexpected token 2.69' ./configure.ac: line 1: AC_PREREQ(2.69)'

but the the version of autoconf is 2.69-11

could somebody help me?
how could I get rid of this error?

Npcap support

WinPcap Has Ceased Development
The WinPcap project has ceased development and WinPcap and WinDump are no longer maintained. We recommend using Npcap instead.

but actually ptunnel-ng does not work with npcap

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.