Advertisement
Guest User

Untitled

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