<?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>Skypher &#187; Shellcode</title>
	<atom:link href="http://skypher.com/index.php/category/security/shellcode/feed/" rel="self" type="application/rss+xml" />
	<link>http://skypher.com</link>
	<description>The blog for absolutely nothing!</description>
	<lastBuildDate>Fri, 16 Jul 2010 08:26:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Download and LoadLibrary shellcode released</title>
		<link>http://skypher.com/index.php/2010/01/11/download-and-loadlibrary-shellcode-released/</link>
		<comments>http://skypher.com/index.php/2010/01/11/download-and-loadlibrary-shellcode-released/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 10:53:36 +0000</pubDate>
		<dc:creator>SkyLined</dc:creator>
				<category><![CDATA[Assembler]]></category>
		<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Shellcode]]></category>

		<guid isPermaLink="false">http://skypher.com/?p=366</guid>
		<description><![CDATA[<p>Everyone and their dog seems to want to use download and execute shellcode in their exploits. Even though this has some drawbacks:</p>

You need to create an .exe file on the system, which will very likely draw unwanted attention...]]></description>
			<content:encoded><![CDATA[<p>Everyone and their dog seems to want to use download and execute shellcode in their exploits. Even though this has some drawbacks:</p>
<ul>
<li>You need to create an .exe file on the system, which will very likely draw unwanted attention.</li>
<li>You cannot use an API that downloads your file to a temporary location, because that will likely not retain the .exe extention.</li>
<li>You need to make an assumption about where a safe place is to write your .exe file, which means you can guess wrong and the code fails.</li>
<li>You need to store the string &#8216;.exe&#8217; in the download &#038; execute shellcode, which means this is 4 bytes larger.</li>
<li>You need to spawn an extra process, which will very likely draw attention.</li>
<li>You leave cleaning up the exploited process to the download &#038; execute shellcode, which means this needs to be larger.</li>
</ul>
<p>To get around these problems, I created download and LoadLibrary shellcode: a shellcode that will download a DLL file to a temporary file and load it into the exploited process using LoadLibrary. The benefits of this approach are:</p>
<ul>
<li>Smaller code.</li>
<li>You can use the <TT>URLDownloadToCacheFileA</TT> API function in urlmon that downloads and saves your DLL to a temporary file, meaning you do not need to provide a location.</li>
<li>No need to create an .exe file on the system: the extention of a DLL is irrelevant.</li>
<li>No need to spawn an extra process.</li>
<li>You can clean up the exploited process from the code in the DLL instead of the shellcode.</li>
</ul>
<p>The size of the final shellcode depends on the length of the URL for your DLL. For most recent version of the code it is 138 bytes + the length of the URL. This is a pretty decent reduction from the average download and execute shellcodes of 200+ bytes (excluding the URL) that I found around the interwebs.</p>
<p>Project homepage:<br />
<a href="http://code.google.com/p/w32-dl-loadlib-shellcode/">http://code.google.com/p/w32-dl-loadlib-shellcode/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2010/01/11/download-and-loadlibrary-shellcode-released/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Testival released</title>
		<link>http://skypher.com/index.php/2010/01/11/testival-released/</link>
		<comments>http://skypher.com/index.php/2010/01/11/testival-released/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 09:48:40 +0000</pubDate>
		<dc:creator>SkyLined</dc:creator>
				<category><![CDATA[Assembler]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Shellcode]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://skypher.com/?p=364</guid>
		<description><![CDATA[<p>During shellcode development, it makes sense to have a program that can easily load your shellcode at a controlable location, allows you to set registers and memory to certain values and execute the shellcode by setting EIP through a RET or CALL instruction.</p>
<p>The <a href="http://code.google.com/p/testival/">Testival</a> project aims to do all those things and more: it also allows you to test ret-into-libc attacks, set the type of memory allocation you want (RWE flags, etc&#8230;), report exceptions in your code to stdout as well as load DLLs to test shellcode in DllMain.</p>
<p>Testival is used by <a href="http://code.google.com/p/alpha3/">ALPHA3</a> for automatically testing if all the en-/decoders work.</p>
<p>Testival requires <a href="http://code.google.com/p/skybuild/">SkyBuild</a> to automatically build all files.</p>
]]></description>
			<content:encoded><![CDATA[<p>During shellcode development, it makes sense to have a program that can easily load your shellcode at a controlable location, allows you to set registers and memory to certain values and execute the shellcode by setting <TT>EIP</TT> through a <TT>RET</TT> or <TT>CALL</TT> instruction.</p>
<p>The <a href="http://code.google.com/p/testival/">Testival</a> project aims to do all those things and more: it also allows you to test ret-into-libc attacks, set the type of memory allocation you want (<TT>RWE</TT> flags, etc&#8230;), report exceptions in your code to stdout as well as load DLLs to test shellcode in <TT>DllMain</TT>.</p>
<p>Testival is used by <a href="http://code.google.com/p/alpha3/">ALPHA3</a> for automatically testing if all the en-/decoders work.</p>
<p>Testival requires <a href="http://code.google.com/p/skybuild/">SkyBuild</a> to automatically build all files.</p>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2010/01/11/testival-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Countslide alphanumeric GetPC</title>
		<link>http://skypher.com/index.php/2010/01/02/countslide-alphanumeric-getpc/</link>
		<comments>http://skypher.com/index.php/2010/01/02/countslide-alphanumeric-getpc/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 20:39:24 +0000</pubDate>
		<dc:creator>SkyLined</dc:creator>
				<category><![CDATA[Assembler]]></category>
		<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Shellcode]]></category>

		<guid isPermaLink="false">http://skypher.com/?p=347</guid>
		<description><![CDATA[<p>One limitation of most alphanumeric shellcode decoders, including those in <a href="http://skypher.com/wiki/index.php/Hacking/Shellcode/Alphanumeric/ALPHA2">ALPHA2</a> and the soon-to-be-released <A href="http://skypher.com/wiki/index.php/Hacking/Shellcode/Alphanumeric/ALPHA3">ALPHA3</a> is that they need to know where they are located in memory in order to decode themselves and run correctly...]]></description>
			<content:encoded><![CDATA[<p>One limitation of most alphanumeric shellcode decoders, including those in <strong><a href="http://skypher.com/wiki/index.php/Hacking/Shellcode/Alphanumeric/ALPHA2">ALPHA2</a></strong> and the soon-to-be-released <strong><A href="http://skypher.com/wiki/index.php/Hacking/Shellcode/Alphanumeric/ALPHA3">ALPHA3</a></strong> is that they need to know where they are located in memory in order to decode themselves and run correctly. This makes using a <em>nopslide</em> hard in most circumstances, because you mostly only need a <em>nopslide</em> if you do not know exactly where your shellcode is in memory to begin with.</p>
<p>Countslide GetPC is a new technique that I developed to allow the use of <em>nopslides</em> and determine exactly where your shellcode is if you can roughly predict where it will be located in memory.</p>
<p>Given a range of addresses <em>A<sub>min</sub></em> &#8211; <em>A<sub>max</sub></em> in which you can predict your shellcode to start, we will calculate the average address <strong>A<sub>avg</sub></strong> and the maximum absolute deviation <strong>D<sub>max</sub></strong> like so: <CODE><br />
                            <strong>A<sub>avg</sub></strong> == <strong>(A<sub>min</sub> + A<sub>max</sub>) / 2</strong><br />
                            <strong>D<sub>max</sub></strong> == <strong>(A<sub>max</sub> &#8211; A<sub>min</sub>) / 2</strong><br />
&nbsp;<br />
</CODE><br />
Using a <em>nopslide</em> of length <strong>D<sub>max</sub> * 2</strong> starting at an address in this range and a return address of <strong>A<sub>avg</sub> + D<sub>max</sub></strong> will always cause the <em>nopslide</em> to get hit and thus the code at the end of the nopslide to get executed:<br />
<CODE><TABLE FRAME=VOID CELLSPACING=0 COLS=17 RULES=NONE BORDER=0> <COLGROUP><COL WIDTH=18><COL WIDTH=66><COL WIDTH=15><COL WIDTH=24><COL WIDTH=25><COL WIDTH=25><COL WIDTH=25><COL WIDTH=25><COL WIDTH=25><COL WIDTH=25><COL WIDTH=25><COL WIDTH=25><COL WIDTH=25><COL WIDTH=25><COL WIDTH=15><COL WIDTH=87><COL WIDTH=18></COLGROUP> <TBODY> <TR> <TD STYLE="border-top: 1px solid #000000; border-left: 1px solid #000000" WIDTH=18 HEIGHT=17 ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000" WIDTH=66 ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000" WIDTH=15 ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000" WIDTH=24 ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000" WIDTH=25 ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000" WIDTH=25 ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000" WIDTH=25 ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000" WIDTH=25 ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000" WIDTH=25 ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000" WIDTH=25 ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000" WIDTH=25 ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000" WIDTH=25 ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000" WIDTH=25 ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000" WIDTH=25 ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000" WIDTH=15 ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000" WIDTH=87 ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000; border-right: 1px solid #000000" WIDTH=18 ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> </TR> <TR> <TD STYLE="border-left: 1px solid #000000" HEIGHT=17 ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-top: 1px solid #000000; border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000" COLSPAN=2 ALIGN=CENTER><B><FONT FACE="Courier New">A<sub>avg</sub></FONT></B></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> </TR> <TR> <TD STYLE="border-left: 1px solid #000000" HEIGHT=17 ALIGN=LEFT><BR></TD> <TD ALIGN=CENTER VALIGN=BOTTOM SDNUM="1043;0;0,###############"><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-top: 1px solid #000000; border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000" COLSPAN=2 ALIGN=CENTER><B><FONT FACE="Courier New">A<sub>avg</sub> &#8211; D<sub>max</sub></FONT></B></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT><BR></TD> <TD STYLE="border-left: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-top: 1px solid #000000; border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000" COLSPAN=2 ALIGN=CENTER><B><FONT FACE="Courier New">A<sub>avg</sub> + D<sub>max</sub></FONT></B></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> </TR> <TR> <TD STYLE="border-left: 1px solid #000000" HEIGHT=17 ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-left: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-left: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-right: 3px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-left: 3px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT VALIGN=BOTTOM SDNUM="1043;0;0,###############"><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> </TR> <TR> <TD STYLE="border-left: 1px solid #000000" HEIGHT=17 ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT BGCOLOR="#E6E6E6"><FONT FACE="Courier New">D = -D<sub>max</sub></FONT></TD> <TD ALIGN=LEFT BGCOLOR="#E6E6E6"><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT BGCOLOR="#E6E6E6"><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-top: 1px solid #000000; border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000" COLSPAN=4 ALIGN=CENTER BGCOLOR="#CCFFCC"><FONT FACE="Courier New">Nopslide</FONT></TD> <TD STYLE="border-top: 1px solid #000000; border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000" COLSPAN=2 ALIGN=CENTER BGCOLOR="#FFFF99"><FONT FACE="Courier New">code</FONT></TD> <TD ALIGN=LEFT BGCOLOR="#E6E6E6"><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT BGCOLOR="#E6E6E6"><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT BGCOLOR="#E6E6E6"><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT BGCOLOR="#E6E6E6"><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT BGCOLOR="#E6E6E6"><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT VALIGN=BOTTOM BGCOLOR="#E6E6E6" SDNUM="1043;0;0,###############"><FONT FACE="Courier New">O = 2 * D<sub>max</sub></FONT></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> </TR> <TR> <TD STYLE="border-left: 1px solid #000000" HEIGHT=17 ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-top: 1px solid #000000; border-left: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-top: 1px solid #000000; border-bottom: 1px solid #000000; border-right: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-top: 1px solid #000000; border-bottom: 1px solid #000000; border-left: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-top: 1px solid #000000; border-bottom: 1px solid #000000; border-right: 3px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-left: 3px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-top: 1px solid #000000; border-bottom: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-bottom: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT VALIGN=BOTTOM SDNUM="1043;0;0,###############"><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> </TR> <TR> <TD STYLE="border-left: 1px solid #000000" HEIGHT=17 ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT BGCOLOR="#E6E6E6"><FONT FACE="Courier New">D = X</FONT></TD> <TD ALIGN=LEFT BGCOLOR="#E6E6E6"><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT BGCOLOR="#E6E6E6"><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-left: 1px solid #000000; border-right: 1px solid #000000" ALIGN=LEFT VALIGN=BOTTOM BGCOLOR="#E6E6E6" SDNUM="1043;0;0,###############"><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-top: 1px solid #000000; border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000" COLSPAN=4 ALIGN=CENTER BGCOLOR="#CCFFCC"><FONT FACE="Courier New">Nopslide</FONT></TD> <TD STYLE="border-top: 1px solid #000000; border-bottom: 1px solid #000000; border-right: 1px solid #000000" COLSPAN=2 ALIGN=CENTER BGCOLOR="#FFFF99"><FONT FACE="Courier New">code</FONT></TD> <TD ALIGN=CENTER BGCOLOR="#E6E6E6"><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT BGCOLOR="#E6E6E6"><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT BGCOLOR="#E6E6E6"><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT BGCOLOR="#E6E6E6"><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT VALIGN=BOTTOM BGCOLOR="#E6E6E6" SDNUM="1043;0;0,###############"><FONT FACE="Courier New">O = D<sub>max</sub> &#8211; X</FONT></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT VALIGN=BOTTOM SDNUM="1043;0;0,###############"><FONT FACE="Courier New"><BR></FONT></TD> </TR> <TR> <TD STYLE="border-left: 1px solid #000000" HEIGHT=17 ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-left: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-top: 1px solid #000000; border-right: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-top: 1px solid #000000; border-left: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-top: 1px solid #000000; border-right: 3px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT VALIGN=BOTTOM SDNUM="1043;0;0,###############"><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> </TR> <TR> <TD STYLE="border-left: 1px solid #000000" HEIGHT=17 ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT BGCOLOR="#E6E6E6"><FONT FACE="Courier New">D = +D<sub>max</sub></FONT></TD> <TD ALIGN=LEFT BGCOLOR="#E6E6E6"><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT BGCOLOR="#E6E6E6"><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-left: 1px solid #000000" ALIGN=LEFT BGCOLOR="#E6E6E6"><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT BGCOLOR="#E6E6E6"><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-left: 1px solid #000000" ALIGN=LEFT BGCOLOR="#E6E6E6"><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-right: 3px solid #000000" ALIGN=LEFT BGCOLOR="#E6E6E6"><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-top: 1px solid #000000; border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000" COLSPAN=4 ALIGN=CENTER BGCOLOR="#CCFFCC"><FONT FACE="Courier New">Nopslide</FONT></TD> <TD STYLE="border-top: 1px solid #000000; border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000" COLSPAN=2 ALIGN=CENTER BGCOLOR="#FFFF99"><FONT FACE="Courier New">code</FONT></TD> <TD ALIGN=LEFT VALIGN=BOTTOM BGCOLOR="#E6E6E6" SDNUM="1043;0;0,###############"><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT VALIGN=BOTTOM BGCOLOR="#E6E6E6" SDNUM="1043;0;0,###############"><FONT FACE="Courier New">O = 0</FONT></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> </TR> <TR> <TD STYLE="border-left: 1px solid #000000" HEIGHT=17 ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-left: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-left: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-right: 3px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-top: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-top: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-top: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-top: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-top: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT VALIGN=BOTTOM SDNUM="1043;0;0,###############"><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> </TR> <TR> <TD STYLE="border-left: 1px solid #000000" HEIGHT=17 ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT VALIGN=BOTTOM SDNUM="1043;0;0,###############"><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-right: 3px solid #000000" ALIGN=LEFT VALIGN=BOTTOM SDNUM="1043;0;0,###############"><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-left: 3px solid #000000" ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT VALIGN=BOTTOM SDNUM="1043;0;0,###############"><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT VALIGN=BOTTOM SDNUM="1043;0;0,###############"><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT VALIGN=BOTTOM SDNUM="1043;0;0,###############"><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> </TR> <TR> <TD STYLE="border-left: 1px solid #000000" HEIGHT=17 ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-top: 1px solid #000000; border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000" COLSPAN=6 ALIGN=CENTER><FONT FACE="Courier New">Return address</FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> </TR> <TR> <TD STYLE="border-bottom: 1px solid #000000; border-left: 1px solid #000000" HEIGHT=17 ALIGN=LEFT><BR></TD> <TD STYLE="border-bottom: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-bottom: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-bottom: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-bottom: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-bottom: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-bottom: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-bottom: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-bottom: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-bottom: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-bottom: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-bottom: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-bottom: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-bottom: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-bottom: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-bottom: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> <TD STYLE="border-bottom: 1px solid #000000; border-right: 1px solid #000000" ALIGN=LEFT><FONT FACE="Courier New"><BR></FONT></TD> </TR> </TBODY> </TABLE> </CODE></p>
<p>In this example, the actual deviation <strong>D</strong> from <strong>A<sub>avg</sub></strong> indicates where the exploit actually ends up jumping to. The base address of the <em>nopslide</em> <strong>A<sub>nop</sub></strong> plus the offset in the <em>nopslide</em> where execution starts <strong>O</strong> are equal to the return address <strong>A<sub>avg</sub> + D<sub>max</sub></strong>:<br />
<CODE><br />
                            A<sub>nop</sub> + O  ==  A<sub>avg</sub> + D<sub>max</sub><br />
&nbsp;<br />
</CODE><br />
Because <strong>A<sub>avg</sub></strong> and <strong>D<sub>max</sub></strong> are values we predict, we can calculate the base address <strong>A<sub>nop</sub></strong> of the <em>nopslide</em> if we can calculate <strong>O</strong>. And because we know the length of the <em>nopslide</em> is <strong>D<sub>max</sub> * 2</strong>, we can calculate the base address of the code that follows the <em>nopslide</em> <strong>A<sub>patcher</sub></strong> as well:<br />
<CODE><br />
                            A<sub>nop</sub> == A<sub>avg</sub> + D<sub>max</sub> &#8211; O<br />
                            A<sub>patcher</sub> == A<sub>avg</sub> + D<sub>max</sub> * 3 &#8211; O<br />
&nbsp;<br />
</CODE><br />
So, any address <strong>A<sub>avg</sub> + D<sub>max</sub> * 3 + X</strong> will be in the code that follows the <em>nopslide</em> at offset <strong>O + X</strong> (if that code is large enough). We can choose to overwrite a byte at that address to modify the code following the <em>nopslide</em>. Which byte of the code gets modified depends entirely on the value of <strong>O</strong>. This means that the value of <strong>O</strong> can directly influence what our code does and this is what we use to calculate the value of <strong>O</strong>.</p>
<p>A small piece of code which I will call the <em>patcher</em> of length <strong>P</strong> is put after the <em>nopslide</em> followed by a second <em>nopslide</em> of length <strong>D<sub>max</sub> * 2</strong> which I will call the <em>countslide</em>. When executed, the <em>patcher</em> overwrites a byte in the <em>countslide</em> at address <strong>A<sub>avg</sub> + D<sub>max</sub> * 3 + P</strong> (the <em>modification address</em>), which is always inside the <em>countslide</em>. Here&#8217;s an example:</p>
<p><CODE><TABLE FRAME=VOID CELLSPACING=0 COLS=21 RULES=NONE BORDER=0> <COLGROUP><COL WIDTH=23><COL WIDTH=22><COL WIDTH=22><COL WIDTH=22><COL WIDTH=22><COL WIDTH=22><COL WIDTH=22><COL WIDTH=22><COL WIDTH=22><COL WIDTH=22><COL WIDTH=22><COL WIDTH=22><COL WIDTH=22><COL WIDTH=22><COL WIDTH=22><COL WIDTH=22><COL WIDTH=22><COL WIDTH=22><COL WIDTH=22><COL WIDTH=22><COL WIDTH=22></COLGROUP> <TBODY> <TR> <TD STYLE="border-top: 1px solid #000000; border-left: 1px solid #000000" WIDTH=23 HEIGHT=16 ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000" WIDTH=22 ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000" WIDTH=22 ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000" WIDTH=22 ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000" WIDTH=22 ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000" WIDTH=22 ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000" WIDTH=22 ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000" WIDTH=22 ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000" WIDTH=22 ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000" WIDTH=22 ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000" WIDTH=22 ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000" WIDTH=22 ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000" WIDTH=22 ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000" WIDTH=22 ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000" WIDTH=22 ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000" WIDTH=22 ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000" WIDTH=22 ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000" WIDTH=22 ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000" WIDTH=22 ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000" WIDTH=22 ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000; border-right: 1px solid #000000" WIDTH=22 ALIGN=LEFT><BR></TD> </TR> <TR> <TD STYLE="border-left: 1px solid #000000" HEIGHT=17 ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000; border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000" COLSPAN=6 ALIGN=CENTER>A<sub>nop</sub> + D<sub>max</sub> * 2 + P</TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT><BR></TD> </TR> <TR> <TD STYLE="border-left: 1px solid #000000" HEIGHT=17 ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000; border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000" COLSPAN=2 ALIGN=CENTER>A<sub>nop</sub></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000; border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000" COLSPAN=4 ALIGN=CENTER>A<sub>nop</sub> + D<sub>max</sub> * 2</TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT><BR></TD> <TD STYLE="border-left: 1px solid #000000" ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000; border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000" COLSPAN=6 ALIGN=CENTER>A<sub>nop</sub> + D<sub>max</sub> * 4 + P</TD> <TD ALIGN=LEFT><BR></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT><BR></TD> </TR> <TR> <TD STYLE="border-left: 1px solid #000000" HEIGHT=17 ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT><BR></TD> <TD STYLE="border-left: 1px solid #000000" ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT><BR></TD> <TD STYLE="border-left: 1px solid #000000" ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT><BR></TD> <TD STYLE="border-left: 1px solid #000000" ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT><BR></TD> <TD STYLE="border-left: 1px solid #000000" ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT><BR></TD> </TR> <TR> <TD STYLE="border-left: 1px solid #000000" HEIGHT=17 ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT BGCOLOR="#E6E6E6"><BR></TD> <TD ALIGN=LEFT BGCOLOR="#E6E6E6"><BR></TD> <TD STYLE="border-top: 1px solid #000000; border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000" COLSPAN=5 ALIGN=CENTER BGCOLOR="#CCFFCC"><FONT FACE="Courier New">Nopslide</FONT></TD> <TD STYLE="border-top: 1px solid #000000; border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000" COLSPAN=3 ALIGN=CENTER BGCOLOR="#FFFF99">patcher</TD> <TD STYLE="border-top: 1px solid #000000; border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000" COLSPAN=5 ALIGN=CENTER BGCOLOR="#CCFFFF">countslide</TD> <TD ALIGN=LEFT BGCOLOR="#E6E6E6"><BR></TD> <TD ALIGN=LEFT BGCOLOR="#E6E6E6"><BR></TD> <TD ALIGN=LEFT BGCOLOR="#E6E6E6"><BR></TD> <TD ALIGN=LEFT BGCOLOR="#E6E6E6"><BR></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT><BR></TD> </TR> <TR> <TD STYLE="border-left: 1px solid #000000" HEIGHT=17 ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD STYLE="border-right: 3px solid #000000" ALIGN=LEFT><BR></TD> <TD STYLE="border-left: 3px solid #000000" ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT><BR></TD> <TD STYLE="border-left: 1px solid #000000" ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT><BR></TD> </TR> <TR> <TD STYLE="border-left: 1px solid #000000" HEIGHT=17 ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000; border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000" COLSPAN=4 ALIGN=CENTER>A<sub>nop</sub> + O</TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000; border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000" COLSPAN=8 ALIGN=CENTER>A<sub>nop</sub> + O + P + D<sub>max</sub> * 2</TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT><BR></TD> </TR> <TR> <TD STYLE="border-left: 1px solid #000000" HEIGHT=17 ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD STYLE="border-right: 3px solid #000000" ALIGN=LEFT><BR></TD> <TD STYLE="border-left: 3px solid #000000" ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT><BR></TD> <TD STYLE="border-left: 1px solid #000000" ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT><BR></TD> </TR> <TR> <TD STYLE="border-left: 1px solid #000000" HEIGHT=17 ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000; border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000" COLSPAN=4 ALIGN=CENTER>A<sub>avg</sub> + D<sub>max</sub></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000; border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000" COLSPAN=6 ALIGN=CENTER>A<sub>avg</sub> + D<sub>max</sub> * 3 + P</TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT><BR></TD> </TR> <TR> <TD STYLE="border-left: 1px solid #000000" HEIGHT=17 ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD STYLE="border-right: 3px solid #000000" ALIGN=LEFT><BR></TD> <TD STYLE="border-left: 3px solid #000000" ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT><BR></TD> <TD STYLE="border-left: 1px solid #000000" ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT><BR></TD> </TR> <TR> <TD STYLE="border-left: 1px solid #000000" HEIGHT=17 ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000; border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000" COLSPAN=6 ALIGN=CENTER>Return address</TD> <TD ALIGN=LEFT><BR></TD> <TD STYLE="border-top: 1px solid #000000; border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000" COLSPAN=8 ALIGN=CENTER>Modification address</TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD ALIGN=LEFT><BR></TD> <TD STYLE="border-right: 1px solid #000000" ALIGN=LEFT><BR></TD> </TR> <TR> <TD STYLE="border-bottom: 1px solid #000000; border-left: 1px solid #000000" HEIGHT=17 ALIGN=LEFT><BR></TD> <TD STYLE="border-bottom: 1px solid #000000" ALIGN=LEFT><BR></TD> <TD STYLE="border-bottom: 1px solid #000000" ALIGN=LEFT><BR></TD> <TD STYLE="border-bottom: 1px solid #000000" ALIGN=LEFT><BR></TD> <TD STYLE="border-bottom: 1px solid #000000" ALIGN=LEFT><BR></TD> <TD STYLE="border-bottom: 1px solid #000000" ALIGN=LEFT><BR></TD> <TD STYLE="border-bottom: 1px solid #000000" ALIGN=LEFT><BR></TD> <TD STYLE="border-bottom: 1px solid #000000" ALIGN=LEFT><BR></TD> <TD STYLE="border-bottom: 1px solid #000000" ALIGN=LEFT><BR></TD> <TD STYLE="border-bottom: 1px solid #000000" ALIGN=LEFT><BR></TD> <TD STYLE="border-bottom: 1px solid #000000" ALIGN=LEFT><BR></TD> <TD STYLE="border-bottom: 1px solid #000000" ALIGN=LEFT><BR></TD> <TD STYLE="border-bottom: 1px solid #000000" ALIGN=LEFT><BR></TD> <TD STYLE="border-bottom: 1px solid #000000" ALIGN=LEFT><BR></TD> <TD STYLE="border-bottom: 1px solid #000000" ALIGN=LEFT><BR></TD> <TD STYLE="border-bottom: 1px solid #000000" ALIGN=LEFT><BR></TD> <TD STYLE="border-bottom: 1px solid #000000" ALIGN=LEFT><BR></TD> <TD STYLE="border-bottom: 1px solid #000000" ALIGN=LEFT><BR></TD> <TD STYLE="border-bottom: 1px solid #000000" ALIGN=LEFT><BR></TD> <TD STYLE="border-bottom: 1px solid #000000" ALIGN=LEFT><BR></TD> <TD STYLE="border-bottom: 1px solid #000000; border-right: 1px solid #000000" ALIGN=LEFT><BR></TD> </TR> </TBODY> </TABLE> </CODE></p>
<p>The <em>countslide</em> will consist entirely of one byte <TT>INC ECX</TT> instructions. The <em>patcher</em> will overwrite one byte at the predictable address <strong>A<sub>avg</sub> + D<sub>max</sub> * 3 + P</strong> with a one byte <TT>POP ECX</TT> instruction. It then stores the predictable value <strong>A<sub>avg</sub> + D<sub>max</sub> * 3 + P + 1</strong> on the stack after which the <em>countslide</em> is executed.</p>
<p>Here is what will happen after the exploit makes code jump to address <strong>A<sub>avg</sub> + D<sub>max</sub></strong> in the <em>nopslide</em>:</p>
<ul>
<li>the <em>nopslide</em> executes until it reaches the <em>patcher</em>,</li>
<li>the <em>patcher</em> modifies the <em>countslide</em> at <strong>A<sub>avg</sub> + D<sub>max</sub> * 3 + P</strong>,</li>
<li>the <em>patcher</em> saves the value <strong>A<sub>avg</sub> + D<sub>max</sub> * 3 + P + 1</strong> on the stack, after which the <em>countslide</em> is executed,
<li>the <em>countslide</em> increments <TT>ECX</TT> over and over, acting like a normal nopslide, until it runs into the patched <TT>POP ECX</TT>,</li>
<li>the <TT>POP ECX</TT> instruction pops the value <strong>A<sub>avg</sub> + D<sub>max</sub> * 3 + P + 1</strong>, saved there by the <em>patcher</em>, off the stack into <TT>ECX</TT>.</li>
<li>the <em>countslide</em> then continues to increment <TT>ECX</TT> for every one byte instruction it executes, until it reaches its end.</li>
</ul>
<p>The number of <TT>INC ECX</TT> instructions executed in the <em>countslide</em> after the <TT>POP ECX</TT> <strong>N<sub>inc</sub></strong> depends on <strong>D<sub>max</sub></strong> and <strong>O</strong> as follows:<br />
<CODE><br />
                            N<sub>inc</sub> == D<sub>max</sub> * 2 &#8211; O &#8211; 1<br />
&nbsp;<br />
</CODE><br />
So, taking into account that the <TT>POP ECX</TT> sets <TT>ECX</TT> to <strong>A<sub>avg</sub> + D<sub>max</sub> * 3 + P + 1</strong>, after the <em>countslide</em> has completely been executed, the value in <TT>ECX</TT> will be:<br />
<CODE><br />
                            ECX == A<sub>avg</sub> + D<sub>max</sub> * 3 + P + 1 + N<sub>inc</sub><br />
                            ECX == A<sub>avg</sub> + D<sub>max</sub> * 5 + P &#8211; O<br />
&nbsp;<br />
</CODE><br />
And because <strong>A<sub>nop</sub> + O</strong> == <strong>A<sub>avg</sub> + D<sub>max</sub></strong>, this means the value in <TT>ECX</TT> is:<br />
<CODE><br />
                            ECX == A<sub>nop</sub> + D<sub>max</sub> * 4 + P<br />
&nbsp;<br />
</CODE><br />
Which, as you can see in the second diagram above, is exactly where our <em>countslide</em> ends, so at this point <TT>ECX</TT> == <TT>EIP</TT>. The <em>countslide</em> is followed by the shellcode, which can use <TT>ECX</TT> as the source of its base address.</p>
<p><strong>*UPDATE*:</strong> <a href="http://skypher.com/index.php/2010/01/10/alpha3-released/">ALPHA3</a> comes with a working version of Countslide mixedcase alphanumeric ascii GetPC for x86.</p>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2010/01/02/countslide-alphanumeric-getpc/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>w32-bind-ngs-shellcode released</title>
		<link>http://skypher.com/index.php/2010/01/02/w32-bind-ngs-shellcode/</link>
		<comments>http://skypher.com/index.php/2010/01/02/w32-bind-ngs-shellcode/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 14:00:09 +0000</pubDate>
		<dc:creator>SkyLined</dc:creator>
				<category><![CDATA[Assembler]]></category>
		<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Shellcode]]></category>

		<guid isPermaLink="false">http://skypher.com/?p=320</guid>
		<description><![CDATA[<p>w32-bind-ngs-shellcode is a small, null-free 32-bit Windows port-binding shellcode. The total shellcode is currently 214 bytes and supports Windows 5.0-7.0 all service packs...]]></description>
			<content:encoded><![CDATA[<p><strong>w32-bind-ngs-shellcode</strong> is a small, null-free 32-bit Windows port-binding shellcode. The total shellcode is currently 214 bytes and supports Windows 5.0-7.0 all service packs. I&#8217;ve released various versions of this shellcode <a href="http://www.milw0rm.com/exploits/9232">before</a>, which is why I decided it makes more sense to create a project for it, so you can always download the latest version.</p>
<p>w32-bind-ngs-shellcode is hosted on Google code <a href="http://code.google.com/p/w32-bind-ngs-shellcode/">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2010/01/02/w32-bind-ngs-shellcode/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shellcode: finding the base address of kernel32 in Windows 7</title>
		<link>http://skypher.com/index.php/2009/07/22/shellcode-finding-kernel32-in-windows-7/</link>
		<comments>http://skypher.com/index.php/2009/07/22/shellcode-finding-kernel32-in-windows-7/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 12:32:03 +0000</pubDate>
		<dc:creator>SkyLined</dc:creator>
				<category><![CDATA[Assembler]]></category>
		<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Shellcode]]></category>

		<guid isPermaLink="false">http://skypher.com/?p=153</guid>
		<description><![CDATA[<p>If you&#8217;ve coded shellcode before, you know that the code often needs to find out the base address address where kernel32.dll is loaded in memory. Most publicly available code expects the second entry in the &#8220;InitializationOrder&#8221; list to be kernel32...]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve coded shellcode before, you know that the code often needs to find out the base address address where kernel32.dll is loaded in memory. Most publicly available code expects the second entry in the &#8220;InitializationOrder&#8221; list to be kernel32. Unfortunately, it seems that <a href="http://www.harmonysecurity.com/blog/2009/06/retrieving-kernel32s-base-address.html">this is not the case</a> in the public Windows 7 beta.</p>
<p>I&#8217;ve create a solution to this problem that should be able to find kernel32.dll on all versions of Windows with minimal code size increase. It works by walking the &#8220;InInitializationOrder&#8221; list mentioned above and checking the length of the name of the module: the Unicode string &#8220;kernel32.dll&#8221; has a terminating 0 as the 12th character. From my (limited) testing, it seems that scanning for a 0 as the 24th byte in the name allows the code to find kernel32.dll correctly.</p>
<p>More details can be found <a href="http://skypher.com/wiki/index.php/Hacking/Shellcode/kernel32">here</a>.</p>
<p>The code:<br />
<CODE><br />
&nbsp;&nbsp;&nbsp;&nbsp;XOR&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ECX,&nbsp;ECX&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;&nbsp;ECX&nbsp;=&nbsp;0<br />
&nbsp;&nbsp;&nbsp;&nbsp;MOV&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ESI,&nbsp;[FS:ECX&nbsp;+&nbsp;0x30]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;&nbsp;ESI&nbsp;=&nbsp;&#038;(PEB)&nbsp;([FS:0x30])<br />
&nbsp;&nbsp;&nbsp;&nbsp;MOV&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ESI,&nbsp;[ESI&nbsp;+&nbsp;0x0C]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;&nbsp;ESI&nbsp;=&nbsp;PEB->Ldr<br />
&nbsp;&nbsp;&nbsp;&nbsp;MOV&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ESI,&nbsp;[ESI&nbsp;+&nbsp;0x1C]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;&nbsp;ESI&nbsp;=&nbsp;PEB->Ldr.InInitOrder<br />
next_module:<br />
&nbsp;&nbsp;&nbsp;&nbsp;MOV&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EBP,&nbsp;[ESI&nbsp;+&nbsp;0x08]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;&nbsp;EBP&nbsp;=&nbsp;InInitOrder[X].base_address<br />
&nbsp;&nbsp;&nbsp;&nbsp;MOV&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EDI,&nbsp;[ESI&nbsp;+&nbsp;0x20]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;&nbsp;EBP&nbsp;=&nbsp;InInitOrder[X].module_name&nbsp;(unicode)<br />
&nbsp;&nbsp;&nbsp;&nbsp;MOV&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ESI,&nbsp;[ESI]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;&nbsp;ESI&nbsp;=&nbsp;InInitOrder[X].flink&nbsp;(next&nbsp;module)<br />
&nbsp;&nbsp;&nbsp;&nbsp;CMP&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[EDI&nbsp;+&nbsp;12*2],&nbsp;CL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;&nbsp;modulename[12]&nbsp;==&nbsp;0&nbsp;?<br />
&nbsp;&nbsp;&nbsp;&nbsp;JNE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;next_module&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;&nbsp;No:&nbsp;try&nbsp;next&nbsp;module.<br />
&nbsp;<br />
</CODE></p>
<p>NB. See <A href="index.php/2009/07/22/shellcode-finding-kernel32-in-windows-7/#comment-620">the comments</A> for a problem (and solution) on Win2K targets courtesy of aniway.</p>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2009/07/22/shellcode-finding-kernel32-in-windows-7/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>ASCII Art</title>
		<link>http://skypher.com/index.php/2008/08/03/ascii-art/</link>
		<comments>http://skypher.com/index.php/2008/08/03/ascii-art/#comments</comments>
		<pubDate>Sun, 03 Aug 2008 18:46:32 +0000</pubDate>
		<dc:creator>SkyLined</dc:creator>
				<category><![CDATA[ASCII Art]]></category>
		<category><![CDATA[Shellcode]]></category>
		<category><![CDATA[Art]]></category>
		<category><![CDATA[ASCII]]></category>

		<guid isPermaLink="false">http://skypher.com/?p=29</guid>
		<description><![CDATA[<p>I&#8217;ve put some of the ASCII Art I&#8217;ve created over the years online <a title="ASCII Art" href="http://skypher.com/wiki/index.php?title=ASCII_Art" target="_self">here</a>. This includes never before publicly released ASCII Art shellcode.</p>
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve put some of the ASCII Art I&#8217;ve created over the years online <a title="ASCII Art" href="http://skypher.com/wiki/index.php?title=ASCII_Art" target="_self">here</a>. This includes never before publicly released ASCII Art shellcode.</p>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2008/08/03/ascii-art/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
