<?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>exploring software and hardware security &#187; tamperproof software</title>
	<atom:link href="http://securityblog.astida.com/category/tamperproof-software/feed/" rel="self" type="application/rss+xml" />
	<link>http://securityblog.astida.com</link>
	<description>articles about secure systems, secure protocols, tamperproofing, obfuscation, authentication, attack vectors...</description>
	<lastBuildDate>Tue, 10 Nov 2009 20:44:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to securely hide a cryptographic key?</title>
		<link>http://securityblog.astida.com/2009/11/10/how-to-securely-hide-a-cryptographic-key/</link>
		<comments>http://securityblog.astida.com/2009/11/10/how-to-securely-hide-a-cryptographic-key/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 06:30:57 +0000</pubDate>
		<dc:creator>davitb</dc:creator>
				<category><![CDATA[how to design secure systems?]]></category>
		<category><![CDATA[software obfuscation]]></category>
		<category><![CDATA[tamperproof software]]></category>
		<category><![CDATA[confidentiality]]></category>
		<category><![CDATA[CryptProtectData]]></category>
		<category><![CDATA[CryptProtectMemory]]></category>
		<category><![CDATA[hardware protection]]></category>
		<category><![CDATA[obfuscation]]></category>
		<category><![CDATA[tamper proofing]]></category>
		<category><![CDATA[TPM]]></category>

		<guid isPermaLink="false">http://securityblog.astida.com/?p=342</guid>
		<description><![CDATA[In my previous article I was discussing how a “non expert” security engineer should think  about choosing the right security protocol for his system. I have tried to  present that complicated task in an easier manner.
However it’s  important to also understand that when we integrate a secret based protocol in  our [...]]]></description>
			<content:encoded><![CDATA[<p>In my previous <a href="http://securityblog.astida.com/2009/11/02/how-to-choose-the-right-security-protocol/">article</a> I was discussing how a “non expert” security engineer should think  about choosing the right security protocol for his system. I have tried to  present that complicated task in an easier manner.</p>
<p>However it’s  important to also understand that when we integrate a secret based protocol in  our system, we will  get another, more serious problem &#8211; how to securely hide the secret that is used in the protocol for authentication?</p>
<p>For example, suppose you have two components which are establishing an SSL protocol. As SSL is based on public key cryptography they both need to possess  private keys (if the authentication is mutual). So how are they going to protect their private keys locally in their systems?</p>
<p>Of course the  problem of hiding cryptographic keys or other secret information doesn’t only apply  to systems which are implementing security protocols. Encryption is the most  popular and convenient way to protect the confidentiality of information. However  when the system encrypts something there should be a way to protect the  encryption key (or the decryption key) and this, believe me, is a much, much  harder problem.</p>
<p>In this article we  will discuss the ways how one can hide secret information in:</p>
<ul>
<li>Windows  environment</li>
<li>Inside a software</li>
<li>Inside a hardware</li>
</ul>
<p>I have been doing  research on this topic more than a year now and would like to share my  knowledge and experience with you.</p>
<p>All the mentioned  topics are heavy and one cannot describe all of them in a single article. I’m  planning to have several articles describing different aspects of these themes  (such as obfuscation and tamper-proofing in software, tamper resistance in  hardware, etc).</p>
<p>So in this article  we will discuss the “theoretical” part of the topic and then will go through an  example and try to apply this knowledge in real life.</p>
<p><span id="more-342"></span></p>
<h3>The Problem</h3>
<p>The problem of  hiding a cryptographic key in a system is a widespread problem and lot of  research is going on over it worldwide. In general we can state that this  problem is not solved. Whatever technique you are going to use to protect your  information, be sure that it will be hacked over time. So engineers, instead of  looking for an ideal solution, should look for protection techniques which will  increase the <span style="text-decoration: underline;">time</span> required for breaking their systems and thus gain  business benefits.</p>
<p>Nowadays obfuscation  is the only technique to protect secret information in an un-trusted  environment. People often say (or assume by default) that putting a key in a  hardware component is much more secure than implementing protection schemes in software  itself however I don’t always agree with that opinion. If you think about it &#8211;  putting a key in a hardware device is just another way of obfuscation&#8230; Yes,  sometimes breaking hardware is more difficult than software, but it really depends  on the protection schemes that have been used on both sides. I think people  usually have this default opinion as most of them don’t have  electrical/hardware engineering education/experience and that’s why they  consider hardware related attacks to be much more difficult.</p>
<p>That is not true.</p>
<p>There are well known  and easy attacks on hardware protections and most of the devices are prone to  these attacks. I’m planning to discuss these kinds of attacks in one of my  upcoming articles.</p>
<p>In my opinion there  is only one big difference between these two systems which really makes sense.  The difference is in fact that in case of hardware the system is able to  physically remove the cryptographic key stored internally once it detected an  active attack. For software systems this is not possible as you always can copy  the software before starting attack on it. You can always put it under emulator  while conducting an attack and in this case there is just no way for it to be  able to delete the key. So you will be able to conduct the attack as many times  as you want and if during one of these experiments one of your actions brings  to deletion of the key – you can use the copy of software and continue  experiments. In case of a hardware device – it’s little harder as you can’t  physically copy the device and once the key is deleted there may be no way to  restore the data back.</p>
<p>So, in general,  hardware protection schemes are more reliable, but only if they are properly  implemented. Software obfuscation and tamper proofing schemes have been  significantly evolved in the past years and breaking these techniques is also  considered to be a big challenge. For example the well known Skype software has  been broken only after one year of its production which gave the developer company  enough time to penetrate the market without letting the competitors to steal  Skype protocol algorithm and make an illegal copy.</p>
<p>From other point of  view there is no example of an unbroken software system while such examples  exist for hardware. IBM 4758 device is a good example.</p>
<p>So let’s see what  kind of software and hardware protection schemes exists currently in the  industry. We will start discussing Windows, then go to general obfuscation and  tamper proofing techniques in software and end with hardware based protection  schemes.</p>
<h3>Hiding cryptographic key in Windows</h3>
<p>We will focus on  Windows environment as I’m more handy with this operating system when it comes  to security.</p>
<p>There is a strong  opinion among the engineering community who are not experts in security that  Windows operating system provides solid mechanism for protecting secret  information in the system. That is not quite true. Windows does a great job by  providing different mechanisms but it only does it in the scope of the  resources it has access to. An ordinary laptop or a PC doesn’t possess a  special device or a special hardware component for protecting your information…  in fact what is has is just a hard disc and a RAM. So if Windows, by its definition,  just cannot have a solid way for securely protecting your secret data.</p>
<p>However, as I said,  it provides interesting opportunities, which, if properly used, can give a  significant improvement for your application.</p>
<p><em>Account based protection</em></p>
<p>Windows provides API  to encrypt data using Windows user account credentials under which the current  application is running. CryptProtectData API receives a buffer as an input argument  and returns the encrypted buffer as a result of successful operation.  CryptUnprotectData API, in its turn, decrypts the encrypted data and returns it  to the caller. Only applications which run under the same windows account are  able to decrypt data.</p>
<p>From first point of view  this is a very limited offering. However if your application is installed under  administrator account then only limited applications would be able to access  the data that you have encrypted.</p>
<p><em>Process based protection</em></p>
<p>I you want to  protect your data in the context of a running process memory you can use  CryptoProtectMemory and CryptoUnprotectMemory APIs. The first will encrypt the  given buffer and return it and the second – decrypt and return.</p>
<p>Note that the buffer  will be encrypted only in the context of the current process. If you run the  same application again – the new process cannot decrypt it. These API are useful  when you don’t want your in-memory data to be swapped to the hard disc.</p>
<p>Another technique  for disallowing swapping is to mark the appropriate page as not swappable via VirtualLock  API.</p>
<p>This is basically  all that I’m aware of the mechanisms that Windows provides for protecting  application specific data.</p>
<h3>Hiding a cryptographic key inside software</h3>
<p>If you don’t have a  hardware component in your system &#8211; you are doomed to protect the secret  information through obfuscation and tamper proofing.</p>
<p>Although there is a  well formed opinion that whatever is obfuscated &#8211; is not secure, I wouldn’t  completely agree with it. Currently there is no alternative to obfuscation.  People who are saying that obfuscation should not be used need to invent better  protection mechanisms before making such statements.</p>
<p>You can achieve a  solid protection by properly using different techniques of obfuscation and  tamper proofing but you also need to realize that it will have an impact on  overall development, testing and deployment of the application. If the  information you are going to protect is very valuable &#8211; I wouldn’t recommend  using homegrown solutions. It’s better to integrate solutions form companies  such as Arxan, Cloakware, Syncrosoft and put the security responsibility on  them. Believe me these guys have a very good story for their secure technology  and your customers will be definitely satisfied. However, most probably, you  won’t be satisfied with their pricing&#8230;</p>
<p>Anyway, if you  decide to design and implement a homegrown solution for obfuscation and tamper  proofing there are many already known techniques that will help you to get to  the approach which is the best for you.</p>
<p>Let’s outline what  kind of techniques exists currently. We will just go over high-level  descriptions of these techniques. I’m planning to dedicate a standalone article  to these topics so there is no need to provide exhaustive explanation at this  point.</p>
<p><em>Obfuscation</em></p>
<ul>
<li>Semantics-preserving  transformations</li>
<li>Complicating  control flow</li>
<li>Opaque  predicates</li>
<li>Data  encodings</li>
<li>Breaking  abstractions</li>
<li>Moving  code around</li>
<li>Encrypting  code</li>
</ul>
<p><em>Tamper-proofing techniques</em></p>
<ul>
<li>Checker  Network</li>
<li>Hiding  hash values</li>
<li>Response  mechanisms</li>
<li>Overlapping  instructions</li>
</ul>
<h3>Hiding a cryptographic key inside hardware</h3>
<p>If you are really  targeting high-end security market you have to consider hardware level  protection for your secret information. By saying hardware I mean a hardware  device with non-volatile memory (such as OTP, ROM, EPROM, EEPROM, Flash, etc).  However, as I said earlier, you will need to implement different complicated  security measures in order to protect the data stored on this memory.</p>
<p>Remember, there are  many attacks which are much easier to conduct for a medium trained electrical  engineer on a bad designed hardware device rather than an expert software  engineer on well obfuscated software.</p>
<p>Another problem  related to hardware based protection is the deployment and adoption through  users.</p>
<p>You can also achieve  the goal of having an encryption key in hardware token without using internal  memory in the device itself. You can have a hardware device which generates a  unique, secure key on each boot so there is no need for a non-volatile memory.  There are currently IPs available for this purpose with their proprietary  technologies.</p>
<p>Many times during my experience I have heard statements like “well, we can  utilize TPM to protect our cryptographic keys”. There are people, who are  making such statements without really knowing what TPM is, and how and where  you can use it. TPM won’t help you in protecting secret information. It’s only  useful when used within the scope of a trusted stack. It can store your key  securely however only if your application is a part of trusted booting chain.  If it’s not – forget about TPM.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fsecurityblog.astida.com%2F2009%2F11%2F10%2Fhow-to-securely-hide-a-cryptographic-key%2F&amp;linkname=How%20to%20securely%20hide%20a%20cryptographic%20key%3F"><img src="http://securityblog.astida.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://securityblog.astida.com/2009/11/10/how-to-securely-hide-a-cryptographic-key/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How the crackers crack code?</title>
		<link>http://securityblog.astida.com/2009/10/11/how-the-crackers-crack-code/</link>
		<comments>http://securityblog.astida.com/2009/10/11/how-the-crackers-crack-code/#comments</comments>
		<pubDate>Sun, 11 Oct 2009 22:33:16 +0000</pubDate>
		<dc:creator>davitb</dc:creator>
				<category><![CDATA[Attacking secure systems]]></category>
		<category><![CDATA[software obfuscation]]></category>
		<category><![CDATA[tamperproof software]]></category>
		<category><![CDATA[breaking code]]></category>
		<category><![CDATA[cracking]]></category>
		<category><![CDATA[debuggers]]></category>
		<category><![CDATA[DLL hooking]]></category>
		<category><![CDATA[tamper proofing]]></category>

		<guid isPermaLink="false">http://securityblog.astida.com/?p=119</guid>
		<description><![CDATA[There are several reasons why a software company would decide to implement heavy protection schemes in their applications by spending lot of development resources, time and money. These reasons are mainly related to the business models of the applications. License based applications (IDE, compilers, etc), applications with valuable IP inside (EDA applications, etc) and applications [...]]]></description>
			<content:encoded><![CDATA[<p>There are several reasons why a software company would decide to implement heavy protection schemes in their applications by spending lot of development resources, time and money. These reasons are mainly related to the business models of the applications. License based applications (IDE, compilers, etc), applications with valuable IP inside (EDA applications, etc) and applications which have access to confidential information (DRM, authentication software, etc), in addition to their main logic, also require difficult protection schemes implemented inside which will ensure that the integrity, confidentiality and availability of the assets, inside these applications, will not be damaged.</p>
<p>It has always been a mystery for me how crackers try to break software. What techniques they are starting with when they have the executable in hand, or what tools they are using for doing the crack.</p>
<p>In general the motivation of crackers is obvious and is the same as what the abovementioned applications want to prevent from:</p>
<ul>
<li>They are trying to use software without paying money (break)</li>
<li>They are trying to steal intellectual property of applications to create a copy of it</li>
<li>They are trying to steal confidential information (such as cryptographic keys) from applications to have access to other valuable information, such as user credentials, high-definition video content, etc, which is accessible in this application</li>
</ul>
<p>In this article we will try to outline the techniques and tools that crackers are using while trying to break protections that exist in applications.</p>
<p><span id="more-119"></span></p>
<p>Typical “cracking lifecycle” consists of the following steps:</p>
<ol>
<li>Static and dynamic analysis of binary executable file</li>
<li>Preparation for an attack</li>
<li>Automation (optional)</li>
</ol>
<p>Usually the first two steps are mandatory but the third is optional and depends on the crackers motivation. If the goal is reverse engineering of IP based algorithms – there is no need to automate the attack. However, for removing license checks – the automation phase is essential.</p>
<p><img class="aligncenter size-full wp-image-120" title="The flow" src="http://securityblog.astida.com/wp-content/uploads/2009/10/flow.jpg" alt="The flow" width="758" height="323" /></p>
<p>The diagram above shows details of these steps and how they actually interact with each other. The adversary usually starts with conducting static and dynamic analyze of the executable. After some protection mechanisms are discovered, the next step will be to remove it, rebuild the executable and test. This process will continue until all protections primitives are removed.</p>
<p>During analysis the adversary can use very different techniques and of course there is no way to cover all possible approaches in one article as they are being improved over time and new, smarter, more complex approaches are being invented. It’s important to note that the cracker has full control over the environment where he runs the target executable. He can run debuggers, run the executable under virtual machine, hook system DLLs, write a kernel rootkit, etc.</p>
<p>Let’s go over each technique mentioned in the diagram above and see how they are performed.</p>
<h3><strong><strong>Learning the Executable structure (Static analysis)</strong></strong></h3>
<p>The first thing that the cracker would do (though it highly depends on his/her taste) is probably learning the structure of executable. Though this step is not very difficult (comparing to others) the information she can gather from it is essential for the next steps.</p>
<p>The following information can be comparably easily obtained from an executable:</p>
<ul>
<li>What libraries is it dynamically linked to? (if any)</li>
<li>Symbol Table (if any)</li>
<li>The starting address of executable</li>
<li>The starting and ending addresses of text and data segments</li>
</ul>
<p>Tools which can help you to dump this information are usually available by default in the operating system or are included in the package of integrated development environments. For Linux type systems it will be GNU Binutils (http://en.wikipedia.org/wiki/GNU_Binary_Utilities), for Windows – set of Dumpbin tools. In addition of course IDA Tool, PE explorer can also be used for this purpose.</p>
<p>The following link provides comprehensive listing of available tools:</p>
<p><a href="http://en.wikibooks.org/wiki/X86_Disassembly/Analysis_Tools">http://en.wikibooks.org/wiki/X86_Disassembly/Analysis_Tools</a></p>
<h3><strong><strong>Searching for known strings (Static analysis)</strong></strong></h3>
<p>The next obvious thing the adversary will try to do is searching for string characters which the program outputs as an indication for error. For example, a license checking or registration based program must have a way to inform the user that registration code is wrong or that the license has been expired. Obviously the adversary can search for these strings in the binary file and try to locate the place of license check.</p>
<p>Constant data is usually embedded in data segment so the basic algorithm for disabling the license check or registration code check would be:</p>
<ol>
<li>Search for the error indication string (smth like “incorrect registration code”) in data segment</li>
<li>Retrieve the address of this string in data segment</li>
<li>Search for the reference of this address in code segment. The code will be something like this:
<ol>
<li>cmp readRegCode, realRegCode</li>
<li>je regCodeValid</li>
<li>…</li>
</ol>
</li>
<li>Replace the “je” command with &#8216;always&#8217; jump command (“jmp”)</li>
</ol>
<p>Note that for some architectures the address gathered from data segment will not be referred directly in code but will be constructed as a “base + offset”. It may make harder finding the appropriate code in code segment.</p>
<p><strong> </strong></p>
<h3><strong><strong>De-compilation (Static analysis)</strong></strong></h3>
<p>Another helpful technique is to try to decompile the binary code into higher level language, such as C. After decompilation is done obviously the code will still be hard to analyze but it may give a better understanding of high-level structure of modules and functions in binary file.</p>
<p>The following resource discusses more about decompilation process and what can be achieved with it:</p>
<p><a href="http://en.wikipedia.org/wiki/Decompiler">http://en.wikipedia.org/wiki/Decompiler</a></p>
<p><strong> </strong></p>
<h3><strong><strong>Searching for algorithm patterns (Static analysis)</strong></strong></h3>
<p>If the target program has cryptographic features implemented inside, such as encryption/decryption functions, it may be an interesting option to try to search the binary file for patterns of “encryption instructions”.</p>
<p>Usually encryption functions have lot of XOR and SHIFT commands inside and that makes them different from usual code. Every standard encryption algorithm (AES, DES, TEA, etc) has its pattern of implementation (a sequence of assembly instructions similar to mov, shl, shl, shl, xor, shr, etc) and if the adversary searches with this pattern, he may be lucky by finding the encryption/decryption functions. After these functions are found if can be easy to locate where exactly the data is being encrypted or decrypted.</p>
<p><strong> </strong></p>
<h3><strong><strong>Listening for library calls (Dynamic analysis)</strong></strong></h3>
<p>The first dynamic analysis technique we will discuss here is the “listening for library calls”. The idea behind this technique is to set a breakpoint on a <span style="text-decoration: underline;">library function call</span> which is definitely going to be called while checking the license expiration or registration code.</p>
<p>Let’s see an example. Suppose the target program checks for registration code and prints “incorrect code” on command prompt if the input code is wrong. Most probably the program will call printf function to do the print. If the adversary sets a breakpoint in printf function and gives a wrong registration code to the program, the breakpoint will be hit. The cracker can navigate up by the call stack and find the appropriate code fragment which is comparing the real registration code with wrong one.</p>
<p>It’s possible that the target program, instead of dynamic linking, used static linking with C libraries. So it won’t be possible to set a break point on printf function as it won’t be called. For these cases there are two options:</p>
<ul>
<li>Search for the pattern of printf function in target binary and set a breakpoint there.</li>
<li>Set a breakpoint on an underlying system call which will be called when printf is called and navigate back by call stack. For printf it will probably be the “write” system call.</li>
</ul>
<p><strong> </strong></p>
<h3><strong><strong>Monitoring memory (Dynamic analysis)</strong></strong></h3>
<p>Sometimes replacing the “je” command with “jmp” won’t be enough for cracking the software. The software developers could implement complicated protections schemes against cracking which assume crashing of software at random places if the registration code was incorrect – e.g. instead of having just an “if” statement for checking the validness of input registration code the software may also have a logic which overwrites some important data in RAM and after the software executes – it crashes at different points. So even if the adversary was able to crack the checking of “reg code” she won’t be able to use the program properly.</p>
<p>In order to understand where exactly the program crashes the following technique could be used:</p>
<ol>
<li>The program is usually crashing when an inaccessible memory is read or write</li>
<li>The cracker will run the program until it’s crashed</li>
<li>The cracker will review the crash dump information and locate the memory address which was being read</li>
<li>The cracker will set a breakpoint on this memory address and wait until it’s hit</li>
<li>In simplest scenario this memory will be is just set to zero</li>
<li>After identifying the code fragment the cracker replaces the “mov” command with appropriate number of “nops” so that the size of binary file is not modified.</li>
</ol>
<p><strong> </strong></p>
<h3><strong><strong>Dumping the internal data (Dynamic analysis)</strong></strong></h3>
<p>Sometime the adversary’s goal is to obtain data which is being available in the program at some point of execution. This data could be user credentials, high definition video content, etc.</p>
<p>Let’s assume that after playing with binary file for some period the attacker found the place where the data is getting available. Now he needs to output it to an external disc. The first option that will come to mind is to add a code to the executable that dumps this data. However, this is not trivial. Adding a new code to a binary executable is not easy as it will break the offsets of different data in the binary file and its integrity will be broken.</p>
<p>So a better approach will be to use the debugger for this purpose. The adversary will run the debugger and set a breakpoint on the place where the data is available. Then he may use the features of debugger to output the content of a variable to external disc (the debuggers usually have a feature of executing set of commands when a breakpoint is hit).</p>
<p><strong> </strong></p>
<h3><strong>Hooking the library calls</strong><strong> (Dynamic analysis)</strong></h3>
<p>I’m sure everyone reading this article has heard about DLL hooking. This technique provides a way to intercept the program data that is being passed to different functions that are called from DLLs.</p>
<p>“Hooking library calls” technique can be used for two purposes:</p>
<ul>
<li>The one that we mentioned above &#8211; intercept the program data</li>
<li>Replace standard functions with yours and make the program to use them</li>
</ul>
<p>We will focus on the second technique.</p>
<p>Sometimes it’s much easier for the adversary to change the environment settings that surround the target program to turn off protection schemes implemented in the program. For example if a program is calling time() function to get the current time, the adversary might provide his own implementation of this function, which will always return a previous time and the license checking code will always succeed.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fsecurityblog.astida.com%2F2009%2F10%2F11%2Fhow-the-crackers-crack-code%2F&amp;linkname=How%20the%20crackers%20crack%20code%3F"><img src="http://securityblog.astida.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://securityblog.astida.com/2009/10/11/how-the-crackers-crack-code/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

