Skip to content
RCE Write-up Advanced

Remote Code Execution in Alpine Linux

The apk package manager extracted package files before verifying their hash, allowing a man-in-the-middle or malicious mirror to write arbitrary files. By creating a persistent commit hook, an attacker could execute code on the user's machine.

justi.cz

Published on justi.cz

tl;dr I found several bugs in apk, the default package manager for Alpine Linux. Alpine is a really lightweight distro that is very commonly used with Docker.

The author, on justi.cz

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

Impact

A network man-in-the-middle or malicious package mirror could execute arbitrary code on the user's machine, and the attacker could also make apk exit with code 0 so Docker builds succeed.

What the attacker needed

Network man-in-the-middle or malicious mirror; apk installs packages over HTTP

The fix

The bug was fixed by changing apk to verify the package hash before extracting files.

How it was found

  1. Create a folder at /etc/apk/commit_hooks.d/ via the archive.
  2. Create a symlink named link pointing to /etc/apk/commit_hooks.d/x.
  3. Create a regular file named link to write through the symlink and create the payload file.
  4. When apk detects the hash mismatch, it unlinks link.apk-new but the payload file persists.
  5. The commit hook executes before apk exits.

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 Linux, the package manager downloads files and checks they are genuine. Here, it unpacked the files before checking, so someone tampering with the download could sneak in a file that runs automatically. That let them run their own code on your computer.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.