Weekly Roundup. Week ending July 18th

Posted by Eric | General, Windows | Friday 18 July 2008 4:20 am

Something new I’m going to try on both of my blogs. At the end of each week I will do a weekly roundup of links to posts and articles I found interesting.

Hack Yourself- How much sleep do you need?

Sans – Obfuscated Javascript Redux

Wordpress 2.6 Fixes 194 Bugs

50+ Personal Development sites you’ve never even heard of

The Black Market Code Industry

What I’ve been Doing on My Summer Vacation

Cyber Capos

CPU Bugs. Are they really necessary?

MetaGoofil FTW!

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

Intro to Dumpbin and PEfile for detection of Packers

Posted by Eric | Research, Reversing, Windows | Tuesday 19 February 2008 11:53 am

<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-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> <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>