<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <id>http://www.morenops.com/</id>
  <title>MoreNOPs Feed</title>
  <updated>2011-10-01T22:00:00Z</updated>
  <link rel="alternate" href="http://www.morenops.com/"/>
  <link rel="self" href="http://www.morenops.com/atom.xml"/>
  <author>
    <name>jg</name>
    <uri>http://www.morenops.com</uri>
  </author>
  <entry>
    <id>tag:www.morenops.com,2011-10-02:/2011/10/02/freebsd/kernel/gdb.html</id>
    <title type="html">FreeBSD kernel debugging with GDB</title>
    <published>2011-10-01T22:00:00Z</published>
    <updated>2011-10-03T01:34:58Z</updated>
    <link rel="alternate" href="http://www.morenops.com/2011/10/02/freebsd/kernel/gdb.html"/>
    <content type="html">&lt;p&gt;In today's post we will cover how to build a testing setup (to test kernel mode rootkit components for instance) in a FreeBSD environment. For this matter we'll build a client-server scheme using VMWare and it's serial port emulation capabilities as a bridge between the two machines. In this setup, one of the boxes will act as a debugger and the other one as the debuggee thanks to GDB's remote debugging feature. The exact versions covered in this article are the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;FreeBSD 8.2-RELEASE (i386)&lt;/li&gt;
&lt;li&gt;VMware Workstation 7.1.4 running under Ubuntu 11.04 (amd64)&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;First of all we need to grab a fresh copy of &lt;a href="www.freebsd.org"&gt;FreeBSD&lt;/a&gt;. Once we got our copy ISO file, we create a single new Virtual Machine (VM) with default FreeBSD settings (8GB of disk space + default disk layout should be more than enough for our setup). During the install process we should take care of selecting kernel developer packages as well as the ports system. The rest of the install process is fairly straightforward if we keep &lt;a href="http://www.freebsd.org/doc/handbook/install.html"&gt;this&lt;/a&gt; guide at hand.&lt;/p&gt;

&lt;p&gt;With a fresh system just ready for action, the next step will consist in installing rsync, which we'll use to move compiled source + binaries to the debugger on a later step. To install rsync one of the easiest methods is to go straight into the ports system and building it from there:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;# cd /usr/ports/net/rsync  
# make install
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And after a few seconds of output we will be back in a shell prompt with a fully functioning rsync deployment. Next, we will avoid ourselves the burden of having to install a second VM by making use of VMWare's VM cloning capability. In this case we will perform a full copy so that we get two separate disk images rather than a single linked copy. From now on, one of the VMs will work as a debuggee (VM A) and the other one as debugger (VM B).&lt;/p&gt;

