/*
   Odin by Brandefense - Monograph 62 YARA Suite
   4 filesize-bounded structural rules covering staged Linux NSS / libnscd.so loaders,
   custom Root CA trust injectors, HAProxy PROXY v1 origin-bypass scripts, and SSH proxy floods.
*/

rule ODIN_WB62_Linux_NSS_Libnscd_Loader_Script
{
    meta:
        author = "Odin by Brandefense"
        monograph = "62"
        description = "Detects staged administrative loader scripts referencing /libnscd.so, /kreport, and Linux NSS or dynamic linker paths"
        date = "2026-11-24"
    strings:
        $u1 = "/libnscd.so" ascii
        $u2 = "/kreport" ascii
        $n1 = "nsswitch.conf" ascii
        $n2 = "LD_PRELOAD" ascii
        $n3 = "nscd" ascii
    condition:
        filesize < 256KB and $u1 and $u2 and ($n1 or $n2 or $n3)
}

rule ODIN_WB62_Custom_CA_Interceptor_Injector
{
    meta:
        author = "Odin by Brandefense"
        monograph = "62"
        description = "Detects Python or JavaScript TLS trust-injection scripts pairing custom PEM CA files with trust-store or TLS context overrides"
        date = "2026-11-24"
    strings:
        $c1 = "kyng-ca.pem" ascii
        $c2 = "BEGIN CERTIFICATE" ascii
        $t1 = "update-ca-certificates" ascii
        $t2 = "NODE_EXTRA_CA_CERTS" ascii
        $t3 = "load_verify_locations" ascii
    condition:
        filesize < 128KB and ($c1 or $c2) and ($t1 or $t2 or $t3)
}

rule ODIN_WB62_HAProxy_TCPShield_Origin_Bypass_Script
{
    meta:
        author = "Odin by Brandefense"
        monograph = "62"
        description = "Detects Python scripts building spoofed HAProxy PROXY v1 TCP4 headers to test direct-to-origin shield bypasses"
        date = "2026-11-24"
    strings:
        $p1 = "PROXY TCP4 " ascii
        $s1 = "socket.socket" ascii
        $s2 = "SOCK_STREAM" ascii
        $h1 = "\\r\\n" ascii
    condition:
        filesize < 64KB and $p1 and ($s1 or $s2) and $h1
}

rule ODIN_WB62_SSH_Proxy_CONNECT_Flood_Script
{
    meta:
        author = "Odin by Brandefense"
        monograph = "62"
        description = "Detects Python scripts tunneling high-rate SSH-2.0 handshake floods through HTTP CONNECT proxies to port 22"
        date = "2026-11-24"
    strings:
        $m1 = "CONNECT " ascii
        $m2 = ":22 HTTP/1." ascii
        $b1 = "SSH-2.0-" ascii
        $s1 = "socket" ascii
    condition:
        filesize < 64KB and $m1 and $m2 and $b1 and $s1
}
