/*
   Odin by Brandefense - Monograph 30 / 30 YARA Artifact Suite
   Scope: Structural detection rules for Python GCS-to-WordPress pax_cmd deployers,
          injected WordPress theme templates (404.php / functions.php), Behinder-compatible
          AES128/XOR PHP 7/8 twin webshells, and stolen-key / PHP OOM workspace manifests.
   Classification: TLP:CLEAR
*/

rule ODIN_GCS_WordPress_PaxCmd_Deployer_Playbook
{
    meta:
        author = "Odin by Brandefense"
        monograph = "30 / 30"
        classification = "TLP:CLEAR"
        disposition = "HUNT_PRIMARY_OFFENSE_PLAYBOOK"
        description = "Matches Python GCS service-account JWT minting and WordPress pax_cmd theme overwrite deployers"
    strings:
        $oa1 = "oauth2.googleapis.com/token" ascii
        $oa2 = "urn:ietf:params:oauth:grant-type:jwt-bearer" ascii
        $sc1 = "devstorage.full_control" ascii
        $up1 = "uploadType=media" ascii
        $wp1 = "wp-content/themes/" ascii
        $px1 = "pax_cmd" ascii
    condition:
        filesize < 128KB and ($oa1 or $oa2) and $sc1 and $up1 and ($wp1 or $px1)
}

rule ODIN_WordPress_PaxCmd_Injected_Theme_Gate
{
    meta:
        author = "Odin by Brandefense"
        monograph = "30 / 30"
        classification = "TLP:CLEAR"
        disposition = "BLOCK_INJECTED_CMS_TEMPLATE"
        description = "Matches WordPress theme files containing the pax_cmd parameter gate and multi-function execution fallback identifiers"
    strings:
        $gate = "pax_cmd" ascii
        $req = "_REQUEST" ascii
        $fn1 = "passthru" ascii
        $fn2 = "shell_exec" ascii
        $fn3 = "system" ascii
    condition:
        filesize < 256KB and $gate and $req and 2 of ($fn*)
}

rule ODIN_Behinder_AES128_XOR_Twin_PHP_Webshell
{
    meta:
        author = "Odin by Brandefense"
        monograph = "30 / 30"
        classification = "TLP:CLEAR"
        disposition = "BLOCK_ENCRYPTED_PHP_WEBSHELL"
        description = "Matches Behinder-compatible PHP 7 create_function and PHP 8 ob_start/eval encrypted twin webshells"
    strings:
        $c1 = "AES128" ascii
        $c2 = "openssl_decrypt" ascii
        $x1 = "15]" ascii
        $e1 = "create_function" ascii
        $e2 = "ob_start" ascii
    condition:
        filesize < 64KB and $c1 and $c2 and $x1 and ($e1 or $e2)
}

rule ODIN_GCS_SA_Workspace_and_Probe_Artifact
{
    meta:
        author = "Odin by Brandefense"
        monograph = "30 / 30"
        classification = "TLP:CLEAR"
        disposition = "WATCHLIST_OPERATOR_WORKSPACE"
        description = "Matches operator workspace artifacts referencing stolen GCS service-account paths or CVE-2026-109618 calibration tools"
    strings:
        $w1 = "gcs_service_account.json" ascii
        $w2 = "deploy_gcs_webshell" ascii
        $w3 = "application/x-php" ascii
        $c1 = "CVE-2026-109618" ascii
        $c2 = "tools/calibrate.py" ascii
    condition:
        filesize < 512KB and ((2 of ($w*)) or ($c1 and $c2))
}
