当前位置:网站首页>(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
边栏推荐
- flex布局常用属性总结
- G1 garbage collector
- 50: Chapter 5: develop admin management service: 3: develop [query whether the admin user name already exists, interface]; (this interface can only be called when logging in; so we have written an int
- (2022牛客多校二)K-Link with Bracket Sequence I(动态规划)
- sqlilabs less-29
- HTB-Beep
- 2021年ICPC陕西省赛热身赛 B.CODE(位运算)
- 动态规划学习笔记
- Continuous maximum sum and judgement palindrome
- easyrecovery免费数据恢复工具操作简单一键恢复数据
猜你喜欢

Softing pngate series gateway: integrate PROFIBUS bus into PROFINET network

(Niuke multi School II) j-link with arithmetic progress (least square method / three points)

Unity accesses chartandgraph chart plug-in

PHP warehouse inventory management system source code WMS source code

Realsense d435i depth map optimization_ High precision mode

ECS is exclusive to old users, and the new purchase of the remaining 10 instances is as low as 3.6% off

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

Leetcode 202. happy number (not happy at all)

Adaptation dynamics | in June, sequoiadb completed mutual certification with five products

线性代数(三)
随机推荐
sqlilabs less-29
编程大杂烩(一)
Odoo14 | about the abnormal display of statusbar keyword after use and Its Solutions
剑指 Offer 32 - I. 从上到下打印二叉树
Leetcode 0121. the best time to buy and sell stocks - simulation from back to front
R language uses LM function to build multiple linear regression model and write regression equation according to model coefficient
Leetcode 237. delete nodes in the linked list
Big talk · book sharing | Haas Internet of things device cloud integrated development framework
Flexible layout summary
VPP cannot load up status interface
Leetcode 202. happy number (not happy at all)
50:第五章:开发admin管理服务:3:开发【查询admin用户名是否已存在,接口】;(这个接口需要登录时才能调用;所以我们编写了拦截器,让其拦截请求,判断用户是否是登录状态;)
Leetcode 204. count prime numbers (wonderful)
LCP plug-in creates peer-to-peer physical interface
LCP plug-in creates peer-to-peer 802.1ad interface
flex布局常用属性总结
Summer summary 2
Array programming problem of CSDN programming challenge
Difference between NPX and NPM
Terminate 5g chip cooperation! The official response of Intel and zhanrui came