/*
   Odin by Brandefense - Monograph 64 (Operation DockHarvest) YARA Suite
   4 filesize-bounded structural rules covering SQL Server CLR & OPENQUERY scripts,
   rogue MySQL LOCAL INFILE listeners, Logback JNDI/SocketReceiver XML stagers,
   and Python /recv HTTP callback receivers (zero victim or vendor identifiers).
*/

rule ODIN_DockHarvest_SQL_CLR_and_OPENQUERY_Script
{
    meta:
        author = "Odin by Brandefense"
        monograph = "64"
        description = "Detects scripts staging SQL Server CLR assemblies, OPENQUERY pass-through probes, and IIS connection-string queries"
        date = "2026-11-25"
    strings:
        $c1 = "CREATE ASSEMBLY" ascii nocase
        $c2 = "clr strict security" ascii nocase
        $c3 = "OPENQUERY(" ascii nocase
        $m1 = "sys.assemblies" ascii nocase
        $m2 = "sp_configure" ascii nocase
        $m3 = "connectionStrings" ascii nocase
        $m4 = "INFORMATION_SCHEMA.TABLES" ascii nocase
    condition:
        filesize < 64KB and 1 of ($c*) and 2 of ($m*)
}

rule ODIN_DockHarvest_Rogue_MySQL_Local_Infile_Server
{
    meta:
        author = "Odin by Brandefense"
        monograph = "64"
        description = "Detects Python rogue MySQL listeners serving 0xfb LOCAL INFILE file-read packets"
        date = "2026-11-25"
    strings:
        $s1 = "socket.socket" ascii
        $s2 = "0.0.0.0" ascii
        $f1 = "\\xfb" ascii
        $f2 = "0xfb" ascii
        $t1 = "/tmp/stolen" ascii
        $t2 = "/etc/passwd" ascii
        $t3 = "mysql_native_password" ascii
    condition:
        filesize < 64KB and $s1 and $s2 and ($f1 or $f2) and 1 of ($t*)
}

rule ODIN_DockHarvest_Logback_JNDI_or_Socket_XML_Stager
{
    meta:
        author = "Odin by Brandefense"
        monograph = "64"
        description = "Detects Logback XML configurations staging insertFromJNDI lookups or SocketReceiver connections"
        date = "2026-11-25"
    strings:
        $x1 = "<configuration" ascii nocase
        $l1 = "ch.qos.logback." ascii
        $l2 = "logback" ascii nocase
        $g1 = "<insertFromJNDI" ascii nocase
        $g2 = "SocketReceiver" ascii nocase
        $g3 = "ServerSocketReceiver" ascii nocase
    condition:
        filesize < 32KB and $x1 and ($l1 or $l2) and 1 of ($g*)
}

rule ODIN_DockHarvest_HTTP_Callback_Receiver_Script
{
    meta:
        author = "Odin by Brandefense"
        monograph = "64"
        description = "Detects lightweight Python HTTP upload and callback receivers writing under /recv routes"
        date = "2026-11-25"
    strings:
        $h1 = "BaseHTTPRequestHandler" ascii
        $h2 = "http.server" ascii
        $p1 = "do_POST" ascii
        $r1 = "/recv" ascii
    condition:
        filesize < 32KB and ($h1 or $h2) and $p1 and $r1
}
