sqlmap

On this page 7

sqlmap is an open-source command-line tool that automates the detection and exploitation of SQL injection vulnerabilities in web applications. Written in Python and released under the GPLv2 license, it is one of the most widely used utilities in security testing, where penetration testers and bug bounty researchers use it to confirm whether a parameter is injectable and to demonstrate the real impact of the flaw.

The tool supports a broad range of database management systems, including MySQL, PostgreSQL, Microsoft SQL Server, Oracle and SQLite, and can move from a single vulnerable parameter to database enumeration, data extraction and, under the right conditions, operating system command execution.

How sqlmap detects SQL injection

sqlmap detects SQL injection by sending crafted payloads to each tested parameter and comparing the responses with a baseline. It looks for differences in page content, HTTP status codes, error messages or response time that reveal whether the database interpreted the injected input as SQL.

Testing starts with heuristic checks that inject characters such as quotes and parentheses to see whether database errors appear. The tool then iterates through payload templates organized by technique, boundary and database dialect, stopping when a payload produces a reliable, repeatable difference.

sqlmap recognizes six injection techniques, abbreviated by the letters B, E, U, S, T and Q in its technique option. The table below explains each one.

TechniqueDetection signalExtraction speed
Boolean-based blindTrue and false conditions change the pageSlow, one bit per request
Error-basedDatabase errors reveal query resultsFast
UNION query-basedInjected UNION adds rows to the outputVery fast
Stacked queriesAdditional statements run after a semicolonDepends on output channel
Time-based blindConditional delays such as SLEEP callsVery slow
Inline queriesSubquery results appear inside outputFast
SQL injection techniques supported by sqlmap

Once a technique works, sqlmap fingerprints the database precisely, identifying the product and often its version. This determines which system tables, functions and payloads it can use in later stages.

Key options and parameters

sqlmap is controlled entirely through command-line options, and choosing them well is the difference between a quick confirmation and hours of noisy traffic. The most important options define the target, the scope of testing and how aggressive the payloads may be.

OptionPurposeTypical value or use
-uTarget URL with parametersA single page with a query string
-rLoad a raw HTTP request from a fileRequest saved from an intercepting proxy
-pRestrict testing to named parametersOne known suspicious parameter
--levelBreadth of tests and injection points1 to 5; level 2 adds cookies, level 3 adds headers
--riskAggressiveness of payloads1 to 3; higher values may modify data
--techniqueLimit injection techniquesLetters such as BEU
--batchAccept default answers automaticallyUnattended runs
--tamperApply payload transformation scriptsEvasion of simple filters
Frequently used sqlmap options

The risk setting deserves special care. At risk 3, sqlmap adds OR-based payloads that can match every row in a table, which in an UPDATE or DELETE statement may alter or destroy production data. Most professional engagements keep risk at 1 unless the client explicitly approves more.

From detection to exploitation

After confirming an injection, sqlmap can escalate through several stages, each controlled by its own option. This lets a tester show business impact rather than reporting a theoretical flaw.

  • Enumeration lists databases, tables, columns, users and privileges with options such as --dbs, --tables and --columns.
  • Data extraction retrieves table contents with --dump, ideally limited to a few rows to prove access without collecting excessive personal data.
  • Password hash handling identifies hashes in dumped data and can run a dictionary attack against them.
  • File system access reads or writes files with --file-read and --file-write when database privileges allow it.
  • Operating system access opens a command shell with --os-shell on certain database configurations with high privileges.

Whether these later stages succeed depends on the database account privileges of the application. An application that connects as a database administrator turns a single injection into full server compromise, while a least-privilege account limits the damage to the data that account can read.

sqlmap compared with other testing tools

sqlmap is a specialized exploitation tool, not a general web vulnerability scanner. It assumes a tester already suspects a parameter and wants deep, reliable confirmation of SQL injection specifically.

ToolPrimary roleSQL injection depth
sqlmapAutomated SQL injection exploitationVery deep, many techniques and dialects
Burp SuiteIntercepting proxy and manual testingModerate in its scanner; deep with manual work
OWASP ZAPOpen-source proxy and DAST scannerBasic detection
NucleiTemplate-driven vulnerability scanningKnown patterns only
MetasploitExploitation framework for many flawsLimited SQL injection modules
sqlmap and related security testing tools

A common workflow combines them: testers capture a request in Burp Suite, save it to a file and pass it to sqlmap with the -r option. This preserves authentication cookies, custom headers and request bodies that would be tedious to reproduce on the command line.

Running sqlmap against a system without written authorization is illegal in most jurisdictions, and the tool itself prints a disclaimer to that effect. Even authorized use carries operational risk, because automated payloads generate heavy, recognizable traffic and can strain fragile applications.

MistakeConsequenceBetter practice
Raising risk without approvalModified or deleted production dataKeep risk 1 by default
Dumping entire tablesUnnecessary exposure of personal dataExtract a few proof rows
Testing every parameter at level 5Thousands of requests and outagesTarget suspected parameters with -p
Trusting tamper scripts blindlyFalse negatives behind real filtersVerify manually with a proxy
Ignoring session stateLogged-out testing and missed flawsUse a saved authenticated request
Common mistakes when using sqlmap

A negative sqlmap result does not prove the absence of SQL injection. Second-order injections, unusual encodings and complex multi-step workflows can evade automated detection, so experienced testers treat the tool as an accelerator for manual analysis.

The idea in brief

Many websites store their information in databases and ask those databases questions when you search or log in. If a website is careless, a visitor can sneak extra commands into those questions. This weakness is called SQL injection.

sqlmap is a tool that checks for that weakness automatically. It tries thousands of carefully built inputs, watches how the website reacts, and reports whether the database can be tricked. Security professionals use it, with permission, to find the problem before criminals do.

A practical scenario

A penetration tester is hired by an online retailer to assess its order tracking page. While browsing through Burp Suite, the tester notices that adding a single quote to the order_id parameter produces a generic server error. The tester saves the request and runs sqlmap with -r, -p order_id, level 1 and risk 1.

Within a few minutes, sqlmap reports a boolean-based blind and time-based blind injection against a PostgreSQL back end. Following the agreed rules of engagement, the tester enumerates table names and extracts only three rows from the customer table to prove that names and addresses are readable.

The report recommends parameterized queries and a least-privilege database account. After the developers fix the code, a retest with the same sqlmap command finds no injectable parameters, and a manual review confirms the fix.