Skip to main content
Be Bitwise

Attack Surface Mapping

Zero-Day Discovery Workflow · Zero-Day Research track

6 min read

In this module

Defining the Attack Surface

The attack surface of a programme is every point where untrusted input enters the system. Every byte an attacker can influence — and that the programme actually processes — is a potential exploitation vector. Attack surface mapping is the systematic process of cataloguing those entry points before you start hunting.

Skip this step and you're searching blind. Do it properly and you can focus effort on the code paths most likely to pay off.

Attack Surface

The attack surface is not about the total size of the codebase. A 10-million-line programme with a single, well-validated input channel has a smaller attack surface than a 1,000-line programme that accepts data from the network, the filesystem, environment variables, and shared memory. Attack surface is determined by input diversity, parsing complexity, and exposure to untrusted data.

Input Sources

Vulnerabilities cluster around code that parses, deserialises, or interprets external data. That's where the interesting terrain is. The major input source categories:

File Parsers

Any programme that reads structured files - images, documents, archives, configuration files, fonts, media files - contains file parsing code that must handle malformed or malicious input. File format parsers are historically one of the richest sources of vulnerabilities because:

  • File formats are often complex, with nested structures, variable-length fields, and multiple encoding schemes.
  • Parsers must handle every valid input and gracefully reject every invalid one - an enormous state space.
  • Many parsers are written in C/C++ for performance, without memory-safe abstractions.

Network Protocols

Any programme that accepts network connections processes untrusted data from remote sources. This includes:

  • HTTP servers and clients (header parsing, chunked encoding, content negotiation)
  • DNS resolvers (compressed domain names, record types)
  • TLS implementations (certificate parsing, handshake state machines)
  • Custom binary protocols (length-prefixed fields, type-length-value structures)

Inter-Process Communication (IPC)

Programmes that communicate with other processes on the same system accept input through IPC mechanisms:

  • Unix domain sockets
  • D-Bus messages (common on Linux desktop systems)
  • Shared memory
  • Pipes and FIFOs
  • Windows named pipes and COM/RPC interfaces
  • macOS XPC services and Mach ports

Hardware Interfaces

  • USB: Devices present descriptors and data to the host OS. Malicious USB devices can send crafted data to kernel drivers.
  • Bluetooth: Pairing, discovery, and data transfer protocols all process external input.
  • Wi-Fi: Management frames, probe responses, and association data are processed by drivers and firmware.

Other Input Channels

  • Command-line arguments and environment variables: Often overlooked, but programmes that use these as configuration inputs may be vulnerable to injection.
  • Clipboard data: Applications that paste and parse clipboard content process untrusted input.
  • Registry and configuration stores: On Windows, values read from the registry may have been modified by another programme or an attacker with local access.

Tools for Mapping the Attack Surface

Several standard tools help you enumerate how a programme interacts with external data:

Static Analysis Tools

bash
# List exported and imported symbols
$ nm -D /usr/bin/target_app | grep -i "read\|recv\|parse\|open\|fopen"
# Examine the import table and identify library calls
$ objdump -T /usr/bin/target_app | grep -i "recv\|read\|fgets\|scanf"
# On macOS, list dynamic library imports
$ otool -L /usr/bin/target_app

Searching for functions like read, recv, recvfrom, fread, fgets, scanf, getenv, and open in the symbol table tells you which system calls the programme uses to ingest external data.

Dynamic Tracing Tools

bash
# Trace system calls to see all file and network operations
$ strace -f -e trace=%file,%network,read,write ./target_app input.dat
# Trace library calls (higher-level than syscalls)
$ ltrace -e fopen+fread+fgets+malloc+recv ./target_app input.dat

strace shows every system call the programme makes, revealing which files it opens, which network connections it initiates, and what data it reads. ltrace traces calls to shared library functions, giving you a higher-level view of how the programme processes input. (Use the %file and %network classes rather than naming calls like open or recv: modern glibc actually calls openat, recvfrom and friends, so a hand-written list silently misses them.)

For a service that's already running, look at what it has open rather than what it does at start-up:

bash
$ ss -tulpn # listening TCP/UDP sockets and owning processes
$ ls -l /proc/<pid>/fd # every open file, socket and pipe
$ lsof -p <pid> # the same, with more detail
$ grep Cap /proc/<pid>/status # capability sets (decode with capsh --decode=...)

On Windows, Sysinternals Process Monitor plays the strace role for file, registry and network activity, Process Explorer shows handles, and pipelist (or PowerShell's Get-ChildItem \\.\pipe\) lists the named pipes a service exposes.

Specialised Reconnaissance

For network services, use tools like nmap to enumerate listening ports and service versions. For web applications, spider the application to enumerate endpoints, parameters, and accepted content types.

Prioritising Targets

Not all input channels are equally promising for vulnerability research. Prioritise based on:

Factors that raise priority:

  • Remote reachability. A flaw in a network-facing parser is exploitable by anyone on the internet. A flaw in a local file parser requires the attacker to deliver a malicious file — a different threat model.
  • Parsing complexity. Nested structures, variable-length fields, multiple encoding layers: more opportunity for the parser author to get it wrong.
  • Code age and language. Older C/C++ that predates modern memory-safe idioms is statistically denser in bugs.
  • Privilege level. Root or kernel code amplifies impact when something breaks.
  • Vulnerability history. Components with previous CVEs tend to have more. Bugs cluster.
The 80/20 Rule of Attack Surface

Most vulnerabilities cluster in a small fraction of the codebase - specifically, the code that handles external input. By systematically mapping input channels and focusing on the most exposed and complex parsers, you concentrate your research where it is most likely to yield results. A thorough attack surface map before you start fuzzing or auditing code is the most important efficiency gain in the entire workflow.

The output is a prioritised list of input channels, the code paths that handle them, and the functions where external data first enters the programme. That map is your foundation for everything that follows.

Here's a small map for a real target, sudo. It's setuid root, so every input a local user controls crosses a privilege boundary, which is why it's local-only and still worth the effort. The command-line branch isn't hypothetical: Baron Samedit (CVE-2021-3156) was a heap overflow in how sudo unescaped backslashes in its arguments, and it sat there for about ten years.