/*
   Odin by Brandefense - Monograph 46 / 46 Defensive Self-Audit YARA Suite
   Purpose: Audit web roots, developer staging folders, and backup directories for unencrypted
            quant trading bot .env backups, MCP crypto-wallet tool caches, BIP-39 derivers,
            and plain-text Kubernetes Secret / SecretList YAML dumps.
   Validation: Structural and fixture checks passed; test in staging before production scanning.
*/

rule ODIN_Exposed_Quant_Bot_Env_Backup_Chain {
    meta:
        author = "Odin by Brandefense"
        monograph = "46 / 46"
        date = "2026-11-20"
        mitre_attack = "T1552.001, T1528"
        description = "Detects plain-text quantitative trading bot environment backup files staging exchange API keys and Ethereum private key variables"
    strings:
        $k1 = "BINANCE_API_KEY" ascii nocase
        $k2 = "BINANCE_API_SECRET" ascii nocase
        $k3 = "BINANCE_SECRET" ascii nocase
        $k4 = "ETH_PRIVATE_KEY" ascii nocase
    condition:
        filesize < 256KB and (2 of ($k*))
}

rule ODIN_Exposed_MCP_Crypto_Wallet_Credential_Tool {
    meta:
        author = "Odin by Brandefense"
        monograph = "46 / 46"
        date = "2026-11-20"
        mitre_attack = "T1552.001"
        description = "Detects Model Context Protocol crypto-wallet credential tool modules and wallet SDK handlers exposed in web-accessible directories"
    strings:
        $mcp1 = "@modelcontextprotocol/sdk" ascii
        $mcp2 = "McpServer" ascii
        $mcp3 = "mcp-server" ascii
        $wal1 = "wallet-sdk" ascii
        $wal2 = "mnemonic" ascii nocase
        $wal3 = "generateWallet" ascii
    condition:
        filesize < 512KB and (1 of ($mcp*)) and (2 of ($wal*))
}

rule ODIN_Exposed_BIP39_Wallet_Deriver_And_Notifier {
    meta:
        author = "Odin by Brandefense"
        monograph = "46 / 46"
        date = "2026-11-20"
        mitre_attack = "T1552.001"
        description = "Detects Python or TypeScript BIP-39 hierarchical deterministic wallet derivation scripts paired with multi-chain scanners or Telegram bot dispatchers"
    strings:
        $hd1 = "m/44'/60'/0'/0" ascii
        $hd2 = "m/44'/0'/0'/0" ascii
        $hd3 = "Bip39SeedGenerator" ascii
        $hd4 = "mnemonic_to_seed" ascii
        $sc1 = "eth_getBalance" ascii
        $sc2 = "getBalance" ascii
        $sc3 = "api.telegram.org/bot" ascii
        $sc4 = "sendMessage" ascii
    condition:
        filesize < 512KB and (1 of ($hd*)) and (2 of ($sc*))
}

rule ODIN_Unencrypted_Kubernetes_Secret_Manifest_Dump {
    meta:
        author = "Odin by Brandefense"
        monograph = "46 / 46"
        date = "2026-11-20"
        mitre_attack = "T1552.001, T1552.007"
        description = "Detects unencrypted Kubernetes Secret or SecretList YAML exports saved on disk with Base64 data maps"
    strings:
        $api = "apiVersion: v1" ascii
        $kind1 = "kind: Secret" ascii
        $kind2 = "kind: SecretList" ascii
        $kind3 = "kind: List" ascii
        $type1 = "type: Opaque" ascii
        $type2 = "kubernetes.io/service-account-token" ascii
        $type3 = "kubernetes.io/dockerconfigjson" ascii
        $data = /\n[ \t]*data:/
    condition:
        filesize < 10MB and $api and (1 of ($kind*)) and (1 of ($type*)) and $data
}
