Advertisement
Guest User

dszdsa

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