/*
   Odin by Brandefense - Report #21 YARA Implant & Staging Detection Suite
   Classification: TLP:CLEAR
   Scope: ShadowPad (S0596) VFS modular loader, PlugX (S0013) side-load HTTP beacon,
          Kimsuky (G0094) VBS/PS1 PHP recon stager, and BianLian Go mTLS backdoor.
*/

rule ODIN_ShadowPad_Modular_VFS_Loader_And_Shellcode
{
    meta:
        author = "Odin by Brandefense"
        date = "2026-11-19"
        tlp = "CLEAR"
        mitre_software = "S0596"
        description = "Detects ShadowPad (POISONPLUG.SHADOW) modular Virtual File System plugin table and decompression loader markers"
    strings:
        $vfs1 = "VFS_ROOT_TABLE" ascii wide
        $vfs2 = "POISONPLUG" ascii wide nocase
        $plg1 = "Plugins\\OnlineKeylogger" ascii wide nocase
        $plg2 = "Plugins\\TcpTunnel" ascii wide nocase
        $api1 = "RtlDecompressBuffer" ascii
        $api2 = "VirtualAllocEx" ascii
    condition:
        filesize < 5MB and (1 of ($vfs*)) and (1 of ($plg*)) and all of ($api*)
}

rule ODIN_PlugX_Korplug_Sideload_Config_And_HTTP_Beacon
{
    meta:
        author = "Odin by Brandefense"
        date = "2026-11-19"
        tlp = "CLEAR"
        mitre_software = "S0013"
        description = "Detects PlugX (Korplug) side-loaded DLL configuration markers and custom X-Session/X-Size HTTP tunnel headers"
    strings:
        $cfg1 = "PLUG_CFG_HDR" ascii
        $hdr1 = "X-Session:" ascii wide
        $hdr2 = "X-Size:" ascii wide
        $hdr3 = "X-Status:" ascii wide
        $ldr1 = "RtlDecompressBuffer" ascii
        $ldr2 = "RunDllEntry" ascii
    condition:
        filesize < 4MB and ($cfg1 or 2 of ($hdr*)) and all of ($ldr*)
}

rule ODIN_Kimsuky_Recon_Stager_And_PHP_Collection_Script
{
    meta:
        author = "Odin by Brandefense"
        date = "2026-11-19"
        tlp = "CLEAR"
        mitre_group = "G0094"
        description = "Detects Kimsuky VBS/script reconnaissance stagers harvesting host survey output to PHP collection gates"
    strings:
        $http1 = "MSXML2.ServerXMLHTTP" ascii wide nocase
        $http2 = "WinHttp.WinHttpRequest" ascii wide nocase
        $cmd1 = "systeminfo" ascii wide nocase
        $cmd2 = "ipconfig /all" ascii wide nocase
        $cmd3 = "tasklist" ascii wide nocase
        $php1 = ".php?sysinfo=" ascii wide nocase
        $php2 = "/upload.php" ascii wide nocase
    condition:
        filesize < 2MB and (1 of ($http*)) and (2 of ($cmd*)) and (1 of ($php*))
}

rule ODIN_BianLian_Golang_mTLS_Backdoor_Implant
{
    meta:
        author = "Odin by Brandefense"
        date = "2026-11-19"
        tlp = "CLEAR"
        reference = "CISA-AA23-136A"
        description = "Detects Go-compiled backdoor binaries combining pinned X.509 certificate pools, TLS handshakes, and yamux multiplexing"
    strings:
        $go1 = "Go build ID:" ascii
        $tls1 = "crypto/tls.(*Conn).Handshake" ascii
        $tls2 = "crypto/x509.(*CertPool).AppendCertsFromPEM" ascii
        $net1 = "net.DialTimeout" ascii
        $mux1 = "hashicorp/yamux" ascii
    condition:
        filesize < 15MB and $go1 and all of ($tls*) and $net1 and $mux1
}
