在学sqlmap
的时候发现,写文件不用into outfile
用的却是into dumpfile
于是去查了一波。
the SELECT ... INTO form of SELECT enables a query result to be stored in variables or written to a file:
SELECT ... INTO var_list selects column values and stores them into variables.
SELECT ... INTO OUTFILE writes the selected rows to a file. Column and line terminators can be specified to produce a specific output format.
SELECT ... INTO DUMPFILE writes a single row to a file without any formatting.
原来select into
有三种用法,还可以写入到变量中。。。
outfile
可以写入多行数据,并且字段和行终止符都可以作为格式输出。dumpfile
只能写一行,并且输出中不存在任何格式。
注意,用这些函数先需要查看权限是否足够。
mysql> show variables like '%secure%';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| secure_auth | OFF |
| secure_file_priv | |
+------------------+-------+
2 rows in set (0.00 sec)
这个secure_file_priv
应该为空,不然在读写文件时就会受到限制,甚至为NULL
时无法读写,改的话很容易,在mysql
的配置文件中加入一行secure_file_priv=
然后重启mysql
服务即可。
先来测试outfile
。
mysql> select * from test into outfile "c:/outfile.txt";
Query OK, 2 rows affected (0.00 sec)
再来测试dumpfile
。
mysql> select * from test into dumpfile "c:/dumpfile.txt";
Query OK, 2 rows affected (0.00 sec)
效果对比还是很明显的。
所以一般情况下,比如脱裤时,那就用outfile
更好使,但是如果用outfife
去导出二进制文件时,就会出错,因为outfile
函数会在行末端写入新行,更致命的是会转义换行符,这样的话这个二进制可执行文件就会被破坏,所以一般导出导出二进制文件(udf提权
)时就用dumpfile
。