Automatic SQL Injection and DB Takeover Tool – SQLmap
Introduction
SQLMap is an open source penetration testing tool that automates the process of detecting and exploiting SQL injection flaws and taking over of database servers. It comes with a powerful detection engine and many features for penetration testers.
SQLMap is capable of databases fingerprinting, fetching data from the databases, accessing the database file systems, running different commands on the target server, etc.
SQLmap: Automatic SQL Injection Tool
This very powerful exploitation tool is developed in Python an it’s FREE to use. It requires Python version 2.6.x or 2.7.x. and comes preinstalled on Kali Linux, but can be run on any platform.
Features
SQLmap have many features divided into 3 groups:
- GENERIC FEATURES
- FINGERPRINT AND ENUMERATION FEATURES
- TAKEOVER FEATURES
We’ll list some of them here:
- Full support for:MySQL, Oracle, PostgreSQL, Microsoft SQL Server, Microsoft Access, IBM DB2, SQLite, Firebird, Sybase and SAP MaxDB database management systems.
- Full support for six SQL injection techniques: boolean-based blind, time-based blind, error-based, UNION query, stacked queries and out-of-band.
- Support to directly connect to the database without passing via a SQL injection, by providing DBMS credentials, IP address, port and database name.
- Support to enumerate users, password hashes, privileges, roles, databases, tables and columns.
- Automatic recognition of password hash formats and support for cracking them using a dictionary-based attack.
- Support to dump database tables entirely, a range of entries or specific columns as per user’s choice. The user can also choose to dump only a range of characters from each column’s entry.
- Support to search for specific database names, specific tables across all databases or specific columns across all databases’ tables. This is useful, for instance, to identify tables containing custom application credentials where relevant columns’ names contain string like name and pass.
- Capable to download and upload any file from the database server underlying file system when the database software is MySQL, PostgreSQL or Microsoft SQL Server.
- Support to execute arbitrary commands and retrieve their standard output on the database server underlying operating system when the database software is MySQL, PostgreSQL or Microsoft SQL Server.
- Ability to establish an out-of-band stateful TCP connection between the attacker machine and the database server underlying operating system. This channel can be an interactive command prompt, a Meterpreter session or a graphical user interface (VNC) session as per user’s choice.
- Support for database process’ user privilege escalation via Metasploit’s Meterpreter getsystem command.
Techniques
SQLmap can detect and exploit different SQL injections:
Boolean-based blind:
sqlmap replaces or appends to the affected parameter in the HTTP request, a syntatically valid SQL statement string containing aSELECT
sub-statement, or any other SQL statement whose the user want to retrieve the output.Time-based blind:
replaces or appends to the affected parameter in the HTTP request, a syntatically valid SQL statement string containing a query which put on hold the back-end DBMS to return for a certain number of seconds.Error-based:
replaces or appends to the affected parameter a database-specific error message provoking statement and parses the HTTP response headers and body in search of DBMS error messages containing the injected pre-defined chain of characters and the subquery statement output within.UNION query-based:
sqlmap appends to the affected parameter a syntactically valid SQL statement starting with anUNION ALL SELECT
.Stacked queries
, also known aspiggy backing:
sqlmap tests if the web application supports stacked queries and then, in case it does support, it appends to the affected parameter in the HTTP request, a semi-colon (;
) followed by the SQL statement to be executed.
Given that these are just basic explanations of techniques, you can read a more detailed explanation on the official SQLmap wiki page.
Dependencies
Required:
- Python version 2.6.x or 2.7.x.
If you want to connect directly to a database server, you need to install the following Python bindings:
- DB2: python ibm-db
- Firebird: python-kinterbasdb
- Microsoft Access: python-pyodbc
- Microsoft SQL Server: python-pymssql
- MySQL: python pymysql
- Oracle: python cx_Oracle
- PostgreSQL: python-psycopg2
- SQLite: python-pysqlite2
- Sybase: python-pymssql
Optionally:
- NTLM: python-ntlm (for web application attack behind NTLM authentication)
- Readline: PyReadline (Windows users)
SQLmap Install
Clone it form the Git repository:
git clone https://github.com/sqlmapproject/sqlmap.git sqlmap-dev
You can also download the latest .tar.gz or .zip.
To update sqlmap run:
python sqlmap.py --update
Usage
Type -h
for basic options list:
python sqlmap.py -h
or -hh
to get a full list of options and switches:
python sqlmap.py -hh
To see all of the sqlmap capabilities, list of supported features, all options, switches and examples click the DOCUMENTATION link bellow.