Skip to content
RCE Write-up Intermediate

CVE-2021-31607 SaltStack Minion Privledge Escaltion in Snapper Module

A command injection vulnerability existed in SaltStack's snapper module where a filename was passed unsanitised to a shell command, allowing an attacker who could create a file to execute arbitrary commands when the master requested a diff. This could lead to privilege escalation on the minion.

sec.stealthcopter.com

Published on sec.stealthcopter.com

I discovered a command injection vulnerability in SaltStack’s Salt that allows privilege escalation using malicious filenames on a minion when the master calls snapper.diff. But… I was too slow!

The author, on sec.stealthcopter.com

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 filename was interpolated directly into a shell command string passed to os.popen, allowing shell metacharacters to inject commands.

Impact

An attacker with the ability to create files on the minion could execute arbitrary commands, leading to privilege escalation.

What the attacker needed

Snapper installed and configured on minion; Master uses snapper module to request diff; Attacker can create files on minion

The fix

The fix replaced os.popen with subprocess.run and passed arguments as a list to prevent command injection.

How it was found

  1. Create a text file with a filename containing a command injection payload.
  2. Wait for the master to request a diff using the snapper.diff command.
  3. The injected command executes on the minion.

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.

This bug is like leaving a door unlocked: the Salt software ran a system command to check a file's type, but it didn't properly handle special characters in the filename. An attacker who can create a file with a tricky name could make the system run their own commands, potentially taking over the machine.

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.