目录

. 漏洞描述
. 漏洞触发条件
. 漏洞影响范围
. 漏洞代码分析
. 防御方法
. 攻防思考

1. 漏洞描述

dedecms采用面向对象封装的方式实现了功能操作的模块集中化,例如对于数据库管理

. /include/dedesql.class.php: mysql数据库操作
. /include/dedesqli.class.php: mysqli数据库操作

当发生数据库操作语句执行错误的时候,框架代码会集中对错误相关信息进行收集,并保存到一个指定的文件中(/data/mysql_error_trace.php),但是这里存在一个安全上的漏洞

. MySQL字段数值采用了C语言同样的定义,当传入的数值大于字段定义的类型的时候,将引发整型上溢出错误

. /data/mysql_error_trace.php没有进行正确的访问认证
/*
security practice
在不需要被访问的日志文件头应该加上以下代码
die('Request Error!');
or
exit();
*/ . 日志文件最好使用例如".txt"的文本文件进行保存

真正导致漏洞的原因是数据库处理库(/include/dedesql.class.php),而触发这个漏洞的文件有很多,攻击向量路径很多,理论上只要调用了如下代码即存在漏洞

/*
$dsql->ExecuteNoneQuery("Update `$maintable` set scores = scores + {$cfg_caicai_add},goodpost=goodpost+1,lastpost=".time()." where id=$id");
*/

目前已知的可以成为攻击向量的文件有

. /plus/digg_frame.php
. /plus/digg_ajax.php
. /plus/comments_frame.php

Relevant Link:

http://icarusli.iteye.com/blog/610715
http://www.007hack.com/?p=522

2. 漏洞触发条件
3. 漏洞影响范围

. < dede 5.7

4. 漏洞代码分析

/include/dedesql.class.php

//显示数据链接错误信息
function DisplayError($msg)
{
$errorTrackFile = dirname(__FILE__).'/../data/mysql_error_trace.inc';
//这里将日志文件的后缀改为了.inc,是一个好的防御方法
if( file_exists(dirname(__FILE__).'/../data/mysql_error_trace.php') )
{
@unlink(dirname(__FILE__).'/../data/mysql_error_trace.php');
}
$emsg = '';
$emsg .= "<div><h3>DedeCMS Error Warning!</h3>\r\n";
$emsg .= "<div><a href='http://bbs.dedecms.com' target='_blank' style='color:red'>Technical Support: http://bbs.dedecms.com</a></div>";
$emsg .= "<div style='line-helght:160%;font-size:14px;color:green'>\r\n";
$emsg .= "<div style='color:blue'><br />Error page: <font color='red'>".$this->GetCurUrl()."</font></div>\r\n";
$emsg .= "<div>Error infos: {$msg}</div>\r\n";
$emsg .= "<br /></div></div>\r\n"; echo $emsg; $savemsg = 'Page: '.$this->GetCurUrl()."\r\nError: ".$msg;
//保存MySql错误日志
$fp = @fopen($errorTrackFile, 'a');
//直接将错误信息写入了可执行的.PHP文件中
@fwrite($fp, '<'.'?php'."\r\n/*\r\n{$savemsg}\r\n*/\r\n?".">\r\n");
@fclose($fp);
}

5. 防御方法

//显示数据链接错误信息
function DisplayError($msg)
{
$errorTrackFile = dirname(__FILE__).'/../data/mysql_error_trace.inc';
if( file_exists(dirname(__FILE__).'/../data/mysql_error_trace.php') )
{
@unlink(dirname(__FILE__).'/../data/mysql_error_trace.php');
}
$emsg = '';
$emsg .= "<div><h3>DedeCMS Error Warning!</h3>\r\n";
$emsg .= "<div><a href='http://bbs.dedecms.com' target='_blank' style='color:red'>Technical Support: http://bbs.dedecms.com</a></div>";
$emsg .= "<div style='line-helght:160%;font-size:14px;color:green'>\r\n";
$emsg .= "<div style='color:blue'><br />Error page: <font color='red'>".$this->GetCurUrl()."</font></div>\r\n";
$emsg .= "<div>Error infos: {$msg}</div>\r\n";
$emsg .= "<br /></div></div>\r\n"; echo $emsg; $savemsg = 'Page: '.$this->GetCurUrl()."\r\nError: ".$msg."\r\nTime".date('Y-m-d H:i:s');
//保存MySql错误日志
$fp = @fopen($errorTrackFile, 'a');
@fwrite($fp, '<'.'?php' . "\r\n" . "die('Request Error!');" . "\r\n/*\r\n{$savemsg}\r\n*/\r\n?".">\r\n");
@fclose($fp);
}

6. 攻防思考

Copyright (c) 2014 LittleHann All rights reserved

