#!/bin/bash #: Title : asroot #: Date Created: Fri Nov 19 16:34:25 CST 2010 #: Last Edit : Mon Nov 7 20:32:25 CST 2011 #: Author : James D. McDaniel #: Version : 1.14 #: Description : run a program as root using an existing encoded password file #: Options : asroot program [options if any], Example: asroot fdisk -l TITLE="ASROOT - Run a Program as a Root User - Version 1.14" # !Warning! !Warning! !Warning! !Warning! !Warning! !Warning! !Warning! !Warning! # # !Warning! its easy for anyone to decode ************************************* # the password file if they have this script! ********************************* # You have only the illusion of security here! ******************************** # # # Written for the openSUSE forums on Monday November 7, 2011 # # # Copy and Paste the text of this script into a text editor and save # it as the file asroot in the folder ~/bin (/home/username/bin/asroot). # This script must be marked executable to be used. Please run # the following Terminal command: chmod +x ~/bin/asroot # # # Where to save your encoded password file ************************************ # Do not add a / at the end of the folder name! ******************************* # pwd_folder="$HOME/Documents" # # What to call your encoded password file ************************************* # You may want to change this name on your system ***************************** # pwd_file="136281aBeqWa2417a890112" # # Do you want to see asroot in color? **************************************** # The default is true, but can be set to false ******************************** # use_color=true # # This is the standard GPL Statement, leave at the top of the script. ********* # Just use the command show_gpl after this function for it to be shown. ******* # function show_gpl { echo "" echo " asroot is a bash script file written to be used with" echo " openSUSE. Copyright (C) 2011 by James D. McDaniel," echo " email address: jmcdaniel3@austin.rr.com" echo "" echo " This program is free software; you can redistribute" echo " it and/or modify it under the terms of the GNU General" echo " Public License as published by the Free Software " echo " Foundation; either version 2 of the License, or (at" echo " your option) any later version." echo "" echo " This program is distributed in the hope that it" echo " will be useful, but WITHOUT ANY WARRANTY; without" echo " even the implied warranty of MERCHANTABILITY or" echo " FITNESS FOR A PARTICULAR PURPOSE. See the GNU" echo " General Public License for more details." echo "" echo " You should have received a copy of the GNU General" echo " Public License along with this program; if not, write" echo " to the Free Software Foundation, Inc., 59 Temple Place," echo " Suite 330, Boston, MA 02111-1307 USA" echo "" return 0 } # # Color Display Request - color forground background [b/n] ******************** # # 0:Black 1:Blue 2:Green 3:Cyan 4:Red 5:Magenta 6:Yellow 7:White function color { if [[ $3 == [Bb] ]] ; then tput bold fi if [[ $3 == [Nn] ]] ; then tput sgr0 fi if $use_color ; then tput setf $(( $1 )) tput setb $(( $2 )) else tput setf 7 tput setb 0 fi return 0 } # # Show the Program Title ****************************************************** # function header { dash="------------------------------------------------------" tput clear color 2 0 B echo " $dash" echo -n " " color 7 2 B echo " $TITLE " color 2 0 B echo " $dash" color 7 0 B } # # Create a New Password File *************************************************** # function new_pw { echo echo -n "Please enter the root user password: " read -s password echo $password | base64 > "$pwd_folder/$pwd_file" echo } # # Delete Existing Password File *********************************************** # function delete_pw { header if [ -e "$pwd_folder/$pwd_file" ] ; then rm "$pwd_folder/$pwd_file" echo echo "The Password File $pwd_file was removed." echo fi } # # asroot Help Display Function ************************************************ # function help { header color 4 0 B cat << EOFHELP !Warning! !Warning! !Warning! !Warning! !Warning! EOFHELP color 7 0 B cat << EOFHELP It is easy for anyone to decode the password file if they have this script! You have only the illusion of security here! asroot allows you to run a program (with options) as a root user. The password is encoded in base 64 in the location and file name of your selection in the script. If you have never ran asroot before, use the example command shown below first and create your new password file. asroot is intended to work with terminal commands. assroot can be used in other script files that run in terminal. asroot program [options] ( Example: asroot fdisk -l ) asroot x [y] ; x=Program to run as root y=option(s) for program x asroot -r ; Remove the Password File asroot -p ; Remove the Password File & Enter new Password asroot -h ; Shows this help asroot --help ; Shows this help EOFHELP echo -n " Press to read the GPL Statement for asroot " read CHOICE tput clear color 7 0 B show_gpl color 7 0 N exit 0 } # # asroot help and options request ********************************************* # case "$1" in -h|--help) help ;; -r) delete_pw show_gpl exit 0 ;; -p) delete_pw new_pw show_gpl exit 0 ;; "") help ;; esac # # Determine if the package coreutils is installed ***************************** # which base64 > /dev/null Exit_Code=$? if [ $(( Exit_Code )) -ge 1 ] ; then header echo echo "The coreutils Utility Package is not installed!" echo echo -n "Would you like to install the coreutils package (y/N)? " read CHOICE if [[ $CHOICE == [Yy] ]] ; then sudo zypper in coreutils else echo "The coreutils Utility Package was not installed!" exit 1 fi fi # # Check to see if the password file exists and create it if not *************** # if [ ! -e "$pwd_folder/$pwd_file" ] ; then header echo echo "The password file $pwd_file does not exist!" new_pw fi # # Lets add the /sbin and /bin folders to our path ***************************** # PATH=/sbin:/bin:$PATH # # This is the proper way to feed the password into sudo *********************** # sudo -k base64 -d "$pwd_folder/$pwd_file" | sudo -v -S sudo $@ Exit_Code=$? exit $Exit_Code # End Of Script