khallenge 2008, Challenge 1

Posted by Eric | Competition, Crackme, Reversing | Sunday 3 August 2008 11:32 pm

I posted up a link the other day about the F-secure 2008 Reversing challenge, or khallenge. I got a little side tracked with things to do around the house Pre Vegas, and the prerequisite quality time so my bride isn’t completely pissed at me. I took a quick look at it Friday before leaving work but completely dropped it until this evening. When you first load it up in Ida Pro and browse through it you will see there is a lot of XOR’ing of 8 bit registers with Bytes. When you jump to the bytes in IDA, some of them already have values (initialized) and others don’t.

This challenge is going to be much easier utilizing dynamic, versus static analysis so it’s off to Olly or Immunitydbg we go! From either Ida Pro, or your debugger of choice you can see after the printing of the message, printing of the input request, and subsequent scanning thereof there is a loop followed by a comparison.


If you happen to have Hex-Ray’s, you can cheat a little, hit F5 and get some pseudo code. Otherwise, you have to figure out this is a compiler optimized strlen function. Although it’s not necessarily important it may trip you up. All it’s doing is scanning the string byte by byte looking for the terminating zero (text cl,cl).

After our compiler optimized strlen, we see a cmp eax, 4. This is testing that our input is 4 bytes long. If not, we jump to a “sorry…” message. So, we can conclude our input is 4 bytes long, or 4 chars.

Next we get into a crap load of XOR’s with bytes, and registers. There’s a lot going on here so it’s really important to:

  • Keep a piece of paper handy
  • Set a break point at every address within the algorithm
  • Put in well crafter input (such as 1234, abcd)

Point number 3 was something I completely neglected. Working with MC for so long I got used to putting a stream of A’s, as my input I did the same here. It hindered me more than anything because I couldn’t differentiate the input at first. I left my comments in the screen shot for you to follow down (and for my own sanity while I was working on it).

I used the input “abcd” which allowed me to follow the data movements since it was not sequential. Our first instruction moved a PTR to EDX, when we press F9 in ImmunityDBG we see the value 63 or “c” loaded in the EDX register. Our next instruction moves the value in input1 (“a”) to the EAX register.

We see 3 XOR Operations, 2 with AL and one with DL. As we follow the program through the debugger we discover that only the last XOR is valid. Going back to Ida Pro we jmp to the byte definition for the last XOR to find out it’s value. As it turns out the byte is initiated with a value of 0×70 The instruction that follow from:

