/*
   Odin by Brandefense - Report #01 Host & Webroot YARA Suite (v1.0)
   Targets residual on-disk artifacts modeled in Chapter 5:
     1) Chunked Base64 PowerShell staging markers (_pushp / PSBG_DONE)
     2) Minimal plaintext JSP command webshells matching tjsp.jsp (JSPOK|); Base64-staged files must be decoded before scanning
     3) PowerShell SpecialAccounts\UserList + Advapi32!LogonUser hidden persistence (fin.ps1)
*/

rule ODIN_R01_Webroot_Chunked_PS1_Stager {
    meta:
        author = "Odin by Brandefense"
        date = "2026-11-16"
        version = "1.0"
        tlp = "CLEAR"
        description = "Detects _pushp chunked Base64 staging scripts or output markers in web upload folders"
    strings:
        $m1 = "_pushp" ascii wide
        $m2 = "PSBG_DONE" ascii wide
        $m3 = "FromBase64String" ascii wide nocase
        $m4 = "WriteAllText" ascii wide nocase
        $m5 = "Set-Content" ascii wide nocase
    condition:
        filesize < 64KB and (($m1 and ($m2 or $m3 or $m4 or $m5)) or ($m2 and $m3))
}

rule ODIN_R01_JSP_Cmd_Webshell_Markers {
    meta:
        author = "Odin by Brandefense"
        date = "2026-11-16"
        version = "1.0"
        tlp = "CLEAR"
        description = "Detects minimal plaintext JSP cmd.exe webshells matching tjsp.jsp (JSPOK|); Base64-staged files require decoding before scanning"
    strings:
        $j1 = "JSPOK|" ascii wide
        $j2 = "Runtime.getRuntime().exec" ascii wide
        $j3 = "ProcessBuilder" ascii wide
        $j4 = "cmd.exe /c" ascii wide nocase
        $j5 = "request.getParameter" ascii wide
    condition:
        filesize < 64KB and ($j1 or ($j4 and $j5 and ($j2 or $j3)))
}

rule ODIN_R01_PS1_SpecialAccounts_Hidden_Admin {
    meta:
        author = "Odin by Brandefense"
        date = "2026-11-16"
        version = "1.0"
        tlp = "CLEAR"
        description = "Detects PowerShell stealth local admin scripts hiding accounts via Winlogon SpecialAccounts\\UserList and testing tokens via LogonUser (fin.ps1)"
    strings:
        $s1 = "Winlogon\\SpecialAccounts\\UserList" ascii wide nocase
        $s2 = "advapi32.dll" ascii wide nocase
        $s3 = "LogonUser" ascii wide
        $s4 = "fDenyTSConnections" ascii wide nocase
    condition:
        filesize < 64KB and $s1 and (($s2 and $s3) or $s4)
}
