コンテンツにスキップ

Msf::Exploit::Remote::Tcp(コード上は Exploit::Remote::Tcp)は素の TCP 接続を扱います。HTTP でない banner / binary protocol 向けです。雛形は modules/exploits/example.rb です。

include Exploit::Remote::Tcp
# または
include Msf::Exploit::Remote::Tcp
メソッド用途
connectRHOST:RPORT へ接続し sock を用意
disconnect切断
sock.put(data)送信
sock.get_once / sock.get受信
handlerペイロードハンドラとの連携(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

HTTP なら Tcp ではなく HttpClient を使います。