How sqlmapproject/sqlmap works
Purpose and entry points
sqlmap is a Python penetration-testing CLI that detects and exploits injection flaws, fingerprints database servers, extracts data, and supports DB/file-system/OS takeover workflows. The primary launcher is sqlmap.py; a separate API service entry point is sqlmapapi.py, with API configuration in sqlmapapi.yaml.
Startup, configuration, and shared state
Command-line/config parsing initializes global options, knowledge/state, logging, targets, sessions, and defaults before execution. Core cross-cutting contracts are concentrated in lib/core/option.py, lib/core/data.py, and lib/core/session.py; command-line and config-file adapters are lib/parse/cmdline.py and lib/parse/configfile.py. This shared state is the boundary between setup and all later request/detection/action stages.
Controller orchestration
The controller selects targets and coordinates injection checking, exploitation, result handling, and requested actions. lib/controller/controller.py is the top-level execution coordinator, while lib/controller/checks.py drives detection checks and lib/controller/action.py dispatches post-detection operations. It consumes normalized target/options state and delegates transport, technique engines, and DBMS plugins.
Target ingestion and HTTP transport
Targets may originate from direct URLs and parsed artifacts/API descriptions, then flow through request construction and response comparison. Relevant boundaries include lib/core/target.py, lib/parse/openapi.py, and lib/parse/sitemap.py. The request layer supports HTTP(S), HTTP/2, WebSocket, proxy/auth variants, direct database connections, and out-of-band channels through lib/request/connect.py, lib/request/inject.py, and lib/request/websocket.py.
Detection and extraction engines
Injection execution is organized by technique families: boolean/time inference, error-based extraction, UNION queries, DNS exfiltration, plus non-SQL injection families. Core examples are lib/techniques/blind/inference.py, lib/techniques/error/use.py, and lib/techniques/union/use.py; payload definitions are data-driven in data/xml/payloads/boolean_blind.xml and data/xml/payloads/union_query.xml. Request comparison feeds these engines to distinguish baseline versus injected behavior.
DBMS plugin boundary
Generic enumeration and operations are specialized through a uniform per-DBMS plugin layout: connector, fingerprint, syntax, enumeration, filesystem, and takeover. Generic fallbacks reside in plugins/generic/enumeration.py and plugins/generic/fingerprint.py; representative implementations are plugins/dbms/mysql/connector.py, plugins/dbms/postgresql/enumeration.py, and plugins/dbms/mssqlserver/takeover.py. This boundary isolates vendor SQL dialects and capabilities for numerous database platforms.
Takeover, payload assets, and evasion
After successful access, takeover adapters perform DB-native command execution, UDF deployment, registry/web operations, and shell integration via lib/takeover/xp_cmdshell.py, lib/takeover/udf.py, and lib/takeover/web.py. Supporting SQL procedures and native binaries are packaged under data/procs/mssqlserver/, data/udf/mysql/, and data/shell/. Payload transformation is a pluggable evasion stage using scripts in tamper/, such as tamper/space2comment.py.
Runtime and external dependencies
The project supports Python 2.7 and Python 3.x across platforms. It embeds compatibility/vendor libraries under thirdparty/, including Bottle for the API service (thirdparty/bottle/bottle.py) and SOCKS support (thirdparty/socks/socks.py). Runtime interactions are external target web services, supported DBMS servers, DNS/out-of-band services (lib/request/dns.py, lib/request/interactsh.py), and optionally Metasploit (lib/takeover/metasploit.py).
Components 21
Entry & Setup
- sqlmap CLI
sqlmap.py - API service · Programmatic service interface.
sqlmapapi.py - Bottle runtime
thirdparty/bottle/bottle.py - CLI & config parsing
lib/parse/cmdline.py - Options, knowledge & sessions · Normalized runtime state used by all execution stages.
lib/core/option.py
Execution Pipeline
- Target ingestion
lib/core/target.py - OpenAPI & sitemap inputs
lib/parse/openapi.py - Execution controller
lib/controller/controller.py - Injection checks
lib/controller/checks.py - Request transport · Builds and sends target requests across supported channels.
lib/request/connect.py - Injection & comparison
lib/request/inject.py
Techniques & Plugins
- Injection engines
lib/techniques/blind/inference.py - Technique payloads
data/xml/payloads/boolean_blind.xml - DBMS plugin layer · Connectors, fingerprints, syntax, enumeration, filesystem, and takeover per DBMS.
plugins/generic/enumeration.py
Takeover & Assets
- Post-detection actions
lib/controller/action.py - Takeover adapters
lib/takeover/xp_cmdshell.py - Takeover assets
- Tamper scripts
tamper/space2comment.py
Other components
- Target services & DBMSs · Web targets and directly connected database servers.
- DNS/OOB services
- Metasploit
Connections 21
- sqlmap CLI → CLI & config parsing: initializes
- API service → Bottle runtime: uses
- CLI & config parsing → Options, knowledge & sessions: normalizes into
- Options, knowledge & sessions → Target ingestion: configures
- OpenAPI & sitemap inputs → Target ingestion: supplies targets
- Options, knowledge & sessions → Execution controller: drives
- Target ingestion → Execution controller: selects
- Execution controller → Injection checks: runs
- Injection checks → Injection & comparison: tests injections
- Injection & comparison → Request transport: sends requests via
- Request transport → Target services & DBMSs: connects to
- Injection & comparison → Injection engines: feeds response signals
- Technique payloads → Injection engines: defines payloads
- Tamper scripts → Injection & comparison: transforms payloads
- Injection engines → DBMS plugin layer: uses vendor behavior
- Injection checks → Post-detection actions: on successful access
- Post-detection actions → DBMS plugin layer: enumerates through
- Post-detection actions → Takeover adapters: dispatches takeover
- Takeover adapters → Takeover assets: deploys
- Takeover adapters → Metasploit: optionally integrates
- Request transport → DNS/OOB services: uses DNS/OOB channels