Courses3 levels
Level 1 · Foundations11 courses
Level 2 · Core5 courses
Level 3 · Advanced5 courses
Labs8 topics
Library Practice exams AI Range Pricing Start free

Practice library / Security operations basics

Workbook · Hard · 5 hoursFree account

Malware Analysis

Static and dynamic analysis, sandboxes, deobfuscation, and IOC extraction.

  • malware-analysis
  • static-analysis
  • dynamic-analysis
  • sandbox
  • ioc
On this page 7 sections
  1. ·About This Workbook
  2. ·Chapter 1 — The Analysis Lab
  3. Locked: Chapter 2 — Static Analysis
  4. Locked: Chapter 3 — Dynamic Analysis
  5. Locked: Chapter 4 — Indicators
  6. Locked: Final exercise
  7. Locked: Next steps

Malware analysis gives defenders the facts they need to detect, contain and remove hostile software. The field joins two disciplines: static review of a file without running it, and dynamic review that watches the file at work in a sandbox. This workbook covers both tracks and shows how they fit together. Tools include a hex editor, strings, PE and ELF readers, VirusTotal, Any.Run, debuggers and YARA. Each tool answers a different question about a sample. The common output is a list of indicators that the rest of the security team can act on, from a SOC analyst to a threat hunter.

What You'll Learn

  • Build an isolated analysis lab and keep a sample from reaching your real network
  • Triage an unknown file with hashes, file type, strings and imports, without running it
  • Recognise packing and explain why it changes your next step
  • Run a sample in a sandbox and read its process, file, registry and network activity
  • Use VirusTotal and Any.Run correctly, and know what each one leaks
  • Extract host and network indicators, write a YARA rule and a short report

About This Workbook

Malware is software that is written to harm a user, a system or an organisation. Malware analysis is the work of finding out what a given file does, so that you can detect it, contain it and stop it from returning.

A defender does not need to be a reverse engineer. In most incidents you answer five questions: Is this file malicious? What does it do? How does it start again after a reboot? Who does it talk to? How do I find it on other systems? This workbook teaches the steps that answer those questions in 30 to 90 minutes. We call this level triage and basic analysis. Full reverse engineering (reading the disassembly in depth) is a separate skill.

The workbook follows the order that analysts use at work:

  1. Build a lab that cannot hurt you.
  2. Study the file without running it (static analysis).
  3. Run it in the lab and watch (dynamic analysis).
  4. Turn the results into indicators, a detection rule and a report.

Authorised samples only. Analyse only files that you are allowed to hold: samples from your own incident, samples from your employer's security team, or samples from a public training source. Never run real malware on your daily computer. Never run it on a network that you do not control. The exercises in this workbook use harmless files (the EICAR test file and normal Windows programs) so that you can practise the method with no risk.

Related items: Malicious Document Analysis covers Office and PDF files. WinDbg Dynamic Analysis covers debugging. The lab YARA & Sigma Detection Rules lets you practise rules, and Memory Forensics with Volatility covers memory images. For the larger response process, read Digital Forensics & Incident Response.

Chapter 1 — The Analysis Lab

Objectives

  • Explain why the lab must be isolated and how isolation fails
  • Name the machines of a basic lab and the job of each
  • Take, use and restore a snapshot
  • Handle samples so that nobody opens one by accident

Explanation

A sample can encrypt files, spread to other computers or send data out. The lab has one rule: nothing that happens inside the lab can reach anything outside it. Everything else follows from this rule.

A basic lab has two virtual machines on a private virtual network.

MachineSystemJob
Analysis VMWindows 10 or 11 (an evaluation copy is enough)Runs the sample. Holds the monitoring tools.
Services VMLinux (for example Ubuntu or REMnux)Pretends to be the internet. Answers DNS and web requests. Records them.

Both VMs connect to one host-only network, for example 10.10.10.0/24. Host-only means that the VMs can talk to each other and to the host, and to nothing else. Do not choose "bridged" or "NAT" for the analysis VM. These modes give the sample a route to your real network.

Isolation fails in a few common ways. Check each one before the first run.

FailureWhy it happensCheck
The VM has a network adapter in NAT or bridged modeA default setting was keptOpen the VM settings and read every adapter
Shared folders or drag and drop are onHypervisor tools enable them for convenienceTurn them off; copy samples in with an ISO or a read-only disk
The host has a clipboard link with the VMSameTurn off clipboard sharing
The VM has a saved login to your cloud account or a password managerThe VM was used for other workUse a clean VM that holds nothing real
Hypervisor escapeA rare flaw in the virtualisation softwareKeep the hypervisor updated; do not store anything valuable on the host

