/*
   Odin by Brandefense  -  Monograph 54 (Operation NightShift) YARA Suite
   4 filesize-bounded structural rules covering fileless C2, rival eviction, SEO cloaking, and Oracle DB-link pivoting.
*/

rule ODIN_NightShift_GitHubC2_Memfd_Loader
{
    meta:
        author = "Odin by Brandefense"
        monograph = "54"
        description = "Detects NightShift fileless Linux C2 loader combining flock mutex locking with Perl/Python memfd_create"
        date = "2026-11-22"
    strings:
        $m1 = "memfd_create" ascii
        $m2 = "inhibit.lock" ascii
        $m3 = "github-c2-agent-dual" ascii
        $m4 = "/proc/self/fd/" ascii
    condition:
        filesize < 128KB and $m1 and ($m2 or $m3) and $m4
}

rule ODIN_NightShift_Rival_Eviction_Watchdog
{
    meta:
        author = "Odin by Brandefense"
        monograph = "54"
        description = "Detects NightShift rival-malware eviction script sweeping processes and crontabs while whitelisting operator markers"
        date = "2026-11-22"
    strings:
        $e1 = ".sysjvd" ascii
        $e2 = "selfok" ascii
        $e3 = "crontab" ascii
        $e4 = ":8899" ascii
    condition:
        filesize < 128KB and 3 of ($e*)
}

rule ODIN_NightShift_PHP_SearchBot_SEO_Cloaker
{
    meta:
        author = "Odin by Brandefense"
        monograph = "54"
        description = "Detects NightShift PHP auto_prepend_file search-bot SEO spam cloaker querying upstream spam feeds"
        date = "2026-11-22"
    strings:
        $c1 = "HTTP_USER_AGENT" ascii
        $c2 = "googlebot" ascii nocase
        $c3 = "bingbot" ascii nocase
        $f1 = "jssnjc.com" ascii nocase
        $f2 = "sysflowus.com" ascii nocase
    condition:
        filesize < 128KB and $c1 and ($c2 or $c3) and ($f1 or $f2)
}

rule ODIN_NightShift_Oracle_EBS_DBLink_Deployer
{
    meta:
        author = "Odin by Brandefense"
        monograph = "54"
        description = "Detects NightShift Oracle E-Business Suite lateral script scheduling OS jobs over database links"
        date = "2026-11-22"
    strings:
        $o1 = "DBMS_SCHEDULER" ascii nocase
        $o2 = "CREATE_JOB" ascii nocase
        $o3 = "EXEC_DDL_STATEMENT@" ascii nocase
    condition:
        filesize < 256KB and all of ($o*)
}
