当前位置:网站首页>IAT hook hijacking process API call
IAT hook hijacking process API call
2022-06-12 13:56:00 【HyperCall】
*ω*
The goose factory answered hijacking during the interview API Various Hook When it comes to the way ,IAT-Hook It should be the simplest one . Than IAT-Hook What's more difficult is R3 Of 5 byte Hook, Then there is the hot patch Hook,SSDT-Hook…..
5 byte Hook In the previous two articles on process hiding ,7 Bytes are mainly right API The requirements are quite high , This article will be updated IAT-Hook Implementation code , Later, update and copy the original API Hot patch for some code Hook and SSDT-Hook
T_T
I was going to spend last night 40 It will be finished in about minutes , As a result, various strange problems occurred , Debug to 2 Point done ! As a result, there are still 1/3 Of people haven't slept yet …… Contemporary college students' daily life ???
Tips & Problems
1. The principle is very simple , hold DLL Inject into thought Hook The process of ( The process has hidden injector code ), then DLL Find the program process handle in the process space , The handle points to MZ The pointer to the head , Then you can find the input table through various structure operations , find IID Structure , Find the one that needs to be modified IAT, And then change it ~~OVER!!, Be more specific ,IAT-Hook The principle of is procedure call func The implementation of call [func Where IAT], For this iat Take the address value and call, The address value is PE Loader stay PE Dynamically obtained during loading .
2. The first problem encountered is the optimization of the compiler , It's no use trying to be lazy DLL The injection tool injects DLL Instead, I wrote a program directly LoadLibrary, Then pop up the window ,DLL Responsible for hijacking MessageBoxW function , But it can't be hijacked …. After debugging step by step, I found that the compiler called MessageBoxW The function is written as call esi, then esi=[MessageBoxW Of iat Address ], however Loadlibrary stay esi=[MessageBoxW Of iat Address ] after , That is to say, no matter how it is modified call esi Eventually, the original MessageBoxW….
3. String comparison function strcmp(char ,char ) The result is only one character …. I remember that this function should be less than ’\0’ No return ….. It took 5s, A string comparison function
4.Hook When the original function is transferred to the new function, you must pay attention to the stack balance problem
5. Because basically MZ Head structure PE The key values in the header structure are RVA, Add the process handle directly to get VA 了 , It's really super convenient
6. because DLL There is no need to uninstall , Generally injected DLL The uninstalled process also exits , So there is no need to write UnHook function
Here is the code
IAT.h
#include "windows.h"
HMODULE Current_Handle; // Process handle
PBYTE pfile; // Point to MZ
PIMAGE_DOS_HEADER Dos_Header; //Dos head
PIMAGE_NT_HEADERS Nt_Header; //NT head
DWORD IATSection_Base; //IAT The base address of the section
DWORD IATSection_Size; //IAT The size of the segment
BOOL str_cmp(char *a,char *b);
void PeInit();
BOOL IatHook(LPCSTR DllName,LPCSTR ProcName);
int WINAPI NewMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType);IAT.cpp
#include "IAT.h"
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason) {
case DLL_PROCESS_ATTACH:
Current_Handle = NULL;
pfile = NULL;
Dos_Header = NULL;
Nt_Header = NULL;
IATSection_Base = 0;
IATSection_Size = 0;
PeInit();
IatHook("USER32.dll","MessageBoxW");
break;
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
BOOL str_cmp(char *a,char *b){
while(*a==*b && *a!='\0' && *b!='\0'){
a++;
b++;
}
if(*a=='\0' && *b=='\0') return true;
return false;
}
int WINAPI NewMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType) {
return MessageBoxW(NULL,L"123",L"123", NULL);
}
BOOL IatHook(LPCSTR DllName,LPCSTR ProcName) {
DWORD oldprotect = 0;
FARPROC ori_func = GetProcAddress(GetModuleHandleA(DllName), ProcName);
PIMAGE_THUNK_DATA pthunk=NULL;
PIMAGE_IMPORT_DESCRIPTOR Current_IID = (PIMAGE_IMPORT_DESCRIPTOR)(pfile + IATSection_Base);
while (Current_IID) {
if (str_cmp((char *)DllName,(char *)(pfile + Current_IID->Name))) {
pthunk = (PIMAGE_THUNK_DATA)(pfile+Current_IID->FirstThunk);
while (pthunk->u1.Function) {
if (pthunk->u1.Function == (DWORD)ori_func) {
VirtualProtect((LPVOID)&pthunk->u1.Function, 4, PAGE_EXECUTE_READWRITE, &oldprotect);
pthunk->u1.Function = (DWORD)NewMessageBoxW;
VirtualProtect((LPVOID)&pthunk->u1.Function, 4, oldprotect, &oldprotect);
break;
}
pthunk++;
}
return true;
}
Current_IID++;
}
return false;
}
void PeInit() {
Current_Handle = GetModuleHandle(NULL);
pfile = (PBYTE)Current_Handle;
Dos_Header = (PIMAGE_DOS_HEADER)pfile;
if (Dos_Header->e_magic != IMAGE_DOS_SIGNATURE){
OutputDebugString(L"Is Not PE");
return;
}
Nt_Header = (PIMAGE_NT_HEADERS)(pfile + Dos_Header->e_lfanew);
if (Nt_Header->Signature != IMAGE_NT_SIGNATURE) {
OutputDebugString(L"Is Not PE");
return;
}
IMAGE_DATA_DIRECTORY IAT_Section = (IMAGE_DATA_DIRECTORY)(Nt_Header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT]);
IATSection_Base = IAT_Section.VirtualAddress;
IATSection_Size = IAT_Section.Size;
}边栏推荐
- 280 weeks /2171 Take out the least number of magic beans
- Tree reconstruction (pre order + middle order or post order + middle order)
- 阿里云开发板HaaS510解析串口JSON数据并发送属性
- [advanced MySQL] evolution of MySQL index data structure (IV)
- Alibaba cloud development board haas510 submission device attributes
- Web3.0,「激发创造」的时代
- Codeforces 1629 D. pecuriar movie preferences - simple thinking, palindrome strings
- 拆改广告机---业余解压
- Is MySQL query limit 1000,10 as fast as limit 10? How to crack deep paging
- 618进入后半段,苹果占据高端市场,国产手机终于杀价竞争
猜你喜欢

