<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0">
  <channel>
    <title><![CDATA[[SecurityRatty] tag: rand]]></title>
    <link>http://securityratty.com/tag/rand</link>
    <description></description>
    <pubDate>Tue, 18 Mar 2008 16:48:00 +0000</pubDate>
    <generator>iRatty Engine</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <item>
      <title><![CDATA[Understanding Terrorist Behavior]]></title>
      <link>http://securityratty.com/article/d3c4c28fba09d80f242a713ad5208337</link>
      <guid>http://securityratty.com/article/d3c4c28fba09d80f242a713ad5208337</guid>
      <description><![CDATA[Two items, one short and one long
The short one: &quot; A Look at Terrorist Behavior: How They Prepare, Where They Strike ,&quot; by Brent Smith, National Institute of Justice Journal , No. 260, 2008
The long...]]></description>
      <content:encoded><![CDATA[<p>Two items, one short and one long.</p>

<p>The short one: "<a href="http://www.ncjrs.gov/pdffiles1/nij/222900.pdf">A Look at Terrorist Behavior: How They Prepare, Where They Strike</a>," by Brent Smith, <i>National Institute of Justice Journal</i>, No. 260, 2008.</p>

<p>The long one: <a href="http://www.rand.org/pubs/monographs/2008/RAND_MG741-1.pdf"><i>How Terrorist Groups End: Lessons for Countering al Qa'ida</i></a>, by Seth G. Jones and Martin C. Libicki, RAND Corporation, 2008.<br />
</p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/schneier/fulltext?a=4RRuN"><img src="http://feeds.feedburner.com/~f/schneier/fulltext?i=4RRuN" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/schneier/fulltext?a=m41mN"><img src="http://feeds.feedburner.com/~f/schneier/fulltext?i=m41mN" border="0"></img></a>
</div>]]></content:encoded>
      <pubDate>Mon, 03 Nov 2008 03:57:40 +0000</pubDate>
      <category domain="http://securityratty.com/tag/terrorist">terrorist</category>
      <category domain="http://securityratty.com/tag/terrorist behavior">terrorist behavior</category>
      <category domain="http://securityratty.com/tag/short">short</category>
      <category domain="http://securityratty.com/tag/national institute">national institute</category>
      <category domain="http://securityratty.com/tag/justice journal">justice journal</category>
      <category domain="http://securityratty.com/tag/rand corporation">rand corporation</category>
      <category domain="http://securityratty.com/tag/brent smith">brent smith</category>
      <category domain="http://securityratty.com/tag/strike">strike</category>
      <category domain="http://securityratty.com/tag/lessons">lessons</category>
      <source url="http://www.schneier.com/blog/archives/2008/11/understanding_t.html">Understanding Terrorist Behavior</source>
    </item>
    <item>
      <title><![CDATA[WordPress 2.6.2 Released Due To PHP Weakness That Might Lead To Attack]]></title>
      <link>http://securityratty.com/article/d17d95ad39817a7dd2c4b3c980804a06</link>
      <guid>http://securityratty.com/article/d17d95ad39817a7dd2c4b3c980804a06</guid>
      <description><![CDATA[New WordPress version, 2.6.2, was released today to mitigate a new attack vector discovered by PHP security researcher Stefan Esser. According to an advisory from WordPress blog, Stefan Esser recently...]]></description>
      <content:encoded><![CDATA[New WordPress version, 2.6.2, was released today to mitigate a new attack vector discovered by PHP security researcher Stefan Esser. According to an advisory from WordPress blog, Stefan Esser recently warned developers of the dangers of SQL Column Truncation and the weakness of mt_rand(). Blogs that allow users registration should be upgraded as soon as [...]]]></content:encoded>
      <pubDate>Mon, 08 Sep 2008 23:24:16 +0000</pubDate>
      <category domain="http://securityratty.com/tag/sql column truncation">sql column truncation</category>
      <category domain="http://securityratty.com/tag/stefan esser recently">stefan esser recently</category>
      <category domain="http://securityratty.com/tag/weakness">weakness</category>
      <category domain="http://securityratty.com/tag/wordpress blog">wordpress blog</category>
      <category domain="http://securityratty.com/tag/users registration">users registration</category>
      <category domain="http://securityratty.com/tag/wordpress version">wordpress version</category>
      <category domain="http://securityratty.com/tag/attack vector">attack vector</category>
      <category domain="http://securityratty.com/tag/blogs">blogs</category>
      <category domain="http://securityratty.com/tag/rand">rand</category>
      <source url="http://cyberinsecure.com/wordpress-262-released-due-to-php-weakness-that-might-lead-to-attack/">WordPress 2.6.2 Released Due To PHP Weakness That Might Lead To Attack</source>
    </item>
    <item>
      <title><![CDATA[Improve Security with "A Layer of Hurt"]]></title>
      <link>http://securityratty.com/article/8863df5f439aabcb64e3fc7d0777f2bf</link>
      <guid>http://securityratty.com/article/8863df5f439aabcb64e3fc7d0777f2bf</guid>
      <description><![CDATA[Hello, Michael here
I got a lot of interesting comments from my TechEd 2008 presentation entitled, &quot;How To Review Your Code And Test For Security Bugs,&quot; but the most comments and questions were...]]></description>
      <content:encoded><![CDATA[Hello, Michael here. 
<P>I got a lot of interesting comments from my <A href="http://blogs.msdn.com/sdl/archive/2008/06/26/security-thoughts-from-teched-2008.aspx" mce_href="http://blogs.msdn.com/sdl/archive/2008/06/26/security-thoughts-from-teched-2008.aspx">TechEd 2008 presentation</A> entitled, "How To Review Your Code And Test For Security Bugs," but the most comments and questions were reserved for fuzz testing; I was blown away by the number of people who thought fuzz testing was hard, or that you only left fuzz testing to ‘leet hackers.</P>
<P>During the presentation I mentioned in some depth how to perform fuzz testing, and what parts of an application should be fuzz testing targets. I also introduced an idea (that's not new) to help people who have never performed fuzz testing begin fuzz testing with very little cost and friction. The idea is to add a small layer of code to an application to automatically mutate untrusted data as it comes into an application; I called that code layer "a layer of hurt."</P>
<P>Before I continue, I want to point out that fuzzing is an SDL requirement, but the idea in this blog post is not an SDL requirement, it's just another way to help meet SDL fuzzing requirements.</P>
<P>Adding a layer of hurt, as shown in the picture below, is pretty simple as it involves adding code to an application to tweak data as it comes into an application. You can work out where to place the fuzzing code by looking at your threat models to see where data crosses trust boundaries. You could also simply grep the code looking for APIs that read data, for example:</P>
<UL>
<LI>Read from files: fread, ReadFile</LI>
<LI>Reading from sockets: recv, recvfrom</LI>
<LI>For .NET code, any stream.Read</LI></UL>
<P>You get the picture.</P>
<P>The fuzzing code should appear right after the API that reads that data.</P>
<P mce_keep="true">For example, C or C++ code that reads from a UDP socket and then fuzzes the data before it's consumed by the rest of the application might look like this:</P><FONT size=1 face=Courier>
<P>char RecvBuf[1024];<BR>int&nbsp; BufLen = sizeof(RecvBuf);</P>
<P mce_keep="true">int result = recvfrom(<BR>&nbsp;&nbsp; RecvSocket, <BR>&nbsp;&nbsp; RecvBuf, <BR>&nbsp;&nbsp; BufLen, <BR>&nbsp;&nbsp; 0, <BR>&nbsp;&nbsp; (SOCKADDR *)&amp;SenderAddr, <BR>&nbsp;&nbsp; &amp;SenderAddrSize);</P></FONT><FONT size=1 face=Courier>
<P>#ifdef _FUZZ<BR>&nbsp;&nbsp; Fuzz(RecvBuf,&amp;BufLen);<BR>#endif</P></FONT>
<P>Or, in C#, code that reads from an untrusted file:</P><FONT size=1 face=Courier>
<P>FileStream fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read);<BR>uint len = (uint)(fileStream.Length);<BR>byte[] fileData = new byte[fileStream.Length];<BR>fileStream.Read(fileData, 0, (int)len);<BR>fileStream.Close();</P></FONT><FONT size=1 face=Courier>
<P mce_keep="true">#if _FUZZ_<BR>&nbsp; Malform pain = new Malform();<BR>&nbsp; fileData = pain.Fuzz(fileData);<BR>#endif</P></FONT>
<P>In both code examples, Fuzz() mutates the incoming data. In the C++ case, the fuzzing code looks like this:</P><FONT size=1 face=Courier>
<P>void Fuzz(_Inout_bytecap_(*pcbBuf) char *pBuf, <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _Inout_ size_t *pcbBuf) {<BR><BR>&nbsp; if (!pcbBuf || !pBuf || !*pcbBuff || *pBuf) return;<BR>&nbsp; if ((rand() % 100) &gt; 5) return; // fuzz about 5% of Buffers</P>
<P>&nbsp; size_t cLoop = 1 + (rand() % 4);</P>
<P>&nbsp; for (size_t j = 0; j &lt; cLoop; j++) {</P>
<P>&nbsp;&nbsp;&nbsp; size_t i=0,&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; iLow = rand() % *pcbBuf,&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; iHigh = 1+rand() % *pcbBuf,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; iIter = 1+rand() % 8;<BR><BR>&nbsp;&nbsp;&nbsp; if (iLow &gt; iHigh)&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {size_t t=iHigh; iHigh=iLow; iLow=t;}</P>
<P>&nbsp;&nbsp;&nbsp; char ch=0;<BR>&nbsp;&nbsp;&nbsp; switch(rand() % 9) {</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 0 : // reset upper bits<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (i=iLow; i &lt; iHigh; i++)&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pBuf[i] &amp;= 0x7F;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case 1 : // set upper bits<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (i=iLow; i &lt; iHigh; i++)&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pBuf[i] |= 0x80;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 2 : // toggle all bits<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (i=iLow; i &lt; iHigh; i++)&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pBuf[i] ^= 0xFF;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case 3 : // set to random chars<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (i=iLow; i &lt; iHigh; i++)&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pBuf[i] = (char)(rand() % 256);&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 4 : // set NULL chars to (possibly) non-NULL<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (i=iLow; i &lt; iHigh; i++)&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (!pBuf[i])&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pBuf[i] = (char)(rand() % 256);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case 5 : // swap adjacent bytes<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (i=iLow; i &lt; __max(iHigh-1,iLow); i+= iIter)&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {char t=pBuf[i]; pBuf[i] = pBuf[i+1]; pBuf[i+1]=t;}&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 6 : // set to random chars every n-bytes<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (i=iLow; i &lt; __max(iHigh-1,iLow); i+= iIter)&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pBuf[i] = (char)(rand()%256);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 7 : // set bytes to one random char<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ch=(char)(rand() % 256);&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (i=iLow; i &lt; iHigh; i++)&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pBuf[i] = ch;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; default: // truncate stream<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *pcbBuf = iHigh;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<BR>&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp; }<BR>}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </P></FONT>
<P>The sample C# and C++ fuzzing code is available as a ZIP file at the end of this post.</P>
<P>This code is an example of dumb-fuzzing, which is fuzzing with little or no regard for the data structure being manipulated. If you've never performed any kind of fuzz testing in the past, then you will probably find bugs with this simple fuzzing technique. Once you have weeded out the low-hanging bugs, you may need to turn your attention to smarter fuzzers. For example, in theory, this code would find few if any bugs in a PNG parser, because PNG files have a built in check-sum, so if you fuzz a PNG file, you'd have to recalculate the checksum to get decent code coverage.</P>
<P>When I showed this code during my presentation, I urged people to add it to their applications today if they currently don't do fuzz testing, and simply run their applications through their normal testing processes. Within three days of my presentation I received emails from people saying they had found bugs. I have no doubt others did too.</P>
<P>One of the comments I made during the session was,"If you can't spend the time on great fuzzing, fuzz anyway" and adding a "layer of hurt" is a reasonable start.</P>
<P>Please feel free to sound off if you have ideas to help improve the code and let us know what you think, either through email or comments to this post.</P><img src="http://blogs.msdn.com/aggbug.aspx?PostID=8794487" width="1" height="1">]]></content:encoded>
      <pubDate>Thu, 31 Jul 2008 15:13:00 +0000</pubDate>
      <category domain="http://securityratty.com/tag/layer">layer</category>
      <category domain="http://securityratty.com/tag/code layer">code layer</category>
      <category domain="http://securityratty.com/tag/code">code</category>
      <category domain="http://securityratty.com/tag/decent code coverage">decent code coverage</category>
      <category domain="http://securityratty.com/tag/fuzz">fuzz</category>
      <category domain="http://securityratty.com/tag/void fuzz">void fuzz</category>
      <category domain="http://securityratty.com/tag/ifdef fuzz">ifdef fuzz</category>
      <category domain="http://securityratty.com/tag/code examples">code examples</category>
      <category domain="http://securityratty.com/tag/perform fuzz">perform fuzz</category>
      <source url="http://blogs.msdn.com/sdl/archive/2008/07/31/improve-security-with-a-layer-of-hurt.aspx">Improve Security with "A Layer of Hurt"</source>
    </item>
    <item>
      <title><![CDATA[True Randomness]]></title>
      <link>http://securityratty.com/article/ff2ff9d806ca80ccb9a8c226a35f4fb6</link>
      <guid>http://securityratty.com/article/ff2ff9d806ca80ccb9a8c226a35f4fb6</guid>
      <description><![CDATA[One more time on the Debian OpenSSL bug. It inspired web developer Bo Allen to look into the randomness of the PHP rand() function. He compared it to the results from random.org , which uses...]]></description>
      <content:encoded><![CDATA[One more time on the Debian OpenSSL bug. <a href="http://www.boallen.com/random-numbers.html">It inspired web developer Bo Allen to look into the randomness of the PHP rand() function.</a> He compared it to the results from <a href="http://random.org/">random.org</a>, which uses atmospheric noise as a random seed. The result is a visually clear example of randomness and not-so-randomness. Read the blog, you'll see what I mean.

Allen's test makes me think that someone (no, I don't have the time) should do the same with other programmatic random number generators.<br style="clear: both;"/>
  <img alt="" style="border: 0; height:1px; width:1px;" border="0" src="http://www.pheedo.com/img.phdo?i=f293038fae6eb9871a875925318c58b3" height="1" width="1"/>
<img src="http://www.pheedo.com/feeds/tracker.php?i=f293038fae6eb9871a875925318c58b3" style="display: none;" border="0" height="1" width="1" alt=""/><img src="http://feeds.ziffdavisenterprise.com/~r/RSS/cheap_hack/~4/295313035" height="1" width="1"/>]]></content:encoded>
      <pubDate>Wed, 21 May 2008 12:36:10 +0000</pubDate>
      <category domain="http://securityratty.com/tag/random">random</category>
      <category domain="http://securityratty.com/tag/random seed">random seed</category>
      <category domain="http://securityratty.com/tag/randomness">randomness</category>
      <category domain="http://securityratty.com/tag/programmatic random">programmatic random</category>
      <category domain="http://securityratty.com/tag/debian openssl bug">debian openssl bug</category>
      <category domain="http://securityratty.com/tag/time">time</category>
      <category domain="http://securityratty.com/tag/atmospheric noise">atmospheric noise</category>
      <category domain="http://securityratty.com/tag/web developer">web developer</category>
      <category domain="http://securityratty.com/tag/php rand">php rand</category>
      <source url="http://feeds.ziffdavisenterprise.com/~r/RSS/cheap_hack/~3/295313035/true_randomness.html">True Randomness</source>
    </item>
    <item>
      <title><![CDATA[Random Number Bug in Debian Linux]]></title>
      <link>http://securityratty.com/article/d97f7c48f785b7b3291ff6888ab149f0</link>
      <guid>http://securityratty.com/article/d97f7c48f785b7b3291ff6888ab149f0</guid>
      <description><![CDATA[This is a big deal : On May 13th, 2008 the Debian project announced that Luciano Bello found an interesting vulnerability in the OpenSSL package they were distributing. The bug in question was caused...]]></description>
      <content:encoded><![CDATA[<p>This is a <a href="http://metasploit.com/users/hdm/tools/debian-openssl/">big deal</a>:</p>

<blockquote>On May 13th, 2008 the Debian project <a href="http://www.debian.org/security/2008/dsa-1571">announced</a> that Luciano Bello found an interesting vulnerability in the OpenSSL package they were distributing. The bug in question was caused by the removal of the following line of code from <i>md_rand.c</i>

<pre>
	MD_Update(&m,buf,j);
	[ .. ]
	MD_Update(&m,buf,j); /* purify complains */
</pre>

<p>These lines were <a href="http://svn.debian.org/viewsvn/pkg-openssl/openssl/trunk/rand/md_rand.c?rev=141&view=diff&r1=141&r2=140&p1=openssl/trunk/rand/md_rand.c&p2=/openssl/trunk/rand/md_rand.c">removed</a> because they caused the <a href="http://valgrind.org/">Valgrind</a> and Purify tools to produce warnings about the use of uninitialized data in any code that was linked to OpenSSL. You can see one such report to the OpenSSL team <a href="http://rt.openssl.org/Ticket/Display.html?id=521&user=guest&pass=guest">here</a>. Removing this code has the side effect of crippling the seeding process for the OpenSSL PRNG. Instead of mixing in random data for the initial seed, the only "random" value that was used was the current process ID. On the Linux platform, the default maximum process ID is 32,768, resulting in a very small number of seed values being used for all PRNG operations.</blockquote></p>

<p>More info, from Debian, <a href="http://www.debian.org/security/2008/dsa-1571">here</a>.  And from the hacker community <a href="http://milw0rm.com/exploits/5622">here</a>.  Seems that the bug was introduced in September 2006.</p>

<p>More <a href="http://blog.sesse.net/blog/tech/2008-05-14-17-21_some_maths.html">analysis</a> <a href="http://taint.org/2008/05/13/153959a.html">here</a>.  And a <a href="http://www.xkcd.com/424/#">cartoon</a>.</p>

<p>Random numbers are used everywhere in cryptography, for both short- and long-term security.  And, as we've seen here, security flaws in random number generators are really easy to accidently create and really hard to discover after the fact.  Back when the NSA was routinely weakening commercial cryptography, their favorite technique was reducing the entropy of the random number generator.</p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/schneier/fulltext?a=IxrPYH"><img src="http://feeds.feedburner.com/~f/schneier/fulltext?i=IxrPYH" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/schneier/fulltext?a=CnBMwH"><img src="http://feeds.feedburner.com/~f/schneier/fulltext?i=CnBMwH" border="0"></img></a>
</div>]]></content:encoded>
      <pubDate>Mon, 19 May 2008 02:07:59 +0000</pubDate>
      <category domain="http://securityratty.com/tag/random">random</category>
      <category domain="http://securityratty.com/tag/openssl">openssl</category>
      <category domain="http://securityratty.com/tag/openssl team">openssl team</category>
      <category domain="http://securityratty.com/tag/random data">random data</category>
      <category domain="http://securityratty.com/tag/process">process</category>
      <category domain="http://securityratty.com/tag/debian">debian</category>
      <category domain="http://securityratty.com/tag/current process">current process</category>
      <category domain="http://securityratty.com/tag/openssl package">openssl package</category>
      <category domain="http://securityratty.com/tag/bug">bug</category>
      <source url="http://www.schneier.com/blog/archives/2008/05/random_number_b.html">Random Number Bug in Debian Linux</source>
    </item>
    <item>
      <title><![CDATA[Got Entropy ?]]></title>
      <link>http://securityratty.com/article/e241bfde32ce971a3341a22fcb76c27d</link>
      <guid>http://securityratty.com/article/e241bfde32ce971a3341a22fcb76c27d</guid>
      <description><![CDATA[So I have been planning a series of podcasts on Cryptographic Controls. In the process of this planning, I fell into one of the classic traps that crypto-geeks fall into: obsessing about random number...]]></description>
      <content:encoded><![CDATA[<p>So I have been planning a series of podcasts on Cryptographic Controls. In the process of this planning, I fell into one of the classic traps that crypto-geeks fall into: obsessing about random number  generators (RNGs).</p>
<p><em>(FYI, for the impatient, <a href="http://gotentropy.artofinfosec.com/" >click here</a>.)<br />
</em></p>
<p>There are two ways to generate random numbers on computers: (1) use a software program called a Pseudorandom Number Generator (PRNG) or (2) use a hardware random number generator. A Pseudorandom Number Generator uses a seed value to generate a sequence of numbers that appear random. The problem is that the same seed generates the same random sequence. The hardware based RNG observes and samples some physical phenomenon which is random, such as cosmic rays, RF noise, etc. (aka Entropy).</p>
<p>RNGs are important in Information Security because they are used to generate encryption keys, salts, etc. Historically, attacking RNGs has proven effective, such as the defeat of <a href="http://community.webreview.com/windows/184409807" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://community.webreview.com/windows/184409807');">Netscape&#8217;s HTTPS sessions</a>.</p>
<p>Most operating systems utilize a hybrid approach, implementing a PseudoRandom Number Generator that has a seed that is regularly updated through the collection of random hardware events. This process is called Entropy Collection or Entropy Harvesting. <strong>For most applications, this approach should be completely sufficient.</strong> However, one of the key assumptions is that the operating system has been up and running long enough for the seed value itself to become hard to predict through the collection of Entropy. Also, many of the Entropy collecting events come from properties of hardware devices, such as the minor variations in hard drive rate of rotation. As such, there are a few circumstances where the OS RNG may not be good enough for strong cryptographic key generation:</p>
<ul>
<li>Live Boot CD ( The start state of the RNG may be predictable. )</li>
<li>Virtualized Hosts ( OS may be dependent on simulated events for randomness. )</li>
</ul>
<p>( Given the exploding popularity of virtualization, this is an area worthy of research. Stay tuned. )</p>
<p><strong>Design of the Got Entropy Service</strong></p>
<p>Many RNGs (such as the one included in Linux, as well as OpenSSL&#8217;s) allow the addition of entropy from outside sources. So I started looking to Entropy sources I could use to bolster the RNGs on my virtual hosts (and other uses&#8230;). While I was looking into this, it occurred to me that I had an unused TV tuner card, a PVR-350.</p>
<p>When a TV is tuned to a channel with no local station, the &#8217;snow&#8217; on the screen is RF noise (the same as the static between stations on AM radios). But, for reasons beyond our scope, you never use a direct physical observation as the RNG. You have to &#8216;de-skew and whiten&#8217; the data prior to sampling it. Here is the process that I use:</p>
<ol>
<li>Collect about 3 minutes of video ( about 130 MB data ).</li>
<li>Using a random key and IV, encrypt the data ( using openssl &amp; AES-128-CBC ).</li>
<li>Discard the first 32k of the file.</li>
<li>Use each of the following 32k blocks as samples.</li>
<li>Compress each sample with SHA-256.</li>
<li>Discard the last block.</li>
</ol>
<ul>
<li>Steps 2 and 3 remove any patterns, such as MPEG file formatting, from the data.</li>
<li>Steps 4 and 5 generate a 32-byte random value ( 1024 to 1 compression in the hash ).</li>
</ul>
<p><strong>Check it out at <a href="http://gotentropy.artofinfosec.com" >http://gotentropy.artofinfosec.com</a></strong></p>
<p><strong>Can an Attacker Broadcast a Signal to Undermine This?</strong></p>
<p>Such an attacker could not remove RF noise from the received signal. Our eyes and brains are good at filtering out the noise in the TV video, but there is a lot of it. Part of the noise comes from the atmospheric background RF, but there are also flaws (noise) in the tuner&#8217;s radio and analog-to-digital capture circuitry.</p>
<p>I think this is a pretty strong RNG, and I have provided an interface for pulling just the values.</p>
<p>Also, I have written a script ( <a href="http://gotentropy.artofinfosec.com/getEntropy.sh" >getEntropy.sh</a> ) that will pull Entropy from the service and seed it into /dev/random on Linux.</p>
<p><strong>Results from ENT</strong></p>
<p>Here are results, from a sample run of the Got Entropy, analyzed by  <a href="http://www.fourmilab.ch/random/" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://www.fourmilab.ch/random/');">ENT</a> ( A Pseudorandom Number Sequence Test Program provided by John Walker of www.fourmilab.ch - Thanks, John! ).</p>
<ul>
<li>Entropy = 7.999987 bits per byte</li>
<li>Optimum compression would reduce the size of this 13366112 byte file by 0 percent.</li>
<li>Chi square distribution for 13366112 samples is 233.85, and randomly would exceed this value 82.48 percent of the time.</li>
<li>Arithmetic mean value of data bytes is 127.4767 (127.5 = random).</li>
<li>Monte Carlo value for Pi is 3.143054786 (error = 0.05 percent).</li>
<li>Serial correlation coefficient is -0.000078 (totally uncorrelated = 0.0).</li>
</ul>
<p><strong>Resources for the Curious&#8230;</strong></p>
<ul>
<li><a href="http://en.wikipedia.org/wiki/Pseudorandom_number_generator" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://en.wikipedia.org/wiki/Pseudorandom_number_generator');">Wikipedia - Pseudo-random Number Generator</a></li>
<li><a href="http://en.wikipedia.org/wiki/Hardware_random_number_generator" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://en.wikipedia.org/wiki/Hardware_random_number_generator');">Wikipedia - Hardware Random Number Generator</a></li>
<li><a href="http://csrc.nist.gov/groups/ST/toolkit/rng/index.html" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://csrc.nist.gov/groups/ST/toolkit/rng/index.html');">NIST - Random Numbers Page</a></li>
<li><a href="http://community.webreview.com/windows/184409807" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://community.webreview.com/windows/184409807');">Netscape RNG Attack</a></li>
<li><a href="http://www.vanheusden.com/ved/" onclick="javascript:pageTracker._trackPageview('/outbound/article/http://www.vanheusden.com/ved/');">van Heusden Video Rand</a></li>
</ul>
<p>Cheers, Erik</p>
<p><a href="http://artofinfosec.com" >Art of Information Security</a> would <a href="http://artofinfosec.com/feedback/" >love your feedback</a> !</p>
<p><a href="http://artofinfosec.com/?p=53" >Got Entropy ?</a></p>
<img src="http://feeds.feedburner.com/~r/artofinfosec/~4/262366868" height="1" width="1"/>]]></content:encoded>
      <pubDate>Tue, 01 Apr 2008 22:55:47 +0000</pubDate>
      <category domain="http://securityratty.com/tag/entropy">entropy</category>
      <category domain="http://securityratty.com/tag/random">random</category>
      <category domain="http://securityratty.com/tag/32-byte random">32-byte random</category>
      <category domain="http://securityratty.com/tag/byte">byte</category>
      <category domain="http://securityratty.com/tag/hardware random">hardware random</category>
      <category domain="http://securityratty.com/tag/entropy sources">entropy sources</category>
      <category domain="http://securityratty.com/tag/sequence">sequence</category>
      <category domain="http://securityratty.com/tag/random sequence">random sequence</category>
      <category domain="http://securityratty.com/tag/pull entropy">pull entropy</category>
      <source url="http://feeds.feedburner.com/~r/artofinfosec/~3/262366868/">Got Entropy ?</source>
    </item>
    <item>
      <title><![CDATA[Banning function calls, assurance, and retrofitting]]></title>
      <link>http://securityratty.com/article/c3835e6e08eb86271d4f5ffac2f324a6</link>
      <guid>http://securityratty.com/article/c3835e6e08eb86271d4f5ffac2f324a6</guid>
      <description><![CDATA[I've been working on some C/C++ secure coding standards lately, and trying to mesh those up with the results from the static analyzer I'm using. As it turns out there is a fine line to be drawn...]]></description>
      <content:encoded><![CDATA[I've been working on some C/C++ secure coding standards lately, and trying to mesh those up with the results from the static analyzer I'm using.  As it turns out there is a fine line to be drawn between what you consider best practices, what a static analyzer can find, how much context the static analyzer has, and how much manual review you really want to put up with.<br /><br />Let me give a specific example.<br /><br />Coverity's Prevent analyzer has a number of built-in "unsafe" functions defined.  The list includes the standard cast such as scanf, strcpy, strcat, etc.  On top of that though they add some things that didn't make Microsoft's <a href="http://msdn2.microsoft.com/en-us/library/bb288454.aspx">list</a>; for example, rand().<br /><br />I don't technically have a problem with including rand() in the list of things to be extremely careful about, but whereas it is nearly impossible to guarantee that someone has used strcpy() right, rand() actually has some pretty legitimate uses.<br /><br />Consider the case where we want to do a randomized delay in processing something, or where we wish to randomly assign work to different people when it comes in, or randomly pull an item off a work queue for a customer service agent.  None of these cases requires a cryptographically sound random number generator.  For the most part, using rand() is a perfectly reasonable choice in this sort of situation.<br /><br />When you decide that you want to ban certain function calls, or call them out in findings in a static analyzer, you're treading a fine line with your developers and the people you're going to ask to go and clean up the old code you have around.  You can choose to go several routes.<br /><br /><ul><li>File defects against the old code for any use of a banned function, without investigating the specific use</li><li>File defects against old code only after verifying that in the context you have a potential vulnerability</li><li>Get a dedicated team together to just go and clean up old code</li></ul>Each of these approaches has its plusses and minuses.<br /><br />If you choose to file defects against your developers for code that is years old and wasn't necessarily written by them without verifying the vulnerabilities, you run the risk of them not taking the secure coding rules seriously.  Many of the items they find are going to be false positives from a currently-exploitable perspective, and they are going to be cranky with you.<br /><br />If you choose to go through the validate each and every defect and the types of defect are pervasive, you're going to spend almost as much verifying the defect as fixing it.  Especially if you're going through and simply replacing strcpy() with strlcpy() for example.   For both this and the case above though, developers are going to be going through the code, and with the proper training/awareness, they might actually learn more about some of the old code, or at least start to have a better sense of some real security issues in the code.<br /><br />If you choose to get a dedicated team together to fix the old code, you're likely to save money in the short run.  A dedicated team is going to get used to fixing the coding defects of this type, and you're going to make a lot shorter job of it.  The downside being that the regular developers aren't getting some of the code review experience you'd really like.<br /><br />To top things off, if you go route #2, wherein you only fix things that are currently exploitable, you run the risk of the code being used in a different way elsewhere and causing problems down the road.<br /><br />Back to my rand() example.  In every case where I've found rand() used it hasn't been in a security critical context.  Do I want to leave these instances of rand() in my code as examples that others might follow, next time in a security sensitive context?  Or, do I want to take a relatively dogmatic approach to this and all other banned/"unsafe" functions and eliminate them entirely from my codebase?<br /><br />I'm leaning towards some sort of middle ground.  If I can find the time for a dedicated team to go through the code to clean up old issues, then I'm likely to remove all instances of things that could be unsafe, just so we don't leave things around that could be copied into an truly unsafe context.<br /><br />Its a tricky balancing act to determine how dogmatic you want to be about fixing up the use of certain "unsafe" functions.  Getting it wrong either way can have long term consequences for your secure development program.  As always, the right answer depends on a lot of factors.<img src="http://feeds.feedburner.com/~r/SecurityRetentive/~4/254025736" height="1" width="1"/>]]></content:encoded>
      <pubDate>Tue, 18 Mar 2008 16:48:00 +0000</pubDate>
      <category domain="http://securityratty.com/tag/code review experience">code review experience</category>
      <category domain="http://securityratty.com/tag/code">code</category>
      <category domain="http://securityratty.com/tag/security sensitive context">security sensitive context</category>
      <category domain="http://securityratty.com/tag/context">context</category>
      <category domain="http://securityratty.com/tag/security critical context">security critical context</category>
      <category domain="http://securityratty.com/tag/unsafe context">unsafe context</category>
      <category domain="http://securityratty.com/tag/static analyzer">static analyzer</category>
      <category domain="http://securityratty.com/tag/file defects">file defects</category>
      <category domain="http://securityratty.com/tag/rand">rand</category>
      <source url="http://feeds.feedburner.com/~r/SecurityRetentive/~3/254025736/banning-function-calls-assurance-and.html">Banning function calls, assurance, and retrofitting</source>
    </item>
  </channel>
</rss>
