|
| 1 | + |
| 2 | +#include "ASMHeader.h" |
| 3 | + |
| 4 | +// Function that returns the default ASM Header |
| 5 | + |
| 6 | +string ASMHeader::GetASMHeader() |
| 7 | +{ |
| 8 | + string sContent = |
| 9 | + "; Shellcode generated using Shellcode Compiler \r\n" |
| 10 | + "; https://github.com/NytroRST/ShellcodeCompiler \r\n\r\n" |
| 11 | + "BITS 32 \r\n" |
| 12 | + "SECTION .text \r\n" |
| 13 | + "global main \r\n" |
| 14 | + "main: \r\n\r\n" |
| 15 | + "xor ecx, ecx \r\n" |
| 16 | + "mov eax, [fs:ecx + 0x30] ; EAX = PEB \r\n" |
| 17 | + "mov eax, [eax + 0xc] ; EAX = PEB->Ldr \r\n" |
| 18 | + "mov esi, [eax + 0x14] ; ESI = PEB->Ldr.InMemOrder \r\n" |
| 19 | + "lodsd ; EAX = Second module \r\n" |
| 20 | + "xchg eax, esi ; EAX = ESI, ESI = EAX \r\n" |
| 21 | + "lodsd ; EAX = Third(kernel32) \r\n" |
| 22 | + "mov ebx, [eax + 0x10] ; EBX = Base address \r\n" |
| 23 | + "mov edx, [ebx + 0x3c] ; EDX = DOS->e_lfanew \r\n" |
| 24 | + "add edx, ebx ; EDX = PE Header \r\n" |
| 25 | + "mov edx, [edx + 0x78] ; EDX = Offset export table \r\n" |
| 26 | + "add edx, ebx ; EDX = Export table \r\n" |
| 27 | + "mov esi, [edx + 0x20] ; ESI = Offset namestable \r\n" |
| 28 | + "add esi, ebx ; ESI = Names table \r\n" |
| 29 | + "xor ecx, ecx ; EXC = 0 \r\n\r\n" |
| 30 | + |
| 31 | + "Get_Function: \r\n\r\n" |
| 32 | + |
| 33 | + "inc ecx ; Increment the ordinal \r\n" |
| 34 | + "lodsd ; Get name offset \r\n" |
| 35 | + "add eax, ebx ; Get function name \r\n" |
| 36 | + "cmp dword [eax], 0x50746547 ; GetP \r\n" |
| 37 | + "jnz Get_Function \r\n" |
| 38 | + "cmp dword [eax + 0x4], 0x41636f72 ; rocA \r\n" |
| 39 | + "jnz Get_Function \r\n" |
| 40 | + "cmp dword [eax + 0x8], 0x65726464 ; ddre \r\n" |
| 41 | + "jnz Get_Function \r\n" |
| 42 | + "mov esi, [edx + 0x24] ; ESI = Offset ordinals \r\n" |
| 43 | + "add esi, ebx ; ESI = Ordinals table \r\n" |
| 44 | + "mov cx, [esi + ecx * 2] ; Number of function \r\n" |
| 45 | + "dec ecx \r\n" |
| 46 | + "mov esi, [edx + 0x1c] ; Offset address table \r\n" |
| 47 | + "add esi, ebx ; ESI = Address table \r\n" |
| 48 | + "mov edx, [esi + ecx * 4] ; EDX = Pointer(offset) \r\n" |
| 49 | + "add edx, ebx ; EDX = GetProcAddress \r\n\r\n" |
| 50 | + |
| 51 | + "xor ecx, ecx ; ECX = 0 \r\n" |
| 52 | + "push ebx ; Kernel32 base address \r\n" |
| 53 | + "push edx ; GetProcAddress \r\n" |
| 54 | + "push ecx ; 0 \r\n" |
| 55 | + "push 0x41797261 ; aryA \r\n" |
| 56 | + "push 0x7262694c ; Libr \r\n" |
| 57 | + "push 0x64616f4c ; Load \r\n" |
| 58 | + "push esp ; LoadLibrary \r\n" |
| 59 | + "push ebx ; Kernel32 base address \r\n" |
| 60 | + "call edx ; GetProcAddress(LL) \r\n\r\n" |
| 61 | + |
| 62 | + "add esp, 0xc ; pop LoadLibrary \r\n" |
| 63 | + "pop ecx ; ECX = 0 \r\n" |
| 64 | + "push eax ; EAX = LoadLibrary \r\n\r\n"; |
| 65 | + |
| 66 | + return sContent; |
| 67 | +} |
0 commit comments