/*
   Odin by Brandefense - Monograph 55 (Operation CampusKey) YARA Suite
   4 filesize-bounded structural rules covering RSA/JWT SSO token forgers, Chisel campus tunnel logs,
   Entra ID ROPC/Graph scripts, and co-hosted ARTEX consoles (zero victim or vendor identifiers).
*/

rule ODIN_CampusKey_RSA_JWT_SSO_Token_Forger
{
    meta:
        author = "Odin by Brandefense"
        monograph = "55"
        description = "Detects custom Python scripts forging RS256-signed SSO handoff JWTs using extracted PEM private keys"
        date = "2026-11-22"
    strings:
        $j1 = "jwt.encode" ascii
        $j2 = "RS256" ascii
        $k1 = "BEGIN RSA PRIVATE KEY" ascii
        $k2 = "BEGIN PRIVATE KEY" ascii
        $k3 = "load_pem_private_key" ascii
    condition:
        filesize < 128KB and $j1 and $j2 and ($k1 or $k2 or $k3)
}

rule ODIN_CampusKey_Chisel_Campus_Service_Tunnel_Log
{
    meta:
        author = "Odin by Brandefense"
        monograph = "55"
        description = "Detects Chisel reverse-tunnel logs forwarding multiple internal Windows and database service ports"
        date = "2026-11-22"
    strings:
        $c1 = "server: session#" ascii nocase
        $c2 = "tun:" ascii nocase
        $p1 = ":1433" ascii
        $p2 = ":445" ascii
        $p3 = ":3389" ascii
        $p4 = ":5985" ascii
        $p5 = ":2383" ascii
    condition:
        filesize < 2MB and ($c1 or $c2) and 3 of ($p*)
}

rule ODIN_CampusKey_Entra_ROPC_and_Graph_Reset_Script
{
    meta:
        author = "Odin by Brandefense"
        monograph = "55"
        description = "Detects scripts combining Entra ID OAuth2 ROPC password grants with Microsoft Graph role or password operations"
        date = "2026-11-22"
    strings:
        $r1 = "login.microsoftonline.com" ascii nocase
        $r2 = "grant_type" ascii
        $r3 = "graph.microsoft.com/v1.0/" ascii nocase
        $g1 = "directoryRoles" ascii
        $g2 = "passwordProfile" ascii
    condition:
        filesize < 256KB and $r1 and $r2 and $r3 and ($g1 or $g2)
}

rule ODIN_CampusKey_ARTEX_Console_and_Task_API
{
    meta:
        author = "Odin by Brandefense"
        monograph = "55"
        description = "Detects exposed ARTEX autonomous testing console bundles and task API definitions"
        date = "2026-11-22"
    strings:
        $a1 = "ARTEX - Autonomous Red-Team Expert" ascii
        $a2 = "/api/v1/tasks" ascii
        $a3 = "artex-swarm-root" ascii
    condition:
        filesize < 5MB and $a1 and ($a2 or $a3)
}
