<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>The What, Why and How of Software Security : Cryptography</title><link>http://blogs.msdn.com/varun_sharma/archive/tags/Cryptography/default.aspx</link><description>Tags: Cryptography</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Catch the Security Flaw #3</title><link>http://blogs.msdn.com/varun_sharma/archive/2008/07/14/catch-the-security-flaw-3.aspx</link><pubDate>Mon, 14 Jul 2008 13:17:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8731276</guid><dc:creator>Varun Sharma</dc:creator><slash:comments>8</slash:comments><comments>http://blogs.msdn.com/varun_sharma/comments/8731276.aspx</comments><wfw:commentRss>http://blogs.msdn.com/varun_sharma/commentrss.aspx?PostID=8731276</wfw:commentRss><description>&lt;p&gt;Quite a few web applications encrypt query string values. This is generally done as an added measure to prevent unauthorized access. Since the end user cannot chose a value and then encrypt it, changing parameters becomes difficult. But encryption is not a panacea. See if you can spot this bug. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/varun_sharma/WindowsLiveWriter/CatchtheSecurityFlaw3_9AB4/encrypt1.gif"&gt;&lt;img title="encrypt1" height="524" alt="encrypt1" src="http://blogs.msdn.com/blogfiles/varun_sharma/WindowsLiveWriter/CatchtheSecurityFlaw3_9AB4/encrypt1_thumb.gif" width="750" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The code behind file looks like this:-&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/varun_sharma/WindowsLiveWriter/CatchtheSecurityFlaw3_9AB4/encrypt2_1.gif"&gt;&lt;img title="encrypt2" height="580" alt="encrypt2" src="http://blogs.msdn.com/blogfiles/varun_sharma/WindowsLiveWriter/CatchtheSecurityFlaw3_9AB4/encrypt2_thumb_1.gif" width="750" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Implementation for the Encrypt and Decrypt methods is not shown. They are using the DES algorithm. There is no flaw in the usage or key management. &lt;/p&gt;  &lt;p&gt;The end user can upload files and the screen look like this:-&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/varun_sharma/WindowsLiveWriter/CatchtheSecurityFlaw3_9AB4/encrypt3.gif"&gt;&lt;img title="encrypt3" height="258" alt="encrypt3" src="http://blogs.msdn.com/blogfiles/varun_sharma/WindowsLiveWriter/CatchtheSecurityFlaw3_9AB4/encrypt3_thumb.gif" width="750" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;On clicking Upload, the file gets uploaded and a message is shown. Note the query string values. The HTML source is also shown. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/varun_sharma/WindowsLiveWriter/CatchtheSecurityFlaw3_9AB4/encrypt4.gif"&gt;&lt;img title="encrypt4" height="489" alt="encrypt4" src="http://blogs.msdn.com/blogfiles/varun_sharma/WindowsLiveWriter/CatchtheSecurityFlaw3_9AB4/encrypt4_thumb.gif" width="750" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Do you think the code or design is flawed in any way? Can this be exploited? &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8731276" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/varun_sharma/archive/tags/Catch+the+security+flaw/default.aspx">Catch the security flaw</category><category domain="http://blogs.msdn.com/varun_sharma/archive/tags/Cryptography/default.aspx">Cryptography</category><category domain="http://blogs.msdn.com/varun_sharma/archive/tags/+++Authorization+++/default.aspx">   Authorization   </category></item><item><title>Confusion property of symmetric block ciphers</title><link>http://blogs.msdn.com/varun_sharma/archive/2008/07/14/confusion-property-of-symmetric-block-ciphers.aspx</link><pubDate>Mon, 14 Jul 2008 09:43:15 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8730991</guid><dc:creator>Varun Sharma</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/varun_sharma/comments/8730991.aspx</comments><wfw:commentRss>http://blogs.msdn.com/varun_sharma/commentrss.aspx?PostID=8730991</wfw:commentRss><description>&lt;p&gt;Modern symmetric block encryption algorithms need to satisfy a number of properties to be considered strong. One such property is the property of “Confusion”. &lt;/p&gt;  &lt;p&gt;What it means is that if an attacker is conducting an exhaustive key search, and if the key being tested is incorrect only in a few bits, the decrypted text should give no such indication. If the decrypted text does give such an indication, then the attacker can stop the brute force process, and simply change the incorrect bits in the key and get the actual key. This will take much less time relative to a full brute force attack. &lt;/p&gt;  &lt;p&gt;To understand this better, I will demo it using the &lt;a href="http://www.cryptool.org/" target="_blank"&gt;CrypTool&lt;/a&gt;, which is a great tool to learn about cryptography. &lt;/p&gt;  &lt;p&gt;1. This will encrypt the text shown in the background using the Simple Substitution Cipher and the key “ONCEUPATIMXBDFGHJKLQRSVWYZ”. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/varun_sharma/WindowsLiveWriter/Confusionpropertyofciphers_9A80/crypt1_1.gif"&gt;&lt;img title="crypt1" height="506" alt="crypt1" src="http://blogs.msdn.com/blogfiles/varun_sharma/WindowsLiveWriter/Confusionpropertyofciphers_9A80/crypt1_thumb_1.gif" width="750" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;2. Text in the background has been encrypted. Using the tool, I will now perform an automatic analysis of the cipher text to try to get the key. Note: This could have been a brute force attack too. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/varun_sharma/WindowsLiveWriter/Confusionpropertyofciphers_9A80/crypt2.gif"&gt;&lt;img title="crypt2" height="523" alt="crypt2" src="http://blogs.msdn.com/blogfiles/varun_sharma/WindowsLiveWriter/Confusionpropertyofciphers_9A80/crypt2_thumb.gif" width="750" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;3. Although the correct key has not been found, since the decrypted text resembles text in English to a great extent, I may be “close” to the the actual key. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/varun_sharma/WindowsLiveWriter/Confusionpropertyofciphers_9A80/crypt3.gif"&gt;&lt;img title="crypt3" height="584" alt="crypt3" src="http://blogs.msdn.com/blogfiles/varun_sharma/WindowsLiveWriter/Confusionpropertyofciphers_9A80/crypt3_thumb.gif" width="750" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;4. I will now stop the brute force process and using manual analysis , one by one substitute only those characters in the key that seem to produce incorrect plaintext, thereby getting the actual key. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/varun_sharma/WindowsLiveWriter/Confusionpropertyofciphers_9A80/crypt4.gif"&gt;&lt;img title="crypt4" height="567" alt="crypt4" src="http://blogs.msdn.com/blogfiles/varun_sharma/WindowsLiveWriter/Confusionpropertyofciphers_9A80/crypt4_thumb.gif" width="750" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Modern encryption algorithms like DES and AES have the Confusion property. Therefore if English text has been encrypted using DES or AES and during the brute force process, the key being tested differs from the actual key by only one bit, still the decrypted text does not resemble English text at all.&amp;#160; &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8730991" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/varun_sharma/archive/tags/Cryptography/default.aspx">Cryptography</category><category domain="http://blogs.msdn.com/varun_sharma/archive/tags/Security+Tool/default.aspx">Security Tool</category></item><item><title>Block Ciphers:  Simple attack on ECB mode</title><link>http://blogs.msdn.com/varun_sharma/archive/2007/11/27/block-ciphers-simple-attack-on-ecb-mode.aspx</link><pubDate>Wed, 28 Nov 2007 00:17:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6560255</guid><dc:creator>Varun Sharma</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/varun_sharma/comments/6560255.aspx</comments><wfw:commentRss>http://blogs.msdn.com/varun_sharma/commentrss.aspx?PostID=6560255</wfw:commentRss><description>This is nothing new, but I just wanted to document it on my blog. Block ciphers encrypt data in blocks of bits. These blocks are generally 64 or 128 bits long. In the ECB (or Electronic Code Book) mode, each block is encrypted independently of the other blocks. As a result if two blocks are same, the same cipher text results. This enables the attacker to figure out all instances of a plaintext if that plaintext-cipher text pair is known and the cipher text is repeating. An attack based on the frequency analysis of the blocks is also possible. Frequently repeating cipher text blocks mean frequently repeating plain text blocks. 
&lt;P&gt;I will show the effects of another simple attack. In this case consider that the plain text is "Give Jo one two one two dollars". Note that I have purposely divided the message into blocks of 8 characters (or 64 bits in ASCII). "Give Jo " is the first block, "one two " is the next and so on. &lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;IMG src="http://blogs.msdn.com/photos/varun_sharma/images/6560151/original.aspx" mce_src="http://blogs.msdn.com/photos/varun_sharma/images/6560151/original.aspx"&gt;&lt;/P&gt;
&lt;P&gt;Now I will use the &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/system.security.cryptography.descryptoserviceprovider.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/system.security.cryptography.descryptoserviceprovider.aspx"&gt;DESCryptoServiceProvider&lt;/A&gt; class to encrypt this plaintext using ECB mode. The code used to encrypt is available &lt;A class="" href="http://support.microsoft.com/kb/307010" mce_href="http://support.microsoft.com/kb/307010"&gt;here&lt;/A&gt;. The only difference is that I have changed the mode to ECB, and the block size to 64 bits for this demo to work. &lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;IMG src="http://blogs.msdn.com/photos/varun_sharma/images/6560147/original.aspx" mce_src="http://blogs.msdn.com/photos/varun_sharma/images/6560147/original.aspx"&gt;&lt;/P&gt;
&lt;P&gt;After encrypting the plain text, the cipher text received is:-&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;IMG src="http://blogs.msdn.com/photos/varun_sharma/images/6560127/original.aspx" mce_src="http://blogs.msdn.com/photos/varun_sharma/images/6560127/original.aspx"&gt;&lt;/P&gt;
&lt;P&gt;First of all note the repeated block because of ECB. "one two one two" (from the plain text) consists of two blocks of 64 bits each. These blocks give identical cipher text blocks because of ECB. &lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;IMG src="http://blogs.msdn.com/photos/varun_sharma/images/6560143/original.aspx" mce_src="http://blogs.msdn.com/photos/varun_sharma/images/6560143/original.aspx"&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Now consider if an attacker removes one of these blocks. This is the cipher text after removing one of the repeating blocks. &lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;IMG src="http://blogs.msdn.com/photos/varun_sharma/images/6560141/original.aspx" mce_src="http://blogs.msdn.com/photos/varun_sharma/images/6560141/original.aspx"&gt;&lt;/P&gt;
&lt;P&gt;If I decrypt this cipher text, using the same code (and key) I get:-&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;IMG src="http://blogs.msdn.com/photos/varun_sharma/images/6560149/original.aspx" mce_src="http://blogs.msdn.com/photos/varun_sharma/images/6560149/original.aspx"&gt;&lt;/P&gt;
&lt;P&gt;Notice that the decryption was possible and successful, but the plain text is now different from the original plain text. Jo now gets lot less dollars ;)&lt;/P&gt;
&lt;P&gt;Ofcourse these are the reasons why ECB mode is not preferred. &lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6560255" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/varun_sharma/archive/tags/Cryptography/default.aspx">Cryptography</category></item><item><title>The Unbreakable Cipher</title><link>http://blogs.msdn.com/varun_sharma/archive/2007/11/15/the-unbreakable-cipher.aspx</link><pubDate>Thu, 15 Nov 2007 10:37:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6247238</guid><dc:creator>Varun Sharma</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/varun_sharma/comments/6247238.aspx</comments><wfw:commentRss>http://blogs.msdn.com/varun_sharma/commentrss.aspx?PostID=6247238</wfw:commentRss><description>&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;The concept of perfect secrecy is that given the cipher text, and any resources and amount of time, the adversary has no way of getting to the plain text. Having the cipher text makes no difference and provides absolutely no additional information. The adversary can try a brute force approach, by trying each and every key, one by one, but this will still require the adversary to guess the plaintext. A cipher that enables this is an unbreakable cipher. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;The contemporary symmetric encryption algorithms like AES and Triple-DES are not unbreakable ciphers in this sense. If you know that the plain text is a sentence in English, you have the cipher text, and you brute force, it may take you a long time, but eventually you will get only a few (probably only one) sentence in English as the plain text. This would beyond doubt be the plain text that you were looking for. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;There is only one unbreakable cipher, which provides perfect secrecy as defined above. This is the One-time pad. In a One-time pad, the key size is equal to the size of the data to be encrypted. A key is used only once to encrypt data. This one-time key is random. When Alice wants to send an encrypted message (a sentence in English) to Bob, Alice generates a random sequence of bits, equal in length to the message and XOR’s this key and the message. To decrypt, Bob then XOR’s the cipher text with this One-time random key and the plain text is retrieved. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;If Eve gets hold of the cipher text in transit, she may decide to get the plain text by brute forcing. If the message is n-bits, Eve can one by one, try all n-bit sequences as the key. But this will create every sentence in English of that length. In other words, given any sentence in English (constructed from n-bits), there will be a key that will transform the given cipher text to that sentence. Hence even knowing the cipher text requires Eve to guess the plaintext and provides absolutely no additional information. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;The reason One-time pad is rarely used is because it requires the key to be transferred securely before the cipher text is transmitted, and since the key length is equal to the message length, key distribution becomes a problem. &lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6247238" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/varun_sharma/archive/tags/Cryptography/default.aspx">Cryptography</category></item></channel></rss>