<?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>Unintended Results &#187; unpacking</title>
	<atom:link href="http://joxeankoret.com/blog/category/unpacking/feed/" rel="self" type="application/rss+xml" />
	<link>http://joxeankoret.com/blog</link>
	<description>Or maybe not</description>
	<lastBuildDate>Sun, 06 May 2012 08:20:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Antiemulation Techniques (Malware Tricks II)</title>
		<link>http://joxeankoret.com/blog/2010/02/23/antiemulation-techniques-malware-tricks-ii/</link>
		<comments>http://joxeankoret.com/blog/2010/02/23/antiemulation-techniques-malware-tricks-ii/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 18:55:00 +0000</pubDate>
		<dc:creator>joxean</dc:creator>
				<category><![CDATA[antidebugging]]></category>
		<category><![CDATA[antiemulation]]></category>
		<category><![CDATA[Malware]]></category>
		<category><![CDATA[Research]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[unpacking]]></category>
		<category><![CDATA[virtual machine detection]]></category>

		<guid isPermaLink="false">http://joxeankoret.com/blog/?p=74</guid>
		<description><![CDATA[From time to time, when reversing malware, I find new antiemulation techniques as they are widely used by malware to evade detection by AVs that uses emulation, however, it seems that no one wrote about them maybe because there are a lot or, maybe, because they aren't very interesting. Anyway, a friend and I decided [...]]]></description>
			<content:encoded><![CDATA[<p>From time to time, when reversing malware, I find new antiemulation techniques as they are widely used by malware to evade detection by AVs that uses emulation, however, it seems that no one wrote about them maybe because there are a lot or, maybe, because they aren't very interesting. Anyway, a friend and I decided to look for antiemulation techniques and we found a bunch of them in just about 2 days. Surprise. Well, the following is a list of antiemulation techniques "found" by us.<br />
<span id="more-74"></span><br />
<strong>API Emulation</strong></p>
<p>The most typically used antiemulation technique is the use of undocumented APIs or the use of non common ones such as, in example, <a href="http://msdn.microsoft.com/en-us/library/ms680621(VS.85).aspx">SetErrorMode</a>:</p>
<div class="geshi no c">
<div class="head">DWORD dwCode = 1024;</div>
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; SetErrorMode<span class="br0">&#40;</span><span class="nu0">1024</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>SetErrorMode<span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span> <span class="sy0">!=</span> <span class="nu0">1024</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">printf</span><span class="br0">&#40;</span><span class="st0">&quot;Hi emulator!<span class="es0">\n</span>&quot;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>This technique catches, at least, the IDAPro+Bochs debugger and Norman Sandbox.</p>
<p>Another typical trick is the use of non existent APIs. Many emulators will try to "emulate" the function by simply returning 0 instead of failing with a null pointer exception. Another one, try to load a vital library for the operating system which is not emulated and call an exported function: just trying to load the library will fail in almost any emulators:</p>
<div class="geshi no c">
<div class="head">int test6(void)</div>
<ol>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">HANDLE hProc;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; hProc <span class="sy0">=</span> LoadLibrary<span class="br0">&#40;</span><span class="st0">&quot;ntoskrnl.exe&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>hProc <span class="sy0">==</span> <span class="kw2">NULL</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> EMULATOR_DETECTED;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">else</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> EMULATOR_NOT_DETECTED;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Just in the case an emulator allows to load any library returning a pseudo handle, a bit more complex examples:</p>
<div class="geshi no c">
<div class="head">struct data1</div>
<ol>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw4">int</span> a1;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw4">int</span> a2;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">struct</span> data2</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw4">int</span> a1;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw4">int</span> a2;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw4">int</span> a3;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw4">int</span> a4;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw4">int</span> a5;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw4">int</span> a6;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw4">struct</span> data1 <span class="sy0">*</span>a7;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">typedef</span> <span class="kw4">int</span> <span class="br0">&#40;</span>WINAPI <span class="sy0">*</span>FCcSetReadAheadGranularity<span class="br0">&#41;</span><span class="br0">&#40;</span><span class="kw4">struct</span> data2 <span class="sy0">*</span>a1, <span class="kw4">int</span> num<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">typedef</span> <span class="kw4">int</span> <span class="br0">&#40;</span>WINAPI <span class="sy0">*</span>FIofCallDriver<span class="br0">&#41;</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">int</span> test8<span class="br0">&#40;</span><span class="kw4">void</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">HINSTANCE hProc;</div>
</li>
<li class="li1">
<div class="de1">FIofCallDriver pIofCallDriver;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;hProc <span class="sy0">=</span> LoadLibrary<span class="br0">&#40;</span><span class="st0">&quot;ntkrnlpa.exe&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw1">if</span> <span class="br0">&#40;</span>hProc <span class="sy0">==</span> <span class="kw2">NULL</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">return</span> <span class="nu0">0</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;pIofCallDriver <span class="sy0">=</span> <span class="br0">&#40;</span>FIofCallDriver<span class="br0">&#41;</span> GetProcAddress<span class="br0">&#40;</span>hProc, <span class="st0">&quot;IofCallDriver&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;pIofCallDriver <span class="sy0">-=</span> <span class="nu0">2</span>; <span class="co1">// At this point there is a 0xCC character, so an INT3 should be raised</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;try</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; pIofCallDriver<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">return</span> EMULATOR_DETECTED;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;catch<span class="br0">&#40;</span>...<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">return</span> EMULATOR_NOT_DETECTED;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">int</span> test9<span class="br0">&#40;</span><span class="kw4">void</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">HINSTANCE hProc;</div>
</li>
<li class="li1">
<div class="de1">FCcSetReadAheadGranularity CcSetReadAheadGranularity;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">struct</span> data1 s1;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">struct</span> data2 s2;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">int</span> ret;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;hProc <span class="sy0">=</span> LoadLibrary<span class="br0">&#40;</span><span class="st0">&quot;ntkrnlpa.exe&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw1">if</span> <span class="br0">&#40;</span>hProc <span class="sy0">==</span> <span class="kw2">NULL</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">return</span> <span class="nu0">0</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;CcSetReadAheadGranularity <span class="sy0">=</span> <span class="br0">&#40;</span>FCcSetReadAheadGranularity<span class="br0">&#41;</span>GetProcAddress<span class="br0">&#40;</span>hProc, <span class="st0">&quot;CcSetReadAheadGranularity&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw1">if</span> <span class="br0">&#40;</span>CcSetReadAheadGranularity <span class="sy0">==</span> <span class="kw2">NULL</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">return</span> <span class="nu0">0</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;s1.<span class="me1">a2</span> <span class="sy0">=</span> <span class="nu0">0</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;s2.<span class="me1">a7</span> <span class="sy0">=</span> <span class="sy0">&amp;</span>amp;s1;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// After this call, ret must be 0x666, the given 2nd argument minus 1</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;ret <span class="sy0">=</span> CcSetReadAheadGranularity<span class="br0">&#40;</span><span class="sy0">&amp;</span>amp;s2, 0x667<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw1">if</span> <span class="br0">&#40;</span>ret <span class="sy0">!=</span> 0x666<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">return</span> EMULATOR_DETECTED;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw1">else</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">return</span> EMULATOR_NOT_DETECTED;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>This technique(s) works in the 3 emulators I tested (Norman Sandbox, IDA+Bochs and Wine) and I'm pretty sure that them will work in any emulator.</p>
<p><strong>Old Features</strong></p>
<p>In the old -<em>good?</em>- days of MSDOS and Windows 9x the AUX, CON, and other special devices were used to read data from the keyboard, change terminal colors, etc... This behavior, while not currently supported (if I'm not wrong), works in current Microsoft Windows operating systems but not in emulators. The following is an easy example:</p>
<div class="geshi no c">
<div class="head">FILE *f;</div>
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; f <span class="sy0">=</span> fopen<span class="br0">&#40;</span><span class="st0">&quot;c:<span class="es0">\\</span>con&quot;</span>, <span class="st0">&quot;r&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>f <span class="sy0">==</span> <span class="kw2">NULL</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> EMULATOR_DETECTED;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">else</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> EMULATOR_NOT_DETECTED;</div>
</li>
</ol>
</div>
<p>The unique "emulator" that simulates correctly this behavior is Wine. This technique was found by 2 of my co-workers, <em>nick-namely</em>, "PE_Luchin" and "Shaddy".</p>
<p><strong>Assembly</strong></p>
<p>Emulating corrrectly a complete CPU is a very hard task and is also the most error prone area to look for incongruencies. Norman Sandbox works remarkably bad in this sense: The emulator fails (or it failed, I didn't tested it since last year) with instructions like ICEBP or UD2 and allows changing, in example, the debug registers via privileged instructions. Easier to see in the following 4 examples:</p>
<div class="geshi no c">
<div class="head">int test1(void)</div>
<ol>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; try</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; __asm</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;mov eax, <span class="nu0">1</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;mov dr0, eax</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; catch<span class="br0">&#40;</span>...<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> EMULATOR_NOT_DETECTED;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> EMULATOR_DETECTED;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">int</span> test2<span class="br0">&#40;</span><span class="kw4">void</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; try</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; __asm</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;mov eax, <span class="nu0">1</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;mov cr0, eax</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; catch<span class="br0">&#40;</span>...<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> EMULATOR_NOT_DETECTED;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> EMULATOR_DETECTED;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">int</span> test3<span class="br0">&#40;</span><span class="kw4">void</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; try</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; __asm <span class="kw4">int</span> <span class="nu0">4</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; catch<span class="br0">&#40;</span>...<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> EMULATOR_NOT_DETECTED;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> EMULATOR_DETECTED;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">/** Norman Sandbox stoped execution at this point <img src='http://joxeankoret.com/blog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  */</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">int</span> test4<span class="br0">&#40;</span><span class="kw4">void</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; try</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; __asm ud2</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; catch<span class="br0">&#40;</span>...<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> EMULATOR_NOT_DETECTED;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> EMULATOR_DETECTED;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">/** Norman Sandbox stoped execution at this point <img src='http://joxeankoret.com/blog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  */</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">int</span> test5<span class="br0">&#40;</span><span class="kw4">void</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; try</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// icebp</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;__asm &nbsp;_emit 0xf1</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; catch<span class="br0">&#40;</span>...<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> EMULATOR_NOT_DETECTED;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> EMULATOR_DETECTED;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>These tests were launched against Wine, IDA+Bochs and Norman. While they don't work in Bochs they makes failing both Norman Sandbox and Wine; both thinks the process has crashed and stops execution.</p>
<p><strong>Conclussion</strong></p>
<p>There are a lot of antiemulation techniques and these are just simple examples; writting much more elaborated ones is a matter of time and it's simply impossible to circunvent all the antiemulation techniques. The old cat &amp; mouse game <img src='http://joxeankoret.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://joxeankoret.com/blog/2010/02/23/antiemulation-techniques-malware-tricks-ii/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Zerowine: Better reports, network conversations and bug fixes</title>
		<link>http://joxeankoret.com/blog/2009/02/10/zerowine-better-reports-network-conversations-and-bug-fixes/</link>
		<comments>http://joxeankoret.com/blog/2009/02/10/zerowine-better-reports-network-conversations-and-bug-fixes/#comments</comments>
		<pubDate>Tue, 10 Feb 2009 10:05:59 +0000</pubDate>
		<dc:creator>joxean</dc:creator>
				<category><![CDATA[antidebugging]]></category>
		<category><![CDATA[Malware]]></category>
		<category><![CDATA[Research]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[unpacking]]></category>
		<category><![CDATA[virtual machine detection]]></category>

		<guid isPermaLink="false">http://joxeankoret.com/blog/?p=67</guid>
		<description><![CDATA[Single user version of Zerowine Yesterday I finished the (surely) last single-user version of Zerowine and added some interesting features to it. Many Zerowine users told me that the reports were very confusing and, yes, that's true. I fixed this problem by adding new debugging channels to the currently latest stable version of Wine (1.1.10) [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Single user version of Zerowine</strong></p>
<p>Yesterday I finished the (surely) last single-user version of Zerowine and added some interesting features to it. Many Zerowine users told me that the reports were very confusing and, yes, that's true. I fixed this problem by adding new debugging channels to the currently latest stable version of Wine (1.1.10) and, well, the reports now are less confusing and more readable. The new debugging channels I added to Wine are the following:</p>
<ol>
<li>humanmalware: This channel shows in human readable format what the malware is doing.</li>
<li>malware: Quite similar to the TRACE channel, but just logs the calls to APIs interesting for malware research.</li>
<li>malwaredump: This channel shows the network conversations.</li>
<li>malwarereg: Shows registry operations.</li>
<li>malwarelib: Shows what libraries the malware is loading/unloading.</li>
</ol>
<p>The following is an example report of running a malware in the sandbox with the latest features:</p>
<div id="attachment_68" class="wp-caption aligncenter" style="width: 300px"><a href="http://joxeankoret.com/blog/wp-content/uploads/2009/02/zerowine_channels1.png"><img class="size-medium wp-image-68" title="Zerowine reports with the new channels" src="http://joxeankoret.com/blog/wp-content/uploads/2009/02/zerowine_channels1-290x300.png" alt="Zerowine reports with the new channels" width="290" height="300" /></a><p class="wp-caption-text">Zerowine reports with the new channels</p></div>
<p>We can see how the malware connects to some remote web server, the HTTP query executed, the local file downloaded, etc... This in the "Report" section, in the "Signature" section we get just the "human readable" format of the report (as is normal, not as detailed as the "Report" section, however).</p>
<p>I also fixed various bugs (in both Wine and Zerowine) and Zerowine now is able to detect more anti-debugging techniques, to dump new malware formats and more <em>secure</em>. I removed some features in the patched version of Wine that are a bit insecure for malware analysis.</p>
<p>Well, and that's all for the mono-user version (I will be releasing it this week, or at least I hope to do so). I will update this entry when the file I'm uploading to the Sourceforge.net finishes, and it's very slow (really, a pain in the ass).</p>
<p><strong>Multiuser Version of Zerowine</strong></p>
<p>The new multi-user version of Zerowine will take a long while because it requires a lot of changes, however, many features are implemented right now (Queues, multiple malware analysis nodes, database support, etc...). The changes will be, mainly, architectural ones but not all. In example, I'm implementing right now new "engines" to analyze malware in other platforms: One IDA Pro based agent to execute the malware with the Bochs Debugger inside IDA, dump &amp; analyze it and get an unpacked IDB database.</p>
<p>Other (possible) agent I'm planning is a Windows hooker to analyze the malware in a real Windows box (but the problem that comes to my mind is how to clean the environment automatically after the malware execution...).</p>
]]></content:encoded>
			<wfw:commentRss>http://joxeankoret.com/blog/2009/02/10/zerowine-better-reports-network-conversations-and-bug-fixes/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Zerowine: Malware dumping and detection tricks [Updated]</title>
		<link>http://joxeankoret.com/blog/2009/01/18/zerowine-malware-dumping-and-detection-tricks/</link>
		<comments>http://joxeankoret.com/blog/2009/01/18/zerowine-malware-dumping-and-detection-tricks/#comments</comments>
		<pubDate>Sun, 18 Jan 2009 17:24:30 +0000</pubDate>
		<dc:creator>joxean</dc:creator>
				<category><![CDATA[antidebugging]]></category>
		<category><![CDATA[Malware]]></category>
		<category><![CDATA[Research]]></category>
		<category><![CDATA[unpacking]]></category>
		<category><![CDATA[virtual machine detection]]></category>

		<guid isPermaLink="false">http://joxeankoret.com/blog/?p=54</guid>
		<description><![CDATA[Update: I released the new version now! Download the prebuilt QEmu virtual machine (or the source code) from here. Remember that the root's password is 'zerowine'. There is also another user account: 'malware' with password 'malware'. I recently added 3 new interesting features to Zerowine. The very first one is the ability to dump the [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update</strong>: I released the new version now! Download the prebuilt QEmu virtual machine (or the source code) from <a href="https://sourceforge.net/project/platformdownload.php?group_id=248410" target="_blank">here</a>. Remember that the root's password is 'zerowine'. There is also another user account: 'malware' with password 'malware'.</p>
<p>I recently added 3 new interesting features to <a href="http://sourceforge.net/projects/zerowine" target="_blank">Zerowine</a>. The very first one is the ability to dump the malware from memory while running and analyze the memory. This way, strings and code hidden in a packed malware can be analyzed because it is completely unpacked, as in the following example showing the strings from a variant of the MyTob malware packed with MEW.</p>
<div id="attachment_56" class="wp-caption aligncenter" style="width: 310px"><a href="http://joxeankoret.com/blog/wp-content/uploads/2009/01/zerowine1.png"><img class="size-medium wp-image-56" title="zerowine1" src="http://joxeankoret.com/blog/wp-content/uploads/2009/01/zerowine1-300x242.png" alt="Zerowine: String analysis of the MyTob malware after dumping it from memory" width="300" height="242" /></a><p class="wp-caption-text">Zerowine: String analysis of the MyTob malware after dumping it from memory </p></div>
<p>The memory dumps can also be downloaded for later analysis with <a href="http://www.hex-rays.com/idapro/" target="_blank">IDA Pro</a>. The dumping process is done from outside <a href="http://www.winehq.org" target="_blank">WINE</a> with a <a href="http://www.python.org" target="_blank">Python</a> script (/home/malware/bin/dump_process.py) that uses <a href="http://python-ptrace.hachoir.org/" target="_blank">python-ptrace</a> to attach to the running malware and dump the memory.</p>
<p>I added also signatures using this new feature to detect the most typical Virtual Machine detection tricks (such as the <a href="http://www.invisiblethings.org/papers/redpill.html" target="_blank">redpill</a> trick or the VMWare's backdoor).</p>
<p style="text-align: center;"><a href="http://joxeankoret.com/blog/wp-content/uploads/2009/01/zerowine11.png"><img class="size-medium wp-image-57 aligncenter" title="Red Pill Virtual Machine trick detected by Zerowine" src="http://joxeankoret.com/blog/wp-content/uploads/2009/01/zerowine11-291x300.png" alt="" width="291" height="300" /></a></p>
<p style="text-align: left;">In this screenshot you can see also the "Debugger detection tricks" section. The detection is done by analyzing the behavior of the malware. The following is an analysis of some Chinesse malware packed with <a href="http://www.oreans.com/products.php" target="_blank">Themida</a>:</p>
<p style="text-align: center;"><a href="http://joxeankoret.com/blog/wp-content/uploads/2009/01/zerowine2.png"><img class="alignnone size-medium wp-image-58" title="Zerowine: Antidebugging techniques detection" src="http://joxeankoret.com/blog/wp-content/uploads/2009/01/zerowine2-278x300.png" alt="" width="278" height="300" /></a></p>
<p>And, well, that's all at the moment. The new version will be released (or at least I hope to do so) in a week.</p>
<p>Cheers!</p>
]]></content:encoded>
			<wfw:commentRss>http://joxeankoret.com/blog/2009/01/18/zerowine-malware-dumping-and-detection-tricks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

