Injecting Brains Into Blind SQL Injection
Jakub Pruzinec (Nanyang Technological University), Quynh Anh Nguyen (Capstone, Unicorn & Keystone Engine)
HITBSecConf2023 - Phuket · Day 1 · Track 1
Overview
This talk, "Injecting Brains Into Blind SQL Injection," delivered by Jakub Pruzinec (representing Nanyang Technological University, with supervisor Quynh Anh Nguyen from Capstone, Unicorn & Keystone Engine) at HITB Phuket, addresses a long-standing challenge in web application security: the inefficiency of Blind SQL injection (BSQLi) data exfiltration. While SQL injection remains a prevalent vulnerability, its blind variant, which relies on inferring data through boolean responses (e.g., HTTP 200 vs. 404), is notoriously slow due to its one-bit-per-request nature. Existing state-of-the-art tools primarily rely on generic optimizations like binary search, which fail to leverage the inherent structure and linguistic properties of much of the data stored in databases.

Key moments
- 0:00 Introduction to Blind SQL Injection problem
- 4:00 State-of-the-art tools and natural language limitations
- 6:00 Introducing Hakin: language models for optimization
- 18:20 Performance results: Hakin 6x faster for schemas
- 19:45 Performance results: Hakin up to 26x faster for content
- 22:40 Live Demo 1: Extracting database schema and content
- 25:50 Live Demo 2: Step-by-step context-aware extraction
- 31:20 Audience Q&A on benchmark performance
Injecting Brains Into Blind SQL Injection
Speakers: Jakub Pruzinec (Nanyang Technological University); Quynh Anh Nguyen (Capstone, Unicorn & Keystone Engine)
Conference: HITB Phuket
YouTube: https://www.youtube.com/watch?v=6tIUActqebU
Overview
This talk, "Injecting Brains Into Blind SQL Injection," delivered by Jakub Pruzinec (representing Nanyang Technological University, with supervisor Quynh Anh Nguyen from Capstone, Unicorn & Keystone Engine) at HITB Phuket, addresses a long-standing challenge in web application security: the inefficiency of Blind SQL injection (BSQLi) data exfiltration. While SQL injection remains a prevalent vulnerability, its blind variant, which relies on inferring data through boolean responses (e.g., HTTP 200 vs. 404), is notoriously slow due to its one-bit-per-request nature. Existing state-of-the-art tools primarily rely on generic optimizations like binary search, which fail to leverage the inherent structure and linguistic properties of much of the data stored in databases.
The core contribution of this research is Hakin, a novel framework designed to dramatically accelerate BSQLi by incorporating probabilistic language models and statistical analysis. Hakin recognizes that a significant portion of database content, including schema information (table and column names) and actual data, is often textual and follows natural language patterns. By applying context-aware predictions and adaptive strategies, Hakin achieves substantially faster data extraction rates compared to traditional methods. This work is highly significant as it demonstrates how advanced linguistic and statistical techniques can transform a slow, cumbersome attack vector into a much more efficient and practical threat, urging defenders to reconsider the perceived low risk of blind SQL injection.
Background
▶ Watch: Introduction to Blind SQL Injection problem (0:00)
SQL injection (SQLi) is a classic web security vulnerability that allows an attacker to interfere with the queries an application makes to its database. This is typically achieved by injecting malicious SQL code into user-supplied input fields, altering the intended logic of the database query. For instance, injecting ' OR 1=1 -- into a login form might bypass authentication by making the WHERE clause always true. When the application directly exposes query results, such as in a search interface or error messages, data exfiltration is relatively straightforward. Attackers can also establish out-of-band channels to directly send data from the database server to an attacker-controlled server.
However, many applications do not directly display database query results or detailed error messages, nor do they permit out-of-band communication. In such scenarios, attackers resort to Blind SQL injection. This technique involves sending carefully crafted SQL queries that return a boolean (true/false) result, which the application then translates into a discernible difference in its response, such as an HTTP 200 (success) or HTTP 404 (not found) status code, or a subtle change in page content. By asking a series of "yes or no" questions, an attacker can infer the content of the database one bit at a time. The fundamental limitation of BSQLi is its inherent slowness; each character of data requires multiple round trips to the server, generating a large volume of suspicious traffic and consuming significant time.
State-of-the-art BSQLi tools, such as SQLMap, BBQSQL, and JSQL Injection, attempt to mitigate this slowness through several optimizations. The most common is binary search, which, instead of exhaustively guessing each character (e.g., 'a', then 'b', then 'c'), narrows down a character's value by repeatedly splitting the search range in half. For example, "is the character in the first half of the ASCII range?" If yes, "is it in the first quarter?", and so on. Other optimizations include character set narrowing (e.g., only querying for digits if expecting a credit card number) and string guessing (attempting to guess common strings like 'users' or 'password' upfront). While these methods improve upon exhaustive search, they largely treat all characters and data as equally probable and lack context awareness, making them sub-optimal for extracting textual data that often exhibits linguistic patterns. The theoretical minimum for binary search to extract a character from a typical ASCII range is around seven requests, a benchmark that existing tools often exceed.
Key Findings
▶ Watch: Introducing Hakin: language models for optimization (6:00)
The central finding presented in this talk is that Blind SQL injection can be drastically optimized by leveraging the linguistic properties and statistical regularities of database content. The researchers introduce Hakin, a novel framework that moves beyond generic binary search to employ probabilistic language models and statistical analysis to make context-aware predictions about the data being extracted. This approach significantly reduces the number of requests required per character, thereby accelerating the entire exfiltration process.
Hakin's effectiveness stems from two distinct, yet complementary, strategies tailored for different types of database information:
- Database Schemas (Table and Column Names): For this static and often transferable data, Hakin utilizes pre-trained language models (specifically, 5-grams) derived from extensive public datasets of SQL-related code. This allows for highly accurate predictions of subsequent characters based on the already extracted context.
- Database Content (Row Data): For the highly diverse and application-specific content, Hakin employs an adaptive, online training approach. It dynamically trains and updates multiple language models (including unigram and 5-gram models) during the extraction process, alongside a fallback binary search. This allows Hakin to continuously learn the data's patterns and choose the most effective model for the current context, even incorporating opportunistic string guessing for frequently recurring values.
The performance evaluations demonstrate that Hakin achieves remarkable speedups, requiring roughly two requests per character for database schemas and general textual content, and even fewer than one request per character for columns with few distinct values. This represents a 6x to 26x improvement over state-of-the-art tools like SQLMap, BBQSQL, and JSQL Injection, effectively making blind SQL injection a much faster and more practical attack vector.
Technical Deep Dive
▶ Watch: Performance results: Hakin up to 26x faster for content (19:45)
Hakin's architecture is built upon the premise that database content, particularly textual data, is not random but follows predictable patterns. It harnesses probabilistic language models to predict the likelihood of the next character or string based on the context of previously extracted data.
For database schemas (table and column names), Hakin employs 5-gram language models. These models are pre-trained on a massive corpus of SQL-related data, specifically terabytes of Stack Exchange questions (Stack Overflow and Database Administrators) where SQL code snippets, table names, and column names were extracted. When Hakin needs to extract a character, it feeds the already known prefix (e.g., "hell" for "hello") to the language model, which then outputs a likelihood distribution for all possible next characters.
This distribution is then used to construct a Huffman tree. A Huffman tree is a binary tree where the path to more frequently occurring (or, in this case, more probable) characters is shorter. Instead of a standard binary search that divides the character range numerically, Hakin's search traverses the Huffman tree. It asks "yes/no" questions (e.g., "Is the character in the left subtree or the right subtree?") based on the tree's structure. Because the most probable characters are closer to the root, they can be identified with fewer requests. Once a character is extracted, the context is updated, and the process repeats. A clever optimization for schema extraction is treating the end-of-string as a special symbol with its own probability in the language model, allowing Hakin to detect string termination with minimal overhead, often at "almost no cost" compared to a separate numeric binary search for length. This translates into a specific SQL query pattern that includes a logical operator to check for the end-of-string symbol.
The approach for database content is significantly more complex due to its application-specific and diverse nature. Since content cannot be reliably pre-trained, Hakin employs online training. As characters and strings are extracted, they are fed back into the models, which continuously learn and adapt to the specific data patterns of the target database. Hakin manages several models simultaneously:
- Unigram model: Learns character frequencies without context. This is particularly useful for data with no discernible patterns, such as password hashes, where individual character probabilities are more relevant than sequential context.
- 5-gram model: A generic model for data with patterns, similar to the one used for schemas, but trained dynamically.
- Binary search: Serves as a fallback, especially when the other models have not yet gathered enough data to make accurate predictions.
To choose the best-performing model, Hakin maintains statistical information about each strategy's historical performance. After each character extraction, it calculates how many requests each model would have required to infer that character. This is done at no additional cost because the correct character is already known. This allows Hakin to dynamically select the most efficient strategy for the current data type and context.
Another crucial component for content extraction is opportunistic string guessing. The observation is that many strings (e.g., city names, product categories) recur multiple times within a database. Hakin keeps a record of all previously extracted strings and uses them to construct a Huffman tree, but this time at a string level rather than a character level. If a guess succeeds, the entire string is extracted with minimal requests, and the models are updated. A key challenge here is managing the trade-off between including more strings (increasing success probability) and increasing the tree size (increasing search cost). Hakin addresses this by:
- Selecting only strings with a high potential for success (details are referred to in the accompanying paper).
- Performing a cost-benefit analysis before attempting string guessing. This involves comparing the expected number of requests for character-by-character inference versus the expected cost of string guessing (which accounts for both success and failure probabilities, and the search cost of the string Huffman tree).
The combined effect of these sophisticated techniques — context-aware language models, Huffman trees, online learning, dynamic model selection, and intelligent string guessing — allows Hakin to adapt to diverse data types and achieve unprecedented speed in Blind SQL injection data exfiltration.
Demo / Proof of Concept
▶ Watch: Live Demo 1: Extracting database schema and content (22:40)
Jakub Pruzinec showcased Hakin's capabilities through two live demonstrations using a simple web application vulnerable to Blind SQL injection. The application featured a single endpoint that took a name parameter, inserted it unsanitized into an SQL query, and responded with either an HTTP 200 (success) or HTTP 404 (not found) based on the query result. This setup perfectly simulated a blind SQL injection scenario.
The first demo illustrated the basic usage and performance of the Hakin framework. The extraction code, from a user's perspective, involved implementing a requester object (to inject queries and infer boolean responses from HTTP status codes) and then utilizing Hakin's pre-implemented database management and extractor objects. The demo successfully extracted the database schema, revealing four tables and several columns. Subsequently, it proceeded to exfiltrate data from a randomly chosen column, users_address. While the full extraction was not shown due to time constraints, the rapid succession of requests and the gradual appearance of address data demonstrated Hakin's active operation and efficiency.
The second, more detailed demo, provided a step-by-step intuition into Hakin's internal workings. For this, the presenter set up hooks within the framework (a feature not typically needed by users) to pause after each character extraction and print debugging information, including the current Huffman tree. The target string for this granular demonstration was "addresses".
Initially, with no context, the language model produced a probabilistic distribution for the first character, leading to a Huffman tree where common starting letters had shorter paths. As the first character 'A' was extracted, the context was updated to "A". The language model then generated a new distribution for the next character, showing 'D' as highly probable. The demo visibly showed how the Huffman tree adapted, making the path to 'D' very short (requiring only one request). This process continued, with 'D', 'R', 'E', 'S', and 'S' being extracted, often requiring just one request due to the high confidence of the model's predictions based on context.
Crucially, when the context was "address", the model predicted both the end-of-string and the plural form "es" as probable next steps. This demonstrated Hakin's ability to prioritize likely outcomes and adapt its querying strategy, further minimizing requests. The demo effectively visualized how Hakin's context-aware predictions, combined with dynamically constructed Huffman trees, allowed it to "prioritize the most likely to succeed characters," significantly outperforming traditional binary search methods.
Defensive Implications
▶ Watch: Audience Q&A on benchmark performance (31:20)
The introduction of the Hakin framework and its demonstrated capabilities have significant defensive implications for web application security. Traditionally, Blind SQL injection has been considered a lower-priority threat compared to error-based or union-based SQLi due to its perceived slowness and high volume of requests, which theoretically makes it easier to detect. However, Hakin fundamentally changes this calculus.
Primary Prevention Remains Paramount: The most critical defense against SQL injection, regardless of its variant, remains robust input validation and the use of prepared statements or parameterized queries. These techniques ensure that user-supplied input is treated as data, not executable code, thereby preventing any form of SQL injection payload from altering the query logic. Web application firewalls (WAFs) can also provide an additional layer of defense by filtering malicious input patterns, though advanced SQLi techniques can sometimes bypass them.
Reassessing the Threat of Blind SQLi: Defenders must now re-evaluate the risk associated with blind SQL injection. Hakin proves that BSQLi can be up to 26 times faster than previously thought possible with state-of-the-art tools. This means that an attacker can exfiltrate sensitive data in a fraction of the time, making the attack much more practical and less resource-intensive for the adversary. The reduced time window for detection and response increases the potential impact of a successful blind SQL injection.
Enhanced Monitoring and Anomaly Detection: Security monitoring systems should be adapted to account for these advanced attack techniques. While high request volumes are still indicative of attacks, Hakin's efficiency means that successful exfiltration might occur with fewer requests than previously expected for blind techniques. Instead of solely focusing on sheer volume, defenders should look for:
- Specific patterns of boolean-based requests: Even if not overwhelmingly high in number, the structure of queries designed for single-bit inference might be detectable.
- Adaptive query sequences: Hakin's dynamic nature means query patterns will change as it learns, making static signature-based detection potentially less effective. Anomaly detection systems that can identify deviations from normal application query behavior, even subtle ones, become more crucial.
- Contextual analysis of HTTP responses: Monitoring for sequences of HTTP 200/404 (or similar boolean indicators) in rapid succession, especially when combined with unusual query parameters, could signal an ongoing blind SQLi attack.
Prioritizing Remediation: Vulnerability management programs should elevate the priority of fixing blind SQL injection vulnerabilities. The "low impact due to slowness" argument is no longer valid. Any application susceptible to SQLi must be patched promptly to prevent data breaches enabled by tools like Hakin.
In essence, Hakin's work serves as a stark reminder that attackers continuously innovate. Defenders must stay abreast of these advancements and proactively strengthen their defenses, moving beyond outdated assumptions about attack feasibility and speed.
Key Takeaways
- Blind SQL injection (BSQLi) is a slow but potent attack vector, traditionally hampered by its one-bit-per-request nature, but this limitation is now significantly mitigated.
- Hakin dramatically optimizes BSQLi by leveraging probabilistic language models and statistical analysis, making data exfiltration much faster and more practical for attackers.
- Context-aware predictions and Huffman trees are central to Hakin's efficiency, reducing the number of requests needed per character by prioritizing likely outcomes based on previously extracted data.
- Adaptive strategies are crucial for diverse data: Hakin employs pre-trained models for schema extraction and an online training approach with multiple models (unigram, 5-gram, binary search fallback) and opportunistic string guessing for application-specific content.
- Significant performance gains are demonstrated: Hakin achieves up to 6 times faster extraction for database schemas and up to 26 times faster for certain types of database content compared to state-of-the-art tools like SQLMap, consistently outperforming the theoretical minimum of binary search (7 requests per character).
- Defenders must re-evaluate the risk of BSQLi, prioritize robust input sanitization and prepared statements, and enhance monitoring for sophisticated, faster blind SQL injection attacks that no longer rely on prohibitively high request volumes.
About the Speaker(s)
Jakub Pruzinec is a researcher associated with Nanyang Technological University. He presented this work at HITB Phuket, stepping in for his supervisor. His research focuses on optimizing security attack techniques, specifically in the realm of Blind SQL injection, by applying advanced computational and linguistic methods.
Quynh Anh Nguyen is affiliated with Capstone, Unicorn & Keystone Engine, and is recognized as a frequent speaker at prominent security conferences like Hacking The Box. While not present for this particular talk due to other work duties, he supervised the research presented by Jakub Pruzinec, indicating his expertise and contribution to the field of security research and offensive techniques.
Reviews
Dr. Zero (Offensive Security Researcher) — STRONG ACCEPT
Solid applied research that takes a well-understood problem—blind SQLi is slow—and throws actual computer science at it. Language models + Huffman coding for character prediction is clever, the online learning for content extraction is the right call, and the 6-26x speedup claims are backed by reasonable methodology. Not paradigm-shifting, but genuinely useful work that advances the state of the art.
Heather Calloway (CISO) — SOLID
Clever academic work that makes blind SQLi faster by applying language models to character prediction. Interesting research, but the practical delta for most defenders is small—if you have SQLi, you already have a problem, and this makes a slow attack less slow rather than changing the threat model.