Pwn2Own Austin 2021 : Defeating the Netgear R6700v3
A stack buffer overflow in the circled daemon's parsing of a downloaded circleinfo.txt file allows an attacker to execute arbitrary code as root. The daemon fetches this file over HTTPS without certificate validation, so an attacker who can redirect the router's DNS or TCP traffic can serve a malicious file and gain remote code execution from the WAN interface.
Published on synacktiv.com
Rédigé par Kevin Denis, Antide Petit - 25/03/2022 - dans Exploit, Reverse-engineering - Téléchargement
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
The daemon uses sscanf with unbounded %s format specifiers to copy parts of a downloaded file into fixed-size stack buffers, causing a stack buffer overflow; additionally, it downloads the file with curl -k, disabling certificate validation.
Impact
An attacker on the WAN side can execute arbitrary code as root on the router without authentication, leading to full compromise.
What the attacker needed
Attacker controls DNS or TCP redirection; attacker can serve HTTPS with self-signed cert; router uses default configuration
The fix
Netgear patched the vulnerability in version 1.0.4.126 by removing the -k option from curl and limiting the sscanf format specifiers to 255 characters.
How it was found
- Configure the router to use an attacker-controlled DNS server so queries for the update server resolve to the attacker's server.
- Serve a malicious circleinfo.txt file from the attacker's HTTPS server (a self-signed certificate is accepted because curl uses -k).
- The circled daemon downloads the file and parses it, triggering the stack buffer overflow.
- Use the overflow to overwrite saved registers and redirect execution to a gadget that calls system with a controlled argument.
- Brute-force heap addresses to locate the attacker's shell commands in memory, relying on the daemon restarting after each crash.
- Once the correct address is found, the shell commands execute and a reverse shell is obtained.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
The router runs a small program that regularly downloads a text file from the internet to check for updates. That program reads the file into a fixed-size memory area without checking if the file is too long, so a longer file spills over into nearby memory. Because the program also does not verify the identity of the server it downloads from, an attacker who can redirect the router's internet traffic can supply a malicious file and take control of the router.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.