Automated Vulnerability Discovery
Emulation & Symbolic Execution · VR Analysis & Discovery track
6 min read
In this module
Finding Bugs Automatically
The techniques from previous lessons — emulation, symbolic execution, and concolic execution — aren't academic exercises. They underpin automated vulnerability discovery: getting computers to find security-relevant bugs before a human reviewer ever looks at the code. This lesson connects those techniques to practical workflows.
Using Symbolic Execution to Find Bugs
Symbolic execution can automatically discover inputs that trigger specific types of vulnerabilities. The key insight is that many vulnerability conditions can be expressed as constraints on program state:
- Buffer overflow: a write operation's destination address exceeds the allocated buffer bounds. Symbolically:
write_addr > buffer_base + buffer_size. - Null pointer dereference: a pointer used in a memory operation has the value zero. Symbolically:
ptr == 0. - Integer overflow: an arithmetic operation produces a value outside the representable range. Symbolically:
a + b > INT_MAXwhen the program treats the result as positive. - Division by zero: the divisor in a division operation is zero. Symbolically:
divisor == 0.
angr can check for these conditions at each instruction and report when a path satisfies them. The sketch below is pseudocode rather than a working script: overflow_condition stands in for a constraint you'd build yourself, typically from a breakpoint on memory writes that compares the symbolic write address with the buffer's bounds.
# Pseudocode sketch: overflow_condition is a placeholderimport angr
proj = angr.Project("./vuln_program", auto_load_libs=False)state = proj.factory.entry_state()simgr = proj.factory.simulation_manager(state)
# Explore with a step function that checks for overflowswhile simgr.active: simgr.step() for s in simgr.active: # Check if any memory write goes out of bounds # (real analysis builds this from mem_write breakpoints) if s.solver.satisfiable(extra_constraints=[overflow_condition]): print(f"Potential overflow at {s.addr:#x}") exploit_input = s.posix.dumps(0)A common use case is generating inputs that reach a specific function or code path. For example, if a vulnerability is in a deeply nested parsing function, you can use angr to find inputs that navigate through all the parsing layers to reach the vulnerable code. Set the target address to the vulnerable function's entry point and let angr find a path through the input validation, protocol parsing, and data processing layers.
Combining Fuzzing and Symbolic Execution
Pure fuzzing (random or mutation-based input generation) is fast but can get stuck at complex input validation checks. Pure symbolic execution is thorough but slow. The combination is more powerful than either alone.
Driller pioneered this hybrid approach: AFL fuzzes the target, generating inputs quickly. When AFL's coverage plateaus (no new code paths discovered after many iterations), Driller takes AFL's best inputs, runs concolic execution starting from the point where fuzzing got stuck, solves the branch constraints that AFL could not randomly satisfy, and feeds the new inputs back to AFL.
Most of the time the loop at the top just spins: the fuzzer keeps finding new paths on its own and the slow half never runs.
The split makes sense: most branches are easy to cover through random mutation (the fuzzer is fast at that), while a handful of branches need specific input values that mutation will never randomly produce. The symbolic executor handles those. Each tool covers the other's weakness.
Generating Inputs That Reach Specific Code Paths
Sometimes you know where a vulnerability is (from a code audit, a CVE description, or a crash report) but need to generate an input that actually reaches it. This is a directed analysis problem.
With angr, you set the vulnerable address as the find target and any error-handling or exit paths as avoid targets. angr's exploration strategies (DFS, BFS, or directed search) guide the symbolic executor towards the target.
For complex programs, this may require:
- Starting from a state close to the target: instead of starting from
main(), take a snapshot (using a debugger) at a point close to the vulnerable function and start symbolic execution from there. - Modelling the environment: the vulnerable function may depend on specific file contents, network data, or global state. You model these as symbolic variables with appropriate constraints.
- Constraining the input format: if the input must be valid JSON, a valid image file, or a specific protocol message, add constraints that ensure the symbolic input satisfies the format requirements. This dramatically prunes the search space.
Limitations and When to Use What
No single technique finds all bugs. Understanding each tool's strengths and weaknesses helps you choose the right approach:
Fuzzing (AFL, libFuzzer) is best for: finding shallow bugs, testing input parsing, and programs with fast execution. It scales to large programs and can find bugs that symbolic execution misses due to path explosion. But it struggles with complex input validation (magic bytes, checksums, encryption).
Symbolic execution (angr, KLEE) is best for: reaching specific code paths, solving complex constraints, and proving the absence of certain bug classes. But it does not scale to large programs due to path explosion and solver timeouts.
Concolic execution (Triton, QSYM) is best for: overcoming specific obstacles that block fuzzing, generating targeted inputs, and analysing individual functions. It combines the scalability of concrete execution with the precision of symbolic reasoning.
CPU emulation (Unicorn, Qiling) is best for: analysing firmware, shellcode, and obfuscated code in a controlled environment. It is not a bug-finding technique itself but provides the execution environment that other techniques operate within.
The state of the art is combining these techniques: use fuzzing as the primary driver (it is fast and finds easy bugs), add symbolic execution to overcome hard-to-fuzz barriers, and use emulation to handle exotic architectures and environments. Tools like Fuzzware (for firmware), Eclipser, and SymCC implement various combinations of these approaches.
Automated vulnerability discovery moves fast. No tool finds everything — but combining these techniques meaningfully raises the odds of catching a bug before an attacker does.