D-Link DIR-3040 prog.cgi SetWan3Settings Stack-Based Buffer Overflow Remote Code Execution Vulnerability
The prog.cgi binary on D-Link DIR-3040 routers copies a user-supplied string into a fixed-size stack buffer without proper validation. An authenticated, network-adjacent attacker could exploit this to execute arbitrary code as root.
Originally disclosed on Zero Day Initiative
This vulnerability allows network-adjacent attackers to execute arbitrary code on affected installations of D-Link DIR-3040 routers. Authentication is required to exploit this vulnerability.
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 report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely a missing length check when copying a user-supplied string into a fixed-size stack buffer in the prog.cgi HNAP handler.
Impact
An authenticated, network-adjacent attacker could execute arbitrary code with root privileges on the router.
What the attacker needed
Network-adjacent access; valid authentication
The fix
D-Link issued an update to correct the vulnerability.
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 report has not been written yet. The Original tab links to the source.
A buffer is a small reserved area of memory. This router program takes a string from a request and copies it into a fixed-size buffer without checking its length, so a longer string spills over into nearby memory. An attacker who is already logged in and close to the network could use that overflow to run their own commands on the router with the highest privileges.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.