Abstract
In this paper, we propose a new approach to infer state machine models from protocol implementations. Our method, STATEINSPECTOR, learns protocol states by using novel program analyses to combine observations of run-time memory and I/O. It requires no access to source code and only lightweight execution monitoring of the implementation under test. We demonstrate and evaluate STATEINSPECTOR's effectiveness on numerous TLS and WPA/2 implementations. In the process, we show STATEINSPECTOR enables deeper state discovery, increased learning efficiency, and more insightful post-mortem analyses than existing approaches. Further to improved learning, our method led us to discover several concerning deviations from the standards and a high impact vulnerability in a prominent Wi-Fi implementation.
Introduction
Security protocols like TLS (Transport Layer Security) and WPA2 are fundamental to modern digital communication. These protocols are essentially complex state machines, transitioning between phases like "unauthenticated," "handshaking," and "encrypted" based on specific message exchanges. If an implementation contains a logic flaw—such as allowing a user to bypass a mandatory handshake state—it can create catastrophic security vulnerabilities.
To identify these flaws, researchers use Automata Learning to automatically map out an implementation's state machine. However, traditional "black-box" methods suffer from a significant blind spot: they only observe external input/output (I/O). If a state change occurs internally without producing a unique external output, a black-box learner will miss it. Furthermore, discovering "deep" states—logic paths that require a long, specific sequence of messages—is computationally expensive for black-box tools, often requiring millions of queries over several days.
The STATEINSPECTOR Framework
To address these challenges, we introduce a grey-box approach. STATEINSPECTOR monitors a program's internal memory and registers in real-time during execution. Crucially, it does not require access to the original source code, making it applicable to proprietary or closed-source software.
The system operates in two primary stages:
- State Discovery: The tool executes "bootstrap" queries and takes memory snapshots. It employs a technique called allocation alignment to track memory usage even when addresses shift between runs. It then identifies "candidate state memory"—specific bytes that change predictably as the protocol progresses.
- Model Learning: Using an active learning algorithm (such as the TTT algorithm), STATEINSPECTOR builds the full state machine. By using internal memory values as a "state classifier," the tool can immediately recognize when it has reached a new state, bypassing the need for the thousands of "equivalence queries" required by black-box methods.
To avoid being misled by irrelevant data (like simple packet counters), the tool uses taint propagation and symbolic execution to verify if a memory change actually influences future control flow decisions. Only memory that impacts the program's logic is considered "state-defining."
Efficiency and Deep State Discovery
A core advantage of the grey-box approach is its ability to uncover states hidden deep within protocol logic. In black-box learning, complexity grows polynomially with the depth of the state. By using memory as a shortcut, STATEINSPECTOR transforms a blind search into a guided exploration.
Consider a state machine with a "backdoor" (State 2) reachable only after 11 consecutive init messages. While a black-box tool would require approximately 360,000 queries to identify this path, STATEINSPECTOR can discover it in just 149 queries. This capability is vital for finding intentional backdoors or obscure implementation bugs that standard testing might overlook.
Experimental Results
We evaluated STATEINSPECTOR on several high-profile targets, including OpenSSL, GnuTLS, and the closed-source RSA-BSAFE-C TLS implementation, as well as Wi-Fi stacks like iNet Wireless Daemon (IWD) and hostapd.
- Vulnerability Discovery: The tool identified a high-impact key reinstallation vulnerability in the IWD Wi-Fi stack (CVE-2020-12312), which could allow an attacker to decrypt and forge data frames.
- Massive Efficiency Gains: For the RSA-BSAFE-C implementation, black-box methods failed to produce a model after three days of continuous testing. STATEINSPECTOR completed the same task in just six minutes.
- Uncovering "Ghost" States: In OpenSSL, the tool revealed that certain configurations accepted invalid certificates due to misleading documentation, leading to insecure state machine configurations that were previously undetected.
Limitations and Future Work
While STATEINSPECTOR represents a significant advancement, some challenges remain. The current version disables protocol retransmissions to simplify analysis, and it can occasionally be confused by infinite counters (e.g., global message increments). Furthermore, the tool requires the ability to attach a debugger-like monitor, which may be difficult on some restricted embedded hardware.
Future research will focus on automatically mapping discovered memory locations back to specific source code lines, providing developers with a direct path to fixing the vulnerabilities STATEINSPECTOR uncovers.
Summary updated