<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>argp's blog</title>
	
	<link>http://argp.gr/blog</link>
	<description>The third argument to ioctl() is traditionally named char *argp.</description>
	<lastBuildDate>Fri, 28 May 2010 14:19:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/argp" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="argp" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>FreeBSD kernel NFS client local vulnerabilities</title>
		<link>http://argp.gr/blog/2010/05/23/freebsd-kernel-nfsclient/</link>
		<comments>http://argp.gr/blog/2010/05/23/freebsd-kernel-nfsclient/#comments</comments>
		<pubDate>Sun, 23 May 2010 08:23:15 +0000</pubDate>
		<dc:creator>argp</dc:creator>
				<category><![CDATA[advisories]]></category>
		<category><![CDATA[census]]></category>
		<category><![CDATA[freebsd]]></category>
		<category><![CDATA[kernel]]></category>
		<category><![CDATA[nfsclient]]></category>
		<category><![CDATA[research]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://argp.gr/blog/?p=256</guid>
		<description><![CDATA[

census ID:
census-2010-0001


CVE ID:
CVE-2010-2020


Affected Products:
FreeBSD 8.0-RELEASE, 7.3-RELEASE, 7.2-RELEASE


Class:
Improper Input Validation (CWE-20)


Remote:
No


Discovered by:
Patroklos Argyroudis


We have discovered two improper input validation vulnerabilities in the FreeBSD kernel&#8217;s NFS client-side implementation (FreeBSD 8.0-RELEASE, 7.3-RELEASE and 7.2-RELEASE) that allow local unprivileged users to escalate their privileges, or to crash the system by performing a denial of service attack.
Details
FreeBSD is an advanced [...]]]></description>
			<content:encoded><![CDATA[<table>
<tr>
<td>census ID:</td>
<td>census-2010-0001</td>
</tr>
<tr>
<td>CVE ID:</td>
<td><a href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2010-2020">CVE-2010-2020</a></td>
</tr>
<tr>
<td>Affected Products:</td>
<td>FreeBSD 8.0-RELEASE, 7.3-RELEASE, 7.2-RELEASE</td>
</tr>
<tr>
<td>Class:</td>
<td>Improper Input Validation (<a href="http://cwe.mitre.org/data/definitions/20.html">CWE-20</a>)</td>
</tr>
<tr>
<td>Remote:</td>
<td>No</td>
</tr>
<tr>
<td>Discovered by:</td>
<td>Patroklos Argyroudis</td>
</tr>
</table>
<p>We have discovered two improper input validation vulnerabilities in the FreeBSD kernel&#8217;s NFS client-side implementation (FreeBSD 8.0-RELEASE, 7.3-RELEASE and 7.2-RELEASE) that allow local unprivileged users to escalate their privileges, or to crash the system by performing a denial of service attack.</p>
<h3>Details</h3>
<p><a href="http://www.freebsd.org/">FreeBSD</a> is an advanced operating system which focuses on reliability and performance.  More information about its features can be found <a href="http://www.freebsd.org/about.html">here</a>.</p>
<p>FreeBSD 8.0-RELEASE, 7.3-RELEASE and 7.2-RELEASE employ an improper input validation method in the kernel&#8217;s NFS client-side implementation.  Specifically, the first vulnerability is in function <code>nfs_mount()</code> (file <code>src/sys/nfsclient/nfs_vfsops.c</code>) which is reachable from the <code>mount(2)</code> and <code>nmount(2)</code> system calls.  In order for them to be enabled for unprivileged users the <code>sysctl(8)</code> variable <code>vfs.usermount</code> must be set to a non-zero value.</p>
<p>The function <code>nfs_mount()</code> employs an insufficient input validation method for copying data passed in a structure of type <code>nfs_args</code> from userspace to kernel.  Specifically, the file handle buffer to be mounted (<code>args.fh</code>) and its size (<code>args.fhsize</code>) are completely user-controllable.  The unbounded copy operation is in file <code>src/sys/nfsclient/nfs_vfsops.c</code> (the excerpts are from 8.0-RELEASE):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1094
1095
1096
1097
1098
1099
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>has_fh_opt<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      error <span style="color: #339933;">=</span> copyin<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>caddr_t<span style="color: #009900;">&#41;</span>args.<span style="color: #202020;">fh</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span>caddr_t<span style="color: #009900;">&#41;</span>nfh<span style="color: #339933;">,</span>
           args.<span style="color: #202020;">fhsize</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>error<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #b1b100;">goto</span> out<span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>The declaration of the variables <code>args</code> and <code>nfh</code> is at:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">static</span> <span style="color: #993333;">int</span>
nfs_mount<span style="color: #009900;">&#40;</span><span style="color: #993333;">struct</span> mount <span style="color: #339933;">*</span>mp<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
        <span style="color: #993333;">struct</span> nfs_args args <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
            .<span style="color: #202020;">version</span> <span style="color: #339933;">=</span> NFS_ARGSVERSION<span style="color: #339933;">,</span>
            .<span style="color: #202020;">addr</span> <span style="color: #339933;">=</span> NULL<span style="color: #339933;">,</span>
            .<span style="color: #202020;">addrlen</span> <span style="color: #339933;">=</span> <span style="color: #993333;">sizeof</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">struct</span> sockaddr_in<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            .<span style="color: #202020;">sotype</span> <span style="color: #339933;">=</span> SOCK_STREAM<span style="color: #339933;">,</span>
            .<span style="color: #202020;">proto</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span>
            .<span style="color: #202020;">fh</span> <span style="color: #339933;">=</span> NULL<span style="color: #339933;">,</span>
            .<span style="color: #202020;">fhsize</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span>
            .<span style="color: #202020;">flags</span> <span style="color: #339933;">=</span> NFSMNT_RESVPORT<span style="color: #339933;">,</span>
            .<span style="color: #202020;">wsize</span> <span style="color: #339933;">=</span> NFS_WSIZE<span style="color: #339933;">,</span>
            .<span style="color: #202020;">rsize</span> <span style="color: #339933;">=</span> NFS_RSIZE<span style="color: #339933;">,</span>
            .<span style="color: #202020;">readdirsize</span> <span style="color: #339933;">=</span> NFS_READDIRSIZE<span style="color: #339933;">,</span>
            .<span style="color: #202020;">timeo</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">10</span><span style="color: #339933;">,</span>
            .<span style="color: #202020;">retrans</span> <span style="color: #339933;">=</span> NFS_RETRANS<span style="color: #339933;">,</span>
            .<span style="color: #202020;">maxgrouplist</span> <span style="color: #339933;">=</span> NFS_MAXGRPS<span style="color: #339933;">,</span>
            .<span style="color: #202020;">readahead</span> <span style="color: #339933;">=</span> NFS_DEFRAHEAD<span style="color: #339933;">,</span>
            .<span style="color: #202020;">wcommitsize</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span>                   <span style="color: #808080; font-style: italic;">/* was: NQ_DEFLEASE */</span>
            .<span style="color: #202020;">deadthresh</span> <span style="color: #339933;">=</span> NFS_MAXDEADTHRESH<span style="color: #339933;">,</span>    <span style="color: #808080; font-style: italic;">/* was: NQ_DEADTHRESH */</span>
            .<span style="color: #202020;">hostname</span> <span style="color: #339933;">=</span> NULL<span style="color: #339933;">,</span>
            <span style="color: #808080; font-style: italic;">/* args version 4 */</span>
            .<span style="color: #202020;">acregmin</span> <span style="color: #339933;">=</span> NFS_MINATTRTIMO<span style="color: #339933;">,</span>
            .<span style="color: #202020;">acregmax</span> <span style="color: #339933;">=</span> NFS_MAXATTRTIMO<span style="color: #339933;">,</span>
            .<span style="color: #202020;">acdirmin</span> <span style="color: #339933;">=</span> NFS_MINDIRATTRTIMO<span style="color: #339933;">,</span>
            .<span style="color: #202020;">acdirmax</span> <span style="color: #339933;">=</span> NFS_MAXDIRATTRTIMO<span style="color: #339933;">,</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
        <span style="color: #993333;">int</span> error<span style="color: #339933;">,</span> ret<span style="color: #339933;">,</span> has_nfs_args_opt<span style="color: #339933;">;</span>
        <span style="color: #993333;">int</span> has_addr_opt<span style="color: #339933;">,</span> has_fh_opt<span style="color: #339933;">,</span> has_hostname_opt<span style="color: #339933;">;</span>
        <span style="color: #993333;">struct</span> sockaddr <span style="color: #339933;">*</span>nam<span style="color: #339933;">;</span>
        <span style="color: #993333;">struct</span> vnode <span style="color: #339933;">*</span>vp<span style="color: #339933;">;</span>
        <span style="color: #993333;">char</span> hst<span style="color: #009900;">&#91;</span>MNAMELEN<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        size_t len<span style="color: #339933;">;</span>
        u_char nfh<span style="color: #009900;">&#91;</span>NFSX_V3FHMAX<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This vulnerability can cause a kernel stack overflow which leads to privilege escalation on FreeBSD 7.3-RELEASE and 7.2-RELEASE.  On FreeBSD 8.0-RELEASE the result is a kernel crash/denial of service due to the SSP/ProPolice kernel stack-smashing protection which is enabled by default.  Versions 7.1-RELEASE and earlier do not appear to be vulnerable since the bug was introduced in 7.2-RELEASE. In order to demonstrate the impact of the vulnerability we have developed a <a href="http://census-labs.com/media/nfs_mount_ex.c">proof-of-concept privilege escalation exploit</a>.  A sample run of the exploit follows:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>argp<span style="color: #000000; font-weight: bold;">@</span>julius ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ <span style="color: #c20cb9; font-weight: bold;">uname</span> <span style="color: #660033;">-rsi</span>
FreeBSD <span style="color: #000000;">7.3</span>-RELEASE GENERIC
<span style="color: #7a0874; font-weight: bold;">&#91;</span>argp<span style="color: #000000; font-weight: bold;">@</span>julius ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ sysctl vfs.usermount
vfs.usermount: <span style="color: #000000;">1</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>argp<span style="color: #000000; font-weight: bold;">@</span>julius ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ <span style="color: #c20cb9; font-weight: bold;">id</span>
<span style="color: #007800;">uid</span>=<span style="color: #000000;">1001</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>argp<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">gid</span>=<span style="color: #000000;">1001</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>argp<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">groups</span></span>=<span style="color: #000000;">1001</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>argp<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>argp<span style="color: #000000; font-weight: bold;">@</span>julius ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ <span style="color: #c20cb9; font-weight: bold;">gcc</span> <span style="color: #660033;">-Wall</span> nfs_mount_ex.c <span style="color: #660033;">-o</span> nfs_mount_ex
<span style="color: #7a0874; font-weight: bold;">&#91;</span>argp<span style="color: #000000; font-weight: bold;">@</span>julius ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ .<span style="color: #000000; font-weight: bold;">/</span>nfs_mount_ex
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> calling nmount<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">!</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> nmount error: <span style="color: #660033;">-1030740736</span>
nmount: Unknown error: <span style="color: #660033;">-1030740736</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>argp<span style="color: #000000; font-weight: bold;">@</span>julius ~<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ <span style="color: #c20cb9; font-weight: bold;">id</span>
<span style="color: #007800;">uid</span>=<span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>root<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">gid</span>=<span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>wheel<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">egid</span>=<span style="color: #000000;">1001</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>argp<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">groups</span></span>=<span style="color: #000000;">1001</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>argp<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>The second vulnerability exists in the function <code>mountnfs()</code> that is called from function <code>nfs_mount()</code>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1119
1120
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">error <span style="color: #339933;">=</span> mountnfs<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>args<span style="color: #339933;">,</span> mp<span style="color: #339933;">,</span> nam<span style="color: #339933;">,</span> args.<span style="color: #202020;">hostname</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>vp<span style="color: #339933;">,</span>
    curthread<span style="color: #339933;">-&gt;</span>td_ucred<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The function <code>mountnfs()</code> is reachable from the <code>mount(2)</code> and <code>nmount(2)</code> system calls by unprivileged users.  As with the <code>nfs_mount()</code> case above, this requires the <code>sysctl(8)</code> variable <code>vfs.usermount</code> to be set to a non-zero value.</p>
<p>The file handle to be mounted (<code>argp->fh</code>) and its size (<code>argp->fhsize</code>) are passed to function <code>mountnfs()</code> from function <code>nfs_mount()</code> and are user-controllable.  These are subsequently used in an unbounded <code>bcopy()</code> call (file <code>src/sys/nfsclient/nfs_vfsops.c</code>):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1219
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">bcopy<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>caddr_t<span style="color: #009900;">&#41;</span>argp<span style="color: #339933;">-&gt;</span>fh<span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span>caddr_t<span style="color: #009900;">&#41;</span>nmp<span style="color: #339933;">-&gt;</span>nm_fh<span style="color: #339933;">,</span> argp<span style="color: #339933;">-&gt;</span>fhsize<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The above can cause a kernel heap overflow when <code>argp->fh</code> is bigger than 128 bytes (the size of <code>nmp->nm_fh</code>) since <code>nmp</code> is an allocated item on the Universal Memory Allocator (UMA, the FreeBSD kernel&#8217;s heap allocator) zone <code>nfsmount_zone</code> (again from <code>src/sys/nfsclient/nfs_vfsops.c</code>):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">static</span> <span style="color: #993333;">int</span>
mountnfs<span style="color: #009900;">&#40;</span><span style="color: #993333;">struct</span> nfs_args <span style="color: #339933;">*</span>argp<span style="color: #339933;">,</span> <span style="color: #993333;">struct</span> mount <span style="color: #339933;">*</span>mp<span style="color: #339933;">,</span> <span style="color: #993333;">struct</span> sockaddr <span style="color: #339933;">*</span>nam<span style="color: #339933;">,</span>
    <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>hst<span style="color: #339933;">,</span> <span style="color: #993333;">struct</span> vnode <span style="color: #339933;">**</span>vpp<span style="color: #339933;">,</span> <span style="color: #993333;">struct</span> ucred <span style="color: #339933;">*</span>cred<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
        <span style="color: #993333;">struct</span> nfsmount <span style="color: #339933;">*</span>nmp<span style="color: #339933;">;</span>
        <span style="color: #993333;">struct</span> nfsnode <span style="color: #339933;">*</span>np<span style="color: #339933;">;</span>
        <span style="color: #993333;">int</span> error<span style="color: #339933;">;</span>
        <span style="color: #993333;">struct</span> vattr attrs<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>mp<span style="color: #339933;">-&gt;</span>mnt_flag <span style="color: #339933;">&amp;</span> MNT_UPDATE<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                nmp <span style="color: #339933;">=</span> VFSTONFS<span style="color: #009900;">&#40;</span>mp<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;%s: MNT_UPDATE is no longer handled here<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> __func__<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                free<span style="color: #009900;">&#40;</span>nam<span style="color: #339933;">,</span> M_SONAME<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><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>
                nmp <span style="color: #339933;">=</span> uma_zalloc<span style="color: #009900;">&#40;</span>nfsmount_zone<span style="color: #339933;">,</span> M_WAITOK<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This kernel heap overflow can lead on FreeBSD 8.0-RELEASE, 7.3-RELEASE and 7.2-RELEASE to privilege escalation and/or a kernel crash/denial of service attack.  Similarly to the first vulnerability, FreeBSD 7.1-RELEASE and earlier versions do not appear to be vulnerable.  We have developed a <a href="http://census-labs.com/media/mountnfsex.c">proof-of-concept DoS exploit</a> to demonstrate the vulnerability.  Furthermore, we have also developed a privilege escalation exploit for this second vulnerability which will not be released at this point.</p>
<p>FreeBSD has released an <a href="http://security.freebsd.org/advisories/FreeBSD-SA-10:06.nfsclient.asc">official advisory</a> and a <a href="http://security.FreeBSD.org/patches/SA-10:06/nfsclient.patch">patch</a> to address both vulnerabilities. All affected parties are advised to follow the upgrade instructions included in the advisory and patch their systems.</p>
]]></content:encoded>
			<wfw:commentRss>http://argp.gr/blog/2010/05/23/freebsd-kernel-nfsclient/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FreeBSD kernel exploitation mitigations</title>
		<link>http://argp.gr/blog/2010/04/26/kernel-exploitation-mitigations/</link>
		<comments>http://argp.gr/blog/2010/04/26/kernel-exploitation-mitigations/#comments</comments>
		<pubDate>Mon, 26 Apr 2010 07:40:46 +0000</pubDate>
		<dc:creator>argp</dc:creator>
				<category><![CDATA[exploitation]]></category>
		<category><![CDATA[exploitation mitigation]]></category>
		<category><![CDATA[freebsd]]></category>
		<category><![CDATA[kernel]]></category>
		<category><![CDATA[memory corruption protection]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://argp.gr/blog/?p=241</guid>
		<description><![CDATA[In my recent Black Hat Europe 2010 talk I gave an overview of the kernel exploitation prevention mechanisms that exist on FreeBSD. A few people at the conference have subsequently asked me to elaborate on the subject. In this post I will collect all the information from my talk and the various discussions I had [...]]]></description>
			<content:encoded><![CDATA[<p>In my recent <a href="http://www.blackhat.com/html/bh-eu-10/bh-eu-10-archives.html#Argyroudis">Black Hat Europe 2010 talk</a> I gave an overview of the kernel exploitation prevention mechanisms that exist on FreeBSD. A few people at the conference have subsequently asked me to elaborate on the subject. In this post I will collect all the information from my talk and the various discussions I had in the Black Hat conference hallways.</p>
<p>Userland memory corruption protections (also known as exploitation mitigations) have made most of the generic exploitation approaches obsolete. This is true both on Windows and Unix-like operating systems. In order to successfully achieve arbitrary code execution from a vulnerable application nowadays a researcher needs to look to the memory layout and the code structure of the particular application.</p>
<p>On the other hand,  exploitation mitigation mechanisms for kernel code have not seen the same level of adoption mostly due to the performance penalty they introduce. This has increased the interest in viewing the operating system kernel as part of the attack surface targeted in a penetration test. Therefore, many operating systems have started to introduce kernel exploitation mitigations. The <a href="http://www.cr0.org/paper/to-jt-party-at-ring0.pdf">recent CanSecWest talk</a> by Tavis Ormandy and Julien Tinnes titled &#8220;There&#8217;s a party at Ring0, and you&#8217;re invited&#8221; presented an overview of such mitigations on Windows and Linux.</p>
<p>FreeBSD also has a number of memory corruption protections for kernel code. Not all of these were developed with the goal of undermining attacks, but primarily as debugging mechanisms. Some are enabled by default in the latest stable version (8.0-RELEASE) and some are not.</p>
<h3>Stack-smashing</h3>
<p>Kernel stack-smashing protection for FreeBSD was introduced in version 8.0 via <a href="http://www.trl.ibm.com/projects/security/ssp/">ProPolice/SSP</a>. Specifically, the file <code>src/sys/kern/stack_protector.c</code> is compiled with gcc&#8217;s <code>-fstack-protector</code> option and registers an event handler called <code>__stack_chk_init</code> that generates a random canary value (the &#8220;guard&#8221; variable in SSP terminology) placed between the local variables and the saved frame pointer of a kernel process’s stack during a function’s prologue. Below is the relevant part of the <code>stack_protector.c</code> file:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #0000dd;">10</span><span style="color: #339933;">:</span> __stack_chk_guard<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">8</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    ...
<span style="color: #0000dd;">20</span><span style="color: #339933;">:</span> <span style="color: #339933;">#define __arraycount(__x)       (sizeof(__x) / sizeof(__x[0]))</span>
<span style="color: #0000dd;">21</span><span style="color: #339933;">:</span> <span style="color: #993333;">static</span> <span style="color: #993333;">void</span>
<span style="color: #0000dd;">22</span><span style="color: #339933;">:</span> __stack_chk_init<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span> <span style="color: #339933;">*</span>dummy __unused<span style="color: #009900;">&#41;</span>
<span style="color: #0000dd;">23</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
<span style="color: #0000dd;">24</span><span style="color: #339933;">:</span>         size_t i<span style="color: #339933;">;</span>
<span style="color: #0000dd;">25</span><span style="color: #339933;">:</span>         <span style="color: #993333;">long</span> guard<span style="color: #009900;">&#91;</span>__arraycount<span style="color: #009900;">&#40;</span>__stack_chk_guard<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #0000dd;">26</span><span style="color: #339933;">:</span> 
<span style="color: #0000dd;">27</span><span style="color: #339933;">:</span>         arc4rand<span style="color: #009900;">&#40;</span>guard<span style="color: #339933;">,</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>guard<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000dd;">28</span><span style="color: #339933;">:</span>         <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> __arraycount<span style="color: #009900;">&#40;</span>guard<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
<span style="color: #0000dd;">29</span><span style="color: #339933;">:</span>                 __stack_chk_guard<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> guard<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #0000dd;">30</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#125;</span></pre></div></div>

<p>When the protected function exits, the canary is checked against its original value. If it has been altered the kernel calls <a href="http://www.freebsd.org/cgi/man.cgi?query=panic&#038;apropos=0&#038;sektion=9&#038;manpath=FreeBSD+8.0-RELEASE&#038;format=html"><code>panic(9)</code></a> bringing down the whole system, but also stopping any execution flow redirection caused by manipulation of the function’s saved frame pointer or saved return address (again from the <code>stack_protector.c</code> file):</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #0000dd;">13</span><span style="color: #339933;">:</span> <span style="color: #993333;">void</span>
<span style="color: #0000dd;">14</span><span style="color: #339933;">:</span> __stack_chk_fail<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>
<span style="color: #0000dd;">15</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
<span style="color: #0000dd;">16</span><span style="color: #339933;">:</span> 
<span style="color: #0000dd;">17</span><span style="color: #339933;">:</span>         panic<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;stack overflow detected; backtrace may be corrupted&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000dd;">18</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#125;</span></pre></div></div>

<p>ProPolice/SSP also performs local variable and pointer reordering in order to protect against the corruption of variables and pointers due to stack buffer overflow vulnerabilities. </p>
<h3>NULL page mappings</h3>
<p>Also in version 8.0, FreeBSD has <a href="http://security.freebsd.org/advisories/FreeBSD-EN-09:05.null.asc">introduced a protection</a> against user mappings at address 0 (NULL). This exploitation mitigation mechanism is exposed through the <a href="http://www.freebsd.org/cgi/man.cgi?query=sysctl&#038;apropos=0&#038;sektion=8&#038;manpath=FreeBSD+8.0-RELEASE&#038;format=html"><code>sysctl(8)</code></a> variable <code>security.bsd.map_at_zero</code> and is enabled by default (i.e. the variable has the value 0). When a user request is made for the NULL page and the feature is enabled, the kernel instead of returning address 0 it returns address 0&#215;1000. Obviously this protection is ineffective in vulnerabilities which the attacker can (directly or indirectly) control the kernel dereference offset. For an applicable example see the exploit for vulnerability CVE-2008-3531 I have previously <a href="http://census-labs.com/news/2009/07/02/cve-2008-3531-exploit/">published</a>.</p>
<h3>Heap-smashing</h3>
<p>FreeBSD has introduced kernel heap-smashing detection in 8.0-RELEASE via an implementation<br />
called <a href="http://fxr.watson.org/fxr/source/vm/redzone.c">RedZone</a>. RedZone is oriented more towards debugging the kernel memory allocator rather than detecting and stopping deliberate attacks against it. If enabled (it is disabled by default) RedZone places a static canary value of 16 bytes above and below each buffer allocated on the heap. The canary value consists of the hexadecimal value 0&#215;42 repeated in these 16 bytes.</p>
<p>During a heap buffer&#8217;s deallocation the canary value is checked and if it has been corrupted the details of the corruption (address of the offending buffer and stack traces of the buffer&#8217;s allocation and deallocation) are logged. The code that performs the check for a heap overflow is the following (from file <code>src/sys/vm/redzone.c</code>):</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #0000dd;">166</span><span style="color: #339933;">:</span> ncorruptions <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #0000dd;">167</span><span style="color: #339933;">:</span> <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> REDZONE_CFSIZE<span style="color: #339933;">;</span> i<span style="color: #339933;">++,</span> faddr<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #0000dd;">168</span><span style="color: #339933;">:</span>       <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span>u_char <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>faddr <span style="color: #339933;">!=</span> <span style="color: #208080;">0x42</span><span style="color: #009900;">&#41;</span>
<span style="color: #0000dd;">169</span><span style="color: #339933;">:</span>               ncorruptions<span style="color: #339933;">++;</span>
<span style="color: #0000dd;">170</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#125;</span></pre></div></div>

<p>This protection mechanism can obviously be easily bypassed. </p>
<h3>Use-after-free</h3>
<p><a href="http://www.freebsd.org/cgi/man.cgi?query=memguard&#038;apropos=0&#038;sektion=9&#038;manpath=FreeBSD+8.0-RELEASE&#038;format=html">MemGuard</a> is a replacement kernel memory allocator introduced in FreeBSD version 6.0 and is designed to detect use-after-free bugs in kernel code. Similarly to RedZone, MemGuard mainly targets debugging scenarios and does not constitute a mechanism to mitigate deliberate attacks. However, MemGuard is not compatible and cannot replace the Universal Memory Allocator&#8217;s (UMA &#8211; which is the default kernel allocator in FreeBSD) calls. Therefore (and also due to the overhead it introduced even before UMA was developed), it is not enabled by default.</p>
]]></content:encoded>
			<wfw:commentRss>http://argp.gr/blog/2010/04/26/kernel-exploitation-mitigations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Black Hat Europe 2010 update</title>
		<link>http://argp.gr/blog/2010/04/22/blackhat-eu-2010-update/</link>
		<comments>http://argp.gr/blog/2010/04/22/blackhat-eu-2010-update/#comments</comments>
		<pubDate>Thu, 22 Apr 2010 05:40:22 +0000</pubDate>
		<dc:creator>argp</dc:creator>
				<category><![CDATA[exploitation]]></category>
		<category><![CDATA[freebsd]]></category>
		<category><![CDATA[kernel]]></category>
		<category><![CDATA[research]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[black hat]]></category>
		<category><![CDATA[census]]></category>
		<category><![CDATA[conference]]></category>

		<guid isPermaLink="false">http://argp.gr/blog/?p=223</guid>
		<description><![CDATA[Black Hat Europe 2010 is now over and after a brief ash cloud caused delay I am back in Greece. It has been a great conference, flawlessly organised and with many outstanding presentations. I would like to thank everyone that attended my presentation but also all the kind people that spoke to me before and [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blackhat.com/html/bh-eu-10/bh-eu-10-home.html">Black Hat Europe 2010</a> is now over and after a brief ash cloud caused delay I am back in Greece. It has been a great conference, flawlessly organised and with many outstanding presentations. I would like to thank everyone that attended my <a href="http://www.blackhat.com/html/bh-eu-10/bh-eu-10-archives.html#Argyroudis">presentation</a> but also all the kind people that spoke to me before and afterwards. I hope to meet all of you again at a future event.</p>
<p><a href="http://blackhat.com/html/bh-eu-10/bh-eu-10-home.html"><br />
<img src="http://argp.gr/blog/wp-content/uploads/2010/04/bheu10_banner.png" alt="Black Hat Europe 2010" width="490" height="155" class="aligncenter size-full wp-image-231"><br />
</a></p>
<p>My presentation, titled &#8220;Binding the Daemon: FreeBSD Kernel Stack and Heap Exploitation&#8221;, was divided into four parts. In the first part I gave an overview of the published work on the subject of kernel exploitation for Unix-like operating systems. The second and third parts were the main body of the presentation. Specifically, in the second part I explained how a kernel stack overflow vulnerability on FreeBSD can be leveraged to achieve arbitrary code execution. The third part focused on a detailed security analysis of the Universal Memory Allocator (UMA), the FreeBSD kernel&#8217;s memory allocator. I explored how UMA overflows can lead to arbitrary code execution in the context of the latest stable FreeBSD kernel (8.0-RELEASE), and I developed an exploitation methodology for privilege escalation and kernel continuation.</p>
<p>In the fourth and final part I gave a demo of a FreeBSD kernel local 0day vulnerability that I have discovered. However, I have not released the details of the vulnerability in my Black Hat presentation. The details of this vulnerability (plus the proof-of-concept exploit) will be released shortly, once the relevant code is patched and the official advisory is out.</p>
<p>Below you may find all the material of my presentation, updated with some extra information and minor corrections:</p>
<ul>
<li>Slides: <a href="http://census-labs.com/media/bheu-2010-slides.pdf">bheu-2010-slides.pdf</a></li>
<li>White paper: <a href="http://census-labs.com/media/bheu-2010-wp.pdf">bheu-2010-wp.pdf</a></li>
<li>Source code: <a href="http://census-labs.com/media/bheu-2010-src.tar.gz">bheu-2010-src.tar.gz</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://argp.gr/blog/2010/04/22/blackhat-eu-2010-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Binding the Daemon – Black Hat Europe 2010</title>
		<link>http://argp.gr/blog/2010/03/19/blackhat-eu-2010/</link>
		<comments>http://argp.gr/blog/2010/03/19/blackhat-eu-2010/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 07:48:43 +0000</pubDate>
		<dc:creator>argp</dc:creator>
				<category><![CDATA[exploitation]]></category>
		<category><![CDATA[freebsd]]></category>
		<category><![CDATA[kernel]]></category>
		<category><![CDATA[research]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[black hat]]></category>
		<category><![CDATA[census]]></category>
		<category><![CDATA[conference]]></category>

		<guid isPermaLink="false">http://argp.gr/blog/?p=200</guid>
		<description><![CDATA[Census, Inc will be presenting &#8220;Binding the Daemon&#8221;, an in-depth analysis of FreeBSD kernel stack and kernel heap exploitation methodologies at Black Hat Europe 2010. This year the European Black Hat Briefings conference will be held in Barcelona, Spain. We hope to see you there!
]]></description>
			<content:encoded><![CDATA[<p><a href="http://census-labs.com/">Census, Inc</a> will be presenting <a href="http://www.blackhat.com/html/bh-eu-10/bh-eu-10-briefings.html#Argyroudis">&#8220;Binding the Daemon&#8221;</a>, an in-depth analysis of FreeBSD kernel stack and kernel heap exploitation methodologies at <a href="http://www.blackhat.com/html/bh-eu-10/bh-eu-10-home.html">Black Hat Europe 2010</a>. This year the European Black Hat Briefings conference will be held in Barcelona, Spain. We hope to see you there!</p>
]]></content:encoded>
			<wfw:commentRss>http://argp.gr/blog/2010/03/19/blackhat-eu-2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>quick kmdb cheatsheet</title>
		<link>http://argp.gr/blog/2010/02/20/kmdb-cheatsheet/</link>
		<comments>http://argp.gr/blog/2010/02/20/kmdb-cheatsheet/#comments</comments>
		<pubDate>Sat, 20 Feb 2010 15:14:20 +0000</pubDate>
		<dc:creator>argp</dc:creator>
				<category><![CDATA[kernel]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[kmdb]]></category>
		<category><![CDATA[opensolaris]]></category>
		<category><![CDATA[solaris]]></category>

		<guid isPermaLink="false">http://argp.gr/blog/?p=178</guid>
		<description><![CDATA[This is mainly a reference for myself since I have been playing with OpenSolaris kernel internals lately:

To enable kmdb edit the kernel&#8217;s grub entry and append -k to it.
Break into kmdb: f1+a
Display status: ::status
List available kmdb commands (and be amazed): ::dcmds
View registers for CPU 0: ::cpuregs -c 0 and/or ::regs
Set a breakpoint at the given [...]]]></description>
			<content:encoded><![CDATA[<p>This is mainly a reference for myself since I have been playing with OpenSolaris kernel internals lately:</p>
<ul>
<li>To enable kmdb edit the kernel&#8217;s grub entry and append <code>-k</code> to it.
<li>Break into kmdb: <code>f1+a</code>
<li>Display status: <code>::status</code>
<li>List available kmdb commands (and be amazed): <code>::dcmds</code>
<li>View registers for CPU 0: <code>::cpuregs -c 0</code> and/or <code>::regs</code>
<li>Set a breakpoint at the given symbol or address: <code>::bp [symbol or address]</code>
<li>Set a read/write watchpoint at the given symbol or address: <code>[symbol or address] ::wp -rw</code>
<li>Display breakpoints and watchpoints: <code>::events</code>
<li>Delete breakpoint (or watchpoint) #1: <code>::delete 1</code>
<li>Continue execution: <code>:c</code>
<li>Next instruction, step into function calls: <code>::step</code>
<li>Next instruction, step over function calls: <code>::step over</code>
<li>Return from current function: <code>::step out</code>
<li>Continue execution until the next branching instruction (only x86): <code>::step branch</code>
<li>Disassemble around RIP: <code>&lt;rip::dis</code>
<li>Disassemble 100 instructions starting at the given symbol or address: <code>::dis -n 100 [symbol or address]</code>
<li>View backtrace: <code>$C</code>
<li>View IDT: <code>::idt</code>
<li>View symbols: <code>::nm</code>
<li>View the kernel message buffer: <code>::msgbuf</code>
<li>Quit kmdb and reboot: <code>::quit</code>
</ul>
<p>This brief cheatsheet does not do kmdb justice; it is an amazing built-in kernel debugger with countless features. For more details <a href="http://docs.sun.com/app/docs/doc/816-5165/kmdb-1?l=en&#038;a=view&#038;q=kmdb">read the manpage</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://argp.gr/blog/2010/02/20/kmdb-cheatsheet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>exploit for CVE-2010-0453</title>
		<link>http://argp.gr/blog/2010/02/07/cve-2010-0453-exploit/</link>
		<comments>http://argp.gr/blog/2010/02/07/cve-2010-0453-exploit/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 15:48:56 +0000</pubDate>
		<dc:creator>argp</dc:creator>
				<category><![CDATA[exploitation]]></category>
		<category><![CDATA[research]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[exploit]]></category>
		<category><![CDATA[opensolaris]]></category>
		<category><![CDATA[solaris]]></category>

		<guid isPermaLink="false">http://argp.gr/blog/?p=176</guid>
		<description><![CDATA[While playing today with kmdb on OpenSolaris I wrote a denial of service (kernel panic) PoC exploit for the UCODE_GET_VERSION ioctl NULL pointer dereference vulnerability.  The vulnerability was discovered by Tobias Klein who always publishes very detailed advisories:
http://www.trapkit.de/advisories/TKADV2010-001.txt
You can get my exploit from:
http://census-labs.com/media/cve-2010-0453.c
]]></description>
			<content:encoded><![CDATA[<p>While playing today with kmdb on OpenSolaris I wrote a denial of service (kernel panic) PoC exploit for the UCODE_GET_VERSION ioctl NULL pointer dereference vulnerability.  The vulnerability was discovered by Tobias Klein who always publishes very detailed advisories:</p>
<p><a href="http://www.trapkit.de/advisories/TKADV2010-001.txt">http://www.trapkit.de/advisories/TKADV2010-001.txt</a></p>
<p>You can get my exploit from:</p>
<p><a href="http://census-labs.com/media/cve-2010-0453.c">http://census-labs.com/media/cve-2010-0453.c</a></p>
]]></content:encoded>
			<wfw:commentRss>http://argp.gr/blog/2010/02/07/cve-2010-0453-exploit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>first 2010 0day</title>
		<link>http://argp.gr/blog/2010/01/06/first-2010-0day/</link>
		<comments>http://argp.gr/blog/2010/01/06/first-2010-0day/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 13:52:49 +0000</pubDate>
		<dc:creator>argp</dc:creator>
				<category><![CDATA[exploitation]]></category>
		<category><![CDATA[research]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[exploit]]></category>

		<guid isPermaLink="false">http://argp.gr/blog/?p=174</guid>
		<description><![CDATA[md5: e8d5dd9d6cdf8602f12c8baef53f6550
sha1: 1322d45eed25260a0d5f85284011e1b205328807
sha256: eb4f95ec1b62d57e022c6945bdcb3f747f94f3ad7ddedc4bfde7dee23d4362ef
]]></description>
			<content:encoded><![CDATA[<p>md5: e8d5dd9d6cdf8602f12c8baef53f6550<br />
sha1: 1322d45eed25260a0d5f85284011e1b205328807<br />
sha256: eb4f95ec1b62d57e022c6945bdcb3f747f94f3ad7ddedc4bfde7dee23d4362ef</p>
]]></content:encoded>
			<wfw:commentRss>http://argp.gr/blog/2010/01/06/first-2010-0day/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>xmas 2009 0day</title>
		<link>http://argp.gr/blog/2009/12/24/xmas-2009-0day/</link>
		<comments>http://argp.gr/blog/2009/12/24/xmas-2009-0day/#comments</comments>
		<pubDate>Thu, 24 Dec 2009 13:04:52 +0000</pubDate>
		<dc:creator>argp</dc:creator>
				<category><![CDATA[exploitation]]></category>
		<category><![CDATA[research]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[exploit]]></category>

		<guid isPermaLink="false">http://argp.gr/blog/?p=172</guid>
		<description><![CDATA[md5: a145ed9d7e1c33124daab40447cc5b56
sha1: c888985f209c26243206f8864783500b0c9353bb
sha256: 27cbcd01cf0e1b6a2ba82d4c0209a791957a3c1c29c131b0208f77981a1a81aa
]]></description>
			<content:encoded><![CDATA[<p>md5: a145ed9d7e1c33124daab40447cc5b56<br />
sha1: c888985f209c26243206f8864783500b0c9353bb<br />
sha256: 27cbcd01cf0e1b6a2ba82d4c0209a791957a3c1c29c131b0208f77981a1a81aa</p>
]]></content:encoded>
			<wfw:commentRss>http://argp.gr/blog/2009/12/24/xmas-2009-0day/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Monkey HTTPd improper input validation vulnerability</title>
		<link>http://argp.gr/blog/2009/12/14/monkey-httpd-vulnerability/</link>
		<comments>http://argp.gr/blog/2009/12/14/monkey-httpd-vulnerability/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 09:19:41 +0000</pubDate>
		<dc:creator>argp</dc:creator>
				<category><![CDATA[advisories]]></category>
		<category><![CDATA[census]]></category>
		<category><![CDATA[exploit]]></category>
		<category><![CDATA[exploitation]]></category>
		<category><![CDATA[monkey]]></category>
		<category><![CDATA[research]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://argp.gr/blog/?p=166</guid>
		<description><![CDATA[

census ID:
census-2009-0004


Affected Products:
Monkey web server versions  &#8804; 0.9.2.


Class:
Improper Input Validation (CWE-20), Incorrect Calculation (CWE-682)


Remote:
Yes


Discovered by:
Patroklos Argyroudis


We have discovered a remotely exploitable &#8220;improper input validation&#8221; vulnerability in the Monkey web server that allows an attacker to perform denial of service attacks by repeatedly crashing worker threads that process HTTP requests.
Details
Monkey is a fast, efficient, small [...]]]></description>
			<content:encoded><![CDATA[<table>
<tr>
<td>census ID:</td>
<td>census-2009-0004</td>
</tr>
<tr>
<td>Affected Products:</td>
<td>Monkey web server versions  &le; 0.9.2.</td>
</tr>
<tr>
<td>Class:</td>
<td>Improper Input Validation (<a href="http://cwe.mitre.org/data/definitions/20.html">CWE-20</a>), Incorrect Calculation (<a href="http://cwe.mitre.org/data/definitions/682.html">CWE-682</a>)</td>
</tr>
<tr>
<td>Remote:</td>
<td>Yes</td>
</tr>
<tr>
<td>Discovered by:</td>
<td>Patroklos Argyroudis</td>
</tr>
</table>
<p>We have discovered a remotely exploitable &#8220;improper input validation&#8221; vulnerability in the Monkey web server that allows an attacker to perform denial of service attacks by repeatedly crashing worker threads that process HTTP requests.</p>
<h3>Details</h3>
<p><a href="http://www.monkey-project.com/">Monkey</a> is a fast, efficient, small and easy to configure HTTP/1.1 compliant web server. It has been designed to be scalable with low memory and CPU consumption. More information about its features can be found <a href="http://www.monkey-project.com/about">here</a>.</p>
<p>Monkey (up to and including version 0.9.2) employs an insufficient input validation method for handling HTTP requests with invalid connection headers. Specifically, the vulnerability is in the calculation for the end of the request body buffer related to newline characters in function <code>Request_Find_Variable()</code> in the file <code>src/request.c</code>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">char</span> <span style="color: #339933;">*</span>Request_Find_Variable<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span>request_body<span style="color: #339933;">,</span>  <span style="color: #993333;">char</span> <span style="color: #339933;">*</span><span style="color: #993333;">string</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   <span style="color: #993333;">int</span> pos_init_var<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> pos_end_var<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
   <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>var_value <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #808080; font-style: italic;">/* Existe *string en request_body ??? */</span>        
   <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>strstr2<span style="color: #009900;">&#40;</span>request_body<span style="color: #339933;">,</span> <span style="color: #993333;">string</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> NULL<span style="color: #009900;">&#41;</span>
       <span style="color: #b1b100;">return</span> NULL<span style="color: #339933;">;</span>
&nbsp;
   pos_init_var <span style="color: #339933;">=</span> str_search<span style="color: #009900;">&#40;</span>request_body<span style="color: #339933;">,</span> <span style="color: #993333;">string</span><span style="color: #339933;">,</span> strlen<span style="color: #009900;">&#40;</span><span style="color: #993333;">string</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   pos_end_var <span style="color: #339933;">=</span> str_search<span style="color: #009900;">&#40;</span>request_body<span style="color: #339933;">+</span>pos_init_var<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>pos_init_var<span style="color: #339933;">&lt;=</span><span style="color: #0000dd;">0</span> <span style="color: #339933;">||</span> pos_end_var<span style="color: #339933;">&lt;=</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
       <span style="color: #b1b100;">return</span>  NULL<span style="color: #339933;">;</span>   
   <span style="color: #009900;">&#125;</span>
&nbsp;
   pos_init_var <span style="color: #339933;">+=</span> strlen<span style="color: #009900;">&#40;</span><span style="color: #993333;">string</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
   pos_end_var <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>pos_init_var  <span style="color: #339933;">+</span> pos_end_var<span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>strlen<span style="color: #009900;">&#40;</span><span style="color: #993333;">string</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   var_value <span style="color: #339933;">=</span> m_copy_string<span style="color: #009900;">&#40;</span>request_body<span style="color: #339933;">,</span> pos_init_var<span style="color: #339933;">,</span> pos_end_var<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> var_value<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>With a specially crafted request body the <code>pos_init_var</code> integer can take the value <code>0x1c</code> (<code>28</code> in decimal) and the <code>pos_end_var</code> integer can take the value <code>0x1a</code> (<code>26</code> in decimal). Then in the <code>m_copy_string()</code> function, the calculation for the unsigned integer <code>size</code> in line 428 (file <code>src/utils.c</code>) leads to a signedness bug and <code>m_copy_string()</code> returns NULL (line 438, file <code>src/utils.c</code>):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">char</span> <span style="color: #339933;">*</span>m_copy_string<span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span><span style="color: #993333;">string</span><span style="color: #339933;">,</span> <span style="color: #993333;">int</span> pos_init<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> pos_end<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   <span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> size<span style="color: #339933;">,</span> bytes<span style="color: #339933;">;</span>
   <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>buffer<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
   size <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>pos_end <span style="color: #339933;">&amp;</span>mdash<span style="color: #339933;">;</span> pos_init <span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>size<span style="color: #339933;">&lt;=</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span> size<span style="color: #339933;">=</span><span style="color: #0000dd;">4</span><span style="color: #339933;">;</span>
&nbsp;
   buffer <span style="color: #339933;">=</span> M_malloc<span style="color: #009900;">&#40;</span>size<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>buffer<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
       <span style="color: #b1b100;">return</span> NULL<span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>pos_end<span style="color: #339933;">&gt;</span>strlen<span style="color: #009900;">&#40;</span><span style="color: #993333;">string</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span>pos_init <span style="color: #339933;">&gt;</span> pos_end<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
       <span style="color: #b1b100;">return</span> NULL<span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>This causes <code>Request_Find_Variable()</code> to return NULL (line 344, file <code>src/request.c</code>) and this to be used in the <code>strstr2()</code> call at line 345 of file <code>src/request.c</code>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>344
345
346
347
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">sr<span style="color: #339933;">-&gt;</span>connection <span style="color: #339933;">=</span> Request_Find_Variable<span style="color: #009900;">&#40;</span>request_body<span style="color: #339933;">,</span> RH_CONNECTION<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: #009900;">&#40;</span>strstr2<span style="color: #009900;">&#40;</span>sr<span style="color: #339933;">-&gt;</span>connection<span style="color: #339933;">,</span><span style="color: #ff0000;">&quot;Keep-Alive&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">!=</span>NULL<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    sr<span style="color: #339933;">-&gt;</span>keep_alive<span style="color: #339933;">=</span>VAR_ON<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>This vulnerability can allow an attacker to perform denial of service attacks by repeatedly crashing Monkey worker threads that process HTTP requests. We have developed <a href="http://census-labs.com/media/monkeyex.txt">a proof-of-concept exploit</a> to demonstrate the vulnerability.</p>
<p>The maintainer of Monkey has been contacted and a new version of the web server (0.9.3) has been <a href="http://www.monkey-project.com/downloads">released</a> that addresses this issue. All affected parties are advised to upgrade to the latest version available.</p>
]]></content:encoded>
			<wfw:commentRss>http://argp.gr/blog/2009/12/14/monkey-httpd-vulnerability/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hellenic Air Force Academy free/open source event</title>
		<link>http://argp.gr/blog/2009/12/03/air-force-oss-event/</link>
		<comments>http://argp.gr/blog/2009/12/03/air-force-oss-event/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 07:12:08 +0000</pubDate>
		<dc:creator>argp</dc:creator>
				<category><![CDATA[greek]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[census]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[hellenic air force academy]]></category>
		<category><![CDATA[σχολή ικάρων]]></category>

		<guid isPermaLink="false">http://argp.gr/blog/?p=160</guid>
		<description><![CDATA[census participated in the free/open source event held last month (Friday 23rd of October) at the Hellenic Air Force Academy (Σχολή Ικάρων).

Our talk presented an overview of the available free/open source software that can be used to build complete security solutions for public offices and infrastructure. Furthermore, we analysed recorded cyberwarfare incidents and how the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://census-labs.com/">census</a> participated in the free/open source event held last month (Friday 23rd of October) at the <a href="http://www.haf.gr/el/career/academies/si/">Hellenic Air Force Academy (Σχολή Ικάρων)</a>.</p>
<p><center><a href="http://www.haf.gr/el/career/academies/si/"><img src="http://census-labs.com/media/si.png"></a></center></p>
<p>Our talk presented an overview of the available free/open source software that can be used to build complete security solutions for public offices and infrastructure. Furthermore, we analysed recorded cyberwarfare incidents and how the open source model can aid in establishing robust defenses. The slides from our presentation are available <a href="http://census-labs.com/media/ellak-sec.pdf">here</a> (in Greek).</p>
<p>We would like to cordially thank Professor Antonios Andreatos for inviting us to the event and for his organisational efforts.</p>
]]></content:encoded>
			<wfw:commentRss>http://argp.gr/blog/2009/12/03/air-force-oss-event/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
