c語言 劫持系統03

2022-08-29 10:30:14 字數 3875 閱讀 8569

1. 回顧

在前2節我們已經實現了劫持原理、函式指標等一些概念,下面進行系統劫持

2. 工具

vs2017

detours

3. windows如何建立乙個程序?

(1)建立程序函式

createprocessw(

//執行程式名稱

lpwstr lpcommandline, //

命令列 lpsecurity_attributes lpprocessattributes, //

程序安裝

lpsecurity_attributes lpthreadattributes, //

程序主線程安裝

bool binherithandles, //

附加引數

dword dwcreationflags, //

建立引數

lpvoid lpenvironment, //

環境變數指標

lpcwstr lpcurrentdirectory, //

程序當前路徑

lpstartupinfow lpstartupinfo, //

程序啟動的附加資訊

lpprocess_information lpprocessinformation //

程序識別符號

);

(2) 我們需要用到哪些引數?

wchar_t str[100]; 用來指定輸入的命令比如notepad mspaint...     對應第二個引數

startupinfo si; 儲存程序資訊                                 也就是倒數第二個引數

process_information pi; 程序識別符號                 也就是最後乙個引數

其他都是null

(3) 完整程式**

#include#include

#include

intmain() ; //

儲存程序資訊

si.dwflags = startf_useshowwindow;//

顯示視窗

si.wshowwindow = 1;//

顯示視窗

process_information pi; //

程序資訊

wchar_t str[100] = l"

notepad";

createprocessw(null, str, null, null,

0, create_new_console, null, null, &si, &pi);

return0;

}

(4) 原理解釋

為什麼是wchar_t,不是char?

漢語佔兩個位元組,英語佔乙個位元組,windows系統為了相容函式,建立了寬字元wchar_t可以直接輸入漢語,而不會出現亂碼

4. 系統程序劫持

(1) 上次劫持原理回顧

void (*pold)(引數) =system;

void

pnew(引數)

void

hook()

(2) 這次函式由system()改為createprocess

第一步:建立函式指標

bool(winapi *poldcreateprocess)(

lpwstr lpcommandline,

lpsecurity_attributes lpprocessattributes,

lpsecurity_attributes lpthreadattributes,

bool binherithandles,

dword dwcreationflags,

lpvoid lpenvironment,

lpcwstr lpcurrentdirectory,

lpstartupinfow lpstartupinfo,

lpprocess_information lpprocessinformation

) = createprocessw;//

在中國使用寬字元更精準

第二步:建立新函式

bool  newcreateprocessw(

lpwstr lpcommandline,

lpsecurity_attributes lpprocessattributes,

lpsecurity_attributes lpthreadattributes,

bool binherithandles,

dword dwcreationflags,

lpvoid lpenvironment,

lpcwstr lpcurrentdirectory,

lpstartupinfow lpstartupinfo,

lpprocess_information lpprocessinformation

)

第三步:實現劫持

void

hook()

第四步:編寫dll函式

_declspec(dllexport)void

go()

第五步:改debug模式 -> rease模式  -> 生成解決方案

完整源**

#include #include 

#include

#include

"detours.h

"#pragma comment(lib,"detours.lib")bool(winapi *poldcreateprocess)(

lpwstr lpcommandline,

lpsecurity_attributes lpprocessattributes,

lpsecurity_attributes lpthreadattributes,

bool binherithandles,

dword dwcreationflags,

lpvoid lpenvironment,

lpcwstr lpcurrentdirectory,

lpstartupinfow lpstartupinfo,

lpprocess_information lpprocessinformation

) = createprocessw;//

寬字元的建立程序

bool newcreateprocessw(

lpwstr lpcommandline,

lpsecurity_attributes lpprocessattributes,

lpsecurity_attributes lpthreadattributes,

bool binherithandles,

dword dwcreationflags,

lpvoid lpenvironment,

lpcwstr lpcurrentdirectory,

lpstartupinfow lpstartupinfo,

lpprocess_information lpprocessinformation

)void

hook()

_declspec(dllexport)

void

go()

4. dll注入

開啟dll注入工具,登陸qq後重新整理dll注入工具選擇qq  

找到編寫的dll,輸入編寫的函式go() 點選注入,在qq上開啟qq空間

如果有explorer.exe的選擇explore.exe 注入後任何程序開啟失敗

C語言提高 03

int a int b 30 int c 120 memset c,0,sizeof c 2.1 陣列首元素位址和陣列的位址是兩個不同的概念 b是首元素位址,b才是整個陣列的位址。b 1 步長為4個位元組 b 1 步長為30 4個位元組 2.2陣列名是首元素的位址,是乙個常量,不能修改 陣列一定義就...

C語言總結 03

21.printf 的返回值為列印字元的個數。22.標頭檔案寫法 ifndef add h define add h intadd int x,int y endif 23.遞迴 求階乘 intfactorial int n 斐波那契數列 指的是這樣乙個數列 0 1 1 2 3 5 8 13 21 ...

C語言03 迴圈結構

int i 0 while i 7 練習1.int i 1 while i 101 i 也可以這樣寫.i 7 i 7 int i 1 while i 101 i 1 100 十位是7.int i 1 while i 101 i int i 1 while i 101 i long moneycoun...