Snapshots are the second pillar. A snapshot saves the full state of a VM. Take the first snapshot when the VM is clean and has all tools installed. After each sample, restore that snapshot. You then start every analysis from the same known state, and the previous sample leaves nothing behind.

Tools for the Analysis VM. Install them, then take the snapshot. Do not install them one by one after the sample runs.

JobTools
File and string triageDetect It Easy (diec), strings or FLOSS, PE-bear, PEStudio
Process and file monitoringProcess Monitor, Process Explorer (Sysinternals)
PersistenceAutoruns (Sysinternals)
Registry differencesRegshot
Event loggingSysmon with a public configuration file
Network captureWireshark
Debugging (later)x64dbg, WinDbg

Tools for the Services VM. INetSim simulates common internet services (DNS, HTTP, HTTPS, SMTP, FTP). FakeNet-NG does the same on Windows itself. Wireshark or tcpdump records the traffic.

Handling samples. Treat each sample as dangerous even when you think that it is not.

  • Keep samples in a password-protected archive. The common community password is infected. The password stops antivirus and mail systems from touching the file, and it stops people from opening it by mistake.
  • Rename a live sample to add .sample or .bin. A name that ends in .exe can run by one double-click.
  • Record the SHA-256 hash of every sample before anything else. The hash is the name of the sample in your notes.
  • Write your notes outside the VM, and copy only text out. Never copy a file out of the lab, except for the report artefacts that you made.

Legal point. In many countries, possession of malware is allowed for defence and research, but sending it to other people or running it on someone else's systems is not. Follow your employer's policy, and do not send a sample to a person who has no reason to hold it.

Worked example

You build the lab and prove that it is isolated. You do this proof once, and you repeat it after any change to the VM settings.

  1. In the hypervisor, create a host-only network. Set the Services VM to 10.10.10.1 and the Analysis VM to 10.10.10.50. Set the default gateway and the DNS server of the Analysis VM to 10.10.10.1.
  2. On the Services VM, start INetSim and capture traffic.
sudo inetsim --bind-address 10.10.10.1
sudo tcpdump -i eth0 -w /home/analyst/captures/lab-test.pcap
  1. On the Analysis VM, try to reach the real internet and a fake name.
ping 8.8.8.8
nslookup update.example.com
curl.exe http://update.example.com/test

The expected results show that the isolation works:

PS> ping 8.8.8.8
Request timed out.                                   <- good: no route out

PS> nslookup update.example.com
Server:  UnKnown
Address:  10.10.10.1
Name:    update.example.com
Address:  10.10.10.1                                 <- the Services VM answers every name

PS> curl.exe http://update.example.com/test
<html><body>This is the default INetSim HTTP server fake file.</body></html>

The ping fails, so there is no path to the real internet. Every name resolves to the Services VM, so a sample that asks for its server finds INetSim and not a real attacker. The page text is the default file that INetSim serves. Take the clean snapshot now and name it clean-tools-installed.

Test with the EICAR file. The EICAR test file is a harmless 68-character text string that every antivirus tool detects on purpose. Use it to check that your analysis tools see it and that the process of moving a file into the VM works. The string is published on the EICAR website, and you can search for "EICAR test file" to get it.

Practice questions

  1. Why is "NAT" a bad choice for the analysis VM, although the VM can still reach only the internet and not your other computers?
  2. The ping 8.8.8.8 test fails and nslookup returns 10.10.10.1. What does each result prove?
  3. After a sample runs, you want to run a second sample. What must you do first?
  4. Why do you store samples in an archive with a password?
Answers
  1. With NAT the sample has a route to the internet. It can contact its real server, download a second stage, send your data out, or attack other systems. Isolation must block this path, not only the path to your own network.
  2. The failed ping proves that the VM has no route to a real external address. The DNS answer proves that the Services VM receives and answers the name requests, so a sample that looks up a domain reaches the simulator.
  3. Restore the clean snapshot. Do not reuse the machine, because the first sample may have changed files, registry keys or settings that affect the second.
  4. The password stops mail and antivirus systems from changing or deleting the file, and it prevents an accidental run. It also makes the file safe to store, because an archive cannot execute.

Sign in to continue

5 more sections are for signed-in members. It is free: sign in with Google.

Related

This workbook is extra practice for the course Security operations basics. Do the lessons first.Open the course