Uncovering Openwrt Remote Code Execution (CVE-2020-7982)
The opkg package manager on OpenWrt failed to verify the SHA256 hash of downloaded packages because a parsing bug caused the hash field to be silently skipped. An attacker who could intercept or redirect the HTTP connection to the package server could serve a malicious package that would be installed and executed.
blog.forallsecure.com
Published on blog.forallsecure.com
For ForAllSecure, I’ve been focusing on finding bugs in OpenWRT using their Mayhem software. My research on OpenWRT has been a combination of writing custom harnesses, running binaries of the box without recompilation, and manual inspection of code.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
The hash decoding function advanced a pointer past leading spaces but then decoded from the original start of the string, so the leading space made decoding fail and the hash was never stored, silently bypassing verification.
Impact
An attacker able to intercept or redirect the device's HTTP traffic to the package server could get a malicious package installed and executed, though the file size must match the value in the package list.
What the attacker needed
Attacker intercepts or controls DNS for the package host; package size must match the list entry; device runs a vulnerable OpenWrt version
How it was found
- Point the package server hostname at an attacker-controlled web server, for example by editing the hosts file to emulate a man-in-the-middle.
- Mirror the signed package lists and download the original package to learn its expected size.
- Build a replacement package containing a malicious binary and pad it with zero bytes so its size matches the Size field.
- Serve the mirrored lists and the tampered package from the web server.
- On the device, run the package list update and install the package, which then executes the malicious binary.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
When you install software on a router, the package manager is supposed to check a fingerprint (a hash) to make sure the file is genuine. Here a small coding mistake meant that check was skipped entirely, so a tampered file could be installed and run as if it came from the official source.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.