

This repository documents the comprehensive reverse engineering and exploitation of CVE-2019-17147, a critical remote code execution (RCE) vulnerability in the TP-Link TL-WR841N router (MIPSEL architecture). The vulnerability resides in the httpd web server daemon, where improper input validation allows for a Stack Buffer Overflow via a custom cstr_strncpy function, leading to arbitrary code execution without authentication.
| Vulnerability | CVE-2019-17147 |
|---|---|
| CVSS v3.1 | 8.8 (High) |
| Vector | AV:A/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H |
| Type | Stack-based Buffer Overflow |
| Component | /usr/bin/httpd |
The analysis environment was established using the following components:
flashrom (Memory dumping), binwalk (Firmware extraction), IDA Pro (Static analysis), GDB-Multiarch (Remote debugging), QEMU (MIPSEL Emulation).TL-WR841N(US)_V14_180319.The vulnerability was identified in the /usr/bin/httpd binary. Static analysis via IDA Pro revealed a custom string copy function, cstr_strncpy, used during HTTP header parsing (specifically the Host header).

The function cstr_strncpy accepts a copy_len parameter derived from the source string length rather than the destination buffer size. This allows a classic stack buffer overflow when an overly long header is supplied. Furthermore, the http_parser_argStrToList function, which manipulates a linked list structure, is affected by this overflow, granting control over next and prev pointers.
Runtime debugging with gdbserver confirmed the crash and control over the execution flow. The memory map (vmmap) analysis revealed a critical lack of hardening:

This configuration permits the direct execution of shellcode placed on the Heap, bypassing the need for complex ROP chains.
The exploit chain utilizes a Write-What-Where primitive derived from the corrupted linked list pointers to achieve RCE.
strcpy, the payload is sent in multiple requests:
atol function entry in the Global Offset Table (GOT) is overwritten with the address of the shellcode.atol (via a Content-Length header), redirecting execution to the injected shellcode.
The final Python script successfully automates the attack, spawning a root shell on port 31337.

The vulnerability stems from insecure coding practices in buffer management.
cstr_strncpy usage with secure alternatives that strictly enforce destination buffer limits (e.g., strncpy with explicit bounds check based on sizeof(dest)).For a detailed step-by-step walkthrough of the entire process, including code analysis and environment setup, please refer to the full guides included in this repository:
This project is for educational and research purposes only. The information provided is intended to improve the security of IoT devices. The authors are not responsible for any misuse of the information or code contained herein.
Based on original research and analysis.