Week 2 - Lecture
Week 2 - Lecture
Malware Forensics
Malware Analysis Environments
Why Use an Analysis Environment vs Local
● Fresh malware can be full of surprises, and if you run it on a local machine:
○ It can spread
○ Install backdoors
○ Lock your files
○ and, so on
● A safe environment will allow you to investigate the malware without
○ exposing your machine or other machines
○ the network to unexpected and unnecessary risk
○ IT contacting you and blocking your machine or traffic (happen w/ last year’s c.w.)
● Options
○ Dedicated physical machine - can build a cheap network using old PCs off E-Bay
■ See https://www.ebay.co.uk/sch/i.html?_nkw=Dell+optiplex
○ Virtual machines - can study malware usually quite safely, issue is PC resources
VM Structure
● A guest OS is installed within the host OS as a virtual machine - isolated in the virtual machine.
● Snap-shotting allows you to save the current state and roll back.
● Can clone or copy virtual machines and distribute.
● Run multiple machines at once - easier said than done on a stock PC/Laptop.
Setting up a Windows VM on Windows 10/11
● Go to https://developer.microsoft.com/en-us/windows/downloads/virtual-machines/ and get a VM
image
● Download and install in Virtual Box or use a OVA file
● Boot it in Virtual Box or another tool
● Disable Updates and add Anti-Virus folder exceptions
● Add your tools and setup any networking configuration: e.g., https://github.com/theRealFr13nd/analysisTools
Connections and Snapshots
● Never connect malware to the Internet without first performing some analysis to
determine what the malware might do when connected. Turn Network on/off (figure)
● Taking snapshots allows you save a computer’s current state and return to an earlier
state, so you see before and after the malware ran
● You can also share folders / drag and drop to share files
● Some malware can detect when it is running within a virtual machine. VMs also have
vulnerabilities which could theoretically be exploited.
Connections and Snapshots
● Never connect malware to the Internet without first performing some analysis to
determine what the malware might do when connected. Turn Network on/off (figure)
● Taking snapshots allows you save a computer’s current state and return to an earlier
state, so you see before and after the malware ran
● You can also share folders / drag and drop to share files
● Some malware can detect when it is running within a virtual machine. VMs also have
vulnerabilities which could theoretically be exploited.
Other Options
● VMware Workstation/Fusion https://www.vmware.com
● QEMU https://www.qemu.org/ very good for running IoT and Router OS’es images
● Cuckoo Sandbox https://cuckoosandbox.org/ - no explicit Windows OS due to licensing
Basic Dynamic Analysis
Step1 - Dynamic Analysis via Sandboxes online
● Online sandboxes e.g., hybrid-analysis.com
○ Number of options and choices to choose from
○ Can profile in multiple OS’es
○ Quick solution to find out as much as possible early on
○ Will run through various tools and tell you what is found
○ Try the lab’s first file
Dynamic Analysis via Sandboxes online
Dynamic Analysis via Sandboxes online
Optional Step - DNS Spoofing / Monitoring with NCAT
● You can spoof the DNS requests of Malware possible to redirect it locally
○ This isn’t always consistent on Windows, due to the complexities of the Networking stack
● But the process is to use ApateDNS, redirect to local host and listen on port 80 to see the
request (and reply, if relevant)
○ Can see the same in Wireshark often, and things via strings
● Alternative is a linux host to do similar, various Python scripts for this - example:
https://github.com/balle/python-network-hacks/blob/master/dns-spoof.py
Step 2 - Running Malware
Assuming your VM is setup and you’ve done preliminary analysis, you can run
malware carefully in isolation.
First take an initial snapshot of your VM so you can roll-back.
Executables
● Simply run from the command line which will show you output (or double click)
DLLs
● Execute rundll32.exe on the DLL with the exported function to run
○ Need to find the exports first e.g., PEView or PEiD
Running Malware - DLL example
rundll32.exe utility is a Windows program that allows users to invoke functions exported from a DLL (Dynamic Link Library).
You can monitor Malware that has been started with Process Monitor (procmon). It provides a way to monitor certain registry,
file system, network, process, and thread activity of the malware.
● Displays configurable columns containing information about individual events,
● The event’s sequence number, timestamp, name of the process causing the event, event operation, path used by the
event, and result of the event
Usage Steps:
1. Use File > Capture Events to stop monitoring and Edit > Clear Display to clear events
2. Next, run the subject malware with capture turned on.
3. choose Filter > Filter to set a filter of events
You can also filter by event types using the icons on the toolbar
● Registry - By examining registry operations, you can tell how a piece of malware installs itself in the registry.
● File system - Exploring file system interaction can show all files that the malware creates or configuration files it uses.
● Process activity - Investigating process activity can tell you whether the malware spawned additional processes.
● Network connections - shows you any ports on which the malware is listening.
Monitoring Processes - Process Explorer
● You can also monitor Malware in process explorer, it gives different information than ProcMon and shows how it is running on
the system, you can also kill the malware and see a number properties which can guide your investigation. It provides a useful
strings function, that will show strings on-file and in-memory, so you can see the difference, if any.
Step 4 - Comparing Registry Snapshots with Regshot
● Allows you to see the registry before and after in time i.e., before malware and after running it.
Steps: Select “HTML document” ; select “1st Shot” (may take 5 mins) ; select “2nd shot” ; select “compare” ;
inspect log.
Step 4 - Comparing Registry Snapshots with Regshot
Allows you to see the registry before and after in time i.e., before malware and after running it.
Steps: Select “HTML document” ; select “1st Shot” ; select “2nd shot” ; select “compare”; inspect
log.
Step 5 - Packet Sniffing with Wireshark
● Investigate the network
traffic packets from the
malware, to confirm other
forensic sources (network
indicators, etc), and see any
other activity.
● Same approach as you’ll
have done in other modules
Basic Dynamic Analysis In Practice
● All the tools can be used in order or together as required.
○ Using Snapshots is preferable on the VM so you can go back and forwards
○ Different malware may call for a different approach.
● Basic dynamic analysis of malware can assist and confirm your basic static analysis
findings.
● The aim is, as with basic static analysis, is find as much information upfront to thwart
the threat before a more comprehensive analysis.
Key Observation: basic static and dynamic analysis can give a lot upfront in a short period
of time
x86 Assembly I
Instruction Set Architecture (ISA)
● Is an abstract model of a computer, which defines the supported instructions,
data types, registers, etc.
● ISA specifies the behavior of machine code running on implementations of
that ISA
● Examples: Intel x86-64, ARM variants, MIPS, etc
○ https://www.mips.com/products/architectures/mips32-2/
Instruction Set Architecture (ISA)
● Essentially the machine’s language and built up from discrete statements or
instructions, which reduce to mathematical definitions.
● A given instruction may specify:
○ opcode (the instruction to be performed)
○ any explicit operands: registers, literal/constant values, addressing modes used to access
memory
Micro-architecture
● Micro-architecture is the way a given instruction set architecture (ISA) is
implemented in hardware (i.e., microchips) – i.e., the processor.
Comments
Program Structure in Assembly*
Function return values are typically stored in the EAX register for integer and pointer values. Therefore to use returned
value you must access it in EAX (See last lab question).
Example Windows Library call – Displaying a Message Box (Def. below)
Example Windows Library call – Displaying a Message Box (Code and Running below)
Example C Library call (MSVCRT.dll) – printf() (Code and Running below)