#!/usr/bin/env python3 """Collect the raw evidence for the Circuit Times bug bounty guide. python3 collect.py survey security.txt survey of the first 1,000 Tranco domains python3 collect.py listings public bug bounty listings from Bugcrowd and YesWeHack Survey rules, in full: * Domains are the first 1,000 rows of the current Tranco list, in rank order, exactly as listed. * Each domain gets at most four GET requests, in this fixed order, with no retries: 1. https://DOMAIN/.well-known/security.txt 3. https://DOMAIN/security.txt 2. https://www.DOMAIN/.well-known/security.txt 4. https://www.DOMAIN/security.txt * Requests for one domain run one after another. The loop stops at the first reply that has status 200 and contains the text "contact:". At most 16 domains are in progress at once. * Timeouts: 8 seconds to connect, 12 seconds to read. Redirects are followed, at most 5. * Every attempt is recorded with its status, final address, content type and, on failure, the error class and message. If a site sends a status and its body then fails to arrive, the status is kept and the body error is recorded separately. * At most the first 100,000 decoded bytes of any body are read, and body_truncated records whether the body was longer. Within that cap, a body is stored whole only when the reply could be a security.txt file (status 200 and "contact:" present). Other bodies keep 200 characters. """ import concurrent.futures as futures import datetime as dt import hashlib import io import json import sys import time import zipfile import requests USER_AGENT = "Mozilla/5.0 (compatible; CircuitTimesSecurityTxtSurvey/2.3; +https://circuittimes.com/)" TRANCO_ID_URL = "https://tranco-list.eu/top-1m-id" TRANCO_ZIP_URL = "https://tranco-list.eu/top-1m.csv.zip" URL_TEMPLATES = ("https://{d}/.well-known/security.txt", "https://www.{d}/.well-known/security.txt", "https://{d}/security.txt", "https://www.{d}/security.txt") LIMIT = 1000 WORKERS = 16 CONNECT_TIMEOUT, READ_TIMEOUT = 8, 12 MAX_REDIRECTS = 5 MAX_BODY_BYTES = 100_000 KEEP_HEAD_CHARS = 200 def now(): return dt.datetime.now(dt.timezone.utc).isoformat(timespec="seconds") def fetch(url): record = {"url": url} session = requests.Session() session.max_redirects = MAX_REDIRECTS session.headers["User-Agent"] = USER_AGENT try: with session.get(url, timeout=(CONNECT_TIMEOUT, READ_TIMEOUT), stream=True) as reply: # The status line and headers have arrived, so record them before touching the body. record.update(status=reply.status_code, final_url=reply.url, redirects=len(reply.history), content_type=reply.headers.get("Content-Type", ""), body_chars=0, body="") try: data = reply.raw.read(MAX_BODY_BYTES + 1, decode_content=True) # one extra byte reveals a longer body except Exception as exc: # the site answered, but its body could not be read record.update(body_error=type(exc).__name__, body_error_detail=str(exc)[:300]) else: truncated = len(data) > MAX_BODY_BYTES text = data[:MAX_BODY_BYTES].decode("utf-8", "replace") candidate = reply.status_code == 200 and "contact:" in text.lower() record.update(body_chars=len(text), body_truncated=truncated, body=text if candidate else text[:KEEP_HEAD_CHARS]) except Exception as exc: # no HTTP response at all: record the failure as evidence record.update(status=None, error=type(exc).__name__, error_detail=str(exc)[:300]) finally: session.close() return record def survey_domain(domain): attempts = [] for template in URL_TEMPLATES: record = fetch(template.format(d=domain)) attempts.append(record) if record.get("status") == 200 and "contact:" in record.get("body", "").lower(): break return {"domain": domain, "attempts": attempts} def survey(): list_id = requests.get(TRANCO_ID_URL, timeout=60, headers={"User-Agent": USER_AGENT}).text.strip() blob = requests.get(TRANCO_ZIP_URL, timeout=180, headers={"User-Agent": USER_AGENT}).content rows = zipfile.ZipFile(io.BytesIO(blob)).read("top-1m.csv").decode().splitlines()[:LIMIT] with open("tranco-top1000.csv", "w") as handle: handle.write("\n".join(rows) + "\n") domains = [row.split(",")[1] for row in rows] started = now() with futures.ThreadPoolExecutor(WORKERS) as pool: results = list(pool.map(survey_domain, domains)) payload = {"tranco_list_id": list_id, "tranco_zip_sha256": hashlib.sha256(blob).hexdigest(), "started_utc": started, "finished_utc": now(), "user_agent": USER_AGENT, "url_templates": URL_TEMPLATES, "results": results} with open("survey-raw.json", "w") as handle: json.dump(payload, handle, indent=0, sort_keys=True) print("survey saved:", len(results), "domains, Tranco list", list_id) def get_json(url): reply = requests.get(url, timeout=60, headers={"User-Agent": USER_AGENT, "Accept": "application/json"}) reply.raise_for_status() time.sleep(1) return reply.json() def listings(): bugcrowd, page = [], 1 while True: data = get_json("https://bugcrowd.com/engagements.json?category=bug_bounty" f"&sort_by=promoted&sort_direction=desc&page={page}") if not data["engagements"]: break for item in data["engagements"]: reward = item.get("rewardSummary") or {} bugcrowd.append({"name": item["name"].strip(), "briefUrl": item["briefUrl"], "type": (item.get("productEngagementType") or {}).get("label"), "minReward": reward.get("minReward"), "maxReward": reward.get("maxReward")}) page += 1 yeswehack, page = [], 1 while True: data = get_json(f"https://api.yeswehack.com/programs?page={page}&resultsPerPage=50") for item in data["items"]: yeswehack.append({key: item.get(key) for key in ("title", "slug", "type", "public", "bounty", "vdp", "disabled", "bounty_reward_min", "bounty_reward_max")}) if page >= data["pagination"]["nb_pages"]: break page += 1 for name, rows in (("bugcrowd-engagements.json", bugcrowd), ("yeswehack-programs.json", yeswehack)): with open(name, "w") as handle: json.dump({"collected_utc": now(), "programs": rows}, handle, indent=0, sort_keys=True) print(name, len(rows)) if __name__ == "__main__": mode = sys.argv[1] if len(sys.argv) > 1 else "" if mode == "survey": survey() elif mode == "listings": listings() else: sys.exit(__doc__)