Tunneling and Port Forwarding
Learn & practice AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Learn & practice GCP Hacking:
HackTricks Training GCP Red Team Expert (GRTE)
Nmap tip
ICMP and SYN scans cannot be tunnelled through socks proxies, so we must disable ping discovery (-Pn) and specify TCP scans (-sT) for this to work.
Bash
Host -> Jump -> InternalA -> InternalB
# On the jump server connect the port 3333 to the 5985
mknod backpipe p;
nc -lvnp 5985 0<backpipe | nc -lvnp 3333 1>backpipe
# On InternalA accessible from Jump and can access InternalB
## Expose port 3333 and connect it to the winrm port of InternalB
exec 3<>/dev/tcp/internalB/5985
exec 4<>/dev/tcp/Jump/3333
cat <&3 >&4 &
cat <&4 >&3 &
# From the host, you can now access InternalB from the Jump server
evil-winrm -u username -i JumpSSH
SSH graphical connection (X)
Local Port2Port
Open new Port in SSH Server --> Other port
Port2Port
Local port --> Compromised host (SSH) --> Third_box:Port
Port2hostnet (proxychains)
Local Port --> Compromised host (SSH) --> Wherever
Reverse Port Forwarding
This is useful to get reverse shells from internal hosts through a DMZ to your host:
VPN-Tunnel
You need root in both devices (as you are going to create new interfaces) and the sshd config has to allow root login:
PermitRootLogin yes
PermitTunnel yes
Enable forwarding on the Server side
Set a new route on the client side
SSHUTTLE
You can tunnel via ssh all the traffic to a subnetwork through a host. For example, forwarding all the traffic going to 10.10.10.0/24
Connect with a private key
Meterpreter
Port2Port
Local port --> Compromised host (active session) --> Third_box:Port
SOCKS
Another way:
Cobalt Strike
SOCKS proxy
Open a port in the teamserver listening in all the interfaces that can be used to route the traffic through the beacon.
rPort2Port
In this case, the port is opened in the beacon host, not in the Team Server and the traffic is sent to the Team Server and from there to the indicated host:port
To note:
Beacon's reverse port forward is designed to tunnel traffic to the Team Server, not for relaying between individual machines.
Traffic is tunneled within Beacon's C2 traffic, including P2P links.
Admin privileges are not required to create reverse port forwards on high ports.
rPort2Port local
In this case, the port is opened in the beacon host, not in the Team Server and the traffic is sent to the Cobalt Strike client (not to the Team Server) and from there to the indicated host:port
reGeorg
https://github.com/sensepost/reGeorg
You need to upload a web file tunnel: ashx|aspx|js|jsp|php|php|jsp
Chisel
You can download it from the releases page of https://github.com/jpillora/chisel You need to use the same version for client and server
socks
Port forwarding
Rpivot
https://github.com/klsecservices/rpivot
Reverse tunnel. The tunnel is started from the victim. A socks4 proxy is created on 127.0.0.1:1080
Pivot through NTLM proxy
Socat
https://github.com/andrew-d/static-binaries
Bind shell
Reverse shell
Port2Port
Port2Port through socks
Meterpreter through SSL Socat
You can bypass a non-authenticated proxy executing this line instead of the last one in the victim's console:
https://funoverip.net/2011/01/reverse-ssl-backdoor-with-socat-and-metasploit/
SSL Socat Tunnel
/bin/sh console
Create certificates on both sides: Client and Server
Remote Port2Port
Connect the local SSH port (22) to the 443 port of the attacker host
Plink.exe
It's like a console PuTTY version ( the options are very similar to an ssh client).
As this binary will be executed in the victim and it is an ssh client, we need to open our ssh service and port so we can have a reverse connection. Then, to forward only locally accessible port to a port in our machine:
Windows netsh
Port2Port
You need to be a local admin (for any port)
SocksOverRDP & Proxifier
You need to have RDP access over the system. Download:
SocksOverRDP x64 Binaries - This tool uses
Dynamic Virtual Channels(DVC) from the Remote Desktop Service feature of Windows. DVC is responsible for tunneling packets over the RDP connection.
In your client computer load SocksOverRDP-Plugin.dll like this:
Now we can connect to the victim over RDP using mstsc.exe, and we should receive a prompt saying that the SocksOverRDP plugin is enabled, and it will listen on 127.0.0.1:1080.
Connect via RDP and upload & execute in the victim machine the SocksOverRDP-Server.exe binary:
Now, confirm in you machine (attacker) that the port 1080 is listening:
Now you can use Proxifier to proxy the traffic through that port.
Proxify Windows GUI Apps
You can make Windows GUI apps navigate through a proxy using Proxifier. In Profile -> Proxy Servers add the IP and port of the SOCKS server. In Profile -> Proxification Rules add the name of the program to proxify and the connections to the IPs you want to proxify.
NTLM proxy bypass
The previously mentioned tool: Rpivot OpenVPN can also bypass it, setting these options in the configuration file:
Cntlm
It authenticates against a proxy and binds a port locally that is forwarded to the external service you specify. Then, you can use the tool of your choice through this port. For example that forward port 443
Now, if you set for example in the victim the SSH service to listen in port 443. You can connect to it through the attacker port 2222. You could also use a meterpreter that connects to localhost:443 and the attacker is listening in port 2222.
YARP
A reverse proxy created by Microsoft. You can find it here: https://github.com/microsoft/reverse-proxy
DNS Tunneling
Iodine
Root is needed in both systems to create tun adapters and tunnel data between them using DNS queries.
The tunnel will be very slow. You can create a compressed SSH connection through this tunnel by using:
DNSCat2
Establishes a C&C channel through DNS. It doesn't need root privileges.
In PowerShell
You can use dnscat2-powershell to run a dnscat2 client in powershell:
Port forwarding with dnscat
Change proxychains DNS
Proxychains intercepts gethostbyname libc call and tunnels tcp DNS request through the socks proxy. By default the DNS server that proxychains use is 4.2.2.2 (hardcoded). To change it, edit the file: /usr/lib/proxychains3/proxyresolv and change the IP. If you are in a Windows environment you could set the IP of the domain controller.
Tunnels in Go
https://github.com/hotnops/gtunnel
ICMP Tunneling
Hans
https://github.com/friedrich/hans https://github.com/albertzak/hanstunnel
Root is needed in both systems to create tun adapters and tunnel data between them using ICMP echo requests.
ptunnel-ng
ngrok
ngrok is a tool to expose solutions to Internet in one command line. Exposition URI are like: UID.ngrok.io
Installation
Create an account: https://ngrok.com/signup
Client download:
Basic usages
Documentation: https://ngrok.com/docs/getting-started/.
It is also possible to add authentication and TLS, if necessary.
Tunneling TCP
Exposing files with HTTP
Sniffing HTTP calls
Useful for XSS,SSRF,SSTI ... Directly from stdout or in the HTTP interface http://127.0.0.1:4040.
Tunneling internal HTTP service
ngrok.yaml simple configuration example
It opens 3 tunnels:
2 TCP
1 HTTP with static files exposition from /tmp/httpbin/
Other tools to check
Learn & practice AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Learn & practice GCP Hacking:
HackTricks Training GCP Red Team Expert (GRTE)
Last updated