/*
   Odin by Brandefense - Monograph #16 YARA Suite for Autonomous Hermes Daemons & Co-Hosted ACME Artifacts
   Classification: TLP:CLEAR
   Scope: 4 deterministic structural rules identifying exposed Hermes Curator distillation logs
          (run.json / REPORT.md), raw HTTP retry-exhaustion request dumps and TUI gateway crash logs,
          Kanban SQLite task boards and Cron job schedules, and co-hosted acme.sh ECDSA TLS material,
          while avoiding false positives on bundled OSS skill documentation and npm package files.
*/

rule ODIN_Hermes_Curator_Distillation_Run_And_Report
{
    meta:
        author = "Odin by Brandefense"
        classification = "TLP:CLEAR"
        date = "2026-11-18"
        description = "Detects unattended Hermes Curator LLM skill-consolidation run.json and REPORT.md outputs"
        mitre_attack = "T1213"
    strings:
        $rj1 = "\"auto_transitions\"" ascii
        $rj2 = "\"cron_jobs_rewritten\"" ascii
        $rj3 = "\"skill_manage\"" ascii
        $rp1 = "## Auto-transitions (pure, no LLM)" ascii
        $rp2 = "## LLM consolidation pass" ascii
        $rp3 = "hermes curator restore" ascii
    condition:
        filesize < 20MB and (
            ($rj1 and $rj2 and $rj3) or
            ($rp1 and $rp2 and $rp3)
        )
}

rule ODIN_Hermes_Request_Dump_And_Gateway_Crash
{
    meta:
        author = "Odin by Brandefense"
        classification = "TLP:CLEAR"
        date = "2026-11-18"
        description = "Detects raw Hermes LLM inference request_dump_*.json payloads and tui_gateway_crash.log stack traces"
        mitre_attack = "T1552.001"
    strings:
        $rd1 = "\"session_id\"" ascii
        $rd2 = "# Hermes Agent Persona" ascii
        $rd_r1 = "\"max_retries_exhausted\"" ascii
        $rd_r2 = "\"upstream_timeout\"" ascii
        $gw1 = "hermes-agent/tui_gateway/entry.py" ascii
        $gw2 = "main-thread stack at signal delivery:" ascii
    condition:
        filesize < 20MB and (
            ($rd1 and $rd2 and ($rd_r1 or $rd_r2)) or
            ($gw1 and $gw2)
        )
}

rule ODIN_Hermes_Kanban_Board_And_Cron_Scheduler
{
    meta:
        author = "Odin by Brandefense"
        classification = "TLP:CLEAR"
        date = "2026-11-18"
        description = "Detects Hermes Kanban SQLite board databases, worker task logs, and application Cron job definitions"
        mitre_attack = "T1213"
    strings:
        $cr1 = "\"job_id\"" ascii
        $cr2 = "\"schedule\"" ascii
        $cr3 = "/.hermes/" ascii
        $sq_hdr = "SQLite format 3" ascii
        $kb_ddl1 = "CREATE TABLE kanban_boards" ascii
        $kb_ddl2 = "CREATE TABLE kanban_cards" ascii
        $kb_ddl3 = "CREATE TABLE cron_executions" ascii
        $ko1 = "# Hermes Cron Execution Output" ascii
        $ko2 = "board_slug:" ascii
        $ko3 = "/.hermes/kanban/boards/" ascii
    condition:
        filesize < 20MB and (
            ($cr1 and $cr2 and $cr3) or
            ($sq_hdr and ($kb_ddl1 or $kb_ddl2 or $kb_ddl3)) or
            ($ko1 and $ko2 and $ko3)
        )
}

rule ODIN_Cohosted_Panel_ACME_TLS_Material
{
    meta:
        author = "Odin by Brandefense"
        classification = "TLP:CLEAR"
        date = "2026-11-18"
        description = "Detects exposed acme.sh ECDSA DNS-01 configuration and dual-use CSR files for co-hosted web-panel TLS domains"
        mitre_attack = "T1552.004"
    strings:
        $ac1 = "Le_Domain=" ascii
        $ac2 = "/.acme.sh/" ascii
        $ac3 = "Le_Keylength='ec-256'" ascii
        $csr1 = "[ req_distinguished_name ]" ascii
        $csr2 = "extendedKeyUsage=serverAuth,clientAuth" ascii
        $csr3 = "subjectAltName=DNS:" ascii
    condition:
        filesize < 20MB and (
            ($ac1 and $ac2 and $ac3) or
            ($csr1 and $csr2 and $csr3)
        )
}
