Dynamic Analysis
Dynamic analysis consists of running the binary and observing its behavior in real time: what files it opens, what network connections it makes, what system calls it performs, how memory changes, and what it really does (not just what it seems to do in the code). It complements static analysis (see Static Analysis): what’s hard to follow reading the disassembly —obfuscated code, runtime encryption, input-dependent logic— becomes clear by running it under observation. It’s essential for analyzing malware and unpacking protected binaries.
What it is
Section titled “What it is”While static reasons about the code “at rest”, dynamic observes the program “in motion”. You run the binary under instrumentation (syscall tracers, debugger, hooks) and record what happens: every file, connection, and syscall reveals its real behavior, even if the code is obfuscated or decrypts itself only at runtime.
Theory: observation levels
Section titled “Theory: observation levels”flowchart TD
A["running binary"] --> B["syscalls: strace"]
A --> C["library calls: ltrace"]
A --> D["files/network/processes: lsof, tcpdump"]
A --> E["internal state: GDB + pwndbg/GEF"]
A --> F["instrumentation: Frida / Pin / Qiling"]
A --> G["symbolic execution: angr"]
B --> H["high-level behavior"]
C --> H
E --> I["memory/registers step by step"]
F --> I
G --> J["solve paths automatically"]
What to observe and with what
Section titled “What to observe and with what”- High-level behavior:
strace ./binary(syscalls:open,connect,execve,read/write),ltrace ./binary(library calls:strcmp,malloc,printf). - Files, network, processes:
lsof,inotifywait(FS changes),tcpdump/Wireshark (generated traffic). - Internal state step by step: GDB + pwndbg/GEF (see Debugging with GDB).
ltrace is gold in crackmes: if the program does strcmp(your_input, "correct_password"), it shows you the expected password directly.
The runtime encryption/obfuscation case
Section titled “The runtime encryption/obfuscation case”A lot of code (malware, protections) only reveals its real logic when run: encrypted strings decrypted in memory, code that unpacks itself. Static doesn’t see it; dynamic does:
# stop right after the decryption and dump the process memorygdb -q ./binary(gdb) b *decrypt+0x80(gdb) run(gdb) dump memory out.bin 0x404000 0x405000(gdb) shell strings out.bin # the now-decrypted stringsExploitation (lab): unpacking
Section titled “Exploitation (lab): unpacking”A packer compresses/encrypts the executable; the real code appears only at runtime, after the unpacking stub:
# standard UPX: trivialupx -d packed_binary -o unpacked_binary# custom packer: run to the OEP (Original Entry Point) and dump# 1) breakpoint after the stub's final jump (OEP)# 2) dump the process memory (now-unpacked binary)# 3) rebuild imports (importrec/Scylla on Windows) -> static analysis of the dumpThe principle: you run the stub until the real code is unpacked in memory, then capture it to analyze statically.
Instrumentation and advanced tracing
Section titled “Instrumentation and advanced tracing”- Frida — runtime hooking (also mobile): intercept functions, read/write arguments and return values live.
- Pin / DynamoRIO / Qiling — instruction-level instrumentation/emulation (full traces, execution in an emulated sandbox).
- angr — symbolic execution: explore paths automatically.
angr can solve many crackmes on its own: you tell it “I want to reach the address that prints ‘Correct’” and it computes the required input:
import angr, claripyproj = angr.Project('./crackme', auto_load_libs=False)simgr = proj.factory.simulation_manager(proj.factory.entry_state())simgr.explore(find=0x401337, avoid=0x401300) # find = "Correct", avoid = "Wrong"print(simgr.found[0].posix.dumps(0)) # the input that reaches "Correct"Safe environment (malware)
Section titled “Safe environment (malware)”Dynamic analysis runs the code, so with malware isolation is essential:
- Dedicated VM, isolated from the network (or with simulated networking) and with snapshots to revert.
- INetSim / FakeNet-NG to simulate the Internet and see what the malware tries to contact without exposing yourself.
- Never run malware on your real machine.
Mitigations / Blue Team (what malware does to avoid it)
Section titled “Mitigations / Blue Team (what malware does to avoid it)”Protected code tries to detect it’s being observed (debugger, VM, sandbox) and change behavior or abort — covered in Anti-debugging and Anti-analysis. The analyst bypasses it by patching detections, using stealthier VMs, or hooking. For the defender, the lesson is that automated sandboxing (EDR, detonation) must anticipate these evasions (sleeps, VM detection).
Checklist
Section titled “Checklist”-
strace/ltraceto see syscalls/calls (behavior) - Monitor files/network/processes
- GDB for internal state step by step (Debugging with GDB)
- Dump memory to see strings/code decrypted at runtime
- Unpack protected binaries (OEP + dump)
- Instrumentation (Frida) / emulation (Qiling) if needed
- Symbolic execution (angr) for crackmes
- Malware: isolated environment with simulated networking