Docsity

Software Cracking Lab: Understanding Code Injection and Serial Key Generators - Prof. Geor, Lab Reports of Electrical and Electronics Engineering

Toggle sidebar
bg1
ECE4112 Internetwork Security
Lab X: Code Injection and Software Cracking
Group Number: _________
Member Names: ___________________ _______________________
Date Assigned: x
Date Due: x
Last Edited: November 26th, 2007
Lab Authored By: Jason Fritts, Zener Bayudan, Utsav Kanani
Please read the entire lab and any extra materials carefully before starting. Be sure to start early enough so
that you will have time to complete the lab. Answer ALL questions in the Answer Sheet and be sure you
turn in ALL materials listed in the Turn-in Checklist on or before the Date Due.
Goal: The goal of this lab is to introduce you to the concept of software cracking and how software
cracks often contain code injection. We will show you how easy it is to inject any type of code (ie.
Malware) in a program and the user will never know it has been executed. We will show you the
different concepts commonly used by software crackers to bypass any type of authentication the software
writer implements, and how a software writer can prevent this from happening.
Summary: You will write a common program which requires an authentication check, crack
this program using different concepts, and then analyze the results. You will also inject code into a
program and have both the host and the injected program run.
Background and Theory: Software cracking is the modification of software
to remove protection methods: copy prevention, trial/demo version, serial number, hardware key,
CD check or software annoyances like nag screens and adware.”
(http://en.wikipedia.org/wiki/Software_cracking)
Software cracking has become widespread on the Internet, where one can find a crack for almost
any commercial software program available on the market. Thousands of websites dedicated to
providing programs which will crack commercial software have appeared on the Internet in the
last ten years, making it easier than ever before to pirate software.
“The most common software crack is the modification of an application's binary to cause or
prevent a specific key branch in the program's execution. This is accomplished by reverse
engineering the compiled program code using a debugger such as SoftICE, OllyDbg, GDB, or
MacsBug until the software cracker reaches the subroutine that contains the primary method of
protecting the software (or by disassembling an executable file with a program such as IDA).
The binary is then modified using the debugger or a hex editor in a manner that replaces a prior
branching opcode with its complement or a NOP opcode so the key branch will either always
execute a specific subroutine or skip over it. Almost all common software cracks are a variation
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15

Partial preview of the text

Download Software Cracking Lab: Understanding Code Injection and Serial Key Generators - Prof. Geor and more Lab Reports Electrical and Electronics Engineering in PDF only on Docsity!

ECE4112 Internetwork Security

Lab X: Code Injection and Software Cracking

Group Number: _________ Member Names: ___________________ _______________________ Date Assigned: x Date Due: x Last Edited: November 26th, 2007 Lab Authored By: Jason Fritts, Zener Bayudan, Utsav Kanani Please read the entire lab and any extra materials carefully before starting. Be sure to start early enough so that you will have time to complete the lab. Answer ALL questions in the Answer Sheet and be sure you turn in ALL materials listed in the Turn-in Checklist on or before the Date Due.

Goal: The goal of this lab is to introduce you to the concept of software cracking and how software

cracks often contain code injection. We will show you how easy it is to inject any type of code (ie. Malware) in a program and the user will never know it has been executed. We will show you the different concepts commonly used by software crackers to bypass any type of authentication the software writer implements, and how a software writer can prevent this from happening.

Summary: You will write a common program which requires an authentication check, crack

this program using different concepts, and then analyze the results. You will also inject code into a program and have both the host and the injected program run.

Background and Theory: Software cracking is the modification of software

to remove protection methods: copy prevention, trial/demo version, serial number, hardware key, CD check or software annoyances like nag screens and adware.” (http://en.wikipedia.org/wiki/Software_cracking) Software cracking has become widespread on the Internet, where one can find a crack for almost any commercial software program available on the market. Thousands of websites dedicated to providing programs which will crack commercial software have appeared on the Internet in the last ten years, making it easier than ever before to pirate software. “The most common software crack is the modification of an application's binary to cause or prevent a specific key branch in the program's execution. This is accomplished by reverse engineering the compiled program code using a debugger such as SoftICE, OllyDbg, GDB, or MacsBug until the software cracker reaches the subroutine that contains the primary method of protecting the software (or by disassembling an executable file with a program such as IDA). The binary is then modified using the debugger or a hex editor in a manner that replaces a prior branching opcode with its complement or a NOP opcode so the key branch will either always execute a specific subroutine or skip over it. Almost all common software cracks are a variation

of this type. Proprietary software developers are constantly developing techniques such as code obfuscation, encryption, and self-modifying code to make this modification increasingly difficult.” Software cracks often contain viruses. This is done through code injection. A virus writer will find a popular crack on the internet, inject his virus code inside of this crack, and then rerelease it on the internet for others to download.

Lab Scenario: For this lab you will be writing a sample program which requires the

user to authenticate themselves using a serial number. Next you will be cracking this program using a disassembler and hex editor. You will also be writing a serial key generator so there is no need to modify the original sample program. After doing both of these examples you will be given a brief overview of common cracking countermeasures using the program EXEcryptor. Finally the dangers of using publicly available cracks on the Internet will be discussed, including cracks which have viruses and backdoors embedded in them.

Section 1: Cracking a simple program.

1.1 Installing the necessary tools (within Windows XP)

For this section you will need the following tools:

  1. Dev-C++ - for writing and compiling the actual C++ program.
  2. W32dsm – a program disassembler used for assembly viewing.
  3. Hex Workshop – a hex editor used for editing the executable program. All of these files should be transferred from the NAS server to your desktop and installed to their default locations.

1.2 Writing the crackable program.

First we will write a program that requires the user to enter a serial number for authentication before continuing. For this example we will be showing the concepts crackers use to get past this authentication check, and therefore this program doesn't need to be very complicated. Our program will ask the user for their serial number and perform a numerical check versus the defined serial number. Note: This entire lab will be done within your Windows XP Vmware virtual image.

Screenshot 1: Example of a crackable program requesting user authentication. You should notice that typing any serial number other than the defined serial “12345” will not authenticate you to the program.

1.3 Cracking the program.

Now that we have created a simple program to crack, we will crack it using the reverse engineering program modification technique. The reverse engineering program modification technique is very simple. First, using a program disassembler the cracker views the assembly code of the program he wants to crack. Next, he uses some means to find the assembly code which compares his typed in serial number with the serial number defined by the program. Next he wants to completely bypass this comparison and jump directly to whatever function an authenticated user will enter after a successful comparison. To accomplish this the cracker notes the program offset (line number) the comparison takes place at and finds this location of the program after opening the program in a hex editor. He will then replace the Jump instruction in the program with a NOP instruction. Now after typing an invalid serial key, the program will not jump to a “invalid serial key” function, it will continue to the “valid serial key” function of an authenticated user.

1.3.1 Finding the serial key comparison instruction.

1. Open up W32dsm: ~\W32dsm\W32dsm87.exe 2. Load Example1.exe compiled earlier: Disassembler-Open file to disassemble- example1.exe As shown in Screenshot 2.

Note: You may need to change your system font: Disassembler-Select Font

3. Find the comparison assembly code: Refs-String data references-”valid serial number, type any”. And double click this line to be taken to it. Note: You should be taken to a “push” instruction, this is the instruction that prepares to print “valid serial number”. Which is the location which will be executed after a successful serial number comparison. We will now find this comparison. 4. Scroll a few lines above the “push” instruction, and you should see an instruction “cmp eax, dword ptr ...”. This is the serial key comparison instruction, below it is the instruction “JNE”, or a jump not equal instruction, meaning it will jump to the memory location specified if the previous comparison failed. Note that the memory instruction this JNE jumps to is the “invalid serial number” print function. 5. Find the offset of the JNE instruction by highlighting it using the Up/Down arrow keys, and noting the “@Offset 00000###h” at the very bottom of the screen. Screenshot 2. Example1.exe loaded in w32dasm.

1.3.2 Editing the program to skip the serial key comparison.

Note: We will now edit the program so this JNE instruction is completely skipped.

  1. Open up HexWorkshop: Start-Programs-Hex Workshop 4.2-Hex Worskshop

2.1 Writing a keygen crackable program

In this section we just want to show how a more secure program can be written and the way it can be bypassed. We will write a simple program that requires the user to enter a product id and a serial key for authentication before continuing. Then using a simple algebraic expression the product id (pid) is used to generate a variable. This variable is then matched with the key entered .If there is a perfect match it means the user has been successfully authenticated.

  1. Open Dev-C++ from the start menu Start-Programs-”Dev-C++”-”Dev-C++”
  2. Start new C++ console project: File-New Project-Console Application-C++ project
  3. Name the project “Example2”
  4. Use the following code:
  5. Compile the program: Execute-Compile
  6. Run the program: Execute-Run Code Example: Example2.exe, code which cannot be exploited using the method in Section 1. int main(int argc, char * argv[]) { int serial; int pid; int output; cout << "Type in your product id:"; cin >> pid; output = ((pid2 + 73)3) - 28; cout << "Type in your serial key:"; cin >> serial; if (serial == output){ cout << "valid serial number, type any character to exit"; cin.ignore(1); cin.get(); return 1; } else cout << "Invalid serial number, type any character to exit"; cin.ignore(1); cin.get(); return 0; }

In this case too, you should notice that typing any product id or serial key other than the defined will not authenticate you to the program. Thus this adds double protection.

2.2 Writing a key generator.

In this section we will see how easy it is to get around the above mentioned security measure using a keygen. The advantage of using a keygen is that it is automated and the user just has to provide an input and the key is outputted. There is no need for the user to disassemble the software code and make changes. Thus there is no need of having any knowledge about assembly level programming. In the following part we will show with the help of a simple C++ program, the basic idea behind the making of a key generator. Code Example: Keygen.exe, code for a key generator for Example2.exe The basic procedure followed while building a keygen is:

  1. The algebraic expression used for authentication is obtained using a disassembler like W32dsm.
  2. Then using this expression in the program and taking the product key as an input the serial key is obtained. Now run the keygen.exe file which is found in the labx folder downloaded from the NAS. Enter any digit number when asked for a product id. Remember the number entered. Also note down #include using namespace std; int main(int argc, char * argv[]) { int serial; int pid; int output; cout << "Type in your product id:"; cin >> pid; output = ((pid2 + 73)3) - 28; cout << "Your serial key is:"; cout << output; cin.ignore(1); cin.get(); return 1; }

which will make code disassembly painfully long for a cracker. However, given enough time any protection scheme will eventually be cracked. In this section we will be looking at one example of a commercial encryption program named EXEcryptor. From the EXEcryptor website: “EXECryptor uses a conceptually new approach to protect software applications. The core of the protection technology is a brand new concept of the code transformation called "Code Morphing". This technology protects the code on the CPU-command level. It is known the x86 processors command system is redundant and allows the execution of the same 'code' using various different system commands. EXECryptor breaks up the protected code into several processor commands or small command snippets and replace them by others, while maintaining the same end result. Thus EXECryptor obfuscates the code not on the source level but on the level of the CPU commands. The Code Morphing is multilevel technology containing hundreds of unique code transformation patterns. In addition this technology includes the special layer that transforms some commands into Virtual Machine commands (like P-Code). EXECryptor's Code Morphing turns binary code into an undecipherable mess that is not similar to normal compiled code, and completely hides execution logic of the protected code. Unlike other code protectors, there is no concept of code decryption with EXECryptor. Protected code blocks are always in the executable state, and they are executed as a transformed code. The original code is completely lost and code restoration is an NP-hard problem.”

3.1 Installation and Configuration (within Windows XP )

  1. Download EXEcryptor.2.3.9.zip from the NAS server.
  2. Unzip to the desktop.
  3. Run EXECryptorSetup.exe, install to default location.
  4. Run EXECryptor: Start-Programs-EXECryptor-EXECryptor.
  5. Start a new project: Project-New, type in a project name, press save.
  6. Choose example1.exe as the application file name, and change the protect file name to example1protected.exe
  7. Under “Protection options”, use default options, but add “VMWare compatible” as shown in Screenshot 3.
  8. Under “Serial number support” choose One-touch trial configuration, and choose your product name to be Example1.
  9. Under Limitation, choose Executions to 3 runs.
  10. Press “Protect” to create your protected program.

Screenshot 4: Default options for EXECryptor.

3.2 Testing your protected program

Now that we have created a program which is protected by EXECryptor’s code encryption, we will test to see if it is possible to still bypass the authentication check using the methods in section 1. First we will attempt to disassemble the program using w32dsm.

  1. Open w32dsm: ~\W32dsm\W32dsm87.exe
  2. Load example1protected.exe: Disassembler-Open File to Disassemble. Q 3.1 What is different about the assembly code shown by w32dsm now? Now that it has been determined that a cracker cannot easily disassemble our program, we will test EXECryptor’s trial version functionality.
  3. Run example1protected.exe, and press the evaluation button. Q 3.2 Do you have access to the actual program?
  1. Transfer the poc1.exe (i.e., the file you downloaded in step (2)) to the CODE folder.
  2. Run poc1.exe and verify that it’s working properly.
  3. Transfer the odbg110.zip (i.e., the file you downloaded in step (3)) to the CODE folder.
  4. Extract the odbg110.zip to a new folder; call that folder as ODBG.
  5. Run OLLYDBG.EXE from ODBG folder; click yes when you see ‘Old DLL’ pop up.
  6. Click File >> Open.
  7. Search and select poc1.exe (i.e., the file from step (5)) and click Open; you should see a screen similar to Figure 4.1.1. Figure 4.1.1. Screen when you just opened poc1.exe.
  8. On the top-left frame, scroll down to the very bottom.
  9. Scroll up until you see codes like in Figure 4.1.2. Figure 4.1.2. DB 00 entries.
  1. Highlight multiple DB 00 entries >> right-click on the selected entries >> Binary >> Edit; a popup window should come out.
  2. On the ASCII field of the popup window, type “ECE 4112” and click OK.
  3. Hit Ctrl + A (not Ctrl + Shift + a) to reanalyze the codes and verify that “ECE 4112” shows up. Q4.1.1 What is the address of “ECE 4112” string? (e.g., 0046090C)
  4. Just below the “ECE 4112” string, select multiple DB 00 entries, again >> right-click on the selected entries >> Binary >> Edit; a popup window should come out.
  5. On the ASCII field of the popup window, type “Success!” and click OK.
  6. Hit Ctrl + A to reanalyze the codes and verify that “Success!” shows up. Q4.1.2 What is the address of “Success!” string? (e.g., 00460915)
  7. Note the next DB 00 address (i.e., just below “Success!” string) and double on that DB 00, not the address! An “Assemble at” window should pop up. Q4.1.3 What is the address of the next DB 00? (e.g., 0046091E)
  8. Type “push 0” (no quotes!) and click Assemble.
  9. Type “push ADDR”, where ADDR is your answer in Q4.1.1, and click Assemble.
  10. Type “push ADDR”, where ADDR is your answer in Q4.1.2, and click Assemble.
  11. Type “push 0” and click Assemble.
  12. Type “call user32.MessageBoxA” and click Assemble.
  13. Close the “Assemble at” window.
  14. Hit Shift + 8 to go the entry point of poc1.exe. Screenshot #4.1.1 Take a screenshot of the entry point of poc1.exe. (MOV EAX,DWORD PTR DS:[46108B])
  15. Hit enter to get to the JMP target.
  16. Double on that target instruction and change it to “jmp ADDR”, where ADDR is your answer in Q4.1.3; note the address just below your new JMP entry. Q4.1.4 What is the address of the instruction just below your new JMP entry? (e.g., 00401313)
  17. Hit Ctrl + G, type ADDR, where ADDR is your answer in Q4.1.3, and hit OK.
  18. Double-click the instruction below your “CALL USER32.MessageBoxA”, type “jmp ADDR”, where ADDR is your answer in Q4.1.4.
  19. Right-click on any entry of the top-left frame >> Copy to executable >> All modifications; a new window should popup.
  20. Click Copy all from the popup window; a new window should popup, again.

References

  1. Cracking: The Removal of Software Copy Protection http://www.mindspring.com/~win32ch/Crackit.htm
  2. Cracking Tutorial [Download Master 2.0] http://71.6.196.237/fravia/es_tor_33.html
  3. EXECryptor – StrongBit Technology http://www.strongbit.com/default.asp
  4. AntiDebugging in Win http://vx.netlux.org/lib/vlj05.html
  5. Cracking4Newbies http://home.online.no/~reopsahl/files/c4nsitut.htm
  6. Fighting Pirates http://research.microsoft.com/displayArticle.aspx?id=
  7. AntiDebugging and Software Protection http://www.woodmann.com/crackz/Tutorials/Protect.htm
  8. Code Injection http://www.codeproject.com/KB/system/ inject2exe.aspx#BuildanImportTableandReconstructtheOriginalImportTable

Turn-in checklist

You need to turn in:  Answer sheet.  4 screenshots  Any corrections or additions to the lab.

Q 2.3 If any other expression is used in Example1.cpp will the serial key outputted by the keygen work. Justify your answer. Q 2.4 How would you prevent such type of cracking if you were a software manufacturer? Q 3.1 What is different about the assembly code shown by w32dsm now? Q 3.2 Do you have access to the actual program? Q 3.3 What occurs after your 3rd^ trial run? Q4.1.1 What is the address of “ECE 4112” string? (e.g., 0046090C) Q4.1.2 What is the address of “Success!” string? (e.g., 00460915)

**Q4.1.3 What is the address of the next DB 00? (e.g., 0046091E) Q4.1.4 What is the address of the instruction just below your new JMP entry? (e.g.,

Q4.5. Which viruses were found by AVG? Q4.6. What types of activities are performed by these viruses?**