TExcelTAD
Home › Malware Analysis, Digital Forensics & Incident Response › Malware Analysis, Forensics and IR: Introduction and Safety

Malware Analysis, Forensics and IR: Introduction and Safety

At 09:12 on a Tuesday an endpoint alert fires: a process nobody recognises, started from a user's Downloads folder, has written a file to AppData, looked up an odd host name and opened a connection every sixty seconds since. Three questions arrive at once. What is this program and what can it do? (malware analysis). What exactly happened on this machine, and since when? (digital forensics). What do we do now, in what order, and who must be told? (incident response). Together they are called DFIR, and they are the subject of this course.

The three disciplines feed each other. Analysis of the file gives indicators (a hash, a domain, a registry path) that forensics searches for on other machines; forensics gives the timeline that tells responders how far the intrusion got; response decides what to contain first and what evidence to preserve before anything is wiped. A good analyst moves between them all day.

The prerequisite is Reverse Engineering & Binary Analysis: this course assumes you can read a PE header, know what imports are and have seen entropy and strings. Where a topic was taught there, this course links to it and adds the analyst's and responder's view. The first look at malware in Security Foundations and the survey lessons on malware and incident response are the on-ramp.

The safety line of this course

Malware analysis is the one field of the track where people deliberately handle hostile code. This course does not. The track's safety line is binding, and here it means:

  1. No real malware, anywhere. Every "sample" in this course is a benign synthetic file that the lesson builds itself: text and byte blobs that look suspicious (a fake configuration block, a fake beacon address under lab.test, harmless strings XOR-encoded, a random high-entropy section, a PE header built with Python's struct). The only "malware" is the EICAR test file, a 68-byte string every anti-virus product agrees to detect so that people can test their tools safely.
  2. No malicious functionality is ever written. No droppers, persistence, keyloggers, encryption of victims' files, command-and-control protocols or evasion tricks. Behaviours like these are described, shown as labelled transcripts of a sandbox run of a benign lab sample, or detected in synthetic logs.
  3. Dynamic analysis runs only harmless programs: a toy C program the lesson prints in full, traced with strace in a sandbox with no network.
  4. Lab addresses only: 10.10.0.0/24, the RFC 5737 blocks 192.0.2.0/24, 198.51.100.0/24 and 203.0.113.0/24, and names under lab.test. No real organisation appears as a victim or attacker.

Never run a file you suspect is malicious on a machine you care about, and never "just try it" outside an isolated lab. If you analyse real samples at work, do it in the employer's lab, under its procedures, with the isolation rules of the next lesson.

What you will learn

Section Questions it answers
Getting started How is an analysis lab isolated? How are samples stored, moved and named safely?
Classification What families of behaviour exist (viruses to wipers)? How are samples named and mapped to MITRE ATT&CK?
Static analysis What does the file say about itself without running: type, hashes, fuzzy hashes, strings, entropy, PE structure, encoded strings?
Dynamic analysis What does it do when it runs: sandboxes, process, file, registry and network activity, call traces?
IOCs and detection Which indicators are worth sharing, how STIX expresses them, how YARA and Sigma rules are written and tested
Digital forensics Evidence principles, chain of custody, timestamps, deleted files and carving, memory forensics, timelines
Incident response NIST SP 800-61 Rev. 3 and CSF 2.0, containment to lessons learned, ransomware, reporting

A first triage, in your sandbox

Here is the whole static workflow in miniature, run in the course's sandbox (no network, no root, only files it creates and the read-only lab samples in $SAMPLES). It writes a synthetic "suspicious" file, identifies it, hashes it, pulls out its readable strings and runs a YARA rule against it and the EICAR sample:

bash · try it yourself
python3 - <<'PY'
import random
blob = b"MZ" + b"\0" * 62                                   # looks like the start of a Windows program
blob += b"LABSAMPLE config: server=update.beacon.lab.test port=8080 interval=60\0"
blob += random.Random(11).randbytes(512)                    # a high-entropy section (fixed seed)
open("sample.bin", "wb").write(blob)
PY
file sample.bin
sha256sum sample.bin
strings -n 10 sample.bin
cat > lab.yar <<'RULE'
rule lab_beacon_config
{
    strings:
        $cfg = "LABSAMPLE config:"
        $dom = ".beacon.lab.test"
    condition:
        uint16(0) == 0x5A4D and all of them
}
RULE
yara -s lab.yar sample.bin
yara -s $SAMPLES/rules/eicar.yar $SAMPLES/files
sample.bin: MS-DOS executable, MZ for MS-DOS
85b0486775c003332af19abdd84dee497455140d4160e896557384051171c04e  sample.bin
LABSAMPLE config: server=update.beacon.lab.test port=8080 interval=60
lab_beacon_config sample.bin
0x40:$cfg: LABSAMPLE config:
0x5f:$dom: .beacon.lab.test
eicar_test_file /opt/sec-samples/files/eicar.com
0x1c:$s: EICAR-STANDARD-ANTIVIRUS-TEST-FILE!

file reads the first bytes and calls it a DOS executable (only the MZ magic is real); the SHA-256 names this exact file; strings reveals the fake configuration; and the rule matches because both strings are present and the file starts with MZ (0x5A4D read as a little-endian 16-bit number). The EICAR rule finds its string at offset 28. Every step reappears in depth later: file types, hashes, strings, YARA.

How the examples run

  • ```bash run blocks are recorded sandbox sessions: real runs of file 5.45, sha256sum, strings, YARA 4.5.0, ssdeep 2.14.1, tshark 4.2.2, strace and Python 3.12 with scapy in a container with no network and no root. Values that change on every run are normalised.
  • ```python run blocks run in your browser (Python in WebAssembly): parsers for headers, a YARA-like matcher, carving, pandas timelines.
  • ```console blocks are labelled lab transcripts of GUI or Windows tools (Process Monitor, Sysmon, Volatility 3 on a lab memory image, a sandbox report) recorded against benign lab samples. They are illustrations: their layout follows the tools, and the scope is stated with each one.

How it is detected, and how it is prevented

Every analysis lesson ends with what defenders do with the result: a rule, a block, a hunt, a hardening step. Analysis that produces no detection or fix is just curiosity. Equally, every forensic lesson explains how evidence is protected from being changed, and every response lesson explains what to do before the incident so that the response works.

Pitfalls

  • Treating analysis as the goal. The goal is a decision: is this malicious, what does it touch, what do we block, who is affected?
  • Skipping the lab. Opening a suspicious attachment "just to look" on a work laptop is how incidents start.
  • Uploading samples to public services. Many public sandboxes and scanners make uploaded files available to their paying users, who can include the attacker, who then learns that you found it. Check policy first (Handling Samples).

Practice

1. Name the three disciplines of DFIR and the question each answers.

Malware analysis: what is this program and what can it do? Digital forensics: what happened on this system and when? Incident response: what do we do, in which order, and whom do we tell?

2. Why does file call the synthetic sample an executable although it contains no code?

file matches magic numbers. The first two bytes are MZ, the DOS executable signature, so it reports the format that signature belongs to. Magic numbers identify a claimed format, not validity.

Test yourself

What is the only 'malware' file used in this course?

  1. A defanged real ransomware sample
  2. The EICAR anti-virus test file
  3. A sample from a public malware repository
  4. None: no files are used

Which discipline answers 'what happened on this machine, and since when'?

  1. Malware analysis
  2. Digital forensics
  3. Penetration testing
  4. Threat modelling

What does the YARA condition uint16(0) == 0x5A4D test?

  1. That the file is 0x5A4D bytes long
  2. That the first two bytes are 'MZ'
  3. That the file contains the string 'ZM' anywhere
  4. That the PE header is valid

Why should an analyst not upload a confidential sample to a public online scanner by default?

  1. Scanners cannot read executables
  2. The file becomes available to other users of the service, possibly including the attacker
  3. It is always illegal
  4. Public scanners modify the file