[System Security] 23. OllyDbg dynamic debugging review of reverse analysis and TraceMe case analysis

You may have seen a similar article I wrote before, why do you have to repeat it? I just want to better help beginners understand virus reverse analysis and system security, and be more systematic without destroying the previous series. Therefore, I reopened this column to prepare systematically and in-depth study of system security, reverse analysis and malicious code detection. The "System Security" series of articles will be more focused, more systematic, and more in-depth. It is also the author's slow growth history. It is really difficult to change a major. Reverse analysis is also a hard part, but I also try to see how much I can learn from it in the next four years. Enjoy the process, come on together~

In the previous article, the author introduced the Microsoft certificate vulnerability CVE-2020-0601, and explained the ECC algorithm, the Windows verification mechanism, and the example of reproducing the executable file signature certificate. This article will explain in detail the basic usage of the OllyDbg dynamic debugging tool for reverse analysis, including interface introduction, commonly used shortcut keys and TraceMe case analysis. These basic knowledge are not only related to system security, but are also closely related to the commonly used software, documents, and operating systems around us. I hope this knowledge will help you, and I hope you all increase your security awareness and have a long way to go. This article refers to the articles in the B-site vulnerability bank, security website, and references (see References for details), and combines my own experience and practice to write this article. I would like to thank these big guys.

Starting in July 2019, I came to an unfamiliar profession-cyberspace security. It is very painful and uncomfortable to enter the security field for the first time. There are too many things to learn and the coverage is too wide, but fortunately, I am struggling to move forward by sharing 100 articles in the "Network Security Self-study" series. I am grateful to the security guys and friends who have met, acquainted, and enjoyed each other this year. If the writing is not good or insufficient, please Haihan!

Next, I will start a new security series called "System Security", which is also a free 100 articles. The author will study malicious sample analysis, reverse analysis, intranet penetration, actual network attack and defense, etc., and will also go online Sharing the form of notes and practical operation and learning with bloggers, I hope to make progress with you, come on~

Author's github resources:

Preamble analysis:

Statement: I firmly oppose the use of teaching methods to commit crimes. All crimes will be severely punished. We need to maintain the green network together. It is recommended that you understand the principles behind them and better protect them. The sample will not be shared with everyone, the analysis tool will be shared. (See the references below)


1. OllyDbg interface introduction and configuration

OllyDbg is a dynamic tracking tool that combines IDA and SoftICE. The Ring 3-level debugger is very easy to use and is one of the most popular debugging decryption tools today. It also supports plug-in extensions and is currently one of the most powerful debugging tools.

OD and IDA can be said to be "Yitian" and "Slaying Dragon" of reverse analysis, a dynamic analysis and a static analysis.

Insert picture description here

This series of articles refers to the video of the "Game Reverse Communication" vulnerabilities at station B. The main contents include:

  • OllyDbg interface introduction and configuration
  • Commonly used shortcut keys
  • OllyDbg basic operation
  • Analysis of common breakpoints INT 3 breakpoint principle
  • Anti-debugging and anti-anti-debugging of INT 3 breakpoints
  • Analysis of hardware breakpoint principle of common breakpoints
  • Analysis of memory breakpoint principle of common breakpoints
  • Analysis of the principle of message breakpoints for common breakpoints
  • Analysis of Conditional Breakpoint Principles of Commonly Used Breakpoints
  • Memory access one-time breakpoint and conditional record breakpoint
  • Plug-in
  • Run trace 和Hit trace
  • Debug symbol
  • Frequently Asked Questions of OllyDbg

Recommend everyone to study, refer to the website: https://www.bilibili.com/video/BV1cE411f7sE


OllyDbg is a commonly used debugging tool for reverse analysis. Open the main interface as shown in the figure below, including disassembly window, register window, information window, data window, and stack window.

  • Common dynamic debugging tools: OllyDbg, WinDbg, x64Dbg
  • Common static debugging tool: IDA

Insert picture description here

If the interface we open is messy like the picture below, you can click the shortcut key C at the top, and then maximize the main window to optimize the layout.

Insert picture description here

Insert picture description here

Then just open an EXE program, and it will display as shown in the figure below:

Insert picture description here


Let's first explain the meaning of each window:

  • Disassembly window: display the disassembly code of the debugged program, including address, HEX data, disassembly, comment
  • Register window: display the contents of the CPU register of the currently selected thread, click the label to switch the way of displaying the register
  • Information window: display the parameters of the first command selected in the disassembly window and the jump destination address, characters, etc.
  • Data window: display the contents of the memory or file, the right-click menu can switch the display mode
  • Stack window: display the stack of the current thread, record the passed parameters or local variables
  • Shortcut to child window

