<?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>Not A Number &#187; security</title>
	<atom:link href="http://notanumber.net/archives/category/security/feed" rel="self" type="application/rss+xml" />
	<link>http://notanumber.net</link>
	<description>Programming, Theory, and Math</description>
	<lastBuildDate>Sat, 21 Nov 2009 00:07:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Underhanded C: The Leaky Redaction</title>
		<link>http://notanumber.net/archives/54/underhanded-c-the-leaky-redaction</link>
		<comments>http://notanumber.net/archives/54/underhanded-c-the-leaky-redaction#comments</comments>
		<pubDate>Sat, 21 Nov 2009 00:03:25 +0000</pubDate>
		<dc:creator>john</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[hacks]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://notanumber.net/?p=54</guid>
		<description><![CDATA[So, it turns out I am the winner of the 2008 Underhanded C Contest. The goal of the contest is to write some straightforward C code to solve a simple task, incorrectly. In particular, you had to introduce a hidden security flaw that would stand up to code review and not stand out at all. [...]]]></description>
			<content:encoded><![CDATA[<p>So, it turns out I am the winner of the <a href="http://underhanded.xcott.com/">2008 Underhanded C Contest</a>. The goal of the contest is to write some straightforward C code to solve a simple task, incorrectly. In particular, you had to introduce a hidden security flaw that would stand up to code review and not stand out at all. This is different than the Obfuscated C contest in that you want your program to look straightforward and that it does one thing, when in fact it does another.</p>
<p>The goal this year was to write a leaky image redaction program. Given an input image in PPM format and a rectangle, it would spit out the image with the rectangle blacked out, perhaps hiding sensitive information. The tricky part was that you had to leak the redacted information. There are more details in the <a href="http://underhanded.xcott.com/?p=8">problem specification</a>.</p>
<p>So, before I go on, here is my complete entry. See if you can figure out how the information is leaked before reading further if you like.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/*
 * This is a simple redactor, it accepts a plain text ppm file, a set of
 * coordinates defining a rectangle, and produces a ppm file with said
 * rectangle blacked out.
 *
 * Usage: redact in.ppm x y width height &gt; out.ppm
 */</span>
&nbsp;
<span style="color: #993333;">int</span>
main<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>argv<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>argc <span style="color: #339933;">!=</span> <span style="color: #0000dd;">6</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            fprintf<span style="color: #009900;">&#40;</span>stderr<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;usage: redact in.ppm x y width height &gt; out.ppm<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// process command line arguments</span>
    <span style="color: #993333;">int</span> rx <span style="color: #339933;">=</span> atoi<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> ry <span style="color: #339933;">=</span> atoi<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> rwidth <span style="color: #339933;">=</span> atoi<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> rheight <span style="color: #339933;">=</span> atoi<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">5</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    FILE <span style="color: #339933;">*</span>ppm <span style="color: #339933;">=</span> fopen<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;r&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>ppm<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        perror<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//read the ppm header</span>
    <span style="color: #993333;">unsigned</span> width<span style="color: #339933;">,</span>height<span style="color: #339933;">,</span>maxdepth<span style="color: #339933;">;</span>
    fscanf<span style="color: #009900;">&#40;</span>ppm<span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;P3<span style="color: #000099; font-weight: bold;">\n</span>%u %u<span style="color: #000099; font-weight: bold;">\n</span>%u<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>width<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>height<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>maxdepth<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;P3<span style="color: #000099; font-weight: bold;">\n</span>%u %u<span style="color: #000099; font-weight: bold;">\n</span>%u<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> width<span style="color: #339933;">,</span> height<span style="color: #339933;">,</span> maxdepth<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//current locations</span>
    <span style="color: #993333;">int</span> x <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> y <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> ws <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//fixed buffer size to avoid overflow</span>
    <span style="color: #993333;">char</span> buf<span style="color: #009900;">&#91;</span>BUFSIZE<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #339933;">*</span>c<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span>fgets<span style="color: #009900;">&#40;</span>buf<span style="color: #339933;">,</span>BUFSIZE<span style="color: #339933;">,</span>ppm<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>c <span style="color: #339933;">=</span> buf<span style="color: #339933;">;*</span>c<span style="color: #339933;">;</span>c<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>isdigit<span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>c<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>ws<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>   <span style="color: #666666; font-style: italic;">// new number, increment location.</span>
                    ws <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span> x<span style="color: #339933;">++;</span>
                    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>x <span style="color: #339933;">&gt;=</span> width <span style="color: #339933;">*</span> <span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        y<span style="color: #339933;">++;</span> x <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>x <span style="color: #339933;">&gt;</span> rx <span style="color: #339933;">*</span> <span style="color: #0000dd;">3</span> <span style="color: #339933;">&amp;&amp;</span> x <span style="color: #339933;">&lt;=</span> <span style="color: #009900;">&#40;</span>rx <span style="color: #339933;">+</span> rwidth<span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #0000dd;">3</span> <span style="color: #339933;">&amp;&amp;</span> y <span style="color: #339933;">&gt;</span> ry <span style="color: #339933;">&amp;&amp;</span> y <span style="color: #339933;">&lt;</span> ry <span style="color: #339933;">+</span> rheight<span style="color: #009900;">&#41;</span>
                    putchar<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'0'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">else</span>
                    putchar<span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>c<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>  <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
               ws <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
               putchar<span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>c<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><span id="more-54"></span><br />
The trick involves the format of the P3 style PPM file. The format is a plain text format, it has some basic header info, then a list of whitespace separated numbers, such as <code>234 2 0 83 255 255 2 43 255</code> where the numbers represent the magnitude of the red, green, and blue component for each pixel in order. The redactor simply replaced values within the target rectangle with zero. However, due to the way I process the file, character by character, I leak how many digits each value had to begin with. i.e., the above would be redacted to <code>000 0 0 00 000 000 0 00 000</code>. This is completely invisible when viewing the PPM file, all the values count as zero as far as the format is concerned, but by looking at the original file, you can recover some information about what was in the blanked out area. It is particular effective on black on white text, the most common thing needing to be redacted, where each value is 0 0 0 or 255 255 255, allowing perfect reconstruction of the original.</p>
<p>One of my favorite parts of my entry that isn&#8217;t mentioned on the prize page is that it has great plausible deniability as the leak was introduced by properly working around a commonly known and particularly insidious C bug, the improper use of gets and (more subtly) fgets. I can imagine a code review going somewhat like the following:</p>
<blockquote><p>Spook: &#8220;So why did you process the file character by character, rather than doing the more obvious scanf(&#8220;%i %i %i&#8221;,&amp;r,&amp;g,&amp;b) to read in the values?&#8221;</p>
<p>Me: &#8220;Well, in order to do that I&#8217;d have to read in entire lines of the file. Now there is the gets function in C which does that, but has a well known buffer overflow bug if the line length exceeds your buffer size, so I naturally used the safe fgets variant of the function. Of course, with fgets, you can just assume your buffer size is greater than the maximum line length, but that introduces a subtle bug if it isn&#8217;t, you may end up splitting a number across two buffers, so scanf will read something like 234 as the two numbers 23 and 4 if it is split after the second character, hence the need to consider each character independently.&#8221;</p>
<p>Spook: &#8220;Ah, of course. good job at spotting that.&#8221;</p>
<p>Me: *snicker*</p></blockquote>
<p>It is also a great example of the principle that you can&#8217;t protect against intending to write the wrong thing. The code will stand up to any buffer overflow check, code style check, or lint program. The code is correct and proper C code; the bug was not introduced in the code, but much earlier, in my head when I conceived the algorithm. No matter how smart your tools are, if you ultimately intend to write the wrong thing or solve the wrong problem, they can&#8217;t protect against that.</p>
]]></content:encoded>
			<wfw:commentRss>http://notanumber.net/archives/54/underhanded-c-the-leaky-redaction/feed</wfw:commentRss>
		<slash:comments>30</slash:comments>
		</item>
		<item>
		<title>On Biometrics and Passwords</title>
		<link>http://notanumber.net/archives/19/on-biometrics-and-passwords</link>
		<comments>http://notanumber.net/archives/19/on-biometrics-and-passwords#comments</comments>
		<pubDate>Thu, 16 Apr 2009 00:41:08 +0000</pubDate>
		<dc:creator>john</dc:creator>
				<category><![CDATA[security]]></category>
		<category><![CDATA[biometrics]]></category>
		<category><![CDATA[crypto]]></category>
		<category><![CDATA[society]]></category>

		<guid isPermaLink="false">http://notanumber.net/?p=19</guid>
		<description><![CDATA[It seems that whenever the topic of biometrics comes up there are some that can&#8217;t stop worrying about what will happen if someone gets ahold of your biometric data. After all, how hard is it to lift a fingerprint off a glass at a pub? Will using fingerprints for authentication mean you have to wear [...]]]></description>
			<content:encoded><![CDATA[<p>It seems that whenever the topic of biometrics comes up there are some that can&#8217;t stop worrying about what will happen if someone gets ahold of your biometric data. After all, how hard is it to lift a fingerprint off a glass at a pub? Will using fingerprints for authentication mean you have to wear gloves everywhere or be subject to identity theft or will you have to burn off your prints and get new ones if someone compromises your fingerprint? Well, The answers are no. The reason for the confusion probably stems from thinking of biometrics as passwords, secret things that only you have. However, this is not the case at all.  The security of biometrics comes from the fact there is only one human that matches the profile, not the secrecy of the profile itself.</p>
<p>A fingerprint cannot be compromised. A biometric identifier is not like a password. it is not meant to be secret. Think of your fingerprint as&#8230; well&#8230; like a public key cryptographic fingerprint really. Your public key fingerprint isn&#8217;t secret. in fact, you generally want to distribute it as far and wide as possible. What makes it useful is that there is a corresponding private key that only you have that can be matched to said public key. A physical fingerprint is similar, everyone knows your fingerprint but there is only one warm human body that is associated with it. Present the warm human body (your own) that matches the fingerprint on file and you gain access. So we have the analogy that a <strong>public key fingerprint</strong> is to a <strong>private key</strong> as a <strong>physical fingerprint</strong> is to a <strong>warm human body with said fingerprint</strong>.</p>
<p>This of course means that biometrics are only good for &#8216;online&#8217; verification, meaning there is a trusted path between your body and whomever you are identifying with. this can be anything from a physically secure ATM, a security guard that applys the test, or whatever is appropriate for the application. The security of biometrics comes not from the secrecy of the fingerprint, but the security of the path from the human being biometrically tested to the verifyer. Hence, you cannot &#8216;compromise a fingerprint&#8217;. You can however compromise a specific biometric system. If you find you can lift and transfer fingerprints easily with a gummy bear for a specific reader, you have broken that particular reader, but you don&#8217;t need to burn off your fingerprints and get new ones (like you change passwords when one has been compromised). you simply stop trusting anything that uses said broken reader.</p>
<p><em>PS. does anyone else enjoy the irony of using an abstract mathematical concept to explain a straightforward real world transaction?</em><em> </em><em> <img src='http://notanumber.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </em></p>
]]></content:encoded>
			<wfw:commentRss>http://notanumber.net/archives/19/on-biometrics-and-passwords/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

