2011-05-12 20:03:55 +00:00
|
|
|
require 'rex/proto/sunrpc'
|
2006-01-21 02:44:54 +00:00
|
|
|
|
|
|
|
module Msf
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# This mixin provides utility methods for interacting with a SunRPC service on
|
|
|
|
# a remote machine. These methods may generally be useful in the context of
|
2010-02-03 20:30:09 +00:00
|
|
|
# exploitation. This mixin extends the Tcp exploit mixin. Only one SunRPC
|
2006-01-21 02:44:54 +00:00
|
|
|
# service can be accessed at a time using this class.
|
2010-02-03 20:30:09 +00:00
|
|
|
#
|
2009-12-23 13:44:53 +00:00
|
|
|
# http://www.ietf.org/rfc/rfc1057.txt
|
2006-01-21 02:44:54 +00:00
|
|
|
#
|
|
|
|
###
|
|
|
|
module Exploit::Remote::SunRPC
|
|
|
|
include Exploit::Remote::Tcp
|
|
|
|
|
2009-12-23 13:44:53 +00:00
|
|
|
XDR = Rex::Encoder::XDR
|
2010-02-03 20:30:09 +00:00
|
|
|
|
2009-12-23 13:44:53 +00:00
|
|
|
MSG_ACCEPTED = 0
|
|
|
|
SUCCESS = 0 # RPC executed successfully
|
|
|
|
PROG_UMAVAIL = 1 # Remote hasn't exported program
|
|
|
|
PROG_MISMATCH = 2 # Remote can't support version #
|
|
|
|
PROC_UNAVAIL = 3 # Program can't support procedure
|
|
|
|
GARBAGE_ARGS = 4 # Procedure can't decode params'
|
2010-02-06 21:50:11 +00:00
|
|
|
SYSTEM_ERR = 5 # System encountered some error
|
2006-02-01 22:31:28 +00:00
|
|
|
|
2006-01-21 02:44:54 +00:00
|
|
|
def initialize(info = {})
|
|
|
|
super
|
2006-03-08 19:14:10 +00:00
|
|
|
|
|
|
|
register_evasion_options(
|
|
|
|
[
|
|
|
|
OptBool.new('ONCRPC::tcp_request_fragmentation', [false, 'Enable fragmentation of TCP ONC/RPC requests', 'false']),
|
|
|
|
], Msf::Exploit::Remote::SunRPC
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2006-01-21 02:44:54 +00:00
|
|
|
register_advanced_options(
|
|
|
|
[
|
2009-12-23 13:44:53 +00:00
|
|
|
# XXX: Use portmapper to do call - Direct portmap to make the request to the program portmap_req
|
2006-01-21 02:44:54 +00:00
|
|
|
], Msf::Exploit::Remote::SunRPC)
|
|
|
|
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
# XXX: XPORT
|
|
|
|
Opt::RHOST,
|
|
|
|
Opt::RPORT(111),
|
|
|
|
], Msf::Exploit::Remote::SunRPC
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def sunrpc_create(protocol, program, version)
|
2010-03-17 23:02:35 +00:00
|
|
|
self.rpcobj = Rex::Proto::SunRPC::Client.new(
|
|
|
|
:rhost => rhost,
|
|
|
|
:rport => rport.to_i,
|
|
|
|
:proto => protocol,
|
|
|
|
:program => program,
|
|
|
|
:version => version,
|
|
|
|
:context => {
|
|
|
|
'Msf' => framework,
|
|
|
|
'MsfExploit' => self,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2006-03-08 19:14:10 +00:00
|
|
|
if datastore['ONCRPC::tcp_request_fragmentation'] == true
|
|
|
|
self.rpcobj.should_fragment = 1
|
|
|
|
end
|
|
|
|
|
2009-12-23 13:44:53 +00:00
|
|
|
ret = rpcobj.create
|
2010-02-03 20:30:09 +00:00
|
|
|
return print_error("#{rhost} - No response to SunRPC PortMap request") unless ret
|
|
|
|
|
2009-12-23 13:44:53 +00:00
|
|
|
arr = XDR.decode!(ret, Integer, Integer, Integer, String, Integer, Integer)
|
|
|
|
if arr[1] != MSG_ACCEPTED || arr[4] != SUCCESS || arr[5] == 0
|
|
|
|
err = "#{rhost} - SunRPC PortMap request failed: "
|
|
|
|
err << 'Message not accepted' if arr[1] != MSG_ACCEPTED
|
|
|
|
err << 'RPC did not execute' if arr[4] != SUCCESS
|
|
|
|
err << 'Program not available' if arr[5] == 0
|
|
|
|
print_error(err)
|
2010-02-07 03:51:14 +00:00
|
|
|
return nil
|
2009-12-23 13:44:53 +00:00
|
|
|
end
|
2010-02-03 20:30:09 +00:00
|
|
|
|
2009-12-23 13:44:53 +00:00
|
|
|
rpcobj.pport = arr[5]
|
2010-02-06 21:50:11 +00:00
|
|
|
#progname = progresolv(rpcobj.program)
|
|
|
|
#print_status("#{rhost} - SunRPC Found #{progname} on #{protocol} port #{rpcobj.pport}")
|
2006-01-21 02:44:54 +00:00
|
|
|
end
|
|
|
|
|
2010-05-24 00:57:18 +00:00
|
|
|
def sunrpc_call(proc, buf, timeout=20)
|
|
|
|
ret = rpcobj.call(proc, buf, timeout)
|
2009-12-23 13:44:53 +00:00
|
|
|
return print_error("#{rhost} - No response to SunRPC call for procedure: #{proc}") unless ret
|
|
|
|
|
|
|
|
arr = Rex::Encoder::XDR.decode!(ret, Integer, Integer, Integer, String, Integer)
|
|
|
|
if arr[1] != MSG_ACCEPTED || arr[4] != SUCCESS
|
2010-02-03 20:30:09 +00:00
|
|
|
progname = progresolv(rpcobj.program)
|
|
|
|
err = "SunRPC call for program #{rpcobj.program} [#{progname}], procedure #{proc}, failed: "
|
2010-02-06 21:50:11 +00:00
|
|
|
if (arr[1] != MSG_ACCEPTED)
|
2010-02-08 00:59:29 +00:00
|
|
|
err << 'Message not accepted'
|
2010-02-06 21:50:11 +00:00
|
|
|
elsif (arr[4] and arr[4] != SUCCESS)
|
|
|
|
case arr[4]
|
|
|
|
when PROG_UMAVAIL then err << "Program Unavailable"
|
|
|
|
when PROG_MISMATCH then err << "Program Version Mismatch"
|
|
|
|
when PROC_UNAVAIL then err << "Procedure Unavailable"
|
|
|
|
when GARBAGE_ARGS then err << "Garbage Arguments"
|
|
|
|
when SYSTEM_ERR then err << "System Error"
|
|
|
|
else err << "Unknown Error"
|
|
|
|
end
|
2009-12-23 13:44:53 +00:00
|
|
|
end
|
|
|
|
print_error("#{rhost} - #{err}")
|
2010-02-07 03:51:14 +00:00
|
|
|
return nil
|
2009-12-23 13:44:53 +00:00
|
|
|
end
|
|
|
|
return ret
|
2006-01-21 02:44:54 +00:00
|
|
|
end
|
|
|
|
|
2010-02-08 00:59:29 +00:00
|
|
|
def sunrpc_callsock
|
|
|
|
self.rpcobj.call_sock
|
|
|
|
end
|
|
|
|
|
2006-01-21 02:44:54 +00:00
|
|
|
def sunrpc_destroy
|
|
|
|
rpcobj.destroy
|
|
|
|
rpcobj = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def sunrpc_authnull(*args)
|
|
|
|
rpcobj.authnull_create(*args)
|
|
|
|
end
|
|
|
|
|
|
|
|
def sunrpc_authunix(*args)
|
|
|
|
rpcobj.authunix_create(*args)
|
|
|
|
end
|
2010-02-03 20:30:09 +00:00
|
|
|
|
2009-12-23 13:44:53 +00:00
|
|
|
# XXX: Incomplete. Just moved from Rex::Proto::SunRPC::Client
|
|
|
|
def portmap_qry()
|
2010-02-03 20:30:09 +00:00
|
|
|
ret = portmap_req()
|
2009-12-23 13:44:53 +00:00
|
|
|
arr = Rex::Encoder::XDR.decode!(ret, Integer, Integer, Integer, String, Integer)
|
|
|
|
if arr[1] != MSG_ACCEPTED || arr[4] != SUCCESS || arr[5] == 0
|
2010-02-03 20:30:09 +00:00
|
|
|
progname = progresolv(rpcobj.program)
|
|
|
|
err = "SunRPC query for program #{rpcobj.program} [#{progname}] failed: "
|
2009-12-23 13:44:53 +00:00
|
|
|
case arr[4]
|
|
|
|
when PROG_UMAVAIL then err << "Program Unavailable"
|
|
|
|
when PROG_MISMATCH then err << "Program Version Mismatch"
|
|
|
|
when PROC_UNAVAIL then err << "Procedure Unavailable"
|
|
|
|
when GARBAGE_ARGS then err << "Garbage Arguments"
|
|
|
|
else err << "Unknown Error"
|
|
|
|
end
|
|
|
|
print_error("#{rhost} - #{err}")
|
2010-02-07 03:51:14 +00:00
|
|
|
return nil
|
2009-12-23 13:44:53 +00:00
|
|
|
end
|
2010-02-03 20:30:09 +00:00
|
|
|
|
2009-12-23 13:44:53 +00:00
|
|
|
return ret
|
|
|
|
end
|
2010-02-03 20:30:09 +00:00
|
|
|
|
2009-12-23 13:44:53 +00:00
|
|
|
def progresolv(number)
|
2010-02-03 20:30:09 +00:00
|
|
|
names = File.join(Msf::Config.install_root, "data", "wordlists", "rpc_names.txt")
|
2010-09-26 21:02:00 +00:00
|
|
|
File.open(names, "rb").each_line do |line|
|
2009-12-23 13:44:53 +00:00
|
|
|
next if line.empty? || line =~ /^\s*#/
|
2010-02-03 20:30:09 +00:00
|
|
|
|
2009-12-23 13:44:53 +00:00
|
|
|
if line =~ /^(\S+?)\s+(\d+)/ && number == $2.to_i
|
|
|
|
return $1
|
|
|
|
end
|
|
|
|
end
|
2010-02-03 20:30:09 +00:00
|
|
|
|
2009-12-23 13:44:53 +00:00
|
|
|
return "UNKNOWN-#{number}"
|
|
|
|
end
|
2006-01-21 02:44:54 +00:00
|
|
|
|
2010-02-03 20:30:09 +00:00
|
|
|
# Used to track the last SunRPC context
|
2006-01-21 02:44:54 +00:00
|
|
|
attr_accessor :rpcobj
|
|
|
|
end
|
|
|
|
|
2010-02-03 20:30:09 +00:00
|
|
|
end
|
2010-02-08 00:59:29 +00:00
|
|
|
|