Remote code execution vulnerability in apt/apt-get
A network man-in-the-middle or malicious package mirror could inject a crafted redirect response into apt's HTTP worker, causing apt to trust attacker-supplied hashes and install a forged package. This allowed arbitrary code execution as root during package installation.
justi.cz
Published on justi.cz
tl;dr I found a vulnerability in apt that allows a network man-in-the-middle (or a malicious package mirror) to execute arbitrary code as root on a machine installing any package. The bug has been fixed in the latest versions of apt.
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 HTTP fetcher process URL-decoded the Location header and appended it without sanitising newline characters, allowing injection of fake protocol messages into the parent process.
Impact
An attacker could execute arbitrary code as root on any machine installing packages over HTTP, though the text notes that using HTTPS repositories would prevent this specific exploit.
What the attacker needed
Network man-in-the-middle or malicious mirror; apt uses HTTP repositories
The fix
The vulnerability was fixed in the latest versions of apt.
How it was found
- Set up a malicious HTTP server or intercept traffic to return a redirect with a crafted Location header.
- The Location header contains URL-encoded newlines and a fake 201 URI Done message with attacker-controlled hashes.
- apt's HTTP worker decodes the header and sends the injected message to the parent process.
- The parent process trusts the injected hashes and accepts the malicious package.
- The attacker also prepends the malicious .deb to the Release.gpg file so it is available at a predictable path.
- apt installs the forged package and executes its code as root.
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.
apt is the tool that downloads and installs software packages on Debian and Ubuntu. When it downloads a package, it talks to a helper program that handles HTTP. The helper did not properly clean up a redirect address from the server, so an attacker who controls the network or the server could sneak extra instructions into the conversation. That let the attacker make apt accept a fake package and run its code with full system rights.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.