Skip to content
RCE Write-up Beginner

Abstract #

The OhMyZsh dotenv plugin used the shell's source command to load .env files, so a malicious .env file could execute arbitrary commands when a user changed into the project directory. An attacker could compromise a user's machine by distributing a malicious repository or compressed file.

mazinahmed.net

Published on mazinahmed.net

OhMyZsh was vulnerable to an RCE (Remote Code Execution) vulnerability due to arbitrarily trusting ENV files in the dotenv plugin. Users downloading a malicious repository or a compressed file can have their machines compromised due to the vulnerability.

Mazin Ahmed, on mazinahmed.net

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 plugin used the shell's source built-in to load .env files, which executes their contents as shell code instead of parsing them as data.

Impact

An attacker could achieve remote code execution on a victim's machine, as demonstrated by commands running with root privileges.

What the attacker needed

OhMyZsh with dotenv plugin enabled; victim downloads and enters malicious project

The fix

The fix prompts the user to confirm sourcing the .env file and adds a trust-on-first-use option for trusted paths; it was merged into the master branch.

How it was found

  1. Download a malicious repository or compressed file containing a crafted .env file.
  2. Extract the archive and change into the project directory.
  3. The dotenv plugin sources the .env file, executing the attacker's commands.

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.

OhMyZsh is a tool that customises the Z shell (a command-line interface). Its dotenv plugin automatically reads a file called .env when you enter a project folder, but it used a shell feature that runs the file's contents as commands rather than just reading values. So a booby-trapped .env file could run any command on your computer as soon as you entered the folder.

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.