0x01 前言
任意文件读取漏洞,从代码审计的角度讲一讲。
0x02 什么是任意文件下载漏洞
一般的网站都提供读取文件功能,常规的思路是使用一个动态页面(php、jsp、aspx、asp等)将待下载文件作为参数一般参数名称为filename,如.php?filename/.jsp?filename等。一般实现过程是,在根据参数filename的值,获得该文件在网站上的绝对路径,读取文件。大部分情况下,与任意文件下载的危害性相同(都获取到了源代码里的包含的信息)。
0x03 任意文件下载漏洞的危害
任意文件读取漏洞,是web安全里高危的漏洞,它可以泄露源码、数据库配置文件等等,导致网站处于极度不安全状态。
0x04 实战的案例
我们来看看zzcms的任意文件读取漏洞,这是个能拿出来当教材的CMS(有兴趣的朋友可以下载看看)
index.php
参数$siteskin是通过$_request['skin']获取的,然后通过fread读取,最后echo出来。
- $file=dirname(__FILE__)."/template/".$siteskin."/index.htm";
- if (file_exists($file)==false){
- WriteErrMsg($file.'模板文件不存在');
- exit;
- }
- $fso = fopen($file,'r');
- $strout = fread($fso,filesize($file));
- 。。。。。。
- echo $strout;
复制代码
http://127.0.0.1/index.php?skin=../inc/config.php%00(00截断)
第二处:
/area/show.php
代码是一样的
- $fp="../template/".$siteskin."/area_show.htm";
- $f = fopen($fp,'r');
- $strout = fread($f,filesize($fp));
- fclose($f);
- $strout=str_replace("{#siteskin}",$siteskin,$strout) ;
- $strout=str_replace("{#sitename}",sitename,$strout) ;
- $strout=str_replace("{#siteurl}",siteurl,$strout) ;
- $strout=str_replace("{#pagetitle}",$province.sitetitle,$strout);
- $strout=str_replace("{#pagekeywords}",$province.sitekeyword,$strout);
- $strout=str_replace("{#pagedescription}",sitedescription,$strout);
- $strout=str_replace("{#province}",$province,$strout) ;
- $strout=str_replace("{#sitebottom}",sitebottom(),$strout);
- $strout=str_replace("{#sitetop}",sitetop(),$strout);
- $strout=showlabel($strout);
- echo $strout;
复制代码
第三处:
/company/company.php
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)