<?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; Recovery</title>
	<atom:link href="http://blog.reversinglabs.com/tag/recovery/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>Attacking the cipher</title>
		<link>http://blog.reversinglabs.com/2010/01/attacking-the-cipher/</link>
		<comments>http://blog.reversinglabs.com/2010/01/attacking-the-cipher/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 05:00:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Reversing]]></category>
		<category><![CDATA[TitanEngine]]></category>
		<category><![CDATA[BruteForce]]></category>
		<category><![CDATA[forensics]]></category>
		<category><![CDATA[Password]]></category>
		<category><![CDATA[Recovery]]></category>
		<category><![CDATA[Research]]></category>

		<guid isPermaLink="false">http://blog.reversinglabs.com/?p=245</guid>
		<description><![CDATA[Not too long ago we dedicated a blog post to removing executable password protections. In that post we said that we will eventually return to this topic to deal with much harder opponent. Well today is that day. This time we take a look at executable password protection named PEPasswordEncryptor As we have seen in [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Not too long ago we dedicated a <a href="http://blog.reversinglabs.com/2009/12/exe-password-protection/" target="_blank">blog post</a> to removing executable password protections. In that post we said that we will eventually return to this topic to deal with much harder opponent. Well today is that day. This time we take a look at executable password protection named <a href="http://smf.chat.ru/e_smf_release.htm" target="_blank">PEPasswordEncryptor</a></p>
<p style="text-align: justify;">As we have seen in our previous blog on this subject tools that provide this kind of protection are very often coded with major design flaws which enable us with quick and painless ways to work around the password protection. However today's password protection option doesn't have such flaws. And that is why we need to find an optimal way to quickly and accurately recover the password. Can it be done in this case?</p>
<p style="text-align: justify;">Quick analysis of the protected file shows us these interesting pieces of code:</p>
<blockquote>
<pre class="asm">  <span style="color: #EE4A02;">PUSH</span> <span style="color: #EE1802; font-weight:bold;">ECX</span>
  <span style="color: #EE4A02;">PUSH</span> <span style="color: #EE1802; font-weight:bold;">ECX</span>
  <span style="color: #EE4A02;">PUSH</span> <span style="color: #ff0000;">40</span>
  <span style="color: #EE4A02;">PUSH</span> 0D
  <span style="color: #EE4A02;">PUSH</span> <span style="color: #DEE002;">DWORD</span> <span style="color: #DEE002;">PTR</span> <span style="color: #EE1802; font-weight:bold;">SS</span>:<span style="color: #FFFFFF;">&#91;</span>EBP<span style="color: #ff0000;">+20</span><span style="color: #FFFFFF;">&#93;</span>
  <span style="color: #EE4A02;">CALL</span> <span style="color: #DEE002;">NEAR</span> <span style="color: #DEE002;">DWORD</span> <span style="color: #DEE002;">PTR</span> <span style="color: #EE1802; font-weight:bold;">DS</span>:<span style="color: #FFFFFF;">&#91;</span>EDI<span style="color: #ff0000;">+402923</span><span style="color: #FFFFFF;">&#93;</span>
  <span style="color: #EE4A02;">POP</span> <span style="color: #EE1802; font-weight:bold;">ESI</span>
  <span style="color: #EE4A02;">CALL</span> L025        <span style="color: #adadad; font-style: italic;">;Calculate the hash for input string</span>
  <span style="color: #EE4A02;">CMP</span> <span style="color: #EE1802; font-weight:bold;">EAX</span>,F492C2C1 <span style="color: #adadad; font-style: italic;">;Correct password hash</span>
  <span style="color: #EE4A02;">MOV</span> <span style="color: #EE1802; font-weight:bold;">EAX</span>,<span style="color: #ff0000;">0</span>
  <span style="color: #EE4A02;">JNZ</span> L015
...
L025:              <span style="color: #adadad; font-style: italic;">;Slow hashing algorithm</span>
  <span style="color: #EE4A02;">XOR</span> <span style="color: #EE1802; font-weight:bold;">EAX</span>,<span style="color: #EE1802; font-weight:bold;">EAX</span>      <span style="color: #adadad; font-style: italic;">;Hash initialization</span>
  <span style="color: #EE4A02;">PUSH</span> <span style="color: #EE1802; font-weight:bold;">ECX</span>
  <span style="color: #EE4A02;">PUSH</span> <span style="color: #EE1802; font-weight:bold;">ESI</span>         <span style="color: #adadad; font-style: italic;">;ESI holds the password pointer</span>
  <span style="color: #EE4A02;">PUSH</span> <span style="color: #EE1802; font-weight:bold;">EDX</span>
  <span style="color: #EE4A02;">XOR</span> <span style="color: #EE1802; font-weight:bold;">EDX</span>,<span style="color: #EE1802; font-weight:bold;">EDX</span>      <span style="color: #adadad; font-style: italic;">;Reason why it executes 0xFFFF times</span>
  <span style="color: #EE4A02;">DEC</span> <span style="color: #EE1802; font-weight:bold;">ESI</span>          <span style="color: #adadad; font-style: italic;">;for every letter</span>
L031:
  <span style="color: #EE4A02;">INC</span> <span style="color: #EE1802; font-weight:bold;">ESI</span>
  <span style="color: #EE4A02;">XOR</span> <span style="color: #EE1802; font-weight:bold;">AH</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>
L033:
  <span style="color: #EE4A02;">XOR</span> <span style="color: #EE1802; font-weight:bold;">AL</span>,<span style="color: #EE1802; font-weight:bold;">DL</span>
  <span style="color: #EE4A02;">ADD</span> <span style="color: #EE1802; font-weight:bold;">EAX</span>,434F4445 <span style="color: #adadad; font-style: italic;">;Constant</span>
  <span style="color: #EE4A02;">MOV</span> <span style="color: #EE1802; font-weight:bold;">CL</span>,<span style="color: #EE1802; font-weight:bold;">AL</span>
  <span style="color: #EE4A02;">ROR</span> <span style="color: #EE1802; font-weight:bold;">EAX</span>,<span style="color: #EE1802; font-weight:bold;">CL</span>
  <span style="color: #EE4A02;">XOR</span> <span style="color: #EE1802; font-weight:bold;">EAX</span>,55AA5A5A <span style="color: #adadad; font-style: italic;">;Constant</span>
  <span style="color: #EE4A02;">DEC</span> <span style="color: #EE1802; font-weight:bold;">DX</span>
  <span style="color: #EE4A02;">JNZ</span> L033
  <span style="color: #EE4A02;">CMP</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: #ff0000;">0</span>
  <span style="color: #EE4A02;">JNZ</span> L031
  <span style="color: #EE4A02;">POP</span> <span style="color: #EE1802; font-weight:bold;">EDX</span>
  <span style="color: #EE4A02;">POP</span> <span style="color: #EE1802; font-weight:bold;">ESI</span>
  <span style="color: #EE4A02;">POP</span> <span style="color: #EE1802; font-weight:bold;">ECX</span>
  <span style="color: #EE4A02;">RET</span></pre>
</blockquote>
<p style="text-align: justify;">Now just by looking at this piece of code we see that the author of the program thought of many things when it comes to protected file's security. Why? Algorithm in charge of hashing the string is really slow because it executes 0xFFFF times for every letter of the password. If it wasn't for this bruteforcing  this algorithm would be nice and quick. But before we go for that extreme we should always check for possible shortcuts that can enable us to skip the password necessity.</p>
<p style="text-align: justify;">Since we already know that password hash must be 0xF492C2C1 lets see if the memory content decryption has a weakness.</p>
<blockquote>
<pre class="asm">  <span style="color: #EE4A02;">PUSHAD</span>
  <span style="color: #EE4A02;">MOV</span> <span style="color: #EE1802; font-weight:bold;">EDI</span>,<span style="color: #EE1802; font-weight:bold;">EAX</span>
  <span style="color: #EE4A02;">MOV</span> <span style="color: #EE1802; font-weight:bold;">ESI</span>,<span style="color: #EE1802; font-weight:bold;">EDX</span>
  <span style="color: #EE4A02;">MOV</span> <span style="color: #EE1802; font-weight:bold;">EAX</span>,<span style="color: #ff0000;">48415348</span> <span style="color: #adadad; font-style: italic;">;Hash initialization</span>
  <span style="color: #EE4A02;">XOR</span> <span style="color: #EE1802; font-weight:bold;">AL</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;">CALL</span> GetPasswordHash
  <span style="color: #EE4A02;">MOV</span> <span style="color: #EE1802; font-weight:bold;">EBX</span>,<span style="color: #EE1802; font-weight:bold;">EAX</span>
  <span style="color: #EE4A02;">XOR</span> <span style="color: #EE1802; font-weight:bold;">AH</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;">CALL</span> GetPasswordHash
  <span style="color: #EE4A02;">SHR</span> <span style="color: #EE1802; font-weight:bold;">ECX</span>,<span style="color: #ff0000;">2</span>
  <span style="color: #EE4A02;">MOV</span> <span style="color: #EE1802; font-weight:bold;">EDX</span>,<span style="color: #EE1802; font-weight:bold;">ECX</span>
L011:              <span style="color: #adadad; font-style: italic;">;Decrypt first section</span>
  <span style="color: #EE4A02;">XOR</span> <span style="color: #DEE002;">DWORD</span> <span style="color: #DEE002;">PTR</span> <span style="color: #EE1802; font-weight:bold;">DS</span>:<span style="color: #FFFFFF;">&#91;</span><span style="color: #EE1802; font-weight:bold;">EDI</span><span style="color: #FFFFFF;">&#93;</span>,<span style="color: #EE1802; font-weight:bold;">EAX</span>
  <span style="color: #EE4A02;">MOV</span> <span style="color: #EE1802; font-weight:bold;">CL</span>,<span style="color: #EE1802; font-weight:bold;">AL</span>
  <span style="color: #EE4A02;">ADD</span> <span style="color: #EE1802; font-weight:bold;">EDI</span>,<span style="color: #ff0000;">4</span>
  <span style="color: #EE4A02;">ROL</span> <span style="color: #EE1802; font-weight:bold;">EBX</span>,<span style="color: #EE1802; font-weight:bold;">CL</span>
  <span style="color: #EE4A02;">XOR</span> <span style="color: #EE1802; font-weight:bold;">EAX</span>,<span style="color: #EE1802; font-weight:bold;">EBX</span>      <span style="color: #adadad; font-style: italic;">;Keys for decryption: EAX and EBX</span>
  <span style="color: #EE4A02;">MOV</span> <span style="color: #EE1802; font-weight:bold;">CL</span>,<span style="color: #EE1802; font-weight:bold;">BH</span>
  <span style="color: #EE4A02;">ROR</span> <span style="color: #EE1802; font-weight:bold;">EAX</span>,<span style="color: #EE1802; font-weight:bold;">CL</span>
  <span style="color: #EE4A02;">ADD</span> <span style="color: #EE1802; font-weight:bold;">EBX</span>,<span style="color: #EE1802; font-weight:bold;">EAX</span>
  <span style="color: #EE4A02;">DEC</span> <span style="color: #EE1802; font-weight:bold;">EDX</span>
  <span style="color: #EE4A02;">JNZ</span> L011
  <span style="color: #EE4A02;">POPAD</span>
  <span style="color: #EE4A02;">RET</span></pre>
</blockquote>
<p style="text-align: justify;">Here is what happens here. Just before the program decrypts the first section it initializes two 32bit decryption keys. Both keys are initialized from the password string, more accurately the keys are password hashes. Second key is calculated fist. This key which is stored in EBX register is a direct product of password hash for algorithm initialize value 0x48415348. However this value isn't a constant, it is modified by XORing with the fist letter of the password. That is why the already calculated  password hash we have 0xF492C2C1 isn't enough to break this algorithm. Fist key is calculated last and its value is stored in EAX register. Hashing algorithm for this key calculation is a direct result of first key stored in EBX XORed with the fist letter of the password. Only by having the state of both keys for decryption beginning we can correctly decrypt the file. However we put it the password seems like a must for decryption. We are going to return to shortcuts a bit later, lets discuss the bruteforce option first.</p>
<p style="text-align: justify;">Building a bruteforcer for this algorithm is quite easy. We just need to go through the all possible combinations that a password can take in order to recover the 'lost' password. However that proves to be a much harder task then it sounds. Building the bruteforcer isn't a problem but the time its needed for recovering a simple password which is only 4 characters in length is very long. Take a look at this program log to see a basic log which shows the "slowness" of this algorithm. It seems that author of the program saw bruteforce as a potential risk and made it slow on purpose. But this isn't the only problem. Our bruteforce test shows that passwords collide meaning the multiple passwords have the same hash. Any of these passwords will unlock the program but it won't be decrypted correctly and therefore it will crash. Here is how the bruteforce program log looks like:</p>
<p style="text-align: justify;"><a href="http://blog.reversinglabs.com/wp-content/uploads/2010/01/bForce1.png" rel="lightbox[245]"><img class="aligncenter size-medium wp-image-252" title="bForce1" src="http://blog.reversinglabs.com/wp-content/uploads/2010/01/bForce1-300x187.png" alt="" width="300" height="187" /></a></p>
<p style="text-align: justify;">Correct password for this sample is: "ap0x" but to recover it bruteforcer needed approximately 4 minutes. And as you can see in log file time needed to go through every four character password combination (a..z + A..Z + 0..9) is more then 2 hours. And even that isn't a guarantee because you have check every password since the protection doesn't have an additional validation to check if the code decrypted correctly. Since that is way too slow for any practical use on longer passwords we return to finding the algorithm weakness.</p>
<p style="text-align: justify;">But is there a weakness? If we look at the decryption algorithm we see that both EAX and EBX keys are needed for decryption to work correctly. However only one key, EAX, is used to decrypt data by XORing the file memory content. Therefore recovering the password would be easy if we knew the first four bytes unencrypted. Which we don't... Could it help if we need the unencrypted value of any random sequence of bytes in the file? It might but that would mean that we would also need one more information for that location, the value of ECX register because it is used to modify successive decryption keys. Is there just such a sequence of bytes? Sure, at the end of file whose sections are aligned to PE.FileAlignment (and its a must for this protection) we have at least 12 bytes which are zeroes. Last four bytes in that case are equal to EAX decryption key at that time, which leaves EBX and CL as unknowns. Four bytes before that we have the same story. In order to recover EAX, EBX and CL we must do the following:</p>
<ul>
<li>Reverse the decryption algorithm so it decrypts the memory backwards</li>
<li>Bruteforce that decryption to recover EAX, EBX and CL values</li>
<li>Make sure that those key values are correct since algorithm does collide</li>
<li>Decrypt the file backwards using the correct keys</li>
</ul>
<p style="text-align: justify;">Since keys are 32bit and we already know the value of one of those at one point we can bruteforce keys between 0x00000000 and 0xFFFFFFFF in order to get the missing EBX and CL values. That is much faster then trying to bruteforce the infinity of possible passwords. Reversed algorithm can be seen in the source code under the function named <em>PEPDecryptFile</em>.</p>
<div style="text-align: center;"><a href="http://www.youtube.com/watch?v=jJG-9l-Urmc"><img src="http://blog.reversinglabs.com/wp-content/plugins/youtube-with-style/inc/img.php?v=jJG-9l-Urmc"></a></div>
<p style="text-align: justify;">
<p style="text-align: justify;">Writing a bruteforcer for PEPasswordEncryptor is a nice reversing exercise especially when algorithm shortcut inspection is involved. As always binary, source code and the samples are included with the blog. Until next week...</p>
<p style="text-align: center;"><a href="http://blog.reversinglabs.com/wp-content/uploads/2010/01/PEBrute.zip">PEBrute</a><br />
(package contains unpacker binary, source and samples used)</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%2F01%2Fattacking-the-cipher%2F&amp;title=Attacking%20the%20cipher" id="wpa2a_2"><img src="http://blog.reversinglabs.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.reversinglabs.com/2010/01/attacking-the-cipher/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Removing executable password protection</title>
		<link>http://blog.reversinglabs.com/2009/12/exe-password-protection/</link>
		<comments>http://blog.reversinglabs.com/2009/12/exe-password-protection/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 12:47:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Reversing]]></category>
		<category><![CDATA[forensics]]></category>
		<category><![CDATA[Password]]></category>
		<category><![CDATA[Protection]]></category>
		<category><![CDATA[Recovery]]></category>
		<category><![CDATA[Research]]></category>

		<guid isPermaLink="false">http://blog.reversinglabs.com/?p=164</guid>
		<description><![CDATA[With the next TitanEngine release just around the corner we decided to do a light an interesting analysis of a simple executable password protection. Today's focus is on LCCrypto a simple example which will show us the general security and vulnerabilities of such and similar tools. Now it theory only one password should be able [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">With the next <em>TitanEngine </em>release just around the corner we decided to do a light an interesting analysis of a simple executable password protection. Today's focus is on <a href="http://www.luocong.com/myworks.htm" target="_blank">LCCrypto</a> a simple example which will show us the general security and vulnerabilities of such and similar tools.</p>
<p style="text-align: justify;">Now it theory only one password should be able to unlock such protected application and allow its execution without any possibility of removing the protection without the correct password. Well that's the theory behind such tools but they themselves have a weakness too because there still must be a way for the application to check the validity of the inputted password. So regardless of the protection executable password protection solution must do one of the following:</p>
<ul>
<li>Compare passwords or password hashes to determine whether or not to execute the file</li>
<li>Use the inputted password for code decryption and verify the decrypted content by hashing</li>
</ul>
<p style="text-align: justify;">So, not a lot of options to choose from. First model would be the least secure since no content is encrypted and the second most secure requiring password bruteforce to be removed. Lets see what we are dealing with in LCCrypto's case. Entry point of the protected file looks like this:</p>
<blockquote>
<pre class="asm">  <span style="color: #EE4A02;">MOV</span> <span style="color: #EE1802; font-weight:bold;">EAX</span>,<span style="color: #DEE002;">DWORD</span> <span style="color: #DEE002;">PTR</span> <span style="color: #EE1802; font-weight:bold;">SS</span>:<span style="color: #FFFFFF;">&#91;</span><span style="color: #EE1802; font-weight:bold;">ESP</span><span style="color: #FFFFFF;">&#93;</span> <span style="color: #adadad; font-style: italic;">;Pointer to ExitProcess API</span>
  <span style="color: #EE4A02;">AND</span> <span style="color: #EE1802; font-weight:bold;">EAX</span>,FFFF0000
L002:
  <span style="color: #EE4A02;">CMP</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;">EAX</span><span style="color: #FFFFFF;">&#93;</span>,905A4D
  <span style="color: #EE4A02;">JE</span> L006
  <span style="color: #EE4A02;">SUB</span> <span style="color: #EE1802; font-weight:bold;">EAX</span>,<span style="color: #ff0000;">1000</span>
  <span style="color: #EE4A02;">JMP</span> L002
L006:
  <span style="color: #EE4A02;">PUSH</span> <span style="color: #EE1802; font-weight:bold;">EBP</span></pre>
</blockquote>
<p style="text-align: justify;">Very simple way to get the kernel base most commonly used in malware which could flag this sample as malicious by some anti-virus vendors. Following this we have:</p>
<blockquote>
<pre class="asm">  <span style="color: #EE4A02;">MOV</span> <span style="color: #EE1802; font-weight:bold;">EBP</span>,<span style="color: #EE1802; font-weight:bold;">EAX</span>
  <span style="color: #EE4A02;">ADD</span> <span style="color: #EE1802; font-weight:bold;">EAX</span>,<span style="color: #DEE002;">DWORD</span> <span style="color: #DEE002;">PTR</span> <span style="color: #EE1802; font-weight:bold;">DS</span>:<span style="color: #FFFFFF;">&#91;</span><span style="color: #EE1802; font-weight:bold;">EAX</span>+3C<span style="color: #FFFFFF;">&#93;</span>
  <span style="color: #EE4A02;">MOV</span> <span style="color: #EE1802; font-weight:bold;">EDI</span>,<span style="color: #DEE002;">DWORD</span> <span style="color: #DEE002;">PTR</span> <span style="color: #EE1802; font-weight:bold;">DS</span>:<span style="color: #FFFFFF;">&#91;</span>EAX<span style="color: #ff0000;">+78</span><span style="color: #FFFFFF;">&#93;</span>
  <span style="color: #EE4A02;">ADD</span> <span style="color: #EE1802; font-weight:bold;">EDI</span>,<span style="color: #EE1802; font-weight:bold;">EBP</span>
  <span style="color: #EE4A02;">MOV</span> <span style="color: #EE1802; font-weight:bold;">ESI</span>,<span style="color: #DEE002;">DWORD</span> <span style="color: #DEE002;">PTR</span> <span style="color: #EE1802; font-weight:bold;">DS</span>:<span style="color: #FFFFFF;">&#91;</span>EDI<span style="color: #ff0000;">+20</span><span style="color: #FFFFFF;">&#93;</span>
  <span style="color: #EE4A02;">ADD</span> <span style="color: #EE1802; font-weight:bold;">ESI</span>,<span style="color: #EE1802; font-weight:bold;">EBP</span>
  <span style="color: #EE4A02;">XOR</span> <span style="color: #EE1802; font-weight:bold;">EDX</span>,<span style="color: #EE1802; font-weight:bold;">EDX</span>
L007:
  <span style="color: #EE4A02;">MOV</span> <span style="color: #EE1802; font-weight:bold;">EAX</span>,<span style="color: #DEE002;">DWORD</span> <span style="color: #DEE002;">PTR</span> <span style="color: #EE1802; font-weight:bold;">DS</span>:<span style="color: #FFFFFF;">&#91;</span><span style="color: #EE1802; font-weight:bold;">ESI</span><span style="color: #FFFFFF;">&#93;</span>
  <span style="color: #EE4A02;">ADD</span> <span style="color: #EE1802; font-weight:bold;">EAX</span>,<span style="color: #EE1802; font-weight:bold;">EBP</span>
  <span style="color: #EE4A02;">CMP</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;">EAX</span><span style="color: #FFFFFF;">&#93;</span>,<span style="color: #ff0000;">50746547</span>
  <span style="color: #EE4A02;">JNZ</span> L025
  <span style="color: #EE4A02;">CMP</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>EAX<span style="color: #ff0000;">+4</span><span style="color: #FFFFFF;">&#93;</span>,41636F72
  <span style="color: #EE4A02;">JNZ</span> L025
  <span style="color: #EE4A02;">CMP</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>EAX<span style="color: #ff0000;">+8</span><span style="color: #FFFFFF;">&#93;</span>,<span style="color: #ff0000;">65726464</span>
  <span style="color: #EE4A02;">JNZ</span> L025
  <span style="color: #EE4A02;">CMP</span> <span style="color: #DEE002;">WORD</span> <span style="color: #DEE002;">PTR</span> <span style="color: #EE1802; font-weight:bold;">DS</span>:<span style="color: #FFFFFF;">&#91;</span><span style="color: #EE1802; font-weight:bold;">EAX</span>+<span style="color: #DEE002;">C</span><span style="color: #FFFFFF;">&#93;</span>,<span style="color: #ff0000;">7373</span>
  <span style="color: #EE4A02;">JNZ</span> L025
  <span style="color: #EE4A02;">MOV</span> <span style="color: #EE1802; font-weight:bold;">EAX</span>,<span style="color: #DEE002;">DWORD</span> <span style="color: #DEE002;">PTR</span> <span style="color: #EE1802; font-weight:bold;">DS</span>:<span style="color: #FFFFFF;">&#91;</span>EDI<span style="color: #ff0000;">+24</span><span style="color: #FFFFFF;">&#93;</span>
  <span style="color: #EE4A02;">ADD</span> <span style="color: #EE1802; font-weight:bold;">EAX</span>,<span style="color: #EE1802; font-weight:bold;">EBP</span>
  <span style="color: #EE4A02;">MOVZX</span> <span style="color: #EE1802; font-weight:bold;">EBX</span>,<span style="color: #DEE002;">WORD</span> <span style="color: #DEE002;">PTR</span> <span style="color: #EE1802; font-weight:bold;">DS</span>:<span style="color: #FFFFFF;">&#91;</span><span style="color: #EE1802; font-weight:bold;">EAX</span>+<span style="color: #EE1802; font-weight:bold;">EDX</span>*<span style="color: #ff0000;">2</span><span style="color: #FFFFFF;">&#93;</span>
  <span style="color: #EE4A02;">MOV</span> <span style="color: #EE1802; font-weight:bold;">EAX</span>,<span style="color: #DEE002;">DWORD</span> <span style="color: #DEE002;">PTR</span> <span style="color: #EE1802; font-weight:bold;">DS</span>:<span style="color: #FFFFFF;">&#91;</span><span style="color: #EE1802; font-weight:bold;">EDI</span>+1C<span style="color: #FFFFFF;">&#93;</span>
  <span style="color: #EE4A02;">ADD</span> <span style="color: #EE1802; font-weight:bold;">EAX</span>,<span style="color: #EE1802; font-weight:bold;">EBP</span>
  <span style="color: #EE4A02;">MOV</span> <span style="color: #EE1802; font-weight:bold;">EAX</span>,<span style="color: #DEE002;">DWORD</span> <span style="color: #DEE002;">PTR</span> <span style="color: #EE1802; font-weight:bold;">DS</span>:<span style="color: #FFFFFF;">&#91;</span><span style="color: #EE1802; font-weight:bold;">EAX</span>+<span style="color: #EE1802; font-weight:bold;">EBX</span>*<span style="color: #ff0000;">4</span><span style="color: #FFFFFF;">&#93;</span>
  <span style="color: #EE4A02;">ADD</span> <span style="color: #EE1802; font-weight:bold;">EAX</span>,<span style="color: #EE1802; font-weight:bold;">EBP</span>
  <span style="color: #EE4A02;">MOV</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: #ff0000;">407408</span><span style="color: #FFFFFF;">&#93;</span>,<span style="color: #EE1802; font-weight:bold;">EAX</span>
L025:
  <span style="color: #EE4A02;">ADD</span> <span style="color: #EE1802; font-weight:bold;">ESI</span>,<span style="color: #ff0000;">4</span>
  <span style="color: #EE4A02;">INC</span> <span style="color: #EE1802; font-weight:bold;">EDX</span>
  <span style="color: #EE4A02;">CMP</span> <span style="color: #EE1802; font-weight:bold;">EDX</span>,<span style="color: #DEE002;">DWORD</span> <span style="color: #DEE002;">PTR</span> <span style="color: #EE1802; font-weight:bold;">DS</span>:<span style="color: #FFFFFF;">&#91;</span>EDI<span style="color: #ff0000;">+18</span><span style="color: #FFFFFF;">&#93;</span>
  <span style="color: #EE4A02;">JNZ</span> L007</pre>
</blockquote>
<p style="text-align: justify;">Another code which is used to locate GetProcAddress API pointer. This is crucial since that API and already located kernel base are all that this protection needs to locate all other needed APIs to create password input dialog and process it. Code that creates the window and its elements is located just after the code locates all needed APIs. Code that is of interest is here:</p>
<blockquote>
<pre class="asm">  <span style="color: #EE4A02;">PUSH</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: #ff0000;">407004</span><span style="color: #FFFFFF;">&#93;</span>
  <span style="color: #EE4A02;">CALL</span> <span style="color: #DEE002;">NEAR</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: #ff0000;">407410</span><span style="color: #FFFFFF;">&#93;</span> <span style="color: #adadad; font-style: italic;">;FreeLibrary</span>
  <span style="color: #EE4A02;">PUSH</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: #ff0000;">407000</span><span style="color: #FFFFFF;">&#93;</span>
  <span style="color: #EE4A02;">CALL</span> <span style="color: #DEE002;">NEAR</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: #ff0000;">407410</span><span style="color: #FFFFFF;">&#93;</span> <span style="color: #adadad; font-style: italic;">;FreeLibrary</span>
  <span style="color: #EE4A02;">CMP</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: #ff0000;">407881</span><span style="color: #FFFFFF;">&#93;</span>,<span style="color: #ff0000;">0</span>
  <span style="color: #EE4A02;">JE</span> L008
  <span style="color: #EE4A02;">MOV</span> <span style="color: #EE1802; font-weight:bold;">EAX</span>,004012C0 <span style="color: #adadad; font-style: italic;">;OriginalEntryPoint</span>
  <span style="color: #EE4A02;">JMP</span> <span style="color: #DEE002;">NEAR</span> <span style="color: #EE1802; font-weight:bold;">EAX</span>
L008:
  <span style="color: #EE4A02;">PUSH</span> <span style="color: #ff0000;">0</span>
  <span style="color: #EE4A02;">CALL</span> <span style="color: #DEE002;">NEAR</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: #ff0000;">407414</span><span style="color: #FFFFFF;">&#93;</span> <span style="color: #adadad; font-style: italic;">;ExitProcess</span></pre>
</blockquote>
<p style="text-align: justify;">This is what happens when the window message processing loop just above this exits, and that will happen when the created window associated with that message processing loop terminates by window closing. Which means that if the byte at address 0x00407881 isn't set to zero LCCrypto will pass the code execution to original entry point which in this case isn't encrypted at all. Patching this compare in memory and closing the window would do the trick. Removing the protection completely would be as easy as setting the entry point address in the PE header to 0x000012C0. Normally our work would be done here, but lets dig in just a little bit more.</p>
<blockquote>
<pre class="asm">  <span style="color: #EE4A02;">PUSH</span> <span style="color: #ff0000;">10</span>
  <span style="color: #EE4A02;">PUSH</span> 0040776E
  <span style="color: #EE4A02;">PUSH</span> <span style="color: #ff0000;">64</span>
  <span style="color: #EE4A02;">PUSH</span> <span style="color: #DEE002;">DWORD</span> <span style="color: #DEE002;">PTR</span> <span style="color: #EE1802; font-weight:bold;">SS</span>:<span style="color: #FFFFFF;">&#91;</span>EBP<span style="color: #ff0000;">+8</span><span style="color: #FFFFFF;">&#93;</span>
  <span style="color: #EE4A02;">CALL</span> <span style="color: #DEE002;">NEAR</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: #ff0000;">407460</span><span style="color: #FFFFFF;">&#93;</span> <span style="color: #adadad; font-style: italic;">;GetDlgItemTextA</span>
  <span style="color: #EE4A02;">CALL</span> 00407FF9 <span style="color: #adadad; font-style: italic;">;Calculate CRC32</span>
  <span style="color: #EE4A02;">LEA</span> <span style="color: #EE1802; font-weight:bold;">EBX</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>40776E<span style="color: #FFFFFF;">&#93;</span>
  <span style="color: #EE4A02;">CALL</span> <span style="color: #ff0000;">00408021</span> <span style="color: #adadad; font-style: italic;">;Update CRC32</span>
  <span style="color: #EE4A02;">CMP</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>40775E<span style="color: #FFFFFF;">&#93;</span>,<span style="color: #EE1802; font-weight:bold;">EAX</span> <span style="color: #adadad; font-style: italic;">;Compare password CRC32</span>
<span style="color: #adadad; font-style: italic;">; DS:[0040775E]=0E1A88EF</span>
  <span style="color: #EE4A02;">SETE</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: #ff0000;">407881</span><span style="color: #FFFFFF;">&#93;</span> <span style="color: #adadad; font-style: italic;">;Set the correct password switch</span></pre>
</blockquote>
<p style="text-align: justify;">This code bit here processes the inputted password. As we can see from the code above inputted password is hashed with CRC32 and that value is compared with the value 0x0E1A88EF, and that means that hash for the password must be 0x0E1A88EF for protection to pass the control to original code. Now, leaving alone the fact that we can patch the file, think about what we can do to legitimately start the application. Bruteforce the hash? What about <a href="http://www.woodmann.com/fravia/crctut1.htm" target="_blank">make a string that has the same one</a>?</p>
<p style="text-align: justify;">CRC32 algorithm collides which means that we can create such a string. Without going into coding a program that can do that we use a <a href="http://www.peid.info/" target="_blank">PeID</a> plugin called CRC32 made by Gelios on a simple text file containing only the string "pwd". After the file's CRC32 has been set to 0x0E1A88EF our string "pwd" becomes "pwd€va" which is a string with the CRC32 hash we need. Entering such string into program will fool it into thinking that is the original password making LCCrypto execute the file normally.</p>
<p style="text-align: justify;">We didn't do any coding today because it wasn't necessary. However we did investigate the security of one executable password protection and saw all the flaws its has. Next time we return to this topic we will do some coding in order to make a bruteforce engine that will recover the password used to protect the file. Until next time...</p>
<p style="text-align: center;"><a href="http://blog.reversinglabs.com/wp-content/uploads/2009/12/LCCrypted.zip"><img title="LCCrypto" src="http://blog.reversinglabs.com/wp-content/uploads/2009/12/LCCrypto.jpg" alt="LCCrypto" width="299" height="212" /></a><br />
<a href="http://blog.reversinglabs.com/wp-content/uploads/2009/12/LCCrypted.zip">Download protected sample</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%2F12%2Fexe-password-protection%2F&amp;title=Removing%20executable%20password%20protection" 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/12/exe-password-protection/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

