/*
   Odin by Brandefense - Monograph 40 / 46 YARA Artifact Suite
   Scope: Structural detection rules for GIF/JPEG image-header polyglot JSP webshells,
          JeecgBoot JimuReport (CVE-2023-4450) and Java Quartz RCE scanners,
          WordPress Core CVE-2026-119977 upgrade-window race scripts, and
          WordPress XML-RPC multicall / shell deployment scripts.
   Classification: TLP:CLEAR
*/

rule ODIN_Polyglot_Image_Header_JSP_Webshell
{
    meta:
        author = "Odin by Brandefense"
        monograph = "40 / 46"
        classification = "TLP:CLEAR"
        action = "BLOCK_POLYGLOT_JSP_WEBSHELL"
        description = "Matches JSP webshells prepending GIF87a/GIF89a or JPEG magic bytes ahead of JSP tags and Java execution primitives"
    strings:
        $gif1 = "GIF89a" ascii
        $gif2 = "GIF87a" ascii
        $jpg1 = { FF D8 FF }
        $jsp1 = "<%" ascii
        $ex1 = "getRuntime" ascii
        $ex2 = "ProcessBuilder" ascii
        $ex3 = "defineClass" ascii
        $ex4 = "javax.crypto.Cipher" ascii
    condition:
        filesize < 256KB and ($gif1 at 0 or $gif2 at 0 or $jpg1 at 0) and $jsp1 and 1 of ($ex*)
}

rule ODIN_JimuReport_and_Quartz_RCE_Scanner_Script
{
    meta:
        author = "Odin by Brandefense"
        monograph = "40 / 46"
        classification = "TLP:CLEAR"
        action = "HUNT_JAVA_MIDDLEWARE_RCE_SCANNER"
        description = "Matches Python scanners probing JeecgBoot JimuReport CVE-2023-4450 template injection or Java Quartz scheduler RCE"
    strings:
        $jmr1 = "/jmreport/queryFieldBySql" ascii
        $jmr2 = "/jmreport/show" ascii
        $ftl1 = "freemarker.template.utility.Execute" ascii
        $qtz1 = "jobClassName" ascii
        $qtz2 = "sys/quartzJob" ascii
        $pay1 = "getRuntime" ascii
        $pay2 = "ProcessBuilder" ascii
        $pay3 = "InitialContext" ascii
    condition:
        filesize < 128KB and ((($jmr1 or $jmr2) and ($ftl1 or 1 of ($pay*))) or (($qtz1 or $qtz2) and 1 of ($pay*)))
}

rule ODIN_WordPress_CVE_2026_119977_Upgrade_Race_Exploit
{
    meta:
        author = "Odin by Brandefense"
        monograph = "40 / 46"
        classification = "TLP:CLEAR"
        action = "HUNT_WP_UPGRADE_RACE_EXPLOIT"
        description = "Matches Python race-condition scripts polling predictable WordPress wp-content/upgrade staging paths during CVE-2026-119977 windows"
    strings:
        $up1 = "/wp-content/upgrade/" ascii
        $rc1 = "ThreadPoolExecutor" ascii
        $rc2 = "threading.Thread" ascii
        $rc3 = "asyncio.gather" ascii
        $ctx1 = "CVE-2026-119977" ascii nocase
        $ctx2 = "update-core.php" ascii
        $ctx3 = "wordpress-7." ascii nocase
    condition:
        filesize < 256KB and $up1 and 1 of ($rc*) and 1 of ($ctx*)
}

rule ODIN_WordPress_XMLRPC_Multicall_and_Shell_Deployer
{
    meta:
        author = "Odin by Brandefense"
        monograph = "40 / 46"
        classification = "TLP:CLEAR"
        action = "HUNT_CMS_BRUTE_AND_DEPLOYER"
        description = "Matches Python WordPress XML-RPC system.multicall brute-force scripts and theme/plugin webshell uploaders"
    strings:
        $x1 = "/xmlrpc.php" ascii
        $x2 = "system.multicall" ascii
        $x3 = "wp.getUsersBlogs" ascii
        $d1 = "wp-admin/theme-editor.php" ascii
        $d2 = "wp-admin/update.php?action=upload-plugin" ascii
        $d3 = "application/zip" ascii
    condition:
        filesize < 256KB and (($x1 and $x2 and $x3) or (($d1 or $d2) and $d3))
}
