Files
metasploit-gs/lib/msf/core/exploit/tcp.rb
T
Matt Miller a0b6980813 options now have explicit class owners
git-svn-id: file:///home/svn/incoming/trunk@2587 4d416f70-5f16-0410-b530-b9f4589650da
2005-06-05 23:45:58 +00:00

63 lines
960 B
Ruby

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
register_options(
[
Opt::RHOST,
Opt::RPORT,
Opt::LHOST(nil, false),
Opt::LPORT(nil, false)
], Msf::Exploit::Remote::Tcp)
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