Advertisement
Guest User

Untitled

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