首页 > 其他分享 >DVWA-File inclusion(文件包含漏洞)

DVWA-File inclusion(文件包含漏洞)

时间:2024-02-16 14:00:56浏览次数:40  
标签:文件 .. inclusion .... DVWA etc File php page

File Inclusion,文件包含(漏洞),是指当服务器开启allow_url_include选项时,就可以通过php的某些特性函数(include(),require()和include_once(),require_once())利用url去动态包含文件,此时如果没有对文件来源进行严格审查,就会导致任意文件读取或者任意命令执行。

PHP中包含文件函数介绍:

Include():当使用该函数包含文件时,只有代码执行到 include()函数时才将文件包含进来,发生错误时之给出一个警告,继续向下执行。

Include_once():功能与include相同,但当重复调用一个文件时,程序只调用一次。

Require():是php的内置函数,作用是引入或者包含外部php文件,当本身php文件被执行时,则外部文件的内容就将被包含进该自身php文件中;当包含的外部文件发生错误时,系统将抛出错误提示,并且停止php文件的执行。

Require_once()::功能与require相同,但当重复调用一个文件时,程序只调用一次。

 

--low 级别:

 服务器端代码:

<?php

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

?>

当前服务器端直接读取page参数,并没有做其他限制。

 正常操作信息如下:

也就是说,当传递正确的文件路径且该文件由读取权限时,能在页面上查看到该文件的内容。

先试一下./file2.php是不是也能访问文件信息,如果可以说明可以通过../进行查看其他目录下的文件内容。

 查看/etc/passwd的内容:../../../../../../etc/passwd

 

--medium级别:

服务器端代码:

<?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参数后,通过str_replace函数将:http://、https://、../、..\字符替换为空。

通过传递:../../../../../../etc/passwd  看看是不是已经没用了

 因为现在../已经被服务器替换为空了,那就重新构造一个替换后,重新组合成的路径:....//....//....//....//....//....//etc/passwd

 说明单独的替换并不能有效的防止这种文件包含的漏洞。

--high 级别:

服务器端代码:

<?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;
}

?>

看一下fnmatch() 函数的说明,根据指定的模式来匹配文件名或字符串。也就是说page中的参数格式必须是以file开头后面拼接任意内容的形式,才能进行读取。

试一下page=../../../../../../etc/passwd,看看是否已经被拦截掉了。

 再试一下page=....//....//....//....//....//....//etc/passwd 看看结果如何?

 

虽然之前构造的page参数已经无效了,但是,从上面服务器端的代码中可以看出page参数必须以file开始,那么试一下通过file的形式进行访问。

page=file:///../../../../../../etc/passwd

 最终通过file:/// 的形式访问,还是能访问到其他文件信息。

--impossible 级别:

服务器端代码:

<?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;
}

?>

在impossible中的方式加了更严的限制,就直接限制只能读取:include.php、file1.php、file2.php、file3.php。

 

标签:文件,..,inclusion,....,DVWA,etc,File,php,page
From: https://www.cnblogs.com/JcHome/p/18017095

相关文章

  • windows下c++遍历各个磁盘的所有文件,不知道为什么FindFirstFileA文件会报错,进而程序退
    下面的程序还有一些问题,比如360的一些目录就用FindFirstFileA函数打开错误;还有  C:\Windows\System32\WebThreatDefSvc ,属性只有 DIRECTORY,用函数 _access检查也没有问题,但是就是用FindFirstFileA打开的时候错误;至今没有想到解决办法,只能临时跳过这种目录。 #include......
  • SHGetSpecialFolderPath(NULL, path, CSIDL_PROGRAM_FILES_COMMONX86, 0)
    CStringstr;TCHARpath[MAX_PATH];BOOLb=SHGetSpecialFolderPath(NULL,path,CSIDL_PROGRAM_FILES_COMMONX86,0);//获取指定的系统路径/*参数1:HWNDhwndOwner窗口所有者的句柄。可以NULL参数2:LPTSTRlpszPath返回路径的缓冲区,该缓冲区的大......
  • DVWA-Command Injection(命令注入)
    命令注入是通过提交含有恶意的服务器端可以执行命令,且这些命令能被服务器执行,从而能间接操作服务器。DVWA的CommandInjection级别分为:--low--medium--high--impossible--low级别看以下,正常的操作是输入IP地址,交由服务器进行ping操作,然后再将结果返回给......
  • bits/libc-header-start.h: No such file or directory
    问题出现在编译一个工程的时候,出现了报错Infileincludedfrom/usr/lib/gcc/x86_64-linux-gnu/9/include/stdint.h:9,frommain.c:1:/usr/includ......
  • 【XV6】 file system
    代码:https://github.com/JasenChao/xv6-labs.git支持大文件XV6目前只支持268个blocks大小的文件,一个block(BSIZE)为1024,文件块inode包含12个一级地址和1个二级地址,二级地址指向另一个block,其中存放了256个一级地址,因此一共是268个。题目要求支持大文件(65803个blocks),提示通过三级......
  • Debug: tf distribute strategy parameter server: NOT_FOUND: No such file or dire
    [ERROR:NOT_FOUND:/tfx/tfx_pv/pipelines/detect_anomolies_on_wafer_tfdv_schema/ImportExampleGen/examples/67/Split-train/data_tfrecord-00000-of-00001.gz;Nosuchfileordirectory]logofpodtfx-trainer-component:ERROR:tensorflow:/job:worker/task:0en......
  • [972] Remove specific sheets from an Excel file
    ToremovespecificsheetsfromanExcelfile,youcanusetheopenpyxllibraryinPython.Here'showyoucandoit:fromopenpyxlimportload_workbook#PathtotheExcelfileexcel_file_path='example.xlsx'#OpentheExcelworkbookwb......
  • [970] Combine multiple Excel files into one Excel file with multiple sheets
    YoucancombinemultipleExcelfilesintooneExcelfilewithmultiplesheetsusingthePandaslibraryinPython.Here'sageneralapproach:ReadeachExcelfileintoaPandasDataFrame.CreateanExcelwriterobjectusingPandas.WriteeachDataFra......
  • [971] [Keep original formats] Combine multiple Excel files into one Excel file w
    IftheexistingExcelfilehasspecialformattingthatpreventsreadingitdirectlywithPandas,youcanusealibrarylikeopenpyxltohandletheappendingofnewsheets.Here'showyoucanachievethis:importosfromopenpyxlimportload_workbook......
  • 解决jstack的报错:Unable to open socket file
    原文网址:​​解决jstack的报错:Unabletoopensocketfile_IT利刃出鞘的博客-CSDN博客​​简介说明本文介绍解决jstack的报错的方法,报错信息为:Unabletoopensocketfile。分享Java技术星球:​​自学精灵-IT技术星球​​详细报错信息:进程号:Unabletoopensocketfile:......