&lt;p&gt;In the next phase, inside VM A we will recompile the kernel such that we enable full debugging capabilities and tracing. For this, we will make a copy of the default kernel compilation configuration file and then add a couple of flags. After completing the kernel &lt;a href="http://www.freebsd.org/doc/handbook/kernelconfig-building.html"&gt;compilation and installing&lt;/a&gt; the new boot image, we will copy the generated debugging kernel + symbols to VM B. Let's begin:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;# cd /usr/src/sys/i386/  
# cp conf/GENERIC conf/MYDEBUGKERNEL  
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;With our favorite text editor we edit MYDEBUGKERNEL and add (note that some of the options might already be enabled and needn't be re-defined):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;DEBUG -g  
OPTION KDB  
OPTION DDB  
OPTION GDB
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And now, it's compile time:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;# cd /usr/src/  
# make buildkernel KERNCONF=MYDEBUGKERNEL  
# make installkernel KERNCONF=MYDEBUGKERNEL  
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;After compilation and installation succeed, we will copy the generated resources to VM B using rsync. Assuming that a folder is ready at /usr/debug in VM B (192.168.45.139 in this case), we pull the trigger:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;# cd /usr/obj/usr/src/sys  
# rsync -avz MYDEBUGKERNEL root@192.168.45.139::/usr/debug  
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The transfer shouldn't take very long. After it's over, we shutdown both machines to let the VM magic begin. By magic, I mean that we will emulate a serial port connection by connecting both machines through a named pipe. Procedure is as follows:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In VM A's tab, right click -&gt; Settings -&gt; Add&lt;/li&gt;
&lt;li&gt;Select "Serial Port" from the list then "output to socket"&lt;/li&gt;
&lt;li&gt;In the next window, choose a filename for the file that will act as a named pipe (e.g. /tmp/com_1)&lt;/li&gt;
&lt;li&gt;Select "From server" to "Virtual Machine"&lt;/li&gt;
&lt;li&gt;That's it. Now repeat the previous steps with VM B but instead of "From Server" choose "From Client"&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;Now that both machines are ready and connected, we can start descending into the catacombs. Fire up both machines. Go to VM A and edit the file /boot/device.hints and change the first serial connection's flag parameter, which in my particular case is "hint.uart.0.flags" to the value "0xC0". Reboot VM A.&lt;/p&gt;

&lt;p&gt;Now shift to VM B and navigate to the directory where we copied the symbols using rsync. From there launch GDB connected to the serial port (serial port device name might not match yours):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;# cd /usr/debug/MYDEBUGKERNEL  
# kgdb -r /dev/cuau0 kernel.debug  
GNU gdb 6.1.1 [FreeBSD]  
Copyright 2004 Free Software Foundation, Inc.  
GDB is free software, covered by the GNU General Public License, and you are  
welcome to change it and/or distribute copies of it under certain conditions.  
Type "show copying" to see the conditions.  
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-marcel-freebsd"...    
switching to remote protocol  
ignoring packet error, continuing...  
Couldn't establish connection to remote target  

(kgdb)  
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Notice at this point how GDB enters a semi-idle state waiting for active connections from VM A. Now back to VM A, directly in the shell we issue:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;# sysctl debug.kdb.enter=1  
debug.kdb.enter: 0KDB: enter: sysctl debug.kdb.enter  
[thread pid 1219 tid 100083]  
Stopped at  kdb_enter+0x3a: movl    $0,kdb_why  
db&amp;gt; gdb  
Step to enter the remote GDB backend.  
db&amp;gt;  
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Notice how now in VM B the debugging prompt changed to an active state. Once we type 's' to step in VM A, the debugger in VM B will break and take control of VM A (with full system control, yay!).&lt;/p&gt;

&lt;p&gt;It's possible to confirm that we're actually debugging VM A by issuing a simple command such as 'bt', which will show the current executing thread's call stack:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;(kgdb) bt  
#0  kdb_enter (why=0xc0c311a6 "sysctl",  
    msg=0xc0cd9a83 sysctl debug.kdb.enter)  
    at /usr/src/sys/kern/subr_kdb.c:354  
#1  0xc08eeaa in kdb_sysctl_enter (oidp=0xc0dbed00, arg1=0x0, arg2=0,  
    req=0xe6c89b74) at /usr/src/sys/kern/subr_kdb.c:174  
    (...output trimmed...)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Happy digging!&lt;/p&gt;
</content>
    <summary type="html">A GDB journey towards FreeBSD's catacombs</summary>
  </entry>
  <entry>
    <id>tag:www.morenops.com,2011-03-21:/2011/03/21/disaster/recovery/plus/plus.html</id>
    <title type="html">Disaster recovery plus plus</title>
    <published>2011-03-20T23:00:00Z</published>
    <updated>2011-06-30T17:17:58Z</updated>
    <link rel="alternate" href="http://www.morenops.com/2011/03/21/disaster/recovery/plus/plus.html"/>
    <content type="html">Apparently a week or so ago my hosting service decided that wordpress wasn't much of his liking and without much explanation the website went down just minutes after I finished a
&lt;a href='http://www.morenops.com/blog/2011/02/24/fuzzing-engine-with-vtrace/' target='_blank'&gt;new post&lt;/a&gt;.
Annoyed by the fact that wordpress required both runtime generation and database backend, and after failing several times trying to put the service back up I decided to switch to this compile-to-static content format. No MySQL, no PHP, no nothing. Fortunately I made fresh SQL dump's from the database just the day before and after several tests I was able to recover all the posts in a XML file.
Anyhow, welcome everyone to the new home and apologies for the downtime.
</content>
    <summary type="html">Holly crap!</summary>
  </entry>
  <entry>
    <id>tag:www.morenops.com,2011-03-08:/2011/03/08/on/python/ruby/and/dangling/handlers.html</id>
    <title type="html">On Python, Ruby and dangling handlers</title>
    <published>2011-03-07T23:00:00Z</published>
    <updated>2011-06-30T17:17:56Z</updated>
    <link rel="alternate" href="http://www.morenops.com/2011/03/08/on/python/ruby/and/dangling/handlers.html"/>
    <content type="html">&lt;a href='http://www.morenops.com/blog/2011/02/24/fuzzing-engine-with-vtrace/' target='_blank'&gt;Last time&lt;/a&gt;
