/*
 * Odin by Brandefense - Monograph 45 / 46 Bounded YARA Suite (Public Edition v1.1)
 * Coverage: Covenant C# credential/ticket models, Covenant SharpSploit & HTTP profile
 *           definitions, sRDI reflective DLL shellcode converters, and NimPlant/PoshC2
 *           listener configuration files.
 * Classification: TLP:CLEAR
 */

rule ODIN_Covenant_Captured_Credential_and_Ticket_Model_Source
{
    meta:
        author = "Odin by Brandefense"
        monograph = "45 / 46"
        description = "Detects Covenant C# credential-harvesting API model classes (CapturedTicketCredential, CapturedHashCredential, CapturedPasswordCredential)"
        tlp = "CLEAR"
        action = "hunt_credential_model_source"
    strings:
        $ns1 = "namespace Covenant.API.Models" ascii wide
        $ns2 = "namespace Covenant.Models.Covenant" ascii wide
        $cls1 = "CapturedTicketCredential" ascii wide
        $cls2 = "CapturedHashCredential" ascii wide
        $cls3 = "CapturedPasswordCredential" ascii wide
        $fld1 = "ServicePrincipalName" ascii wide
        $fld2 = "HashCredentialType" ascii wide
        $fld3 = "TicketByteString" ascii wide
    condition:
        filesize < 256KB and (1 of ($ns*)) and (1 of ($cls*)) and (1 of ($fld*))
}

rule ODIN_Covenant_SharpSploit_Credentials_and_HttpProfile_Config
{
    meta:
        author = "Odin by Brandefense"
        monograph = "45 / 46"
        description = "Detects Covenant SharpSploit credential/lateral-movement task definitions or malleable HttpProfileHeader classes"
        tlp = "CLEAR"
        action = "hunt_covenant_profile_or_task"
    strings:
        $task1 = "SharpSploit.Credentials" ascii wide
        $task2 = "SharpSploit.LateralMovement" ascii wide
        $katz1 = "powerkatz_x64" ascii wide
        $katz2 = "MimikatzCommand" ascii wide
        $prof1 = "class HttpProfileHeader" ascii wide
        $prof2 = "EditHttpProfileHeaderList" ascii wide
        $cov = "Covenant" ascii wide
    condition:
        filesize < 512KB and $cov and ((1 of ($task*) and 1 of ($katz*)) or (1 of ($prof*)))
}

rule ODIN_sRDI_Reflective_DLL_Shellcode_Converter_Suite
{
    meta:
        author = "Odin by Brandefense"
        monograph = "45 / 46"
        description = "Detects sRDI Python and PowerShell reflective DLL shellcode converter function and header flags"
        tlp = "CLEAR"
        action = "hunt_shellcode_converter"
    strings:
        $fn1 = "ConvertTo-Shellcode" ascii wide
        $fn2 = "ShellcodeRDI" ascii wide
        $fn3 = "ConvertToShellcode" ascii wide
        $flag1 = "SRDI_CLEARHEADER" ascii wide
        $flag2 = "HashFunctionName" ascii wide
        $flag3 = "FunctionName" ascii wide
    condition:
        filesize < 256KB and (1 of ($fn*)) and (1 of ($flag*))
}

rule ODIN_NimPlant_and_PoshC2_Listener_Config_Indicators
{
    meta:
        author = "Odin by Brandefense"
        monograph = "45 / 46"
        description = "Detects NimPlant config.toml listener profiles (NimPlant C2 Client) or PoshC2 default self-signed certificate generator parameters (CN=P18055077)"
        tlp = "CLEAR"
        action = "hunt_c2_listener_config"
    strings:
        $nim_ua = "NimPlant C2 Client" ascii wide
        $nim_reg = "registerPath = \"/register\"" ascii wide
        $nim_risk = "riskyMode" ascii wide
        $posh_cn = "P18055077" ascii wide
        $posh_o = "Pajfds" ascii wide
        $posh_ou = "Jethpro" ascii wide
    condition:
        filesize < 256KB and (($nim_ua and ($nim_reg or $nim_risk)) or ($posh_cn and $posh_o and $posh_ou))
}