Insert picture description here

Then add the knowledge points of interface options, click "Options" -> "Interface" to set the UDD path and plug-in path.

Insert picture description here

The UDD path is used to save our debugging information.

Insert picture description here

The plugin path contains various plugins and can be used directly.

Insert picture description here

If you want to select an EXE file, right-click it to open it directly with OllyDbg, how to set it?

Insert picture description here

Click "Options" -> "Add to Browser" to add OllyDbg to the System Explorer menu.

Insert picture description here

If we prompt the administrator permission to run every time we run OD, then we can simply set the shortcut keys.

Insert picture description here

The setting method is as follows: In compatibility, select "Run this program as an administrator".

Insert picture description here



2. Commonly used shortcut keys

The following briefly explains the commonly used shortcut key debugging methods.

F2: Set breakpoint To
set a breakpoint, just press the F2 key at the position where the cursor is located, and press the F2 key again to delete the breakpoint. In the red position as shown in the figure below, the program will pause when it runs to this point.

Insert picture description here


F9: Run
Press F9 to run the program. If the corresponding breakpoint is not set, the debugged program will start running directly.

Insert picture description here


F8: Single step over
Single step over, each time you press this button, an instruction in the disassembly window will be executed, and the code will not be entered into subroutines such as CALL.

Insert picture description here


F7: Single step in
Single step in, the function is similar to single step over (F8), the difference is that when you encounter a subprogram such as CALL, it will enter it, and it will first stay on the first instruction of the subprogram after entering. Enter the CALL subroutine as shown in the figure below.

Insert picture description here

CALL means to enter the function, RETN means to return.

Insert picture description here


F4: Run to the selected position
Run to the selected position, the function is to run directly to the position where the cursor is and pause. For example, if the cursor is at 0x00401034, we then run from 0x00401027, which will jump directly to the cursor. When we encounter a loop during debugging, we can adjust the cursor to skip the loop.

Insert picture description here


CTRL+F9: Execute to return
Execute to return, press this key to pause when a return instruction is executed. It is often used to return from the system airspace to the program airspace that we are debugging. When debugging a program, pressing CTRL+F9 will run the program until a RETURN returns. For example, when we enter the subroutine shown in the figure below, it will run to RETN 10.

Insert picture description here

Then press F8 at the RETN 10 position, it will return to the position shown in the figure below, after executing the CALL function, enter the next sentence.

Insert picture description here


CTRL+F2: Restart
When the program wants to re-debug, just press CTRL+F2.

ALT+F9: Execute to user code
Execute to user code, quickly return from the system airspace to the airspace of the program we debugged.

Insert picture description here



3. OllyDbg dynamic blasting software demo

Let's take the "TraceMe.exe" program of "Encryption and Decryption" as an example. Program download address:

Insert picture description here

When we input the wrong user name and serial number, clicking the "Check" button will display the input error.

Insert picture description here

Next, we need to use OD to blast. The basic flow of the program is shown in the figure below. Only when the correct user name and serial number are entered can the correct dialog box be displayed.

Insert picture description here

Then open the program through OD, it will automatically locate the module entry point 0x004013A0 position. The author github resource provides various OD versions for readers to use.

Insert picture description here


The first step, first press F9, the program will run, and a dialog box will pop up

Insert picture description here


In the second step, we need to know what functions are used to input values ​​in the dialog box.
Click "API Breakpoint Setting Tool" -> "Common Breakpoint Setting".

Insert picture description here

Check the two functions "GetWindowTextA" and "GetDlgItemTextA" to get the input value of the dialog box, which means to set a breakpoint for these two functions, and it will stop when the program runs to a certain function. If the reader is not sure of the corresponding function, you can check all the functions.

Insert picture description here


The third step is to enter the user name and serial number and click the "Check" button.
At this point, the program enters the 0x75CA4390 position and displays the call to the GetDlgItemTextA function.

Insert picture description here

We first press F2 to remove the breakpoint, and then press F9 to execute the code, you can see the "Serial number error, do it again!" pop-up box. This proves that the breakpoint we just made is effective.

The four parameters of GetDlgItemTextA: dialog box handle, control identification (ID number), buffer pointer, maximum number of characters in the buffer, refer to the Win32.API manual.

Insert picture description here

Then we check the "GetDlgItemTextA" function, and then click the "Check" button, it will continue to locate the 0x75CA4390 position, as shown in the figure below.

Insert picture description here

Insert picture description here


The fourth step, then press Ctrl+F9 to execute to the return position.
The address 0x75CA43C1 is displayed at this time.

Insert picture description here