Scyther工具形式化分析Woo-Lam协议

Transmission and response of events and use cases

Alibaba cloud development board haas510 submission device attributes

动态搜索广告智能查找匹配关键字

Single bus temperature sensor 18B20 data on cloud (Alibaba cloud)

Formal analysis of Woo Lam protocol with scyther tool
![[WUSTCTF2020]颜值成绩查询-1](/img/dc/47626011333a0e853be87e492d8528.png)
[WUSTCTF2020]颜值成绩查询-1

【mysql进阶】索引分类及索引优化方案(五)

Implementation of Ackermann function with simulated recursion

通过loganalyzer展示数据库中的日志
随机推荐
Codeforces 1638 B. odd swap sort - tree array, no, simple thinking
[wustctf2020] selfie score query -1
【mysql进阶】索引分类及索引优化方案(五)
Codeforces 1637 D. yet another minimization problem - Mathematics, DP
go-zero 微服务实战系列(二、服务拆分)
Programmer interview golden classic good question / interview question 01.05 Edit once
初学者入门阿里云haas510开板式DTU(2.0版本)--510-AS
通过loganalyzer展示数据库中的日志
Talk about the top 10 classic MySQL errors
[semidrive source code analysis] [x9 chip startup process] 26 - LK of R5 safetyos_ INIT_ LEVEL_ Target phase code flow analysis (TP drvier, audio server initialization)
Codeforces 1637 A. sorting parts - simple thinking
Implementing singleton mode of database under QT multithreading
基于Profibus-DP协议的PLC智能从站设计
Byte order data read / write
[video lesson] a full set of tutorials on the design and production of Android studio Internet of things app -- all mastered during the National Day
My resume.
CSDN博客积分规则
注重点击,追求更多用户进入网站,可以选择什么出价策略?
Compile and install lamp architecture of WordPress and discuz for multi virtual hosts based on fastcgi mode
如果要打造品牌知名度,可以选择什么出价策略?