Abstract
Injection attacks have been a major threat to web applications. Despite the significant effort in thwarting injection attacks, protection against injection attacks remains challenging due to the sophisticated attacks that exploit the existing protection techniques' design and implementation flaws. In this paper, we develop Spinner, a system that provides general protection against input injection attacks, including OS/shell command, SQL, and XXE injection. Instead of focusing on detecting malicious inputs, Spinner constantly randomizes underlying subsystems so that injected inputs (e.g., commands or SQL queries) that are not properly randomized will not be executed, hence prevented. We revisit the design and implementation choices of previous randomization-based techniques and develop a more robust and practical protection against various sophisticated input injection attacks. To handle complex real-world applications, we develop a bidirectional analysis that combines forward and backward static analysis techniques to identify intended commands or SQL queries to ensure the correct execution of the randomized target program. We implement Spinner for the shell command processor and two different database engines (MySQL and SQLite) and in diverse programming languages including C/C++, PHP, JavaScript and Lua. Our evaluation results on 42 real-world applications including 27 vulnerable ones show that it effectively prevents a variety of input injection attacks with low runtime overhead (around 5%).
Introduction
Injection attacks remain the top threat to web applications, where attackers insert malicious code into program inputs to be executed by backend subsystems like shells or databases. Traditional defenses, such as input sanitization, are notoriously difficult to implement correctly because the "grammar" of commands is incredibly complex; a single missed edge case can lead to total system compromise.
Previous researchers proposed Instruction Set Randomization (ISR), which changes keywords (e.g., changing SELECT to SELECT_SECRET_KEY). However, these older methods faced significant hurdles: parser fragility, where complex SQL dialects would crash the defense; static keys that, once leaked, rendered the defense useless; and scalability issues in identifying intended commands within complex, dynamically generated strings. Spinner addresses these challenges by providing a robust, automated, and dynamic perturbation system for command subsystems.
System Design and Methodology
Spinner operates through a two-phase process: an offline instrumentation phase and a dynamic runtime phase.
Instrumentation Phase: Bidirectional Analysis
A core challenge in automated randomization is distinguishing between developer-intended command components and user-provided data. Spinner introduces a novel Bidirectional Command Composition Analysis to solve this.
- Forward Analysis: Traces data flow from trusted sources, such as hard-coded strings and local configuration files.
- Backward Analysis: Traces arguments from "sinks" (e.g.,
system(),mysql_query(),popen()) back to their origins. By "meeting in the middle," Spinner accurately identifies intended command structures even in complex real-world codebases like WordPress, avoiding the "over-tainting" issues that often plague standard security tools.
Runtime Phase: Dynamic Perturbation
At runtime, Spinner hooks into the underlying subsystems to enforce the randomization scheme.
- Shell Randomization: Spinner randomizes internal command names and provides a "randomized view" of the filesystem for external binaries. For example,
/bin/wgetmight be mapped to a randomized path like.lye.qjpc. - Database Randomization: Spinner utilizes a scanner-based, grammar-agnostic approach. This allows it to handle idiosyncratic SQL dialects that typically break traditional proxy-based parsers.
- Moving Target Defense: Crucially, Spinner can change the randomization mapping for every single command execution. By treating randomization keys like one-time pads, Spinner effectively eliminates the threat of memory disclosure attacks.
Evaluation and Results
The authors evaluated Spinner across 42 real-world applications, including 27 known vulnerable applications and 15 popular, complex apps from NPM, Packagist, and WordPress. They utilized automated attack tools such as commix, sqlmap, and xcat to launch 223 distinct injection attacks (102 command, 97 SQL, and 24 XXE).
The results demonstrate Spinner's effectiveness and practicality:
- 100% Prevention: Spinner successfully blocked all 223 automated attacks and 27 manual Proof-of-Concept exploits.
- Low Performance Impact: The average runtime overhead is approximately 5%, making it suitable for production environments.
- Robustness: Spinner outperformed state-of-the-art tools like Diglossia and SQLRand, which failed when encountering complex SQL dialects or parser errors.
- Scalability: The system successfully instrumented WordPress, identifying and protecting 462 distinct command/query sinks.
Conclusion
Spinner represents a significant advancement in protecting web applications from injection attacks. By shifting the defense from input detection to dynamic subsystem perturbation and employing a robust bidirectional analysis for instrumentation, it overcomes the limitations of previous ISR techniques. While it requires source code for analysis and relies on LD_PRELOAD for deployment, its grammar-agnostic nature and per-execution randomization provide a powerful "Moving Target Defense" against sophisticated modern threats.
Summary updated