Lab-18-Introducing VulnServer
Lab-18-Introducing VulnServer
Overview
Before we start our penetration test, we need to gather as much information as we can about
the target (assume we did that). This lab is going to the next phase of our attack, the port
scanning phase. This phase aims to gather information about open ports, running services,
services versions, and the operating systems running. The final report of this phase will help us
move to the next phase of our attack, so don’t forget to prepare a final report of your discovery.
Requirements:
1. Two machines or virtual machines are needed: KALI and your Windows 10.
2. Vulnserver Application, found here.
Part #1 – Preparations
Let’s start by finding the IP Address of the KALI and Windows Machine (this could be skipped
since you know it!).
1. Open a Terminal window by going to Applications → Accessories → Terminal.
2. In the Terminal window, execute the ifconfig command. Make a note of your IP address
for later reference.
3. On the Windows machine, click Start → Run. In the Run box, enter cmd.exe (cmd alone
is enough) and press the Enter key. In the Command Prompt window, enter the ipconfig
command and press the Enter key.
6. You should see lines starting "64 bytes from…". Press Ctrl+C to stop the pinging.
Task #1.1: What IP address and subnet mask your KALI Linux system using now?
(Remember it!)
7. If you don't see any replies, your virtual machine is not able to reach your Windows
target. You need to be able to communicate with the Windows target to proceed with this lab.
Try troubleshooting it.
Note: The application “vulnserver.exe” will serve as our vulnerable application that we need to
exploit using our KALI Linux machine.
Task #2.1:
A) What are the running TCP services, and what ports are they using?
B) What is the TCP port used by our vulnserver.exe application?
######################################################
#!/usr/bin/env python
import socket
host = "<windows-ip-address>"
port = <vulnserver-port>
cmd=”TRUN .”
offset="A" * USE_A_NUMBER_HERE # cause the crash
shellcode = cmd + offset
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host,port))
data=s.recv(1024)
print "\n" + data
s.send(shellcode)
s.close()
print "Done Sending: ", len(shellcode), “ bytes”
######################################################
2. In the Windows machine check if your “vulnserver.exe” has crashed after sending a
huge number of bytes after the TRUN command. This can be done by adjusting the number
used in the template above “USE_A_NUMBER_HERE”.
3. Restart your test and check if the application crashed.
Task #4.1: How many bytes did you send with the TRUN command?
Task #4.2: Check the debugger; Did the application crash? How can you prove that?
7. By now you must have managed to overwrite the EIP register. If you did continue to the
next step, if you didn’t then adjust the USE_A_NUMBER_HERE and restart the application
inside the debugger, and run your exploit again until you make sure that EIP is overwritten with
four A’s.
9. Now replace the created pattern instead of the buffer number you used before and
restart the process.
Task #4.3: Check what are the 4 bytes that have written over EIP, write them down for
our next step
10. Now we’re going to use the Metasploit’s pattern_offset to check the offset that is
needed to overwrite EIP. This can be done as following:
# pattern_offset “REPLACE_WITH_4_BYTES_FOUND”
Note: please adjust the commands pattern_create and pattern_offset to suite your testing
environment, because the location of the pattern_create will be different on different KALI
versions.
11. Now use that number for the buffer and adjust your exploit to send the EIP 4 bytes as
“B” and the rest of the buffer as “C” for example. (Explanation: let’s say we needed 1000 bytes
to overflow the application, and the offset was 350 bytes. Then use “A” * 350, plus “B” * 4, plus
“B” * 646 for the rest of the buffer, which is a total of 1000 bytes).
12. Restart your testing.
Task #4.4: What is the opcode for JMP ESP? Why did we search for a JMP ESP
assembly instruction?
Task #5.1: How can you connect to the target box (the exploited Windows box)?
2. By now if you we are able to connect to that port, you are given a cmd.exe shell on the
target. If you didn’t then check the previous steps and make sure you’ve done them correctly.
Task #5.2: How can you prove that you are truly on the Windows box?
3. If all went successfully, then congrats for another successful software exploitation
(buffer overflow) lab!
Task #5.3: Now suppose your target is running behind a firewall. Will the approach we
did above succeed or not? Why?