Dll注入經典方法完整版

2021-06-26 21:46:01 字數 2473 閱讀 8512

pnig0s1992:算是複習了,最經典的教科書式的dll注入。

總結一下基本的注入過程,分注入和解除安裝

注入dll:

1,openprocess獲得要注入程序的控制代碼

2,virtualallocex在遠端程序中開闢出一段記憶體,長度為strlen(dllname)+1;

3,writeprocessmemory將dll的名字寫入第二步開闢出的記憶體中。

4,createremotethread將loadlibrarya作為執行緒函式,引數為dll的名稱,建立新執行緒

5,closehandle關閉執行緒控制代碼

解除安裝dll:

1,createremotethread將getmodulehandle注入到遠端程序中,引數為被注入的dll名

2,getexitcodethread將執行緒退出的退出碼作為dll模組的控制代碼值。

3,closehandle關閉執行緒控制代碼

3,createremotethread將freelibrarya注入到遠端程序中,引數為第二步獲得的控制代碼值。

4,waitforsingleobject等待物件控制代碼返回

5,closehandle關閉執行緒及程序控制代碼。

//code by pnig0s1992 

//date:2012,3,13

#include #include #include dword getprocesshandle(lpctstr lpprocessname)//根據程序名查詢程序pid

processentry32 pe32;//宣告程序入口物件

pe32.dwsize = sizeof(processentry32);//填充程序入口物件大小

process32first(hsnapshot,&pe32);//遍歷程序列表

do

} while (process32next(hsnapshot,&pe32));

closehandle(hsnapshot);

return dwret;//返回 }

int main(int argc,char * argv)

dword dwsize = strlen(lpdllname)+1;

dword dwhaswrite;

lpvoid lpremotebuf = virtualallocex(hprocess,null,dwsize,mem_commit,page_readwrite);

if(writeprocessmemory(hprocess,lpremotebuf,lpdllname,dwsize,&dwhaswrite))

}else

dword dwnewthreadid;

lpvoid lploaddll = loadlibrarya;

handle hnewremotethread = createremotethread(hprocess,null,0,(lpthread_start_routine)lploaddll,lpremotebuf,0,&dwnewthreadid);

if(hnewremotethread == null)

waitforsingleobject(hnewremotethread,infinite);

closehandle(hnewremotethread);

//準備解除安裝之前注入的dll

dword dwhandle,dwid;

lpvoid pfunc = getmodulehandlea;//獲得在遠端執行緒中被注入的dll的控制代碼

handle hthread = createremotethread(hprocess,null,0,(lpthread_start_routine)pfunc,lpremotebuf,0,&dwid);

waitforsingleobject(hthread,infinite);

getexitcodethread(hthread,&dwhandle);//執行緒的結束碼即為dll模組兒的控制代碼

closehandle(hthread);

pfunc = freelibrary;

hthread = createremotethread(hthread,null,0,(lpthread_start_routine)pfunc,(lpvoid)dwhandle,0,&dwid); //將freelibrarya注入到遠端執行緒中去解除安裝dll

waitforsingleobject(hthread,infinite);

closehandle(hthread);

closehandle(hprocess);

return 0;

}

Dll注入經典方法完整版

windows核心程式設計中dll章節有相關介紹 總結一下基本的注入過程,分注入和解除安裝 注入dll 1,openprocess獲得要注入程序的控制代碼 2,virtualallocex在遠端程序中開闢出一段記憶體,長度為strlen dllname 1 3,writeprocessmemory將...

Dll注入經典方法完整版

pnig0s1992 算是複習了,最經典的教科書式的dll注入。總結一下基本的注入過程,分注入和解除安裝 注入dll 1,openprocess獲得要注入程序的控制代碼 2,virtualallocex在遠端程序中開闢出一段記憶體,長度為strlen dllname 1 3,writeprocess...

Dll注入經典方法完整版

標籤 dll注入winapi 遠端執行緒 原始出處 作者資訊和本宣告。否則將追究法律責任。注入dll 1,openprocess獲得要注入程序的控制代碼 2,virtualallocex在遠端程序中開闢出一段記憶體,長度為strlen dllname 1 3,writeprocessmemory將d...