2009-12-28 05:07:50 +00:00
|
|
|
##
|
2014-10-17 16:47:33 +00:00
|
|
|
# This module requires Metasploit: http://metasploit.com/download
|
2013-10-15 18:50:46 +00:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
2009-12-28 05:07:50 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
|
2016-03-08 13:02:44 +00:00
|
|
|
class MetasploitModule < Msf::Auxiliary
|
2013-08-30 21:28:54 +00:00
|
|
|
include Msf::Exploit::Remote::SunRPC
|
|
|
|
include Msf::Auxiliary::Report
|
|
|
|
include Msf::Auxiliary::Scanner
|
2009-12-28 05:07:50 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def initialize
|
|
|
|
super(
|
2014-10-21 17:04:04 +00:00
|
|
|
'Name' => 'SunRPC Portmap Program Enumerator',
|
|
|
|
'Description' => '
|
|
|
|
This module calls the target portmap service and enumerates all program
|
|
|
|
entries and their running port numbers.
|
|
|
|
',
|
|
|
|
'Author' => ['<tebo[at]attackresearch.com>'],
|
|
|
|
'References' =>
|
2013-08-30 21:28:54 +00:00
|
|
|
[
|
2014-10-21 17:04:04 +00:00
|
|
|
['URL', 'http://www.ietf.org/rfc/rfc1057.txt']
|
2013-08-30 21:28:54 +00:00
|
|
|
],
|
|
|
|
'License' => MSF_LICENSE
|
|
|
|
)
|
|
|
|
end
|
2009-12-28 05:07:50 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def run_host(ip)
|
2014-10-21 16:25:21 +00:00
|
|
|
peer = "#{ip}:#{rport}"
|
2016-02-01 22:06:34 +00:00
|
|
|
vprint_status "SunRPC - Enumerating programs"
|
2009-12-28 05:07:50 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
begin
|
|
|
|
program = 100000
|
|
|
|
progver = 2
|
|
|
|
procedure = 4
|
2009-12-28 05:07:50 +00:00
|
|
|
|
2014-11-18 17:20:41 +00:00
|
|
|
sunrpc_create('udp', program, progver)
|
2014-10-21 17:04:04 +00:00
|
|
|
sunrpc_authnull
|
2013-08-30 21:28:54 +00:00
|
|
|
resp = sunrpc_call(procedure, "")
|
2009-12-28 05:07:50 +00:00
|
|
|
|
2014-10-21 17:04:04 +00:00
|
|
|
progs = resp[3, 1].unpack('C')[0]
|
2013-09-26 14:42:38 +00:00
|
|
|
maps = []
|
2013-08-30 21:28:54 +00:00
|
|
|
if (progs == 0x01)
|
2014-10-21 17:04:04 +00:00
|
|
|
while XDR.decode_int!(resp) == 1
|
|
|
|
maps << XDR.decode!(resp, Integer, Integer, Integer, Integer)
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
sunrpc_destroy
|
2014-10-21 16:25:21 +00:00
|
|
|
return if maps.empty?
|
2016-02-01 22:06:34 +00:00
|
|
|
vprint_good("Found #{maps.size} programs available")
|
2014-10-21 16:25:21 +00:00
|
|
|
|
2016-08-10 18:30:09 +00:00
|
|
|
table = Rex::Text::Table.new(
|
2014-10-21 17:04:04 +00:00
|
|
|
'Header' => "SunRPC Programs for #{ip}",
|
2014-10-21 16:25:21 +00:00
|
|
|
'Indent' => 1,
|
|
|
|
'Columns' => %w(Name Number Version Port Protocol)
|
|
|
|
)
|
2009-12-28 05:07:50 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
maps.each do |map|
|
2014-10-21 17:04:04 +00:00
|
|
|
prog, vers, prot_num, port = map[0, 4]
|
2014-10-21 16:25:21 +00:00
|
|
|
thing = "RPC Program ##{prog} v#{vers} on port #{port} w/ protocol #{prot_num}"
|
|
|
|
if prot_num == 0x06
|
|
|
|
proto = 'tcp'
|
|
|
|
elsif prot_num == 0x11
|
|
|
|
proto = 'udp'
|
|
|
|
else
|
|
|
|
print_error("#{peer}: unknown protocol number for #{thing}")
|
|
|
|
next
|
|
|
|
end
|
2009-12-28 05:07:50 +00:00
|
|
|
|
2014-10-21 16:25:21 +00:00
|
|
|
resolved = progresolv(prog)
|
|
|
|
table << [ resolved, prog, vers, port, proto ]
|
2013-08-30 21:28:54 +00:00
|
|
|
report_service(
|
2014-10-21 17:04:04 +00:00
|
|
|
host: ip,
|
|
|
|
port: port,
|
|
|
|
proto: proto,
|
|
|
|
name: resolved,
|
|
|
|
info: "Prog: #{prog} Version: #{vers} - via portmapper"
|
2013-08-30 21:28:54 +00:00
|
|
|
)
|
|
|
|
end
|
2009-12-28 05:07:50 +00:00
|
|
|
|
2014-10-21 16:25:21 +00:00
|
|
|
print_good(table.to_s)
|
2014-10-21 17:54:52 +00:00
|
|
|
rescue ::Rex::Proto::SunRPC::RPCTimeout, ::Rex::Proto::SunRPC::RPCError => e
|
|
|
|
vprint_error(e.to_s)
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
|
|
|
end
|
2009-12-28 05:07:50 +00:00
|
|
|
end
|