139-Article Text-205-1-10-20230405
139-Article Text-205-1-10-20230405
Abstract:
The major goal of this study is to provide anti-debugging and anti-reversing strategies/techniques
employed by executables, DLLs, and packers/protectors, as well as to examine strategies that can be
utilized to bypass or disable these protections. Anti-debugging techniques are designed to make sure
that a program is not being executed inside a debugger. In most cases, the anti-debugging process
slows down the reverse engineering [1] process but doesn't stop it. This information will allow
malware analysts and researchers to identify the techniques used by the malware. This information
may also be used by security researchers, reverse engineers those want to slow down the process of
reverse engineering in order to add security [2] to their software. It causes some difficulties for a
reverse engineer, but, of course, nothing stops a skilled, knowledgeable, and committed reverse
engineer.
Keywords: malware analysis, anti-debugging, anti-reversing, protectors, packers
control systems (ICS)[5]. In addition, In many manually. The fs segment register can access
situations, knowing how to apply anti-debug- the Process Environment Block (PEB) at fs:
ging techniques to malicious code to prevent it [30]. On an x86 [8] computer, this register
from being tracked down and evaluated is also corresponds to a Thread Information Block
helpful. One of the main tools used by malware (TIB).There is also a flag below the Process
analysts and reverse engineers is the debugger. Environment Block (PEB) that indicates
What is a debugger? A debugger is software whether the first memory space of the process
that is used to evaluate and control the flow of was created in debug mode. Provide an offset
execution of other executables or software. By of 0x18 in the Process Environment Bloc
using a debugger, we can execute each instruc- (PEB). So, here I break down the anti-debug-
tion step by step and can note down the chang- ging techniques into two categories: static
es that can be displayed on the stack, memory anti-debugging and dynamic anti-debugging
dumps, registers, etc. Most packers use these [9], as seen in the Table 1 below.
techniques to determine whether the system is
running a debugger or if a process is being Table 1. Static Vs Dynamic Techniques
debugged. These debugger detection meth- Difference
ods[6] include checks that are relatively basic Static Dynamic
all the way up to ones that are applicable to
Difficulty Easy, Medium Hard
native Application Programming Interfaces Level
(APIs) and kernel objects[7].This section Use System Reverse and exploit
discusses how anti-debugging techniques Main Idea Debugger
Info
work. Each process's user space contains a data Detect Hide its own code
Target
structure called a Process Environment Block Debugger and data
(PEB), which holds information about the Time Point When While debugger is
debugging start running
related process. Each process's user space
contains a data structure called a Process Defend API Hook, API hook, Debugger
Method(s) debugger plugin Plugin
Environment Block (PEB), which holds infor-
Breakpoints (INT3),
mation about the related process. It is intended Example(s) PEB, TEB, TLS
TimingCheck
to access Windows API (WinAPI)It is intended
to access Windows API (WinAPI) but access is In our research we will discuss we will discuss
not restricted by this. Process Environment some of the main anti-debugging techniques
Block (PEB) can be accessed directly from and how a reverse engineer can be able to
memory. Checking the value of the Process identify them easily for example in this paper
Environment Block (PEB) structure that has we will discuss about the IsDebuggerPresent,
been debugged is a relatively straightforward TimeChecks, NtQueryInformationProcess,
implementation and technique. As we know NtSetInformationThread, SwitchDesktops,
that there are so many Applications Program- SeDebugPrivilege, ParentProcess, Debugger-
mable Interfaces (APIs) which are documented Window, DeviceDrivers etc.
and undocumented. For example, IsDebugger-
Present, which we will discuss later in this Anti-Debugging Techniques Mechanism:
paper. To enhance, we can also check the APIs Anti-debugging[10] is the implementation of
C/C++ Code:
As we can see in the example if IsDebugger-
Present() in Figure 2.
ProcessInformation class is set to as to hide threads from the debugger. It can also be
ProcessDebugPort as we can see C/C++ code done with the help of a non-documented value,
in the Figure 4. which is not documented but can be used.
THREAD_INFORMATION_CLASS::Threa-
dHideFromDebugger (0x11). When a thread is
hidden in the debugger, it will not be informed
of anything pertaining to that thread not be
informed of anything pertaining to that thread.
Figure 4. C/C++ Code for NtQueryInfor- The thread is also capable of anti-debugging
mationProcess() methods, such as examining debug flags, code
checksums, etc. If there are hidden breakpoints
This example shows how the call to the Check- in the thread, If we try to keep the main thread
RemoteDebuggerPresent() and To see whether hidden from the debugger, either the process
the current process is being debugged, utilize will crash or the debugger will gets stuck. An
the NtQueryInformationProcess function. as example of calling the NtSetInformation-
we can see in Figure 5 and Figure 6. Thread would be like this, as we can see in
Figure 7.
C/C++ Code:
As we can see, C/C++ code in Figure 8.
C/C++ Code:
As we can see the C/C++ code in the Figure 10.
Mitigations:
• During Debugging, just fill time checks
with NOPs and set the result of these
checks to the appropriate value.
2. The target is being debugged if the Sometimes these methods also use Kernel32
Process ID (PID) of the parent process ReadProcessMemory() to read process
differs from the Process ID (PID) of the memory and then look for debugger-related
explorer.exe. strings such as "x64dbg", "IDA", "OllyDBG",
etc. to reverse engineer the debugger. to imple-
Solution: ment. After getting the debugger. The malware
We need to patch the element of will stop his execution and silently exit or
Kernel32!Process32NextW() that contains the terminates the process.
code that performs a return after setting the
value of EAX to 0. Solution:
Another solution is to check the main process,
8. Debugger Window: including patching the kernel 32 patch!
Process32NextW() always fails and prevents
The presence of the debug window is a flag the developer from enumerating the process.
that the debugger is running system[13].
Because the debugger creates windows with 10. Device Drivers
special class names (OllyDBG for OLLYDBG
and WinDbgFrameClass for WinDbg), user32 An old technique is to verify that the debugger
can easily identify these debug windows! is running in a Kernel Mode in the system and
FindWindow`() or User32! findWindowEx(). try to, access device drivers. This technique is
very simple and consists of simply making a
call to the against well-known device names
Process Memory:
A process can check or interact with its own
memory for the presence of a debugger. This
section includes anti-hitch methods[15] such
as process memory and thread context check-
ing, breakpoint DETECTION, PATCHING function
and debugging functions.
To verify if our code has any software break- Figure 14. C/C++ code of Software Break-
points, we may still inspect the process point Detection
memory, and we can also check the CPU
debug registers to see if any hardware break- Solution:
points have been set. Hardware breakpoints can be reverse
engineered if software breakpoints are identi-
12. Software Breakpoints fied. If you need to set a breakpoint in the API
Detection: code, and when the packer tries to find a break-
point in the API code, reverse engineering the
Software breakpoints are defined as break- UNICODE API version allows for the setting
points that are created by altering the code at of breakpoints. That eventually calls the ANSI
the target location and replacing it with the version, such as LoadLibraryExW LoadLibrar-
C/C++ Code:
As we can see the C/C++ code in the Figure
Figure 15 C/C++ code of Hardware 17.
Breakpoints
The memory page of the process in which the Figure 17 C/C++ Code for Hardware
code is located is shared by all processes prior Breakpoints
to the page being written. Then the OS creates
a replica of this page and allocates it to the 16. Detecting A function Patch:
process's virtual memory[19], so the page is no
longer "shared". Now we can see how to Calling kernel32 is a common approach to find
declare NTDLL, as we can see in figure 16. a debugger. IsDebuggerPresent(). By altering
the outcome in the EAX register or hacking the
NTDLL declarations: kernel32, you may easily get around this
check! IsDebuggerPresent(). Instead of
looking for breakpoints in the process memory, Of course, as with all malware analysis, the
we can check to see if kernel32IsDebuggerPre- best way to learn how to stop it by using
sent() has been altered[20].The first few bytes debugging techniques by continuously testing
of this function can be read and compared to malware. Malware developers are constantly
the same function's bytes from other processes. coming up with new techniques to evade
Windows libraries are loaded at the same base debuggers and keep security researchers like
address throughout the process, even if the you on their toes.
Address Space Layout Randomization (ASLR)
feature is enabled. The base address only 17. References:
changes across reboots but remains the same
for the duration of the session. [1] V. Bhardwaj, V. Kukreja, C. Sharma, I.
Kansal, and R. Popali, “Reverse
Mitigations: Engineering-A Method for Analyzing
• During Debugging: Enter the function Malicious Code Behavior,” in 2021
that conducts the Step-Over check and International Conference on Advances
run it till the end(Ctrl + F9). in Computing, Communication, and
Control (ICAC3), Dec. 2021, pp. 1–5.
• Finding the specific check and either doi: 10.1109/ICAC353642.2021.
path it with NOPs or setting the return to 9697150.
a value that permits the application to
keep running are the best ways to [2] M. N. Gagnon, S. Taylor, and A. K.
mitigate all "memory" techniques, Ghosh, “Software Protection through
including anti-step over. Anti-Debugging,” IEEE Security &
Privacy Magazine, vol. 5, no. 3, pp.
Conclusion: 82–84, May 2007, doi: 10.1109/M-
To defend itself against reverse engineering SP.2007.71.
analysis, the malware employs anti-debugging
techniques. Debug analysis can be avoided by [3] J.-W. Kim, J. Bang, Y.-S. Moon, and
anti-debugging techniques. Reverse engineers M.-J. Choi, “Disabling Anti-Debugging
need advanced debuggers and knowledge to Techniques for Unpacking System in
analyze malware using anti-debugging User-level Debugger,” in 2019 Interna-
techniques. By applying common sense and tional Conference on Information and
slowly debugging the process, it is possible to Communication Technology Conver-
identify the majority of anti-debugging gence (ICTC), Oct. 2019, pp. 954–959.
techniques. For example, if you see that the doi: 10.1109/ICTC46691.2019.
code is terminating too rapidly in a conditional 8939719.
jump, which could mean preventing debugging
[4] T. Akhtar, B. B. Gupta, and S. Yamagu-
technical. The most widely used anti-debug-
chi, “Malware propagation effects on
ging methods involve fs access: [30h] by using
SCADA system and smart power grid,”
a Windows API or performing a time check.
in 2018 IEEE International Conference
on Consumer Electronics (ICCE), Jan.
2018, pp. 1–6. doi: 10.1109/ICCE.2018. (APCC), Oct. 2012, pp. 765–769. doi:
8326281. 10.1109/APCC.2012.6388211.