Skip to content
Tutorials Center
My learning

Topics

Lesson 15 of 37 ยท Dynamic Analysis

Dynamic Analysis Basics

Learn the method of dynamic malware analysis: preparing the lab, taking baselines, running a sample, recording behaviour, diffing system state and handling evasion.

Dynamic analysis means running a sample in a controlled environment and watching what it does. Where static analysis tells you what a program could do, dynamic analysis shows what it does: which processes it starts, which files and registry keys it changes, what it sends over the network. It is the fastest route to indicators and often the point where a confusing sample suddenly makes sense.

It is also the stage that carries risk, so everything in Building a Safe Analysis Lab applies. This course never asks you to run real malware: the examples simulate observations with ordinary Python data so you can practice the method.

The method: baseline, run, compare

flowchart LR
    A["Clean snapshot"] --> B["Start monitors"]
    B --> C["Capture baseline state"]
    C --> D["Run sample"]
    D --> E["Wait and interact"]
    E --> F["Capture end state"]
    F --> G["Compare and record"]
    G --> H["Revert snapshot"]
  1. Revert to a clean snapshot. You start from a known state.
  2. Start the monitors (process, file, registry, network) before running the sample so you do not miss the first moments.
  3. Capture a baseline of the system: running processes, registry autorun keys, files in sensitive folders.
  4. Run the sample. Use a realistic way to launch it: double-click an executable, open a document, run a DLL with the correct loader.
  5. Wait and interact. Some samples act immediately; others wait minutes. Click dialogs, open documents, simulate a user.
  6. Capture the end state and compare it with the baseline.
  7. Save evidence (logs, captures, screenshots), then revert.

What to watch

Area Questions Chapter
Processes What starts? Parent and child relationships, command lines, injected code Processes and files
Files What is created, modified, deleted, encrypted? same
Registry What keys are written, especially autoruns? Registry and persistence
Network DNS, HTTP, other protocols, destinations, intervals Network behaviour
Memory Injected code, unpacked payloads later chapters
Windows objects Mutexes, services, scheduled tasks, pipes persistence lesson

System-state diffing

The oldest dynamic technique is also the simplest: record the state before, record it after, and list the differences. Tools such as Regshot do it for the registry, and file-integrity tools do it for files. In the example below, "state" is a dictionary of made-up paths and values.

Python Diff system state before and after a run

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The result reads like a story: a program dropped upd.exe, registered it in a Run key, changed the hosts file (a classic way to redirect domains) and started a command shell. Each line is an observation you would record, then interpret.

Timing: samples that wait

Sandbox-aware samples delay their activity (with Sleep calls) or wait for user input. Common ways to deal with this:

  • Wait longer and keep the monitors running.
  • Interact: move the mouse, open files, type.
  • Speed up time in the sandbox (some tools skip sleep calls; this itself can be detected).
  • Debugging to skip the wait (advanced).

Because real runs take minutes, analysts use timelines: every event with a timestamp, in order. The simulation below shows how to build one from separate logs.

Python Merge monitor logs into a timeline

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice how the combined view reveals something no single log shows: the same domain queried every five minutes.

Realism matters

Malware often checks whether it is being watched. To get honest behaviour:

  • Give the VM a realistic environment: typical RAM and disk size, a few documents, installed common software, a plausible user name, a screen resolution of an ordinary desktop.
  • Avoid analyst-looking artifacts: lab hostnames, obvious tool folders.
  • Connect it to the simulated internet so DNS and HTTP requests get answers.
  • Expect some samples to still refuse. Absence of behaviour is a finding to note, not to ignore.

Safety during runs

  • Check your pre-flight list (Ethics, Law and Safety Rules).
  • Never connect the lab to the real network because a sample "will not do anything otherwise".
  • Stop the run and revert if something unexpected happens (the sample tries to reach your host, the VM misbehaves).
  • Keep a log of exactly what you did.

Common mistakes

  • Starting the monitors after launching the sample.
  • Giving up after 60 seconds.
  • Not saving evidence before reverting.
  • Forgetting that a sample may need arguments or a specific export to run (DLLs).
  • Concluding "benign" because nothing happened in the sandbox.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why should monitoring tools be started before running the sample?

    Samples often act in their first seconds. Late monitors miss those events.
  2. 2. What does comparing a before and after snapshot of the registry and files reveal?

    A state diff lists created, modified and deleted items, which become candidate indicators.
  3. 3. A sample does nothing in the sandbox for two minutes. What is the best interpretation?

    Delays and sandbox checks are common. Lack of behaviour is not proof of safety.
  4. 4. Why build a merged timeline from separate logs?

    A combined timeline reveals relationships and patterns, such as periodic beaconing, that single logs do not show.

Summary

  • Dynamic analysis runs a sample in an isolated lab and records behaviour.
  • Method: clean snapshot, start monitors, baseline, run, wait and interact, compare, save evidence, revert.
  • Diff states for files, registry and processes, and merge logs into a timeline.
  • Samples may delay or check for analysis; make the lab realistic and run long enough.
  • No behaviour does not mean no malware.

Next: Monitoring Processes and Files