# DrayTek Vigor2960 Authenticated set_table JSONData Command Injection - Product: DrayTek Vigor2960 - Firmware: Vigor2960 1.5.1.6 (revision 8218) - Vulnerability Title: Authenticated set_table JSONData Command Injection - Case ID: DRV2960-0006 ## 1. Executive Summary The `jsondata` accepted by `action=set_table` is deeply parsed, and the `sectiontype` field reaches later UCI/shell command construction. The current PoC confirms command execution on the real device by setting `apmd.general.codexpoc=hit`. - Affected path(s): - `POST /cgi-bin/mainfunction.cgi` with `action=set_table` - Root cause: - The parsed `jsondata.sectiontype` value is inserted into command construction and reaches `system()` without shell-safe isolation. - Confirmed impact: - An authenticated attacker can inject arbitrary shell commands through `jsondata` and execute them with the CGI process privileges on the device. ## 2. Preconditions - An authenticated administrator session is required. - The PoC reads and removes a UCI marker over SSH by default, so device SSH/CLI access must be available. ## 3. Root Cause Analysis - Binary: `www/cgi-bin/mainfunction.cgi`. - Route entry: `main` (`0x239B4`) dispatches `action=set_table` into `sub_26520` (`0x26520`). - Attacker-controlled input: `sub_26520` (`0x26520`) reads `jsondata`. - JSON parsing and dispatch: `sub_261D4` (`0x261D4`) extracts per-item fields and forwards them into the later configuration path. - Final command execution: `sub_23394` (`0x23394`). ```c int sub_26520() { jsondata = cgiGetValue("jsondata"); parsed = json_loads(jsondata, ...); return sub_261D4(parsed, ...); } int sub_261D4(...) { item = json_array_get(parsed, i); sectiontype = json_string_value(json_object_get(item, "sectiontype")); ... return sub_23394(..., sectiontype, ...); } int sub_23394(...) { snprintf(cmd, sizeof(cmd), "uci set ... %s ...", sectiontype); system(cmd); } ``` This is not a trivial string pass-through. The value first goes through JSON parsing and is then dispatched by `sub_261D4()` into a later configuration-handling path. The current PoC chooses a low-side-effect payload: it replaces `sectiontype` with `status;uci set apmd.general.codexpoc=hit;uci commit apmd;#` and reads the UCI key back over SSH. ## 4. Impact and Boundaries ### 4.1 Confirmed impact - Execution of an attacker-controlled shell fragment is confirmed on the real device. - The PoC removes the temporary UCI marker after verification to avoid leaving the device in a dirty state. ### 4.2 Currently confirmed limitations - The current PoC requires authenticated access to the management action. - The current success criterion depends on reading the UCI marker back over CLI/SSH. ## 5. What `poc.py` Does 1. First, clean up any previous `apmd.general.codexpoc` marker. 2. Log in and send a `set_table` request with malicious `jsondata`. 3. Read `uci get apmd.general.codexpoc` over SSH and then remove that marker again. This proves: - A field inside `jsondata` reaches shell-level execution. - The issue is not just theoretical reachability; it has an observable effect on the real device. ## 6. PoC Usage ```bash python3 poc.py ``` - If the target address or credentials differ, override the defaults with `--host`, `--web-username`, `--web-password`, and `--ssh-password`. ## 7. What Output Indicates Success - The terminal ends with `[SUCCESS] Injected set_table payload created apmd.general.codexpoc=hit ...`. - The `uci_get` output contains a standalone `hit` line. ## 8. Remediation - Do not construct UCI commands through a shell; call the UCI library directly or execute a fixed program with an argument array that bypasses shell parsing. - Apply strict character-set and length allowlists to `config`, `table`, and `option` identifiers instead of relying on quoting.