Skip to content
Memory corruption Write-up Advanced

[Debug/Exploit CVE-2022-24355] TP-Link TL-WR940N Stack-based Buffer Overflow

The httpd binary on the TP-Link TL-WR940N router copies a filename taken from an HTTP request into a fixed stack buffer without checking its length, so a long value overflows the stack. An attacker could overwrite the saved return address and run their own code on the device.

Mohamed Sayed Follow

Published on flex0geek.blogspot.com

on April 20, 2024

Mohamed Sayed (Flex), on flex0geek.blogspot.com

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

Likely the httpRpmFs function copies a user-supplied filename into a fixed-size stack buffer without limiting the length, and the fixed version adds a check that stops copying after six characters.

Impact

An attacker could achieve code execution on the router, but the exploit was only demonstrated in an emulated environment and the text does not claim it works on real hardware.

What the attacker needed

Network access to the router's web interface; a request with a crafted cookie value; emulated or real device running vulnerable firmware

How it was found

  1. Emulate the vulnerable firmware with firmadyne and start it under QEMU with ASLR disabled.
  2. Add a MIPS gdbserver to the emulated file system using the mount and umount scripts.
  3. Log in to the router and change the admin password.
  4. Send an HTTP request to the loginFs path with a long run of characters in the cookie to trigger the crash.
  5. Use the crash to overwrite the return address and redirect execution to shellcode placed on the stack.
  6. Send a small first-stage shellcode that reads a second-stage payload, then interact with the resulting shell.

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.

A router runs a small web server that handles requests from your browser. One part of that server takes a file name from the request and copies it into a fixed-size space in memory without checking how long it is. If the name is much longer than the space, it spills over into nearby memory, including the address the program uses to decide where to continue, which lets an attacker redirect it to their own code.

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.

More by Mohamed Sayed

View all

9 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.