The fifth step, press F8 again to execute the return.
At this point, we see the location where the GetDlgItemTexeA function is executed. It will return the next line of code for the calling function. Note that it is the next line. Our program has two dialog box values, so there will be two calls to GetDlgItemTexeA function.

Insert picture description here

Then we continue to press F8 to go down, these two values ​​are obtained, the next step should be the process of calculating the sequence, and then we will judge whether it is correct.

Insert picture description here

Continue to go down to the 0x004011E4 position, we can see that the values ​​of EDX and EAX in the upper right corner are the "eastmount" and "123456" we entered. At the same time, the lower right corner shows that both values ​​have been pushed into the stack.

  • EAX:123456
  • EDX:eastmount

Insert picture description here


The sixth step is to access the TraceMe.00401340 function.
We can guess that the "call TraceMe.00401340" function called is for judgment, and add the following comments. But it may not be. When we perform software reverse analysis or blasting, we usually need to rely on logic ability and programming ability to speculate.

Insert picture description here

Press F7 to enter the program, position 0x00401340.

Insert picture description here

Press F8 again to execute, you can find that there is a loop here to determine whether the input value is consistent with its original value.

Insert picture description here

After the loop, continue to execute and you can see some judgment information of the serial number "123456".

Insert picture description here

Eventually it will return a value and put it in EAX, the value is equal to 0, and then continue to return to the value.

Insert picture description here

The return value is 0, and then continue to execute.

Insert picture description here


The seventh step, jump function analysis
If this function is a judgment function, then the following jump is likely to be the key jump. It is the jump that we need to modify, and use it to blast. Location: 0x004011F5

Insert picture description here

Increase the breakpoint, and then press F8 to continue running.

Insert picture description here

It was found that it jumped directly to 0x0040122E, and then prompted "Serial number error, do it again!".

Insert picture description here

Then press F9 to run, and an error dialog box pops up behind, so that it is determined that the above is a key jump.

Insert picture description here


The eighth step, press Ctrl+F2 to re-run the program and
then press F9 to execute the program, enter the content in the pop-up dialog box, and click "check".

Insert picture description here

Continue to press F9 to run the program and jump to the "key jump" position where we just hit the breakpoint.

Insert picture description here

The key step: modify the assembly code, JE is to achieve jump, modified to JNZ not to jump.

Insert picture description here

Continue to press F8 to execute, or directly press F9, you can prompt a dialog box of "Congratulations, success". This is the basic process of blasting.

Insert picture description here


The ninth step is to save the blasting software.
Select the modified lines, then right-click and click "Copy to Executable File".

Insert picture description here

Select the "TraceMe.exe" file and right-click to save the file, such as "TraceMe_PO2.exe".

Insert picture description here

After the save is successful, just enter the user name and serial number, and it will prompt success!

Insert picture description here

At the same time, the input length of the program has a judgment, we can also try to blast.

Insert picture description here

But what is the principle? We will continue to introduce it in subsequent articles.



Four. Summary

After writing this, the introduction of this article is over, I hope you like it~

  • OllyDbg interface introduction and configuration
  • Commonly used shortcut keys
  • OllyDbg dynamic blasting software demo

If there are some shortcomings in this article, please ask Haihan. The author is slowly growing up as a beginner in network security! I hope to write related articles more thoroughly in the future. At the same time, I am very grateful to the security experts in the references for sharing their articles, and thank the masters, brothers and sisters, and sisters and sisters for their teachings. I know that I am very good and have to work hard.

Welcome everyone to discuss, do you think this series of articles help you! Any suggestions can be commented to inform readers and encourage each other.

The newly opened "Nazhang AI Security Home" on August 18, 2020 will mainly focus on Python big data analysis, cyberspace security, artificial intelligence, Web penetration and offensive and defensive technology, and share CCF, SCI, South and North nuclear papers The algorithm implementation. Nazhang’s House will be more systematic and will reconstruct all the author’s articles, explain Python and security from scratch, and have written articles for nearly ten years. I really want to share what I have learned, what I have learned, and what I have done. I would also like to invite you to give me your advice and sincerely invite you. your attention! Thank you.

Insert picture description here

(By: Eastmount 2021-02-22 12 noon written in Wuhan http://blog.csdn.net/eastmount/ )


Reference materials:
[1] OllyDbg (OD) tutorial for dynamic debugging tools-B station yxfzedu
[2] [Reverse notes] OD tool usage-Reverse TraceMe.exe-17bdw notes
[3] "Encryption and Decryption" Duan Gang waiting
[4] "OllyDBG Introductory Course" Kanxue Academy-CCDebuger
[5] 160 Crackme006-Ghost Hand 56 Big Brother

Guess you like

Origin blog.csdn.net/Eastmount/article/details/113923604