/*
   Odin by Brandefense - Report #19 Deterministic YARA Suite (TLP:CLEAR)
   Covers: BruteRatel C4 Badger Syscall & Malleable Config, Havoc Demon Ekko Sleep-Mask,
           Mythic Apollo/Poseidon Agent Check-In Stubs, and Hashtopolis Distributed GPU Agents.
*/

rule ODIN_BruteRatel_C4_Badger_Config_And_Syscall_Stub
{
    meta:
        author = "Odin by Brandefense"
        description = "Detects BruteRatel C4 Badger telemetry JSON keys paired with indirect-syscall / AMSI-ETW hardware-breakpoint strings"
        reference = "Odin Monograph #19 (19 / 30)"
        classification = "TLP:CLEAR"
        mitre_software = "S1063"
    strings:
        $mz = { 4D 5A }
        $b1 = "\"b_arch\"" ascii wide
        $b2 = "\"c_name\"" ascii wide
        $b3 = "\"d_name\"" ascii wide
        $s1 = "NtAllocateVirtualMemory" ascii wide
        $s2 = "EtwEventWrite" ascii wide
        $s3 = "AmsiScanBuffer" ascii wide
        $s4 = "coffee" ascii wide
    condition:
        filesize < 15MB and (
            ($mz at 0 and 2 of ($b*) and 2 of ($s*)) or
            (all of ($b*) and 2 of ($s*))
        )
}

rule ODIN_Havoc_Demon_Ekko_SleepMask_Implant
{
    meta:
        author = "Odin by Brandefense"
        description = "Detects Havoc Demon implant artifacts chaining SystemFunction032 RC4 memory encryption with NtContinue ROP timer sleep-masking"
        reference = "Odin Monograph #19 (19 / 30)"
        classification = "TLP:CLEAR"
        mitre_technique = "T1027"
    strings:
        $mz = { 4D 5A }
        $e1 = "SystemFunction032" ascii wide
        $e2 = "CreateTimerQueueTimer" ascii wide
        $e3 = "NtContinue" ascii wide
        $h1 = "Demon" ascii wide
        $h2 = "Havoc" ascii wide
        $h3 = "SpoofCallStack" ascii wide
    condition:
        filesize < 12MB and (
            ($mz at 0 and all of ($e*) and 1 of ($h*)) or
            (all of ($e*) and 2 of ($h*))
        )
}

rule ODIN_Mythic_Apollo_Poseidon_Agent_Checkin_Stub
{
    meta:
        author = "Odin by Brandefense"
        description = "Detects Mythic C2 modular agent (Apollo .NET or Poseidon Go) check-in and tasking JSON serialization markers"
        reference = "Odin Monograph #19 (19 / 30)"
        classification = "TLP:CLEAR"
        mitre_technique = "T1071.001"
    strings:
        $m1 = "\"action\":\"checkin\"" ascii wide nocase
        $m2 = "\"action\":\"get_tasking\"" ascii wide nocase
        $m3 = "\"action\":\"post_response\"" ascii wide nocase
        $u1 = "/api/v1.4/agent_message" ascii wide
        $u2 = "ApolloInterop" ascii wide
        $u3 = "poseidon" ascii wide nocase
        $u4 = "mythic_encrypt" ascii wide
    condition:
        filesize < 25MB and (
            (2 of ($m*) and 1 of ($u*)) or
            (1 of ($m*) and 2 of ($u*))
        )
}

rule ODIN_Hashtopolis_Agent_And_Hashcat_Orchestrator
{
    meta:
        author = "Odin by Brandefense"
        description = "Detects Hashtopolis distributed cracking agent scripts or binaries polling /api/server.php for Hashcat task chunks"
        reference = "Odin Monograph #19 (19 / 30)"
        classification = "TLP:CLEAR"
        mitre_technique = "T1110.002"
    strings:
        $api = "/api/server.php" ascii wide
        $a1 = "\"action\":\"login\"" ascii wide
        $a2 = "\"action\":\"getTask\"" ascii wide
        $a3 = "\"action\":\"sendCrack\"" ascii wide
        $a4 = "\"action\":\"sendProgress\"" ascii wide
        $hc1 = "hashcat" ascii wide nocase
        $hc2 = "clientSignature" ascii wide
    condition:
        filesize < 20MB and $api and 2 of ($a*) and 1 of ($hc*)
}
