Advertisement
Guest User

Untitled

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