Labs / Defensive Tools / Detect and analyse: signatures, sandbox, telemetry and decoys

Lab 2 of 5 · Detect and analyse: signatures, sandbox, telemetry and decoys

Malware sandboxing: detonate it and watch what it does

Run an unknown sample under strace on an isolated machine and read the behaviour no signature could name.

Start this lab 5 steps

The idea

A signature can only name malware it has already met. The sample Marlowe Toys pulled from quarantine matches nothing, so Sofia takes the other road: detonate it on an isolated machine fitted with tracing tools, and learn what it does by watching, not by reading its code.

strace records every system call the sample makes (each request it sends to the kernel, the core of the operating system): every file it opens, every connection it starts, every byte it writes. From one run she reads the file it steals, the file it drops, and the address it beacons to: indicators she pushes straight back into detection.

The screen shows what the author chose
The screen shows what the author chose
strace sits between program and kernel
strace sits between program and kernel
Two calls make a dropped file
Two calls make a dropped file
The request names the address
The request names the address
Isolation turns an unknown into indicators
Isolation turns an unknown into indicators

Steps

  1. Run it, and it tells you nothing

    The sample sits on an isolated sandbox: a machine with nothing else on its network and no route to the real world, so whatever the sample does stays contained. Treat the file as a black box. Reading its code is out, because real malware is usually compiled or scrambled past reading. So you learn what it does by running it and watching.

    Start with the obvious move: run it and read what it prints. A program's output is only what its author chose to show, which is exactly why it is worth so little here.

    sandbox:~# python3 /root/sample.py
  2. Watch which files it reads

    Everything a program does to the outside (read a file, open a network connection, write data) it does by asking the kernel, with a system call. strace sits between the program and the kernel and logs those calls, so it sees what the program actually did regardless of what it printed. That is the heart of a sandbox: instrumentation the sample cannot talk its way around.

    Point the lens at one question first. -P /etc/passwd tells strace to report only the system calls that touch that path. It is the file that lists every account on the machine, and a common first read for a program exploring a machine it does not belong on.

    sandbox:~# strace -f -P /etc/passwd python3 /root/sample.py
  3. Catch what it drops

    Malware rarely only reads; it writes. It drops a copy of itself to survive a reboot, a config file, or data it has staged for later theft. Those dropped files are evidence, and their paths are indicators to hunt for on every other machine the company owns.

    Move the lens to the writing side. A name that starts with a dot is hidden from a plain ls, and no installed program keeps its files loose under /tmp. Trace the calls that touch /tmp/.sync-cache, then look at what actually landed there.

    sandbox:~# strace -f -P /tmp/.sync-cache python3 /root/sample.py
    sandbox:~# cat /tmp/.sync-cache
  4. Where it calls home

    The find an analyst wants most is the command-and-control address: where the malware reaches out for orders. Block it and hunt every machine for connections to it, and one sample's detonation protects the whole network.

    A connection starts with the connect system call, which carries the destination address and port. Trace that one call. The sandbox has nothing listening and no route out, so the attempt leads nowhere. But the address the sample aimed at is recorded the moment it asks.

    sandbox:~# strace -f -e trace=connect python3 /root/sample.py
  5. An unknown turned into indicators

    Pull the run together. The signature tools in the last lab could not name this file. One detonation under instrumentation produced a profile no database held: it reads /etc/passwd, drops /tmp/.sync-cache, and beacons to 198.51.100.23:4444.

    The last piece is a name for the file itself: its hash, the same shareable fingerprint from the signatures lab. Take it, and you have everything to feed detection: a hash for the scanners, a dropped path to hunt, and a command-and-control (C2) address to block.

    sandbox:~# sha256sum /root/sample.py

Run these steps on real machines

Learn it on real machines.

Every lab is a small network of real Linux machines in your browser. Sign in with Google or email to start.

Start this lab