import shutil
import asyncio
async def brute_force_login(target: str, service: str, user_list: str, pass_list: str) -> dict:
"""
Brute force using Hydra
"""
if not shutil.which("hydra"):
return {"error": "hydra not installed"}
try:
# hydra -L <user_list> -P <pass_list> <target> <service> -I
# -I : ignore existing restore file
cmd = ["hydra", "-L", user_list, "-P", pass_list, target, service, "-I", "-o", "-", "-b", "json"]
# Hydra doesn't output JSON nicely to stdout in all versions, but let's try
# Actually hydra's output is text mostly. -b json is for some versions or specific modules?
# Standard hydra is text.
cmd = ["hydra", "-L", user_list, "-P", pass_list, target, service, "-I"]
process = await asyncio.create_subprocess_exec(
*cmd,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE
)
stdout, stderr = await process.communicate()
output = stdout.decode()
# Simple parsing
findings = []
for line in output.splitlines():
if "login:" in line and "password:" in line:
findings.append(line)
return {"findings": findings, "raw_output": output}
except Exception as e:
return {"error": str(e)}