Tcp
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
Section titled “include”include Exploit::Remote::Tcp# Orinclude Msf::Exploit::Remote::TcpMain APIs
Section titled “Main APIs”| Method | Purpose |
|---|---|
connect | Connect to RHOST:RPORT and prepare sock |
disconnect | Disconnect |
sock.put(data) | Send data |
sock.get_once / sock.get | Receive data |
handler | Work with the payload handler in an exploit |
Examples
Section titled “Examples”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 handlerensure disconnectenddef 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 disconnectendFor HTTP, use HttpClient instead of Tcp.

