/*
   Odin by Brandefense - Report #06 YARA AiTM Keylogger, Site Cloner & M365 Enumeration Rules
   Classification: TLP:CLEAR
*/

rule ODIN_AiTM_SendBeacon_PreSubmit_Keylogger_JS {
    meta:
        author = "Odin by Brandefense"
        description = "Detects pre-submit DOM keydown streamer flushing partial/abandoned inputs via navigator.sendBeacon"
        sha256_specimen = "dc89160b8501065099a69bc6a8f34ce085774878387d071f4e249eebb57a757b"
        classification = "TLP:CLEAR"
    strings:
        $s1 = "navigator.sendBeacon(" ascii
        $s2 = "keepalive:true" ascii
        $s3 = "<DEL>" ascii
        $s4 = "beforeunload" ascii
        $s5 = "document.activeElement" ascii
        $s6 = "type==='password'" ascii
    condition:
        filesize < 64KB and 4 of ($s*)
}

rule ODIN_AiTM_CORS_Keystroke_Receiver_Python {
    meta:
        author = "Odin by Brandefense"
        description = "Detects Python BaseHTTPRequestHandler CORS-wildcard keystroke sink and redirector"
        sha256_specimen = "629fd5033240e77684003b632c3b247671ac2043a4e87ae7f420feb836551a45"
        classification = "TLP:CLEAR"
    strings:
        $c1 = "BaseHTTPRequestHandler" ascii
        $c2 = "Access-Control-Allow-Origin" ascii
        $c3 = "SITE = '/root/phish/site'" ascii
        $c4 = "redirect.txt" ascii
        $c5 = "timeout = 5" ascii
        $c6 = "k.js" ascii
    condition:
        filesize < 64KB and $c1 and $c2 and 2 of ($c3, $c4, $c5, $c6)
}

rule ODIN_AiTM_OneClick_Login_Site_Cloner_Shell {
    meta:
        author = "Odin by Brandefense"
        description = "Detects bash login-portal cloner and relative/protocol-relative asset rewriter (switch_site.sh)"
        sha256_specimen = "7da269d7b5b55d409b71702dc53d4329bbeb0afb0540ab3d98896c3625836c54"
        classification = "TLP:CLEAR"
    strings:
        $b1 = "#!/bin/bash" ascii
        $b2 = "(src|href)=\"[^\"]+\"" ascii
        $b3 = "^(data:|javascript:|#|mailto:|tel:)" ascii
        $b4 = "woff2?|ttf|eot|json|map" ascii
        $b5 = "abs=\"$PROTO://$HOST$u\"" ascii
    condition:
        filesize < 64KB and 4 of ($b*)
}

rule ODIN_M365_GetCredentialType_And_Lateral_Auth_Toolkit {
    meta:
        author = "Odin by Brandefense"
        description = "Detects Python M365 GetCredentialType account/federation enumerators and multi-service credential stuffers"
        sha256_specimen = "24146b8cbbafc57995e77c7a65e799fc471374b27c06a7ac931a7282c2c9cfaa"
        classification = "TLP:CLEAR"
    strings:
        $o1 = "login.microsoftonline.com/common/GetCredentialType" ascii
        $o2 = "isFidoSupported" ascii
        $o3 = "IfExistsResult" ascii
        $o4 = "PrefCredential" ascii
        $l1 = "/service/preauth" ascii
        $l2 = "/j_spring_security_check" ascii
        $l3 = "smtplib.SMTP_SSL" ascii
    condition:
        filesize < 64KB and ((3 of ($o*)) or (all of ($l*)))
}