1
2
3
4
690010B3  . 0FB615 0331006&gtMOVZX EDX,BYTE PTR DS:[69003103
 
To:
690010C7  . 3005 D9300069  XOR BYTE PTR DS:[690030D9],AL              XOR 0x20, arg 2

Are crap instructions. I mean, they do something but they are overwritten starting in the next instruction.

We pick back up with:

1
690010CD  . 8A0D D5300069  MOV CL,BYTE PTR DS:[690030D5

Again we used Ida Pro to find the value of the byte ptr, it turns out to be 0×2e.
After this we move the 3rd byte into EDX, and the 4th into EAX. The second byte, still loaded in CL is XORED with 0×2e, the 3rd byte Xored with 0×76, and the 4th xored with 0×68.

After all the Xoring madness stop’s, we find outselfs at a cmp instruction. We need the second argument to somehow turn out a value 0×61 after being xored with 0×2e. Following the Code down, we see other comparison’s. We just need to figure out what byte ptr’s they are referring to by looking back at the instructions.

Easy, Inverse XOR the values to arrive at X. Really the hardest part is following the byte ptr’s around and keeping track of what is being compared.

We arrive at

Arg 1: x = 0×70 ^ 0×32, x = 0×42 or “B”
Arg 2: x = 0×61 ^ 0×2e, x = 0×4F or “O”
Arg 3: x = 0×30 ^ 0×76, x = 0×46 or “F”
Arg 4: x = 0×79 ^ 0×29, x = 0×50 or “P”

When we restart the debugger and enter “BOFP” we are quickly directed (after removing our breakpoints) to:

This gives us the Email address to send an email to in order to receive challenge 2! Unfortunately I didn’t get this knocked out till a little while ago!

 Subscribe in a reader

LSO Crackme 0×03 Solution

Posted by Eric | Crackme, Reversing | Sunday 27 April 2008 6:02 pm

<meta content="OpenOffice.org 2.0 (Linux)" name="GENERATOR" /><meta content="20080427;15494200" name="CREATED" /><meta content="20080427;16445500" name="CHANGED" /> <br /> <style> <!-- @page { size: 8.5in 11in; margin: 0.79in } P { margin-bottom: 0.08in } --> </style> <p style="margin-bottom: 0in">Learnsecurityonline.com released Crackme 0×03 at the beginning of the month and I ended up knocking it out in about 20-30 minutes after it was posted and posting a screen shot on the blog. This is the write up following that screen shot with the method of how I approached the crackme.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">All we had was a binary, and we did not know much about it. Our goal was to solve the Crackme via the given binary. The instructions were vague, the functionality was vague. We are forced to execute the program to determine both it’s functionality and our objective. When we start the binary we are shown a small window with three buttons and the instructions “Find a way to play the above tones to pass”.</p> <p style="margin-bottom: 0in"> <img src="http://hamsterswheel.com/pictures/blog/crackme3-1.JPG" /></p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">Pressing the button play tone delivers us a MessageBox that tells us the tones don’t match. Listening to the tones from the three buttons, and having pressed the “play this tone” button you can tell that the tones are by no way the same. This means it’s impossible to generate the stored tone with the buttons provided.</p> <p style="margin-bottom: 0in">At this point I wanted to open up the binary and take a look at how it was doing its magic. Checking it for a Packer revealed nothing with the standard PE identifiers. I ran it through my standard three, none of which came up with anything. PEID did however, mention that it was built in Visual Studio using .net. Instead of loading it up with Ida Pro or Ollydbg I decided to open it with .Net Reflector[1]. I then chose to Disassemble the Binary. As I was walking through the disassembled code I noticed class references to NetZ. Curious as to what the hell it was I googled Netz and found out that the binary was after all Compressed with this Open Source .Net Packer called Netz and that the disassembly code I was looking at was the code for the Packer. Ok, back to google I ended up searching real quick for an Unpacker for Netz. Nothing turned up. SHIT!</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">Tebo mentioned that the RSS feed for Woodmann’s collaborative RCE tools had popped up a Generic .Net Unpacker[2]. My only other option was to Manually unpack the binary… Well screw that I will give this Generic .Net Unpacker a shot. It ended up working great, and I was able to load up one of the output binaries into .Net Reflector and disassemble it to about 90% of the original source. That’s truly the beauty of .Net code and .Net Reflector, you don’t have to muck around in too much assembly because you can disassemble straight to source, minus the variable names some times. Going through the code for Form 1, we find the Play_Click function and take a peak at the functionality.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in"><img src="http://hamsterswheel.com/pictures/blog/crackme3-2.JPG" /></p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">If you take notice, there is a single if statement that checks the values of the NumArray2[] to be set too 300,600,900. But if you pay attention the values set to numArray2[] are 250,500, and 0×3e8. No where in the code is there a place to change the tone values on that Array (which in case you weren’t paying attention correspond to Button 1, 2 and 3.)</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">At this point I knew I needed to change the values in that array. But I am lazy.. Real lazy so I didn’t feel like walking through it with Ollydbg, and manually changing the value. I found something called Reflexil[3] which is an assembly editor that runs as a plugin for .Net reflector. This tool allowed me to go in and modify the values in that array to what we needed, then save the program with the modifications.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in"><img src="http://hamsterswheel.com/pictures/blog/crackme3-3.JPG" /></p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">Turning around and saving the file, we can then run the program and just press play. Pushing buttons 1,2, and 3 doesn’t really matter because the logic in the program doesn’t even check to see if you pushed any buttons.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">And we get our Win!</p> <p style="margin-bottom: 0in"> <img src="http://hamsterswheel.com/re/crackme3.JPG" /></p> <p>[1] .Net Reflector – http://www.aisto.com/roeder/dotnet/</p> <p>[2] Generic .Net Unpacker – http://www.woodmann.net/collaborative/tools/index.php/.NET_Generic_Unpacker</p> <p>[3] Reflexil – http://sebastien.lebreton.free.fr/reflexil/</p> </div> <div class="feedback"> <a href="http://hamsterswheel.com/techblog/?p=61#respond" title="Comment on LSO Crackme 0×03 Solution">Comments (0)</a> </div> </div> <div class="post"> <h2 id="post-44"><a href="http://hamsterswheel.com/techblog/?p=44" rel="bookmark">Code Obfuscation and LSO Crackme 0×02</a></h2> <div class="meta">Posted by Eric | <a href="http://hamsterswheel.com/techblog/?cat=14" title="View all posts in Crackme" rel="category">Crackme</a>, <a href="http://hamsterswheel.com/techblog/?cat=13" title="View all posts in Reversing" rel="category">Reversing</a> | Thursday 21 February 2008 11:10 am </div> <div class="storycontent"> <p><meta http-equiv="CONTENT-TYPE" content="text/html; charset=utf-8" /><title /><meta name="GENERATOR" content="OpenOffice.org 2.0 (Linux)" /><meta name="CREATED" content="20080221;7460700" /><meta name="CHANGED" content="16010101;0" /><br /> <style> <!-- @page { size: 8.5in 11in; margin: 0.79in } P { margin-bottom: 0.08in } --> </style> <p style="margin-bottom: 0in">Obfuscation’s aim is to reduce the ability for a reverse engineer to perform static Analysis on the Binary/program. Obfuscation can be accomplish by modifying the programs layout, logic, data and the organization. Essentially Obfuscation transforms the code in such a way that it becomes less human readable, but still retains its functionality. Obfuscators often add irrelevant instructions that don’t really produce valuable data, its possible for others to make a DeObfuscator. A Deobfuscator will implement various data flow analysis algorithms on an obfuscated program which will enable it to seperate the good code from the chaff thrown in by the obfuscator, and auto magically remove the irrelevant instructions.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">The reason we bring up code obfuscation and stray from Packing is because Monday evening Chris over at LSO released Crackme0×02. I went into the Crackme yesterday morning expecting it to be slightly harder than the first, but definitely not as difficult as it was. Honestly, The Crackme was made much more difficult by myself than it really was. I broke the first rule of Reverse Engineering. “Never Assume Anything.” As I first started poking around with the Binary I made assumptions which took me on a detour of where I should have been. So, Let’s begin our 3 Hour tour.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">Standard practice we want to grab some information about the binary. We run my favorite pefile scripts accross the binary and everything looks normal except the imports. We notice that the imports section is looking a bit sluggish. We load up the binary in a Utilities called “Execinfo PE” and we don’t get much back. Exeinfo proclaims that the file is an unknown EXE and we should check it out with PEID. We open up the file with “DIE, Detect It Easy” to grab some more info, No hueristics on a packer are found. One last test with RDG Packer Detecter… Nothing. Hmm, So we have normal sections, only one import… Wtf? If we open it up in IDA the Code body is Tiny! This is definitely pointing to a packer! Just for the hell of it, let’s dump strings!</p> <p style="margin-bottom: 0in"><img src="http://www.hamsterswheel.com/blogpics/crackme2-strings.JPG" /></p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">AHA! Something catches our eyes… Two things actually… First off a lot of the “strings” in the binary seem to be encrypted or something. Then towards the bottom of the dump we see “This software protected by 9rays.net Spices.Obfuscator.” Well, That would explain it. Renamed functions, small code body, Wierd jmp’s in the code, encrypted strings. When we start to google we don’t find too much information, and we certainly don’t find anything about deobfuscating the code. So we have some .Net code, that is Obfuscated using 9Rays Spices… Well, we notice that 9Rays utility Spices.Net is available for download. When we grab a copy and load up our binary theres a few things we can do, one being disassemble. Logic would have it, if it obfuscated it perhaps it can do the reverse on it’s own algorithm. It surely can…. If you pay that is! I found the evaluation copy will only give you a 50% decompilation. Which left code like this:</p> <p style="margin-bottom: 0in"> <blockquote> <p style="margin-bottom: 0in">return ?.?.GetString ((byte[] ?.?), 188, ?);</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">Or:</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">internal static object ? ()</p> <p style="margin-bottom: 0in">{</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">//Warning – Unlicensed copy will only decompile 50%</p> <p style="margin-bottom: 0in">}</p> </blockquote> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">Although I got a few pieces of code out of it, there were many classes so ?.? Didn’t exactly help me out too much! Next on the block was a utility called DIS#. Dis# is similar to Spices.Net in every way, I did however like the flow of dis# a lot better, and it was able to decompile the code a lot better and even provide readable and logical names for variables. The Problem</p> <p style="margin-bottom: 0in"> <blockquote> <p style="margin-bottom: 0in">public static void XsNksq(string[] A_0)</p> <p style="margin-bottom: 0in">{</p> <p style="margin-bottom: 0in">//trial</p> <p style="margin-bottom: 0in">}</p> </blockquote> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">Same thing as Spices.Net! DAMN!</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">Next Utility. Lutz Roeder’s .Net Reflector. This utility is available free for download with just providing your email address, company and name information. I put in some crap info and hoped they didn’t email a trial key or anything. Fortunately they did not. .Net Reflector was able to decompile and DeObfuscate most of the code but had some confusion on a few things. One of the confusions was in the central Logic of the function Main. The class and function calls were somehow confused but it still gave you a fair idea of the program logic.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in"><a href="http://www.hamsterswheel.com/blogpics/crackme2-reflector.JPG">Link to ScreenShot</a></p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in"><a name="ctl00_rs1_mainContentContainer_ctl03"></a>     While browsing around in the almost completely decompiled code, as we use .Net Reflector to Analyze the code we see something that looks like an encoded array held within the cctor section.</p> <p style="margin-bottom: 0in"><img src="http://www.hamsterswheel.com/blogpics/crackme2-array.JPG" /></p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">It appears to be a Byte Array, with a bunch of data in it, then at the end it is encoded with Unicode. When we go back to the Main function we Notice a function String that is called a lot. This function turns out to be what .Net Reflector calls “GetString.” Looking up that function on MSDN, we find that GetString is a front for GetChars, which takes a Byte Array, and index, and a count. This is where I started assuming that the password was encoded in the byte array and began a long journey into discovering it wasn’t. When you start looking through, there are multiple declarations in E(): Object which call GetString, all with different indexs and count’s. While attempting to create a decoder using C# we stumbled upon two pieces of code that seemed out of the norm.</p> <p style="margin-bottom: 0in"><img src="http://www.hamsterswheel.com/blogpics/crackme2-webclient.JPG" /></p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">The first Uses WebClient, and the second is a function that accepts an object and a string, then calls DownloadData (part of webclient) wtih the argument of the text string passed to it…. Hmm.. MSDN! <a href="http://msdn2.microsoft.com/en-us/library/system.net.webclient%28VS.80%29.aspx">Webclient</a> Provides common methods for sending data to and receiving data from a resource identified by a URI. <a href="http://msdn2.microsoft.com/en-us/library/system.net.webclient.downloaddata.aspx">DownloadData</a> Downloads with the specified URI as a Byte array. Let’s go back and run a dynamic analysis on this binary real quick…</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">We execute the binary and it tells us we need to enter a password. That must be the code block in main that goes</p> <p style="margin-bottom: 0in"> <blockquote> <p style="margin-bottom: 0in">if(TextArray1.length == 0)</p> <p style="margin-bottom: 0in">{</p> <p style="margin-bottom: 0in">Object.GetString(Object2.Method);</p> <p style="margin-bottom: 0in">}</p> </blockquote> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">Apparently, its grabbing some text within that encoded byte array, decoding it and printing it up. Lets try giving the binary some cruff.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in"><img src="http://www.hamsterswheel.com/blogpics/crackme2-test.JPG" /></p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">It repeats the password we entered, tell’s us its checking it, then tells us sorry. In main, we see numerous calls back to that byte array. Judging by our last discovery of Webclient.Download Data… Me thinks this is using the network! Firing up wireshark!</p> <p style="margin-bottom: 0in"><a href="http://www.hamsterswheel.com/blogpics/crackme2-wireshark.JPG">SCREENSHOT </a></p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">Holy Crap, Its grabbing a text file</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">We try it out: And….</p> <blockquote> <p style="margin-bottom: 0in"><img src="http://www.hamsterswheel.com/blogpics/crackme2-win.JPG" /></p> </blockquote> <p style="margin-bottom: 0in">Boom!</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">Although the code was obfuscated pretty damn well, and the URL was encoded into a byte Array the password was in clear text. One way the author could have obfuscated the password transfer a little more would be to encode it with base64 or some type of encoding. Once wireshark picked it up it was apparent what the password was.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">Overall though, it was a pretty good Crackme…would have taken a lot less time had I followed Rule #1… So let that be a lesson. NEVER ASSUME!</p> </div> <div class="feedback"> <a href="http://hamsterswheel.com/techblog/?p=44#comments" title="Comment on Code Obfuscation and LSO Crackme 0×02">Comments (1)</a> </div> </div> <div class="post"> <h2 id="post-35"><a href="http://hamsterswheel.com/techblog/?p=35" rel="bookmark">LSo Crackme Numero uno</a></h2> <div class="meta">Posted by Eric | <a href="http://hamsterswheel.com/techblog/?cat=14" title="View all posts in Crackme" rel="category">Crackme</a>, <a href="http://hamsterswheel.com/techblog/?cat=13" title="View all posts in Reversing" rel="category">Reversing</a> | Monday 14 January 2008 12:08 am </div> <div class="storycontent"> <p><meta http-equiv="CONTENT-TYPE" content="text/html; charset=utf-8" /><title /><meta name="GENERATOR" content="OpenOffice.org 2.0 (Linux)" /><meta name="CREATED" content="20080113;21493100" /><meta name="CHANGED" content="20080113;22014400" /><br /> <style><!-- @page { size: 8.5in 11in; margin: 0.79in } P { margin-bottom: 0.08in } --></style> <p>Not to stray off topic but Learnsecurityonline.com had their first ever crackme which was released Friday night. Apparently I didn’t get the memo about it until sometime late Saturday. I ran into some trouble with it because the file wasn’t loading. I was stuck in “DLL Hell.” The crackme was written in vb.net using visual studio 2005. I didn’t have what it needed apparently. However, once I updated to .Net 2.0 everything worked like a charm.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">First thing to do since this was supposed to be a n00b challenge was dump strings. Nothing for hard coded passwords came up but i did notice a lot of crap. First thing, I was able to identify that I would be working with vb code, and then I was about to determine that the version of the file was a debug file, which coincidentally (not that it mattered) still had debug symbols in it (as it should in a debug version). Anyhow, I was also able to obtain the names of functions to start poking around in.</p> <p style="margin-bottom: 0in"><img src="http://www.hamsterswheel.com/blogpics/Screenshot.png" /></p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in"><meta http-equiv="CONTENT-TYPE" content="text/html; charset=utf-8" /><title /><meta name="GENERATOR" content="OpenOffice.org 2.0 (Linux)" /><meta name="CREATED" content="20080113;21493100" /><meta name="CHANGED" content="20080113;22014400" /><br /> <style> <!-- @page { size: 8.5in 11in; margin: 0.79in } P { margin-bottom: 0.08in } --> </style> </p> <p style="margin-bottom: 0in">After we found our functions and what not I decided to load her up in IDA Pro. Now, you could have used a debugger such as Ollydbg which is now in version 2.0, it’s really a matter of preference. But since I figured Id go a static analysis route first, I used IDA.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">Scrolling through, we were able to locate the function titled “Submit_Click” which we saw in our strings dump.</p> <p style="margin-bottom: 0in"><a href="http://www.hamsterswheel.com/blogpics/LSO-Crackme.jpeg"> </a></p> <p style="margin-bottom: 0in"><meta http-equiv="CONTENT-TYPE" content="text/html; charset=utf-8" /><title /><meta name="GENERATOR" content="OpenOffice.org 2.0 (Linux)" /><meta name="CREATED" content="20080113;21493100" /><meta name="CHANGED" content="20080113;22014400" /><br /> <style> <!-- @page { size: 8.5in 11in; margin: 0.79in } P { margin-bottom: 0.08in } --> </style> </p> <p style="margin-bottom: 0in">We also see that within that function there is what appears to be a hard coded password in it, and a string comparison call. I think we got it! Lets have a look see!</p> <p><img src="http://www.hamsterswheel.com/blogpics/Forthewin.jpeg" /></p> <p><meta content="text/html; charset=utf-8" http-equiv="CONTENT-TYPE" /><title /><meta content="OpenOffice.org 2.0 (Linux)" name="GENERATOR" /><meta content="20080113;21493100" name="CREATED" /><meta content="20080113;22014400" name="CHANGED" /><br /> <style> <!-- @page { size: 8.5in 11in; margin: 0.79in } P { margin-bottom: 0.08in } --> </style> <p style="margin-bottom: 0in">And such is the reason, we don’t hard code passwords!</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">Another route you could have taken would have been to open up the executable in a hex editor. Of course, there was a chance you would have blown over the password, but if you were looking carefully you would have found it!</p> <p><img src="http://www.hamsterswheel.com/blogpics/lso-crackme-hex.jpeg" /></p> </div> <div class="feedback"> <a href="http://hamsterswheel.com/techblog/?p=35#comments" title="Comment on LSo Crackme Numero uno">Comments (1)</a> </div> </div> </div> <div id="footer"> © Copyright 2009 | <a href="http://hamsterswheel.com/techblog">Phn1x – Hamsterswheel</a> | Theme by <a href="http://clubparexcellancetech.com/">Club Par Excellance</a> | All Rights Reserved | Sponsored by <a href="http://www.voipkit.ca/">VoIP</a> </div> </body> </html>