Intro:
All the tools you will need can be found online:
pm to give you the link or just download it here
http://#.com/files/268231152/hw32v601.exe
Let us first get set up and ready to crack. I like to open the folder with my target in it. In this case c:\program files\@stake\ and make a quick backup that we can work on without fear of screwing up the file. I named mine lc52.exe and I will refer to it as such through the tutorial.
We will begin again by opening LC52.exe in PEID to see if it is packed or protected. The result: Microsoft Visual C++ 7.0. Good, we will not have to worry about unpacking this file before reversing it.
Note: I used three seperate computers to create this tutorial. This is why my serial changes halway through. It is also why my Addresses in Olly change. If your Addresses in Olly do not match mine, it is not a problem. The code will be the same.
Body:
Knowing that we will not need to unpack the executable lets us do a little examination of the protection scheme. Open up LC52.exe. It goes directly into the nag screen. From the previous tutorial we know that it is checking for a registration key. Press Register and we are presented with a new window holding a unique serial number and a box asking for our unlock code. Enter anything in as the unlock code and press Okay. We get a message box saying "You have entered an invalid code. Please try again.". Remeber to write this message down as we will be searching for it later. Press Okay and the program returns to the window asking for our unlock code.
Searching For A Serial:
Rather than try and patch the registration of this target, we are going to try and find a valid serial number. Close LC52.exe and open Ollydbg. In Olly, go to File, and open LC52.exe. It will take a second as Olly analyzes the code. We are going to start by looking for the string from the error message we recieved. To do this, right click on the code window and go to Search For, select All Referenced Text Strings.
[img]http://i562.photobucket.com/albums/ss64/themetalisme/Ollytut1.gif[/img]
A new window will open up with all the referenced strings in the executable. Scroll to the top of the page and select the first string. Right click and choose Search For Text. In the dialog box enter "you have entered" without the quotes. Make sure Case Sensitive in unchecked. You should end up here.
[img]http://i562.photobucket.com/albums/ss64/themetalisme/Ollytut22.gif[/img]
Double click the selected line and you will be taken to this code in the program:
[img]http://i562.photobucket.com/albums/ss64/themetalisme/Ollytut11.gif[/img]
Scroll up a little and we can see that there are three different versions of the program you can register as. Basic, Professional, and Administrator. We see that there is a TEST EAX, EAX before each registration confirmation. The program first tests if you entered the Basic unlock code, then if you entered the Professional unlock code and, finally if you entered the Administrator code. We are going to try and register the Administrator version. Scroll back down until your Screen matches what is shown above. If we look closely we can see where the test is made to call the messagebox. 0041082A . 85C0 TEST EAX,EAX followed by a push and then a Jump if Not Zero, JNZ 4108B2. 004108B2 is where our invalid message is created. Let's find out what is going on when the test is made. Select 0041082A . 85C0 TEST EAX,EAX and press F2. This will set a breakpoint on the test. Press the Run button. The LC5 nag screen pops up, press the Register button. In the window asking for our unlock code enter any serial. Let's try 1234567890. Press Okay. Olly breaks on our TEST EAX, EAX. First thing you notice is the registers on the right hand side. There are a string of numbers and letters in ECX and EDX that look suspiciously like an unlock code.
[img]http://i562.photobucket.com/albums/ss64/themetalisme/Ollytut4.gif[/img]
Was it that easy? Well, try them and find out. Open the original LC5.exe and use the numbers to try and register. This is new, a license agreement opens up. After pressing Okay on the License Agreement, we are presented with the message that we have successfully registered the Administrator version of LC5.
It was that easy!
So, are we done?
No!
Before we continue, return the program to the state of unregistered. Go the the START MENU in Windows and select the RUN command. Type in REGEDIT and press Okay. In REGEDIT's left window, click on the [+] in front of HKEY_CURRENT_USER. Then click on the [+] in front of SOFTWARE. Click on the [+] in front of @STAKE and then the [+] in front of LC5. Select the Registration folder. In the right hand window you will see Unlock Code. Double click it, and erase the Value Data in the new window. Press Okay and close REGEDIT.
Creating An Internal Keygen:
Because the unlock code for this program is computed based on the unique serial of our computer, anyone who wants to register would have to find the unlock code for themselves. We are going to solve that problem by using the program as a personal keygen. This is not often considered good reversing because you do not understand how the key is generated. However, as a beginner it can be an valuable learning experience.
Before we begin let's evaluate what we need to do to create an internal keygen.
1. We need to find where the unlock code is created and stored in memory
2. We need to find someway to display the unlock code to the user
3. We need to let the user know that they are seeing the unlock code
We already know where to find the unlock code so we need to solve how to display the code. A good idea would be, rather than displaying an error message, we display the unlock code. Let's reexamine the code where we see the test and where we see the "You have entered an invalid..." string pushed for the message box.
[img]http://i562.photobucket.com/albums/ss64/themetalisme/Ollytut5.gif[/img]
What we want to do is edit the code. Instead of pushing the error message onto the stack we can push our unlock code. There are a few things to consider when editing code. We need to make sure that what we change is not vital to the program's function. We are also restrained by how many bytes we can use to write new code. We can only overwrite current code. We cannot add our own. (There are ways to add your own code but it is more advanced than this tutorial, search for "code caves" if interested ) The other thing we need to consider is the stack. The stack is a designated part of memory where you can save values and instructions to. The stack is true to it's name, values are stacked onto it as you would stack boxes. The first one on is at the bottom and the last one is on the top. Instructions are then removed from the stack in the order of top to bottom. Last one on is the first one off.
[img]http://i562.photobucket.com/albums/ss64/themetalisme/Ollytut6.gif[/img]
You can view the stack in Ollydbg at the bottom right of the window. When modifying code we must make sure that nothing extra gets added or removed from the stack. Otherwise our program will cease to function.
Now that we know what we need to consider, let's move onto how to implement the unlock code into the messagebox. We know where the error message is pushed onto the stack so let's start by changing the code to push our code instead. We can see our code in both the ECX and EDX registers. However before we get to the PUSH, EAX is zeroed out and our code is overwritten in memory. So let's address that issue first. We only need our code in one register so we can keep XOR EAX, EAX. To stop our code from being overwritten we need to change MOV DWORD PTR SS:[ESP+14],ECX, MOV DWORD PTR SS:[ESP+1C],ECX and, MOV BYTE PTR SS:[ESP+24],CL. Select the first one with your mouse and right click. Choose Assemble from the menu. This will bring up a box where you can edit the code.
[img]http://i562.photobucket.com/albums/ss64/themetalisme/Ollytut7.gif[/img]
We want to remove this code alltogether, so in the box type NOP and make sure that the Fill With NOP's is selected. NOP stands for No Operation and is written in hex as 90. When the program runs it will just pass over these bytes. Press the Assemble button and your code is edited with NOP's. Do the same for the other two lines that overwrite our unlock code. It should end up looking like this:
[img]http://i562.photobucket.com/albums/ss64/themetalisme/Ollytut8.gif[/img]
All the tools you will need can be found online:
pm to give you the link or just download it here
http://#.com/files/268231152/hw32v601.exe
Let us first get set up and ready to crack. I like to open the folder with my target in it. In this case c:\program files\@stake\ and make a quick backup that we can work on without fear of screwing up the file. I named mine lc52.exe and I will refer to it as such through the tutorial.
We will begin again by opening LC52.exe in PEID to see if it is packed or protected. The result: Microsoft Visual C++ 7.0. Good, we will not have to worry about unpacking this file before reversing it.
Note: I used three seperate computers to create this tutorial. This is why my serial changes halway through. It is also why my Addresses in Olly change. If your Addresses in Olly do not match mine, it is not a problem. The code will be the same.
Body:
Knowing that we will not need to unpack the executable lets us do a little examination of the protection scheme. Open up LC52.exe. It goes directly into the nag screen. From the previous tutorial we know that it is checking for a registration key. Press Register and we are presented with a new window holding a unique serial number and a box asking for our unlock code. Enter anything in as the unlock code and press Okay. We get a message box saying "You have entered an invalid code. Please try again.". Remeber to write this message down as we will be searching for it later. Press Okay and the program returns to the window asking for our unlock code.
Searching For A Serial:
Rather than try and patch the registration of this target, we are going to try and find a valid serial number. Close LC52.exe and open Ollydbg. In Olly, go to File, and open LC52.exe. It will take a second as Olly analyzes the code. We are going to start by looking for the string from the error message we recieved. To do this, right click on the code window and go to Search For, select All Referenced Text Strings.
[img]http://i562.photobucket.com/albums/ss64/themetalisme/Ollytut1.gif[/img]
A new window will open up with all the referenced strings in the executable. Scroll to the top of the page and select the first string. Right click and choose Search For Text. In the dialog box enter "you have entered" without the quotes. Make sure Case Sensitive in unchecked. You should end up here.
[img]http://i562.photobucket.com/albums/ss64/themetalisme/Ollytut22.gif[/img]
Double click the selected line and you will be taken to this code in the program:
[img]http://i562.photobucket.com/albums/ss64/themetalisme/Ollytut11.gif[/img]
Scroll up a little and we can see that there are three different versions of the program you can register as. Basic, Professional, and Administrator. We see that there is a TEST EAX, EAX before each registration confirmation. The program first tests if you entered the Basic unlock code, then if you entered the Professional unlock code and, finally if you entered the Administrator code. We are going to try and register the Administrator version. Scroll back down until your Screen matches what is shown above. If we look closely we can see where the test is made to call the messagebox. 0041082A . 85C0 TEST EAX,EAX followed by a push and then a Jump if Not Zero, JNZ 4108B2. 004108B2 is where our invalid message is created. Let's find out what is going on when the test is made. Select 0041082A . 85C0 TEST EAX,EAX and press F2. This will set a breakpoint on the test. Press the Run button. The LC5 nag screen pops up, press the Register button. In the window asking for our unlock code enter any serial. Let's try 1234567890. Press Okay. Olly breaks on our TEST EAX, EAX. First thing you notice is the registers on the right hand side. There are a string of numbers and letters in ECX and EDX that look suspiciously like an unlock code.
[img]http://i562.photobucket.com/albums/ss64/themetalisme/Ollytut4.gif[/img]
Was it that easy? Well, try them and find out. Open the original LC5.exe and use the numbers to try and register. This is new, a license agreement opens up. After pressing Okay on the License Agreement, we are presented with the message that we have successfully registered the Administrator version of LC5.
It was that easy!
So, are we done?
No!
Before we continue, return the program to the state of unregistered. Go the the START MENU in Windows and select the RUN command. Type in REGEDIT and press Okay. In REGEDIT's left window, click on the [+] in front of HKEY_CURRENT_USER. Then click on the [+] in front of SOFTWARE. Click on the [+] in front of @STAKE and then the [+] in front of LC5. Select the Registration folder. In the right hand window you will see Unlock Code. Double click it, and erase the Value Data in the new window. Press Okay and close REGEDIT.
Creating An Internal Keygen:
Because the unlock code for this program is computed based on the unique serial of our computer, anyone who wants to register would have to find the unlock code for themselves. We are going to solve that problem by using the program as a personal keygen. This is not often considered good reversing because you do not understand how the key is generated. However, as a beginner it can be an valuable learning experience.
Before we begin let's evaluate what we need to do to create an internal keygen.
1. We need to find where the unlock code is created and stored in memory
2. We need to find someway to display the unlock code to the user
3. We need to let the user know that they are seeing the unlock code
We already know where to find the unlock code so we need to solve how to display the code. A good idea would be, rather than displaying an error message, we display the unlock code. Let's reexamine the code where we see the test and where we see the "You have entered an invalid..." string pushed for the message box.
[img]http://i562.photobucket.com/albums/ss64/themetalisme/Ollytut5.gif[/img]
What we want to do is edit the code. Instead of pushing the error message onto the stack we can push our unlock code. There are a few things to consider when editing code. We need to make sure that what we change is not vital to the program's function. We are also restrained by how many bytes we can use to write new code. We can only overwrite current code. We cannot add our own. (There are ways to add your own code but it is more advanced than this tutorial, search for "code caves" if interested ) The other thing we need to consider is the stack. The stack is a designated part of memory where you can save values and instructions to. The stack is true to it's name, values are stacked onto it as you would stack boxes. The first one on is at the bottom and the last one is on the top. Instructions are then removed from the stack in the order of top to bottom. Last one on is the first one off.
[img]http://i562.photobucket.com/albums/ss64/themetalisme/Ollytut6.gif[/img]
You can view the stack in Ollydbg at the bottom right of the window. When modifying code we must make sure that nothing extra gets added or removed from the stack. Otherwise our program will cease to function.
Now that we know what we need to consider, let's move onto how to implement the unlock code into the messagebox. We know where the error message is pushed onto the stack so let's start by changing the code to push our code instead. We can see our code in both the ECX and EDX registers. However before we get to the PUSH, EAX is zeroed out and our code is overwritten in memory. So let's address that issue first. We only need our code in one register so we can keep XOR EAX, EAX. To stop our code from being overwritten we need to change MOV DWORD PTR SS:[ESP+14],ECX, MOV DWORD PTR SS:[ESP+1C],ECX and, MOV BYTE PTR SS:[ESP+24],CL. Select the first one with your mouse and right click. Choose Assemble from the menu. This will bring up a box where you can edit the code.
[img]http://i562.photobucket.com/albums/ss64/themetalisme/Ollytut7.gif[/img]
We want to remove this code alltogether, so in the box type NOP and make sure that the Fill With NOP's is selected. NOP stands for No Operation and is written in hex as 90. When the program runs it will just pass over these bytes. Press the Assemble button and your code is edited with NOP's. Do the same for the other two lines that overwrite our unlock code. It should end up looking like this:
[img]http://i562.photobucket.com/albums/ss64/themetalisme/Ollytut8.gif[/img]
