<?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; Tools</title>
	<atom:link href="http://skypher.com/index.php/category/security/tools/feed/" rel="self" type="application/rss+xml" />
	<link>http://skypher.com</link>
	<description>The blog for absolutely nothing!</description>
	<lastBuildDate>Sat, 25 Feb 2012 11:27:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Exploits, ASLR and randomness</title>
		<link>http://skypher.com/index.php/2010/09/03/exploit-aslr-randomness/</link>
		<comments>http://skypher.com/index.php/2010/09/03/exploit-aslr-randomness/#comments</comments>
		<pubDate>Fri, 03 Sep 2010 09:40:39 +0000</pubDate>
		<dc:creator>SkyLined</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://skypher.com/?p=538</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>When trying to bypass <a href="https://secure.wikimedia.org/wikipedia/en/wiki/Data_Execution_Prevention">DEP</a>, I often use a <a href="https://secure.wikimedia.org/wikipedia/en/wiki/Heap_spray">heap spray</a> to get data (including my <a href="https://secure.wikimedia.org/wikipedia/en/wiki/Shellcode">shellcode</a>) in a predictable location first. Next, I use <a href="https://secure.wikimedia.org/wikipedia/en/wiki/Return-to-libc_attack">ret-into-libc</a> to call <a href="http://msdn.microsoft.com/en-us/library/aa366898(VS.85).aspx">VirtualProtect</a> in an attempt to give the chunk of the heap that contains my shellcode &#8220;RWE&#8221; permissions. Finally, I returning to my shellcode, which can now be executed without causing an exception. However, if <a href="https://secure.wikimedia.org/wikipedia/en/wiki/Address_space_layout_randomization">ASLR</a> is enabled, you must first bypass that to find out where VirtualProtect is located in memory.</p>
<p>I haven&#8217;t got as much time as I used to to write exploits for bugs I find, but when I write exploits, I usually do so in incremental steps: I first create a simple version that ignores ASLR/DEP and I make sure that works with ASLR/DEP disabled. I then add the code that uses ret-into-libc to bypass DEP, and provide it with the exact location of VirtualProtect to make sure that works as well before I add the code that automatically determines the location of VirtualProtect to bypass ASLR. Because I have ASLR enabled on most of my systems, I created a simple tool to extract its current location:</p>
<p><code style="color:silver; background-color: black;"><br />
C:\Sample&gt;type <a href="http://skypher.com/SkyLined/download/ASLR/vp.c">vp.c</a><br />
#define WINVER 0x0500<br />
#define _WIN32_WINNT 0x0500<br />
#include &lt;windows.h&gt;<br />
int main(int argc, char** argv) {<br />
  HMODULE hModule = 0;<br />
  FARPROC pFunction = 0;<br />
  if (argc &lt; 2 || argc &gt; 3) {<br />
    printf("Usage:\r\n  %s module_name [function_name]\r\n", argv[0]);<br />
  } else {<br />
    hModule = LoadLibraryEx(argv[1], NULL, DONT_RESOLVE_DLL_REFERENCES);<br />
    if (!hModule) {<br />
      printf("Module not found!\r\n");<br />
    } else {<br />
      printf("Module base     : %08X\r\n", (UINT)hModule);<br />
      if (argc == 3) {<br />
        pFunction = GetProcAddress(hModule, argv[2]);<br />
        if (!pFunction) {<br />
          printf("Function not found!\r\n");<br />
        } else {<br />
          printf("Function offset : %+8X\r\n", (UINT)pFunction - (UINT)hModule);<br />
        }<br />
      }<br />
    }<br />
  }<br />
}<br />
&nbsp;<br />
C:\Sample&gt;<a href="http://code.google.com/p/skybuild/">build</a><br />
== Sample ==<br />
  @ Generating build configuration.<br />
  @ Version 0.1 alpha, build 1, started at Fri, 03 Sep 2010 07:55:45 (UTC)<br />
  [Sample]<br />
    + Build: vp.obj<br />
    + Build: vp.exe<br />
      - Cleanup: vp.ilk<br />
    - Cleanup: vp.obj<br />
    @ Project built successfully.<br />
