/*
   Odin by Brandefense - Report #09 YARA Workbench & Exploitation Toolkit Ruleset
   Classification: TLP:CLEAR
*/

rule ODIN_Electron_IDE_ASAR_Secret_Extractor {
    meta:
        author = "Odin by Brandefense"
        description = "Detects Node.js scripts scraping cross-platform Electron app.asar and companion CLI CJS bundles for embedded OAuth secrets and spawn-host closures"
        reference = "Report #09 - Host W (address withheld)"
        tlp = "CLEAR"
    strings:
        $b1 = "resources/app.asar" ascii nocase
        $b2 = "resources\\app.asar" ascii nocase
        $b3 = "Contents/Resources/app.asar" ascii nocase
        $io = "readFileSync" ascii
        $s1 = "OAUTH_APP_SECRET" ascii nocase
        $s2 = "OAUTH_CLIENT_SECRET" ascii nocase
        $s3 = "appSecret" ascii
        $s4 = "hostProcessLocalEnv" ascii
        $s5 = "spawnHostProcess" ascii
        $s6 = "tokenByAuthCode" ascii
    condition:
        filesize < 50KB and $io and (1 of ($b*)) and (1 of ($s*))
}

rule ODIN_Rogue_JNDI_LDAP_and_MySQL_JDBC_Blob_Kit {
    meta:
        author = "Odin by Brandefense"
        description = "Detects Python rogue Log4Shell BER LDAP and MySQL protocol BLOB deserialization servers"
        reference = "Report #09 - 202.162.109.5:8081"
        tlp = "CLEAR"
    strings:
        $ldap1 = "javaSerializedData" ascii
        $ldap2 = "ber_tlv(tag, content)" ascii
        $mysql1 = "autoDeserialize" ascii
        $mysql2 = "pkt(seq, data)" ascii
        $mysql3 = "5.7.36-debug" ascii
        $mysql4 = "5.7.36-evilblob" ascii
    condition:
        filesize < 60KB and (($ldap1 and $ldap2) or ($mysql1 and $mysql2) or ($mysql2 and ($mysql3 or $mysql4)))
}

rule ODIN_H2_Database_Create_Alias_Java_RCE {
    meta:
        author = "Odin by Brandefense"
        description = "Detects H2 SQL injection scripts compiling inline Java Runtime.getRuntime().exec aliases"
        reference = "Report #09 - evil1.sql"
        tlp = "CLEAR"
    strings:
        $a1 = "CREATE ALIAS IF NOT EXISTS" ascii nocase
        $a2 = "Runtime.getRuntime().exec" ascii
        $a3 = "java.net.URLEncoder.encode" ascii
    condition:
        filesize < 25KB and all of ($a*)
}

rule ODIN_Rogue_JWKS_and_Cloud_IMDS_SSRF_Redirector {
    meta:
        author = "Odin by Brandefense"
        description = "Detects rogue RS256 JWKS keysets (kid=hktest1) and Python HTTP 301/302/307/308 Cloud IMDS SSRF redirectors"
        reference = "Report #09 - 38.246.253.11:8085"
        tlp = "CLEAR"
    strings:
        $j1 = "\"keys\"" ascii
        $j2 = "\"hktest1\"" ascii
        $j3 = "\"RS256\"" ascii
        $p_base = "BaseHTTPRequestHandler" ascii
        $p_loc_sq = "send_header('Location'" ascii
        $p_loc_dq = "send_header(\"Location\"" ascii
        $r1 = "100.100.100.200" ascii
        $r2 = "169.254.169.254" ascii
        $r3 = "/r-ram" ascii
        $r4 = "/r-meta" ascii
        $r5 = "/r301" ascii
        $r6 = "/r302" ascii
        $r7 = "/r307" ascii
        $r8 = "/r308" ascii
    condition:
        filesize < 30KB and (all of ($j*) or ($p_base and (1 of ($p_loc_*)) and (1 of ($r*))))
}
