Vulnserver - HTER Command
As part of my preparation for the taking the CTP course and OSCE exam I used the vulnserver.exe to practice and develop my skills.
Last updated
As part of my preparation for the taking the CTP course and OSCE exam I used the vulnserver.exe to practice and develop my skills.
Last updated
Vulnserver is a Windows based threaded TCP server application that is designed to be exploited. The program is intended to be used as a learning tool to teach about the process of software exploitation, as well as a good victim program for testing new exploitation techniques and shellcode.
You can get a copy of the application here https://github.com/zflemingg1/OSCE/tree/master/Vulnserver
Using netcat connect to X.X.X.X:9999 and issue the HELP command to confirm that everything is working as expected:
For the purpose of this tutorial we will be focusing on fuzzing the HTER command. Observing that the valid argument structure for the HTER command is roughly <HTER>[space]<command_value>
we can try sending HTER hello
as a test and see if it’s accepted.
As can bee seen above, the command and argument executed successfully. Now that we have confirmed the structure of a command and its arguments, we can start fuzzing this command to see if we can get the program to crash when submitting various argument values to the HTER
command.
The following BOOFUZZ template was created to fuzz the HTER command in an effort to get the program to crash.
The following command appears to have crashed the program indicating that the "HTER" command can be manipulated to force the program to crash.
Based on the TCP stream (Figure 4), the number of bytes that was sent by the fuzzer and that caused the crash was around 2050 bytes.
To gain a better understanding of this, the following template was used to identify the length needed to overflow the HTER command and cause the crash:
As can be seen from figure 6 the program crashes when a string of 4950 chars is sent. Checking the dump using immunity it can be seen that we control a buffer of length 4080 bytes - Figure 7. However, EIP was overwritten with AAAAAAAA
instead of 41414141
. From this we can observe that the buffer was somehow being converted into hex bytes as opposed to ASCII.
Due to the hex conversion, we are unable to use some of the traditional methods such as using msf-pattern_create
to generate unique strings. To circumvent this, we can use the “Binary Tree Analysis” method to determine the offset. Instead of sending 3000 A’s, we can break it up into smaller sections such as 1500 A’s and 1500 B’s.
Restart the application and run the updates exploit shown below:
From Figure 8 we can see that EIP is overwritten in our B section. Lets repeat this step again and modify our A and B lengths.
From Figure 9 we can see that EIP is overwritten in our B section. Again we repeat this process of modifying our A and B lengths until we find a the correct offset that allows us to take control of EIP. After some trial and error the offset was found to be at 2045 bytes as shown below:
Our next step is to find an address that contains a JMP ESP
instruction.
NOTE: It’s always recommended to use an address from the application itself, or a DLL that comes with the application for compatibility purposes. I.E. the exploit will work even if the application was installed on a different machine. For Vulnserver.exe we can look at the DLL that comes with it (essfunc.dll).
Restart the application in Immunity and execute the following command !mona jmp -r esp -m "essfunc.dll"
.
Take note of the address highlighted in the above picture (0x625011AF)
Restart the application in Immunity, set a breakpoint at address 0x625011AF
and execute the updated POC below
Step through the breakpoint using F8 and you will land in our buffer - Figure 13.
Using all the information that we've gathered we can now generate the payload as shown below:
msfvenom -p windows/shell_bind_tcp EXITFUNC=thread -b "\x00" -f hex -v shellcode
Restart the application and execute the updated POC shown below:
NOTE: A nopsled (80 NOP instructions) were added before the shellcode to give room for the decoder to work
Using netcat, connect to the target host using port 4444 and you should now have a reverse shell: