joemccray

New Linux For InfoSec

Jun 29th, 2016
2,233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.14 KB | None | 0 0
  1. ##############################
  2. # Linux For InfoSec Pros #
  3. # By Joe McCray #
  4. ##############################
  5.  
  6.  
  7.  
  8. ##########
  9. # VMWare #
  10. ##########
  11. - For this workshop you'll need the latest version of VMWare Workstation (Windows), Fusion (Mac), or Player.
  12.  
  13. - http://www.vmware.com/ap/products/player.html
  14.  
  15.  
  16. - Although you can get the VM to run in VirtualBox, I will not be supporting this configuration for this class.
  17.  
  18.  
  19. ##########################
  20. # Download the attack VM #
  21. ##########################
  22. https://s3.amazonaws.com/StrategicSec-VMs/StrategicsecUbuntu14.zip
  23. user: strategicsec
  24. pass: strategicsec
  25.  
  26. - Here is a good set of slides for getting started with Linux:
  27. http://www.slideshare.net/olafusimichael/linux-training-24086319
  28.  
  29.  
  30.  
  31.  
  32. - Log in to your Ubuntu host with the following credentials:
  33. user: strategicsec
  34. pass: strategicsec
  35.  
  36.  
  37.  
  38. - I prefer to use Putty to SSH into my Ubuntu host on pentests and I'll be teaching this class in the same manner that I do pentests.
  39. - You can download Putty from here:
  40. - http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe
  41.  
  42.  
  43. - For the purpose of this workshop 192.168.230.128 is my Ubuntu IP address so anytime you see that IP you'll know that's my Ubuntu host
  44.  
  45.  
  46.  
  47. ########################
  48. # Basic Linux Commands #
  49. ########################
  50.  
  51. pwd
  52.  
  53. whereis pwd
  54.  
  55. which pwd
  56.  
  57. sudo find / -name pwd
  58.  
  59. /bin/pwd
  60.  
  61. mkdir test
  62.  
  63. cd test
  64.  
  65. touch one two three
  66.  
  67. ls -l t (without pressing the Enter key, press the Tab key twice. What happens?)
  68.  
  69. h (and again without pressing the Enter key, press the Tab key twice. What happens?)
  70.  
  71. Press the 'Up arrow key' (What happens?)
  72.  
  73. Press 'Ctrl-A' (What happens?)
  74.  
  75. ls
  76.  
  77. clear (What happens?)
  78.  
  79. echo one > one
  80.  
  81. cat one (What happens?)
  82.  
  83. man cat (What happens?)
  84. q
  85.  
  86. cat two
  87.  
  88. cat one > two
  89.  
  90. cat two
  91.  
  92. cat one two > three
  93.  
  94. cat three
  95.  
  96. echo four >> three
  97.  
  98. cat three (What happens?)
  99.  
  100. wc -l three
  101.  
  102. man wc
  103. q
  104.  
  105. cat three | grep four
  106.  
  107. cat three | grep one
  108.  
  109. man grep
  110. q
  111.  
  112.  
  113. sudo grep eth[01] /etc/* (What happens?)
  114.  
  115. cat /etc/iftab
  116.  
  117.  
  118. man ps
  119. q
  120.  
  121. ps
  122.  
  123. ps aux
  124.  
  125. ps aux | less
  126.  
  127. Press the 'Up arrow key' (What happens?)
  128.  
  129. Press the 'Down arrow key' (What happens?)
  130. q
  131.  
  132. top
  133.  
  134. ############
  135. # VIM Demo #
  136. ############
  137. http://www.thegeekstuff.com/2009/03/8-essential-vim-editor-navigation-fundamentals/
  138.  
  139. -- DO VIM THIS TUTORIAL --
  140.  
  141.  
  142.  
  143. #########################################################################
  144. # What kind of Linux am I on and how can I find out? #
  145. # Great reference: #
  146. # https://blog.g0tmi1k.com/2011/08/basic-linux-privilege-escalation/ #
  147. #########################################################################
  148. - What’s the distribution type? What version?
  149. -------------------------------------------
  150. cat /etc/issue
  151. cat /etc/*-release
  152. cat /etc/lsb-release # Debian based
  153. cat /etc/redhat-release # Redhat based
  154.  
  155.  
  156.  
  157. - What’s the kernel version? Is it 64-bit?
  158. -------------------------------------------
  159. cat /proc/version
  160. uname -a
  161. uname -mrs
  162. rpm -q kernel
  163. dmesg | grep Linux
  164. ls /boot | grep vmlinuz-
  165.  
  166.  
  167.  
  168. - What can be learnt from the environmental variables?
  169. ----------------------------------------------------
  170. cat /etc/profile
  171. cat /etc/bashrc
  172. cat ~/.bash_profile
  173. cat ~/.bashrc
  174. cat ~/.bash_logout
  175. env
  176. set
  177.  
  178.  
  179. - What services are running? Which service has which user privilege?
  180. ------------------------------------------------------------------
  181. ps aux
  182. ps -ef
  183. top
  184. cat /etc/services
  185.  
  186.  
  187. - Which service(s) are been running by root? Of these services, which are vulnerable - it’s worth a double check!
  188. ---------------------------------------------------------------------------------------------------------------
  189. ps aux | grep root
  190. ps -ef | grep root
  191.  
  192.  
  193.  
  194. - What applications are installed? What version are they? Are they currently running?
  195. ------------------------------------------------------------------------------------
  196. ls -alh /usr/bin/
  197. ls -alh /sbin/
  198. dpkg -l
  199. rpm -qa
  200. ls -alh /var/cache/apt/archivesO
  201. ls -alh /var/cache/yum/
  202.  
  203.  
  204. - Any of the service(s) settings misconfigured? Are any (vulnerable) plugins attached?
  205. ------------------------------------------------------------------------------------
  206. cat /etc/syslog.conf
  207. cat /etc/chttp.conf
  208. cat /etc/lighttpd.conf
  209. cat /etc/cups/cupsd.conf
  210. cat /etc/inetd.conf
  211. cat /etc/apache2/apache2.conf
  212. cat /etc/my.conf
  213. cat /etc/httpd/conf/httpd.conf
  214. cat /opt/lampp/etc/httpd.conf
  215. ls -aRl /etc/ | awk '$1 ~ /^.*r.*/
  216.  
  217.  
  218.  
  219. - What jobs are scheduled?
  220. ------------------------
  221. crontab -l
  222. ls -alh /var/spool/cron
  223. ls -al /etc/ | grep cron
  224. ls -al /etc/cron*
  225. cat /etc/cron*
  226. cat /etc/at.allow
  227. cat /etc/at.deny
  228. cat /etc/cron.allow
  229. cat /etc/cron.deny
  230. cat /etc/crontab
  231. cat /etc/anacrontab
  232. cat /var/spool/cron/crontabs/root
  233.  
  234.  
  235. - Any plain text usernames and/or passwords?
  236. ------------------------------------------
  237. grep -i user [filename]
  238. grep -i pass [filename]
  239. grep -C 5 "password" [filename]
  240. find . -name "*.php" -print0 | xargs -0 grep -i -n "var $password" # Search for Joomla passwords
  241.  
  242.  
  243. - What NIC(s) does the system have? Is it connected to another network?
  244. ---------------------------------------------------------------------
  245. /sbin/ifconfig -a
  246. cat /etc/network/interfaces
  247. cat /etc/sysconfig/network
  248.  
  249.  
  250. - What are the network configuration settings? What can you find out about this network? DHCP server? DNS server? Gateway?
  251. ------------------------------------------------------------------------------------------------------------------------
  252. cat /etc/resolv.conf
  253. cat /etc/sysconfig/network
  254. cat /etc/networks
  255. iptables -L
  256. hostname
  257. dnsdomainname
  258.  
  259. - What other users & hosts are communicating with the system?
  260. -----------------------------------------------------------
  261. lsof -i
  262. lsof -i :80
  263. grep 80 /etc/services
  264. netstat -antup
  265. netstat -antpx
  266. netstat -tulpn
  267. chkconfig --list
  268. chkconfig --list | grep 3:on
  269. last
  270. w
  271.  
  272.  
  273.  
  274. - Whats cached? IP and/or MAC addresses
  275. -------------------------------------
  276. arp -e
  277. route
  278. /sbin/route -nee
  279.  
  280.  
  281. - Who are you? Who is logged in? Who has been logged in? Who else is there? Who can do what?
  282. ------------------------------------------------------------------------------------------
  283. id
  284. who
  285. w
  286. last
  287. cat /etc/passwd | cut -d: # List of users
  288. grep -v -E "^#" /etc/passwd | awk -F: '$3 == 0 { print $1}' # List of super users
  289. awk -F: '($3 == "0") {print}' /etc/passwd # List of super users
  290. cat /etc/sudoers
  291. sudo -l
  292.  
  293.  
  294.  
  295. - What sensitive files can be found?
  296. ----------------------------------
  297. cat /etc/passwd
  298. cat /etc/group
  299. cat /etc/shadow
  300. ls -alh /var/mail/
  301.  
  302.  
  303.  
  304. - Anything “interesting” in the home directorie(s)? If it’s possible to access
  305. ----------------------------------------------------------------------------
  306. ls -ahlR /root/
  307. ls -ahlR /home/
  308.  
  309.  
  310. - Are there any passwords in; scripts, databases, configuration files or log files? Default paths and locations for passwords
  311. ---------------------------------------------------------------------------------------------------------------------------
  312. cat /var/apache2/config.inc
  313. cat /var/lib/mysql/mysql/user.MYD
  314. cat /root/anaconda-ks.cfg
  315.  
  316.  
  317. - What has the user being doing? Is there any password in plain text? What have they been edting?
  318. -----------------------------------------------------------------------------------------------
  319. cat ~/.bash_history
  320. cat ~/.nano_history
  321. cat ~/.atftp_history
  322. cat ~/.mysql_history
  323. cat ~/.php_history
  324.  
  325.  
  326.  
  327. - What user information can be found?
  328. -----------------------------------
  329. cat ~/.bashrc
  330. cat ~/.profile
  331. cat /var/mail/root
  332. cat /var/spool/mail/root
  333.  
  334.  
  335. - Can private-key information be found?
  336. -------------------------------------
  337. cat ~/.ssh/authorized_keys
  338. cat ~/.ssh/identity.pub
  339. cat ~/.ssh/identity
  340. cat ~/.ssh/id_rsa.pub
  341. cat ~/.ssh/id_rsa
  342. cat ~/.ssh/id_dsa.pub
  343. cat ~/.ssh/id_dsa
  344. cat /etc/ssh/ssh_config
  345. cat /etc/ssh/sshd_config
  346. cat /etc/ssh/ssh_host_dsa_key.pub
  347. cat /etc/ssh/ssh_host_dsa_key
  348. cat /etc/ssh/ssh_host_rsa_key.pub
  349. cat /etc/ssh/ssh_host_rsa_key
  350. cat /etc/ssh/ssh_host_key.pub
  351. cat /etc/ssh/ssh_host_key
  352.  
  353.  
  354. - Any settings/files (hidden) on website? Any settings file with database information?
  355. ------------------------------------------------------------------------------------
  356. ls -alhR /var/www/
  357. ls -alhR /srv/www/htdocs/
  358. ls -alhR /usr/local/www/apache22/data/
  359. ls -alhR /opt/lampp/htdocs/
  360. ls -alhR /var/www/html/
  361.  
  362.  
  363. - Is there anything in the log file(s) (Could help with “Local File Includes”!)
  364. -----------------------------------------------------------------------------
  365. cat /etc/httpd/logs/access_log
  366. cat /etc/httpd/logs/access.log
  367. cat /etc/httpd/logs/error_log
  368. cat /etc/httpd/logs/error.log
  369. cat /var/log/apache2/access_log
  370. cat /var/log/apache2/access.log
  371. cat /var/log/apache2/error_log
  372. cat /var/log/apache2/error.log
  373. cat /var/log/apache/access_log
  374. cat /var/log/apache/access.log
  375. cat /var/log/auth.log
  376. cat /var/log/chttp.log
  377. cat /var/log/cups/error_log
  378. cat /var/log/dpkg.log
  379. cat /var/log/faillog
  380. cat /var/log/httpd/access_log
  381. cat /var/log/httpd/access.log
  382. cat /var/log/httpd/error_log
  383. cat /var/log/httpd/error.log
  384. cat /var/log/lastlog
  385. cat /var/log/lighttpd/access.log
  386. cat /var/log/lighttpd/error.log
  387. cat /var/log/lighttpd/lighttpd.access.log
  388. cat /var/log/lighttpd/lighttpd.error.log
  389. cat /var/log/messages
  390. cat /var/log/secure
  391. cat /var/log/syslog
  392. cat /var/log/wtmp
  393. cat /var/log/xferlog
  394. cat /var/log/yum.log
  395. cat /var/run/utmp
  396. cat /var/webmin/miniserv.log
  397. cat /var/www/logs/access_log
  398. cat /var/www/logs/access.log
  399. ls -alh /var/lib/dhcp3/
  400. ls -alh /var/log/postgresql/
  401. ls -alh /var/log/proftpd/
  402. ls -alh /var/log/samba/
  403.  
  404. - Note: auth.log, boot, btmp, daemon.log, debug, dmesg, kern.log, mail.info, mail.log, mail.warn, messages, syslog, udev, wtmp
  405.  
  406.  
  407.  
  408.  
  409. #################
  410. # IPTables Demo #
  411. #################
  412. - Reference:
  413. http://www.thegeekstuff.com/2011/06/iptables-rules-examples/
  414.  
  415. - Delete Existing Rules
  416. ---------------------
  417. sudo /sbin/iptables -F
  418. (or)
  419. sudo /sbin/iptables --flush
  420.  
  421.  
  422.  
  423. - Set Default Chain Policies
  424. --------------------------
  425. iptables -P INPUT DROP
  426. iptables -P FORWARD DROP
  427. iptables -P OUTPUT DROP
  428.  
  429.  
  430.  
  431. - Delete Existing Rules
  432. ---------------------
  433. sudo /sbin/iptables -F
  434. (or)
  435. sudo /sbin/iptables --flush
  436.  
  437.  
  438. - Block a Specific ip-address
  439. ---------------------------
  440. BLOCK_THIS_IP="1.2.3.4"
  441. iptables -A INPUT -s "$BLOCK_THIS_IP" -j DROP
  442.  
  443.  
  444. iptables -A INPUT -i eth0 -s "$BLOCK_THIS_IP" -j DROP
  445. iptables -A INPUT -i eth0 -p tcp -s "$BLOCK_THIS_IP" -j DROP
  446.  
  447.  
  448. - Allow ALL Incoming SSH
  449. ----------------------
  450. iptables -A INPUT -i eth0 -p tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
  451. iptables -A OUTPUT -o eth0 -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT
  452.  
  453.  
  454. - Allow Incoming SSH only from a Sepcific Network
  455. -----------------------------------------------
  456. iptables -A INPUT -i eth0 -p tcp -s 192.168.100.0/24 --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
  457. iptables -A OUTPUT -o eth0 -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT
  458.  
  459.  
  460. - Allow Incoming HTTP and HTTPS
  461. -----------------------------
  462. iptables -A INPUT -i eth0 -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
  463. iptables -A OUTPUT -o eth0 -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT
  464.  
  465.  
  466. iptables -A INPUT -i eth0 -p tcp --dport 443 -m state --state NEW,ESTABLISHED -j ACCEPT
  467. iptables -A OUTPUT -o eth0 -p tcp --sport 443 -m state --state ESTABLISHED -j ACCEPT
  468.  
  469.  
  470.  
  471. - Combine Multiple Rules Together using MultiPorts
  472. ------------------------------------------------
  473. iptables -A INPUT -i eth0 -p tcp -m multiport --dports 22,80,443 -m state --state NEW,ESTABLISHED -j ACCEPT
  474. iptables -A OUTPUT -o eth0 -p tcp -m multiport --sports 22,80,443 -m state --state ESTABLISHED -j ACCEPT
  475.  
  476.  
  477. - Allow Outgoing SSH
  478. ------------------
  479. iptables -A OUTPUT -o eth0 -p tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
  480. iptables -A INPUT -i eth0 -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT
  481.  
  482.  
  483.  
  484.  
  485.  
  486.  
  487.  
  488.  
  489.  
  490. ####################
  491. # MD5 Hashing Demo #
  492. ####################
  493. mkdir ~/demo
  494. cd ~/demo
  495.  
  496.  
  497.  
  498. mkdir hashdemo
  499. cd hashdemo
  500. echo test > test.txt
  501. cat test.txt
  502. md5sum test.txt
  503. echo hello >> test.txt
  504. cat test.txt
  505. md5sum test.txt
  506. cd ..
  507.  
  508.  
  509.  
  510. Reference:
  511. https://www.howtoforge.com/tutorial/linux-commandline-encryption-tools/
  512.  
  513.  
  514. #################################
  515. # Symmetric Key Encryption Demo #
  516. #################################
  517. mkdir gpgdemo
  518. cd gpgdemo
  519. echo test > test.txt
  520. cat test.txt
  521. gpg -c test.txt
  522. password
  523. password
  524. ls | grep test
  525. cat test.txt
  526. cat test.txt.gpg
  527. rm -rf test.txt
  528. ls | grep test
  529. gpg -o output.txt test.txt.gpg
  530. cat output.txt
  531.  
  532.  
  533. #########################################################################################################################
  534. # Asymmetric Key Encryption Demo #
  535. # #
  536. # Configure random number generator #
  537. # https://www.howtoforge.com/helping-the-random-number-generator-to-gain-enough-entropy-with-rng-tools-debian-lenny #
  538. #########################################################################################################################
  539.  
  540. sudo apt-get install rng-tools
  541. strategicsec
  542.  
  543. /etc/init.d/rng-tools start
  544.  
  545. sudo rngd -r /dev/urandom
  546. strategicsec
  547.  
  548.  
  549. echo hello > file1.txt
  550. echo goodbye > file2.txt
  551. echo green > file3.txt
  552. echo blue > file4.txt
  553.  
  554. tar czf files.tar.gz *.txt
  555.  
  556. gpg --gen-key
  557. 1
  558. 1024
  559. 0
  560. y
  561. John Doe
  562. --blank comment--
  563. O
  564. password
  565. password
  566.  
  567.  
  568.  
  569. gpg --armor --output file-enc-pubkey.txt --export 'John Doe'
  570.  
  571. cat file-enc-pubkey.txt
  572.  
  573. gpg --armor --output file-enc-privkey.asc --export-secret-keys 'John Doe'
  574.  
  575. cat file-enc-privkey.asc
  576.  
  577. gpg --encrypt --recipient 'John Doe' files.tar.gz
  578.  
  579. rm -rf files.tar.gz *.txt
  580.  
  581. ls
  582.  
  583. tar -zxvf files.tar.gz.gpg
  584.  
  585. gpg --output output.tar.gz --decrypt files.tar.gz.gpg
  586. password
  587.  
  588. tar -zxvf output.tar.gz
  589.  
  590. ls
  591.  
  592. Reference:
  593. http://linoxide.com/security/gpg-comand-linux-how-to-encrypt-and-decrypt-file/
  594.  
  595.  
  596.  
  597. ############################
  598. # Encryption using OpenSSL #
  599. ############################
  600. openssl genrsa -out private_key.pem 1024
  601. openssl rsa -in private_key.pem -out public_key.pem -outform PEM -pubout
  602.  
  603.  
  604. echo hello > encrypt.txt
  605. openssl rsautl -encrypt -inkey public_key.pem -pubin -in encrypt.txt -out encrypt.dat
  606.  
  607. cat encrypt.dat
  608.  
  609. rm -rf encrypt.txt
  610.  
  611. ls
  612.  
  613. openssl rsautl -decrypt -inkey private_key.pem -in encrypt.dat -out decrypt.txt
  614.  
  615. cat decrypt.txt
  616.  
  617.  
  618.  
  619.  
  620. ##############################################
  621. # Log Analysis with Linux command-line tools #
  622. ##############################################
  623. - The following command line executables are found in the Mac as well as most Linux Distributions.
  624.  
  625. cat – prints the content of a file in the terminal window
  626. grep – searches and filters based on patterns
  627. awk – can sort each row into fields and display only what is needed
  628. sed – performs find and replace functions
  629. sort – arranges output in an order
  630. uniq – compares adjacent lines and can report, filter or provide a count of duplicates
  631.  
  632.  
  633.  
  634. ###############
  635. # Apache Logs #
  636. ###############
  637.  
  638. Reference:
  639. http://www.the-art-of-web.com/system/logs/
  640.  
  641. wget https://s3.amazonaws.com/SecureNinja/Python/access_log
  642.  
  643.  
  644. - You want to list all user agents ordered by the number of times they appear (descending order):
  645.  
  646. awk -F\" '{print $6}' access_log | sort | uniq -c | sort -fr
  647.  
  648.  
  649.  
  650. - Using the default separator which is any white-space (spaces or tabs) we get the following:
  651.  
  652. awk '{print $1}' access_log # ip address (%h)
  653. awk '{print $2}' access_log # RFC 1413 identity (%l)
  654. awk '{print $3}' access_log # userid (%u)
  655. awk '{print $4,5}' access_log # date/time (%t)
  656. awk '{print $9}' access_log # status code (%>s)
  657. awk '{print $10}' access_log # size (%b)
  658.  
  659. - You might notice that we've missed out some items. To get to them we need to set the delimiter to the " character which changes the way the lines are 'exploded' and allows the following:
  660.  
  661. awk -F\" '{print $2}' access_log # request line (%r)
  662. awk -F\" '{print $4}' access_log # referer
  663. awk -F\" '{print $6}' access_log # user agent
  664.  
  665.  
  666. awk -F\" '{print $6}' access_log \
  667. | sed 's/(\([^;]\+; [^;]\+\)[^)]*)/(\1)/' \
  668. | sort | uniq -c | sort -fr
  669.  
  670.  
  671. - The next step is to start filtering the output so you can narrow down on a certain page or referer. Would you like to know which pages Google has been requesting from your site?
  672.  
  673. awk -F\" '($6 ~ /Googlebot/){print $2}' access_log | awk '{print $2}'
  674. Or who's been looking at your guestbook?
  675.  
  676. awk -F\" '($2 ~ /guestbook\.html/){print $6}' access_log
  677.  
  678.  
  679. Reference:
  680. https://blog.nexcess.net/2011/01/21/one-liners-for-apache-log-files/
  681.  
  682. # top 20 URLs from the last 5000 hits
  683. tail -5000 ./access_log | awk '{print $7}' | sort | uniq -c | sort -rn | head -20
  684. tail -5000 ./access_log | awk '{freq[$7]++} END {for (x in freq) {print freq[x], x}}' | sort -rn | head -20
  685.  
  686. # top 20 URLS excluding POST data from the last 5000 hits
  687. tail -5000 ./access_log | awk -F"[ ?]" '{print $7}' | sort | uniq -c | sort -rn | head -20
  688. tail -5000 ./access_log | awk -F"[ ?]" '{freq[$7]++} END {for (x in freq) {print freq[x], x}}' | sort -rn | head -20
  689.  
  690. # top 20 IPs from the last 5000 hits
  691. tail -5000 ./access_log | awk '{print $1}' | sort | uniq -c | sort -rn | head -20
  692. tail -5000 ./access_log | awk '{freq[$1]++} END {for (x in freq) {print freq[x], x}}' | sort -rn | head -20
  693.  
  694. # top 20 URLs requested from a certain ip from the last 5000 hits
  695. IP=1.2.3.4; tail -5000 ./access_log | grep $IP | awk '{print $7}' | sort | uniq -c | sort -rn | head -20
  696. IP=1.2.3.4; tail -5000 ./access_log | awk -v ip=$IP ' $1 ~ ip {freq[$7]++} END {for (x in freq) {print freq[x], x}}' | sort -rn | head -20
  697.  
  698. # top 20 URLS requested from a certain ip excluding, excluding POST data, from the last 5000 hits
  699. IP=1.2.3.4; tail -5000 ./access_log | fgrep $IP | awk -F "[ ?]" '{print $7}' | sort | uniq -c | sort -rn | head -20
  700. IP=1.2.3.4; tail -5000 ./access_log | awk -F"[ ?]" -v ip=$IP ' $1 ~ ip {freq[$7]++} END {for (x in freq) {print freq[x], x}}' | sort -rn | head -20
  701.  
  702. # top 20 referrers from the last 5000 hits
  703. tail -5000 ./access_log | awk '{print $11}' | tr -d '"' | sort | uniq -c | sort -rn | head -20
  704. tail -5000 ./access_log | awk '{freq[$11]++} END {for (x in freq) {print freq[x], x}}' | tr -d '"' | sort -rn | head -20
  705.  
  706. # top 20 user agents from the last 5000 hits
  707. tail -5000 ./access_log | cut -d\ -f12- | sort | uniq -c | sort -rn | head -20
  708.  
  709. # sum of data (in MB) transferred in the last 5000 hits
  710. tail -5000 ./access_log | awk '{sum+=$10} END {print sum/1048576}'
  711.  
  712.  
  713. ##############
  714. # Cisco Logs #
  715. ##############
  716.  
  717. wget https://s3.amazonaws.com/StrategicSec-Files/LogAnalysis/cisco.log
  718.  
  719.  
  720. AWK Basics
  721. ----------
  722. - To quickly demonstrate the print feature in awk, we can instruct it to show only the 5th word of each line. Here we will print $5. Only the last 4 lines are being shown for brevity.
  723.  
  724. cat cisco.log | awk '{print $5}' | tail -n 4
  725.  
  726.  
  727.  
  728.  
  729. - Looking at a large file would still produce a large amount of output. A more useful thing to do might be to output every entry found in “$5”, group them together, count them, then sort them from the greatest to least number of occurrences. This can be done by piping the output through “sort“, using “uniq -c” to count the like entries, then using “sort -rn” to sort it in reverse order.
  730.  
  731. cat cisco.log | awk '{print $5}'| sort | uniq -c | sort -rn
  732.  
  733.  
  734.  
  735.  
  736. - While that’s sort of cool, it is obvious that we have some garbage in our output. Evidently we have a few lines that aren’t conforming to the output we expect to see in $5. We can insert grep to filter the file prior to feeding it to awk. This insures that we are at least looking at lines of text that contain “facility-level-mnemonic”.
  737.  
  738. cat cisco.log | grep %[a-zA-Z]*-[0-9]-[a-zA-Z]* | awk '{print $5}' | sort | uniq -c | sort -rn
  739.  
  740.  
  741.  
  742.  
  743.  
  744. - Now that the output is cleaned up a bit, it is a good time to investigate some of the entries that appear most often. One way to see all occurrences is to use grep.
  745.  
  746. cat cisco.log | grep %LINEPROTO-5-UPDOWN:
  747.  
  748. cat cisco.log | grep %LINEPROTO-5-UPDOWN:| awk '{print $10}' | sort | uniq -c | sort -rn
  749.  
  750. cat cisco.log | grep %LINEPROTO-5-UPDOWN:| sed 's/,//g' | awk '{print $10}' | sort | uniq -c | sort -rn
  751.  
  752. cat cisco.log | grep %LINEPROTO-5-UPDOWN:| sed 's/,//g' | awk '{print $10 " changed to " $14}' | sort | uniq -c | sort -rn
  753.  
  754.  
  755.  
  756. ###########################
  757. # Target IP Determination #
  758. ###########################
  759. - This portion starts the actual workshop content
  760. - Zone Transfer fails on most domains, but here is an example of one that works:
  761. dig axfr heartinternet.co.uk @ns.heartinternet.co.uk
  762.  
  763.  
  764. - Usually you will need to do a DNS brute-force with something like blindcrawl or fierce
  765. perl blindcrawl.pl -d motorola.com
  766. Look up the IP addresses at:
  767. http://www.networksolutions.com/whois/index.jsp
  768.  
  769. cd ~/toolz/fierce2
  770. sudo apt-get install -y cpanminus cpan-listchanges cpanoutdated libappconfig-perl libyaml-appconfig-perl libnetaddr-ip-perl libnet-cidr-perl vim
  771. strategicsec
  772. wget http://search.cpan.org/CPAN/authors/id/A/AB/ABW/Template-Toolkit-2.14.tar.gz
  773. tar -zxvf Template-Toolkit-2.14.tar.gz
  774. cd Template-Toolkit-2.14/
  775. perl Makefile.PL
  776. y
  777. y
  778. n
  779. y
  780. sudo make install
  781.  
  782. sudo bash install.sh
  783.  
  784. ./fierce
  785.  
  786. ./fierce -dns motorola.com
  787.  
  788. cd ~/toolz/
  789.  
  790.  
  791.  
  792.  
  793. - Here we do a forward lookup against an entire IP range. Basically take every IP in the range and see what it's hostname is
  794. cd ~/toolz/
  795. ./ipcrawl 148.87.1.1 148.87.1.254 (DNS forward lookup against an IP range)
  796.  
  797.  
  798. sudo nmap -sL 148.87.1.0-255
  799. sudo nmap -sL 148.87.1.0-255 | grep oracle
  800.  
  801.  
  802.  
  803.  
  804.  
  805.  
  806. ###########################
  807. # Load Balancer Detection #
  808. ###########################
  809.  
  810. - Here are some options to use for identifying load balancers:
  811. - http://toolbar.netcraft.com/site_report/
  812. - Firefox LiveHTTP Headers
  813.  
  814.  
  815. - Here are some command-line options to use for identifying load balancers:
  816.  
  817. dig google.com
  818.  
  819. cd ~/toolz
  820. ./lbd-0.1.sh google.com
  821.  
  822.  
  823. halberd microsoft.com
  824. halberd motorola.com
  825. halberd oracle.com
  826.  
  827.  
  828.  
  829.  
  830.  
  831. ######################################
  832. # Web Application Firewall Detection #
  833. ######################################
  834.  
  835. cd ~/toolz/wafw00f
  836. python wafw00f.py http://www.oracle.com
  837. python wafw00f.py http://www.strategicsec.com
  838.  
  839.  
  840. cd ~/toolz/
  841. sudo nmap -p 80 --script http-waf-detect.nse oracle.com
  842.  
  843. sudo nmap -p 80 --script http-waf-detect.nse healthcare.gov
  844.  
  845.  
  846. #########################
  847. # Playing with Nmap NSE #
  848. #########################
  849.  
  850. nmap -Pn -p80 --script ip-geolocation-* strategicsec.com
  851.  
  852. nmap -p80 --script dns-brute strategicsec.com
  853.  
  854. nmap --script http-robtex-reverse-ip secore.info
  855.  
  856. nmap -Pn -p80 --script=http-headers strategicsec.com
  857.  
  858.  
  859. ls /usr/share/nmap/scripts | grep http
  860. nmap -Pn -p80 --script=http-* strategicsec.com
  861.  
  862. sudo nmap -Pn -n --open -p21 --script=banner,ftp-anon,ftp-bounce,ftp-proftpd-backdoor,ftp-vsftpd-backdoor 148.87.1.0/24
  863.  
  864. sudo nmap -Pn -n --open -p22 --script=sshv1,ssh2-enum-algos 148.87.1.0/24
  865.  
  866. sudo nmap -Pn -n -sU --open -p53 --script=dns-blacklist,dns-cache-snoop,dns-nsec-enum,dns-nsid,dns-random-srcport,dns-random-txid,dns-recursion,dns-service-discovery,dns-update,dns-zeustracker,dns-zone-transfer 148.87.1.0/24
  867.  
  868. sudo nmap -Pn -n --open -p111 --script=nfs-ls,nfs-showmount,nfs-statfs,rpcinfo 148.87.1.0/24
  869.  
  870. sudo nmap -Pn -n --open -p445 --script=msrpc-enum,smb-enum-domains,smb-enum-groups,smb-enum-processes,smb-enum-sessions,smb-enum-shares,smb-enum-users,smb-mbenum,smb-os-discovery,smb-security-mode,smb-server-stats,smb-system-info,smbv2-enabled,stuxnet-detect 148.87.1.0/24
  871.  
  872. sudo nmap -Pn -n --open -p1433 --script=ms-sql-dump-hashes,ms-sql-empty-password,ms-sql-info 148.87.1.0/24
  873.  
  874. sudo nmap -Pn -n --open -p1521 --script=oracle-sid-brute --script oracle-enum-users --script-args oracle-enum-users.sid=ORCL,userdb=orausers.txt 148.87.1.0/24
  875.  
  876. sudo nmap -Pn -n --open -p3306 --script=mysql-databases,mysql-empty-password,mysql-info,mysql-users,mysql-variables 148.87.1.0/24
  877.  
  878. sudo nmap -Pn -n --open -p3389 --script=rdp-vuln-ms12-020,rdp-enum-encryption 148.87.1.0/24
  879.  
  880. sudo nmap -Pn -n --open -p5900 --script=realvnc-auth-bypass,vnc-info 148.87.1.0/24
  881.  
  882. sudo nmap -Pn -n --open -p6000-6005 --script=x11-access 148.87.1.0/24
  883.  
  884. sudo nmap -Pn -n --open -p27017 --script=mongodb-databases,mongodb-info 148.87.1.0/24
  885.  
  886. ############
  887. # Nmap NSE #
  888. ############
  889.  
  890. - Reference for this tutorial is:
  891. https://thesprawl.org/research/writing-nse-scripts-for-vulnerability-scanning/
  892.  
  893. ----------------------------------------------------------------------
  894. sudo vi /usr/share/nmap/scripts/intro-nse.nse
  895.  
  896. -- The Head Section --
  897. -- The Rule Section --
  898. portrule = function(host, port)
  899. return port.protocol == "tcp"
  900. and port.number == 80
  901. and port.state == "open"
  902. end
  903.  
  904. -- The Action Section --
  905. action = function(host, port)
  906. return "Linux for InfoSec Professionals!"
  907. end
  908. ----------------------------------------------------------------------
  909.  
  910. - Ok, now that we've made that change let's run the script
  911. sudo nmap --script=/usr/share/nmap/scripts/intro-nse.nse darkoperator.com -p 22,80,443
  912.  
  913.  
  914.  
  915.  
  916.  
  917.  
  918. ----------------------------------------------------------------------
  919. sudo vi /usr/share/nmap/scripts/intro-nse.nse
  920.  
  921. -- The Head Section --
  922. local shortport = require "shortport"
  923.  
  924. -- The Rule Section --
  925. portrule = shortport.http
  926.  
  927.  
  928. -- The Action Section --
  929. action = function(host, port)
  930. return "Linux for InfoSec Professionals!"
  931. end
  932. ----------------------------------------------------------------------
  933.  
  934. - Ok, now that we've made that change let's run the script
  935. sudo nmap --script=/usr/share/nmap/scripts/intro-nse.nse darkoperator.com -p 22,80,443
  936.  
  937.  
  938.  
  939.  
  940.  
  941.  
  942.  
  943. ----------------------------------------------------------------------
  944. sudo vi /usr/share/nmap/scripts/intro-nse.nse
  945.  
  946. -- The Head Section --
  947. local shortport = require "shortport"
  948. local http = require "http"
  949.  
  950. -- The Rule Section --
  951. portrule = shortport.http
  952.  
  953. -- The Action Section --
  954. action = function(host, port)
  955.  
  956. local uri = "/blog/2016/4/2/meterpreter-new-windows-powershell-extension/"
  957. local response = http.get(host, port, uri)
  958. return response.status
  959.  
  960. end
  961. ----------------------------------------------------------------------
  962.  
  963. - Ok, now that we've made that change let's run the script
  964. sudo nmap --script=/usr/share/nmap/scripts/intro-nse.nse darkoperator.com -p 22,80,443
  965.  
  966.  
  967.  
  968.  
  969. ----------------------------------------------------------------------
  970. sudo vi /usr/share/nmap/scripts/intro-nse.nse
  971.  
  972. -- The Head Section --
  973. local shortport = require "shortport"
  974. local http = require "http"
  975.  
  976. -- The Rule Section --
  977. portrule = shortport.http
  978.  
  979. -- The Action Section --
  980. action = function(host, port)
  981.  
  982. local uri = "/blog/2016/4/2/meterpreter-new-windows-powershell-extension/"
  983. local response = http.get(host, port, uri)
  984.  
  985. if ( response.status == 200 ) then
  986. return response.body
  987. end
  988.  
  989. end
  990. ----------------------------------------------------------------------
  991.  
  992. - Ok, now that we've made that change let's run the script
  993. sudo nmap --script=/usr/share/nmap/scripts/intro-nse.nse darkoperator.com -p 22,80,443
  994.  
  995.  
  996.  
  997.  
  998.  
  999.  
  1000.  
  1001.  
  1002.  
  1003. ----------------------------------------------------------------------
  1004. sudo vi /usr/share/nmap/scripts/intro-nse.nse
  1005.  
  1006. -- The Head Section --
  1007. local shortport = require "shortport"
  1008. local http = require "http"
  1009. local string = require "string"
  1010.  
  1011. -- The Rule Section --
  1012. portrule = shortport.http
  1013.  
  1014. -- The Action Section --
  1015. action = function(host, port)
  1016.  
  1017. local uri = "/blog/2016/4/2/meterpreter-new-windows-powershell-extension/"
  1018. local response = http.get(host, port, uri)
  1019.  
  1020. if ( response.status == 200 ) then
  1021. local title = string.match(response.body, "Pentest Candidate Program")
  1022. return title
  1023. end
  1024.  
  1025. end
  1026. ----------------------------------------------------------------------
  1027.  
  1028. - Ok, now that we've made that change let's run the script
  1029. sudo nmap --script=/usr/share/nmap/scripts/intro-nse.nse darkoperator.com -p 22,80,443
  1030.  
  1031.  
  1032.  
  1033.  
  1034.  
  1035.  
  1036.  
  1037. ----------------------------------------------------------------------
  1038. sudo vi /usr/share/nmap/scripts/intro-nse.nse
  1039.  
  1040. -- The Head Section --
  1041. local shortport = require "shortport"
  1042. local http = require "http"
  1043. local string = require "string"
  1044.  
  1045. -- The Rule Section --
  1046. portrule = shortport.http
  1047.  
  1048. -- The Action Section --
  1049. action = function(host, port)
  1050.  
  1051. local uri = "/blog/2016/4/2/meterpreter-new-windows-powershell-extension/"
  1052. local response = http.get(host, port, uri)
  1053.  
  1054. if ( response.status == 200 ) then
  1055. local title = string.match(response.body, "Pentest Candidate Program")
  1056.  
  1057. if (title) then
  1058. return "Vulnerable"
  1059. else
  1060. return "Not Vulnerable"
  1061. end
  1062. end
  1063. end
  1064.  
  1065. ----------------------------------------------------------------------
  1066.  
  1067. - Ok, now that we've made that change let's run the script
  1068. sudo nmap --script=/usr/share/nmap/scripts/intro-nse.nse darkoperator.com -p 22,80,443
  1069.  
  1070.  
  1071.  
  1072.  
  1073.  
  1074.  
  1075.  
  1076.  
  1077.  
  1078. #############################
  1079. # Linux For InfoSe Homework #
  1080. #############################
  1081. In order to receive your certificate of attendance you must complete the all of the quizzes on the http://linuxsurvival.com/linux-tutorial-introduction/ website.
  1082.  
  1083.  
  1084. Submit the results via email in an MS Word document with (naming convention example: YourFirstName-YourLastName-Linux-For-InfoSec-Homework.docx)
  1085.  
  1086.  
  1087.  
  1088.  
  1089. ##############################
  1090. # Linux For InfoSe Challenge #
  1091. ##############################
  1092.  
  1093. In order to receive your certificate of proficiency you must complete all of the tasks covered in the Linux For InfoSec pastebin (http://pastebin.com/b5SxBRf6).
  1094.  
  1095. Submit the results via email in an MS Word document with (naming convention example: YourFirstName-YourLastName-Linux-For-InfoSec-Challenge.docx)
  1096.  
  1097.  
  1098.  
  1099.  
  1100. IMPORTANT NOTE:
  1101. Your homework/challenge must be submitted via email to both (joe-at-strategicsec-.-com and kasheia-at-strategicsec-.-com) by Sunday October 16th at midnight EST.
Add Comment
Please, Sign In to add comment