we saw how to build a fuzzing engine with
&lt;strong&gt;Python&lt;/strong&gt;
and
&lt;em&gt;vtrace&lt;/em&gt;.
Unfortunately the implementation I presented in that post generated certain issues once a decent amount of iterations were completed. Apparently Python doesn't like simultaneous thread's launching and finishing every 5 seconds. Analysis with
&lt;strong&gt;Process Explorer&lt;/strong&gt;showed
that although past threads aren't used anymore the garbage collector fails coping with them. This ultimately lead to handle exhaustion (+10000
&lt;em&gt;dangling&lt;/em&gt;thread+file
handles) and subsequent fuzzer crash.
&lt;!-- more --&gt;
A change in the approach failed as well. In this case the second tree architecture tested looked like so:
&lt;ul&gt;
  &lt;li&gt;
    Main fuzz controller
    &lt;ul&gt;
      &lt;li&gt;
        Iteration monitor
        &lt;ul&gt;
          &lt;li&gt;Debuggee&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;
Making extensive use of the
&lt;em&gt;subprocess&lt;/em&gt;module
in this case led to the same result, the only difference in this case is that process handles get leaked instead of thread handles. Somebody might shed more light on this but looks more like a Python garbage collector issue than anything else. Annoyed by this apparent fact, we move onto the next section.
#### Fuzzing engine with Ruby and Ragweed
This seemed like a nice chance to get a good grasp of Ruby and it's low-level foo capabilities. Looking for a already proven programmatic debugging choices are few;
&lt;strong&gt;ragweed&lt;/strong&gt;seems
like the most mature decision. I'm not going to extend myself much on how to get a hand of the tool but I'll point a few steps:
&lt;ol&gt;
  &lt;li&gt;Download the latest package from the FFI branch (0.2.0.pre2 right now).&lt;/li&gt;
  &lt;li&gt;Install any ruby release from the 1.8 branch.&lt;/li&gt;
  &lt;li&gt;Install dependencies (CMD.exe commands):&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote&gt;
  &lt;ul&gt;
    &lt;li&gt;gem install rake&lt;/li&gt;
    &lt;li&gt;cd tduehr-ragweed/&lt;/li&gt;
    &lt;li&gt;gem build ragweed.gemspec&lt;/li&gt;
    &lt;li&gt;gem install ragweedXXXXX.gem&lt;/li&gt;
  &lt;/ul&gt;
&lt;/blockquote&gt;
And that's about it. In this incarnation of the fuzzing engine I followed a slightly different approach to the one described in the beginning:
&lt;ul&gt;
  &lt;li&gt;
    Main fuzz controller
    &lt;ul&gt;
      &lt;li&gt;Debuggee&lt;/li&gt;
      &lt;li&gt;Iteration Monitor&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;
It's worth mentioning that both the
&lt;em&gt;debuggee&lt;/em&gt;and
the
&lt;em&gt;iteration monitor&lt;/em&gt;
are launched as full-fledged processes. The code that accompanies this post is still fairly dirty and definitely not polished, but it works and does NOT leave dangling handlers messing around with OS resources. Also, note that the code is essentially a file fuzzer that lacks certain (albeit fundamental) features like sample logging and so on. This lacking features might make it as a future release
&lt;em&gt;Egurra&lt;/em&gt;,
who knows... :-)
To make the PoC code work you'll need to satisfy a couple more of dependencies, namely:
&lt;ul&gt;
  &lt;li&gt;
    win32-process from
    &lt;a href='http://win32utils.rubyforge.org/' target='_blank'&gt;Win32Utils&lt;/a&gt;.
  &lt;/li&gt;
  &lt;li&gt;
    sys-proctable from
    &lt;a href='http://rubyforge.org/projects/sysutils' target='_blank'&gt;Sys Utils&lt;/a&gt;.
  &lt;/li&gt;
