Last active
August 29, 2015 14:07
-
-
Save MasterOdin/22b39a642f8d053d3214 to your computer and use it in GitHub Desktop.
Brute Force Postgres Role Password Checker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import md5 | |
import string | |
import time | |
''' | |
# Brute force solves a md5 hash (for a postgres user role) | |
# Assumes that password is only [a-zA-Z] | |
''' | |
def getNextCharacter(string,pos,characters): | |
if pos == -1: | |
return string; | |
if string == characters[-1]*len(string): | |
string = characters[0]*(len(string)+1) | |
elif string[pos] == characters[-1]: | |
string = getNextCharacter(string,pos-1,characters) | |
string = list(string) | |
string[pos] = characters[0] | |
string = ''.join(string) | |
else: | |
string = list(string) | |
string[pos] = characters[characters.index(string[pos])+1] | |
string = ''.join(string) | |
return string | |
user = raw_input("Enter Postgres Role Username ==> ") | |
md5hash = raw_input("Enter md5 hash of password ==> ") | |
start = time.time() | |
characters = list(string.ascii_uppercase)+list(string.ascii_lowercase) | |
string = characters[0]; | |
m = md5.new() | |
m.update(string) | |
genhash = m.hexdigest(); | |
count = 0 | |
while genhash != md5hash and len(string) < 20: | |
string = getNextCharacter(string,len(string)-1,characters) | |
m = md5.new() | |
m.update(string+user) | |
genhash = m.hexdigest() | |
count += 1 | |
print count | |
print string | |
print genhash | |
print "Time Taken:",(time.time()-start) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment