Skip to content

Msf::Exploit::Remote::Tcp (written as Exploit::Remote::Tcp in code) handles raw TCP connections. Use it for banners or binary protocols rather than HTTP. The template is modules/exploits/example.rb.

include Exploit::Remote::Tcp
# Or
include Msf::Exploit::Remote::Tcp
MethodPurpose
connectConnect to RHOST:RPORT and prepare sock
disconnectDisconnect
sock.put(data)Send data
sock.get_once / sock.getReceive data
handlerWork with the payload handler in an exploit
def exploit
connect
print_status("Sending #{payload.encoded.length} byte payload...")
buf = rand_text_alpha(1024)
buf << [target.ret].pack('V')
buf << payload.encoded
sock.put(buf)
sock.get_once
handler
ensure
disconnect
end
def run_host(ip)
connect
sock.put("HELP\r\n")
banner = sock.get_once(1024, 3)
print_status("#{ip}: #{banner}")
report_service(host: ip, port: rport, name: 'example', info: banner.to_s)
ensure
disconnect
end

For HTTP, use HttpClient instead of Tcp.