/*
   Odin by Brandefense - Monograph 69 YARA Suite
   4 filesize-bounded structural rules covering unencrypted ACME ECDSA/PKCS8 private keys,
   unpacked SVR4 newc cpio BusyBox initramfs images, micro-VM host-mount configuration templates,
   and SSRF metadata / OOB callback verification scripts.
*/

rule ODIN_Unencrypted_ACME_ECDSA_or_PKCS8_Key
{
    meta:
        author = "Odin by Brandefense"
        monograph = "69"
        description = "Detects unencrypted EC or PKCS8 PEM private keys when scans are scoped to ACME state directories"
        date = "2026-11-25"
    strings:
        $pem1 = "-----BEGIN EC PRIVATE KEY-----" ascii
        $pem2 = "-----BEGIN PRIVATE KEY-----" ascii
    condition:
        filesize < 64KB and ($pem1 or $pem2)
}

rule ODIN_Custom_Cpio_Newc_Initramfs_BusyBox_Archive
{
    meta:
        author = "Odin by Brandefense"
        monograph = "69"
        description = "Detects unpacked SVR4 newc cpio initial-ramdisk archives bundling BusyBox and an init entrypoint"
        date = "2026-11-25"
    strings:
        $magic = "070701" ascii
        $b1 = "bin/busybox" ascii
        $b2 = "dev/console" ascii
        $b3 = "sbin/init" ascii
        $b4 = "init" ascii
    condition:
        filesize < 60MB and $magic at 0 and $b1 and $b2 and ($b3 or $b4)
}

rule ODIN_MicroVM_Host_Bind_Mount_and_Egress_Config
{
    meta:
        author = "Odin by Brandefense"
        monograph = "69"
        description = "Detects micro-VM sandbox configuration files combining guest boot descriptors with host-path bind mounts or egress route rules"
        date = "2026-11-25"
    strings:
        $vm1 = "boot_source" ascii
        $vm2 = "vcpu_count" ascii
        $vm3 = "initramfs" ascii
        $mnt1 = "host_path" ascii
        $mnt2 = "virtio-fs" ascii
        $net1 = "egress_policy" ascii
        $net2 = "169.254.169.254" ascii
    condition:
        filesize < 1MB and 2 of ($vm*) and (($mnt1 or $mnt2) or ($net1 or $net2))
}

rule ODIN_SSRF_Metadata_and_OOB_Callback_Test_Script
{
    meta:
        author = "Odin by Brandefense"
        monograph = "69"
        description = "Detects Python or shell verification scripts pairing cloud instance metadata endpoints with OOB callback correlation parameters"
        date = "2026-11-25"
    strings:
        $http1 = "urllib.request" ascii
        $http2 = "requests.get" ascii
        $http3 = "aiohttp" ascii
        $imds1 = "169.254.169.254" ascii
        $imds2 = "X-aws-ec2-metadata-token" ascii
        $oob1 = "correlation-id" ascii
        $oob2 = "/poll?id=" ascii
    condition:
        filesize < 512KB and 1 of ($http*) and 1 of ($imds*) and 1 of ($oob*)
}
