Advertisement
Guest User

Untitled

a guest
Feb 17th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 45.88 KB | None | 0 0
  1. #!/bin/bash
  2. #A script to enumerate local information from a Linux host
  3. version="version 0.95"
  4. #@rebootuser
  5.  
  6. #help function
  7. usage ()
  8. {
  9. echo -e "\n\e[00;31m#########################################################\e[00m"
  10. echo -e "\e[00;31m#\e[00m" "\e[00;33mLocal Linux Enumeration & Privilege Escalation Script\e[00m" "\e[00;31m#\e[00m"
  11. echo -e "\e[00;31m#########################################################\e[00m"
  12. echo -e "\e[00;33m# www.rebootuser.com | @rebootuser \e[00m"
  13. echo -e "\e[00;33m# $version\e[00m\n"
  14. echo -e "\e[00;33m# Example: ./LinEnum.sh -k keyword -r report -e /tmp/ -t \e[00m\n"
  15.  
  16. echo "OPTIONS:"
  17. echo "-k Enter keyword"
  18. echo "-e Enter export location"
  19. echo "-s Supply user password for sudo checks (INSECURE)"
  20. echo "-t Include thorough (lengthy) tests"
  21. echo "-r Enter report name"
  22. echo "-h Displays this help text"
  23. echo -e "\n"
  24. echo "Running with no options = limited scans/no output file"
  25.  
  26. echo -e "\e[00;31m#########################################################\e[00m"
  27. }
  28. header()
  29. {
  30. echo -e "\n\e[00;31m#########################################################\e[00m"
  31. echo -e "\e[00;31m#\e[00m" "\e[00;33mLocal Linux Enumeration & Privilege Escalation Script\e[00m" "\e[00;31m#\e[00m"
  32. echo -e "\e[00;31m#########################################################\e[00m"
  33. echo -e "\e[00;33m# www.rebootuser.com\e[00m"
  34. echo -e "\e[00;33m# $version\e[00m\n"
  35.  
  36. }
  37.  
  38. debug_info()
  39. {
  40. echo "[-] Debug Info"
  41.  
  42. if [ "$keyword" ]; then
  43. echo "[+] Searching for the keyword $keyword in conf, php, ini and log files"
  44. fi
  45.  
  46. if [ "$report" ]; then
  47. echo "[+] Report name = $report"
  48. fi
  49.  
  50. if [ "$export" ]; then
  51. echo "[+] Export location = $export"
  52. fi
  53.  
  54. if [ "$thorough" ]; then
  55. echo "[+] Thorough tests = Enabled"
  56. else
  57. echo -e "\e[00;33m[+] Thorough tests = Disabled\e[00m"
  58. fi
  59.  
  60. sleep 2
  61.  
  62. if [ "$export" ]; then
  63. mkdir $export 2>/dev/null
  64. format=$export/LinEnum-export-`date +"%d-%m-%y"`
  65. mkdir $format 2>/dev/null
  66. fi
  67.  
  68. if [ "$sudopass" ]; then
  69. echo -e "\e[00;35m[+] Please enter password - INSECURE - really only for CTF use!\e[00m"
  70. read -s userpassword
  71. echo
  72. fi
  73.  
  74. who=`whoami` 2>/dev/null
  75. echo -e "\n"
  76.  
  77. echo -e "\e[00;33mScan started at:"; date
  78. echo -e "\e[00m\n"
  79. }
  80.  
  81. # useful binaries (thanks to https://gtfobins.github.io/)
  82. binarylist='nmap\|perl\|awk\|find\|bash\|sh\|man\|more\|less\|vi\|emacs\|vim\|nc\|netcat\|python\|ruby\|lua\|irb\|tar\|zip\|gdb\|pico\|scp\|git\|rvim\|script\|ash\|csh\|curl\|dash\|ed\|env\|expect\|ftp\|sftp\|node\|php\|rpm\|rpmquery\|socat\|strace\|taskset\|tclsh\|telnet\|tftp\|wget\|wish\|zsh\|ssh$\|ip$\|arp\|mtr'
  83.  
  84. system_info()
  85. {
  86. echo -e "\e[00;33m### SYSTEM ##############################################\e[00m"
  87.  
  88. #basic kernel info
  89. unameinfo=`uname -a 2>/dev/null`
  90. if [ "$unameinfo" ]; then
  91. echo -e "\e[00;31m[-] Kernel information:\e[00m\n$unameinfo"
  92. echo -e "\n"
  93. fi
  94.  
  95. procver=`cat /proc/version 2>/dev/null`
  96. if [ "$procver" ]; then
  97. echo -e "\e[00;31m[-] Kernel information (continued):\e[00m\n$procver"
  98. echo -e "\n"
  99. fi
  100.  
  101. #search all *-release files for version info
  102. release=`cat /etc/*-release 2>/dev/null`
  103. if [ "$release" ]; then
  104. echo -e "\e[00;31m[-] Specific release information:\e[00m\n$release"
  105. echo -e "\n"
  106. fi
  107.  
  108. #target hostname info
  109. hostnamed=`hostname 2>/dev/null`
  110. if [ "$hostnamed" ]; then
  111. echo -e "\e[00;31m[-] Hostname:\e[00m\n$hostnamed"
  112. echo -e "\n"
  113. fi
  114. }
  115.  
  116. user_info()
  117. {
  118. echo -e "\e[00;33m### USER/GROUP ##########################################\e[00m"
  119.  
  120. #current user details
  121. currusr=`id 2>/dev/null`
  122. if [ "$currusr" ]; then
  123. echo -e "\e[00;31m[-] Current user/group info:\e[00m\n$currusr"
  124. echo -e "\n"
  125. fi
  126.  
  127. #last logged on user information
  128. lastlogedonusrs=`lastlog 2>/dev/null |grep -v "Never" 2>/dev/null`
  129. if [ "$lastlogedonusrs" ]; then
  130. echo -e "\e[00;31m[-] Users that have previously logged onto the system:\e[00m\n$lastlogedonusrs"
  131. echo -e "\n"
  132. fi
  133.  
  134. #who else is logged on
  135. loggedonusrs=`w 2>/dev/null`
  136. if [ "$loggedonusrs" ]; then
  137. echo -e "\e[00;31m[-] Who else is logged on:\e[00m\n$loggedonusrs"
  138. echo -e "\n"
  139. fi
  140.  
  141. #lists all id's and respective group(s)
  142. grpinfo=`for i in $(cut -d":" -f1 /etc/passwd 2>/dev/null);do id $i;done 2>/dev/null`
  143. if [ "$grpinfo" ]; then
  144. echo -e "\e[00;31m[-] Group memberships:\e[00m\n$grpinfo"
  145. echo -e "\n"
  146. fi
  147.  
  148. #added by phackt - look for adm group (thanks patrick)
  149. adm_users=$(echo -e "$grpinfo" | grep "(adm)")
  150. if [[ ! -z $adm_users ]];
  151. then
  152. echo -e "\e[00;31m[-] It looks like we have some admin users:\e[00m\n$adm_users"
  153. echo -e "\n"
  154. fi
  155.  
  156. #checks to see if any hashes are stored in /etc/passwd (depreciated *nix storage method)
  157. hashesinpasswd=`grep -v '^[^:]*:[x]' /etc/passwd 2>/dev/null`
  158. if [ "$hashesinpasswd" ]; then
  159. echo -e "\e[00;33m[+] It looks like we have password hashes in /etc/passwd!\e[00m\n$hashesinpasswd"
  160. echo -e "\n"
  161. fi
  162.  
  163. #contents of /etc/passwd
  164. readpasswd=`cat /etc/passwd 2>/dev/null`
  165. if [ "$readpasswd" ]; then
  166. echo -e "\e[00;31m[-] Contents of /etc/passwd:\e[00m\n$readpasswd"
  167. echo -e "\n"
  168. fi
  169.  
  170. if [ "$export" ] && [ "$readpasswd" ]; then
  171. mkdir $format/etc-export/ 2>/dev/null
  172. cp /etc/passwd $format/etc-export/passwd 2>/dev/null
  173. fi
  174.  
  175. #checks to see if the shadow file can be read
  176. readshadow=`cat /etc/shadow 2>/dev/null`
  177. if [ "$readshadow" ]; then
  178. echo -e "\e[00;33m[+] We can read the shadow file!\e[00m\n$readshadow"
  179. echo -e "\n"
  180. fi
  181.  
  182. if [ "$export" ] && [ "$readshadow" ]; then
  183. mkdir $format/etc-export/ 2>/dev/null
  184. cp /etc/shadow $format/etc-export/shadow 2>/dev/null
  185. fi
  186.  
  187. #checks to see if /etc/master.passwd can be read - BSD 'shadow' variant
  188. readmasterpasswd=`cat /etc/master.passwd 2>/dev/null`
  189. if [ "$readmasterpasswd" ]; then
  190. echo -e "\e[00;33m[+] We can read the master.passwd file!\e[00m\n$readmasterpasswd"
  191. echo -e "\n"
  192. fi
  193.  
  194. if [ "$export" ] && [ "$readmasterpasswd" ]; then
  195. mkdir $format/etc-export/ 2>/dev/null
  196. cp /etc/master.passwd $format/etc-export/master.passwd 2>/dev/null
  197. fi
  198.  
  199. #all root accounts (uid 0)
  200. superman=`grep -v -E "^#" /etc/passwd 2>/dev/null| awk -F: '$3 == 0 { print $1}' 2>/dev/null`
  201. if [ "$superman" ]; then
  202. echo -e "\e[00;31m[-] Super user account(s):\e[00m\n$superman"
  203. echo -e "\n"
  204. fi
  205.  
  206. #pull out vital sudoers info
  207. sudoers=`grep -v -e '^$' /etc/sudoers 2>/dev/null |grep -v "#" 2>/dev/null`
  208. if [ "$sudoers" ]; then
  209. echo -e "\e[00;31m[-] Sudoers configuration (condensed):\e[00m$sudoers"
  210. echo -e "\n"
  211. fi
  212.  
  213. if [ "$export" ] && [ "$sudoers" ]; then
  214. mkdir $format/etc-export/ 2>/dev/null
  215. cp /etc/sudoers $format/etc-export/sudoers 2>/dev/null
  216. fi
  217.  
  218. #can we sudo without supplying a password
  219. sudoperms=`echo '' | sudo -S -l -k 2>/dev/null`
  220. if [ "$sudoperms" ]; then
  221. echo -e "\e[00;33m[+] We can sudo without supplying a password!\e[00m\n$sudoperms"
  222. echo -e "\n"
  223. fi
  224.  
  225. #check sudo perms - authenticated
  226. if [ "$sudopass" ]; then
  227. if [ "$sudoperms" ]; then
  228. :
  229. else
  230. sudoauth=`echo $userpassword | sudo -S -l -k 2>/dev/null`
  231. if [ "$sudoauth" ]; then
  232. echo -e "\e[00;33m[+] We can sudo when supplying a password!\e[00m\n$sudoauth"
  233. echo -e "\n"
  234. fi
  235. fi
  236. fi
  237.  
  238. ##known 'good' breakout binaries (cleaned to parse /etc/sudoers for comma separated values) - authenticated
  239. if [ "$sudopass" ]; then
  240. if [ "$sudoperms" ]; then
  241. :
  242. else
  243. sudopermscheck=`echo $userpassword | sudo -S -l -k 2>/dev/null | xargs -n 1 2>/dev/null|sed 's/,*$//g' 2>/dev/null | grep -w $binarylist 2>/dev/null`
  244. if [ "$sudopermscheck" ]; then
  245. echo -e "\e[00;33m[-] Possible sudo pwnage!\e[00m\n$sudopermscheck"
  246. echo -e "\n"
  247. fi
  248. fi
  249. fi
  250.  
  251. #known 'good' breakout binaries (cleaned to parse /etc/sudoers for comma separated values)
  252. sudopwnage=`echo '' | sudo -S -l -k 2>/dev/null | xargs -n 1 2>/dev/null | sed 's/,*$//g' 2>/dev/null | grep -w $binarylist 2>/dev/null`
  253. if [ "$sudopwnage" ]; then
  254. echo -e "\e[00;33m[+] Possible sudo pwnage!\e[00m\n$sudopwnage"
  255. echo -e "\n"
  256. fi
  257.  
  258. #who has sudoed in the past
  259. whohasbeensudo=`find /home -name .sudo_as_admin_successful 2>/dev/null`
  260. if [ "$whohasbeensudo" ]; then
  261. echo -e "\e[00;31m[-] Accounts that have recently used sudo:\e[00m\n$whohasbeensudo"
  262. echo -e "\n"
  263. fi
  264.  
  265. #checks to see if roots home directory is accessible
  266. rthmdir=`ls -ahl /root/ 2>/dev/null`
  267. if [ "$rthmdir" ]; then
  268. echo -e "\e[00;33m[+] We can read root's home directory!\e[00m\n$rthmdir"
  269. echo -e "\n"
  270. fi
  271.  
  272. #displays /home directory permissions - check if any are lax
  273. homedirperms=`ls -ahl /home/ 2>/dev/null`
  274. if [ "$homedirperms" ]; then
  275. echo -e "\e[00;31m[-] Are permissions on /home directories lax:\e[00m\n$homedirperms"
  276. echo -e "\n"
  277. fi
  278.  
  279. #looks for files we can write to that don't belong to us
  280. if [ "$thorough" = "1" ]; then
  281. grfilesall=`find / -writable ! -user \`whoami\` -type f ! -path "/proc/*" ! -path "/sys/*" -exec ls -al {} \; 2>/dev/null`
  282. if [ "$grfilesall" ]; then
  283. echo -e "\e[00;31m[-] Files not owned by user but writable by group:\e[00m\n$grfilesall"
  284. echo -e "\n"
  285. fi
  286. fi
  287.  
  288. #looks for files that belong to us
  289. if [ "$thorough" = "1" ]; then
  290. ourfilesall=`find / -user \`whoami\` -type f ! -path "/proc/*" ! -path "/sys/*" -exec ls -al {} \; 2>/dev/null`
  291. if [ "$ourfilesall" ]; then
  292. echo -e "\e[00;31m[-] Files owned by our user:\e[00m\n$ourfilesall"
  293. echo -e "\n"
  294. fi
  295. fi
  296.  
  297. #looks for hidden files
  298. if [ "$thorough" = "1" ]; then
  299. hiddenfiles=`find / -name ".*" -type f ! -path "/proc/*" ! -path "/sys/*" -exec ls -al {} \; 2>/dev/null`
  300. if [ "$hiddenfiles" ]; then
  301. echo -e "\e[00;31m[-] Hidden files:\e[00m\n$hiddenfiles"
  302. echo -e "\n"
  303. fi
  304. fi
  305.  
  306. #looks for world-reabable files within /home - depending on number of /home dirs & files, this can take some time so is only 'activated' with thorough scanning switch
  307. if [ "$thorough" = "1" ]; then
  308. wrfileshm=`find /home/ -perm -4 -type f -exec ls -al {} \; 2>/dev/null`
  309. if [ "$wrfileshm" ]; then
  310. echo -e "\e[00;31m[-] World-readable files within /home:\e[00m\n$wrfileshm"
  311. echo -e "\n"
  312. fi
  313. fi
  314.  
  315. if [ "$thorough" = "1" ]; then
  316. if [ "$export" ] && [ "$wrfileshm" ]; then
  317. mkdir $format/wr-files/ 2>/dev/null
  318. for i in $wrfileshm; do cp --parents $i $format/wr-files/ ; done 2>/dev/null
  319. fi
  320. fi
  321.  
  322. #lists current user's home directory contents
  323. if [ "$thorough" = "1" ]; then
  324. homedircontents=`ls -ahl ~ 2>/dev/null`
  325. if [ "$homedircontents" ] ; then
  326. echo -e "\e[00;31m[-] Home directory contents:\e[00m\n$homedircontents"
  327. echo -e "\n"
  328. fi
  329. fi
  330.  
  331. #checks for if various ssh files are accessible - this can take some time so is only 'activated' with thorough scanning switch
  332. if [ "$thorough" = "1" ]; then
  333. sshfiles=`find / \( -name "id_dsa*" -o -name "id_rsa*" -o -name "known_hosts" -o -name "authorized_hosts" -o -name "authorized_keys" \) -exec ls -la {} 2>/dev/null \;`
  334. if [ "$sshfiles" ]; then
  335. echo -e "\e[00;31m[-] SSH keys/host information found in the following locations:\e[00m\n$sshfiles"
  336. echo -e "\n"
  337. fi
  338. fi
  339.  
  340. if [ "$thorough" = "1" ]; then
  341. if [ "$export" ] && [ "$sshfiles" ]; then
  342. mkdir $format/ssh-files/ 2>/dev/null
  343. for i in $sshfiles; do cp --parents $i $format/ssh-files/; done 2>/dev/null
  344. fi
  345. fi
  346.  
  347. #is root permitted to login via ssh
  348. sshrootlogin=`grep "PermitRootLogin " /etc/ssh/sshd_config 2>/dev/null | grep -v "#" | awk '{print $2}'`
  349. if [ "$sshrootlogin" = "yes" ]; then
  350. echo -e "\e[00;31m[-] Root is allowed to login via SSH:\e[00m" ; grep "PermitRootLogin " /etc/ssh/sshd_config 2>/dev/null | grep -v "#"
  351. echo -e "\n"
  352. fi
  353. }
  354.  
  355. environmental_info()
  356. {
  357. echo -e "\e[00;33m### ENVIRONMENTAL #######################################\e[00m"
  358.  
  359. #env information
  360. envinfo=`env 2>/dev/null | grep -v 'LS_COLORS' 2>/dev/null`
  361. if [ "$envinfo" ]; then
  362. echo -e "\e[00;31m[-] Environment information:\e[00m\n$envinfo"
  363. echo -e "\n"
  364. fi
  365.  
  366. #check if selinux is enabled
  367. sestatus=`sestatus 2>/dev/null`
  368. if [ "$sestatus" ]; then
  369. echo -e "\e[00;31m[-] SELinux seems to be present:\e[00m\n$sestatus"
  370. echo -e "\n"
  371. fi
  372.  
  373. #phackt
  374.  
  375. #current path configuration
  376. pathinfo=`echo $PATH 2>/dev/null`
  377. if [ "$pathinfo" ]; then
  378. echo -e "\e[00;31m[-] Path information:\e[00m\n$pathinfo"
  379. echo -e "\n"
  380. fi
  381.  
  382. #lists available shells
  383. shellinfo=`cat /etc/shells 2>/dev/null`
  384. if [ "$shellinfo" ]; then
  385. echo -e "\e[00;31m[-] Available shells:\e[00m\n$shellinfo"
  386. echo -e "\n"
  387. fi
  388.  
  389. #current umask value with both octal and symbolic output
  390. umaskvalue=`umask -S 2>/dev/null & umask 2>/dev/null`
  391. if [ "$umaskvalue" ]; then
  392. echo -e "\e[00;31m[-] Current umask value:\e[00m\n$umaskvalue"
  393. echo -e "\n"
  394. fi
  395.  
  396. #umask value as in /etc/login.defs
  397. umaskdef=`grep -i "^UMASK" /etc/login.defs 2>/dev/null`
  398. if [ "$umaskdef" ]; then
  399. echo -e "\e[00;31m[-] umask value as specified in /etc/login.defs:\e[00m\n$umaskdef"
  400. echo -e "\n"
  401. fi
  402.  
  403. #password policy information as stored in /etc/login.defs
  404. logindefs=`grep "^PASS_MAX_DAYS\|^PASS_MIN_DAYS\|^PASS_WARN_AGE\|^ENCRYPT_METHOD" /etc/login.defs 2>/dev/null`
  405. if [ "$logindefs" ]; then
  406. echo -e "\e[00;31m[-] Password and storage information:\e[00m\n$logindefs"
  407. echo -e "\n"
  408. fi
  409.  
  410. if [ "$export" ] && [ "$logindefs" ]; then
  411. mkdir $format/etc-export/ 2>/dev/null
  412. cp /etc/login.defs $format/etc-export/login.defs 2>/dev/null
  413. fi
  414. }
  415.  
  416. job_info()
  417. {
  418. echo -e "\e[00;33m### JOBS/TASKS ##########################################\e[00m"
  419.  
  420. #are there any cron jobs configured
  421. cronjobs=`ls -la /etc/cron* 2>/dev/null`
  422. if [ "$cronjobs" ]; then
  423. echo -e "\e[00;31m[-] Cron jobs:\e[00m\n$cronjobs"
  424. echo -e "\n"
  425. fi
  426.  
  427. #can we manipulate these jobs in any way
  428. cronjobwwperms=`find /etc/cron* -perm -0002 -type f -exec ls -la {} \; -exec cat {} 2>/dev/null \;`
  429. if [ "$cronjobwwperms" ]; then
  430. echo -e "\e[00;33m[+] World-writable cron jobs and file contents:\e[00m\n$cronjobwwperms"
  431. echo -e "\n"
  432. fi
  433.  
  434. #contab contents
  435. crontabvalue=`cat /etc/crontab 2>/dev/null`
  436. if [ "$crontabvalue" ]; then
  437. echo -e "\e[00;31m[-] Crontab contents:\e[00m\n$crontabvalue"
  438. echo -e "\n"
  439. fi
  440.  
  441. crontabvar=`ls -la /var/spool/cron/crontabs 2>/dev/null`
  442. if [ "$crontabvar" ]; then
  443. echo -e "\e[00;31m[-] Anything interesting in /var/spool/cron/crontabs:\e[00m\n$crontabvar"
  444. echo -e "\n"
  445. fi
  446.  
  447. anacronjobs=`ls -la /etc/anacrontab 2>/dev/null; cat /etc/anacrontab 2>/dev/null`
  448. if [ "$anacronjobs" ]; then
  449. echo -e "\e[00;31m[-] Anacron jobs and associated file permissions:\e[00m\n$anacronjobs"
  450. echo -e "\n"
  451. fi
  452.  
  453. anacrontab=`ls -la /var/spool/anacron 2>/dev/null`
  454. if [ "$anacrontab" ]; then
  455. echo -e "\e[00;31m[-] When were jobs last executed (/var/spool/anacron contents):\e[00m\n$anacrontab"
  456. echo -e "\n"
  457. fi
  458.  
  459. #pull out account names from /etc/passwd and see if any users have associated cronjobs (priv command)
  460. cronother=`cut -d ":" -f 1 /etc/passwd | xargs -n1 crontab -l -u 2>/dev/null`
  461. if [ "$cronother" ]; then
  462. echo -e "\e[00;31m[-] Jobs held by all users:\e[00m\n$cronother"
  463. echo -e "\n"
  464. fi
  465.  
  466. # list systemd timers
  467. if [ "$thorough" = "1" ]; then
  468. # include inactive timers in thorough mode
  469. systemdtimers="$(systemctl list-timers --all 2>/dev/null)"
  470. info=""
  471. else
  472. systemdtimers="$(systemctl list-timers 2>/dev/null |head -n -1 2>/dev/null)"
  473. # replace the info in the output with a hint towards thorough mode
  474. info="\e[2mEnable thorough tests to see inactive timers\e[00m"
  475. fi
  476. if [ "$systemdtimers" ]; then
  477. echo -e "\e[00;31m[-] Systemd timers:\e[00m\n$systemdtimers\n$info"
  478. echo -e "\n"
  479. fi
  480.  
  481. }
  482.  
  483. networking_info()
  484. {
  485. echo -e "\e[00;33m### NETWORKING ##########################################\e[00m"
  486.  
  487. #nic information
  488. nicinfo=`/sbin/ifconfig -a 2>/dev/null`
  489. if [ "$nicinfo" ]; then
  490. echo -e "\e[00;31m[-] Network and IP info:\e[00m\n$nicinfo"
  491. echo -e "\n"
  492. fi
  493.  
  494. #nic information (using ip)
  495. nicinfoip=`/sbin/ip a 2>/dev/null`
  496. if [ ! "$nicinfo" ] && [ "$nicinfoip" ]; then
  497. echo -e "\e[00;31m[-] Network and IP info:\e[00m\n$nicinfoip"
  498. echo -e "\n"
  499. fi
  500.  
  501. arpinfo=`arp -a 2>/dev/null`
  502. if [ "$arpinfo" ]; then
  503. echo -e "\e[00;31m[-] ARP history:\e[00m\n$arpinfo"
  504. echo -e "\n"
  505. fi
  506.  
  507. arpinfoip=`ip n 2>/dev/null`
  508. if [ ! "$arpinfo" ] && [ "$arpinfoip" ]; then
  509. echo -e "\e[00;31m[-] ARP history:\e[00m\n$arpinfoip"
  510. echo -e "\n"
  511. fi
  512.  
  513. #dns settings
  514. nsinfo=`grep "nameserver" /etc/resolv.conf 2>/dev/null`
  515. if [ "$nsinfo" ]; then
  516. echo -e "\e[00;31m[-] Nameserver(s):\e[00m\n$nsinfo"
  517. echo -e "\n"
  518. fi
  519.  
  520. nsinfosysd=`systemd-resolve --status 2>/dev/null`
  521. if [ "$nsinfosysd" ]; then
  522. echo -e "\e[00;31m[-] Nameserver(s):\e[00m\n$nsinfosysd"
  523. echo -e "\n"
  524. fi
  525.  
  526. #default route configuration
  527. defroute=`route 2>/dev/null | grep default`
  528. if [ "$defroute" ]; then
  529. echo -e "\e[00;31m[-] Default route:\e[00m\n$defroute"
  530. echo -e "\n"
  531. fi
  532.  
  533. #default route configuration
  534. defrouteip=`ip r 2>/dev/null | grep default`
  535. if [ ! "$defroute" ] && [ "$defrouteip" ]; then
  536. echo -e "\e[00;31m[-] Default route:\e[00m\n$defrouteip"
  537. echo -e "\n"
  538. fi
  539.  
  540. #listening TCP
  541. tcpservs=`netstat -antp 2>/dev/null`
  542. if [ "$tcpservs" ]; then
  543. echo -e "\e[00;31m[-] Listening TCP:\e[00m\n$tcpservs"
  544. echo -e "\n"
  545. fi
  546.  
  547. tcpservsip=`ss -t 2>/dev/null`
  548. if [ ! "$tcpservs" ] && [ "$tcpservsip" ]; then
  549. echo -e "\e[00;31m[-] Listening TCP:\e[00m\n$tcpservsip"
  550. echo -e "\n"
  551. fi
  552.  
  553. #listening UDP
  554. udpservs=`netstat -anup 2>/dev/null`
  555. if [ "$udpservs" ]; then
  556. echo -e "\e[00;31m[-] Listening UDP:\e[00m\n$udpservs"
  557. echo -e "\n"
  558. fi
  559.  
  560. udpservsip=`ip -u 2>/dev/null`
  561. if [ ! "$udpservs" ] && [ "$udpservsip" ]; then
  562. echo -e "\e[00;31m[-] Listening UDP:\e[00m\n$udpservsip"
  563. echo -e "\n"
  564. fi
  565. }
  566.  
  567. services_info()
  568. {
  569. echo -e "\e[00;33m### SERVICES #############################################\e[00m"
  570.  
  571. #running processes
  572. psaux=`ps aux 2>/dev/null`
  573. if [ "$psaux" ]; then
  574. echo -e "\e[00;31m[-] Running processes:\e[00m\n$psaux"
  575. echo -e "\n"
  576. fi
  577.  
  578. #lookup process binary path and permissisons
  579. procperm=`ps aux 2>/dev/null | awk '{print $11}'|xargs -r ls -la 2>/dev/null |awk '!x[$0]++' 2>/dev/null`
  580. if [ "$procperm" ]; then
  581. echo -e "\e[00;31m[-] Process binaries and associated permissions (from above list):\e[00m\n$procperm"
  582. echo -e "\n"
  583. fi
  584.  
  585. if [ "$export" ] && [ "$procperm" ]; then
  586. procpermbase=`ps aux 2>/dev/null | awk '{print $11}' | xargs -r ls 2>/dev/null | awk '!x[$0]++' 2>/dev/null`
  587. mkdir $format/ps-export/ 2>/dev/null
  588. for i in $procpermbase; do cp --parents $i $format/ps-export/; done 2>/dev/null
  589. fi
  590.  
  591. #anything 'useful' in inetd.conf
  592. inetdread=`cat /etc/inetd.conf 2>/dev/null`
  593. if [ "$inetdread" ]; then
  594. echo -e "\e[00;31m[-] Contents of /etc/inetd.conf:\e[00m\n$inetdread"
  595. echo -e "\n"
  596. fi
  597.  
  598. if [ "$export" ] && [ "$inetdread" ]; then
  599. mkdir $format/etc-export/ 2>/dev/null
  600. cp /etc/inetd.conf $format/etc-export/inetd.conf 2>/dev/null
  601. fi
  602.  
  603. #very 'rough' command to extract associated binaries from inetd.conf & show permisisons of each
  604. inetdbinperms=`awk '{print $7}' /etc/inetd.conf 2>/dev/null |xargs -r ls -la 2>/dev/null`
  605. if [ "$inetdbinperms" ]; then
  606. echo -e "\e[00;31m[-] The related inetd binary permissions:\e[00m\n$inetdbinperms"
  607. echo -e "\n"
  608. fi
  609.  
  610. xinetdread=`cat /etc/xinetd.conf 2>/dev/null`
  611. if [ "$xinetdread" ]; then
  612. echo -e "\e[00;31m[-] Contents of /etc/xinetd.conf:\e[00m\n$xinetdread"
  613. echo -e "\n"
  614. fi
  615.  
  616. if [ "$export" ] && [ "$xinetdread" ]; then
  617. mkdir $format/etc-export/ 2>/dev/null
  618. cp /etc/xinetd.conf $format/etc-export/xinetd.conf 2>/dev/null
  619. fi
  620.  
  621. xinetdincd=`grep "/etc/xinetd.d" /etc/xinetd.conf 2>/dev/null`
  622. if [ "$xinetdincd" ]; then
  623. echo -e "\e[00;31m[-] /etc/xinetd.d is included in /etc/xinetd.conf - associated binary permissions are listed below:\e[00m"; ls -la /etc/xinetd.d 2>/dev/null
  624. echo -e "\n"
  625. fi
  626.  
  627. #very 'rough' command to extract associated binaries from xinetd.conf & show permisisons of each
  628. xinetdbinperms=`awk '{print $7}' /etc/xinetd.conf 2>/dev/null |xargs -r ls -la 2>/dev/null`
  629. if [ "$xinetdbinperms" ]; then
  630. echo -e "\e[00;31m[-] The related xinetd binary permissions:\e[00m\n$xinetdbinperms"
  631. echo -e "\n"
  632. fi
  633.  
  634. initdread=`ls -la /etc/init.d 2>/dev/null`
  635. if [ "$initdread" ]; then
  636. echo -e "\e[00;31m[-] /etc/init.d/ binary permissions:\e[00m\n$initdread"
  637. echo -e "\n"
  638. fi
  639.  
  640. #init.d files NOT belonging to root!
  641. initdperms=`find /etc/init.d/ \! -uid 0 -type f 2>/dev/null |xargs -r ls -la 2>/dev/null`
  642. if [ "$initdperms" ]; then
  643. echo -e "\e[00;31m[-] /etc/init.d/ files not belonging to root:\e[00m\n$initdperms"
  644. echo -e "\n"
  645. fi
  646.  
  647. rcdread=`ls -la /etc/rc.d/init.d 2>/dev/null`
  648. if [ "$rcdread" ]; then
  649. echo -e "\e[00;31m[-] /etc/rc.d/init.d binary permissions:\e[00m\n$rcdread"
  650. echo -e "\n"
  651. fi
  652.  
  653. #init.d files NOT belonging to root!
  654. rcdperms=`find /etc/rc.d/init.d \! -uid 0 -type f 2>/dev/null |xargs -r ls -la 2>/dev/null`
  655. if [ "$rcdperms" ]; then
  656. echo -e "\e[00;31m[-] /etc/rc.d/init.d files not belonging to root:\e[00m\n$rcdperms"
  657. echo -e "\n"
  658. fi
  659.  
  660. usrrcdread=`ls -la /usr/local/etc/rc.d 2>/dev/null`
  661. if [ "$usrrcdread" ]; then
  662. echo -e "\e[00;31m[-] /usr/local/etc/rc.d binary permissions:\e[00m\n$usrrcdread"
  663. echo -e "\n"
  664. fi
  665.  
  666. #rc.d files NOT belonging to root!
  667. usrrcdperms=`find /usr/local/etc/rc.d \! -uid 0 -type f 2>/dev/null |xargs -r ls -la 2>/dev/null`
  668. if [ "$usrrcdperms" ]; then
  669. echo -e "\e[00;31m[-] /usr/local/etc/rc.d files not belonging to root:\e[00m\n$usrrcdperms"
  670. echo -e "\n"
  671. fi
  672.  
  673. initread=`ls -la /etc/init/ 2>/dev/null`
  674. if [ "$initread" ]; then
  675. echo -e "\e[00;31m[-] /etc/init/ config file permissions:\e[00m\n$initread"
  676. echo -e "\n"
  677. fi
  678.  
  679. # upstart scripts not belonging to root
  680. initperms=`find /etc/init \! -uid 0 -type f 2>/dev/null |xargs -r ls -la 2>/dev/null`
  681. if [ "$initperms" ]; then
  682. echo -e "\e[00;31m[-] /etc/init/ config files not belonging to root:\e[00m\n$initperms"
  683. echo -e "\n"
  684. fi
  685.  
  686. systemdread=`ls -lthR /lib/systemd/ 2>/dev/null`
  687. if [ "$systemdread" ]; then
  688. echo -e "\e[00;31m[-] /lib/systemd/* config file permissions:\e[00m\n$systemdread"
  689. echo -e "\n"
  690. fi
  691.  
  692. # systemd files not belonging to root
  693. systemdperms=`find /lib/systemd/ \! -uid 0 -type f 2>/dev/null |xargs -r ls -la 2>/dev/null`
  694. if [ "$systemdperms" ]; then
  695. echo -e "\e[00;33m[+] /lib/systemd/* config files not belonging to root:\e[00m\n$systemdperms"
  696. echo -e "\n"
  697. fi
  698. }
  699.  
  700. software_configs()
  701. {
  702. echo -e "\e[00;33m### SOFTWARE #############################################\e[00m"
  703.  
  704. #sudo version - check to see if there are any known vulnerabilities with this
  705. sudover=`sudo -V 2>/dev/null| grep "Sudo version" 2>/dev/null`
  706. if [ "$sudover" ]; then
  707. echo -e "\e[00;31m[-] Sudo version:\e[00m\n$sudover"
  708. echo -e "\n"
  709. fi
  710.  
  711. #mysql details - if installed
  712. mysqlver=`mysql --version 2>/dev/null`
  713. if [ "$mysqlver" ]; then
  714. echo -e "\e[00;31m[-] MYSQL version:\e[00m\n$mysqlver"
  715. echo -e "\n"
  716. fi
  717.  
  718. #checks to see if root/root will get us a connection
  719. mysqlconnect=`mysqladmin -uroot -proot version 2>/dev/null`
  720. if [ "$mysqlconnect" ]; then
  721. echo -e "\e[00;33m[+] We can connect to the local MYSQL service with default root/root credentials!\e[00m\n$mysqlconnect"
  722. echo -e "\n"
  723. fi
  724.  
  725. #mysql version details
  726. mysqlconnectnopass=`mysqladmin -uroot version 2>/dev/null`
  727. if [ "$mysqlconnectnopass" ]; then
  728. echo -e "\e[00;33m[+] We can connect to the local MYSQL service as 'root' and without a password!\e[00m\n$mysqlconnectnopass"
  729. echo -e "\n"
  730. fi
  731.  
  732. #postgres details - if installed
  733. postgver=`psql -V 2>/dev/null`
  734. if [ "$postgver" ]; then
  735. echo -e "\e[00;31m[-] Postgres version:\e[00m\n$postgver"
  736. echo -e "\n"
  737. fi
  738.  
  739. #checks to see if any postgres password exists and connects to DB 'template0' - following commands are a variant on this
  740. postcon1=`psql -U postgres template0 -c 'select version()' 2>/dev/null | grep version`
  741. if [ "$postcon1" ]; then
  742. echo -e "\e[00;33m[+] We can connect to Postgres DB 'template0' as user 'postgres' with no password!:\e[00m\n$postcon1"
  743. echo -e "\n"
  744. fi
  745.  
  746. postcon11=`psql -U postgres template1 -c 'select version()' 2>/dev/null | grep version`
  747. if [ "$postcon11" ]; then
  748. echo -e "\e[00;33m[+] We can connect to Postgres DB 'template1' as user 'postgres' with no password!:\e[00m\n$postcon11"
  749. echo -e "\n"
  750. fi
  751.  
  752. postcon2=`psql -U pgsql template0 -c 'select version()' 2>/dev/null | grep version`
  753. if [ "$postcon2" ]; then
  754. echo -e "\e[00;33m[+] We can connect to Postgres DB 'template0' as user 'psql' with no password!:\e[00m\n$postcon2"
  755. echo -e "\n"
  756. fi
  757.  
  758. postcon22=`psql -U pgsql template1 -c 'select version()' 2>/dev/null | grep version`
  759. if [ "$postcon22" ]; then
  760. echo -e "\e[00;33m[+] We can connect to Postgres DB 'template1' as user 'psql' with no password!:\e[00m\n$postcon22"
  761. echo -e "\n"
  762. fi
  763.  
  764. #apache details - if installed
  765. apachever=`apache2 -v 2>/dev/null; httpd -v 2>/dev/null`
  766. if [ "$apachever" ]; then
  767. echo -e "\e[00;31m[-] Apache version:\e[00m\n$apachever"
  768. echo -e "\n"
  769. fi
  770.  
  771. #what account is apache running under
  772. apacheusr=`grep -i 'user\|group' /etc/apache2/envvars 2>/dev/null |awk '{sub(/.*\export /,"")}1' 2>/dev/null`
  773. if [ "$apacheusr" ]; then
  774. echo -e "\e[00;31m[-] Apache user configuration:\e[00m\n$apacheusr"
  775. echo -e "\n"
  776. fi
  777.  
  778. if [ "$export" ] && [ "$apacheusr" ]; then
  779. mkdir --parents $format/etc-export/apache2/ 2>/dev/null
  780. cp /etc/apache2/envvars $format/etc-export/apache2/envvars 2>/dev/null
  781. fi
  782.  
  783. #installed apache modules
  784. apachemodules=`apache2ctl -M 2>/dev/null; httpd -M 2>/dev/null`
  785. if [ "$apachemodules" ]; then
  786. echo -e "\e[00;31m[-] Installed Apache modules:\e[00m\n$apachemodules"
  787. echo -e "\n"
  788. fi
  789.  
  790. #htpasswd check
  791. htpasswd=`find / -name .htpasswd -print -exec cat {} \; 2>/dev/null`
  792. if [ "$htpasswd" ]; then
  793. echo -e "\e[00;33m[-] htpasswd found - could contain passwords:\e[00m\n$htpasswd"
  794. echo -e "\n"
  795. fi
  796.  
  797. #anything in the default http home dirs (a thorough only check as output can be large)
  798. if [ "$thorough" = "1" ]; then
  799. apachehomedirs=`ls -alhR /var/www/ 2>/dev/null; ls -alhR /srv/www/htdocs/ 2>/dev/null; ls -alhR /usr/local/www/apache2/data/ 2>/dev/null; ls -alhR /opt/lampp/htdocs/ 2>/dev/null`
  800. if [ "$apachehomedirs" ]; then
  801. echo -e "\e[00;31m[-] www home dir contents:\e[00m\n$apachehomedirs"
  802. echo -e "\n"
  803. fi
  804. fi
  805.  
  806. }
  807.  
  808. interesting_files()
  809. {
  810. echo -e "\e[00;33m### INTERESTING FILES ####################################\e[00m"
  811.  
  812. #checks to see if various files are installed
  813. echo -e "\e[00;31m[-] Useful file locations:\e[00m" ; which nc 2>/dev/null ; which netcat 2>/dev/null ; which wget 2>/dev/null ; which nmap 2>/dev/null ; which gcc 2>/dev/null; which curl 2>/dev/null
  814. echo -e "\n"
  815.  
  816. #limited search for installed compilers
  817. compiler=`dpkg --list 2>/dev/null| grep compiler |grep -v decompiler 2>/dev/null && yum list installed 'gcc*' 2>/dev/null| grep gcc 2>/dev/null`
  818. if [ "$compiler" ]; then
  819. echo -e "\e[00;31m[-] Installed compilers:\e[00m\n$compiler"
  820. echo -e "\n"
  821. fi
  822.  
  823. #manual check - lists out sensitive files, can we read/modify etc.
  824. echo -e "\e[00;31m[-] Can we read/write sensitive files:\e[00m" ; ls -la /etc/passwd 2>/dev/null ; ls -la /etc/group 2>/dev/null ; ls -la /etc/profile 2>/dev/null; ls -la /etc/shadow 2>/dev/null ; ls -la /etc/master.passwd 2>/dev/null
  825. echo -e "\n"
  826.  
  827. #search for suid files
  828. findsuid=`find / -perm -4000 -type f -exec ls -la {} 2>/dev/null \;`
  829. if [ "$findsuid" ]; then
  830. echo -e "\e[00;31m[-] SUID files:\e[00m\n$findsuid"
  831. echo -e "\n"
  832. fi
  833.  
  834. if [ "$export" ] && [ "$findsuid" ]; then
  835. mkdir $format/suid-files/ 2>/dev/null
  836. for i in $findsuid; do cp $i $format/suid-files/; done 2>/dev/null
  837. fi
  838.  
  839. #list of 'interesting' suid files - feel free to make additions
  840. intsuid=`find / -perm -4000 -type f -exec ls -la {} \; 2>/dev/null | grep -w $binarylist 2>/dev/null`
  841. if [ "$intsuid" ]; then
  842. echo -e "\e[00;33m[+] Possibly interesting SUID files:\e[00m\n$intsuid"
  843. echo -e "\n"
  844. fi
  845.  
  846. #lists word-writable suid files
  847. wwsuid=`find / -perm -4007 -type f -exec ls -la {} 2>/dev/null \;`
  848. if [ "$wwsuid" ]; then
  849. echo -e "\e[00;33m[+] World-writable SUID files:\e[00m\n$wwsuid"
  850. echo -e "\n"
  851. fi
  852.  
  853. #lists world-writable suid files owned by root
  854. wwsuidrt=`find / -uid 0 -perm -4007 -type f -exec ls -la {} 2>/dev/null \;`
  855. if [ "$wwsuidrt" ]; then
  856. echo -e "\e[00;33m[+] World-writable SUID files owned by root:\e[00m\n$wwsuidrt"
  857. echo -e "\n"
  858. fi
  859.  
  860. #search for sgid files
  861. findsgid=`find / -perm -2000 -type f -exec ls -la {} 2>/dev/null \;`
  862. if [ "$findsgid" ]; then
  863. echo -e "\e[00;31m[-] SGID files:\e[00m\n$findsgid"
  864. echo -e "\n"
  865. fi
  866.  
  867. if [ "$export" ] && [ "$findsgid" ]; then
  868. mkdir $format/sgid-files/ 2>/dev/null
  869. for i in $findsgid; do cp $i $format/sgid-files/; done 2>/dev/null
  870. fi
  871.  
  872. #list of 'interesting' sgid files
  873. intsgid=`find / -perm -2000 -type f -exec ls -la {} \; 2>/dev/null | grep -w $binarylist 2>/dev/null`
  874. if [ "$intsgid" ]; then
  875. echo -e "\e[00;33m[+] Possibly interesting SGID files:\e[00m\n$intsgid"
  876. echo -e "\n"
  877. fi
  878.  
  879. #lists world-writable sgid files
  880. wwsgid=`find / -perm -2007 -type f -exec ls -la {} 2>/dev/null \;`
  881. if [ "$wwsgid" ]; then
  882. echo -e "\e[00;33m[+] World-writable SGID files:\e[00m\n$wwsgid"
  883. echo -e "\n"
  884. fi
  885.  
  886. #lists world-writable sgid files owned by root
  887. wwsgidrt=`find / -uid 0 -perm -2007 -type f -exec ls -la {} 2>/dev/null \;`
  888. if [ "$wwsgidrt" ]; then
  889. echo -e "\e[00;33m[+] World-writable SGID files owned by root:\e[00m\n$wwsgidrt"
  890. echo -e "\n"
  891. fi
  892.  
  893. #list all files with POSIX capabilities set along with there capabilities
  894. fileswithcaps=`getcap -r / 2>/dev/null || /sbin/getcap -r / 2>/dev/null`
  895. if [ "$fileswithcaps" ]; then
  896. echo -e "\e[00;31m[+] Files with POSIX capabilities set:\e[00m\n$fileswithcaps"
  897. echo -e "\n"
  898. fi
  899.  
  900. if [ "$export" ] && [ "$fileswithcaps" ]; then
  901. mkdir $format/files_with_capabilities/ 2>/dev/null
  902. for i in $fileswithcaps; do cp $i $format/files_with_capabilities/; done 2>/dev/null
  903. fi
  904.  
  905. #searches /etc/security/capability.conf for users associated capapilies
  906. userswithcaps=`grep -v '^#\|none\|^$' /etc/security/capability.conf 2>/dev/null`
  907. if [ "$userswithcaps" ]; then
  908. echo -e "\e[00;33m[+] Users with specific POSIX capabilities:\e[00m\n$userswithcaps"
  909. echo -e "\n"
  910. fi
  911.  
  912. if [ "$userswithcaps" ] ; then
  913. #matches the capabilities found associated with users with the current user
  914. matchedcaps=`echo -e "$userswithcaps" | grep \`whoami\` | awk '{print $1}' 2>/dev/null`
  915. if [ "$matchedcaps" ]; then
  916. echo -e "\e[00;33m[+] Capabilities associated with the current user:\e[00m\n$matchedcaps"
  917. echo -e "\n"
  918. #matches the files with capapbilities with capabilities associated with the current user
  919. matchedfiles=`echo -e "$matchedcaps" | while read -r cap ; do echo -e "$fileswithcaps" | grep "$cap" ; done 2>/dev/null`
  920. if [ "$matchedfiles" ]; then
  921. echo -e "\e[00;33m[+] Files with the same capabilities associated with the current user (You may want to try abusing those capabilties):\e[00m\n$matchedfiles"
  922. echo -e "\n"
  923. #lists the permissions of the files having the same capabilies associated with the current user
  924. matchedfilesperms=`echo -e "$matchedfiles" | awk '{print $1}' | while read -r f; do ls -la $f ;done 2>/dev/null`
  925. echo -e "\e[00;33m[+] Permissions of files with the same capabilities associated with the current user:\e[00m\n$matchedfilesperms"
  926. echo -e "\n"
  927. if [ "$matchedfilesperms" ]; then
  928. #checks if any of the files with same capabilities associated with the current user is writable
  929. writablematchedfiles=`echo -e "$matchedfiles" | awk '{print $1}' | while read -r f; do find $f -writable -exec ls -la {} + ;done 2>/dev/null`
  930. if [ "$writablematchedfiles" ]; then
  931. echo -e "\e[00;33m[+] User/Group writable files with the same capabilities associated with the current user:\e[00m\n$writablematchedfiles"
  932. echo -e "\n"
  933. fi
  934. fi
  935. fi
  936. fi
  937. fi
  938.  
  939. #look for private keys - thanks djhohnstein
  940. if [ "$thorough" = "1" ]; then
  941. privatekeyfiles=`grep -rl "PRIVATE KEY-----" /home 2>/dev/null`
  942. if [ "$privatekeyfiles" ]; then
  943. echo -e "\e[00;33m[+] Private SSH keys found!:\e[00m\n$privatekeyfiles"
  944. echo -e "\n"
  945. fi
  946. fi
  947.  
  948. #look for AWS keys - thanks djhohnstein
  949. if [ "$thorough" = "1" ]; then
  950. awskeyfiles=`grep -rli "aws_secret_access_key" /home 2>/dev/null`
  951. if [ "$awskeyfiles" ]; then
  952. echo -e "\e[00;33m[+] AWS secret keys found!:\e[00m\n$awskeyfiles"
  953. echo -e "\n"
  954. fi
  955. fi
  956.  
  957. #look for git credential files - thanks djhohnstein
  958. if [ "$thorough" = "1" ]; then
  959. gitcredfiles=`find / -name ".git-credentials" 2>/dev/null`
  960. if [ "$gitcredfiles" ]; then
  961. echo -e "\e[00;33m[+] Git credentials saved on the machine!:\e[00m\n$gitcredfiles"
  962. echo -e "\n"
  963. fi
  964. fi
  965.  
  966. #list all world-writable files excluding /proc and /sys
  967. if [ "$thorough" = "1" ]; then
  968. wwfiles=`find / ! -path "*/proc/*" ! -path "/sys/*" -perm -2 -type f -exec ls -la {} 2>/dev/null \;`
  969. if [ "$wwfiles" ]; then
  970. echo -e "\e[00;31m[-] World-writable files (excluding /proc and /sys):\e[00m\n$wwfiles"
  971. echo -e "\n"
  972. fi
  973. fi
  974.  
  975. if [ "$thorough" = "1" ]; then
  976. if [ "$export" ] && [ "$wwfiles" ]; then
  977. mkdir $format/ww-files/ 2>/dev/null
  978. for i in $wwfiles; do cp --parents $i $format/ww-files/; done 2>/dev/null
  979. fi
  980. fi
  981.  
  982. #are any .plan files accessible in /home (could contain useful information)
  983. usrplan=`find /home -iname *.plan -exec ls -la {} \; -exec cat {} 2>/dev/null \;`
  984. if [ "$usrplan" ]; then
  985. echo -e "\e[00;31m[-] Plan file permissions and contents:\e[00m\n$usrplan"
  986. echo -e "\n"
  987. fi
  988.  
  989. if [ "$export" ] && [ "$usrplan" ]; then
  990. mkdir $format/plan_files/ 2>/dev/null
  991. for i in $usrplan; do cp --parents $i $format/plan_files/; done 2>/dev/null
  992. fi
  993.  
  994. bsdusrplan=`find /usr/home -iname *.plan -exec ls -la {} \; -exec cat {} 2>/dev/null \;`
  995. if [ "$bsdusrplan" ]; then
  996. echo -e "\e[00;31m[-] Plan file permissions and contents:\e[00m\n$bsdusrplan"
  997. echo -e "\n"
  998. fi
  999.  
  1000. if [ "$export" ] && [ "$bsdusrplan" ]; then
  1001. mkdir $format/plan_files/ 2>/dev/null
  1002. for i in $bsdusrplan; do cp --parents $i $format/plan_files/; done 2>/dev/null
  1003. fi
  1004.  
  1005. #are there any .rhosts files accessible - these may allow us to login as another user etc.
  1006. rhostsusr=`find /home -iname *.rhosts -exec ls -la {} 2>/dev/null \; -exec cat {} 2>/dev/null \;`
  1007. if [ "$rhostsusr" ]; then
  1008. echo -e "\e[00;33m[+] rhost config file(s) and file contents:\e[00m\n$rhostsusr"
  1009. echo -e "\n"
  1010. fi
  1011.  
  1012. if [ "$export" ] && [ "$rhostsusr" ]; then
  1013. mkdir $format/rhosts/ 2>/dev/null
  1014. for i in $rhostsusr; do cp --parents $i $format/rhosts/; done 2>/dev/null
  1015. fi
  1016.  
  1017. bsdrhostsusr=`find /usr/home -iname *.rhosts -exec ls -la {} 2>/dev/null \; -exec cat {} 2>/dev/null \;`
  1018. if [ "$bsdrhostsusr" ]; then
  1019. echo -e "\e[00;33m[+] rhost config file(s) and file contents:\e[00m\n$bsdrhostsusr"
  1020. echo -e "\n"
  1021. fi
  1022.  
  1023. if [ "$export" ] && [ "$bsdrhostsusr" ]; then
  1024. mkdir $format/rhosts 2>/dev/null
  1025. for i in $bsdrhostsusr; do cp --parents $i $format/rhosts/; done 2>/dev/null
  1026. fi
  1027.  
  1028. rhostssys=`find /etc -iname hosts.equiv -exec ls -la {} 2>/dev/null \; -exec cat {} 2>/dev/null \;`
  1029. if [ "$rhostssys" ]; then
  1030. echo -e "\e[00;33m[+] Hosts.equiv file and contents: \e[00m\n$rhostssys"
  1031. echo -e "\n"
  1032. fi
  1033.  
  1034. if [ "$export" ] && [ "$rhostssys" ]; then
  1035. mkdir $format/rhosts/ 2>/dev/null
  1036. for i in $rhostssys; do cp --parents $i $format/rhosts/; done 2>/dev/null
  1037. fi
  1038.  
  1039. #list nfs shares/permisisons etc.
  1040. nfsexports=`ls -la /etc/exports 2>/dev/null; cat /etc/exports 2>/dev/null`
  1041. if [ "$nfsexports" ]; then
  1042. echo -e "\e[00;31m[-] NFS config details: \e[00m\n$nfsexports"
  1043. echo -e "\n"
  1044. fi
  1045.  
  1046. if [ "$export" ] && [ "$nfsexports" ]; then
  1047. mkdir $format/etc-export/ 2>/dev/null
  1048. cp /etc/exports $format/etc-export/exports 2>/dev/null
  1049. fi
  1050.  
  1051. if [ "$thorough" = "1" ]; then
  1052. #phackt
  1053. #displaying /etc/fstab
  1054. fstab=`cat /etc/fstab 2>/dev/null`
  1055. if [ "$fstab" ]; then
  1056. echo -e "\e[00;31m[-] NFS displaying partitions and filesystems - you need to check if exotic filesystems\e[00m"
  1057. echo -e "$fstab"
  1058. echo -e "\n"
  1059. fi
  1060. fi
  1061.  
  1062. #looking for credentials in /etc/fstab
  1063. fstab=`grep username /etc/fstab 2>/dev/null |awk '{sub(/.*\username=/,"");sub(/\,.*/,"")}1' 2>/dev/null| xargs -r echo username: 2>/dev/null; grep password /etc/fstab 2>/dev/null |awk '{sub(/.*\password=/,"");sub(/\,.*/,"")}1' 2>/dev/null| xargs -r echo password: 2>/dev/null; grep domain /etc/fstab 2>/dev/null |awk '{sub(/.*\domain=/,"");sub(/\,.*/,"")}1' 2>/dev/null| xargs -r echo domain: 2>/dev/null`
  1064. if [ "$fstab" ]; then
  1065. echo -e "\e[00;33m[+] Looks like there are credentials in /etc/fstab!\e[00m\n$fstab"
  1066. echo -e "\n"
  1067. fi
  1068.  
  1069. if [ "$export" ] && [ "$fstab" ]; then
  1070. mkdir $format/etc-exports/ 2>/dev/null
  1071. cp /etc/fstab $format/etc-exports/fstab done 2>/dev/null
  1072. fi
  1073.  
  1074. fstabcred=`grep cred /etc/fstab 2>/dev/null |awk '{sub(/.*\credentials=/,"");sub(/\,.*/,"")}1' 2>/dev/null | xargs -I{} sh -c 'ls -la {}; cat {}' 2>/dev/null`
  1075. if [ "$fstabcred" ]; then
  1076. echo -e "\e[00;33m[+] /etc/fstab contains a credentials file!\e[00m\n$fstabcred"
  1077. echo -e "\n"
  1078. fi
  1079.  
  1080. if [ "$export" ] && [ "$fstabcred" ]; then
  1081. mkdir $format/etc-exports/ 2>/dev/null
  1082. cp /etc/fstab $format/etc-exports/fstab done 2>/dev/null
  1083. fi
  1084.  
  1085. #use supplied keyword and cat *.conf files for potential matches - output will show line number within relevant file path where a match has been located
  1086. if [ "$keyword" = "" ]; then
  1087. echo -e "[-] Can't search *.conf files as no keyword was entered\n"
  1088. else
  1089. confkey=`find / -maxdepth 4 -name *.conf -type f -exec grep -Hn $keyword {} \; 2>/dev/null`
  1090. if [ "$confkey" ]; then
  1091. echo -e "\e[00;31m[-] Find keyword ($keyword) in .conf files (recursive 4 levels - output format filepath:identified line number where keyword appears):\e[00m\n$confkey"
  1092. echo -e "\n"
  1093. else
  1094. echo -e "\e[00;31m[-] Find keyword ($keyword) in .conf files (recursive 4 levels):\e[00m"
  1095. echo -e "'$keyword' not found in any .conf files"
  1096. echo -e "\n"
  1097. fi
  1098. fi
  1099.  
  1100. if [ "$keyword" = "" ]; then
  1101. :
  1102. else
  1103. if [ "$export" ] && [ "$confkey" ]; then
  1104. confkeyfile=`find / -maxdepth 4 -name *.conf -type f -exec grep -lHn $keyword {} \; 2>/dev/null`
  1105. mkdir --parents $format/keyword_file_matches/config_files/ 2>/dev/null
  1106. for i in $confkeyfile; do cp --parents $i $format/keyword_file_matches/config_files/ ; done 2>/dev/null
  1107. fi
  1108. fi
  1109.  
  1110. #use supplied keyword and cat *.php files for potential matches - output will show line number within relevant file path where a match has been located
  1111. if [ "$keyword" = "" ]; then
  1112. echo -e "[-] Can't search *.php files as no keyword was entered\n"
  1113. else
  1114. phpkey=`find / -maxdepth 10 -name *.php -type f -exec grep -Hn $keyword {} \; 2>/dev/null`
  1115. if [ "$phpkey" ]; then
  1116. echo -e "\e[00;31m[-] Find keyword ($keyword) in .php files (recursive 10 levels - output format filepath:identified line number where keyword appears):\e[00m\n$phpkey"
  1117. echo -e "\n"
  1118. else
  1119. echo -e "\e[00;31m[-] Find keyword ($keyword) in .php files (recursive 10 levels):\e[00m"
  1120. echo -e "'$keyword' not found in any .php files"
  1121. echo -e "\n"
  1122. fi
  1123. fi
  1124.  
  1125. if [ "$keyword" = "" ]; then
  1126. :
  1127. else
  1128. if [ "$export" ] && [ "$phpkey" ]; then
  1129. phpkeyfile=`find / -maxdepth 10 -name *.php -type f -exec grep -lHn $keyword {} \; 2>/dev/null`
  1130. mkdir --parents $format/keyword_file_matches/php_files/ 2>/dev/null
  1131. for i in $phpkeyfile; do cp --parents $i $format/keyword_file_matches/php_files/ ; done 2>/dev/null
  1132. fi
  1133. fi
  1134.  
  1135. #use supplied keyword and cat *.log files for potential matches - output will show line number within relevant file path where a match has been located
  1136. if [ "$keyword" = "" ];then
  1137. echo -e "[-] Can't search *.log files as no keyword was entered\n"
  1138. else
  1139. logkey=`find / -maxdepth 4 -name *.log -type f -exec grep -Hn $keyword {} \; 2>/dev/null`
  1140. if [ "$logkey" ]; then
  1141. echo -e "\e[00;31m[-] Find keyword ($keyword) in .log files (recursive 4 levels - output format filepath:identified line number where keyword appears):\e[00m\n$logkey"
  1142. echo -e "\n"
  1143. else
  1144. echo -e "\e[00;31m[-] Find keyword ($keyword) in .log files (recursive 4 levels):\e[00m"
  1145. echo -e "'$keyword' not found in any .log files"
  1146. echo -e "\n"
  1147. fi
  1148. fi
  1149.  
  1150. if [ "$keyword" = "" ];then
  1151. :
  1152. else
  1153. if [ "$export" ] && [ "$logkey" ]; then
  1154. logkeyfile=`find / -maxdepth 4 -name *.log -type f -exec grep -lHn $keyword {} \; 2>/dev/null`
  1155. mkdir --parents $format/keyword_file_matches/log_files/ 2>/dev/null
  1156. for i in $logkeyfile; do cp --parents $i $format/keyword_file_matches/log_files/ ; done 2>/dev/null
  1157. fi
  1158. fi
  1159.  
  1160. #use supplied keyword and cat *.ini files for potential matches - output will show line number within relevant file path where a match has been located
  1161. if [ "$keyword" = "" ];then
  1162. echo -e "[-] Can't search *.ini files as no keyword was entered\n"
  1163. else
  1164. inikey=`find / -maxdepth 4 -name *.ini -type f -exec grep -Hn $keyword {} \; 2>/dev/null`
  1165. if [ "$inikey" ]; then
  1166. echo -e "\e[00;31m[-] Find keyword ($keyword) in .ini files (recursive 4 levels - output format filepath:identified line number where keyword appears):\e[00m\n$inikey"
  1167. echo -e "\n"
  1168. else
  1169. echo -e "\e[00;31m[-] Find keyword ($keyword) in .ini files (recursive 4 levels):\e[00m"
  1170. echo -e "'$keyword' not found in any .ini files"
  1171. echo -e "\n"
  1172. fi
  1173. fi
  1174.  
  1175. if [ "$keyword" = "" ];then
  1176. :
  1177. else
  1178. if [ "$export" ] && [ "$inikey" ]; then
  1179. inikey=`find / -maxdepth 4 -name *.ini -type f -exec grep -lHn $keyword {} \; 2>/dev/null`
  1180. mkdir --parents $format/keyword_file_matches/ini_files/ 2>/dev/null
  1181. for i in $inikey; do cp --parents $i $format/keyword_file_matches/ini_files/ ; done 2>/dev/null
  1182. fi
  1183. fi
  1184.  
  1185. #quick extract of .conf files from /etc - only 1 level
  1186. allconf=`find /etc/ -maxdepth 1 -name *.conf -type f -exec ls -la {} \; 2>/dev/null`
  1187. if [ "$allconf" ]; then
  1188. echo -e "\e[00;31m[-] All *.conf files in /etc (recursive 1 level):\e[00m\n$allconf"
  1189. echo -e "\n"
  1190. fi
  1191.  
  1192. if [ "$export" ] && [ "$allconf" ]; then
  1193. mkdir $format/conf-files/ 2>/dev/null
  1194. for i in $allconf; do cp --parents $i $format/conf-files/; done 2>/dev/null
  1195. fi
  1196.  
  1197. #extract any user history files that are accessible
  1198. usrhist=`ls -la ~/.*_history 2>/dev/null`
  1199. if [ "$usrhist" ]; then
  1200. echo -e "\e[00;31m[-] Current user's history files:\e[00m\n$usrhist"
  1201. echo -e "\n"
  1202. fi
  1203.  
  1204. if [ "$export" ] && [ "$usrhist" ]; then
  1205. mkdir $format/history_files/ 2>/dev/null
  1206. for i in $usrhist; do cp --parents $i $format/history_files/; done 2>/dev/null
  1207. fi
  1208.  
  1209. #can we read roots *_history files - could be passwords stored etc.
  1210. roothist=`ls -la /root/.*_history 2>/dev/null`
  1211. if [ "$roothist" ]; then
  1212. echo -e "\e[00;33m[+] Root's history files are accessible!\e[00m\n$roothist"
  1213. echo -e "\n"
  1214. fi
  1215.  
  1216. if [ "$export" ] && [ "$roothist" ]; then
  1217. mkdir $format/history_files/ 2>/dev/null
  1218. cp $roothist $format/history_files/ 2>/dev/null
  1219. fi
  1220.  
  1221. #all accessible .bash_history files in /home
  1222. checkbashhist=`find /home -name .bash_history -print -exec cat {} 2>/dev/null \;`
  1223. if [ "$checkbashhist" ]; then
  1224. echo -e "\e[00;31m[-] Location and contents (if accessible) of .bash_history file(s):\e[00m\n$checkbashhist"
  1225. echo -e "\n"
  1226. fi
  1227.  
  1228. #is there any mail accessible
  1229. readmail=`ls -la /var/mail 2>/dev/null`
  1230. if [ "$readmail" ]; then
  1231. echo -e "\e[00;31m[-] Any interesting mail in /var/mail:\e[00m\n$readmail"
  1232. echo -e "\n"
  1233. fi
  1234.  
  1235. #can we read roots mail
  1236. readmailroot=`head /var/mail/root 2>/dev/null`
  1237. if [ "$readmailroot" ]; then
  1238. echo -e "\e[00;33m[+] We can read /var/mail/root! (snippet below)\e[00m\n$readmailroot"
  1239. echo -e "\n"
  1240. fi
  1241.  
  1242. if [ "$export" ] && [ "$readmailroot" ]; then
  1243. mkdir $format/mail-from-root/ 2>/dev/null
  1244. cp $readmailroot $format/mail-from-root/ 2>/dev/null
  1245. fi
  1246. }
  1247.  
  1248. docker_checks()
  1249. {
  1250.  
  1251. #specific checks - check to see if we're in a docker container
  1252. dockercontainer=` grep -i docker /proc/self/cgroup 2>/dev/null; find / -name "*dockerenv*" -exec ls -la {} \; 2>/dev/null`
  1253. if [ "$dockercontainer" ]; then
  1254. echo -e "\e[00;33m[+] Looks like we're in a Docker container:\e[00m\n$dockercontainer"
  1255. echo -e "\n"
  1256. fi
  1257.  
  1258. #specific checks - check to see if we're a docker host
  1259. dockerhost=`docker --version 2>/dev/null; docker ps -a 2>/dev/null`
  1260. if [ "$dockerhost" ]; then
  1261. echo -e "\e[00;33m[+] Looks like we're hosting Docker:\e[00m\n$dockerhost"
  1262. echo -e "\n"
  1263. fi
  1264.  
  1265. #specific checks - are we a member of the docker group
  1266. dockergrp=`id | grep -i docker 2>/dev/null`
  1267. if [ "$dockergrp" ]; then
  1268. echo -e "\e[00;33m[+] We're a member of the (docker) group - could possibly misuse these rights!\e[00m\n$dockergrp"
  1269. echo -e "\n"
  1270. fi
  1271.  
  1272. #specific checks - are there any docker files present
  1273. dockerfiles=`find / -name Dockerfile -exec ls -l {} 2>/dev/null \;`
  1274. if [ "$dockerfiles" ]; then
  1275. echo -e "\e[00;31m[-] Anything juicy in the Dockerfile:\e[00m\n$dockerfiles"
  1276. echo -e "\n"
  1277. fi
  1278.  
  1279. #specific checks - are there any docker files present
  1280. dockeryml=`find / -name docker-compose.yml -exec ls -l {} 2>/dev/null \;`
  1281. if [ "$dockeryml" ]; then
  1282. echo -e "\e[00;31m[-] Anything juicy in docker-compose.yml:\e[00m\n$dockeryml"
  1283. echo -e "\n"
  1284. fi
  1285. }
  1286.  
  1287. lxc_container_checks()
  1288. {
  1289.  
  1290. #specific checks - are we in an lxd/lxc container
  1291. lxccontainer=`grep -qa container=lxc /proc/1/environ 2>/dev/null`
  1292. if [ "$lxccontainer" ]; then
  1293. echo -e "\e[00;33m[+] Looks like we're in a lxc container:\e[00m\n$lxccontainer"
  1294. echo -e "\n"
  1295. fi
  1296.  
  1297. #specific checks - are we a member of the lxd group
  1298. lxdgroup=`id | grep -i lxd 2>/dev/null`
  1299. if [ "$lxdgroup" ]; then
  1300. echo -e "\e[00;33m[+] We're a member of the (lxd) group - could possibly misuse these rights!\e[00m\n$lxdgroup"
  1301. echo -e "\n"
  1302. fi
  1303. }
  1304.  
  1305. footer()
  1306. {
  1307. echo -e "\e[00;33m### SCAN COMPLETE ####################################\e[00m"
  1308. }
  1309.  
  1310. call_each()
  1311. {
  1312. header
  1313. debug_info
  1314. system_info
  1315. user_info
  1316. environmental_info
  1317. job_info
  1318. networking_info
  1319. services_info
  1320. software_configs
  1321. interesting_files
  1322. docker_checks
  1323. lxc_container_checks
  1324. footer
  1325. }
  1326.  
  1327. while getopts "h:k:r:e:st" option; do
  1328. case "${option}" in
  1329. k) keyword=${OPTARG};;
  1330. r) report=${OPTARG}"-"`date +"%d-%m-%y"`;;
  1331. e) export=${OPTARG};;
  1332. s) sudopass=1;;
  1333. t) thorough=1;;
  1334. h) usage; exit;;
  1335. *) usage; exit;;
  1336. esac
  1337. done
  1338.  
  1339. call_each | tee -a $report 2> /dev/null
  1340. #EndOfScript
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement