Repost from LSO

Posted by Eric | General - Security, Windows | Thursday 28 February 2008 1:42 pm

Ive been taking it easy this week, I’ve been hit with some type of bug and can’t seem to get rid of it. I’ve also been working on expanding business so I haven’t had much attention on the blog.. Sorries!

Over at EH.net there was some chatter about a webcast presented by Core, featuring Ed skoudous. Ok, cool I read one of his books, but the selling point of the webcast was
“Do you know how to create an automated, iterative reverse DNS lookup tool in a
single Windows command? How about a ping sweeper in a single Windows command?
A password guesser?”

For the record, I didn’t attent because I read that and was like wtf, I hope that isnt going to be the focus of the webcast. After all, I feel as though that block should be common knowledge. Then I started reading the eh.net forum and realized not many people have the command line f00. So, I want everyone to purchase this book:
http://search.barnesandnoble.com/Microsoft-Windows-Command-Line- Administrators-Pocket-Consultant/William-R-Stanek/e/9780735620384/? itm=1

this book will provide you so much more info than any Administering Windows Server book will ever give you. Remember, when you are popping shells you don’t have a gui… Unless you use the VNC payload, or crakc a password and Term serv in… But wheres the fun in any of that?

So let’s get started shall we? The first topic is reverse dns, which chrisg answered no and yes to in the forum over at eh.net. He knows how in bash, but not in windows…. Ok, lets see

———————————————————————
nope but i can do it in bash…

Code:


#!/bin/bash

cat iprange.txt | while read IP;
do echo ${IP} && host ${IP} nameserverIP;
done >> hostoutput.txt
 

——————————————————————–
First, I wouldnt even bother with this.

Code:


$ UNSET HISTFILE
$ for addr in `cat iprange.txt`; do echo $addr && host $addr >> output.txt; done


 

That’s besides the point, we are talking about windows!

Code:


for /F %host in (c:iplist.txt) do echo %host && nslookup %host >> output.txt

 

NEXT!!!!!!!

ping sweep

one of two ways
with a target list:

generate a target list:

Code:


for /l %i in (1,1,254) do echo 192.168.1.%i >> targetlist.txt
for /F %addr in (c:targets.txt) do echo %addr && ping -n 1 -w 2 %addr >> output.txt
 

without target list :

Code:


for /l %i in (1,1,254) do ping -n 1 -w 2 192.168.1.%i >> output.txt
 

what about a larger network?

Code:


for /l %i in (1,1,254) do ping -n 1 -w 2 10.10.%i.%i >> biglist.txt
 

next up is a password guesser

this one is easy!

Code:


for /F %passwd in (c:passwdlist.txt) do net use localhostipc$ %passwd /u:"administrator"
 

There’s your Windows cmd line f00 for the day

Code Obfuscation and LSO Crackme 0×02

Posted by Eric | Crackme, Reversing | Thursday 21 February 2008 11:10 am

