0

I have been trying to think of a way to iterate through a username list and check each value of password from a password list. For example, there is a list of 2 usernames, admin and root, there is also a password list of 5 passwords.

For each of the usernames all passwords will have to checked.

I have been able to come up with this piece of code:

if os.path.isfile(USER_FILE) and os.path.isfile(PASS_FILE):
    with open(USER_FILE, 'r') as user_file, open(PASS_FILE, 'r') as pass_file:
        for u in user_file.read().splitlines():
            for p in pass_file.read().splitlines():
                print(f"{u}:{p}")

However, after the first username the scripts stops and the 2nd username is not checked agains all passwords in my list.

The output I am getting from the script is as follows:

./brute.py users.txt passwd.txt
admin:root
admin:admin
admin:toor
admin:123456
admin:000000000
admin:password

Any suggestion is appreciated..

Kr0ff
  • 49
  • 6
  • 1
    Please add the sample contents of the first file. As a side note, I do not see where you _check_ anything. You simply print all pairs of names and passwords. – DYZ Mar 21 '21 at 00:59
  • 1
    You can't keep calling `pass_file.read()` on the same file inside the loop. Once you've read through it once the iterator is spent. You are probably better off using `itertools.product` for this. – Mark Mar 21 '21 at 01:00
  • Sample contents of username list: admin root – Kr0ff Mar 21 '21 at 01:03

0 Answers0