&lt;/ul&gt;

References:
&lt;ul&gt;
  &lt;li&gt;
    &lt;a href='https://github.com/tduehr/ragweed' target='_blank'&gt;ragweed&lt;/a&gt;
    on github.
  &lt;/li&gt;
  &lt;li&gt;&lt;a href='http://www.morenops.com/code/ruzz.zip' target='_blank'&gt;ruby fuzzing engine&lt;/a&gt;.
  &lt;/li&gt;
&lt;/ul&gt;
</content>
    <summary type="html">Handler madness</summary>
  </entry>
  <entry>
    <id>tag:www.morenops.com,2011-02-24:/2011/02/24/fuzzing/engine/with/vtrace.html</id>
    <title type="html">Fuzzing engine with vtrace</title>
    <published>2011-02-23T23:00:00Z</published>
    <updated>2011-06-30T17:17:51Z</updated>
    <link rel="alternate" href="http://www.morenops.com/2011/02/24/fuzzing/engine/with/vtrace.html"/>
    <content type="html">Ever since I first started building my first fuzz-like tools, I always felt that having a solid monitoring engine was a must. While developing
&lt;a href='http://code.google.com/p/egurra/' title='egurra - Google Code'&gt;Egurra&lt;/a&gt;,
and motivated by the learnings from
&lt;a href='http://nostarch.com/ghpython.htm' title='Gray Hat Python'&gt;Gray Hat Python&lt;/a&gt;
by Justin Seitz, I leaned pretty straightforwardly towards
&lt;strong&gt;PyDbg&lt;/strong&gt;.
Unfortunately the component in charge of loading the debuggee in each iteration did so using the
&lt;strong&gt;load()&lt;/strong&gt;
method. This entry point kept failing in an inconsistent fashion, as also confirmed by
&lt;a href='https://www.openrce.org/forums/posts/1331' title='OpenRCE'&gt;other&lt;/a&gt;
users. Even the creator, Pedram Amini itself, acknowledged so in the official documentation (&lt;a href='http://pedram.redhive.com/PaiMei/docs/PyDbg/public/pydbg.pydbg_core.pydbg_core-class.html#load' title='Documentation'&gt;source&lt;/a&gt;):
&lt;!-- more --&gt;
&lt;blockquote&gt;
  &lt;strong&gt;To Do:&lt;/strong&gt;
  This routines needs to be further tested ... I nomally just  attach.
&lt;/blockquote&gt;
Hence, looking for other alternatives two names stuck out for me:
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;PyDbgEng&lt;/strong&gt;: Python wrapper around the official windows debugging engine. Also, current underlying engine for the Peach fuzzer.
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;vtrace&lt;/strong&gt;: VDB is a debugger written using the vtrace API built by Invisigoth from Kenshoto.
  &lt;/li&gt;
