当前位置:网站首页>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
边栏推荐
- Vb+access hotel service management system
- SQL performance optimization skills
- Talk about the SQL server version of DTM sub transaction barrier function
- 【做题打卡】集成每日5题分享(第三期)
- Azkaban概述
- SQL injection exercise -- sqli Labs
- Single box check box
- 有个疑问 flink sql cdc 的话可以设置并行度么, 并行度大于1会有顺序问题吧?
- Kubernetes - identity and authority authentication
- [groovy] groovy environment setup (download groovy | install groovy | configure groovy environment variables)
猜你喜欢
![[system security] ten thousand words summary system virtualization container bottom layer principle experiment](/img/c6/1bdb29a0acb0739f67b882fa6b3b47.jpg)
[system security] ten thousand words summary system virtualization container bottom layer principle experiment

Leetcode42. connect rainwater

The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety

Azkaban installation and deployment

Pat grade a 1119 pre- and post order traversals (30 points)

Apache Web page security optimization
![[groovy] string (string splicing | multi line string)](/img/c7/2471d13e5d49cca3727d05b4f9fb36.jpg)
[groovy] string (string splicing | multi line string)
![[安洵杯 2019]不是文件上传](/img/f1/736eb5fe51c299e3152ca87895ee99.png)
[安洵杯 2019]不是文件上传

Pdf things

为什么腾讯阿里等互联网大厂诞生的好产品越来越少?
随机推荐
040. (2.9) relieved
El select, El option drop-down selection box
The latest blind box mall, which has been repaired very popular these days, has complete open source operation source code
qrcode:将文本生成二维码
SQL performance optimization skills
The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
[安洵杯 2019]不是文件上传
Ask, does this ADB MySQL support sqlserver?
[groovy] groovy environment setup (download groovy | install groovy | configure groovy environment variables)
Port, domain name, protocol.
FBO and RBO disappeared in webgpu
Subversive cognition: what does SRE do?
Daily question 2 12
glibc strlen 实现方式分析
Dart series: collection of best practices
Jd.com 2: how to prevent oversold in the deduction process of commodity inventory?
Pat class a 1160 forever (class B 1104 forever)
端口,域名,协议。
Yyds dry goods inventory embedded matrix
2.常见的请求方法