/*
   Odin by Brandefense - Report #08 YARA Malware Build-Factory & Workbench Rules
   Classification: TLP:CLEAR
*/


rule ODIN_XWorm56_VBNet_Windows_Update_Helper_Masquerade {
    meta:
        author = "Odin by Brandefense"
        description = "Detects XWorm 5.6 VB.NET source files (incl. /client.vb), /build.bat vbc.exe stagers, and masquerade-string .NET assemblies"
        classification = "TLP:CLEAR"
    strings:
        $m1 = "Windows Update Helper Service" ascii wide
        $m2 = "Windows Update Util Service" ascii wide
        $v1 = "Imports Microsoft.VisualBasic.CompilerServices" ascii wide
        $v2 = "AssemblyFileVersion(\"1\" + \".\" + \"0\" + \".\" + \"0\" + \".\" + \"0\")" ascii wide
        $n1 = "System.Net.Sockets" ascii wide
        $n2 = "System.Security.Cryptography" ascii wide
        $n3 = "System.Management" ascii wide
        $pe_vb = "Microsoft.VisualBasic.CompilerServices" ascii wide
        $b1 = "vbc.exe /target:winexe /out:client.exe" ascii wide nocase
        $b2 = "certutil -urlcache -split -f" ascii wide nocase
    condition:
        filesize < 10MB and (
            (($m1 or $m2) and ($v1 or $v2 or ($pe_vb and $n1 and $n2)))
            or ($v1 and $v2 and $n1 and $n2 and $n3)
            or ($b1 and $b2)
        )
}

rule ODIN_RDP_PerUser_CLSID_InProcServer32_Hijacker {
    meta:
        author = "Odin by Brandefense"
        description = "Detects PowerShell scripts terminating Chrome and registering per-user HKCU CLSID {1f486a52-3cb1-48fd-8f50-b8dc300d9f9d} InProcServer32"
        classification = "TLP:CLEAR"
    strings:
        $clsid = "{1f486a52-3cb1-48fd-8f50-b8dc300d9f9d}" ascii wide nocase
        $reg = "Classes\\CLSID\\" ascii wide nocase
        $inproc = "\\InProcServer32" ascii wide nocase
        $dll1 = "C:\\Users\\Public\\hijack.dll" ascii wide nocase
        $dll2 = "hijack_standalone.dll" ascii wide nocase
    condition:
        filesize < 2MB and $clsid and ($inproc or $reg) and ($dll1 or $dll2)
}

rule ODIN_PowerShell_CSharp_WH_KEYBOARD_LL_Keylogger {
    meta:
        author = "Odin by Brandefense"
        description = "Detects PowerShell Add-Type inline CSharp low-level keyboard hook keyloggers (WH_KEYBOARD_LL)"
        classification = "TLP:CLEAR"
    strings:
        $a1 = "Add-Type" ascii wide nocase
        $h1 = "WH_KEYBOARD_LL" ascii wide
        $h2 = "SetWindowsHookEx" ascii wide
        $h3 = "GetForegroundWindow" ascii wide
        $h4 = "0x0104" ascii wide
        $h5 = "CallNextHookEx" ascii wide
    condition:
        filesize < 2MB and $a1 and $h1 and $h2 and 2 of ($h3, $h4, $h5)
}
