Labs / Forensics / The analyst's bench

Lab 5 of 5 · The analyst's bench

Reverse a binary: making a suspicious program give up its secrets

Take an unknown ELF apart statically, then run it to reveal its hidden secret.

Start this lab 4 steps

The idea

Hana, who runs IT at Fenwick Logistics, found a program called report-sync on the dispatch laptop lp03. It looks like a harmless sync tool, but she suspects it sends data somewhere. Find out where: read the program first, then run it in this sealed lab.

Symbols are the labels on the code
Symbols are the labels on the code
What strings can and cannot see
What strings can and cannot see
What the reveal loop does
What the reveal loop does
Reading it versus running it
Reading it versus running it

Steps

  1. First, find out what it is

    Before anything else, ask the file what it is. file reads a program's header and tells you its type, the processor it is built for, whether it is a standalone executable, and whether it has been stripped. That last one matters most for reversing. A compiler can leave in the names of functions and variables (the symbols), or strip them out to make the program smaller and harder to read. A stripped binary is a wall of unnamed code, and an unstripped one comes with a labelled map.

    Identifying a file first costs nothing, and it often tells you how hard the rest of the job will be.

    The first rule of reversing comes before any tool: never run an unknown program to see what happens. Learn everything you can without running it. Only then, somewhere sealed off, let it run to confirm.

    Ask file about the suspicious program.

    analyst:~# file /evidence/report-sync
  2. The strings in plain sight

    The fastest look inside any binary is strings, which scans the file for runs of readable text and prints them. Programs are full of text: error messages, menu text, format strings, and sometimes the very secret you're after, like a password, a key or a URL left in plain sight. It costs nothing, and now and then it gives you the whole answer.

    Hana's worry is that this tool reports back to some address when it runs. See whether the author was careless enough to leave that address, or anything else interesting, as plain text.

    analyst:~# strings /evidence/report-sync
  3. Static analysis: read the code without running it

    The address isn't a stored string, so the program must compute it as it runs. You could find out how by running the program, but a careful analyst first reads the code without running it. That's called static analysis. It's the safe path: you learn what a program does without letting it do anything, which matters when the program might really be hostile.

    Reading code means looking at the disassembly: the CPU instructions the compiler produced, turned back into short readable names like mov and xor. objdump -d does that. Because this binary isn't stripped, you can ask for one function by name instead of wading through all of it. The first step mentioned a function called reveal, so disassemble that one.

    analyst:~# objdump -d --disassemble=reveal /evidence/report-sync
  4. Dynamic analysis: let it run and reveal the answer

    Static analysis showed you how the address is hidden. The fastest way to the actual value is dynamic analysis: run the program and watch what it produces. The cost is real, because you're running code you don't trust, so you only ever do it somewhere sealed off like this lab, never on a machine or network you care about. This binary only prints the address and never connects anywhere. The lab is sealed too: the analyst machine has no route out of its own small network, so even a program that tried to call home would reach nothing.

    The evidence copy is read-only and not executable, so first make your own copy you can run. Then give it the activation key you pulled out of the strings. Try a wrong key first, to see the check the key guards.

    analyst:~# cp /evidence/report-sync report-sync
    analyst:~# chmod +x report-sync
    analyst:~# ./report-sync WRONG-KEY
    analyst:~# ./report-sync FENWICK-7731-LOGI

Run these steps on real machines

Keep reading

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