/*
   Odin by Brandefense - Monograph 65 YARA Suite
   4 filesize-bounded structural rules covering staged Python install.py wrappers,
   multi-stage boot/agent2 callback loaders, Git clean/smudge filter abuse, and dumb-HTTP bare Git manifests.
*/

rule ODIN_WB65_Python_Install_Wrapper_Stage_Fetch
{
    meta:
        author = "Odin by Brandefense"
        monograph = "65"
        description = "Detects compact Python install.py package wrappers referencing high-port stage-two routes (:9999/slw, :8088/boot, or :8088/agent2.py)"
        date = "2026-11-25"
    strings:
        $r1 = ":9999/slw" ascii
        $r2 = ":8088/boot" ascii
        $r3 = ":8088/agent2.py" ascii
        $r4 = ":8088/cmd" ascii
        $p1 = "urllib" ascii
        $p2 = "subprocess" ascii
        $p3 = "os.system" ascii
        $p4 = "requests" ascii
    condition:
        filesize < 16KB and ($r1 or $r2 or $r3 or $r4) and ($p1 or $p2 or $p3 or $p4)
}

rule ODIN_WB65_Python_MultiStage_Callback_Loader
{
    meta:
        author = "Odin by Brandefense"
        monograph = "65"
        description = "Detects multi-stage Python bootstrap and callback scripts combining /cb/, boot2.py, or agent2.py endpoints with network and process execution"
        date = "2026-11-25"
    strings:
        $c1 = "/cb/" ascii
        $c2 = "boot2.py" ascii
        $c3 = "agent2.py" ascii
        $n1 = "urllib.request" ascii
        $n2 = "socket" ascii
        $e1 = "subprocess" ascii
        $e2 = "exec(" ascii
    condition:
        filesize < 32KB and ($c1 and ($c2 or $c3)) and ($n1 or $n2) and ($e1 or $e2)
}

rule ODIN_WB65_GitAttributes_Filter_Config_Abuse
{
    meta:
        author = "Odin by Brandefense"
        monograph = "65"
        description = "Detects Git configuration files registering clean or smudge filter commands invoking Python, curl, wget, or shell interpreters"
        date = "2026-11-25"
    strings:
        $f1 = "[filter " ascii
        $f2 = "filter." ascii
        $m1 = "smudge =" ascii
        $m2 = "clean =" ascii
        $x1 = "python" ascii
        $x2 = "sh -c" ascii
        $x3 = "curl " ascii
        $x4 = "wget " ascii
    condition:
        filesize < 64KB and ($f1 or $f2) and ($m1 or $m2) and ($x1 or $x2 or $x3 or $x4)
}

rule ODIN_WB65_Bare_Git_DumbHTTP_Repo_Manifest
{
    meta:
        author = "Odin by Brandefense"
        monograph = "65"
        description = "Detects small bare Git configuration files for analyst triage; this structural match does not establish malicious use."
        date = "2026-11-25"
    strings:
        $g1 = "[core]" ascii
        $g2 = "bare = true" ascii
    condition:
        filesize < 8KB and $g1 and $g2
}
