metasploit-framework/lib/msf/core/exploit/tcp.rb

62 lines
952 B
Ruby
Raw Normal View History

module Msf
###
#
# Tcp
# ---
#
# This module provides methods for establish a connection to a remote host and
# communicating with it.
#
###
module Exploit::Remote::Tcp
def initialize(info = {})
super(merge_info(info,
'Options' =>
[
Opt::RHOST,
Opt::RPORT,
Opt::LHOST(nil, false),
Opt::LPORT(nil, false)
]))
end
#
# Establishes a TCP connection to the specified RHOST/RPORT
#
def connect(global = true)
sock = Rex::Socket::Tcp.create(
'PeerHost' => datastore['RHOST'],
'PeerPort' => datastore['RPORT'].to_i,
'LocalHost' => datastore['LHOST'],
'LocalPort' => datastore['LPORT'].to_i)
# Set this socket to the global socket as necessary
esock = sock if (global)
return esock
end
#
# Closes the TCP connection
#
def disconnect(sock = esock)
if (sock)
sock.shutdown
sock.close
end
if (sock == esock)
esock = nil
end
end
protected
attr_accessor :esock
end
end