// Odin by Brandefense - Monograph 71 // Hunts patched PowerMTA daemon replacements, automated ESP installers, suppression SQL imports, and unapproved SMTP egress. let Lookback = 7d; let ApprovedMailRelayHosts = dynamic(["mta-relay-01.corp.example", "esp-admin-01.corp.example"]); let EspAndRotationScripts = dynamic([ "mailwizzinstaller7.sh", "interspireinstaller6.sh", "mumarainstaller6.sh", "sparkmail.sh", "trocadominio-2015.sh", "mwchangedomain.sh", "iemchangedomain.sh", "changeip.sh", "/setupxmpta/" ]); let PatchedMtaAndEspInstallerProcesses = DeviceProcessEvents | where Timestamp >= ago(Lookback) | where not(DeviceName in~ (ApprovedMailRelayHosts)) | where ( (FileName in~ ("rpm", "yum", "dnf", "cp", "install", "mv", "chmod") and ProcessCommandLine has_any ("PowerMTA5.0.rpm", "/patch/usr/sbin/pmtad", "/patch/usr/sbin/pmtahttpd")) or (FileName in~ ("bash", "sh") and ProcessCommandLine has_any (EspAndRotationScripts)) or (FileName in~ ("mysql", "mariadb") and ProcessCommandLine has_any ("mw_email_blacklist.sql", "email_banned_emails.sql", "mumara_email_blacklist")) ) | project Timestamp, DeviceName, AccountName, SignalType = "PatchedMtaOrEspKitExec", Detail = ProcessCommandLine; let PatchedDaemonAndLoaderFileWrites = DeviceFileEvents | where Timestamp >= ago(Lookback) | where not(DeviceName in~ (ApprovedMailRelayHosts)) | where ActionType in ("FileCreated", "FileModified", "FileRenamed") | where ( (FolderPath == "/usr/sbin" and FileName in ("pmtad", "pmtahttpd")) or FileName in~ ( "ioncube_loader_lin_5.6.so", "ioncube_loader_lin_5.3.so", "mw_email_blacklist.sql", "email_banned_emails.sql", "PowerMTA5.0.rpm" ) ) | project Timestamp, DeviceName, AccountName = InitiatingProcessAccountName, SignalType = "MtaDaemonOrSuppressionWrite", Detail = strcat(InitiatingProcessFileName, " -> ", FolderPath, "/", FileName); let UnapprovedSmtpEgress = DeviceNetworkEvents | where Timestamp >= ago(Lookback) | where not(DeviceName in~ (ApprovedMailRelayHosts)) | where InitiatingProcessFileName in~ ("pmtad", "pmtahttpd", "php", "php-fpm", "curl", "wget") | where RemotePort in (25, 465, 587, 2525) | project Timestamp, DeviceName, AccountName = InitiatingProcessAccountName, SignalType = "UnapprovedSmtpEgress", Detail = strcat(InitiatingProcessFileName, " -> ", RemoteIP, ":", tostring(RemotePort)); union PatchedMtaAndEspInstallerProcesses, PatchedDaemonAndLoaderFileWrites, UnapprovedSmtpEgress | summarize FirstSeen = min(Timestamp), LastSeen = max(Timestamp), EventCount = count(), Signals = make_set(SignalType, 6), SampleDetails = make_set(Detail, 5) by DeviceName, AccountName | order by LastSeen desc