/*
   Odin by Brandefense - Monograph 57 (Operation SapperSync) YARA Suite
   4 filesize-bounded structural rules covering local-upload AI agent skill manifests,
   ImageMagick MSL XML scripts, hidden container .agent_sync wrappers, and layered runtime markers.
*/

rule ODIN_SapperSync_LocalUpload_Agent_Skill_Meta
{
    meta:
        author = "Odin by Brandefense"
        monograph = "57"
        description = "Detects local-upload AI agent skill manifests and archives pairing SKILL.md or _meta.json structure with source=local-upload"
        date = "2026-11-24"
    strings:
        $s1 = "local-upload" ascii
        $m1 = "SKILL.md" ascii
        $m2 = "\"source\"" ascii
        $m3 = "source=" ascii
    condition:
        filesize < 64KB and $s1 and ($m1 or $m2 or $m3)
}

rule ODIN_SapperSync_ImageMagick_MSL_Polyglot_Script
{
    meta:
        author = "Odin by Brandefense"
        monograph = "57"
        description = "Detects staged ImageMagick Magick Scripting Language XML files pairing image blocks with read and write file directives"
        date = "2026-11-24"
    strings:
        $x1 = "<image>" ascii nocase
        $x2 = "</image>" ascii nocase
        $r1 = "<read " ascii nocase
        $w1 = "<write " ascii nocase
        $f1 = "filename=" ascii nocase
    condition:
        filesize < 256KB and ($x1 or $x2) and $r1 and $w1 and $f1
}

rule ODIN_SapperSync_Container_Entrypoint_AgentSync
{
    meta:
        author = "Odin by Brandefense"
        monograph = "57"
        description = "Detects staged container entrypoint, periodic cron, and hidden .agent_sync scripts targeting web container environments"
        date = "2026-11-24"
    strings:
        $a1 = "/usr/local/bin/.agent_sync" ascii
        $p1 = "runtime-entrypoint" ascii
        $p2 = ".runtime-sync" ascii
        $e1 = "DB_HOST" ascii
        $e2 = "/var/www/html/cache" ascii
    condition:
        filesize < 64KB and $a1 and ($p1 or $p2 or ($e1 and $e2))
}

rule ODIN_SapperSync_Runtime_Hotfix_Layer_Markers
{
    meta:
        author = "Odin by Brandefense"
        monograph = "57"
        description = "Detects individual extracted container marker file contents containing release=2.4.2 or channel=hotfix (verify /opt/runtime/VERSION or /opt/runtime/CHANNEL path separately)"
        date = "2026-11-24"
    strings:
        $v2 = "release=2.4.2" ascii
        $c2 = "channel=hotfix" ascii
    condition:
        filesize < 64KB and ($v2 or $c2)
}
