index=wineventlog sourcetype=WinEventLog:Security EventCode=4625 user=jsmith
SecurityEvent
| where EventID == 4625
| where TargetUserName =~ "jsmith"
SPL-Feldwerte sind standardmäßig nicht case-sensitiv, KQL == dagegen schon; nutze =~ (oder has), wenn du die Groß-/Kleinschreibung nicht kontrollierst.
index=wineventlog sourcetype=WinEventLog:Security EventCode=4624 earliest=-24h@h latest=now
SecurityEvent
| where TimeGenerated between (ago(24h) .. now())
| where EventID == 4624
Splunk kann die Zeit mit @h runden; ago(24h) rundet nicht, also nutze startofday() oder bin(), wenn du ausgerichtete Grenzen brauchst, und filtere aus Performancegründen immer zuerst nach TimeGenerated.
index=wineventlog sourcetype=WinEventLog:Security EventCode=4625
| stats count by user, src_ip
| sort - count
SecurityEvent
| where EventID == 4625
| summarize Count = count() by TargetAccount, IpAddress
| sort by Count desc
stats ... by entspricht summarize ... by; KQL braucht einen expliziten Spaltennamen für das Aggregat, wenn du sauber danach sortieren willst.
index=sysmon EventCode=1
| top limit=10 Image
index=sysmon EventCode=1
| rare limit=10 Image
DeviceProcessEvents
| summarize Count = count() by FileName
| top 10 by Count desc
DeviceProcessEvents
| summarize Count = count() by FileName
| top 10 by Count asc
SPL top/rare zählen und fügen dir eine Prozentspalte hinzu; KQL top sortiert nur und nimmt N Zeilen, daher musst du zuerst summarize ausführen.
index=wineventlog sourcetype=WinEventLog:Security EventCode=4624 Logon_Type=10
| dedup user, src_ip
| table _time, user, src_ip, host
SecurityEvent
| where EventID == 4624 and LogonType == 10
| distinct TargetAccount, IpAddress, Computer
dedup behält das gesamte jüngste Event, distinct liefert nur die aufgeführten Spalten; nutze summarize arg_max(TimeGenerated, *) by TargetAccount, IpAddress, um wie bei dedup vollständige Zeilen zu behalten.
index=wineventlog sourcetype=WinEventLog:Security EventCode=4624
| rename src_ip AS SourceIP, user AS Account
| table _time, Account, SourceIP, host
SecurityEvent
| where EventID == 4624
| project TimeGenerated, Account = TargetAccount, SourceIP = IpAddress, Computer
KQL project benennt um und wählt aus in einem Schritt; nutze project-rename, wenn du alle anderen Spalten behalten willst.
index=web sourcetype=access_combined
| eval is_error=if(status>=500, 1, 0), uri_len=len(uri)
| stats sum(is_error) AS errors avg(uri_len) AS avg_uri_len by clientip
W3CIISLog
| extend IsError = iff(toint(scStatus) >= 500, 1, 0), UriLen = strlen(csUriStem)
| summarize Errors = sum(IsError), AvgUriLen = avg(UriLen) by cIP
eval entspricht extend und if() entspricht iff(); in W3CIISLog ist die Spalte scStatus ein String, also wandle sie vor numerischen Vergleichen mit toint() um.
index=wineventlog sourcetype=WinEventLog:Security EventCode=4625 earliest=-24h
| timechart span=1h count AS failed_logons
SecurityEvent
| where TimeGenerated > ago(24h) and EventID == 4625
| summarize FailedLogons = count() by bin(TimeGenerated, 1h)
| render timechart
timechart füllt leere Buckets mit null, summarize by bin() lässt sie einfach weg; nutze in KQL make-series, wenn Lücken für das Baselining wichtig sind.
index=wineventlog sourcetype=WinEventLog:Security EventCode=4624
| lookup privileged_accounts.csv user OUTPUT role
| where isnotnull(role)
| table _time, user, role, src_ip, host
let PrivAccounts = _GetWatchlist('PrivilegedAccounts')
| project TargetUserName = tostring(SearchKey), Role = tostring(Role);
SecurityEvent
| where EventID == 4624
| join kind=inner PrivAccounts on TargetUserName
| project TimeGenerated, TargetUserName, Role, IpAddress, Computer
Sentinel-Watchlists ersetzen Splunk-Lookup-Dateien; denk daran, dass der Standard-Join in KQL innerunique ist und die linke Seite stillschweigend dedupliziert, also gib kind=inner explizit an.
index=wineventlog sourcetype=WinEventLog:Security EventCode=4625 earliest=-1h
| stats count AS failures dc(user) AS distinct_users values(user) AS targeted by src_ip
| where failures > 20
| sort - failures
SecurityEvent
| where TimeGenerated > ago(1h) and EventID == 4625
| summarize Failures = count(), DistinctUsers = dcount(TargetAccount), Targeted = make_set(TargetAccount, 20) by IpAddress
| where Failures > 20
| sort by Failures desc
dc()/values() entsprechen dcount()/make_set(); eine hohe Zahl unterschiedlicher Benutzer von einer IP deutet auf Spraying, eine niedrige auf Brute-Force.
AuthentifizierungT1110.001index=wineventlog sourcetype=WinEventLog:Security (EventCode=4625 OR EventCode=4624) earliest=-1h
| eval fail_time=if(EventCode=4625, _time, null()), success_time=if(EventCode=4624, _time, null())
| stats count(fail_time) AS failures min(fail_time) AS first_fail count(success_time) AS successes max(success_time) AS last_success by src_ip, user
| where failures >= 10 AND successes > 0 AND last_success > first_fail
| convert ctime(first_fail) ctime(last_success)
let Failures = SecurityEvent
| where TimeGenerated > ago(1h) and EventID == 4625
| summarize FailCount = count(), FirstFail = min(TimeGenerated) by IpAddress, TargetAccount;
SecurityEvent
| where TimeGenerated > ago(1h) and EventID == 4624
| summarize LastSuccess = max(TimeGenerated) by IpAddress, TargetAccount
| join kind=inner Failures on IpAddress, TargetAccount
| where FailCount >= 10 and LastSuccess > FirstFail
| project IpAddress, TargetAccount, FailCount, FirstFail, LastSuccess
SPL löst das meist in einem Durchlauf mit bedingtem stats, in KQL liest es sich natürlicher als zwei let-Mengen, die über IP und Konto gejoint werden.
AuthentifizierungT1078.004index=o365 sourcetype=o365:management:activity Workload=AzureActiveDirectory Operation=UserLoggedIn earliest=-24h
| iplocation ClientIP
| stats dc(Country) AS countries values(Country) AS country_list values(ClientIP) AS ips by UserId
| where countries > 1
SigninLogs
| where TimeGenerated > ago(24h) and ResultType == "0"
| extend Country = tostring(LocationDetails.countryOrRegion)
| summarize Countries = dcount(Country), CountryList = make_set(Country), IPs = make_set(IPAddress), Apps = make_set(AppDisplayName) by UserPrincipalName
| where Countries > 1
Splunk geolokalisiert zur Suchzeit mit iplocation, während SigninLogs bereits LocationDetails enthält; ResultType ist ein String, also vergleiche mit "0", nicht mit 0.
index=wineventlog sourcetype=WinEventLog:Security EventCode=4740
| stats count values(Caller_Computer_Name) AS caller_computers by user
| sort - count
SecurityEvent
| where EventID == 4740
| summarize Lockouts = count(), CallerComputers = make_set(TargetDomainName) by TargetAccount
| sort by Lockouts desc
In SecurityEvent landet der Caller Computer Name von 4740 in der Spalte TargetDomainName, eine bekannte Eigenheit, über die man beim Übersetzen leicht stolpert.
AuthentifizierungT1136.001index=wineventlog sourcetype=WinEventLog:Security EventCode=4720
| table _time, host, src_user, user
| rename src_user AS created_by, user AS new_account
SecurityEvent
| where EventID == 4720
| project TimeGenerated, Computer, CreatedBy = SubjectAccount, NewAccount = TargetAccount
Das Splunk Windows Add-on normalisiert Ersteller und Ziel zu src_user und user, während SecurityEvent die rohe Aufteilung SubjectAccount/TargetAccount beibehält.
index=sysmon EventCode=1 (Image="*\\powershell.exe" OR Image="*\\pwsh.exe") (CommandLine="* -e *" OR CommandLine="* -ec *" OR CommandLine="*-enc*")
| table _time, host, User, ParentImage, CommandLine
DeviceProcessEvents
| where TimeGenerated > ago(7d)
| where FileName in~ ("powershell.exe", "pwsh.exe")
| where ProcessCommandLine matches regex @"(?i)\s-(e|ec|en\w*)\s"
| project TimeGenerated, DeviceName, AccountName, InitiatingProcessFileName, ProcessCommandLine
PowerShell akzeptiert jedes Präfix von -EncodedCommand, daher schlägt eine Regex feste Strings; die Payload ist UTF-16LE-Base64, dekodierter Text zeigt also Null-Bytes, wenn du sie nicht entfernst.
index=sysmon EventCode=1 (ParentImage="*\\winword.exe" OR ParentImage="*\\excel.exe" OR ParentImage="*\\powerpnt.exe" OR ParentImage="*\\outlook.exe") (Image="*\\cmd.exe" OR Image="*\\powershell.exe" OR Image="*\\wscript.exe" OR Image="*\\cscript.exe" OR Image="*\\mshta.exe" OR Image="*\\rundll32.exe")
| table _time, host, User, ParentImage, Image, CommandLine
DeviceProcessEvents
| where InitiatingProcessFileName in~ ("winword.exe", "excel.exe", "powerpnt.exe", "outlook.exe")
| where FileName in~ ("cmd.exe", "powershell.exe", "pwsh.exe", "wscript.exe", "cscript.exe", "mshta.exe", "rundll32.exe", "regsvr32.exe")
| project TimeGenerated, DeviceName, AccountName, InitiatingProcessFileName, FileName, ProcessCommandLine
Sysmon liefert vollständige Pfade, daher braucht SPL Wildcards mit escapten Backslashes, während MDE reine FileName-Werte liefert, die gut zu einer nicht case-sensitiven in~-Liste passen.
index=sysmon EventCode=1 earliest=-7d
| eval parent=lower(mvindex(split(ParentImage, "\\"), -1)), child=lower(mvindex(split(Image, "\\"), -1))
| stats count dc(host) AS hosts values(host) AS host_list by parent, child
| where count < 5
| sort count
DeviceProcessEvents
| where TimeGenerated > ago(7d)
| summarize Count = count(), Hosts = dcount(DeviceName), HostList = make_set(DeviceName, 10) by Parent = tolower(InitiatingProcessFileName), Child = tolower(FileName)
| where Count < 5
| sort by Count asc
In SPL musst du den Dateinamen mit split/mvindex aus dem Pfad herausschneiden; KQL kann Gruppierungsschlüssel direkt in summarize ... by berechnen.
index=sysmon EventCode=1 (Image="*\\certutil.exe" OR OriginalFileName="CertUtil.exe") (CommandLine="*urlcache*" OR CommandLine="*verifyctl*" OR CommandLine="*-decode*")
| table _time, host, User, ParentImage, CommandLine
DeviceProcessEvents
| where FileName =~ "certutil.exe" or ProcessVersionInfoOriginalFileName =~ "CertUtil.exe"
| where ProcessCommandLine has_any ("urlcache", "verifyctl", "decode")
| project TimeGenerated, DeviceName, AccountName, InitiatingProcessFileName, ProcessCommandLine
Das Matching auf den ursprünglichen Dateinamen erwischt umbenannte Kopien; KQL has_any matcht ganze Begriffe und ist auf großen Tabellen deutlich schneller als contains.
index=sysmon EventCode=3 Initiated=true NOT DestinationPort IN (80, 443, 53, 22, 25, 88, 123, 389, 445, 3389)
| where NOT (cidrmatch("10.0.0.0/8", DestinationIp) OR cidrmatch("172.16.0.0/12", DestinationIp) OR cidrmatch("192.168.0.0/16", DestinationIp))
| stats count dc(host) AS hosts values(Image) AS processes by DestinationPort
| where hosts < 3
| sort count
DeviceNetworkEvents
| where TimeGenerated > ago(7d)
| where ActionType == "ConnectionSuccess" and RemoteIPType == "Public"
| where RemotePort !in (80, 443, 53, 22, 25, 88, 123, 389, 445, 3389)
| summarize Count = count(), Hosts = dcount(DeviceName), Processes = make_set(InitiatingProcessFileName, 10) by RemotePort
| where Hosts < 3
| sort by Count asc
Splunk braucht cidrmatch(), um private Bereiche auszuschließen, während MDE Adressen in RemoteIPType vorklassifiziert; NOT x IN (...) wird zu !in.
index=sysmon EventCode=22
| eval qlen=len(QueryName)
| where qlen > 60
| rex field=QueryName "(?<domain>[^.]+\.[^.]+)$"
| stats dc(QueryName) AS unique_queries max(qlen) AS max_len values(Image) AS processes by domain, host
| where unique_queries > 50
| sort - unique_queries
DnsEvents
| where TimeGenerated > ago(24h) and SubType == "LookupQuery"
| where strlen(Name) > 60
| extend Domain = extract(@"([^.]+\.[^.]+)$", 1, Name)
| summarize UniqueQueries = dcount(Name), MaxLen = max(strlen(Name)), Clients = make_set(ClientIP, 10) by Domain
| where UniqueQueries > 50
| sort by UniqueQueries desc
rex entspricht extract(); die naive Regex auf die letzten zwei Labels gruppiert Domains wie co.uk falsch, also behandle Ergebnisse als Hinweise und prüfe die Zahl eindeutiger Subdomains pro übergeordneter Domain.
index=mail sourcetype=ms:o365:reporting:messagetrace earliest=-24h NOT SenderAddress="*@corp.example.com"
| stats dc(RecipientAddress) AS recipients values(Subject) AS subjects values(Status) AS statuses by SenderAddress, FromIP
| where recipients > 20
| sort - recipients
EmailEvents
| where TimeGenerated > ago(24h) and EmailDirection == "Inbound"
| summarize Recipients = dcount(RecipientEmailAddress), Subjects = make_set(Subject, 5), Actions = make_set(DeliveryAction) by SenderFromAddress, SenderIPv4
| where Recipients > 20
| sort by Recipients desc
EmailEvents liefert dir EmailDirection und DeliveryAction direkt, während du bei Message-Trace-Daten in Splunk deine eigene Domain ausschließen und den Zustell-Status selbst auswerten musst.
index=mail sourcetype=ms:o365:reporting:messagetrace Status=Delivered (Subject="*invoice*" OR Subject="*payment*" OR Subject="*wire transfer*")
| table _time, SenderAddress, FromIP, RecipientAddress, Subject
EmailEvents
| where TimeGenerated > ago(7d) and EmailDirection == "Inbound" and DeliveryAction == "Delivered"
| where Subject has_any ("invoice", "payment", "wire transfer")
| extend Auth = parse_json(AuthenticationDetails)
| where tostring(Auth.DMARC) =~ "fail" or tostring(Auth.SPF) =~ "fail"
| project TimeGenerated, SenderFromAddress, SenderIPv4, RecipientEmailAddress, Subject, AuthenticationDetails
Message Trace enthält keine SPF/DKIM/DMARC-Ergebnisse, daher pivotierst du in Splunk zu Gateway- oder Header-Logs, während EmailEvents sie als JSON in AuthenticationDetails bereitstellt.
index=web sourcetype=access_combined
| eval decoded=urldecode(uri)
| where match(decoded, "(?i)(union\s+(all\s+)?select|or\s+1=1|sleep\(|benchmark\(|information_schema|' or ')")
| stats count values(status) AS statuses values(uri_path) AS paths by clientip
| sort - count
W3CIISLog
| where TimeGenerated > ago(24h)
| extend Q = url_decode(csUriQuery)
| where Q matches regex @"(?i)(union\s+(all\s+)?select|or\s+1=1|sleep\(|benchmark\(|information_schema|' or ')"
| summarize Requests = count(), Statuses = make_set(scStatus), Paths = make_set(csUriStem, 10) by cIP
| sort by Requests desc
Dekodiere vor dem Matching (urldecode vs. url_decode), sonst rutschen kodierte Payloads durch; prüfe auch die Statuscodes, denn eine 200 auf eine Injection-Payload ist wichtiger als eine 403.
index=o365 sourcetype=o365:management:activity Workload IN (SharePoint, OneDrive) Operation=FileDownloaded earliest=-24h
| bin _time span=1h
| stats dc(ObjectId) AS files values(ClientIP) AS ips by _time, UserId
| where files > 100
| sort - files
OfficeActivity
| where TimeGenerated > ago(24h)
| where OfficeWorkload in ("SharePoint", "OneDrive") and Operation == "FileDownloaded"
| summarize Files = dcount(OfficeObjectId), IPs = make_set(ClientIP, 10) by UserId, bin(TimeGenerated, 1h)
| where Files > 100
| sort by Files desc
SPL teilt die Zeit mit einem separaten bin-Befehl vor stats in Buckets, während KQL bin() direkt in die summarize ... by-Klausel setzt.
index=o365 sourcetype=o365:management:activity Workload=Exchange (Operation=New-InboxRule OR Operation=Set-InboxRule OR Operation=UpdateInboxRules)
| search Parameters{}.Name IN (DeleteMessage, MoveToFolder, ForwardTo, RedirectTo, ForwardAsAttachmentTo)
| table _time, UserId, ClientIP, Operation, Parameters{}.Name, Parameters{}.Value
OfficeActivity
| where OfficeWorkload == "Exchange"
| where Operation in~ ("New-InboxRule", "Set-InboxRule", "UpdateInboxRules")
| where Parameters has_any ("DeleteMessage", "MoveToFolder", "ForwardTo", "RedirectTo", "ForwardAsAttachmentTo")
| project TimeGenerated, UserId, ClientIP, Operation, Parameters
Splunk stellt die Regelparameter als mehrwertige Felder Parameters{}.Name/Value bereit, während OfficeActivity sie als JSON-String speichert, den du mit has_any durchsuchen oder mit parse_json auflösen kannst.