2005-11-26 11:16:50 +00:00
|
|
|
module Msf
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# This module provides methods for communicating with a host over UDP
|
|
|
|
#
|
|
|
|
###
|
|
|
|
module Exploit::Remote::Udp
|
|
|
|
|
|
|
|
#
|
|
|
|
# Initializes an instance of an exploit module that exploits a
|
|
|
|
# vulnerability in a UDP service
|
|
|
|
#
|
|
|
|
def initialize(info = {})
|
|
|
|
super
|
|
|
|
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
Opt::RHOST,
|
|
|
|
Opt::RPORT,
|
|
|
|
], Msf::Exploit::Remote::Udp)
|
2010-05-01 16:26:24 +00:00
|
|
|
|
2007-02-18 07:02:47 +00:00
|
|
|
register_advanced_options(
|
|
|
|
[
|
|
|
|
Opt::CPORT,
|
|
|
|
Opt::CHOST
|
2009-06-17 21:05:19 +00:00
|
|
|
], Msf::Exploit::Remote::Udp
|
2010-05-01 16:26:24 +00:00
|
|
|
)
|
2005-11-26 11:16:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Creates a UDP socket for communicating with a remote host
|
|
|
|
#
|
2007-04-14 07:16:33 +00:00
|
|
|
def connect_udp(global = true, opts={})
|
2005-11-26 11:16:50 +00:00
|
|
|
nsock = Rex::Socket::Udp.create(
|
2007-04-14 07:16:33 +00:00
|
|
|
'PeerHost' => opts['RHOST'] || rhost,
|
|
|
|
'PeerPort' => (opts['RPORT'] || rport).to_i,
|
|
|
|
'LocalHost' => opts['CHOST'] || chost || "0.0.0.0",
|
|
|
|
'LocalPort' => (opts['CPORT'] || cport || 0).to_i,
|
2005-11-26 11:16:50 +00:00
|
|
|
'Context' =>
|
|
|
|
{
|
|
|
|
'Msf' => framework,
|
|
|
|
'MsfExploit' => self,
|
|
|
|
})
|
|
|
|
|
|
|
|
# Set this socket to the global socket as necessary
|
|
|
|
self.udp_sock = nsock if (global)
|
|
|
|
|
|
|
|
# Add this socket to the list of sockets created by this exploit
|
2009-07-09 06:58:11 +00:00
|
|
|
add_socket(nsock)
|
2005-11-26 11:16:50 +00:00
|
|
|
|
|
|
|
return nsock
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Closes the UDP socket
|
|
|
|
#
|
|
|
|
def disconnect_udp(nsock = self.udp_sock)
|
|
|
|
begin
|
|
|
|
if (nsock)
|
|
|
|
nsock.shutdown
|
|
|
|
nsock.close
|
|
|
|
end
|
|
|
|
rescue IOError
|
|
|
|
end
|
|
|
|
|
|
|
|
if (nsock == udp_sock)
|
|
|
|
self.udp_sock = nil
|
|
|
|
end
|
2010-05-01 16:26:24 +00:00
|
|
|
|
2005-11-26 11:16:50 +00:00
|
|
|
# Remove this socket from the list of sockets created by this exploit
|
2009-07-09 06:58:11 +00:00
|
|
|
remove_socket(nsock)
|
2005-11-26 11:16:50 +00:00
|
|
|
end
|
|
|
|
|
2010-05-01 16:26:24 +00:00
|
|
|
#
|
2007-04-16 16:20:59 +00:00
|
|
|
# Claims the UDP socket if the payload so desires.
|
|
|
|
#
|
|
|
|
def handler(nsock = self.udp_sock)
|
|
|
|
# If the handler claims the socket, then we don't want it to get closed
|
|
|
|
# during cleanup
|
|
|
|
if ((rv = super) == Handler::Claimed)
|
|
|
|
if (nsock == self.udp_sock)
|
|
|
|
self.sock = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
# Remove this socket from the list of sockets so that it will not be
|
|
|
|
# aborted.
|
2009-07-09 06:58:11 +00:00
|
|
|
remove_socket(nsock)
|
2007-04-16 16:20:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return rv
|
|
|
|
end
|
|
|
|
|
2005-11-26 11:16:50 +00:00
|
|
|
#
|
|
|
|
# Performs cleanup, disconnects the socket if necessary
|
|
|
|
#
|
|
|
|
def cleanup
|
|
|
|
super
|
|
|
|
disconnect_udp
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
#
|
|
|
|
# Wrappers for getters
|
|
|
|
#
|
|
|
|
##
|
|
|
|
|
|
|
|
#
|
|
|
|
# Returns the target host
|
|
|
|
#
|
|
|
|
def rhost
|
|
|
|
datastore['RHOST']
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Returns the remote port
|
|
|
|
#
|
|
|
|
def rport
|
|
|
|
datastore['RPORT']
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Returns the local host
|
|
|
|
#
|
|
|
|
def lhost
|
|
|
|
datastore['LHOST']
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Returns the local port
|
|
|
|
#
|
|
|
|
def lport
|
|
|
|
datastore['LPORT']
|
|
|
|
end
|
|
|
|
|
2006-08-12 23:08:20 +00:00
|
|
|
#
|
|
|
|
# Returns the local host for outgoing connections
|
|
|
|
#
|
|
|
|
def chost
|
|
|
|
datastore['CHOST']
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Returns the local port for outgoing connections
|
|
|
|
#
|
|
|
|
def cport
|
|
|
|
datastore['CPORT']
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2005-11-26 11:16:50 +00:00
|
|
|
protected
|
|
|
|
|
|
|
|
attr_accessor :udp_sock
|
|
|
|
|
|
|
|
end
|
2009-03-28 05:49:33 +00:00
|
|
|
end
|
2010-05-01 16:26:24 +00:00
|
|
|
|