/*
   WannaCry - rules written during the static analysis of
   e9c82c0f40b82eb9e7fffa7600628fa5dbe6a387829ec13342bb8d75f34ea661
   (x64 launcher.dll + mssecsvc.exe + tasksche.exe, kill switch patched out)
*/

rule WannaCry_Launcher_DLL
{
    meta:
        description = "WannaCry launcher.dll delivered through DoublePulsar: drops and runs C:\\WINDOWS\\mssecsvc.exe"
        sample      = "e9c82c0f40b82eb9e7fffa7600628fa5dbe6a387829ec13342bb8d75f34ea661"
    strings:
        $name   = "launcher.dll" ascii
        $export = "PlayGame" ascii
        $drop   = "mssecsvc.exe" ascii
        $fmt    = "C:\\%s\\%s" ascii
    condition:
        uint16(0) == 0x5A4D and all of them
}

rule WannaCry_Worm_mssecsvc
{
    meta:
        description = "WannaCry worm component (mssecsvc.exe): kill switch URL, service and SMB exploit packets"
    strings:
        $ks      = "iuqerfsodp9ifjaposdfjhgosurijfaewrwergwea" ascii
        $svc     = "mssecsvc2.0" ascii
        $svcname = "Microsoft Security Center (2.0) Service" ascii
        $cmd     = "%s -m security" ascii
        $ipc     = "\\\\%s\\IPC$" ascii
        $ph1     = "__USERID__PLACEHOLDER__" ascii
        $ph2     = "__TREEID__PLACEHOLDER__" ascii
        $task    = "tasksche.exe" ascii
        $tmp     = "qeriuwjhrf" ascii
    condition:
        uint16(0) == 0x5A4D and 5 of them
}

rule WannaCry_Killswitch_Patched
{
    meta:
        description = "mssecsvc.exe with the kill switch check removed (JNZ after InternetOpenUrlA replaced by two NOPs)"
    strings:
        $ks    = "iuqerfsodp9ifjaposdfjhgosurijfaewrwergwea" ascii
        // mov edi,eax / push esi / mov esi,[InternetCloseHandle] / test edi,edi / nop / nop / call esi
        $patch = { 8B F8 56 8B 35 ?? ?? ?? ?? 85 FF 90 90 FF D6 }
    condition:
        uint16(0) == 0x5A4D and all of them
}

rule WannaCry_Installer_tasksche
{
    meta:
        description = "WannaCry installer (tasksche.exe): zip password, mutex, t.wnry loader"
    strings:
        $pw     = "WNcry@2ol7" ascii
        $magic  = "WANACRY!" ascii
        $mutex  = "Global\\MsWinZonesCacheCounterMutexA" ascii
        $export = "TaskStart" ascii
        $icacls = "icacls . /grant Everyone:F /T /C /Q" ascii
        $attrib = "attrib +h ." ascii
        $twnry  = "t.wnry" ascii
        $cwnry  = "c.wnry" ascii
        $btc1   = "13AM4VW2dhxYgXeQepoHkHSQuy6NgaEb94" ascii
        $btc2   = "12t9YDPgwueZ9NyMgw519p7AA8isjr6SMw" ascii
        $btc3   = "115p7UMMngoj1pMvkpHijcRdfJNXj6LrLn" ascii
    condition:
        uint16(0) == 0x5A4D and 5 of them
}

rule WannaCry_Encrypted_Container
{
    meta:
        description = "File starting with the WannaCry container magic (t.wnry or a .WNCRY victim file)"
    condition:
        uint32(0) == 0x414E4157 and uint32(4) == 0x21595243   // "WANACRY!"
}
