/*
   Odin by Brandefense - Monograph 52 / 52 YARA Detection Suite
   Scope: Gh0stRAT zlib-framed Windows implants, PlugX side-loaded payload loaders,
          njRAT .NET TCP 1177 clients, and Gamaredon VBS/HTA fast-flux script droppers.
   Classification: TLP:CLEAR
*/

rule ODIN_Gh0stRAT_Magic_Zlib_Implant
{
    meta:
        author = "Odin by Brandefense"
        description = "Detects Gh0stRAT Windows PE implants combining the 5-byte Gh0st packet magic, zlib compression routines, and remote desktop or keylogger manager strings"
        reference = "https://attack.mitre.org/software/S0032/"
        date = "2026-11-21"
        tlp = "CLEAR"
    strings:
        $magic = "Gh0st" ascii
        $zlib_ver = "1.1.4" ascii
        $zlib_hdr = { 78 9C }
        $m1 = "ScreenSpy" ascii wide
        $m2 = "KeyboardManager" ascii wide
        $m3 = "ShellManager" ascii wide
    condition:
        uint16(0) == 0x5A4D and filesize < 5120KB and $magic and ($zlib_ver or $zlib_hdr) and 2 of ($m*)
}

rule ODIN_PlugX_Sideloaded_Payload_Loader
{
    meta:
        author = "Odin by Brandefense"
        description = "Detects PlugX DLL side-loading modules combining characteristic header/config markers with LZNT1 decompression and WinInet or DNS resolution APIs"
        reference = "https://attack.mitre.org/software/S0013/"
        date = "2026-11-21"
        tlp = "CLEAR"
    strings:
        $tag1 = "GULP" ascii
        $tag2 = "PLUG" ascii
        $tag3 = "boot.ldr" ascii wide nocase
        $api1 = "RtlDecompressBuffer" ascii
        $api2 = "VirtualAlloc" ascii
        $net1 = "HttpSendRequestA" ascii
        $net2 = "HttpSendRequestW" ascii
        $net3 = "DnsQuery_A" ascii
    condition:
        uint16(0) == 0x5A4D and filesize < 4096KB and 1 of ($tag*) and $api1 and $api2 and 1 of ($net*)
}

rule ODIN_njRAT_DotNet_Port1177_Client
{
    meta:
        author = "Odin by Brandefense"
        description = "Detects njRAT .NET implants featuring the default pipe-quote field delimiter, firewall bypass command strings, and 0.7d/1177 client artifacts"
        reference = "https://attack.mitre.org/software/S0385/"
        date = "2026-11-21"
        tlp = "CLEAR"
    strings:
        $dotnet = "mscoree.dll" ascii
        $delim = "|'|'|" ascii wide
        $ver1 = "0.7d" ascii wide
        $ver2 = "1177" ascii wide
        $fw1 = "netsh firewall add allowedprogram" ascii wide nocase
        $fw2 = "SEE_MASK_NOZONECHECKS" ascii wide
    condition:
        uint16(0) == 0x5A4D and filesize < 2048KB and $dotnet and $delim and 1 of ($ver*) and 1 of ($fw*)
}

rule ODIN_Gamaredon_VBS_FastFlux_Relay_Dropper
{
    meta:
        author = "Odin by Brandefense"
        description = "Detects Gamaredon-style VBScript and HTA stage-1 droppers polling HTTPS fast-flux relays via XMLHTTP/WinHttp and staging payloads with ADODB.Stream"
        reference = "https://attack.mitre.org/groups/G0047/"
        date = "2026-11-21"
        tlp = "CLEAR"
    strings:
        $sh1 = "WScript.Shell" ascii wide nocase
        $sh2 = "Scripting.FileSystemObject" ascii wide nocase
        $http1 = "MSXML2.XMLHTTP" ascii wide nocase
        $http2 = "WinHttp.WinHttpRequest.5.1" ascii wide nocase
        $stream = "ADODB.Stream" ascii wide nocase
        $exec1 = "wscript.exe" ascii wide nocase
        $exec2 = "mshta.exe" ascii wide nocase
    condition:
        filesize < 1024KB and 1 of ($sh*) and 1 of ($http*) and $stream and 1 of ($exec*)
}
