Ian Dunn · Report #1785378
Double evaluation in .bash_prompt of dotfiles allows a malicious repository to execute arbitrary commands
How it was found
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.
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.
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
- Set up dotfiles. (For the minimal setup, I used {F2051541} to set up
.bash_prompt.) - Create a git repository with a crafted name:
git init -b '$(touch${IFS}/tmp/pwned)' repo - Enter the repository:
cd repo - Confirm that
touch /tmp/pwnedis executed.
{F2051546}
Impact
An attacker can execute arbitrary commands by tricking the victim into entering a malicious directory.