Windows Security
  Home arrow Windows Security arrow Page 8 - Windows Reverse Engineering
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SECURITY

Windows Reverse Engineering
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 23
    2004-07-27

    Table of Contents:
  • Windows Reverse Engineering
  • History of RCE, Reversing Tools
  • Basic IDA Configuration and Manipulation Steps
  • Debuggers
  • System Monitors
  • Unpackers
  • Personal Firewalls and Install Managers
  • Reverse Engineering Examples
  • Example 2: Reversing Malicious Code

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Windows Reverse Engineering - Reverse Engineering Examples


    (Page 8 of 9 )

    Before beginning your practical journey, there is one final issue to note. Similar to software debugging, reverse engineering by definition goes in reverse. In other words, you must be able to think backward. Zen meditation skills will serve you better than many years of formal programming education. If you are good at solving verbal brain-teaser riddles on long trips with friends, you will probably be good at RCE. In fact, master reversers like +Fravia recommend cracking while intoxicated with a mixture of strong alcoholic beverages. While for health reasons we cannot recommend this method, you may find that a relaxing cup of hot tea unwinds your mind and allows you to think in reverse. The following segments walk you through live examples of Windows reverse engineering.

    Since it is illegal to defeat protections on copyrighted works, reverse engineers now program their own protection schemes for teaching purposes. Thus, crackmes are small programs that contain the heart of the protection scheme and little else.

    Example 1: A Sample Crackme

    Example 1 is Muad’Dib’s Crackme #1.

    The sample binaries (crackmes) used in this chapter may be downloaded from our web site at http://www.securitywarrior.com.

    This is a simple program, with a twist. The program’s only function is to keep you from closing it. For example, when you run the program you will see an Exit button. However, pressing the Exit button does not work (on purpose). Instead, it presents you with a nag screen that says, “Your job is to make me work as an exit button” (Figure 2-12).

    warrior

    Thus, the crackme emulates shareware or software that has features removed or restricted to the user (i.e., crippleware). Your job is to enable the program in order to make it fully functional. Fortunately, the program itself gives you a great clue. By searching the disassembled program for the following string:

    "Your job is to make me work as an exit button"

    you will probably be able to trace back to find the jump in the program that leads to functionality—i.e., a working Exit button.

    Once you have installed IDA Pro, open your target (in our case, Muad’Dib’s Crackme #1) and wait for it to disassemble. You will be looking at the bare, naked ASM. Go straight for the protection by searching the convenient list of strings that IDA Pro has extracted (Figure 2-13).

    warrior

    Double-clicking on our target string takes us directly to the target code in the disassembly (Figure 2-14).

    We arrive at this code:

    *Reference To: KERNEL32.ExitProcess, Ord:0075h

                                          |
    :00401024 E843000000       Call 0040106C
    ;( ThisCalls ExitProcess when we click on theWindows Exit Cross)
    :00401029 55                 push ebp
    :0040102A 8BEC               mov ebp, esp

    warrior

    :0040102C 817D0C11010000    cmp dword ptr [ebp+0C], 00000111
    :00401033 751F              jne 00401054
    :00401035 8B4510            mov eax, dword ptr [ebp+10]
    :00401038 6683F864          cmp ax, 0064
    :0040103C 752A              jne 00401068
    :0040103E 6A00              push 00000000

    *Possible StringData Ref from Data Obj ->"GOAL:"

    |
    :00401040 682F304000 push 0040302F
    ; This references the text in the MessageBox

    *Possible StringData Ref from Data Obj ->"Your job is to make me work as an exit button!"

    |
    :00401045 6800304000 push 00403000
    :0040104A FF7508 push [ebp+08]
    ;These lines push the Caption and Handle of the MessageBox

    *Reference To: USER32.MessageBoxA, Ord:01BBh
    :0040104D E832000000 Call 00401080
    :00401053 EB2A jmp 00401068

    This is the call to the annoying message box that we want to bypass! We need to patch this address to jump to the Exit Process API. This is the heart of the protection.

    Looking back at line 401024, we see it calls the exit process 0040106C, as follows:

    *Referenced by a CALL at Address:
    |:00401024 ;This made the call to 0040106C

    *Reference To: KERNEL32.ExitProcess, Ord:0075h
    This is the Exit Process API call that we need.
    |:0040106C FF2504204000 jmp dword ptr [00402004]

    Thus, we will patch with this jump instead. We replace the bytes at offsets 40104D and 401053 with those at offset 40106C, and when we click on the Exit button, the program will exit and the nagging message box will not appear.

    The best way to patch it is to replace these lines:

    :0040104D E832000000      Call 00401080
    :00401053 EB2A            jmp 00401068
    with the following:
    :0040104D FF2504204000    jmp dword ptr [00402004]
    :00401053 90              nop

    Thus, 0040104D now jumps to the ExitProcess address. The program exits appropriately when we click on either the X or the Exit button. 00401053 is extraneous, so we can just NOP it; this involves changing the JMP to a NOP (no operation).

    In order to do the actual opcode patching, you need to open the program in a hex editor. After you have installed the hex editor, simply right-click the binary program in Windows and select “open with Ultra Edit.” You will see the raw hex code (Figure 2-15) ready to be patched.

    warrior

    How do we find the bytes that we need to patch? Search the hex dump for a unique string of hex bytes that represents the target code. For example, to find:

    :0040104D E832000000     Call 00401080
    :00401053 EB2A           jmp 00401068

    we search for its unique hex string (Figure 2-16):

    E832000000EB2A

    warrior

    The key is to search for a hex string that is long enough that it will be unique in the application.

    Make sure to search using hex, rather than ASCII.

    Once you have found the target bytes, carefully replace them to bypass the jump. Then, simply save the binary application again and run it. In our example, the program exits properly when you click the Exit button. 

    Buy the book!If you've enjoyed what you've seen here, or to get more information, click on the "Buy the book!" graphic. Pick up a copy today!

    Visit the O'Reilly Network http://www.oreillynet.com for more online content.

    More Windows Security Articles
    More By O'Reilly Media


     

    WINDOWS SECURITY ARTICLES

    - Which Version of Windows 7 Should You Use?
    - Choosing the Best Windows XP Firewall
    - Finding the Correct Drivers for Windows XP D...
    - Windows Network Troubleshooting: Tips and Te...
    - Windows XP Home Network Setup: Essential Ste...
    - Using Windows Recovery Console to Fix Blue S...
    - Fix Blue Screen of Death in Windows XP: Corr...
    - Storing Data with Windows Skydrive
    - Windows System Administrator`s Toolbox
    - Solving Windows Genuine Advantage Problems
    - Encrypted Browsing in Windows using OpenSSH
    - Working with the Hosts File on Windows XP
    - Inventorying HDDs Remotely on Windows
    - Inventorying RAMs Remotely on Windows
    - Vital Windows Security Guidelines





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT