Skip to content
RCE Disclosed report Intermediate

Double evaluation in .bash_prompt of dotfiles allows a malicious repository to execute arbitrary commands

The dotfiles .bash_prompt script builds the shell prompt by embedding the output of git and svn status commands into PS1, which bash then re-evaluates. A malicious repository with a crafted branch name can therefore run arbitrary commands when the victim changes into that directory.

ryotak Follow

Originally disclosed on HackerOne

  • Triaged in 18 hours
  • Fixed in 3 days
  • Paid in 18 hours
  • Disclosed after 3 days

Summary

Due to the improper usage of the PS1 environment variable in .bash_prompt of dotfiles, a malicious repository can execute arbitrary commands when changed the current directory to it.

Description

The PS1 environment variable of bash supports command substitutions. For example, setting PS1 to $(echo hello) executes echo hello each time the prompt is displayed.

Because .bash_prompt of dotfiles uses the following code to display the VCS information, if any outputs of these commands contain command substitution syntaxes, it'll be evaluated while printing the prompt.

.bash_prompt line 264-266

Bash
	export PS1="\n${command_mark}${color_user_host}\u${color_reset} @ ${color_user_host}$hostname${color_reset} in ${color_folder}\w${color_reset} \
	$(vcs_prompt) \
	\n> "

Since vcs_prompt contains the information of Git or SVN, a malicious repository with a crafted branch name can execute arbitrary commands.

.bash_prompt line 241-254

Bash
function vcs_prompt {
	GIT_PROMPT=$(git_status)
	SVN_PROMPT=$(svn_status)

	if [[ -n $GIT_PROMPT ]]; then
		echo -n "\n$GIT_PROMPT"

		if [[ -n $SVN_PROMPT ]]; then
			echo -n ", $SVN_PROMPT"
		fi
	elif [[ -n $SVN_PROMPT ]]; then
		echo "\n$SVN_PROMPT"
	fi
}

Steps to reproduce

  1. Set up dotfiles. (For the minimal setup, I used (Attachment on the original report: setup.sh) to set up .bash_prompt.)
  2. Create a git repository with a crafted name: git init -b '$(touch${IFS}/tmp/pwned)' repo
  3. Enter the repository: cd repo
  4. Confirm that touch /tmp/pwned is executed.
2022-11-28_13-27-48.mp4 From the original on HackerOne

Impact

An attacker can execute arbitrary commands by tricking the victim into entering a malicious directory.

The original report as published on HackerOne, by ryotak. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The script places untrusted repository data (branch names) into PS1, which bash evaluates for command substitutions, causing a second round of evaluation.

Impact

An attacker can execute arbitrary commands by tricking the victim into entering a malicious directory.

What the attacker needed

Dotfiles .bash_prompt installed; victim enters a malicious repository

How it was found

  1. Set up the dotfiles so that .bash_prompt is loaded.
  2. Create a git repository whose branch name contains command substitution syntax.
  3. Change into that repository directory.
  4. Observe that the embedded command has been executed.

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 report has not been written yet. The Original tab links to the source.

Your shell prompt is the text shown before each command you type. This script puts information from the current git repository into that prompt, and the shell then treats parts of that text as commands to run. So a repository whose branch name looks like a command can make your computer run that command just by you entering 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.

More by ryotak

View all

23 more disclosed reports, best first.

More from Ian Dunn

View all

The newest disclosed reports for this program.

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.