Branching Out Our Tunnels
DNS Tunneling with Dnscat2
Dnscat2 is a tunneling tool that uses DNS protocol to send data between two hosts. It uses an encrypted Command-&-Control
(C&C
or C2
) channel and sends data inside TXT records within the DNS protocol.
If dnscat2 is not already set up on our attack host, we can do so using the following commands:
Starting the dnscat2 server
After running the server, it will provide us the secret key, which we will have to provide to our dnscat2 client on the Windows host so that it can authenticate and encrypt the data that is sent to our external dnscat2 server.
We can use the client with the dnscat2 project or use dnscat2-powershell, a dnscat2 compatible PowerShell-based client that we can run from Windows targets to establish a tunnel with our dnscat2 server
Once the dnscat2.ps1
file is on the target we can import it and run associated cmd-lets.
We must use the pre-shared secret (-PreSharedSecret
) generated on the server to ensure our session is established and encrypted. If all steps are completed successfully, we will see a session established with our server.
We can list the options we have with dnscat2 by entering ?
at the prompt.
Listing dnscat2 Options
Interacting with the Established Session
SOCKS5 Tunneling with Chisel
Chisel is a TCP/UDP-based tunneling tool written in Go that uses HTTP to transport data that is secured using SSH.
Chisel
can create a client-server tunnel connection in a firewall restricted environment.
Setting Up & Using Chisel
If we want to mind the size of the binary we can follow IppSec's explanation of Chisel, building the binary and shrinking the size of the binary at the 24:29 mark of his video. This is sometimes useful to avoid detection.
Once the binary is built, we can use SCP
to transfer it to the target pivot host.
Running the Chisel Server on the Pivot Host
The Chisel listener will listen for incoming connections on port 1234
using SOCKS5 (--socks5
) and forward it to all the networks that are accessible from the pivot host.
We can start a client on our attack host and connect to the Chisel server.
Connecting to the Chisel Server
Now we can modify our proxychains.conf file located at /etc/proxychains.conf
and add 1080
port at the end so we can use proxychains to pivot using the created tunnel between the 1080 port and the SSH tunnel.
Now if we use proxychains with RDP, we can connect to the DC on the internal network through the tunnel we have created to the Pivot host.
Chisel Reverse Pivot
there may be scenarios where firewall rules restrict inbound connections to our compromised target. In such cases, we can use Chisel with the reverse option.
We'll start the server in our attack host with the option --reverse
.
Starting the Chisel Server on our Attack Host
Then we connect from the Ubuntu (pivot host) to our attack host, using the option R:socks
Same proxychains config as above
Older versions of pre-compiled Chisel (in case you need old libc)
ICMP Tunneling with SOCKS
ICMP tunneling encapsulates your traffic within ICMP packets
containing echo requests
and responses
. ICMP tunneling would only work when ping responses are permitted within a firewalled network.
We will use the ptunnel-ng tool to create a tunnel between our Ubuntu server and our attack host.
Once a tunnel is created, we will be able to proxy our traffic through the ptunnel-ng client
. We can start the ptunnel-ng server
on the target pivot host. Let's start by setting up ptunnel-ng.
Setting Up & Using ptunnel-ng
If ptunnel-ng is not on our attack host, we can clone the project using git.
Alternative approach of building a static binary
Transferring Ptunnel-ng to the Pivot Host
Starting the ptunnel-ng Server on the Pivot Host
The IP address following -r
should be the IP we want ptunnel-ng to accept connections on
Back on the attack host, we can attempt to connect to the ptunnel-ng server (-p <ipAddressofTarget>
) but ensure this happens through local port 2222 (-l2222
). Connecting through local port 2222 allows us to send traffic through the ICMP tunnel.
With the ptunnel-ng ICMP tunnel successfully established, we can attempt to connect to the target using SSH through local port 2222 (-p2222
).
Tunneling an SSH connection through an ICMP Tunnel
We may also use this tunnel and SSH to perform dynamic port forwarding to allow us to use proxychains in various ways.
We could use proxychains with Nmap to scan targets on the internal network (172.16.5.x). Based on our discoveries, we can attempt to connect to the target.
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.
Last updated