Dll注入經典方法完整版

2021-06-19 15:12:58 字數 2785 閱讀 5304



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關閉執行緒及程序控制代碼。

01.//code by pnig0s1992 

02.//date:2012,3,13

03.#include 04.#include 05.#include 06.

07.

08.dword getprocesshandle(lpctstr lpprocessname)//根據程序名查詢程序pid

09.

17.

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

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

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

21. do

22.

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

29. closehandle(hsnapshot);

30. return dwret;//返回

31.}

32.

33.int main(int argc,char * argv)

34.

43. dword dwsize = strlen(lpdllname)+1;

44. dword dwhaswrite;

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

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

47.

54.

55. }else

56.

61.

62. dword dwnewthreadid;

63. lpvoid lploaddll = loadlibrarya;

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

65. if(hnewremotethread == null)

66.

71.

72. waitforsingleobject(hnewremotethread,infinite);

73. closehandle(hnewremotethread);

74.

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

76. dword dwhandle,dwid;

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

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

79. waitforsingleobject(hthread,infinite);

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

81. closehandle(hthread);

82. pfunc = freelibrary;

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

84. waitforsingleobject(hthread,infinite);

85. closehandle(hthread);

86. closehandle(hprocess);

87. return 0;

88.}

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...