<?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; Reversing</title>
	<atom:link href="http://blog.reversinglabs.com/category/reversing/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>Constant Insecurity: Things you didn&#8217;t know about (PE) Portable Executable file format</title>
		<link>http://blog.reversinglabs.com/2011/07/constant-insecurity-things-you-didnt-know-about-pe-portable-executable-file-format/</link>
		<comments>http://blog.reversinglabs.com/2011/07/constant-insecurity-things-you-didnt-know-about-pe-portable-executable-file-format/#comments</comments>
		<pubDate>Sat, 02 Jul 2011 10:53:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[Reversing]]></category>
		<category><![CDATA[ReversingLabs]]></category>

		<guid isPermaLink="false">http://blog.reversinglabs.com/?p=919</guid>
		<description><![CDATA[One constant challenge of modern security will always be the difference between published and implemented specifications. Evolving projects, by their very nature, open up a host of exploit areas and implementation ambiguities that cannot be fixed. As such, complex documentation such as that for PECOFF or PDF are goldmines of possibilities. In this talk we [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">One constant challenge of modern security will always be the  difference between published and implemented specifications. Evolving  projects, by their very nature, open up a host of exploit areas and  implementation ambiguities that cannot be fixed. As such, complex  documentation such as that for PECOFF or PDF are goldmines of  possibilities.</p>
<p style="text-align: justify;">In this talk we will disclose our recent findings about never before  seen PE or Portable executable format malformations. These findings have  serious consequences on security and reverse engineering tools and lead  to multiple exploit vectors.</p>
<p style="text-align: justify;">PE is the main executable image file format on Windows operating system  since its introduction in Windows NT 18 years ago. PE file format itself  can be found on numerous Windows-based devices including PCs, mobile  and gaming devices, BIOS environments and others. Its proper  understanding is the key for securing these platforms. The talk will focus on all aspects of PE file format parsing that leads  to undesired behavior or prevents security and reverse engineering tools  from inspecting malformated files due to incorrect parsing. Special  attention will be given to differences between PECOFF documentation and  the actual implementation done by the operating system loader. With  respect to these differences we will demonstrate existence of files that  can't possibly be considered valid from a documentation standpoint but  which are still correctly processed and loaded by the operating system.  These differences and numerous design logic flaws can lead to PE  processing errors that have serious and hardly detectable security  implications. Effects of these PE file format malformations will be  compared against several reverse engineering tools, security  applications and unpacking systems. Special attention will be given to following PE file format aspects and  their malformation consequences:</p>
<ul style="text-align: justify;">
<li> General PE header layout in respect to data positioning and  consequences of different memory model implementations as specified by  PECOFF documentation. Use of multiple PE headers in a single file along  with self-destructing headers.</li>
<li> Alignment fields with their impact on disk and memory layout with  the section layout issues that can occur due to disk or memory data  overlapping or splicing. In addition to this, section table content will  be inspected for issues of data hiding and its limits will be tested  for upper and lower content boundaries. We will demonstrate how such  issues affect existing static and dynamic PE unpacking systems.</li>
<li> Data tables, including imports and exports, will be discussed in  detail to show how their malformated content can break analysis tools  but is still considered valid from the operating system loader  standpoint. We will demonstrate existence of files that can miss use  existing PE features in order to cloak important file information and  omit reverse engineering process. Furthermore based upon these methods a  unique undetectable method of API hooking that requires no code for  hooks insertion will be presented.</li>
<li> PE file format will be inspected for integer overflows and we will  show how their presence can lead to arbitrary code execution in  otherwise safe analysis environments. We will show how PE fields  themselves could be used to deliver code payload resulting in a  completely new field of programming; via the file format itself.</li>
<li> In addition to single field and table malformations more complex  ones involving multiple fields and tables will also be discussed. As a  demonstration of such use case scenario a unique malformation requiring  multiple fields working together to establish custom file encryption  will be presented. This simple, yet effective, encryption that is  reversed during runtime by the operating system loader itself requires  no code in the malformated binary itself to be executed. Its  effectiveness is in a unique approach to encryption trough file format  features themselves in order to prevent static and dynamic file analysis  tools from processing such files.</li>
</ul>
<p style="text-align: justify;">This talk will be a Black Hat exclusive; Whitepaper accompanying the  presentation materials will contain detailed description of all  malformations discussed during the talk. This whitepaper aims to be a  mandatory reading material for security analysts. It will continue to be  maintained as new information on PE format malformations are  discovered.</p>
<p style="text-align: justify;">More information <a href="http://blackhat.com/html/bh-us-11/bh-us-11-briefings.html#Vuksan" target="_blank">here</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%2F2011%2F07%2Fconstant-insecurity-things-you-didnt-know-about-pe-portable-executable-file-format%2F&amp;title=Constant%20Insecurity%3A%20Things%20you%20didn%26%238217%3Bt%20know%20about%20%28PE%29%20Portable%20Executable%20file%20format" 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/2011/07/constant-insecurity-things-you-didnt-know-about-pe-portable-executable-file-format/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Reversing software compressions: Tale of dragons and men who slay them</title>
		<link>http://blog.reversinglabs.com/2011/07/tale-of-dragons-and-men-who-slay-them/</link>
		<comments>http://blog.reversinglabs.com/2011/07/tale-of-dragons-and-men-who-slay-them/#comments</comments>
		<pubDate>Sat, 02 Jul 2011 10:50:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[Reversing]]></category>
		<category><![CDATA[TitanEngine]]></category>

		<guid isPermaLink="false">http://blog.reversinglabs.com/?p=917</guid>
		<description><![CDATA[Reverse engineering compressed binaries has been a necessity for more than a two decades now, and we as reverse engineers are always on a lookout for newest and fastest ways of accomplishing our goal. In that spirit numerous presentations, during the last few years, have been held involving the great abundance of ways one can [...]]]></description>
			<content:encoded><![CDATA[<div style="text-align: justify;">Reverse engineering compressed binaries has been a necessity for more  than a two decades now, and we as reverse engineers are always on a  lookout for newest and fastest ways of accomplishing our goal. In that  spirit numerous presentations, during the last few years, have been held  involving the great abundance of ways one can make a single generic  solution that unpacks it all. This presentation is its exact opposite as  it will focus on reverse engineering specifics for numerous commonly  used software compressions.</div>
<div style="text-align: justify;">
<p>When building a system for automated file analysis our goal is to  make an optimal system that accurately identifies files and unpacks them  in the blink of an eye. Such system must be able to be deployed in any  environment without the risk of anything going even remotely wrong. That  kind of requirements eliminate most generic unpacking solutions making  us focus on what is without a doubt hardest unpacking scenario; static  unpacking. Writing static unpackers is a hard task which is why it is  more than often avoided by reverse engineers. However it is necessary as  their performance far overtakes the difficulty of implementation.</p>
<p>We will focus on reverse engineering of all known and possible  implementations of various transformations performed by the compression  solution in an aim to show that the best way to observe the software  compression is as subset of its parts. Detailed descriptions of reverse  engineering procedures needed to analyze internal data structures along  with ways to restore them to original PECOFF format will be provided.  These techniques will be applied to both custom and traditional  compression &amp; encryption algorithms with examples that shows how to  reverse engineer vital functions from assembly back to source code. In  addition to this first step in reversing we will tackle the problems of  data layout and import, resource, relocation and TLS table  transformation and analysis. Differences between x86, x64 and .net  packers and the ways to unpack them will also be covered. Solution to  all of these problems will be presented from a standpoint of writing a  high load static unpacker that operates in a multi-threaded environment.  As an implementation platform upcoming TitanEngine3 unique design will  be presented along with approach it uses to solve the problems that come  with writing static unpackers.</p>
<p>More information <a href="http://recon.cx/2011/schedule/events/118.en.html" target="_blank">here</a>.</p>
</div>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.reversinglabs.com%2F2011%2F07%2Ftale-of-dragons-and-men-who-slay-them%2F&amp;title=Reversing%20software%20compressions%3A%20Tale%20of%20dragons%20and%20men%20who%20slay%20them" 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/2011/07/tale-of-dragons-and-men-who-slay-them/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reverse engineering software protections</title>
		<link>http://blog.reversinglabs.com/2011/07/reversing-software-protections/</link>
		<comments>http://blog.reversinglabs.com/2011/07/reversing-software-protections/#comments</comments>
		<pubDate>Sat, 02 Jul 2011 10:46:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[Reversing]]></category>
		<category><![CDATA[TitanEngine]]></category>

		<guid isPermaLink="false">http://blog.reversinglabs.com/?p=915</guid>
		<description><![CDATA[Learn how to do in depth analysis of compressed and encrypted binary files. Attendees will receive hands-on experience working with the tools designed to do static and dynamic analysis of the PECOFF file format and formats derived from it covering both x86 and x64 platforms. Instructors: Tomislav Pericin and Nicolas Brulez Dates: 6-7 July 2011 [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Learn how to do in depth analysis of compressed and encrypted binary  files. Attendees will receive hands-on experience working with the tools  designed to do static and dynamic analysis of the PECOFF file format  and formats derived from it covering both x86 and x64 platforms.</p>
<p style="text-align: justify;">Instructors: Tomislav Pericin and Nicolas Brulez<br />
Dates: 6-7 July 2011<br />
Availability: 20 Seats</p>
<h3 style="text-align: justify;">Day 1: Inside the PECOFF file format</h3>
<p style="text-align: justify;">During the first day of the training we will focus on reviewing the  PECOFF file format and examining its aspects to determine the structures  and tables most commonly compressed and protected by PE modifiers.  General memory models used by all known PE format modifiers will be  described based upon which software compressions will be classified into  groups. Key features of crypters, packers and protectors will be  analyzed on real world samples and the most representative formats will  be manually unpacked.</p>
<p style="text-align: justify;">PE file format properties obscured by the format modifier will be  discussed. These properties include import, export, resource, relocation  and tls tables and the ways that PE modifiers transform them from  standard PECOFF to packer specific formats. By applying reverse  engineering techniques we will decipher these internal packer specific  formats and restore them to their original state. In addition to this  attendees will learn how to reverse engineer custom compression and  encryption algorithms and implement them in their code in order to  produce fully functional format unpackers. Special attention will be  given to static unpacker coding layout and the benefits of using  TitanEngine to minimize the time it takes to create an unpacker.</p>
<p style="text-align: justify;">Attendees will learn how to identify and reverse engineer key PE file  format modifier sections. Single PE packer format that supports  x86/x64/.net packing will be inspected in detail for which static  unpacker will be coded.</p>
<h3 style="text-align: justify;">Day 2: Inside the nightmares of file analysis</h3>
<p style="text-align: justify;">During the second day of the training we will focus on analyzing and  unpacking complex software protections. Special attention will be given  to methods used to harden against format reverse engineering and prevent  unpacking. We will describe common protection techniques utilized by  both legitimate software protectors and those specifically designed for  use in malware. We will then use information to show coding techniques  needed for such complex static unpackers and ways to counter all the  tricks used to harden detection, analysis and unpacking.</p>
<p style="text-align: justify;">Single PE protection format will be inspected in detail for which dynamic and/or static unpackers will be coded.</p>
<h3 style="text-align: justify;">Class Requirements</h3>
<p style="text-align: justify;">Very basic knowledge of C/C++ or any other programming language.<br />
Very basic understanding of assembly, debugging and Windows internals.<br />
OllyDBG 1.10 and IDA Pro 5 (free version will be sufficient).<br />
Microsoft Visual Studio 2008 (express will be sufficient).<br />
Additional tools and scripts will be provided by the instrutor.</p>
<p style="text-align: justify;">More information <a href="http://recon.cx/2011/training4.html" target="_blank">here</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%2F2011%2F07%2Freversing-software-protections%2F&amp;title=Reverse%20engineering%20software%20protections" 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/2011/07/reversing-software-protections/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Combat reverse engineering</title>
		<link>http://blog.reversinglabs.com/2010/09/combat-reverse-engineering/</link>
		<comments>http://blog.reversinglabs.com/2010/09/combat-reverse-engineering/#comments</comments>
		<pubDate>Mon, 06 Sep 2010 17:55:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Reversing]]></category>
		<category><![CDATA[Malware analysis]]></category>
		<category><![CDATA[Rogue AV]]></category>
		<category><![CDATA[Unpacking]]></category>

		<guid isPermaLink="false">http://blog.reversinglabs.com/?p=883</guid>
		<description><![CDATA[Reverse engineering is the only weapon of choice when it comes to malware unpacking and analysis. It gives us an inside look into the malware creations and enables us to understand their ins and outs. One such malicious sample was sent to us today for analysis. The file in question is an update for a [...]]]></description>
			<content:encoded><![CDATA[<div style="text-align: center;"><a href="http://www.youtube.com/watch?v=wC51TQvsNWU"><img src="http://blog.reversinglabs.com/wp-content/plugins/youtube-with-style/inc/img.php?v=wC51TQvsNWU"></a></div>
<p style="text-align: justify;">
<p style="text-align: justify;"><a href="http://en.wikipedia.org/wiki/Reverse_engineering" target="_blank">Reverse engineering</a> is the only weapon of choice when it comes to <a href="http://en.wikipedia.org/wiki/Malware" target="_blank">malware</a> unpacking and analysis. It gives us an inside look into the malware creations and enables us to understand their ins and outs. One such malicious sample was sent to us today for analysis. The file in question is an update for a <a href="http://en.wikipedia.org/wiki/Rogue_security_software" target="_blank">rogue anti-virus solution</a> and it uses an interesting encryption and packing options to hide its presence from legitimate security software solutions. For our today's blog we demonstrate the actions needed to remove the protections utilized by malicious software in order to get to the core malware functionality. 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%2F09%2Fcombat-reverse-engineering%2F&amp;title=Combat%20reverse%20engineering" 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/09/combat-reverse-engineering/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ReversingLabs Summer Challenge</title>
		<link>http://blog.reversinglabs.com/2010/07/reversinglabs-summer-challenge/</link>
		<comments>http://blog.reversinglabs.com/2010/07/reversinglabs-summer-challenge/#comments</comments>
		<pubDate>Wed, 14 Jul 2010 17:28:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[Reversing]]></category>
		<category><![CDATA[ReversingLabs]]></category>
		<category><![CDATA[Challenge]]></category>
		<category><![CDATA[NyxEngine]]></category>

		<guid isPermaLink="false">http://blog.reversinglabs.com/?p=770</guid>
		<description><![CDATA[Looks cool? Want one? All you have to do is solve this challenge and tell us what is the password we seek. Sounds easy? Its not... Mail us with your solution at: blog(at)reversinglabs(dot)com; Challenge is now closed! Thanks to everyone who participated. Click read more for the solution... We didn't even dream about getting so [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://blog.reversinglabs.com/wp-content/uploads/2010/07/124829145.jpg" rel="lightbox[770]"><img class="size-full wp-image-597 alignnone" title="TShirt" src="http://blog.reversinglabs.com/wp-content/uploads/2010/07/124829145.jpg" alt="" width="630" height="261" /></a></p>
<p style="text-align: justify;">Looks cool? Want one? All you have to do is solve this <a href="http://blog.reversinglabs.com/wp-content/uploads/2010/07/r.zip">challenge</a> and tell us what is the password we seek. Sounds easy? Its not... Mail us with your solution at: blog(at)reversinglabs(dot)com; <strong>Challenge is now closed! Thanks to everyone who participated. Click read more for the solution...<br />
</strong></p>
<p><span id="more-770"></span></p>
<p style="text-align: justify;">We didn't even dream about getting so many people to participate in our little challenge. The sheer number of emails simply flooded our mailbox with possible solutions and compliments about  our challenge! One of those compliments expresses just what we want to do in the not-so-distant future, we quote: "<em>Fun challenge, do more of  these!</em>" We definitely will!</p>
<p style="text-align: justify;">Now to the solution, and discussion of the parts that proved troublesome for many...</p>
<p style="text-align: justify;">We start by downloading the file and doing our initial analysis. Since the file is a <a href="http://en.wikipedia.org/wiki/ZIP_%28file_format%29" target="_blank">ZIP</a> archive we open it with any program that works with this archive format to find a folder named "r" with the file named "r.zip" in it. This part of the challenge is just a decoy to keep you busy and distracted from the real content which is appended to the archive as an archive comment. That real content is another archive in <a href="http://en.wikipedia.org/wiki/7-Zip" target="_blank">7Zip</a> file format, which once extracted produces a single <a href="http://en.wikipedia.org/wiki/Cabinet_%28file_format%29" target="_blank">CAB</a> file, and that is where the things get interesting. The CAB file has a single <a href="http://en.wikipedia.org/wiki/PNG" target="_blank">PNG</a> file in it, but to solve this challenge we must observe the image and the archive as two separate objects.</p>
<p style="text-align: justify;">First the image part of the puzzle. The image, once opened, shows a normal picture with the logo of our company. However the picture itself has embedded <a href="http://en.wikipedia.org/wiki/Steganography" target="_blank">steganography</a> data. Since we didn't want to do any hard stego which can be solved by inspecting image pixels we embedded our hidden information between valid records inside the PNG file header. Something very similar to what we demonstrated on <a href="http://www.blackhat.com/html/bh-eu-10/bh-eu-10-briefings.html#Vuksan" target="_blank">BlackHat Barcelona</a> earlier this year. With the obvious difference that the file format is an image not an archive. Nonetheless the principle is the same. So, what's hidden? If you open the image file with any hex editor you will see a string "pSWD" near the start of the file. That string is followed by a 16 number sequence: 538B327278BBAB654747288999FBCDA1 which isn't the password we need. Nope, its not - even though many of you thought that that was the end solution. Why isn't it?</p>
<p style="text-align: justify;">Because of the fact that the CAB file that compressed that PNG image holds the last piece of the puzzle. If we scan that CAB file with our <a href="http://www.reversinglabs.com/products/NyxEngine.php" target="_blank">NyxEngine</a> we get the following output:</p>
<blockquote><p>Steganography ID: 0x00000b<br />
Possible steganography due to suspicious CAB extra data present between entries!<br />
Data start: 0x5a; Data size: 0x0000f6</p></blockquote>
<p style="text-align: justify;">And in that data there is the following text block:</p>
<blockquote>
<p style="text-align: justify;">UmFyIRoHAM6Zc4AADQAAAAAAAAA8MSAOyRZcWCVhcEFcUfp<br />
P4JdbtU2derwgjSYp+BpxVYkWJPDtQ/TITifo4qO7qyYz+yLpd9+6<br />
nkwwxmomWHbHK0Bt6UPHOwL/pEKm6IGXo/5dioeP66Fq5brTldgi<br />
Z7do5bbFjykQIsx6PMCBre4iUJ7jcwrwD2MDs69XwuuHL+fMKy9hD<br />
UJQPDEgDskWXFjp6jPWFXoWVSNb4H1zjQpW</p>
</blockquote>
<p style="text-align: justify;">Which is, in fact, a <a href="http://en.wikipedia.org/wiki/Base64" target="_blank">base64</a> encoded password protected <a href="http://en.wikipedia.org/wiki/RAR" target="_blank">RAR</a> file. But, what's the password? The password is the PNG image number sequence converted to lower case text. So, its: <a href="http://www.google.com/search?q=538b327278bbab654747288999fbcda1" target="_blank">538b327278bbab654747288999fbcda1</a> which isn't an MD5 and needs not to be bruteforced. Once its entered and the RAR file is decrypted we can see the file named "file" containing the following text: "Password is: <a href="http://www.google.com/search?q=9ec4c12949a4f31474f299058ce2b22a" target="_blank">9ec4c12949a4f31474f299058ce2b22a</a>". And that's it, the challenge is successfully completed at that point. No more stego or hidden files.</p>
<p style="text-align: justify;">There are six accepted solutions to this challenge, but the one that simply astonished us is the following python script which solves our challenge:</p>
<blockquote><p>#! /usr/bin/env python<br />
URL="<a href="http://blog.reversinglabs.com/wp-content/uploads/2010/07/r.zip" target="_blank">http://blog.reversinglabs.com/wp-content/uploads/2010/07/r.zip</a>"</p>
<p>import os<br />
import urllib2<br />
import struct</p>
<p>os.chdir("/tmp")<br />
rzip=urllib2.urlopen("<a href="http://blog.reversinglabs.com/wp-content/uploads/2010/07/r.zip" target="_blank">http://blog.reversinglabs.com/wp-content/uploads/2010/07/r.zip</a>").read()<br />
r7z = rzip[rzip.find("7z"):]<br />
open("r.7z","w").write(r7z)<br />
os.system("7z e r.7z")<br />
cab = open("puzzle.cab").read()<br />
os.system("cabextract puzzle.cab")<br />
open("r.rar","w").write(cab[0x5a:0x5a+250].decode("base64"))<br />
png = open("ReversingLabs.png").read()<br />
ppos = png.find("pSWD")<br />
sz, = struct.unpack("&gt;I", png[ppos-4:ppos])<br />
pwd = png[ppos+4:ppos+4+sz]<br />
os.system("unrar e -P%s r.rar" % pwd.encode("hex"))<br />
print open("file").read()</p></blockquote>
<p style="text-align: justify;">Thanks to everyone who participated in our little competition. Winners, your T-shirts are in the mail. Until our next challenge...</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="NyxEngine" href="http://www.facebook.com/pages/NyxEngine/101460583240402" target="_TOP">NyxEngine</a><br />
<a title="NyxEngine" href="http://www.facebook.com/pages/NyxEngine/101460583240402" target="_TOP"><img style="border: 0px;" src="http://badge.facebook.com/badge/101460583240402.92.1401198119.png" alt="" width="120" height="146" /></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">Our challenge got beaten by our own NyxEngine! Oh, Nyx...</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%2Freversinglabs-summer-challenge%2F&amp;title=ReversingLabs%20Summer%20Challenge" 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/07/reversinglabs-summer-challenge/feed/</wfw:commentRss>
		<slash:comments>6</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_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/07/everything-in-one-go/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Reverse engineering self defense</title>
		<link>http://blog.reversinglabs.com/2010/06/reversing-self-defense/</link>
		<comments>http://blog.reversinglabs.com/2010/06/reversing-self-defense/#comments</comments>
		<pubDate>Wed, 23 Jun 2010 00:54:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Reversing]]></category>
		<category><![CDATA[NoobyProtect]]></category>
		<category><![CDATA[OllyDBG]]></category>

		<guid isPermaLink="false">http://blog.reversinglabs.com/?p=688</guid>
		<description><![CDATA[If you remember not so long ago we wrote about minor inconveniences we encountered while working with OllyDBG. Today we return to that subject with challenges we face when reversing modern software protectors. One such protection is SafeEngine or NoobyProtect, which uses a simple portable executable malformation in order to crash OllyDBG. Even though this [...]]]></description>
			<content:encoded><![CDATA[<div style="text-align: center;"><a href="http://www.youtube.com/watch?v=-3nwk9DPsN4"><img src="http://blog.reversinglabs.com/wp-content/plugins/youtube-with-style/inc/img.php?v=-3nwk9DPsN4"></a></div>
<p style="text-align: justify;">If you remember not so long ago we wrote about <a href="http://blog.reversinglabs.com/2010/02/minor-inconvenience/">minor inconveniences</a> we encountered while working with OllyDBG. Today we return to that subject with challenges we face when reversing modern software protectors. One such protection is <a href="http://www.safengine.com/" target="_blank">SafeEngine</a> or NoobyProtect, which uses a simple portable executable malformation in order to crash <a href="http://www.ollydbg.de/" target="_blank">OllyDBG</a>. Even though this crash is limited to old OllyDBG versions, it is interesting for us nevertheless. The crash itself wouldn't be interesting if, in fact, the application didn't then operate normally. But it does, which makes it even more sinister. This leads us to conclude that this portable executable malformation is either ignored by the system or irrelevant to the system loader ... but not to our debugger. So, where's the trick? What does it apply to?</p>
<p style="text-align: justify;">If you look at the import table you will see that the first entry is rather unusual. Its name in LordPE is "kernel32...". Which could be fine since the trailing ".dll" is optional. If only it wasn't for those three little dots. Those dots represent multiple new lines after the name. In fact if we open the file with a hex editor we see that there are exactly 0x100 bytes following the first import library name. And in addition, there are 0x3000 bytes that follow the name of the first imported function in the first library trunk. These extra bytes seem to be too large for Olly to handle, overwriting some memory and ultimately making it crash. Since EIP is rewritten to 0x0d0a0d0a this could be an exploitable attack vector. Now we knew about this kind of attack for a while, having first seen it as an attack via too long names in the export table. But this is a bigger issue, since the <em>import</em> table is affected.</p>
<p style="text-align: justify;">If we investigate further we find an even more interesting issue that arises because of the way Windows processes the import table. If the import address table pointer inside the image import descriptor isn't nil and if it points to a sequence of eight zero bytes, the import entry will be ignored completely. Also, if the import lookup table pointer is valid and it points to at least one valid import address pointer, tools such as LordPE will read that data and display a list of functions that never get imported. This means that Windows will ignore the image import descriptor entry completely, which makes the dynamic link library name irrelevant as it will never reach the loading stage. This enables anyone to craft a file that only looks like its importing a specified library which may or may not be present on the system. And that can create confusion about which library is actually needed and which isn't.</p>
<p style="text-align: justify;">This isn't something that NoobyProtect does - but it could if it wanted to. Working around our crash problem is as easy as updating to OllyDBG 2.0 or patching the broken import table. Until next week...</p>
<p style="text-align: center;"><a href="http://blog.reversinglabs.com/wp-content/uploads/2010/06/sampleFile.zip">sampleFile</a><br />
(package contains a harmless sample file that imports a non existent DLL)</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%2Freversing-self-defense%2F&amp;title=Reverse%20engineering%20self%20defense" 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/06/reversing-self-defense/feed/</wfw:commentRss>
		<slash:comments>0</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_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/06/unpacking-by-hooking/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Sophos decodeme at AusCERT</title>
		<link>http://blog.reversinglabs.com/2010/05/decodeme/</link>
		<comments>http://blog.reversinglabs.com/2010/05/decodeme/#comments</comments>
		<pubDate>Sun, 23 May 2010 15:05:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Reversing]]></category>
		<category><![CDATA[Base64]]></category>
		<category><![CDATA[GIF]]></category>
		<category><![CDATA[GZIP]]></category>

		<guid isPermaLink="false">http://blog.reversinglabs.com/?p=633</guid>
		<description><![CDATA[Being the huge file analysis geeks (you must be shocked by this, we know) that we are, we couldn't help solving the more than interesting #decodeme challenge from Sophos at this years AusCert. The challenge itself was printed on a T-Shirt and the puzzle looked exactly like this: %~~~~~~~~~~~~~~~~~~~~~~~~% &#124;H4sIAAAAAAACA3P3dLOwTOxh&#124; &#124;YGF4zsBg7tHJMApGwYgE////&#124; &#124;V/zJwsjF8I9BB8QH5QkGjhYG&#124; &#124;xj/MD' gULH&#124; &#124;JrY' [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Being the huge file analysis geeks (<em>you must be shocked by this, we know</em>) that we are, we couldn't help solving the more than interesting #<a href="http://www.sophos.com/blogs/duck/g/2010/05/16/decodeme-t-shirt-tex/" target="_blank">decodeme</a> challenge from <a href="http://www.sophos.com" target="_blank">Sophos</a> at this years <a href="http://conference.auscert.org.au/conf2010/" target="_blank">AusCert</a>. The challenge itself was printed on a <a href="http://www.sophos.com/blogs/duck/g/2010/05/15/sophos-auscert-decodeme/" target="_blank">T-Shirt</a> and the puzzle looked exactly like this:</p>
<blockquote>
<pre>%~~~~~~~~~~~~~~~~~~~~~~~~%
|H4sIAAAAAAACA3P3dLOwTOxh|
|YGF4zsBg7tHJMApGwYgE////|
|V/zJwsjF8I9BB8QH5QkGjhYG|
|xj/MD'              gULH|
|JrY'                BbVi|
|Tlx|   Y4NgmoOxWoxH4yL5d|
|VDR|   oTseHh8f6WK359lQU|
|qJy\              \YJOGt|
|xhN5I\              \dlr|
|qoJvnIznRDXvHjPWZ   |SY7|
|Lz31nKtYPklkV0F6w   |AKr|
|1E17                ,Vk5|
|afng              ,hp63R|
|VsvNzy8u9qpU670lon11hvnS|
|KNWuSS+vrvNf3HV05beU0NXB|
|p71kJQQYrAFt8kQCpwMAAA==|
%~~~~~~~~~~~~~~~~~~~~~~~~%
  D  E  C  O  D  E  M  E
</pre>
</blockquote>
<p style="text-align: justify;">We are pretty sure that "S" stands for Sophos not Superman. Now, the first thing that comes to mind when you look at the "picture" is that the data around the "S" is important. And if we look at the last two letters we see the <a href="http://en.wikipedia.org/wiki/Base64" target="_blank">base64</a> trademark signature. Which means that all that data is an encoded message or a file. To decode it, we must strip that "S" to form a proper base64 data chain. Once done, the data looks like this:</p>
<blockquote><p>H4sIAAAAAAACA3P3dLOwTOxhYGF4zsBg7tHJMApGwYgE////V/zJwsj<br />
F8I9BB8QH5QkGjhYGxj/MDgULHJrYBbViTlxY4NgmoOxWoxH4yL5dVD<br />
RoTseHh8f6WK359lQUqJyYJOGtxhN5IdlrqoJvnIznRDXvHjPWZSY7L<br />
z31nKtYPklkV0F6wAKr1E17Vk5afnghp63RVsvNzy8u9qpU670lon11<br />
hvnSKNWuSS+vrvNf3HV05beU0NXBp71kJQQYrAFt8kQCpwMAAA==</p></blockquote>
<p style="text-align: justify;">That data must be reverted to either text or binary to continue. First, we tried  an online <a href="http://www.motobit.com/util/base64-decoder-encoder.asp" target="_blank">base64 decoder</a> but it returns a very strange string. So then, we decoded the data to a binary file and opened that with a hex editor, where we see the well known 0x1F 0x8B signature, which indicates that the decoded data is in fact a <a href="http://en.wikipedia.org/wiki/Gzip" target="_blank">GZIP</a> file. Now, we know GZip files may or may not store a file name, so when we decompress the packed data we do another hex data inspection to discover that the decompressed file is a <a href="http://en.wikipedia.org/wiki/Gif" target="_blank">GIF</a> file. It's an image showing us this:<a href="http://blog.reversinglabs.com/wp-content/uploads/2010/05/base64.gif" rel="lightbox[633]"><img title="Base64" src="http://blog.reversinglabs.com/wp-content/uploads/2010/05/base64.gif" alt="" width="140" height="4" /></a> Not quite readable, but once you zoom in on it, and lower-case it, it points to: <a href="http://www.sophos.com/anz/sofarsogood.html" target="_blank">http://www.sophos.com/anz/sofarsogood.html</a> which holds the last piece of the puzzle.</p>
<p style="text-align: justify;">Sadly last piece of the puzzle has nothing to do with file analysis whatsoever. Its a crypto challenge requiring you to play with letter substitution crypto algorithms. And this isn't something we are really interested in. You are however more than welcome to fiddle with it if you like. For some help on solving it check <a href="http://community.websense.com/blogs/securitylabs/archive/2010/05/20/a-simple-n-gram-calculator-pyngram.aspx" target="_blank">this</a> out. 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%2F05%2Fdecodeme%2F&amp;title=Sophos%20decodeme%20at%20AusCERT" 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/05/decodeme/feed/</wfw:commentRss>
		<slash:comments>1</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_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/05/working-around-checksums/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

