当前位置:网站首页>(16) [system call] track system call (3 rings)
(16) [system call] track system call (3 rings)
2022-07-25 05:45:00 【One orange per bite】
WriteProcessMemory
open IDA,ALT + T The search function WriteProcessMemory(x,x,x,x,x), Enter the body of the function
You can clearly see that there are three functions
NtProtectVirtualMemory(x,x,x,x,x)
NtWriteVirtualMemory(x,x,x,x,x)
NtFlushInstructionCache(x,x,x)
Enter the import table to view the second function ( In fact, all three functions will end up with similar results , But I can only find the third one Zw At the beginning , No, Nt At the beginning )
stay ntdll.dll in
NtWriteVirtualMemory
Search to see NtWriteVirtualMemory function , It's simple , Only four lines
; NtProtectVirtualMemory
mov eax, 115h ; Service number
mov edx, 7FFE0300h ; Point to A function pointer
call dword ptr [edx]
retn 14h
Here are two strange things , One is Service number , The other is that 0x7FFE0300
Service number : A number , Indicates which service to call ( function ), We'll learn more about
0x7FFE0300

- Casually enter a process space
- Find the address you just saw , Get the value in this address
uInstruction query function
Mainly look at the following two functions
ntdll!KiFastSystemCall:
7c92e4f0 8bd4 mov edx,esp // preservation esp
7c92e4f2 0f34 sysenter // Quick call
ntdll!KiIntSystemCall:
7c92e500 8d542408 lea edx,[esp+8] // preservation esp
7c92e504 cd2e int 2Eh // Break the door
7c92e506 c3 ret
So how to distinguish whether the system has fast calls ? Use cpuid Instructions (eax = 1) The query ,eax Parameters are stored in , The result information will be saved to ecx and edx In the register , among edx contain SEP position ( The first 11 position ), Indicate the present CPU Whether quick call is supported 
dl register = 0xFF = 0B1111 1111, So it supports fast invocation
ok , The result was really disappointing , You can't see how this function is executed , The depth is not enough now
But this knowledge is enough for us to make some small things
Call system functions manually
#include <windows.h>
__declspec(naked) // Master the whole function by yourself , It's not easy to write half by yourself while others write half
void MyWriteProcessMemory(
HANDLE hProcess,
LPVOID lpBaseAddress,
LPVOID lpBuffer,
DWORD nSize,
LPDWORD lpNumberOfBytesWritten
){
_asm{
push ebp
mov ebp, esp
sub esp, 0x10 // Raise the stack a little , It's OK not to improve
push [lpNumberOfBytesWritten]
push [nSize]
push [lpBuffer]
push [lpBaseAddress]
push [hProcess] // Push the 5 Parameters
push 0 //push eip It was a call Of , Just align here
// system call , Just copy
mov eax, 0x115
mov edx, 0x7FFE0300
call dword ptr[edx]
// add esp, 0x04 //pop eip
// add esp, 0x10 // No stack checking , Omit this one and just quit
mov esp, ebp
pop ebp // Remember to balance back
retn 0x14 // The outside is pressed 5 Parameters
}
}
int main(){
DWORD val = 0x12345678;
DWORD write_val = 0x11112222;
// Get your own process PID
DWORD curPID = GetCurrentProcessId();
// The following function uses this
HANDLE dst_hdl = OpenProcess(PROCESS_ALL_ACCESS, FALSE, curPID);
// Self realized WriteProcessMemory
//WriteProcessMemory(dst_hdl, &val, &write_val, sizeof(val), NULL);// Try it first
MyWriteProcessMemory(dst_hdl, &val, &write_val, sizeof(val), NULL);
// The effect of the two functions is the same
printf("%X", val);
getchar();
return 0;
}
// Print the results :11112222
Successful experiment
prevent : Don't let others hook Find a breakthrough in your own function or breakpoint
Attack : Bypass others hook Check
边栏推荐
- Application of hard coding and streaming integration scheme based on spice protocol in cloud games
- 10、渲染基础
- Summary of common attributes of flex layout
- Big talk · book sharing | Haas Internet of things device cloud integrated development framework
- G1 garbage collector
- C100: smallest hevc visual IOT MCU
- LCP plug-in creates peer-to-peer 802.1ad interface
- Bug --- redis deserialization failed
- The computer accesses the Internet normally with the same network cable, and the mobile phone connects to WiFi successfully, but it cannot access the Internet
- PHP warehouse inventory management system source code WMS source code
猜你喜欢

Arm PWN basic tutorial

Talk about how redis handles requests

C编程 --“最大子数组的和” 的动态规划的解法

Realsense d435i depth map optimization_ High precision mode

QT qtextedit setting qscrollbar style sheet does not take effect solution

Basset: learning the regulatory code of the accessible genome with deep convolutional neural network

Unity接入ChartAndGraph图表插件

CCID released the "Lake warehouse integrated technology research report", and Jushan database was selected as a typical representative of domestic enterprises

Programming hodgepodge (I)

Odoo14 | about the abnormal display of statusbar keyword after use and Its Solutions
随机推荐
Vim配置Golang开发环境
LCP plug-in creates peer-to-peer 802.1ad interface
Concepts of phase velocity and phase in transmission line theory
(2022牛客多校二)L-Link with Level Editor I(动态规划)
LCP plug-in creates peer VLAN interface
Unity accesses chartandgraph chart plug-in
How to start if you want to be a product manager?
50:第五章:开发admin管理服务:3:开发【查询admin用户名是否已存在,接口】;(这个接口需要登录时才能调用;所以我们编写了拦截器,让其拦截请求,判断用户是否是登录状态;)
HTB-Optimum
Continuous maximum sum and judgement palindrome
The computer accesses the Internet normally with the same network cable, and the mobile phone connects to WiFi successfully, but it cannot access the Internet
Flexible layout summary
(2022牛客多校二)K-Link with Bracket Sequence I(动态规划)
flex布局常用属性总结
sqlilabs less-28~less-8a
基于ISO13209(OTX)实现EOL下线序列
Summer summary 2
sqlilabs less-29
Unity接入ChartAndGraph图表插件
AirServer 7.3.0中文版手机设备无线传送电脑屏幕工具