当前位置:网站首页>Anti debugging (basic principles of debugger Design & NT NP and other anti debugging principles)
Anti debugging (basic principles of debugger Design & NT NP and other anti debugging principles)
2022-07-05 03:33:00 【#A#】
Add application level anti debugging function to the game ( No write drive ), Make it resistant to general debugging tools , such as OllyDbg、CE、x96dbg wait ..、
The level of de debugging :
- Prohibit or destroy the debugging function
- Detection of debugging status
The basic principle of software debugger design :
BOOL DebugByCreate;//TRUE Debug new process FALSE Create a process and debug
DWORD dwPID; // Of the debugged process ID
DEBUG_EVENT dbgevent;
if (!DebugByCreate)
{
CreateProcess(..., DEBUG_PROCESS, ...);
}
else {
DebugActiveProcess(dwPID);// Debug the existing process
}
while (WaitForDebugEvent(&dbgevent, INFINITE) == TRUE)
{
switch (dbgevent.dwDebugEventCode)
{
// Handle debugging events
}
ContinueDebugEvent(...);
}
CreateProcess Create the underlying implementation of the debugged process
BOOL
WINAPI
CreateProcessA(
_In_opt_ LPCSTR lpApplicationName,
_Inout_opt_ LPSTR lpCommandLine,
_In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes,
_In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,
_In_ BOOL bInheritHandles,
_In_ DWORD dwCreationFlags, // Process creation flag bit
_In_opt_ LPVOID lpEnvironment,
_In_opt_ LPCSTR lpCurrentDirectory,
_In_ LPSTARTUPINFOA lpStartupInfo,
_Out_ LPPROCESS_INFORMATION lpProcessInformation
);
dwCreationFlags Value :
DEBUG_PROCESS 0x1 [ Debug the process and its child processes ]
DEBUG_ONLY_THIS_PROCESS 0x2 [ Only debug this process ]
Bottom call :
[1] DbgUiConnectToDbg();// The debugger process establishes a connection with the debugging subsystem
establish DEBUG_OBJECT Kernel object
preservation DEBUG_OBJECT Data to thread environment DbgSsReserved[1]
[2] NtCreateProcess() / NtCreateProcessEx()
take DbgSsReserved[1] Pass to the kernel process manager
PsCreateProcess take DbgSsReserved Data transfer to EPROCESS Structural DebugPort Field
PsCreateProcess call MmCeatePeb Create a process PEB data
MmCreatePeb The function will DebugPort Not empty adjustment PEB Of BeingDebugged Field is 1
DebugActiveProcess Debug the underlying call of the process :
[1]DbgUiconnectToDbg(); // The debugger process establishes a connection with the debugging subsystem
[2]ProcessIdToHandle(); // Get process handle Internal calls OpenProcess->NtOpenProcess
[3]DbgUiDebugActiveProcess();// Set the debugging state of the process
>>NtDebugActiveProccess(); // Get according to the specified process handle EPROCESS structure
>>DbgkpSetProcessDebugObject Attach debug objects to EPROCESS Of DebugPort
>>DbgfkpMarkProcessPeb To set the debug process PEB->BeingDebuggged
Conclusion : A process is debugged , In kernel state EPROCESS Structural DebugPort It must not be for 0
In user mode PEB Structural BeingDebuged It must not be for 0
TP NP Wait for the principle of anti debugging drive :
The basic working state of a debugger is CreateProcess Create and DebugActiveProcess additional Two structures
CreateProcess:
You must call several functions under the kernel , When the application layer reaches the kernel . The most typical takeover is HOOK, You can also use the callback function now Windows The change of ,HOOK It's not a good way anymore , Basically, the callback function is used , It's easy to see with callback function PsCreateProcess The situation of , You can see who the created path is , Found to be xxx Go straight back to failure Even the process can't run , Let alone build and debug .
Generally speaking There are few processes to create . More is to add to debug .
about DebugActiveProcess :
In the second step , OpenProcess->NtOpenProcess When To take over NtProcess It's easy to see who the debugging target is If it is xx Direct to failure You can't run directly , The back can also be destroyed , The more damage , The more places to recover , The more difficult it is to attack
For both methods, we should DebugPort Attach to debug object Maybe DebugPort Zero clearing Delete here It's equivalent to the port being killed The information about establishing channels is recorded in a place , Removing this will destroy the channel
In addition to opening the process , Also read and write processes , Dispose of all these places , And that's what happened
边栏推荐
- How to define a unified response object gracefully
- Bumblebee: build, deliver, and run ebpf programs smoothly like silk
- FBO and RBO disappeared in webgpu
- 2021 Li Hongyi machine learning (2): pytorch
- [groovy] groovy environment setup (download groovy | install groovy | configure groovy environment variables)
- Flex flexible layout
- Basic knowledge of tuples
- Breaking the information cocoon - my method of actively obtaining information - 3
- Leetcode42. connect rainwater
- 1.五层网络模型
猜你喜欢
Jd.com 2: how to prevent oversold in the deduction process of commodity inventory?
[groovy] string (string type variable definition | character type variable definition)
Learning notes of raspberry pie 4B - IO communication (I2C)
Ubantu disk expansion (VMware)
[groovy] string (string injection function | asBoolean | execute | minus)
How to define a unified response object gracefully
Use of kubesphere configuration set (configmap)
Redis6-01nosql database
Flume configuration 4 - customize mysqlsource
Accuracy problem and solution of BigDecimal
随机推荐
001 chip test
Use UDP to send a JPEG image, and UPD will convert it into the mat format of OpenCV after receiving it
[安洵杯 2019]不是文件上传
Share the newly released web application development framework based on blazor Technology
Binary heap implementation (priority queue implementation)
Three line by line explanations of the source code of anchor free series network yolox (a total of ten articles, which are guaranteed to be explained line by line. After reading it, you can change the
The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
Anchor free series network yolox source code line by line explanation Part 2 (a total of 10, ensure to explain line by line, after reading, you can change the network at will, not just as a participan
Monitoring web performance with performance
Azkaban实战
Single box check box
2. Common request methods
Watch the online press conference of tdengine community heroes and listen to TD hero talk about the legend of developers
Sqoop installation
How can we truncate the float64 type to a specific precision- How can we truncate float64 type to a particular precision?
LeetCode 234. Palindrome linked list
有个疑问 flink sql cdc 的话可以设置并行度么, 并行度大于1会有顺序问题吧?
1. Five layer network model
Acwing game 58 [End]
Voice chip wt2003h4 B008 single chip to realize the quick design of intelligent doorbell scheme