/*
   Odin by Brandefense - Monograph 32 / 35 YARA Artifact Suite
   Scope: Bounded structural detection rules for ADCS ESC8 NTLM relay console logs
          (Certipy and Impacket ntlmrelayx output) and Base64-encoded OpenXML .docm
          macro templates.
   Classification: TLP:CLEAR
*/

rule ODIN_ADCS_ESC8_NTLM_Relay_Capture_Log
{
    meta:
        author = "Odin by Brandefense"
        monograph = "32 / 35"
        classification = "TLP:CLEAR"
        disposition = "HUNT_ADCS_ESC8_RELAY_LOG"
        description = "Matches Certipy relay (ESC8) or Impacket ntlmrelayx ADCS attack console logs, using strings these tools print"
        note = "Neither tool logs the POST body (Mode=newreq / CertRequest=); Impacket does not print the certfnsh.asp URL"
    strings:
        // Certipy relay output
        $u1 = "/certsrv/certfnsh.asp" ascii nocase
        $c_t = "(ESC8)" ascii
        $c_r = "Requesting certificate for" ascii
        $c_w = "Wrote certificate and private key" ascii
        // Impacket ntlmrelayx adcsattack output
        $i_g = "Generating CSR" ascii
        $i_ok = "GOT CERTIFICATE! ID" ascii
        $i_p = "Base64-encoded PKCS#12 certificate" ascii
        $i_w = "Writing PKCS#12 certificate" ascii
    condition:
        filesize < 8MB and (($u1 and $c_t and 1 of ($c_r, $c_w)) or ($i_g and 1 of ($i_ok, $i_p, $i_w)))
}

rule ODIN_GoPhish_Base64_Docm_Variable_Template_Artifact
{
    meta:
        author = "Odin by Brandefense"
        monograph = "32 / 35"
        classification = "TLP:CLEAR"
        disposition = "HUNT_GOPHISH_DOCM_TEMPLATE"
        description = "Matches Base64-encoded macro-enabled OpenXML files (such as GoPhish .docm.b64 templates): a Base64 ZIP header at offset 0 and the Base64 form of the uncompressed ZIP entry name word/vbaProject.bin at any of its three alignments"
        note = "Recipient variables sit inside deflated XML parts, so they are not matched; single-line Base64 only"
    strings:
        $pk_b64 = "UEsDB" ascii
        // "word/vbaProject.bin" Base64-encoded at byte offsets 0, 1 and 2
        $vba0 = "d29yZC92YmFQcm9qZWN0LmJpb" ascii
        $vba1 = "dvcmQvdmJhUHJvamVjdC5iaW" ascii
        $vba2 = "3b3JkL3ZiYVByb2plY3QuYmlu" ascii
    condition:
        filesize > 100KB and filesize < 2MB and $pk_b64 at 0 and 1 of ($vba*)
}
