Presentation is loading. Please wait.

Presentation is loading. Please wait.

Web安全基础教程 灯芯@看雪学院.

Similar presentations


Presentation on theme: "Web安全基础教程 灯芯@看雪学院."— Presentation transcript:

1 Web安全基础教程

2 主要内容 文件包含

3 当服务器开启allow_url_include选项时,可以通过php的某些特性函数include(),require(),include_once(),require_once()利用url去动态包含文件,导致任意文件读取或任意命令执行。 文件包含分为两种:本地文件包含和远程文件包含(allow_url_fopen)

4 low <?php // The page we wish to display $file = $_GET[ 'page' ]; ?> 在代码中可以看到并没有对page参数做任何的过滤和防护, 在用户对url进行传参时不管page=?都会被服务器当成php来执行,所以造成任意文件读取和任意命令执行。

5 Med 替换了../和..\只是对相对路径做了限制,对绝对路径依然不起作用,而且对远程文件包含也没有作用
<?php // The page we wish to display $file = $_GET[ ‘page’ ]; // Input validation $file = str_replace( array( “ //str_replace可参考代码审计 主要是对给出的http://等做一个替换 ,但是存在双写绕过的情况hthttp://tp:// $file = str_replace( array( “../”, “..\”“ ), ”“, $file ); 空格 ?> 替换了../和..\只是对相对路径做了限制,对绝对路径依然不起作用,而且对远程文件包含也没有作用

6 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参数,要求page参数的开头必须是file,和我们本地打开文件是一样的,使用的是file协议

7 Thanks


Download ppt "Web安全基础教程 灯芯@看雪学院."

Similar presentations


Ads by Google