/*
   Odin by Brandefense - Monograph 38 / 46 Static YARA Detection Rules
   Scope: Automated secret-harvesting bots, TruffleHog scan outputs, AWS IAM batch validators, and Git/JS token aggregators
*/

rule ODIN_Keyleak_Secret_Scanner_And_Alert_Bot
{
    meta:
        author = "Odin by Brandefense"
        monograph = "38 / 46"
        date = "2026-11-20"
        mitre_attack = "T1552.001, T1528, T1567"
        description = "Matches Python/TOML secret-scanning and alerting bot artifacts paired with cloud or messaging API endpoints"
    strings:
        $k1 = "DetectorName" ascii
        $k2 = "AWS_ACCESS_KEY_ID" ascii
        $k3 = "github_pat_" ascii
        $k4 = "sk_live_" ascii
        $api1 = "api.telegram.org/bot" ascii
        $api2 = "api.github.com" ascii
        $api3 = "GetCallerIdentity" ascii
    condition:
        filesize < 512KB and (2 of ($k*)) and (1 of ($api*))
}

rule ODIN_TruffleHog_Org_Secret_Scan_Output
{
    meta:
        author = "Odin by Brandefense"
        monograph = "38 / 46"
        date = "2026-11-20"
        mitre_attack = "T1552.001"
        description = "Matches structured TruffleHog JSON scan outputs containing verified or unverified credential records"
    strings:
        $th1 = "\"SourceMetadata\"" ascii
        $th2 = "\"DetectorName\"" ascii
        $th3 = "\"DetectorType\"" ascii
        $th4 = "\"Verified\"" ascii
        $det1 = "Postgres" ascii nocase
        $det2 = "MySQL" ascii nocase
        $det3 = "MongoDB" ascii nocase
        $det4 = "Github" ascii nocase
        $det5 = "AWS" ascii nocase
    condition:
        filesize < 10MB and (3 of ($th*)) and (1 of ($det*))
}

rule ODIN_AWS_IAM_Batch_Credential_Validator_Script
{
    meta:
        author = "Odin by Brandefense"
        monograph = "38 / 46"
        date = "2026-11-20"
        mitre_attack = "T1078.004, T1580"
        description = "Matches shell or Python scripts iterating over harvested AWS IAM access keys to test liveness via STS or S3"
    strings:
        $env1 = "AWS_ACCESS_KEY_ID" ascii
        $env2 = "AWS_SECRET_ACCESS_KEY" ascii
        $call1 = "get-caller-identity" ascii
        $call2 = "GetCallerIdentity" ascii
        $call3 = "aws s3 ls" ascii
        $loop1 = "while IFS=" ascii
        $loop2 = "for key in" ascii
        $loop3 = "boto3.client" ascii
    condition:
        filesize < 256KB and $env1 and $env2 and (1 of ($call*)) and (1 of ($loop*))
}

rule ODIN_JS_Bundle_And_GitConfig_Token_Aggregator
{
    meta:
        author = "Odin by Brandefense"
        monograph = "38 / 46"
        date = "2026-11-20"
        mitre_attack = "T1552.001, T1528"
        description = "Matches consolidated .git/config remote credential dumps or JavaScript bundle scraper caches"
    strings:
        $git1 = "[remote \"origin\"]" ascii
        $git2 = "url = https://" ascii
        $git3 = "gitlab.com" ascii nocase
        $git4 = "github.com" ascii nocase
        $js1 = "oauth2:" ascii
        $js2 = "AWS_ACCESS_KEY_ID" ascii
        $js3 = "api.telegram.org/bot" ascii
    condition:
        filesize < 5MB and (($git1 and $git2 and ($git3 or $git4)) or (2 of ($js*)))
}
