leonteale

LinEsc.sh

Jan 17th, 2014
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.11 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # A script designed to help aid in the process of escalating a user privalage to root!
  4. #
  5. #
  6. # Usage = ./LinEsc
  7. #
  8. # Leon Teale (@leonteale)
  9.  
  10. ## Setting Coloured variables
  11. red=`echo -e "\033[31m"`
  12. lcyan=`echo -e "\033[36m"`
  13. yellow=`echo -e "\033[33m"`
  14. green=`echo -e "\033[32m"`
  15. blue=`echo -e "\033[34m"`
  16. purple=`echo -e "\033[35m"`
  17. normal=`echo -e "\033[m"`
  18.  
  19. #Funcetions
  20. header () {
  21.             clear
  22.             echo "$yellow  _      _       ______          "
  23.             echo " | |    (_)     |  ____|         "
  24.             echo " | |     _ _ __ | |__   ___  ___ "
  25.             echo " | |    | | '_ \|  __| / __|/ __|"
  26.             echo " | |____| | | | | |____\__ \ (__ "
  27.             echo " |______|_|_| |_|______|___/\___|$normal"
  28.             echo " "  
  29.             echo "A script designed to aid the process of escilating user privalage to root"
  30.             echo ""
  31.         }
  32.  
  33.  
  34.  
  35. # Check that the user isnt  already root or running script as root
  36. sudo_check () {
  37.     if [ "$(id -u)" == "0" ]; then
  38.         echo "$green You  already have root access! :D$normal" 1>&2
  39.         exit 1
  40.         echo ""
  41.     fi
  42. }
  43.  
  44. info () {
  45.             echo "$yellow Current User$normal :  `whoami`"
  46.             echo "$yellow uid/gid/group$normal:  `id 2>/dev/null`"
  47.             echo "$yellow System  Info$normal :  `uname -a`"
  48.             echo "$yellow Distribution$normal :  `cat /etc/issue`"
  49.             echo "$yellow Hostname $normal    :  `hostname`"
  50.             echo ""        
  51. }
  52.  
  53. # Check to see what sudo access the user has been granted
  54. sudo_script_access  () {
  55.                         CAN_I_RUN_SUDO=$(sudo -n uptime 2>&1|grep "load"|wc -l)
  56.                         if [ ${CAN_I_RUN_SUDO} -gt 0 ]; then
  57.                             if  sudo -l  | grep "may run the following commands on this host" 2>/dev/null;  then
  58.                                 echo "This user has access to $green"
  59.                                 sudo -l | grep root
  60.                                 echo "$normal"
  61.                             fi
  62.                         else
  63.                             echo "$red  Current user has no sudo access$normal"
  64.                             echo ""
  65.                         fi 
  66. }
  67.  
  68. # Check for suid files
  69. suid () {      
  70.             if  find / -perm -4000 -type f 2>/dev/null | grep -w 'nmap\|perl\|'awk'\|'find'\|'bash'\|'sh'\|'man'\|'more'\|'less'\|'vi'\|'vim'\|'nc'\|'netcat'\|python\|ruby\|lua\|irb\|pl'  ; then
  71.                 echo "$yellow  Possibly  interesting suid files: $green"
  72.                 find / -perm -4000 -type f 2>/dev/null | grep -w 'nmap\|perl\|'awk'\|'find'\|'bash'\|'sh'\|'man'\|'more'\|'less'\|'vi'\|'vim'\|'nc'\|'netcat'\|python\|ruby\|lua\|irb\|pl'
  73.                 echo "$normal"
  74.             fi
  75.                 echo "$yellow uid files found$normal"
  76.                 find / -xdev \( -perm -4000 \) -type f -print0 2>/dev/null | xargs -0 ls -l
  77.                 echo ""
  78.         }
  79.  
  80. # Check for world writable and executable files
  81. wre () {
  82.             echo "$yellow world writable & executable files found$normal"
  83.             find / -perm -0002  -type f 2>/dev/null | grep -vE 'proc'
  84.             echo " "
  85.        }
  86.  
  87. # Check /etc/passwd for passwords
  88. passwd () {
  89.             passwd_check=$(cat /etc/passwd | cut -d : -f 2 |  grep  -vE 'x' | wc -l)
  90.                 if [ ${passwd_check} -gt 0 ]; then
  91.                     echo "$yellow Possible password(s) found in /etc/passwd$green"
  92.                     grep `cat /etc/passwd | cut -d : -f 2 |  grep  -w -vE 'x'` /etc/passwd
  93.                     echo "$normal"
  94.                 fi
  95. }
  96.  
  97. file_access () {
  98. echo ""
  99.  
  100. }
  101.  
  102.  
  103.  
  104. # Run the script
  105. header
  106. sudo_check
  107. info
  108. sudo_script_access
  109. suid
  110. wre
  111. passwd
Advertisement
Add Comment
Please, Sign In to add comment