Skip to content
RCE Write-up Advanced

Reversing, Discovering, And Exploiting A TP-Link Router Vulnerability — CVE-2024–54887

A stack buffer overflow in the TP-Link TL-WR940N router's IPv6 tunnelling configuration allows an authenticated attacker to overwrite saved registers and the return address, leading to remote code execution. The author develops a working exploit using ROP and custom MIPS shellcode.

Joward Follow

Published on infosecwriteups.com

Recently, I picked up an interest in reverse engineering and exploit development. After a while, picking at Hack The Box challenges can get tired, and I started looking for a more interesting real world target.

Joward, on infosecwriteups.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

The dnsserver1 and dnsserver2 parameters are copied into a 45-byte stack buffer using strcpy() without any length validation.

Impact

An authenticated attacker could achieve remote code execution on the router, potentially leading to full compromise.

What the attacker needed

Authentication to the router's web interface; network access to the router

The fix

The vulnerability was mitigated in later hardware versions, but the text does not specify a software fix; it should be fixed by validating the length of the dnsserver1 and dnsserver2 parameters before copying.

How it was found

  1. Log in to the router's web interface.
  2. Send a request to the Wan6to4TunnelCfgRpm.htm endpoint with a long value for dnsserver1.
  3. Observe that the saved registers and return address are overwritten with controlled data.
  4. Use a cyclic pattern to determine the exact offsets for each register and the program counter.
  5. Build a ROP chain using gadgets from libuClibc to call sleep and then jump to shellcode.
  6. Send the final payload containing the ROP chain and shellcode to achieve code execution.

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's web interface has a form for setting IPv6 DNS servers. The program copies the text you type into a fixed-size memory box without checking its length, so a long input spills over into nearby memory. An attacker who can log in to the router can use this to run their own commands on the device.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.