Web Application Hacking · Topic 8 of 8

SQL Injection Tools, Evasion and Countermeasures

SQL injection tools such as sqlmap, how attackers try to evade filters and WAFs, and the countermeasures that actually stop SQL injection, in exam terms.

  • 5 min
  • Includes a diagram
In a nutshell
  • sqlmap is the main tool. Burp and ZAP help find injection points.
  • Evasion: case variation, comments, encoding, concatenation, null bytes, parameter pollution.
  • Blacklists and WAF rules are bypassable. Treat them as extra layers only.

What it is

SQL injection tools automate finding and using injection flaws. Evasion techniques try to slip input past filters, intrusion detection or a web application firewall (WAF). Countermeasures remove the flaw itself rather than trying to spot every bad input.

The key idea for the exam is that blacklists and filters can be evaded, while parameterized queries and least privilege cannot be argued with.

Injection flawTool automates detectionFilter or WAF tries to blockEvasion changes the form of inputFix at the rootparameterized queries

How it works

Tools

ToolWhat it does
sqlmapOpen source tool that automates detection and use of SQL injection, supports many databases and techniques
HavijOlder automated GUI tool, now historic
jSQL InjectionJava based tool for testing SQL injection
SQLNinjaFocuses on Microsoft SQL Server
MoleAutomated tool that detects and extracts through injection
Burp Suite and OWASP ZAPProxies with scanners that find injection points
Acunetix and similar scannersCommercial web vulnerability scanners

sqlmap is the one to know. It can detect which parameters are injectable, identify the database, list databases, tables and columns, and retrieve data. Its technique setting covers boolean based blind, error based, union query, stacked queries, time based blind and inline queries. It has "tamper" scripts that change how the payload is written, which relates to evasion. It must be used only against systems you are authorized to test.

Evasion techniques

Filters that look for known bad words or characters can be bypassed by changing the form of the input while keeping the same meaning to the database. The exam names the ideas.

TechniqueIdea
Case variationMixing upper and lower case so a case sensitive filter misses a keyword
Inline comments and whitespace changesUsing comments or alternative space characters inside the statement
URL, hex and Unicode encodingRepresenting characters in another encoding that the application decodes later
String concatenation and building valuesAssembling words from parts so no blocked word appears whole
Character functionsUsing database functions that build text from character codes
Null bytesInserting a null byte to cut off a filter's view of the string
Obfuscated or encoded codeHiding the query in a form the filter does not recognize
Parameter pollutionSending the same parameter more than once so filter and application read different values
Splitting across inputsSpreading the statement over several fields that are joined later
Slow or low volume testingStaying below detection thresholds

The lesson is that blacklisting is weak. A filter would have to anticipate every encoding, and an attacker needs only one that works.

Countermeasures

Layered SQL injection defense: allow list input validation, parameterized queries that send input as data and never as SQL code, a least privilege database account, and generic error pages.

ControlWhy it helps
Parameterized queries (prepared statements)Keep data separate from SQL, which removes the root cause
Stored procedures, used safelyReduce risk only when they themselves do not build SQL from strings
Input validation with an allow listAccept only the expected type, length and format
Escaping, as a fallbackHelps in some legacy code but is easy to get wrong
Least privilege database accountsThe application account cannot drop tables or read unrelated data
Disable dangerous featuresTurn off unneeded database functions such as command execution
Generic error messagesHide database details from users
Web application firewallBlocks known patterns as an extra layer
Object relational mapping (ORM) used correctlyParameterizes by default
Testing and code reviewSAST, DAST and scheduled penetration tests
MonitoringAlert on database errors and unusual query patterns
PatchingKeep the database and drivers current

Detection of attacks includes web server and WAF logs showing odd characters in parameters, repeated database errors, and long delays on certain requests. An intrusion detection system can add signatures but is not a cure.

A worked example

A security team adds a WAF rule that blocks a list of dangerous keywords, and the number of alerts falls. A tester then shows the same flaw is exploitable by using a different encoding of the input. The lasting fix is to change the code to use parameterized queries, and to reduce the database account to read access on the one table it needs.

How the exam asks about this

  • "Which tool automates detection and exploitation of SQL injection across many databases?" -> sqlmap.
  • "Mixing upper and lower case letters in keywords to bypass a filter is which evasion technique?" -> Case variation.
  • "Which single measure best removes the root cause of SQL injection?" -> Parameterized queries (prepared statements).

What to remember for the exam

  • sqlmap is the main tool. Burp and ZAP help find injection points.
  • Evasion: case variation, comments, encoding, concatenation, null bytes, parameter pollution.
  • Blacklists and WAF rules are bypassable. Treat them as extra layers only.
  • Best fix: parameterized queries, allow list validation and least privilege.
  • Hide database errors and monitor for patterns.
Watch out

A WAF alone is not the right answer to "best way to prevent SQL injection". Choose parameterized queries.

Common mistakes

Trusting a keyword blacklist. Encoding and case changes defeat it.

Assuming stored procedures are always safe. They are safe only when they use parameters internally.

Running the application as database administrator. One flaw then gives full control.

Check yourself

  • Why is a blacklist weak against SQL injection?

    Attackers can change case, encoding or structure, so a filter must anticipate every form while they need only one that passes.

  • Which sqlmap capability relates to evasion?

    Tamper scripts that change how the injected input is written.

  • Which database account setting limits damage from a successful injection?

    Least privilege, giving the application account only the rights it needs.

Topic 8 of 8 in Web Application Hacking

Test yourself on Web Application Hacking

The full EC-Council 312-50 question bank has 1,000 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by EC-Council. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.