Advertisement
Guest User

aaasaaa

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