2005-06-05 05:42:43 +00:00
|
|
|
module Msf
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# Tcp
|
|
|
|
# ---
|
|
|
|
#
|
|
|
|
# This module provides methods for establish a connection to a remote host and
|
|
|
|
# communicating with it.
|
|
|
|
#
|
|
|
|
###
|
|
|
|
module Exploit::Remote::Tcp
|
|
|
|
|
2005-06-05 06:07:18 +00:00
|
|
|
def initialize(info = {})
|
2005-06-05 05:42:43 +00:00
|
|
|
super(merge_info(info,
|
|
|
|
'Options' =>
|
|
|
|
[
|
|
|
|
Opt::RHOST,
|
2005-06-05 06:07:18 +00:00
|
|
|
Opt::RPORT,
|
|
|
|
Opt::LHOST(nil, false),
|
|
|
|
Opt::LPORT(nil, false)
|
2005-06-05 05:42:43 +00:00
|
|
|
]))
|
|
|
|
end
|
|
|
|
|
2005-06-05 06:07:18 +00:00
|
|
|
#
|
|
|
|
# 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
|
|
|
|
|
2005-06-05 05:42:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|