<?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>ReversingLabs &#124; Blog &#187; TitanEngine</title>
	<atom:link href="http://blog.reversinglabs.com/tag/titanengine/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.reversinglabs.com</link>
	<description>Everything in reverse...</description>
	<lastBuildDate>Sat, 02 Jul 2011 10:53:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.4</generator>
		<item>
		<title>BlackHat USA Recap</title>
		<link>http://blog.reversinglabs.com/2010/08/blackhat-usa-recap/</link>
		<comments>http://blog.reversinglabs.com/2010/08/blackhat-usa-recap/#comments</comments>
		<pubDate>Thu, 12 Aug 2010 14:12:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[ReversingLabs]]></category>
		<category><![CDATA[TitanEngine]]></category>
		<category><![CDATA[TitanMist]]></category>
		<category><![CDATA[BlackHat]]></category>

		<guid isPermaLink="false">http://blog.reversinglabs.com/?p=836</guid>
		<description><![CDATA[BlackHat, one of the world's biggest security conferences, was held in Las Vegas two weeks ago. Among the BlackHat conferences this year, Las Vegas was by far the biggest event  - bringing thousands of security researchers to the heart of the Sin City. Bigger then ever before, BlackHat featured eleven tracks with an impressive number [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://blog.reversinglabs.com/wp-content/uploads/2010/08/39840_474324758265_840353265_6835934_4567789_n.jpg" rel="lightbox[836]"><img class="aligncenter size-full wp-image-839" title="BlackHat USA 2010 - Presentation" src="http://blog.reversinglabs.com/wp-content/uploads/2010/08/39840_474324758265_840353265_6835934_4567789_n.jpg" alt="" width="583" height="329" /></a></p>
<p style="text-align: justify;"><a href="http://www.blackhat.com/" target="_blank">BlackHat</a>, one of the world's biggest security conferences, was held in Las Vegas two weeks ago. Among the BlackHat conferences this year, Las Vegas was by far the biggest event  - bringing thousands of security researchers to the heart of the Sin City. Bigger then ever before, BlackHat featured eleven tracks with an impressive number of high quality talks and trainings. We were <a href="http://www.blackhat.com/html/bh-us-10/bh-us-10-briefings.html#Vuksan" target="_blank">there,</a> and we were more than proud to present our newest file analysis tool, <a href="http://blog.reversinglabs.com/2010/07/introducing-titanmist/" target="_blank">TitanMist</a>, to the World.</p>
<p style="text-align: justify;">In a fairly full room, for a reversing track that is, we presented the TitanMist project we have been working on for the past couple of months. Best described as  an automated PE32 file format identification and unpacking tool, TitanMist aims to improve collaboration among reverse engineers across the globe. That is an ambitious goal, but we have high hopes for this project and believe that we can grow it into something of great value in the coming months. Our detailed project roadmap will be unveiled on our blog next week.</p>
<p style="text-align: justify;">The TitanMist presentation was <a href="http://blog.reversinglabs.com/wp-content/uploads/2010/08/38254_471536768265_840353265_6757982_3977018_n.jpg" rel="lightbox[836]"><img class="size-full wp-image-838 alignleft" title="BlackHat USA 2010 - Arsenal" src="http://blog.reversinglabs.com/wp-content/uploads/2010/08/38254_471536768265_840353265_6757982_3977018_n.jpg" alt="" width="259" height="432" /></a>accompanied by the <a href="http://www.blackhat.com/html/bh-us-10/bh-us-10-specialevents_arsenal.html#suvajac" target="_blank">Arsenal</a> presentation that featured all of our tools: <a href="http://blog.reversinglabs.com/titanengine/" target="_blank">TitanEngine</a>, <a href="http://blog.reversinglabs.com/nyxengine/" target="_blank">NyxEngine</a> and <a href="http://blog.reversinglabs.com/titanmist/" target="_blank">TitanMist</a>. This kind of tool demo was introduced at this year's BlackHat USA and we must admit that we like the idea of tool presentations, during which authors receive direct feedback from the community. This feedback enables us to add new features and improve our tools even further. We got  many great ideas from talking to attendees with an interest in our tools and what we do. Ones attendees with particularly intriguing questions or ideas questions were rewarded with one of our <a href="http://blog.reversinglabs.com/2010/07/reversinglabs-summer-challenge/" target="_blank">TitanEngine T-Shirts</a>. But t-shirt winner or not, we thank you all for your continuing support of ReversingLabs and the TitanEngine project!</p>
<p style="text-align: justify;">In the picture on the left you can see our Arsenal booth and one of our senior software engineers, Mario Suvajac. Mario is one of the guys behind the TitanMist project, in charge of the byte pattern matching and overall tool design.</p>
<p style="text-align: justify;">That is it for this report, until next week...</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.reversinglabs.com%2F2010%2F08%2Fblackhat-usa-recap%2F&amp;title=BlackHat%20USA%20Recap" id="wpa2a_2"><img src="http://blog.reversinglabs.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.reversinglabs.com/2010/08/blackhat-usa-recap/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>REcon recap</title>
		<link>http://blog.reversinglabs.com/2010/07/recon-recap/</link>
		<comments>http://blog.reversinglabs.com/2010/07/recon-recap/#comments</comments>
		<pubDate>Wed, 14 Jul 2010 17:12:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[ReversingLabs]]></category>
		<category><![CDATA[ReCon]]></category>
		<category><![CDATA[TitanEngine]]></category>
		<category><![CDATA[Training]]></category>

		<guid isPermaLink="false">http://blog.reversinglabs.com/?p=754</guid>
		<description><![CDATA[RECon party - We got freestyle rapped @ 3:50 We had a great time during this year's REcon Conference last week.  Now it is the time to sort out our impressions. First of all, thanks to all that attended our TitanEngine training and during the course of 3 days learned how to make unpackers with [...]]]></description>
			<content:encoded><![CDATA[<div style="text-align: center;"><a href="http://www.youtube.com/watch?v=0UGVNljKhQs"><img src="http://blog.reversinglabs.com/wp-content/plugins/youtube-with-style/inc/img.php?v=0UGVNljKhQs"></a><br />
<em><a href="http://recon.cx/2010/party.html" target="_blank">RECon party</a> - We got freestyle rapped @ 3:50</em></div>
<p style="text-align: justify;">We had a great time during this year's <a href="http://www.recon.cx" target="_blank">REcon</a> Conference last week.  Now it is the  time to sort out our impressions. First of all, thanks to all that attended our <a href="http://recon.cx/2010/training4.html" target="_blank">TitanEngine training</a> and during the course of 3 days learned how to make unpackers with our engine. We covered coding of both static and dynamic unpackers and showed how to deal with the complex protection options that reverse engineers come across on a daily basis. In addition to training attendees, we also want to thank everyone who grabbed one of our TitanEngine T-shirts to show support for the project. You want one too? Click <a href="http://blog.reversinglabs.com/2010/07/reversinglabs-summer-challenge/">here</a>...</p>
<p style="text-align: justify;">We can, without any false flattering, call REcon our <a href="http://twitter.com/alexsotirov/status/18416332164" target="_blank">favorite small conference</a> and promise to be back next year too! But that doesn't mean that everything went smoothly, as there were some problems with the air conditioning that flooded the conference twitter feed with AC related rants. The heat was so bad that the conference <a href="http://recon.cx/2010/speakers.html#ethical" target="_blank">opening talk</a> dedicated a good amount of time to it. Being slightly older than the average REcon attendee, Richard Thieme, made a parallel between <a href="http://en.wikipedia.org/wiki/Woodstock_Festival" target="_blank">Woodstock</a> and the problems we had. He argued that Woodstock wasn't that great either but that over time it became a myth due to people, rain and mud and that the same can be said about the heat in Montreal which will probably make us say on some later REcon "remember the one when the AC was broken? That one was great!" Because indeed it was, and as the AC problems went away, everyone's will to commune ignited. And the people who  attend the conference on a regular basis are probably the best thing about the conference. Don't get us wrong, the trainings were great, the talks were awesome but it was the people who impressed us the most. And it is these great people that we will meet again in two weeks at <a href="http://www.blackhat.com/html/bh-us-10/bh-us-10-briefings.html#Vuksan" target="_blank">BlackHat US</a>. Until then...</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.reversinglabs.com%2F2010%2F07%2Frecon-recap%2F&amp;title=REcon%20recap" id="wpa2a_4"><img src="http://blog.reversinglabs.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.reversinglabs.com/2010/07/recon-recap/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Everything in one go</title>
		<link>http://blog.reversinglabs.com/2010/07/everything-in-one-go/</link>
		<comments>http://blog.reversinglabs.com/2010/07/everything-in-one-go/#comments</comments>
		<pubDate>Sun, 04 Jul 2010 10:37:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Reversing]]></category>
		<category><![CDATA[TitanEngine]]></category>
		<category><![CDATA[Unpacker]]></category>
		<category><![CDATA[UPX]]></category>
		<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://blog.reversinglabs.com/?p=710</guid>
		<description><![CDATA[When talking about new concepts, its always best to demonstrate them on something everyone is familiar with. In our case that's of-course UPX with which we are fairly familiar. It almost feels like we write one UPX unpacker each week, doesn't it? Today we are presenting an optimization concept that enables us to unpack everything [...]]]></description>
			<content:encoded><![CDATA[<div style="text-align: center;"><a href="http://www.youtube.com/watch?v=g_dQ1xp7AfE"><img src="http://blog.reversinglabs.com/wp-content/plugins/youtube-with-style/inc/img.php?v=g_dQ1xp7AfE"></a></div>
<p style="text-align: justify;">When talking about new concepts, its always best to demonstrate them on something everyone is familiar with. In our case that's of-course <a href="http://upx.sourceforge.net/" target="_blank">UPX</a> with which we are fairly familiar. It almost feels like we write one UPX unpacker each week, doesn't it?</p>
<p style="text-align: justify;">Today we are presenting an optimization concept that enables us to unpack everything in a single go. Now, when talking about file unpacking we always unpack everything in one go, but we never unpack both the main executable module and all of its packed dependencies in a single run. Normally, you wold do this by batching through individual files.  But from a speed perspective, the best optimization imaginable comes from unpacking the main module and all of its dependencies at once. Since <em>TitanEngine </em>wasn't really designed to do that out-of-the-box, it needs just a little bit of help to pull it off.</p>
<p style="text-align: justify;">The problem is the existence of multiple relocation tables, and more importantly multiple import tables. Since TitanEngine was designed to unpack files one at the time, we must do some additional coding around these boundaries to achieve our goal. Compared to a traditional TitanEngine dynamic unpacker, the only difference is the need to collect import table data for modules in one place, and use that data for any module that has reached its entry point jump. The UPX is a special case because it always imports packed file dependencies through the import table. This is, of course, a static way of importing libraries but our approach must be flexible enough to cover both dynamic and static importing.</p>
<p style="text-align: justify;">To achieve our goal we have to scan the main module and all loaded libraries and try to find  the appropriate patterns. Once the patterns are found, we set breakpoints and store info about them so we know which module triggered which callback event. Normally we have three callbacks for UPX unpackers (LoadLibrary, GetProcAddress and EP jump) but since we are doing transverse unpacking we need one more: the load library event custom handler, which determines whether the loaded dependencies are packed with UPX by trying to find the neccessary breakpoint patterns. Even though it is impossible to have more than one module loading at a time, we still need to store the import data because the import tables for the main executable and dependencies might overlap if the modules are loaded dynamically. Once stored, the import info for each module is retrieved when it hits its entry point callback. Relocations aren't really a problem since there is just one module loading at a time, so we can use our "snapshot and compare" model, provided that modules load on non-default image bases. This can be done in numerous ways - one of the easiest is to compile the sample files so that they do that by default (which is considered cheating in the unpacking game), alternatively, we can pre-allocate the memory so that the modules have no choice but to pick another base address. For the purpose of this blog we cheated, in a real world application of this approach you mustn't.</p>
<p style="text-align: justify;">In the real world you will hardly ever see this kind of case but if you do, you now know how to get everything in one go. Until next week...</p>
<p><!-- Facebook Badge START --></p>
<table border="0" cellspacing="0" cellpadding="0" width="600" align="center">
<tbody>
<tr>
<td width="150" align="center" valign="middle"><a style="font-family: &amp;amp;amp; font-size: 11px; font-variant: normal; font-style: normal; font-weight: normal; color: #3b5998; text-decoration: none;" title="TitanEngine" href="http://www.facebook.com/pages/TitanEngine/136818796342291" target="_TOP">TitanEngine</a><br />
<a title="TitanEngine" href="http://www.facebook.com/pages/TitanEngine/136818796342291" target="_TOP"><img style="border: 0px;" src="http://badge.facebook.com/badge/136818796342291.1698.1945128657.png" alt="" width="120" height="144" /></a><br />
<a style="font-family: &amp;amp;amp; font-size: 11px; font-variant: normal; font-style: normal; font-weight: normal; color: #3b5998; text-decoration: none;" href="http://www.reversinglabs.com" target="_TOP">ReversingLabs Corporation</a></td>
<td width="450" align="center" valign="middle"><a href="http://blog.reversinglabs.com/wp-content/uploads/2010/07/RL!deUPX_oneGo.rar">RL!deUPX</a><br />
(package contains the unpacker with source and the samples  used)</td>
</tr>
</tbody>
</table>
<p><!-- Facebook Badge END --></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.reversinglabs.com%2F2010%2F07%2Feverything-in-one-go%2F&amp;title=Everything%20in%20one%20go" id="wpa2a_6"><img src="http://blog.reversinglabs.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.reversinglabs.com/2010/07/everything-in-one-go/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>TitanMist: Your First Step to Reversing Nirvana</title>
		<link>http://blog.reversinglabs.com/2010/06/titanmist-blackhat-usa10/</link>
		<comments>http://blog.reversinglabs.com/2010/06/titanmist-blackhat-usa10/#comments</comments>
		<pubDate>Thu, 24 Jun 2010 13:54:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[ReversingLabs]]></category>
		<category><![CDATA[TitanEngine]]></category>
		<category><![CDATA[BlackHat]]></category>
		<category><![CDATA[TitanMist]]></category>

		<guid isPermaLink="false">http://blog.reversinglabs.com/?p=705</guid>
		<description><![CDATA[Security is notoriously disunited. Every year multiple tools and projects are released and never maintained. TitanMist is its inverse opposite. Built on top of TitanEngine, it provides automation and manages all known and good PEID signatures, unpacking scripts and other tools in one unified tool. TitanMist is the nicely packaged and open source catch-all tool [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Security is notoriously disunited. Every year multiple tools and  projects are released and never maintained. TitanMist is its inverse  opposite. Built on top of <a href="http://reversinglabs.com/products/TitanEngine.php">TitanEngine</a>, it provides automation and  manages all known and good <a href="http://www.peid.info/" target="_blank">PEID</a> signatures, unpacking scripts and other  tools in one unified tool. TitanMist is the nicely packaged and open  source catch-all tool that will become your first line of defense. The  project goes beyond pure tool development. It builds a forum to  share information and reverse-engineering experience built around the  biggest online and collaborative knowledge base regarding software packers.</p>
<p style="text-align: justify;">With the increase in packed and protected malicious payloads,  collaboration and quick response among researchers has become  critical. As new sample numbers are quickly approaching 40M samples per  year, the solution to this problem has to come from reverse-engineers  themselves, integrating their prior and current work. Huge databases of format identification data and  unpacking scripts can be reused to maximize automation. Yet,  where do we find a definite collection of functional tools,  identification signatures and unpacking tools? And how do we integrate  them in a meaningful and accurate way?</p>
<p style="text-align: justify;">Come to this talk to hear how we plan to raise reversing  collaboration to a whole new level with TitanMist. We will address  today's and future challenges, source code, packaging and distribution,  and define your role in making TitanMist the most powerful community  tool for years to come.</p>
<p style="text-align: justify;">This talk will be a <a href="http://www.blackhat.com/html/bh-us-10/bh-us-10-briefings.html#Vuksan" target="_blank">BlackHat</a> exclusive; a launch and demonstration  of TitanMist, a new open-source project based on TitanEngine. All  components will be available for distribution with the conference  materials.</p>
<p style="text-align: justify;">See you in Vegas...</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.reversinglabs.com%2F2010%2F06%2Ftitanmist-blackhat-usa10%2F&amp;title=TitanMist%3A%20Your%20First%20Step%20to%20Reversing%20Nirvana" id="wpa2a_8"><img src="http://blog.reversinglabs.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.reversinglabs.com/2010/06/titanmist-blackhat-usa10/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Unpacking by hooking?</title>
		<link>http://blog.reversinglabs.com/2010/06/unpacking-by-hooking/</link>
		<comments>http://blog.reversinglabs.com/2010/06/unpacking-by-hooking/#comments</comments>
		<pubDate>Sun, 13 Jun 2010 13:31:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Reversing]]></category>
		<category><![CDATA[TitanEngine]]></category>
		<category><![CDATA[Hooks]]></category>
		<category><![CDATA[Unpacker]]></category>
		<category><![CDATA[UPX]]></category>

		<guid isPermaLink="false">http://blog.reversinglabs.com/?p=676</guid>
		<description><![CDATA[Lets try something totally crazy. Lets try dynamic unpacking without total unpacking control, without breakpoints, without any kind of debugging whatsoever. Lets merge our unpacking process with the packer itself, binding them into one unique work-flow that collects information while the packer is executing. It's similar to what we do with debugging - just without [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Lets try something totally crazy. Lets try dynamic unpacking without total unpacking control, without breakpoints, without any kind of debugging whatsoever. Lets merge our unpacking process with the packer itself, binding them into one unique work-flow that collects information while the packer is executing. It's similar to what we do with debugging - just without the debugger. How do we do this? Can we for that matter?</p>
<p style="text-align: justify;">We can, with a little help from TitanEngine's hooking library. The idea is to use our unpacker as a library which will be injected into the packed file during its execution. Such a library would place hooks inside the packer code, redirecting the control flow to our unpacker wherever data collection or execution handling is needed. Those places are usually spots where the packer processes the import table or relocations, jumps to the original entry point, or just switches execution from one layer to another.</p>
<p style="text-align: justify;">What are the benefits of such an approach? Even though its <em>slightly</em> harder to create and test such unpackers, the most notable benefit of unpacking by hooking is total immunity to various anti-debugging tricks used to detect the unpacking process. The only detection applicable to this unpacking scenario is anti-hooking and memory checksumming. The first is hardly ever used in modern protections due to the large number of false positives it gives, which are triggered by the operating system itself, security software and various window skinning applications. The second one is rarely present, and when it is it only covers specific memory regions that correspond to a single protection layer. In conclusion this method of implementing the unpacking process should result in fewer things to worry about.</p>
<p style="text-align: justify;">Implementing this kind of hooking requires building custom functions to process the hook events. This is necessary to maintain the packed program work flow, and is exactly why we preserve the register state with PUSHAD, and if there is a jump affected by our hook, even EFLAGS with PUSHFD. These ASM instructions are embedded in our C code and with the help of naked pre-processor instruction they become the prologue and epilogue of the function. To apply the hooks we use the DLL_PROCESS_ATTACH event. For example if we were to hook the UPX code which loads libraries the hook code flow would look like this:</p>
<p style="text-align: justify;"><a href="http://blog.reversinglabs.com/wp-content/uploads/2010/06/hooking.png" rel="lightbox[676]"><img class="aligncenter size-full wp-image-597" title="Hook Flow" src="http://blog.reversinglabs.com/wp-content/uploads/2010/06/hooking.png" alt="" width="627" height="247" /></a>Since our hooks are 5 bytes we need to "borrow" as many instructions as we need to insert the hook. In this case we are "borrowing" three instructions. These instructions will be executed right after our inserted function is called. This is done to preserve the packer work flow. As you can see from this diagram we are using hooks instead of breakpoints. Therefore these hooks will be placed on at least three places: when UPX calls LoadLibraryA, GetProcAddress and finally once it jumps to the entry point. The most basic sample UPX unpacker is limited to working on executables that don't import functions by ordinals and use the old jump to entry point method. It's quite limited, but it's enough for a proof-of-concept of our technique.</p>
<p style="text-align: justify;">Debugging this kind of unpacker can be rather tricky. This video shows a quick and easy way to do it:</p>
<div style="text-align: center;"><a href="http://www.youtube.com/watch?v=Sub3huN18qI"><img src="http://blog.reversinglabs.com/wp-content/plugins/youtube-with-style/inc/img.php?v=Sub3huN18qI"></a></div>
<p style="text-align: justify;">Since we are creating a hook library unpacker, we also need a loader which will execute the unpacking target and inject the unpacker library in it. This can be done in number of ways but we decided to do it via the debug - detach method. Once both the unpacker hook library and the loader are made, our unpacker is complete. We hope you got the idea on how to use this technique to build your own hooking unpackers from our short blog. Until next week...</p>
<p><!-- Facebook Badge START --></p>
<table border="0" cellspacing="0" cellpadding="0" width="600" align="center">
<tbody>
<tr>
<td width="150" align="center" valign="middle"><a style="font-family: &amp;amp;amp; font-size: 11px; font-variant: normal; font-style: normal; font-weight: normal; color: #3b5998; text-decoration: none;" title="TitanEngine" href="http://www.facebook.com/pages/TitanEngine/136818796342291" target="_TOP">TitanEngine</a><br />
<a title="TitanEngine" href="http://www.facebook.com/pages/TitanEngine/136818796342291" target="_TOP"><img style="border: 0px;" src="http://badge.facebook.com/badge/136818796342291.1698.1945128657.png" alt="" width="120" height="144" /></a><br />
<a style="font-family: &amp;amp;amp; font-size: 11px; font-variant: normal; font-style: normal; font-weight: normal; color: #3b5998; text-decoration: none;" href="http://www.reversinglabs.com" target="_TOP">ReversingLabs Corporation</a></td>
<td width="450" align="center" valign="middle"><a href="http://blog.reversinglabs.com/wp-content/uploads/2010/06/upxHooks.zip">upxHooks</a><br />
(package contains the unpacker with source and the samples  used)</td>
</tr>
</tbody>
</table>
<p><!-- Facebook Badge END --></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.reversinglabs.com%2F2010%2F06%2Funpacking-by-hooking%2F&amp;title=Unpacking%20by%20hooking%3F" id="wpa2a_10"><img src="http://blog.reversinglabs.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.reversinglabs.com/2010/06/unpacking-by-hooking/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Working around checksums</title>
		<link>http://blog.reversinglabs.com/2010/05/working-around-checksums/</link>
		<comments>http://blog.reversinglabs.com/2010/05/working-around-checksums/#comments</comments>
		<pubDate>Tue, 18 May 2010 17:20:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Reversing]]></category>
		<category><![CDATA[ReversingLabs]]></category>
		<category><![CDATA[TitanEngine]]></category>
		<category><![CDATA[checksum]]></category>
		<category><![CDATA[Nexus]]></category>
		<category><![CDATA[tELock]]></category>

		<guid isPermaLink="false">http://blog.reversinglabs.com/?p=620</guid>
		<description><![CDATA[We are going to start today's blog with a short apology about the TitanEngine 2.0.3 availability during last week. Issue was that during certain amount of time during last week the old TitanEngine 2.0.2 was distributed instead of the fresh new version. This happened mainly because we were moving our hosting to a new server [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">We are going to start today's blog with a short apology about the <a href="http://blog.reversinglabs.com/2010/05/titanengine-update/">TitanEngine 2.0.3</a> availability during last week. Issue was that during certain amount of time during last week the old TitanEngine 2.0.2 was distributed instead of the fresh new version. This happened mainly because we were moving our hosting to a new server and mixed-up the TitanEngine packages.  We apologize for any inconvenience this might have caused and urge the users to update to current engine version. With that out of the way we can focus on the task at hand.</p>
<p style="text-align: justify;">We have already talked about fixing the <a href="http://blog.reversinglabs.com/2010/03/fixing-broken-files-with-nexus/">damaged, broken or missing files</a> in several occasions. Based on what we know we created the <a href="http://blog.reversinglabs.com/tag/nexus/">Nexus</a> TitanEngine plugin to deal with cases of missing dependencies and damaged files. Implementing the basic TitanEngine features to correct file abnormalities does however change the file <a href="http://en.wikipedia.org/wiki/Checksum" target="_blank">checksum</a> since modifications  needed to correct detected problems modify file and memory content. And that doesn't go well with software protections that check the file integrity during execution. One of those software protectors is <a href="http://www.softpedia.com/get/Programming/Packers-Crypters-Protectors/Telock.shtml" target="_blank">tELock</a>, and that is the starting point for today's blog. That and a question "How can we work around checksums when file repairing is necessary?".</p>
<p style="text-align: justify;">Luckily for us most software protections only check the file integrity on disk while the memory integrity checks are only limited to protected data and the protection itself. Therefore we only need to worry about the integrity of the file on disk. To be able to fool any software protection integrity check in a generic way we need to know how these checks are performed. Usually is as simple as opening a file, reading its content in a buffer, hashing it with a custom hashing algorithm and checking if the hash is different then the one stored during file protection. So the logical place to catch the integrity checks is by hooking functions used open the file. Most commonly that involves hooking CreateFile API since all protections use it to gain access to protected file.</p>
<p style="text-align: justify;">Hooking an API in a remote process is easy but not very practical since it involves injecting a DLL into the unpacking process and that isn't something we want to do. Other option is to set a breakpoint at the selected API and filter the information returned to the protection. In order to fool the checksum checks we do the following:</p>
<ul>
<li>Detect if the file is broken (Nexus already did this)</li>
<li>Correct the damaged file and produce a backup file (Nexus already did this)</li>
<li>Catch all calls to CreateFileW API to determine when the integrity check is performed</li>
<li>Open a handle to backup file (which is valid for execution since its checksum is unaltered)</li>
<li>Pass the open handle back to protector so that backup file is hashed and its checksum is confirmed</li>
</ul>
<p style="text-align: justify;">Since we only place a breakpoint on CreateFileW API we need to filter the information somehow to make the program open the backup file which is unaltered and therefore has the correct checksum. We can alter the parameter string and possibly corrupt the memory or we can pass the correct handle back to the protection. To do that we open a handle to backup file inside the context of the debugger and duplicate it inside the context of the unpacking process. That new handle is then used by the software protection to read the data from the backup file which successfully fools any integrity check regardless of the checksum algorithm used. We do this handle switch only if the file which the protected file is trying to open is the file we are currently unpacking. Since this method is generic we can use it for any software protection, not just tELock.</p>
<p style="text-align: justify;">To test out theory we intentionally damage the sample file by modifying a single non relevant byte. This damaged file is now named <strong>damaged.exe</strong> and the backup file which is the original one is named <strong>damaged.exe.bak.</strong> If we try to unpack <strong>damaged.exe</strong> file the unpacker will unpack the file correctly regardless of the damage done to the file. This process effectively simulates the scenario in which the Nexus plugin automatically corrects the damaged file. Until next week...</p>
<p><!-- Facebook Badge START --></p>
<table width="600" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="150" align="center" valign="middle"><a style="font-family: &amp;amp;quot; font-size: 11px; font-variant: normal; font-style: normal; font-weight: normal; color: #3b5998; text-decoration: none;" title="TitanEngine" href="http://www.facebook.com/pages/TitanEngine/136818796342291" target="_TOP">TitanEngine</a><br />
<a title="TitanEngine" href="http://www.facebook.com/pages/TitanEngine/136818796342291" target="_TOP"><img style="border: 0px;" src="http://badge.facebook.com/badge/136818796342291.1698.1945128657.png" alt="" width="120" height="144" /></a><br />
<a style="font-family: &amp;amp;quot; font-size: 11px; font-variant: normal; font-style: normal; font-weight: normal; color: #3b5998; text-decoration: none;" title="" href="http://www.reversinglabs.com" target="_TOP">ReversingLabs Corporation</a></td>
<td width="450" align="center" valign="middle">
<p><a href="http://blog.reversinglabs.com/wp-content/uploads/2010/05/NexusChecksum.zip">NexusCheckSum</a><br />
(package contains the plugin with source and the samples  used)</p>
</td>
</tr>
</table>
<p><!-- Facebook Badge END --></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.reversinglabs.com%2F2010%2F05%2Fworking-around-checksums%2F&amp;title=Working%20around%20checksums" id="wpa2a_12"><img src="http://blog.reversinglabs.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.reversinglabs.com/2010/05/working-around-checksums/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Back to the basics</title>
		<link>http://blog.reversinglabs.com/2010/05/back-to-the-basics/</link>
		<comments>http://blog.reversinglabs.com/2010/05/back-to-the-basics/#comments</comments>
		<pubDate>Tue, 11 May 2010 21:33:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Reversing]]></category>
		<category><![CDATA[TitanEngine]]></category>
		<category><![CDATA[LUA]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[Unpacker]]></category>

		<guid isPermaLink="false">http://blog.reversinglabs.com/?p=606</guid>
		<description><![CDATA[Its been a really long time since we made an unpacker for... well anything. Sure we did a format converter and some archive format unpacker but our last PE unpacker was (checks the blog) in February. So, lets get back to the basics and create a dynamic unpacker for PackMan. We already have an unpacker [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Its been a really long time since we made an unpacker for... well anything. Sure we did a <a href="http://blog.reversinglabs.com/2010/04/archive-conversion/">format converter</a> and some <a href="http://blog.reversinglabs.com/2010/04/unpacking-archives-with-titanengine/">archive format unpacker</a> but our last PE unpacker was (<em>checks the blog</em>) in February. So, lets get back to the basics and create a dynamic unpacker for PackMan. We already have an unpacker for PackMan? Its in the TitanEngine package already, you say? Well we do, but what's stopping us from having a little fun with unpacker optimizations?</p>
<p style="text-align: justify;">There are a lot of optimizations one can do with the <em>TitanEngine </em>to make it work even faster then lightning. During the related unpacker execution timing research for our upcoming <a href="http://blog.reversinglabs.com/2010/04/caro-workshop/">CARO Workshop</a> talk we measured the impact that certain operations inside the engine itself have on the total unpacking time. We realized that there is significant space for performance improvement in certain unpacking areas which is especially important when we are processing large file volumes. Now, when unpacking files with unpackers built around the TitanEngine you get unpacker execution times quite similar to the sample execution time, except for cases where dynamic link library unpacking requires snapshots to correct the relocation table. in those cases we see a significant unpacking execution time increase. To counter this we can either do memory snapshots to memory or optimize relocation processing and avoid using snapshots at all.</p>
<p style="text-align: justify;">Generally when talking about fixing relocation table we refer to the easy snap-and-compare method. However there is another way of making the unpacked dynamic link library valid for loading on non default base. We can use RelocaterGrabRelocationTableEx function for cases when the packer uses non modified relocation table, defined as it is in the PECOFF document. Relocation data is still compressed and can only be accessed just before the file is relocated, which is why we need a function to inspect the memory and determine the relocation table size. And that is exactly what RelocaterGrabRelocationTableEx does. It determines the size of the relocation table at the provided address and copies it to the engine for later exporting. If we look at the following PackMan code snippet which does the image relocation:</p>
<pre class="asm">  <span style="color: #EE4A02;">OR</span> <span style="color: #EE1802; font-weight:bold;">ECX</span>,<span style="color: #EE1802; font-weight:bold;">ECX</span>
  <span style="color: #EE4A02;">JE</span> L018
  <span style="color: #EE4A02;">MOV</span> <span style="color: #EE1802; font-weight:bold;">EDI</span>,<span style="color: #DEE002;">DWORD</span> <span style="color: #DEE002;">PTR</span> <span style="color: #EE1802; font-weight:bold;">DS</span>:<span style="color: #FFFFFF;">&#91;</span>EBX<span style="color: #ff0000;">+24</span><span style="color: #FFFFFF;">&#93;</span>
  <span style="color: #EE4A02;">JMP</span> L013
L004:
  <span style="color: #EE4A02;">XOR</span> <span style="color: #EE1802; font-weight:bold;">EAX</span>,<span style="color: #EE1802; font-weight:bold;">EAX</span>
  <span style="color: #EE4A02;">LODS</span> <span style="color: #DEE002;">WORD</span> <span style="color: #DEE002;">PTR</span> <span style="color: #EE1802; font-weight:bold;">DS</span>:<span style="color: #FFFFFF;">&#91;</span><span style="color: #EE1802; font-weight:bold;">ESI</span><span style="color: #FFFFFF;">&#93;</span>
  <span style="color: #EE4A02;">OR</span> <span style="color: #EE1802; font-weight:bold;">EAX</span>,<span style="color: #EE1802; font-weight:bold;">EAX</span>
  <span style="color: #EE4A02;">JE</span> L011
  <span style="color: #EE4A02;">AND</span> <span style="color: #EE1802; font-weight:bold;">AH</span>,0F
  <span style="color: #EE4A02;">ADD</span> <span style="color: #EE1802; font-weight:bold;">EAX</span>,<span style="color: #DEE002;">DWORD</span> <span style="color: #DEE002;">PTR</span> <span style="color: #EE1802; font-weight:bold;">DS</span>:<span style="color: #FFFFFF;">&#91;</span><span style="color: #EE1802; font-weight:bold;">EBX</span><span style="color: #FFFFFF;">&#93;</span>
  <span style="color: #EE4A02;">ADD</span> <span style="color: #DEE002;">DWORD</span> <span style="color: #DEE002;">PTR</span> <span style="color: #EE1802; font-weight:bold;">DS</span>:<span style="color: #FFFFFF;">&#91;</span><span style="color: #EE1802; font-weight:bold;">EDX</span>+<span style="color: #EE1802; font-weight:bold;">EAX</span><span style="color: #FFFFFF;">&#93;</span>,<span style="color: #EE1802; font-weight:bold;">ECX</span>
L011:
  <span style="color: #EE4A02;">CMP</span> <span style="color: #EE1802; font-weight:bold;">ESI</span>,<span style="color: #EE1802; font-weight:bold;">EDI</span>
  <span style="color: #EE4A02;">JNZ</span> L004
L013:
  <span style="color: #EE4A02;">MOV</span> <span style="color: #EE1802; font-weight:bold;">EDX</span>,<span style="color: #DEE002;">DWORD</span> <span style="color: #DEE002;">PTR</span> <span style="color: #EE1802; font-weight:bold;">DS</span>:<span style="color: #FFFFFF;">&#91;</span><span style="color: #EE1802; font-weight:bold;">EDI</span><span style="color: #FFFFFF;">&#93;</span>
  <span style="color: #EE4A02;">LEA</span> <span style="color: #EE1802; font-weight:bold;">ESI</span>,<span style="color: #DEE002;">DWORD</span> <span style="color: #DEE002;">PTR</span> <span style="color: #EE1802; font-weight:bold;">DS</span>:<span style="color: #FFFFFF;">&#91;</span>EDI<span style="color: #ff0000;">+8</span><span style="color: #FFFFFF;">&#93;</span>
  <span style="color: #EE4A02;">ADD</span> <span style="color: #EE1802; font-weight:bold;">EDI</span>,<span style="color: #DEE002;">DWORD</span> <span style="color: #DEE002;">PTR</span> <span style="color: #EE1802; font-weight:bold;">DS</span>:<span style="color: #FFFFFF;">&#91;</span>EDI<span style="color: #ff0000;">+4</span><span style="color: #FFFFFF;">&#93;</span>
  <span style="color: #EE4A02;">TEST</span> <span style="color: #EE1802; font-weight:bold;">EDX</span>,<span style="color: #EE1802; font-weight:bold;">EDX</span>
  <span style="color: #EE4A02;">JNZ</span> L011
L018:
  <span style="color: #EE4A02;">POPAD</span>
&nbsp;</pre>
<p style="text-align: justify;">We can see that the relocation table is stored at EBX+0x24 address. Therefore by reading that memory pointer before the actual relocation occurs we have all the parameters we need to fix the relocation table. Passing that parameter to the RelocaterGrabRelocationTableEx will result in the engine reading the relocation table and estimating its size. Therefore we can just use the pointer we read at the EBX+0x24 address and the return from RelocaterEstimatedSize to correct the PE header for the unpacked file. However RelocaterEstimatedSize doesn't return the accurate size due to the system design. It must be reduced by 8 to be correct for all cases.</p>
<p style="text-align: justify;">Since we are only updating the PE header data we can free the relocation table stored inside the engine with RelocaterCleanup. Once we dump the process relocation table fixing is as easy as updating the PE header fields. By doing the relocation table fixing this way we optimize the speed of execution by a significant percent. No actual data needs to be written to the file on the disk since it is already there and in the correct format. Furthermore you can start the debugging without the previously necessary DLL loading on the address other then default. If you choose to use that optimization as well packer execution time will be shorter since the file might not be relocated at all thus saving CPU cycles. Until next week...</p>
<p><!-- Facebook Badge START --></p>
<table width="600" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="150" align="center" valign="middle"><a style="font-family: &amp;amp;quot; font-size: 11px; font-variant: normal; font-style: normal; font-weight: normal; color: #3b5998; text-decoration: none;" title="TitanEngine" href="http://www.facebook.com/pages/TitanEngine/136818796342291" target="_TOP">TitanEngine</a><br />
<a title="TitanEngine" href="http://www.facebook.com/pages/TitanEngine/136818796342291" target="_TOP"><img style="border: 0px;" src="http://badge.facebook.com/badge/136818796342291.1698.1945128657.png" alt="" width="120" height="144" /></a><br />
<a style="font-family: &amp;amp;quot; font-size: 11px; font-variant: normal; font-style: normal; font-weight: normal; color: #3b5998; text-decoration: none;" title="" href="http://www.reversinglabs.com" target="_TOP">ReversingLabs Corporation</a></td>
<td width="450" align="center" valign="middle">
<p><a href="http://blog.reversinglabs.com/wp-content/uploads/2010/05/PackMan.zip">RL!dePackMan</a><br />
(package contains the unpacker with source and the samples  used)</p>
</td>
</tr>
</table>
<p><!-- Facebook Badge END --></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.reversinglabs.com%2F2010%2F05%2Fback-to-the-basics%2F&amp;title=Back%20to%20the%20basics" id="wpa2a_14"><img src="http://blog.reversinglabs.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.reversinglabs.com/2010/05/back-to-the-basics/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>TitanEngine 2.0.3</title>
		<link>http://blog.reversinglabs.com/2010/05/titanengine-update/</link>
		<comments>http://blog.reversinglabs.com/2010/05/titanengine-update/#comments</comments>
		<pubDate>Mon, 03 May 2010 16:02:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Reversing]]></category>
		<category><![CDATA[TitanEngine]]></category>

		<guid isPermaLink="false">http://blog.reversinglabs.com/?p=590</guid>
		<description><![CDATA[After few months of intense work and code polishing we are proud to present the next major update for the TitanEngine project. Latest update we labeled as TitanEngine 2.0.3. Even though the version incrementation is small the number of changes and the pure size of the code is vast. That is why we dedicate today's [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.reversinglabs.com/wp-content/uploads/2010/05/TE203.png" rel="lightbox[590]"><img class="aligncenter size-full wp-image-597" title="TE203" src="http://blog.reversinglabs.com/wp-content/uploads/2010/05/TE203.png" alt="" width="588" height="226" /></a></p>
<p style="text-align: justify;">After few months of intense work and code polishing we are proud to present the next major update for the <a href="http://www.reversinglabs.com/products/TitanEngine.php" target="_blank">TitanEngine</a> project. Latest update we labeled as TitanEngine 2.0.3. Even though the version incrementation is small the number of changes  and the pure size of the code is vast. That is why we dedicate today's  blog for listing all additions and changes done to the engine. So, what is new?</p>
<p style="text-align: justify;">This update can be declared as a script update as we were driven by the idea that the TitanEngine should be as easy to use as and as widespread as possible. That is why we have extended the programming language support to <a href="http://blog.reversinglabs.com/2009/12/titanengine-on-lua/" target="_blank">LUA</a> and <a href="http://blog.reversinglabs.com/2010/02/titanengine-on-python/" target="_blank">Python</a>, two very popular script languages. Traditionally these script languages execute in a console window with little to no graphical user interface which is why for this update we have integrated easy to use unpacker interface. This interface can be customized to fit your unpacker project and still enables you to use the TitanEngine with any supported script language without the need to make your unpacker a console project. But we didn't stop there, we realized that with more than 400 functions TitanEngine can be overwhelming at first glance. That is why we tried to <a href="http://blog.reversinglabs.com/2010/02/te-simplification-project/" target="_blank">simplify</a> writing the most basic dynamic unpackers, lowering the knowledge barrier to learning only 5 engine's functions.</p>
<p style="text-align: justify;">In addition to this we introduced a way to set any breakpoint type, be it INT3 single or double byte or UD2 breakpoints. This option was present as a global setting in the engine making it possible to set only one breakpoint type at the time. Now you can set different breakpoints for any byte pattern you choose within the same existing breakpoint manipulation functions.</p>
<p>Release without bug fixes is unimaginable. In this release we fixed  all bugs that we are aware of. Thank you for all your reports, you keep <em>TitanEngine </em>with as bugs free as possible.</p>
<p style="text-align: justify;"><strong>*Note:</strong> If you downloaded the old <em>TitanEngine 2.0.2 </em>instead of the new one please re-download the package as there was a small mix-up with the files while moving hosting servers. We apologize for the inconvenience.</p>
<p><strong>TitanEngine 2.0.3 in numbers<br />
</strong></p>
<ul>
<li>405 functions</li>
<li>28,000+ lines of code</li>
<li>44 usage samples</li>
<li>6 supported programming languages</li>
<li>390 pages of documentation</li>
<li>1 <a href="http://www.reversinglabs.com/products/TitanEngine.php" target="_blank">download</a> waiting to happen...</li>
</ul>
<p><a href="http://blog.reversinglabs.com/wp-content/uploads/2009/12/RL.png" rel="lightbox[590]"><img class="aligncenter size-full wp-image-191" title="RL" src="http://blog.reversinglabs.com/wp-content/uploads/2009/12/RL.png" alt="" width="150" height="50" /></a></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.reversinglabs.com%2F2010%2F05%2Ftitanengine-update%2F&amp;title=TitanEngine%202.0.3" id="wpa2a_16"><img src="http://blog.reversinglabs.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.reversinglabs.com/2010/05/titanengine-update/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Unpacking archives with TitanEngine</title>
		<link>http://blog.reversinglabs.com/2010/04/unpacking-archives-with-titanengine/</link>
		<comments>http://blog.reversinglabs.com/2010/04/unpacking-archives-with-titanengine/#comments</comments>
		<pubDate>Mon, 05 Apr 2010 15:01:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Reversing]]></category>
		<category><![CDATA[TitanEngine]]></category>
		<category><![CDATA[BlackHat]]></category>
		<category><![CDATA[DEB]]></category>
		<category><![CDATA[Unpacker]]></category>

		<guid isPermaLink="false">http://blog.reversinglabs.com/?p=471</guid>
		<description><![CDATA[TitanEngine is primarily envisioned as a portable executable file format unpacker and handling framework. However due to its static unpacking functions it can be used to unpack other file format types such as installers and archives. That is why today we are showing the utilization of the new static unpacking functions that will be available [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;"><em>TitanEngine </em>is primarily envisioned as a portable executable file format unpacker and handling framework. However due to its static unpacking functions it can be used to unpack other file format types such as installers and archives. That is why today we are showing the utilization of the new static unpacking functions that will be available with the next update. We are discussing the upcoming features which is something we generally like to avoid but it is for a good reason. It is only because of the unveiling of the new SDK we have secretly been working on during these last few months that we are even touching the archive unpacking subject. What is it and what does it do will be talked about on <a href="http://blackhat.com/html/bh-eu-10/bh-eu-10-briefings.html#Vuksan" target="_blank">BlackHat Europe</a> next week. Until then we will tickle your imagination with an unusual blog about unpacking archives with TitanEngine.</p>
<p style="text-align: justify;">Format we have selected is a simple a <a href="http://www.debian.org/" target="_blank">Debian</a> archive file format called <a href="http://en.wikipedia.org/wiki/Deb_%28file_format%29" target="_blank">Deb</a>. Debian packages (DEB files) are standard Unix <a href="http://en.wikipedia.org/wiki/Ar_%28Unix%29" target="_blank">ar archives</a> that include two gzipped, bzipped or lzmaed <a href="http://en.wikipedia.org/wiki/Tar_%28file_format%29" target="_blank">tar</a> archives: one that holds the control information and another that contains the data. These two files present in the archive are not compressed but instead they are just stored inside the binary package. Each stored item has its own header, which is defined like this:</p>
<blockquote>
<pre class="cpp"><span style="">typedef</span> <span style="">struct</span> DEB_HEADER<span style="color: #FFFFFF;">&#123;</span>
    <span style="">char</span> FileName<span style="color: #FFFFFF;">&#91;</span><span style="color: #0000dd;">16</span><span style="color: #FFFFFF;">&#93;</span>;
    <span style="">char</span> FileTime<span style="color: #FFFFFF;">&#91;</span><span style="color: #0000dd;">12</span><span style="color: #FFFFFF;">&#93;</span>;
    <span style="">char</span> Reserved0<span style="color: #FFFFFF;">&#91;</span><span style="color: #0000dd;">6</span><span style="color: #FFFFFF;">&#93;</span>;
    <span style="">char</span> Reserved1<span style="color: #FFFFFF;">&#91;</span><span style="color: #0000dd;">6</span><span style="color: #FFFFFF;">&#93;</span>;
    <span style="">char</span> Mode<span style="color: #FFFFFF;">&#91;</span><span style="color: #0000dd;">8</span><span style="color: #FFFFFF;">&#93;</span>;
    <span style="">char</span> ItemSize<span style="color: #FFFFFF;">&#91;</span><span style="color: #0000dd;">10</span><span style="color: #FFFFFF;">&#93;</span>;
    <span style="">char</span> TerminateQuote;
    <span style="">char</span> TerminateNewLine;
<span style="color: #FFFFFF;">&#125;</span>DEB_HEADER, *PDEB_HEADER;</pre>
</blockquote>
<p style="text-align: justify;">Preceding the first header which is used to describe the archive is the magic string "!&lt;arch&gt;\n" which is used to identify the binary package type. Therefore unpacking the DEB archive format is essentially reading the archive header and copying the binary content that follows it to the selected folder. Header for each binary content contains the file name and time information which can be used during the unpacking process to restore the packed item to its pre-packing state. Because this file format doesn't employ any compression by itself unpacking the DEB format only refers to extraction of the stored binary content. That content is additionally packed but with a different file format which commonly uses compression to reduce the size of the packed file on disk.</p>
<p style="text-align: justify;">This is just one of the many uses for TitanEngine outside the area of unpacking and processing portable executable file format. As we have seen unpacking archives with TitanEngine is quite possible as long as there is no compression or content decompression is supported by the engine. Keep an eye out for our blog next week when we unveil our super secret project. Until then...</p>
<p><!-- Facebook Badge START --></p>
<table width="600" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="150" align="center" valign="middle"><a style="font-family: &amp;amp;quot; font-size: 11px; font-variant: normal; font-style: normal; font-weight: normal; color: #3b5998; text-decoration: none;" title="TitanEngine" href="http://www.facebook.com/pages/TitanEngine/136818796342291" target="_TOP">TitanEngine</a><br />
<a title="TitanEngine" href="http://www.facebook.com/pages/TitanEngine/136818796342291" target="_TOP"><img style="border: 0px;" src="http://badge.facebook.com/badge/136818796342291.1698.1945128657.png" alt="" width="120" height="144" /></a><br />
<a style="font-family: &amp;amp;quot; font-size: 11px; font-variant: normal; font-style: normal; font-weight: normal; color: #3b5998; text-decoration: none;" title="" href="http://www.reversinglabs.com" target="_TOP">ReversingLabs Corporation</a></td>
<td width="450" align="center" valign="middle">
<p><a href="http://blog.reversinglabs.com/wp-content/uploads/2010/04/DebUnpacker.zip">DEB unpacker</a><br />
(package contains source code, binary unpacker and a sample archive)</p>
</td>
</tr>
</table>
<p><!-- Facebook Badge END --></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.reversinglabs.com%2F2010%2F04%2Funpacking-archives-with-titanengine%2F&amp;title=Unpacking%20archives%20with%20TitanEngine" id="wpa2a_18"><img src="http://blog.reversinglabs.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.reversinglabs.com/2010/04/unpacking-archives-with-titanengine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatic broken file fixing with Nexus</title>
		<link>http://blog.reversinglabs.com/2010/03/fixing-broken-files-with-nexus/</link>
		<comments>http://blog.reversinglabs.com/2010/03/fixing-broken-files-with-nexus/#comments</comments>
		<pubDate>Mon, 29 Mar 2010 11:41:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Reversing]]></category>
		<category><![CDATA[TitanEngine]]></category>
		<category><![CDATA[Nexus]]></category>
		<category><![CDATA[Plugin]]></category>

		<guid isPermaLink="false">http://blog.reversinglabs.com/?p=393</guid>
		<description><![CDATA[In the last couple of years we have seen a drastic increase in numbers of malicious sample we see a day. These numbers are quickly closing to 40M samples a year mark that we expect to see hit this year. That is why the sheer volume of data we are bombarded with each day raises [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">In the last couple of years we have seen a drastic increase in numbers of malicious sample we see a day. These numbers are quickly closing to 40M samples a year mark that we expect to see hit this year. That is why the sheer volume of data we are bombarded with each day raises an important question, where is the relevant data in this sea of information?  And even is all data we have relevant?</p>
<p style="text-align: justify;">Prioritization is the main way of extracting relevant data with the techniques and methods used to highlight interesting information varying from one antivirus company to another. However we can think differently in order to sort this information. We can think in reverse asking ourselves which of this data isn’t interesting. With that question in mind we developed a system to exclude damaged, invalid and broken files from our sample bases. In depth file analysis tell us exactly which files have zero chance of execution on any system flagging them as crapware. But is everything broken to that extent?</p>
<p style="text-align: justify;">If you remember recently we gave you a good idea what to do with <a href="http://blog.reversinglabs.com/2010/01/if-it-aint-broken/">broken files</a> and how to implement <em>TitanEngine </em>statical validity analysis to identify and fix broken files. For this purpose we will update the TitanEngine Nexus plugin to automatically identify and fix broken files. This will extend this plugin functionality from creating missing dynamic link library dependencies to fixing every aspect of the broken inputted file. And since the plugin will work automatically it needs to be compatible with all existing unpackers. To achieve this we must recognize the basic dynamic unpacker model which looks like this:</p>
<p style="text-align: justify;"><a href="http://blog.reversinglabs.com/wp-content/uploads/2010/03/TEDynamicUnpackerLayout.png" rel="lightbox[393]"><img class="aligncenter size-full wp-image-402" title="TEDynamicUnpackerLayout" src="http://blog.reversinglabs.com/wp-content/uploads/2010/03/TEDynamicUnpackerLayout.png" alt="" width="610" height="708" /></a></p>
<p style="text-align: justify;">As we can see from this flow chart all dynamic unpackers share a certain logic model. Perfect place for Nexus to handle the inputted file is at the start of unpacking process which is achieved by hooking TitanEngine's function IsPE32FileValidExW. This function is called before the unpacking process starts by all unpackers and if it estimates the file as invalid or broken unpacking is aborted. So what does our hook need to do? List of steps to do would be:</p>
<ul>
<li>Perform statical validity analysis by calling IsPE32FileValid</li>
<li>Determine if file is valid or not and if it isn't do the following
<ul>
<li>Create a backup for inputted file</li>
<li>Perform statical file fixing by calling FixBrokenPE32FileEx</li>
<li>Validate the file fixing success</li>
<li>Return TRUE</li>
</ul>
</li>
</ul>
<p style="text-align: justify;">But this is just the first step because in order to fix the file the <em>TitanEngine </em>can temporarily disable certain fields by removing them from PE header. To revert these changes we must add another hook to revert these changes. Since we are improving Nexus to automatically correct broken files for dynamic unpackers the function to hook is easily recognized as DumpProcessW. This function is called at the start of the unpacking process finalization, just before the necessary data is exported to file on the disk. That makes this function a perfect place to revert the changes to temporarily disabled PE fields. To do this we just need to call FixBrokenPE32FileEx again with the saved FILE_FIX_INFO structure.</p>
<p style="text-align: justify;">By implementing these changes to TitanEngine's Nexus plugin we convert it to all purpose dynamic unpacker helper module because with its help we can unpack broken files and files that are missing their dependencies. And all this done with no modification to the source code of any unpacker we made in the past. As a demonstration of the plugin capabilities we have attached it and a broken UPX sample file with this blog. Until next week...</p>
<p><!-- Facebook Badge START --></p>
<table width="600" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="150" align="center" valign="middle"><a style="font-family: &amp;amp;quot; font-size: 11px; font-variant: normal; font-style: normal; font-weight: normal; color: #3b5998; text-decoration: none;" title="TitanEngine" href="http://www.facebook.com/pages/TitanEngine/136818796342291" target="_TOP">TitanEngine</a><br />
<a title="TitanEngine" href="http://www.facebook.com/pages/TitanEngine/136818796342291" target="_TOP"><img style="border: 0px;" src="http://badge.facebook.com/badge/136818796342291.1698.1945128657.png" alt="" width="120" height="144" /></a><br />
<a style="font-family: &amp;amp;quot; font-size: 11px; font-variant: normal; font-style: normal; font-weight: normal; color: #3b5998; text-decoration: none;" title="" href="http://www.reversinglabs.com" target="_TOP">ReversingLabs Corporation</a></td>
<td width="450" align="center" valign="middle">
<p><a href="http://blog.reversinglabs.com/wp-content/uploads/2010/03/Nexus.zip">Nexus plugin</a><br />
(package contains Nexus plugin, UPX unpacker and a broken sample file)</p>
</td>
</tr>
</table>
<p><!-- Facebook Badge END --></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.reversinglabs.com%2F2010%2F03%2Ffixing-broken-files-with-nexus%2F&amp;title=Automatic%20broken%20file%20fixing%20with%20Nexus" id="wpa2a_20"><img src="http://blog.reversinglabs.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.reversinglabs.com/2010/03/fixing-broken-files-with-nexus/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