@ Build successful.<br />
&nbsp;<br />
C:\Sample&gt;vp %SystemRoot%\system32\kernel32.dll<br />
Module base     : 77000000<br />
&nbsp;<br />
C:\Sample&gt;vp %SystemRoot%\system32\kernel32.dll VirtualProtect<br />
Module base     : 77000000<br />
Function offset :    134EC<br />
&nbsp;<br />
C:\Sample&gt;<br />
&nbsp;<br />
</code><br />
As you can see, both times I ran the tool, the base address of kernel32.dll was the same. This is because ASLR is only re-randomized at boot time, so until you reboot your machine, you can hard-code the value obtained this way into your exploit.</p>
<p>So, how random is the base address of kernel32.dll in real life? One way to find out is to set up a Windows machine to automatically run a script at startup that extracts the base address of kernel32.dll using the code above and then reboots. If you let this run for a while, you get a number of different values. Here&#8217;s a script I created to do just that:</p>
<p><code><br />
@ECHO OFF<br />
vp.exe "%SystemRoot%\system32\kernel32.dll" >> %COMPUTERNAME%.txt<br />
IF EXIST continue.txt (<br />
  shutdown.exe -r -t 0<br />
)<br />
&nbsp;<br />
</code><br />
In addition to logging the base address of kernel32.dll in a file named after the machine it is running on, and rebooting the machine, it also checks for the existence of a file called &#8220;continue.txt&#8221;. That way, I can stop the machine from continuously rebooting by deleting that file (the script is loaded of a network share, so I can access the file from another machine). I used the &#8220;CONTROL USERPASSWORDS2&#8243; configuration panel to tell Windows to automatically log in as a local user account at startup, and put the script in the &#8220;startup&#8221; folder of that local user.</p>
<p>After running for a while on a 32-bit Vista sp2 en-us virtual machine, I used the following Python script to extract some useful data from the information I gathered:</p>
<p><code><br />
if __name__ == "__main__":<br />
  import sys;<br />
  file = open(sys.argv[1], 'rb');<br />
  try:<br />
    data = file.read();<br />
  finally:<br />
    file.close();<br />
  base_addresses_counts = {};<br />
  results_count = 0;<br />
  for line in data.split('\r\n'):<br />
    if not line:<br />
      continue;<br />
    results_count += 1;<br />
    base_address = int(line[18:], 16);<br />
    if base_address not in base_addresses_counts:<br />
      base_addresses_counts[base_address] = 1;<br />
    else:<br />
      base_addresses_counts[base_address] += 1;<br />
  base_addresses = base_addresses_counts.keys();<br />
  base_addresses.sort();<br />
  lowest_base_address = base_addresses[0];<br />
  highest_base_address = base_addresses[-1];<br />
  smallest_delta = highest_base_address - lowest_base_address;<br />
  previous_base_address = None;<br />
  print ' Base        | Offset      | Delta       | Count     ';<br />
  print '-------------|-------------|-------------|--------------';<br />
  for base_address in base_addresses:<br />
    offset = base_address - lowest_base_address;<br />
    if previous_base_address is not None:<br />
      delta = base_address - previous_base_address;<br />
      if delta &lt; smallest_delta:<br />
        smallest_delta = delta;<br />
    else:<br />
      delta = 0;<br />
    print ' %11s | %11s | %11s | %d' % ( \<br />
        '0x%08X' % base_address, '+0x%X' % offset, '+0x%X' % delta, \<br />
        base_addresses_counts[base_address]);<br />
    previous_base_address = base_address;<br />
  print '-------------\'-------------\'-------------\'--------------';<br />
  print ' Total runs: %d' % results_count;<br />
  print ' Total different values: %d' % len(base_addresses);<br />
  print ' Smallest delta: 0x%X' % smallest_delta;<br />
  print ' Total possible values: >= %(v)d (%(v)X)' % {'v': offset / smallest_delta};<br />
&nbsp;<br />
</code></p>
<p>Here&#8217;s part of the output of this script:<br />
<code style="color:silver; background-color: black;"><br />
C:\Sample&gt;<a href="http://skypher.com/SkyLined/download/ASLR/analyze.py">analyze.py</a> VM3-V32SP2-N.txt<br />
 Base        | Offset      | Delta       | Count<br />
-------------|-------------|-------------|--------------<br />
  0x75490000 |        +0x0 |        +0x0 | 1<br />
  0x75550000 |    +0xC0000 |    +0xC0000 | 1<br />
  0x75580000 |    +0xF0000 |    +0x30000 | 1<br />
  0x755A0000 |   +0x110000 |    +0x20000 | 2<br />
<span style="color:grey">&lt;snip&gt;</span><br />
  0x77E40000 |  +0x29B0000 |    +0x40000 | 1<br />
  0x77E80000 |  +0x29F0000 |    +0x40000 | 1<br />
  0x77EB0000 |  +0x2A20000 |    +0x30000 | 1<br />
  0x77ED0000 |  +0x2A40000 |    +0x20000 | 2<br />
-------------'-------------'-------------'--------------<br />
 Total runs: 807<br />
 Total different values: 460<br />
 Smallest delta: 0x10000<br />
 Total possible values: &gt;= 676 (2A4)<br />