&lt;/ul&gt;
Althought PyDbgEng has the richest documentation of the two, I'll cover the latter one for the rest of this article because I got the most consistent results with it.
&lt;em&gt;vtrace&lt;/em&gt;
comes with no documentation at all, aside from the source code itself. This inevitably forces us to take a look at the source in order to get some clues as to what is what and how to build anything useful out of it. Appart from the code,
&lt;strong&gt;atlas&lt;/strong&gt;'s
&lt;em&gt;atlasutils&lt;/em&gt;
came very handy for example reference.
The main class that will support the meat of our debugging entity is the
&lt;strong&gt;Trace&lt;/strong&gt;
class stored in the
&lt;em&gt;vtrace&lt;/em&gt;
folder. Let's see it in action:
&lt;pre lang='python'&gt;def fuzz(exe_path,format):  &amp;#x000A;&amp;#x000A;    print "[*]"&amp;#x000A;    print "[*] Starting fuzzer"&amp;#x000A;    print "[*]"&amp;#x000A;&amp;#x000A;    try:&amp;#x000A;        it = 0&amp;#x000A;        while 1:&amp;#x000A;            print "[*]"&amp;#x000A;            print "[*] running iteration %d" % it&amp;#x000A;            print "[*]"&amp;#x000A;            mutate(format)&amp;#x000A;            me = getTrace()&amp;#x000A;            handler = VerboseNotifier(format)&amp;#x000A;            me.registerNotifier(NOTIFY_SIGNAL,handler)&amp;#x000A;            thread = threading.Thread(target=proc,args=(me,exe_path,format))&amp;#x000A;            thread.setDaemon(0)&amp;#x000A;            thread.start()&amp;#x000A;            time.sleep(5)&amp;#x000A;            if me.isRunning():&amp;#x000A;                print "[*]"&amp;#x000A;                print "[*] killing process %d " % me.getPid()&amp;#x000A;                print "[*]"&amp;#x000A;                me.kill()&amp;#x000A;            time.sleep(1)&amp;#x000A;            it += 1&amp;#x000A;&amp;#x000A;    except KeyboardInterrupt:&amp;#x000A;        print "[*]"&amp;#x000A;        print "[*] Closing fuzzing session, %d iterations completed." % it&amp;#x000A;        print "[*]"&amp;#x000A;        sys.exit(0)In this block we instantiate a Trace entity calling&lt;/pre&gt;
&lt;strong&gt;getTrace()&lt;/strong&gt;
. In the next two lines, we register a handler for SIGNAL events inside the debugged process, which we'll cover deeply latter on. In this context,
&lt;em&gt;format&lt;/em&gt;refers
to the file format currently being fuzzed. Apart from that, the rest of the code is standard Python threading code: Launch a debugging thread and wait for 5 seconds and then check if the process is still running (hence, no crash) and kill it if that's the case.
In the following code, we will take a quick glance at the
&lt;em&gt;proc&lt;/em&gt;
function that will launch the debugged app:
&lt;pre lang='python'&gt;def proc(dbg,exe_path,format):&amp;#x000A;    dbg.execute(exe_path+" test.%s" % format)&amp;#x000A;    dbg.run()No voodoo here either, just load the executable and let it run.&amp;#x000A;&lt;/pre&gt;
Finally we will cover the most juicy aspect of all this process, the signaling and exception handling. For this matter, althought not the most elegant and most correct solution, I opted for tweaking directly some code in the vtrace libs. The following tweaks happened inside
&lt;em&gt;vtrace/notifiers.py&lt;/em&gt;:
&lt;pre lang='python'&gt;class VerboseNotifier(Notifier):&amp;#x000A;    def __init__(self,format):&amp;#x000A;        self.format = format&amp;#x000A;&amp;#x000A;    def notify(self, event, trace):&amp;#x000A;        dict = trace.getMeta("Win32Event")&amp;#x000A;        if dict['ExceptionCode'] == 0xC0000005L:&amp;#x000A;            print "[*] Access violation spotted!"&amp;#x000A;            stamp = time.localtime()&amp;#x000A;&amp;#x000A;            fd = open("crashes\\crash-%s.log" % stamp, "w")&amp;#x000A;            fd.write("ESP: 0x%08x" % trace.getRegisterByName('esp'))&amp;#x000A;            fd.write("\n")&amp;#x000A;            fd.write("EIP: 0x%08x" % trace.getProgramCounter())&amp;#x000A;            fd.write("\n")&amp;#x000A;            fd.write(repr(trace.getMeta("Win32Event")))&amp;#x000A;            fd.close()&amp;#x000A;&amp;#x000A;            shutil.copy("test.%s" % self.format, "crashes\\%s.%s" % (stamp,self.format))&amp;#x000A;&amp;#x000A;            trace.kill()&amp;#x000A;        else:&amp;#x000A;            print "[*] First chance...passing over."&amp;#x000A;            trace.setMode("RunForever", True)&lt;/pre&gt;
&lt;strong&gt;VerboseNotifier()&lt;/strong&gt;
is, as the name implies, a very informative type of Notifier. It simply spits out generic information regarding every event that happens inside the debugged process.
In this particular case we are interested in catching
&lt;em&gt;ACCESS_VIOLATION&lt;/em&gt;
exceptions only. Every time a event happens inside the debugged process, the
&lt;strong&gt;notify()&lt;/strong&gt;
routine will be referenced with the parameters properly populated. All we need to do is check whether the event was
&lt;em&gt;ACCESS_VIOLATION&lt;/em&gt;
exception or not. If this is the case, we will log both the crash and the sample file for latter analysis. Yet again, the
&lt;em&gt;format&lt;/em&gt;parameter
refers to the file format being fuzzed, pure convenience.
Althought we focused on a particular use case here, vtrace contains A LOT of functionality and could definitely be used in a lot of different scenarios.
Happy hunting!
&lt;span style='text-decoration: underline;'&gt;References:&lt;/span&gt;
&lt;ul&gt;
  &lt;li&gt;
    &lt;a href='http://atlas.r4780y.com' title='atlas wandering'&gt;atlas wandering&lt;/a&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;a href='http://www.youtube.com/watch?v=BiOXLRbDpOQ' title='DEFCON 16: VulnCatcher: Fun with Vtrace and Programmatic Debugging '&gt;DEFCON 16: VulnCatcher: Fun with Vtrace and Programmatic Debugging&lt;/a&gt;
    (&lt;em&gt;Youtube Video&lt;/em&gt;)
  &lt;/li&gt;
  &lt;li&gt;
    &lt;a href='http://code.google.com/p/vtrace-mirror/' title='vtrace GoogleCode'&gt;vtrace&lt;/a&gt;
    (&lt;em&gt;GoogleCode mirror&lt;/em&gt;)
  &lt;/li&gt;
  &lt;li&gt;
    &lt;a href='http://pydbgeng.sourceforge.net/' title='PyDbgEng'&gt;PyDbgEng&lt;/a&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</content>
    <summary type="html">vtrace fuzzing</summary>
  </entry>
  <entry>
    <id>tag:www.morenops.com,2010-11-16:/2010/11/16/internet/explorer/cliprect0/memory/corruption/vulnerability.html</id>
    <title type="html">Internet Explorer clip:rect(0) Memory Corruption Vulnerability</title>
    <published>2010-11-15T23:00:00Z</published>
    <updated>2011-06-30T17:57:41Z</updated>
    <link rel="alternate" href="http://www.morenops.com/2010/11/16/internet/explorer/cliprect0/memory/corruption/vulnerability.html"/>
    <content type="html">Today we're going to talk about a currently unpatched vulnerability in IE reportedly affecting versions 6/7/8. In this brief analysis we're going to focus on Internet Explorer version 7.0.5730.13 in Windows XP SP3. This bug tagged CVE-2010-3962, made it into the public because apparently it was found being actively exploited in the wild (&lt;a href='http://www.symantec.com/connect/blogs/new-ie-0-day-used-targeted-attacks' target='_blank'&gt;SYMANTEC&lt;/a&gt;). Trigger code has been widely published in many sites, and for documentation purposes, it's reproduced here:
&lt;!-- more --&gt;
&lt;code&gt;&lt;table&lt;/code&gt;
&lt;code&gt;style&lt;/code&gt;
&lt;code&gt;=&lt;/code&gt;
&lt;code&gt;position&lt;/code&gt;
&lt;code&gt;:absolute;clip:rect(0)&gt;&lt;/code&gt;
There isn't much to say about it. It's seems that the
&lt;a href='http://www.w3.org/TR/CSS2/visufx.html#clipping' target='_blank'&gt;original&lt;/a&gt;
purpose of this properties (besides allowing system compromise :-), is to manipulate table borders in certain elements. But do we care about fancy HTML shapes here? not really... The essence of the bug lies in the implementation of certain methods inside
&lt;strong&gt;mshtml.dll&lt;/strong&gt;,
the HTML rendering engine in Windows. First we need to look at
&lt;strong&gt;CTableLayoutBlock::EnsureTableDispNode&lt;/strong&gt;
which allocates a new object:
&lt;pre lang='asm'&gt;.text:7E9A93E5                 push    esi&amp;#x000A;.text:7E9A93E6                 lea     eax, [ebx+0Ch]&amp;#x000A;.text:7E9A93E9                 push    eax&amp;#x000A;.text:7E9A93EA                 call    ?New@CDispContainer@@SGPAV1@PAVCDispClient@@K@Z ; CDispContainer::New(CDispClient *,ulong)&amp;#x000A;.text:7E9A93EF                 mov     esi, eax&amp;#x000A;.text:7E9A93F1                 test    esi, esi&amp;#x000A;.text:7E9A93F3                 jz      loc_7E9EA792&amp;#x000A;.text:7E9A93F9                 or      dword ptr [esi+4], 40000000h&amp;#x000A;.text:7E9A9400                 mov     ecx, [ebx+8]Next, this very object gets passed to&lt;/pre&gt;
&lt;strong&gt;CDispNode::SetUserClip&lt;/strong&gt;
inside the same
&lt;strong&gt;CTableLayoutBlock::EnsureTableDispNode&lt;/strong&gt;
function:
&lt;pre lang='asm'&gt;.text:7E9EA691                 xor     eax, eax&amp;#x000A;.text:7E9EA693                 mov     [ebp+var_9C], eax&amp;#x000A;.text:7E9EA699                 mov     [ebp+var_A0], eax&amp;#x000A;.text:7E9EA69F                 mov     [ebp+var_A4], eax&amp;#x000A;.text:7E9EA6A5                 mov     [ebp+var_A8], eax&amp;#x000A;.text:7E9EA6AB                 lea     eax, [ebp+var_A8]&amp;#x000A;.text:7E9EA6B1                 push    eax&amp;#x000A;.text:7E9EA6B2                 mov     ecx, esi ; our object&amp;#x000A;.text:7E9EA6B4                 call    ?SetUserClip@CDispNode@@QAEXABUtagRECT@@@Z ; CDispNode::SetUserClip(tagRECT const &amp;)And here comes the funny part. Inside&lt;/pre&gt;
&lt;strong&gt;CDispNode::SetUserClip&lt;/strong&gt;
the
&lt;em&gt;vftable&lt;/em&gt;
address gets dereferenced and OR'ed with 0x1, corrupting the table as a result:
&lt;pre lang='asm'&gt;.text:7EA3FB95                 mov     eax, edi ; load object in eax&amp;#x000A;.text:7EA3FB97                 shl     ecx, 2&amp;#x000A;.text:7EA3FB9A                 sub     eax, ecx&amp;#x000A;.text:7EA3FB9C                 or      dword ptr [eax], 1 ; BUG!&amp;#x000A;.text:7EA3FB9F                 mov     eax, [edi+4]Once we have a corrupted entity, we need to actually call any method in the&lt;/pre&gt;
&lt;em&gt;vftable&lt;/em&gt;
because it will point to corrupted memory. This happens inside
&lt;strong&gt;CTableLayout::CalculateLayout&lt;/strong&gt;:
&lt;pre lang='asm'&gt;.text:7E9A9604                 mov     ecx, [ebp+corruptObj_ptr]&amp;#x000A;.text:7E9A9607                 and     [ebp+var_8], 0&amp;#x000A;.text:7E9A960B                 lea     edx, [ebp+var_8]&amp;#x000A;.text:7E9A960E                 mov     [ebp+var_4], eax&amp;#x000A;.text:7E9A9611                 mov     eax, [ecx]      ; vtable[0]&amp;#x000A;.text:7E9A9613                 push    edx&amp;#x000A;.text:7E9A9614                 call    dword ptr [eax+44h] ; PWN!&amp;#x000A;.text:7E9A9617                 jmp     loc_7E8A3954As many other researchers pointed out this bug is a bit difficult to exploit reliably because it depends largely on mshtml.dll's version (7.0.5730.13 was used here). Heap Spray anyone?&amp;#x000A;&lt;/pre&gt;
Links:
&lt;ul&gt;
  &lt;li&gt;
    &lt;a href='http://www.exploit-db.com/exploits/15421/'&gt;http://www.exploit-db.com/exploits/15421/&lt;/a&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;a href='http://www.microsoft.com/security/portal/Threat/Encyclopedia/Entry.aspx?Name=Exploit:Win32/CVE-2010-3962.A'&gt;http://www.microsoft.com/security/portal/Threat/Encyclopedia/Entry.aspx?Name=Exploit:Win32/CVE-2010-3962.A&lt;/a&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;a href='http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2010-3962'&gt;http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2010-3962&lt;/a&gt;
  &lt;/li&gt;
&lt;/ul&gt;
P.D: While I was writing this I noticed that the guys at
&lt;a href='http://hdlsec.com/exploiting/process-continuation-after-exploit-aka-internet-explorer-is-my-process-launcher/' target='_blank'&gt;hdlsec.com&lt;/a&gt;
had a nice work relating to this very vulnerability. Unfortunately their site seems to be down, suggested read when it's running again.
</content>
    <summary type="html">IE bug analysis</summary>
  </entry>
</feed>