<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-43"><a href="http://hamsterswheel.com/techblog/?p=43" rel="bookmark">Intro to Dumpbin and PEfile for detection of Packers</a></h2> <div class="meta">Posted by Eric | <a href="http://hamsterswheel.com/techblog/?cat=11" title="View all posts in Research" rel="category">Research</a>, <a href="http://hamsterswheel.com/techblog/?cat=13" title="View all posts in Reversing" rel="category">Reversing</a>, <a href="http://hamsterswheel.com/techblog/?cat=2" title="View all posts in Windows" rel="category">Windows</a> | Tuesday 19 February 2008 11:53 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="20080219;8313200" /><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">After reading the last post we have some general idea’s of what we are looking for, let’s look at using dumpbin and pefile to analyze a file and see if we can determine the presence of a packer.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">For the sake of the post/ learning I have copied notepad.exe from c:\windows\system32 to a local working directory. I have downloaded the latest copy of UPX and packed the notepad file using the command line:</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">upx -9 -o noteupx.exe notepad.exe</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">Doing this allows us to compare and contrast differences as we look at the packed file. This will enhance your learning experience. Afterall, if you don’t know what the data should look like, how will you be able to tell if something is not right.</p> <p style="margin-bottom: 0in">Dumpbin comes with Microsoft Visual c++. The utility provides information about the format and symbols provided in an executable, library or DLL file. A full description of dumpbin can be found here. <a href="http://support.microsoft.com/kb/177429">http://support.microsoft.com/kb/177429</a>.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">Using the /imports option we can dump a list of imports for our file.</p> <p style="margin-bottom: 0in"><img src="http://www.hamsterswheel.com/blogpics/dumpbin-imp.JPG" /></p> <p style="margin-bottom: 0in">We see that our file has hardly any imports. Looking at the original file, we dump the imports and we see quite a few imports in the file. Going back to the last blog post, We know a lack of imports is indicative of a packer.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">Utilizing strings from sysinternals, or on a Linux machine we find that the original PE file has quite a few strings in it. When we dump the strings on the packed file however, we find what appears to be mostly garbage data. Strings can be used simply by typing the following on the windows or Linux command line.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">strings</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">Next we want to take a look at the sections. We know what sections should be there, but we don’t know if they will be. After all if the PE is Packed, there is a chance the packer changed the section names. Using Dumpbin we can obtain a list of the sections names. On the command line we simply type</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">dumpbin /HEADERS noteupx.exe</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">We recieve some output as follows:</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in"><img src="http://www.hamsterswheel.com/blogpics/dumpbin-header.JPG" /></p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">We see that within out headers we have a few sections with weird names. First section that comes to our attention is UPX0, The Second is UPX1. The .RSRC section is our Resources Section and we would expect that to be there. If you are following along with the notes on PE format, you will note that the UPX sections are obviously different from what we would expect. A little googling will reveal that UPX (although we already knew that) is the name of a packer that is very common.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">With the information we just obtained we could easily go on to Tuts4you.com and grab a tutorial on unpacking UPX. Of course, for UPX there are some automated utilities that will help in unpacking the PE for you.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">Moving on, let’s look at pefile. Pefile is a “multiplatorm python module to read and work with PE files….” pefile is hosted on google code and can be located at <a href="http://code.google.com/p/pefile/">http://code.google.com/p/pefile/</a>. To install pefile simply download the code, browse to the directory on the windows command line and execute the setup.py file by running python setup.py install. From here on out we will be writing some code in python to utilize pefile. All our python scripts will start with</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">import pefile</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">Lets use pefile to look at our sections:</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in"><code /></p> <p style="margin-bottom: 0in">import pefile</p> <p style="margin-bottom: 0in">import sys</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">file = pefile.PE(sys.argv[1])</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">for section in file.sections:</p> <p style="margin-bottom: 0in">print(section.Name, hex(section.VirtualAddress),</p> <p style="margin-bottom: 0in">hex(section.Misc_VirtualSize), section.SizeOfRawData)</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">When run against each of our PE files, we recieve a nice dump of the sections along with their virtual addresses, sizes and the size of the raw data. From the screen shot below, you can see the differences not only in the section names, but also the sizes.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in"><img src="http://www.hamsterswheel.com/blogpics/pefile-sections.JPG" /></p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">Next we will use pefile to take a look at the imports of the PE. Like the previous example this one is pretty simple to code up and works very well.</p> <p style="margin-bottom: 0in"><code /></p> <p style="margin-bottom: 0in">import pefile</p> <p style="margin-bottom: 0in">import sys</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">file = pefile.PE(sys.argv[1])</p> <pre>for entry in file.DIRECTORY_ENTRY_IMPORT: print entry.dll for imp in entry.imports: print 't', hex(imp.address), imp.name</pre> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in"><img src="http://www.hamsterswheel.com/blogpics/pefile-imports.JPG" /></p> <p style="margin-bottom: 0in">running our code against both executables again reveals what we figured it would. The packed PE has very few imports, the unpacked PE on the other hand scrolled off the screen with all the imports.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">This post was a rough introduction to Pefile and dumpbin. You can do a lot of cool stuff with Pefile and I recommend you go check out the wiki and play around with it a bit. <a href="http://code.google.com/p/pefile/w/list">http://code.google.com/p/pefile/w/list</a></p> <p style="margin-bottom: 0in"> </div> <div class="feedback"> <a href="http://hamsterswheel.com/techblog/?p=43#respond" title="Comment on Intro to Dumpbin and PEfile for detection of Packers">Comments (0)</a> </div> </div> <div class="post"> <h2 id="post-41"><a href="http://hamsterswheel.com/techblog/?p=41" rel="bookmark">Detecting Packers</a></h2> <div class="meta">Posted by Eric | <a href="http://hamsterswheel.com/techblog/?cat=1" title="View all posts in General" rel="category">General</a>, <a href="http://hamsterswheel.com/techblog/?cat=11" title="View all posts in Research" rel="category">Research</a>, <a href="http://hamsterswheel.com/techblog/?cat=13" title="View all posts in Reversing" rel="category">Reversing</a> | Thursday 14 February 2008 12:27 am </div> <div class="storycontent"> <p><meta content="text/html; charset=utf-8" http-equiv="CONTENT-TYPE" /><title /><meta content="OpenOffice.org 2.0 (Linux)" name="GENERATOR" /><meta content="20080213;21561600" name="CREATED" /><meta content="16010101;0" name="CHANGED" /><br /> <style> <!-- @page { size: 8.5in 11in; margin: 0.79in } P { margin-bottom: 0.08in } --> </style> <p style="margin-bottom: 0in">My wife’s been back for almost a week and I’ve gotten little computer time. Between her and the baby I’ve been trying to dish out time and my lab has not gotten the best of the time allocation! Next month I need to do a little tour back to Basics and lock down my Linux and Bsd Exploitation. After that I need to get spun up on Sparc Architecture and exploitation on Sparcs and the Solaris Operating system. Orange County DC group (DC949) is hosting the Actf again this year, but its now known as the Octf, which stands for Open Capture the Flag. If I can get out to Defcon this year I have every intention on participating. They had a short spoiler posted to their website a few day’s ago that outlined a Sparc server someone donated, so I fully expect to see sparc out there this year. Aside from that, I’ve got a few penetration test’s coming up and as it would turn out they will be outside of my world of HIPPA. This means I have to spin myself up on I.T Governance outside of the Medical field.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">Back to Packers!</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">We’ve discussed what packers are, We’ve addressed how they function. Now let’s discuss how to detect them. There are manual methods of detecting, and automated analysis tools. It should be advised that the automated analysis will work often, However, they can be circumvented and should be used cautiously. Furthermore, if the Packing Algorithm is custom you are pretty much out of luck because an automated tool will not help you. Usually you will want to begin by analyzing the PE header and layout. According to Paul Craig of Security-assessment.com there are essentially four way in which we can detect the presence of a Packer.</p> <p style="margin-bottom: 0in"> <ol> <li> <p style="margin-bottom: 0in">The Import table</p> </li> <li> <p style="margin-bottom: 0in">String Table</p> </li> <li> <p style="margin-bottom: 0in">Code body</p> </li> <li> <p style="margin-bottom: 0in">Section Names</p> </li> </ol> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">The Import Table.</p> <p style="margin-bottom: 0in">Recall from previous notes that the import table is a table of external functions that an application wants to use. Normally even a small executable will contain a good amount of imports depending on its functionality. If you notice only a few imports Its time to be suspect. Furthermore, if those few imports are functions that locate other functions, or depend on other functions… Chances are you have a packer.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">String Table.</p> <p style="margin-bottom: 0in">As you will recall a string table is a table of commonly used strings in the application. When you use strings on an executable you usually get a pretty decent list. However, if this list goes missing, is corrupt or is encrypted it becomes apparent that a packer has been used. Beyond that, Packers also tend to add their own entries into a string table.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">Code Body.</p> <p style="margin-bottom: 0in">When you disassemble a normal application, even a small one the code body can be big. If you disassemble a binary and the code body is a lot smaller than normal Theres a chance you’ve been packed. The disassembly would only show the PE Packer stub routine, you may see a large amount of data in the executable, but since it’s packed you don’t see it as code.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">Section Names.</p> <p style="margin-bottom: 0in">Compilers and linkers have standard naming conventions for each code and data section. Once you become familiar with these naming conventions it becomes easy to spot something out of the ordinary. Also, in the case of UPX the Packer will nicely Label itself in a section name.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">There are a few Automatic detectors out there, but I’ve already outlined their shortcomings. It’s advised to use caution with them. Peid is one, GT2 is another. I’ve got other stuff to do so feel free to google and comment on any others you know of or find!</p> <p style="margin-bottom: 0in"> </div> <div class="feedback"> <a href="http://hamsterswheel.com/techblog/?p=41#respond" title="Comment on Detecting Packers">Comments (0)</a> </div> </div> <div class="post"> <h2 id="post-40"><a href="http://hamsterswheel.com/techblog/?p=40" rel="bookmark">Well there goes 400 bucks</a></h2> <div class="meta">Posted by Eric | <a href="http://hamsterswheel.com/techblog/?cat=1" title="View all posts in General" rel="category">General</a> | Tuesday 12 February 2008 2:59 pm </div> <div class="storycontent"> <p><font size="2">Dear Eric</font></p> <p><font size="2">RE: CISA Exam Result Notification — Exam ID: 07449544</font></p> <p><font size="2">At your request (per your exam registration authorization), this email is being sent to notify you of your December 2007 CISA exam result.</font></p> <p><font size="2">We are sorry to inform you that you were not successful in passing the CISA exam. You received a total scaled score of 422. A scaled score of 450 or higher is required to pass, which represents the minimum consistent standard of knowledge as established by ISACA’s CISA Certification Board.</font></p> <p><font size="2">SCALED SCORES OF YOUR PERFORMANCE BY AREA:<br /> 299 IS Audit Process<br /> 496 IT Governance<br /> 345 Systems and Infrastructure Life Cycle Management<br /> 345 IT Service Delivery and Support<br /> 521 Protection of Information Assets<br /> 377 Business Continuity and Disaster Recovery</font></p> <p>I guess that teachs me not to ever go take a $400, 200 question test without studying! Oh well, back to self studying of the things that matter…</p> </div> <div class="feedback"> <a href="http://hamsterswheel.com/techblog/?p=40#respond" title="Comment on Well there goes 400 bucks">Comments (0)</a> </div> </div> <div class="post"> <h2 id="post-39"><a href="http://hamsterswheel.com/techblog/?p=39" rel="bookmark">Notes on Portable Executable Format (2)</a></h2> <div class="meta">Posted by Eric | <a href="http://hamsterswheel.com/techblog/?cat=13" title="View all posts in Reversing" rel="category">Reversing</a>, <a href="http://hamsterswheel.com/techblog/?cat=2" title="View all posts in Windows" rel="category">Windows</a> | Friday 8 February 2008 3:25 pm </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="20080208;12594600" /><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">Round 2 of Notes on PE Format</p> <p style="margin-bottom: 0in"><a href="http://msdn.microsoft.com/msdnmag/issues/02/03/PE2/">http://msdn.microsoft.com/msdnmag/issues/02/03/PE2/</a></p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">Portable Executable Sections</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">EXPORTS SECTION:</p> <p style="margin-bottom: 0in">When an executable exports data it makes functions and variables available to others.</p> <p style="margin-bottom: 0in">-Exported functions and variables are known as symbols.</p> <p style="margin-bottom: 0in">-Each symbol has an ordinal Number and an ASCII name.</p> <p style="margin-bottom: 0in">-Lookups by ordinals are faster, and the ASCII names are just for convenience.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">IMAGE_EXPORT_DIRECTORY</p> <p style="margin-bottom: 0in">Exports directory points to 3 arrays and a table of ASCII strings.</p> <p style="margin-bottom: 0in">-Only required array is the EAT (export Address Table), which is an array of function pointers that contain the address of an exported function.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">-When calling a function the ordinal value of the function is looked up.</p> <p style="margin-bottom: 0in">-Using the ordinal value as an index into the export address table it resolved the relative virtual address (RVA) of the function. Adding the RVA to the load address of the DLL yields the actual address of the function.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">IMPORTS SECTION:</p> <p style="margin-bottom: 0in">IMAGE_IMPORT_DESCRIPTOR – Anchor of imports section</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">Data directory entry for imports points to an array of these structures.</p> <p style="margin-bottom: 0in">Each Import has one descriptor structure.</p> <p style="margin-bottom: 0in">Each descriptor points to two identical arrays</p> <p style="margin-bottom: 0in">-Import Address Table(IAT)</p> <p style="margin-bottom: 0in">-Import Name Table (INT)</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">-Both arrays have elements of type IMAGE_THUNK_DATA.</p> <p style="margin-bottom: 0in">-Each element corresponds to one imported function from the executable.</p> <p style="margin-bottom: 0in">-In the executable the thunk_data structure contains either an ordinal value or RVA to an IMAGE_IMPORT_BY_NAME structure.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">IMAGE_IMPORT_BY_NAME structure is just a word, followed by a string naming the imported API</p> <p style="margin-bottom: 0in">-The word value serves as a hint to the loader for what the ordinal might be.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">When the windows Loader brings in the executable it overwrites the IAT with the actual address of the imported function.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">The INT is identical to the IAT but the key difference is the INT is not overwritten by the loader. Why then have two identical arrays? So the original information can be retrieved later on.</p> </div> <div class="feedback"> <a href="http://hamsterswheel.com/techblog/?p=39#respond" title="Comment on Notes on Portable Executable Format (2)">Comments (0)</a> </div> </div> <div class="post"> <h2 id="post-38"><a href="http://hamsterswheel.com/techblog/?p=38" rel="bookmark">Notes on Portable Executable Format (1)</a></h2> <div class="meta">Posted by Eric | <a href="http://hamsterswheel.com/techblog/?cat=13" title="View all posts in Reversing" rel="category">Reversing</a>, <a href="http://hamsterswheel.com/techblog/?cat=2" title="View all posts in Windows" rel="category">Windows</a> | Monday 4 February 2008 12:05 pm </div> <div class="storycontent"> <p><meta content="text/html; charset=utf-8" http-equiv="CONTENT-TYPE" /><title /><meta content="OpenOffice.org 2.0 (Linux)" name="GENERATOR" /><meta content="20080204;8054500" name="CREATED" /><meta content="16010101;0" name="CHANGED" /><br /> <style> <!-- @page { size: 8.5in 11in; margin: 0.79in } P { margin-bottom: 0.08in } --> </style> <p style="margin-bottom: 0in">A few Notes on the MSDN Article “<a href="http://msdn.microsoft.com/msdnmag/issues/02/02/PE/">An In-depth look into the win32 Portable Executable Format</a>“, which is considered in the RE Community one of the best articles to day on the PE Format.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">Data structures on disk are the same in memory</p> <p style="margin-bottom: 0in"> The Windows Loader decides what sections to map into memory</p> <p>Higher Offsets in the file coorespond to higher offsets in memory</p> <p>However, offsets on disk image may differ from memory image</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">When a Portable Executable is loaded into memory it is known as a module.</p> <p style="margin-bottom: 0in"> A Module represents all code, data and resources that is needed by a process.</p> <p>Api functions for Modules : IMAGEHLP.DLL</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">To avoid hardcoding memory addresses in Portable Executables and RVA is used</p> <p>A Relative Virtual Address is an offset in memory relative to where the portable executable was loaded.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">When you use code or data from another dll you are importing it.<br /> The windows Loader takes care of loading all imported functions (via populating the IAT)</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">Within a portable executable file there is an array of data structures one for each imported DLL.<br /> Each data structure gives the name of the imported dll and points to an array of function pointers.</p> <p style="margin-bottom: 0in">This array of function pointers is what is known as the Import Address table (IAT)</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">Notes on the IAT:</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">The Import Address Table is a table of external functions that an application wants to use.</p> <p>As an example the function Sleep() in found in kernel32.dll</p> <ul /> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">The Import Address Table contains the location in memory of an imported Function</p> <p style="margin-bottom: 0in">The Application uses the IAT to find other dll’s in memory.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">When code is compiled, the IAT contains NULL memory pointers for each function. Then the executable is started the windows loader finds the correct address and overwrites the NULL Pointers.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in"> <p><center> <!-- Begin Google Adsense code --> <script type="text/javascript"><!-- google_ad_client = "pub-9774791470740882"; google_ad_width = 468; google_ad_height = 60; google_ad_format = "468x60_as"; google_ad_type = "text_image"; google_ad_channel =""; //--></script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> <!-- End Google Adsense code --> </center></p> </div> <div class="feedback"> <a href="http://hamsterswheel.com/techblog/?p=38#respond" title="Comment on Notes on Portable Executable Format (1)">Comments (0)</a> </div> </div> <div class="post"> <h2 id="post-37"><a href="http://hamsterswheel.com/techblog/?p=37" rel="bookmark">Introduction to Portable Executable Packing</a></h2> <div class="meta">Posted by Eric | <a href="http://hamsterswheel.com/techblog/?cat=11" title="View all posts in Research" rel="category">Research</a>, <a href="http://hamsterswheel.com/techblog/?cat=13" title="View all posts in Reversing" rel="category">Reversing</a> | Sunday 3 February 2008 10:41 pm </div> <div class="storycontent"> <p><meta name="CREATED" content="20080203;20110700" /><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"> <p style="margin-bottom: 0in">Packing Portable Executables was orginally intended as a means of data compression in order to reduce the size of an executable. The way this works is an executable is contained within another executable. Consider as an example<a href="http://www.lwalton.co.uk/images/20060619191239_russian%20dolls.jpg"> Russian Dolls</a>. Where the inner doll (code) is the actual code. So when the outter executable is run, it decompresses the inner executable into memory. After the inner executable is in memory its code is executed normally.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">For information on PE Coff I would advise anyone needing even a refresher to visit <a href="http://msdn.microsoft.com/msdnmag/issues/02/02/PE/">this article</a>, It’s one of the best articles I’ve found. Perhaps tomorrow I will type up my Notes on the PE File Format and post them up.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">First, Execution of the packed binary begins as any other. The DOS MZ Header is read, followed by the PE Header, and then the windows Loader reads the Section Table. At this point System Memory is allocated for all the Sections and Headers within the Packed binary. The executable is copied into memory and then the disk image is no longer used. The windows Loader proceeds to populate the Import Address Table.(See SIDEBAR) After the Windows Loader populated the Import Address Table execution is passed to the Entry point of the packed binary. This leads into a packed section of code. The packed section executes code which will pretty much be the Packers Unpacking routine. So the inner (packed code) is now in memory. But wait, the packed binary is in memory in an unpacked form, but it doesnt have an import address table. The windows didn’t load it, and we have no addresses for our imported functions. The Packer must now take the time to populate the IAT for the code in memory. After it does this, it resets its stack pointers to NULL. It resets the stack pointers in order to avoid having any effect on execution. The Packer turns over execution to the OEP (Original Entry Point) of the packed binary in memory. This is usually done with a JMP, CALL or RET instruction. Now the Packed Binary Executes Normally.</p> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">Why should this concern you?</p> <p style="margin-bottom: 0in"> <ul> <p style="margin-bottom: 0in">Malware can utilize packers in order to hide their true purpose from Anti Virus scanners</p> <p style="margin-bottom: 0in">The code is extracted into memory, this is dangerous for forensics</p> <p style="margin-bottom: 0in">Lastly, Packing Data can Slow down Reverse Engineering efforts</p> </ul> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in"> <p style="margin-bottom: 0in">SIDEBAR:</p> <p style="margin-bottom: 0in">(When Code is compiled into binaries, the IAT contains Null Pointers, this is due to locations of functions being Dynamic due to Service pack, and OS Distro… This is a common reason why in exploitation an exploit may have many return addresses, e.g Win XP SP 0, Win 2000 SP 4)</p> <p><center> <!-- Begin Google Adsense code --> <script type="text/javascript"><!-- google_ad_client = "pub-9774791470740882"; google_ad_width = 468; google_ad_height = 60; google_ad_format = "468x60_as"; google_ad_type = "text_image"; google_ad_channel =""; //--></script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> <!-- End Google Adsense code --> </center></p> </div> <div class="feedback"> <a href="http://hamsterswheel.com/techblog/?p=37#comments" title="Comment on Introduction to Portable Executable Packing">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>