&nbsp;<br />
C:\Sample&gt;<br />
</code></p>
<p>To clarify: the machine was rebooted to collect another base address 806 times, yielding 807 base addresses. The base addresses were distributed among 460 different values, some values occurring more than once. Because of the number of the tests I performed and the randomness at which the addresses get chosen, it is to be expected that some values occur more often than others and that some values do not occur at all. Based on the lowest and highest value (07549000 and 077ED0000) and the smallest difference between two addresses (10000), I calculate that there are at least 676 different possible values for the base address.</p>
<p>I was a bit surprised by the results. I haven&#8217;t kept up-to-date with ASLR randomness, but IIRC it was 8-bits (256 possible values) last time I checked. Microsoft appears to have increased the randomness of their ASLR implementation in Vista. This makes a brute force attack against ASLR, in which you try all possible values until you find the right one, take longer. This also decreases the chances of success for an attacker that only has one try at guessing the address: a 1/256 chance is bad, a 1/676 chance is worse.</p>
<p>Should you decide to run a similar test, let me know what OS you tested and what values you found!</p>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2010/09/03/exploit-aslr-randomness/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>JsSfx &#8211; JavaScript compression/obfuscation</title>
		<link>http://skypher.com/index.php/2010/08/10/jssfx/</link>
		<comments>http://skypher.com/index.php/2010/08/10/jssfx/#comments</comments>
		<pubDate>Tue, 10 Aug 2010 10:43:02 +0000</pubDate>
		<dc:creator>SkyLined</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://skypher.com/?p=483</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 revisited and released an old tool for compressing and obfuscating JavaScript. Given a JavaScript as input, it will generate and output self-extracting compressed JavaScript.</p>
<p><a href="http://code.google.com/p/jssfx/">http://code.google.com/p/jssfx/<br />
</a></p>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2010/08/10/jssfx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Advances in heap spraying #1: when size matters.</title>
		<link>http://skypher.com/index.php/2010/01/18/advances-in-heap-spraying-size/</link>
		<comments>http://skypher.com/index.php/2010/01/18/advances-in-heap-spraying-size/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 15:08:02 +0000</pubDate>
		<dc:creator>SkyLined</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Internet Explorer]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://skypher.com/?p=146</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><a href="http://skypher.com/SkyLined/heap_spray/small_heap_spray_generator.html">http://skypher.com/SkyLined/heap_spray/small_heap_spray_generator.html</a></p>
<p>I&#8217;ve created a <a href="http://en.wikipedia.org/wiki/Heap_spraying">heap-spray</a> generator. It generates a small piece of JavaScript that sprays the heap using the following customizable settings:<br />
<UL><br />
  <LI><strong>Shellcode</strong>, easy to enter using hexadecimal byte values (see also <a href="http://code.google.com/p/beta3/">BETA3</a>).</LI><br />
  <LI><strong>Target address</strong> and <strong>block size</strong>.</LI><br />
  <LI><strong>heap header size</strong> based on target browsers or manual value.</LI><br />
</UL><br />
The resulting code is smaller than any heap-spray I&#8217;ve seen in the wild:<br />
<UL><br />
  <LI>The heap-spray code itself is <strong>just over 70 bytes</strong>.</LI><br />
  <LI>The shellcode can be encoded using a <strong>custom-build 7-bit encoding</strong>.</LI><br />
</UL><br />
Most exploits contain shellcode encoded as &#8220;\uXXXX&#8221; or even &#8220;%uXXXX&#8221;. The resulting encoded shellcode data contains 3 bytes for every byte in the original shellcode. Because this is very wasteful, it is quite easy to improve on this by creating a custom en-/decoder. The &#8220;7-bit&#8221; encoding I created converts the 16-bit characters in the unicode string that contains the shellcode to a series of 7-bit values, which are encoded into <a href="http://en.wikipedia.org/wiki/ISO/IEC_8859-1">latin-1</a> characters. The resulting encoded shellcode data contains only 1.125 bytes for every byte in the shellcode, a saving of almost 63% compared to conventional encodings.<br />
The heap-spray will of course need some additional code to decode the shellcode, so the combined code+data will only be smaller for large enough shellcodes. Because my decoder is also rather small (just under 130 bytes), the break-even point is just under 70 bytes of shellcode. For a a 100 byte shellcode, you save about 50 bytes and for a 200 bytes shellcode, you save about 200 bytes!</p>
<p>You can try out the heap-spray generator <a href="http://skypher.com/SkyLined/heap_spray/small_heap_spray_generator.html">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2010/01/18/advances-in-heap-spraying-size/feed/</wfw:commentRss>
		<slash:comments>2</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>BETA3 released</title>
		<link>http://skypher.com/index.php/2010/01/02/beta3-released/</link>
		<comments>http://skypher.com/index.php/2010/01/02/beta3-released/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 10:00:14 +0000</pubDate>
		<dc:creator>SkyLined</dc:creator>
				<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://skypher.com/?p=306</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>As part of my <a href="http://skypher.com/index.php/2010/01/02/new-years-resolutions/">New Year&#8217;s resolutions</a>, I am releasing <strong>BETA3</strong>, the follow up to <strong><a href="http://www.milw0rm.com/exploits/656">BETA2</a></strong>. BETA3 is a multi-format shellcode encoding tool that can be used to turn binary shellcode into text for use in exploits. This release has a number of improvements over BETA2, including more different types of encoding, the ability to reverse encoding (== decode encoded shellcode taken from an exploit) and supports more character sets and restrictions.</p>
<p>BETA3 is hosted on Google code <a href="http://code.google.com/p/beta3/">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2010/01/02/beta3-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