dedeCMS /data/mysql_error_trace.php DB error raised PHP Code Injection Via /include/dedesql.class.php Log FIle Without Access Validation的更多相关文章

  1. dedeCMS /plus/ad_js.php、/plus/mytag_js.php Vul Via Injecting PHP Code By /plus/download.php Into DB && /include/dedesql.class.php

    目录 . 漏洞描述 . 漏洞触发条件 . 漏洞影响范围 . 漏洞代码分析 . 防御方法 . 攻防思考 1. 漏洞描述 对于这个漏洞,我们可以简单概括如下 . "/plus/download. ...

  2. dedecms data文件夹外迁

    出于网站安全考虑,我们一般要把data文件夹迁移到网站根目录外面. dedecms data文件夹外迁方法: 1. 修改首页文件中配置文件路径 打开/index.php,把代码 if(!file_ex ...

  3. Data access between different DBMS and other txt/csv data source by DB Query Analyzer

        1 About DB Query Analyzer DB Query Analyzer is presented by Master Genfeng,Ma from Chinese Mainl ...

  4. Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'系列一:

    从库报这个错误:Got fatal error 1236 from master when reading data from binary log: 'Could not find first lo ...

  5. 元数据管理器中存在错误。 实例化来自文件“\\?\C:\Program Files\Microsoft SQL Server\MSAS11.MSSQLSERVER\OLAP\Data\Tfs_Analysis.0.db\vDimTestCaseOverlay.874.dim.xml”的元数据对象时出错。

    一.发现问题 启动SQLSERVER的数据分析服务失败 查看系统日志错误如下: 双击错误后显示详细错误: 元数据管理器中存在错误. 实例化来自文件“\\?\C:\Program Files\Micro ...

  6. mysql从库Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'报错处理

    年后回来查看mysql运行状况与备份情况,登录mysql从库查看主从同步状态 mysql> show slave status\G; *************************** . ...

  7. hive sequencefile导入文件遇到FAILED: SemanticException Unable to load data to destination table. Error: The file that you are trying to load does not match the file format of the destination table.错误

    hive sequencefile导入文件遇到FAILED: SemanticException Unable to load data to destination table. Error: Th ...

  8. Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'

    setup slave from backup i got error Got fatal error 1236 from master when reading data from binary l ...

  9. How to Fix "Linux Failure to Download extra data files for ttf-mscorefonts-installer" error

    How to Fix "Linux Failure to Download extra data files for ttf-mscorefonts-installer" erro ...

随机推荐

  1. Django admin 显示图片

    我有一个表用来储存轮播图片,有一个 `picture` 字段储存的是图片的url,图片的 url 通过上传文件到 cdn 获得.目前这个表的编辑是通过自定义一个 `ModelForm`,然后重写 Dj ...

  2. win8.1环境下安装arduino驱动问题解决方案

    1. Windows 键+ R, 输入 shutdown.exe /r /o /f /t 00 2.此时电脑会自动重启,进入一下画面,选择Troubleshoot (转载请注明原处:http://ww ...

  3. c++ 头文件

    可以将程序分为二部分: 头文件:包含结构声明和使用这些结构的函数的原型 源代码文件: 包含与结构有关的函数的代码 不要将函数的定义或变量的声明放在头文件里, 一般头文件可以包含以下内容 >函数原 ...

  4. 页面跳转Transfer与Redirect的区别你知道吗?

    一 前言 关于页面跳转的方式常用的应该就是,链接跳转,js跳转,Server.Tranfser和Response.Redirect 这几种,可是在Tranfser与Redirect之间用哪种更好(本文 ...

  5. 使用pngquant来压缩png资源缩小apk

    最近发现了一个叫做pngquant的工具,可以有效的压缩资源文件中的png文件,从而减小发布的apk的大小.我发现这个工具有两个特点: 1. 真无损,压缩后重新运行了我的app发现是没有任何区别的 2 ...

  6. Nodejs进阶:核心模块https 之 如何优雅的访问12306

    本文摘录自<Nodejs学习笔记>,更多章节及更新,请访问 github主页地址.欢迎加群交流,群号 197339705. 模块概览 这个模块的重要性,基本不用强调了.在网络安全问题日益严 ...

  7. 学习Google Protocol buffer之语法

    上一篇结尾的时候问了几个问题,其实主要就是这个protoBuffer协议的语法,弄清楚语法后边才好开展工作嘛,不然大眼而对小眼儿,互相不认识,就没法玩耍了.其实就是学习怎么用google提供的这套 p ...

  8. 一个奇妙的java坑:Long 类型的比较

    Long userId=127L; Long authorId=127L; System.out.println(userId==authorId);//true userId=128L; autho ...

  9. jQuery——$(function(){});与$(document).ready(function(){});的区别

    只要在我们的jsp页面中写上 <script> $(function(){ //内容 }); </script> 则,函数中的内容就会在jsp页面被载入的时候就被执行,实际上, ...

  10. OKhttp初步

    OkHttp 使用方法:1.分为同步和异步.同步:1.getRequest request = new Request.Builder().url(utl).build();Response resp ...