<?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; MEW</title>
	<atom:link href="http://blog.reversinglabs.com/tag/mew/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>Static unpackers, MEW5 story</title>
		<link>http://blog.reversinglabs.com/2009/09/static-unpackers-mew5-story/</link>
		<comments>http://blog.reversinglabs.com/2009/09/static-unpackers-mew5-story/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 05:59:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Reversing]]></category>
		<category><![CDATA[TitanEngine]]></category>
		<category><![CDATA[MEW]]></category>
		<category><![CDATA[Unpacker]]></category>
		<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://blog.reversinglabs.com/?p=54</guid>
		<description><![CDATA[This is our last blog about MEW, we promise. We intend to keep that promise since this is the last known version of MEW. Whats so special about MEW anyway? The reason we chose to do MEW (again) is that in its version 5 it is a simple crypter which can be used as a [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">This is our last blog about MEW, we promise. We intend to keep that promise since this is the last known version of MEW. Whats so special about MEW anyway?</p>
<p style="text-align: justify;">The reason we chose to do MEW (<em>again</em>) is that in its version 5 it is a simple crypter which can be used as a perfect example on how to write static unpackers for these kind of crypters. That kind would be the kind that doesn't do anything to imports but only encrypts the executable code section. Next time we revisit static unpackers we will be talking about such cases. We are going to leave that aside for now because this Monday is all about simple and fast unpacker writing. Start your timers we will do in under 10 minutes.</p>
<p style="text-align: justify;"><strong>Minute 1 - 2:</strong></p>
<p style="text-align: justify;">We load our sample into Olly and see the entire MEW5 code at the entry point.</p>
<blockquote>
<pre class="asm">  <span style="color: #EE4A02;">MOV</span> <span style="color: #EE1802; font-weight:bold;">ESI</span>,0040005B
  <span style="color: #EE4A02;">LODS</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;">ESI</span><span style="color: #FFFFFF;">&#93;</span>
  <span style="color: #EE4A02;">XCHG</span> <span style="color: #EE1802; font-weight:bold;">EAX</span>,<span style="color: #EE1802; font-weight:bold;">ECX</span>
  <span style="color: #EE4A02;">LODS</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;">ESI</span><span style="color: #FFFFFF;">&#93;</span>
  <span style="color: #EE4A02;">XCHG</span> <span style="color: #EE1802; font-weight:bold;">EAX</span>,<span style="color: #EE1802; font-weight:bold;">EBX</span>
  <span style="color: #EE4A02;">PUSH</span> <span style="color: #EE1802; font-weight:bold;">EBX</span>
  <span style="color: #EE4A02;">LODS</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;">ESI</span><span style="color: #FFFFFF;">&#93;</span>
  <span style="color: #EE4A02;">XCHG</span> <span style="color: #EE1802; font-weight:bold;">EAX</span>,<span style="color: #EE1802; font-weight:bold;">ESI</span>
  <span style="color: #EE4A02;">PUSH</span> <span style="color: #EE1802; font-weight:bold;">ESI</span>
  <span style="color: #EE4A02;">POP</span> <span style="color: #EE1802; font-weight:bold;">EDI</span>
L010:
  <span style="color: #EE4A02;">LODS</span> <span style="color: #DEE002;">BYTE</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;">ROL</span> <span style="color: #EE1802; font-weight:bold;">AL</span>,<span style="color: #ff0000;">29</span>
  <span style="color: #EE4A02;">ADD</span> <span style="color: #EE1802; font-weight:bold;">AL</span>,BA
  <span style="color: #EE4A02;">ROR</span> <span style="color: #EE1802; font-weight:bold;">AL</span>,<span style="color: #ff0000;">50</span>
  <span style="color: #EE4A02;">STOS</span> <span style="color: #DEE002;">BYTE</span> <span style="color: #DEE002;">PTR</span> <span style="color: #EE1802; font-weight:bold;">ES</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;">LOOPD</span> L010
  <span style="color: #EE4A02;">RET</span></pre>
</blockquote>
<p style="text-align: justify;">Yes, that it. The whole code. So what does it do? First it loads a pointer to all internal information into ESI register. We follow ESI in the hex dump to find that there are 3 DWORDs that have the data necessary for unpacking. First DWORD is 0x3000 which is the size of the first section, second DWORD is 0x004012c0 which is the address of the original entry point and third DWORD is 0x00401000 which is the virtual address of the first section. Code following this loads 0x3000 bytes one by one and decrypts them with a custom decryption algorithm. Here instruction sequence ROL, ADD and ROR is used to decrypt data.</p>
<p style="text-align: justify;"><strong>Minute 3 - 4:</strong></p>
<p style="text-align: justify;">We make a copy of existing <em>TitanEngine </em>SDK sample for DEF and use that as a template for our unpacker. We are making a Delphi unpacker since,... well since TitanEngine is low on Delphi samples and this is a nice and quick exercise.</p>
<p style="text-align: justify;"><strong>Minute 5 - 9:</strong></p>
<p style="text-align: justify;">We code the unpacker. First we need to read the ESI pointer and read the data from the file. Once we make that we convert third DWORD to physical address inside mapped file and we also convert the original entry point address to relative one. Simple call to <em>StaticMemoryDecryptEx </em>makes sure that our <em>StaticCallBack</em> decrypts the data by executing this custom decryption algorithm. Lastly we add the code to store the new entry point to PE32 header and we're done.</p>
<p style="text-align: justify;"><strong>Minute 9:47 - 10:</strong></p>
<p>We run the compiled unpacker to test if it works... Success!<br />
<!-- 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/2009/09/RLdeMEW5.rar">Download RL!deMEW5 unpacker</a><br />
<span>(package contains unpacker binary, source and samples used)</span></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%2F2009%2F09%2Fstatic-unpackers-mew5-story%2F&amp;title=Static%20unpackers%2C%20MEW5%20story" 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/2009/09/static-unpackers-mew5-story/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Packer security advisory: MEW design flaw</title>
		<link>http://blog.reversinglabs.com/2009/09/packer-security-advisor-mew-design-flaw/</link>
		<comments>http://blog.reversinglabs.com/2009/09/packer-security-advisor-mew-design-flaw/#comments</comments>
		<pubDate>Mon, 14 Sep 2009 13:15:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Reversing]]></category>
		<category><![CDATA[Advisory]]></category>
		<category><![CDATA[MEW]]></category>
		<category><![CDATA[Research]]></category>
		<category><![CDATA[Vulnerabilities]]></category>

		<guid isPermaLink="false">http://blog.reversinglabs.com/?p=39</guid>
		<description><![CDATA[This is a followup on MEW file format analysis. As mentioned in our video blog yesterday we noticed that MEW 10 has a design flaw that wrongfully passes function names to LoadLibraryA which firstly tries to load it as a DLL file and once that has failed it passes the same string to GetProcAddress and [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">This is a followup on MEW file format analysis. As mentioned in our <a href="http://blog.reversinglabs.com/2009/09/analyzing-mew-10-11/">video blog yesterday</a> we noticed that MEW 10 has a design flaw that wrongfully passes function names to LoadLibraryA which firstly tries to load it as a DLL file and once that has failed it passes the same string to GetProcAddress and successfully finds selected function in previously loaded DLL. We can exploit this by creating a dummy DLL file named as a function which every file on Windows imports, for example ExitProcess or GetModuleHandleA. Placing such file in %Windows%\System32 would ensure that that file is loaded each time a MEW 10 packed file is executed on the system. But we have a problem we must resolve before we proceed. As said earlier function only gets found if the DLL isn't loaded, or more specifically call to LoadLibraryA returns <em>NULL</em>. This must be resolved because we don't want to crash the packed fie. So to work around this we simply do this inside our GetModuleHandleA.dll file:</p>
<blockquote>
<pre class="cpp"><span style="">BOOL</span> APIENTRY DllMain<span style="color: #FFFFFF;">&#40;</span>HMODULE hModule,
   DWORD  ul_reason_for_call, LPVOID lpReserved<span style="color: #FFFFFF;">&#41;</span><span style="color: #FFFFFF;">&#123;</span>
	<span style="color: #EE4A02;">switch</span> <span style="color: #FFFFFF;">&#40;</span>ul_reason_for_call<span style="color: #FFFFFF;">&#41;</span>
	<span style="color: #FFFFFF;">&#123;</span>
	<span style="color: #EE4A02;">case</span> DLL_PROCESS_ATTACH:
		<span style="color: #EE4A02;">if</span><span style="color: #FFFFFF;">&#40;</span>GetModuleHandleA<span style="color: #FFFFFF;">&#40;</span><span style="color: #666666;">&quot;BadGuy.dll&quot;</span><span style="color: #FFFFFF;">&#41;</span> == <span style="color: #EE1802;">NULL</span><span style="color: #FFFFFF;">&#41;</span><span style="color: #FFFFFF;">&#123;</span>
			LoadLibraryA<span style="color: #FFFFFF;">&#40;</span><span style="color: #666666;">&quot;BadGuy.dll&quot;</span><span style="color: #FFFFFF;">&#41;</span>;
			<span style="color: #EE4A02;">return</span> <span style="color: #EE1802;">false</span>;
		<span style="color: #FFFFFF;">&#125;</span>
	<span style="color: #EE4A02;">case</span> DLL_THREAD_ATTACH:
	<span style="color: #EE4A02;">case</span> DLL_THREAD_DETACH:
	<span style="color: #EE4A02;">case</span> DLL_PROCESS_DETACH:
		<span style="color: #EE1802;">break</span>;
	<span style="color: #FFFFFF;">&#125;</span>
	<span style="color: #EE4A02;">return</span> <span style="color: #EE1802;">TRUE</span>;
<span style="color: #FFFFFF;">&#125;</span></pre>
</blockquote>
<p style="text-align: justify;">Returning <em>false </em>at DLL_PROCESS_ATTACH makes Windows unload our GetModuleHandleA.dll but not before BadGuy.dll gets loaded. Simple code above ensures that our BadGuy.dll gets loaded only once (<em>Windows also prevents this so this isn't really needed</em>) since MEW 10 packed file can import GetModuleHandleA multiple times. Our BadGuy.dll only creates a new thread which displays a message box about it being successfully loaded. This could have been done with a single DLL file but we wanted to keep it short and simple.</p>
<p style="text-align: justify;">There are many examples of design flaws in PE shell modifiers which could seriously threaten system security. Such example are not only limited to arbitrary code execution but could also lead to privilege elevation. We will continue to write about such shell modifier flaws in the future.</p>
<p style="text-align: center;"><a href="http://blog.reversinglabs.com/wp-content/uploads/2009/09/MEW-LoadLibrary-exploit.rar">Download MEW 10 LoadLibrary exploit POC</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%2F2009%2F09%2Fpacker-security-advisor-mew-design-flaw%2F&amp;title=Packer%20security%20advisory%3A%20MEW%20design%20flaw" 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/2009/09/packer-security-advisor-mew-design-flaw/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Analyzing MEW 10 &#8211; 11</title>
		<link>http://blog.reversinglabs.com/2009/09/analyzing-mew-10-11/</link>
		<comments>http://blog.reversinglabs.com/2009/09/analyzing-mew-10-11/#comments</comments>
		<pubDate>Sat, 12 Sep 2009 14:08:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Reversing]]></category>
		<category><![CDATA[TitanEngine]]></category>
		<category><![CDATA[MEW]]></category>
		<category><![CDATA[Unpacker]]></category>

		<guid isPermaLink="false">http://blog.reversinglabs.com/?p=32</guid>
		<description><![CDATA[This week we do a video tutorial about MEW analysis and we give pointers into making unpacker for this format. Download RL!deMEW 10 - 11 unpacker.]]></description>
			<content:encoded><![CDATA[<div style="text-align: center;"><a href="http://www.youtube.com/watch?v=CKhreF_0uzU"><img src="http://blog.reversinglabs.com/wp-content/plugins/youtube-with-style/inc/img.php?v=CKhreF_0uzU"></a></div>
<p>This week we do a video tutorial about MEW analysis and we give pointers into making unpacker for this format. <a href="http://blog.reversinglabs.com/wp-content/uploads/2009/09/RLdeMEW.rar">Download RL!deMEW 10 - 11 unpacker</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%2F2009%2F09%2Fanalyzing-mew-10-11%2F&amp;title=Analyzing%20MEW%2010%20%26%238211%3B%2011" 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/2009/09/analyzing-mew-10-11/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

