// Odin by Brandefense - Report #03 YARA Detection Ruleset (TLP:CLEAR)

rule ODIN_R3_Linux_Deploy_GitHubC2_Memfd_Guard {
    meta:
        author = "Odin by Brandefense"
        description = "Detects deploy_ghc2.sh fileless memfd GitHub-C2 bootstrapper and 3-tier guard script"
        classification = "TLP:CLEAR"
    strings:
        $s1 = "/var/tmp/.systemd/inhibit" ascii
        $s2 = "/usr/local/lib/.cache-sync" ascii
        $s3 = "github-c2-agent-dual" ascii
        $s4 = "flock -n" ascii
        $s5 = "PR_SET_MM_EXE_FILE" ascii
    condition:
        filesize < 50KB and 3 of ($s*)
}

rule ODIN_R3_Linux_Exclusive_Turf_Eviction_Watchdog {
    meta:
        author = "Odin by Brandefense"
        description = "Detects excl_evict4.sh rival-implant quarantine watchdog"
        classification = "TLP:CLEAR"
    strings:
        $w1 = "/tmp/.excl_q" ascii
        $w2 = "z_73570" ascii
        $w3 = "kinsing|kdevtmpfsi|.ksmd_" ascii
        $w4 = ".sysjvd/.va" ascii
    condition:
        filesize < 60KB and 3 of ($w*)
}

rule ODIN_R3_PHP_AutoPrepend_Crawler_SEO_Cloaker {
    meta:
        author = "Odin by Brandefense"
        description = "Detects z_prepend.php, wbi_v10.php, and .wp_inc.php rootless auto_prepend_file crawler SEO cloakers"
        classification = "TLP:CLEAR"
    strings:
        $p1 = "define('Z_73570_SEO', 1);" ascii
        $p2 = "HTTP_ACCEPT_LANGUAGE" ascii
        $p3 = "/feed.php?js=1" ascii
        $p4 = "/feed.php?domain=%s&path=%s" ascii
        $p5 = "xxe_debug" ascii
        $p6 = "wl-main/_xxe_inject/jssnjc" ascii
        $p7 = "xxe_off" ascii
    condition:
        filesize < 30KB and 2 of ($p*)
}

rule ODIN_R3_Oracle_DBLink_DDL_Lateral_Pivot {
    meta:
        author = "Odin by Brandefense"
        description = "Detects Oracle DBMS_UTILITY.EXEC_DDL_STATEMENT, Java wrapper, and DBMS_SCHEDULER lateral pivot scripts without firing on routine DBA queries"
        classification = "TLP:CLEAR"
    strings:
        $hi1 = "DBMS_UTILITY.EXEC_DDL_STATEMENT@" ascii nocase
        $hi2 = "CREATE OR REPLACE DIRECTORY TMPX9" ascii nocase
        $hi3 = "COMPILE JAVA SOURCE NAMED \"PWN" ascii nocase
        $hi4 = "APPS.P9ZZ@" ascii nocase
        $hi5 = "P9RUN" ascii nocase
        $hi6 = "JZEBS1" ascii
        $ax1 = "'TMPX9'" ascii nocase
        $ax2 = "WPOLL" ascii
        $ax3 = "session_privs@" ascii nocase
        $ax4 = "user_scheduler_job_run_details" ascii nocase
        $ax5 = "java_update" ascii nocase
        $ax6 = "krxYMRN97D" ascii nocase
        $st1 = "utl_file.fopen" ascii nocase
        $st2 = "DBMS_SCHEDULER.CREATE_JOB" ascii nocase
        $st3 = "gv$instance@" ascii nocase
        $st4 = "dual@TO_" ascii nocase
        $st5 = "dba_db_links" ascii nocase
    condition:
        filesize < 40KB and (1 of ($hi*) or (1 of ($ax*) and 2 of ($ax*, $st*)) or 3 of ($st*))
}

rule ODIN_R3_Campaign_Monetization_Config_And_Stager {
    meta:
        author = "Odin by Brandefense"
        description = "Host-side file hunt for TLS-wrapped Kryptex account krxYMRN97D, Monero wallet, and custom pool proxy configs"
        classification = "TLP:CLEAR"
    strings:
        $m1 = "krxYMRN97D" ascii nocase
        $m2 = "89v9DbfLx49f6kuziDnExs6BHGyVV2UanFvMhcAU386sDKtT8eBqAwfhsSmxPwYSJT1r5bQyRgbpGHY741w5gMnk4McHFL3" ascii
        $m3 = "wa.theshyc.xyz:5556" ascii nocase
    condition:
        filesize < 200KB and 1 of ($m*)
}
