index=wineventlog sourcetype=WinEventLog:Security EventCode=4625 user=jsmith
SecurityEvent
| where EventID == 4625
| where TargetUserName =~ "jsmith"
SPL 필드 값은 기본적으로 대소문자를 구분하지 않지만, KQL ==는 대소문자를 구분합니다. 대소문자를 통제할 수 없다면 =~(또는 has)를 사용하세요.
index=wineventlog sourcetype=WinEventLog:Security EventCode=4624 earliest=-24h@h latest=now
SecurityEvent
| where TimeGenerated between (ago(24h) .. now())
| where EventID == 4624
Splunk는 @h로 시간을 맞출(snap) 수 있지만 ago(24h)는 맞추지 않습니다. 경계를 정렬해야 한다면 startofday()나 bin()을 사용하고, 성능을 위해 항상 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는 summarize ... by에 대응합니다. KQL에서 집계 결과로 깔끔하게 정렬하려면 집계 컬럼 이름을 명시해야 합니다.
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는 개수를 세고 비율 컬럼까지 추가해 줍니다. KQL top은 정렬해서 N개 행만 가져오므로 먼저 summarize를 해야 합니다.
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은 가장 최근 이벤트 전체를 유지하지만 distinct는 지정한 컬럼만 반환합니다. dedup처럼 전체 행을 유지하려면 summarize arg_max(TimeGenerated, *) by TargetAccount, IpAddress를 사용하세요.
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는 이름 변경과 선택을 한 번에 합니다. 나머지 컬럼을 모두 유지하려면 project-rename을 사용하세요.
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은 extend에, if()는 iff()에 대응합니다. W3CIISLog에서 scStatus 컬럼은 문자열이므로 숫자 비교 전에 toint()로 변환하세요.
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는 빈 구간을 0으로 채우지만 summarize by bin()은 그냥 생략합니다. 기준선 수립에 공백이 중요하다면 KQL에서 make-series를 사용하세요.
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 watchlist가 Splunk lookup 파일을 대신합니다. KQL의 기본 join은 innerunique로 왼쪽을 조용히 중복 제거하므로, kind=inner를 명시하세요.
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()는 dcount()/make_set()에 대응합니다. 한 IP의 고유 사용자 수가 많으면 스프레이, 적으면 브루트포스입니다.
index=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은 보통 조건부 stats로 한 번에 해결하고, KQL은 IP와 계정으로 조인한 두 개의 let 집합으로 쓰는 것이 더 자연스럽습니다.
index=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는 검색 시점에 iplocation으로 위치를 조회하지만 SigninLogs에는 이미 LocationDetails가 들어 있습니다. ResultType은 문자열이므로 0이 아니라 "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
SecurityEvent에서 4740의 Caller Computer Name은 TargetDomainName 컬럼에 들어갑니다. 쿼리를 변환할 때 많은 사람이 걸려 넘어지는 잘 알려진 특이점입니다.
index=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
Splunk Windows add-on은 생성자와 대상을 src_user와 user로 정규화하지만, SecurityEvent는 원래의 SubjectAccount/TargetAccount 구분을 그대로 유지합니다.
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은 -EncodedCommand의 어떤 접두어든 받아들이므로 고정 문자열보다 정규식이 낫습니다. 페이로드는 UTF-16LE Base64이므로, 제거하지 않으면 디코딩된 텍스트에 null 바이트가 보입니다.
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은 전체 경로를 제공하므로 SPL에서는 백슬래시를 이스케이프한 와일드카드가 필요하고, MDE는 순수한 FileName 값을 분리해 주므로 대소문자를 구분하지 않는 in~ 목록에 적합합니다.
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
SPL에서는 split/mvindex로 경로에서 파일 이름을 잘라내야 하고, KQL은 summarize ... by 안에서 그룹화 키를 인라인으로 계산할 수 있습니다.
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
원본 파일 이름으로 일치시키면 이름을 바꾼 복사본도 잡을 수 있습니다. KQL has_any는 전체 단어로 일치하며 큰 테이블에서 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는 사설 대역을 제외하려면 cidrmatch()가 필요하지만, MDE는 RemoteIPType에서 주소를 미리 분류합니다. NOT x IN (...)은 !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는 extract()에 대응합니다. 마지막 두 레이블만 뽑는 단순한 정규식은 co.uk 같은 도메인을 잘못 그룹화하므로, 결과는 단서로 취급하고 상위 도메인별 고유 서브도메인 수를 확인하세요.
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는 EmailDirection과 DeliveryAction을 바로 제공하지만, Splunk 메시지 추적 데이터에서는 자사 도메인을 직접 제외하고 전달 Status를 직접 읽어야 합니다.
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
메시지 추적에는 SPF/DKIM/DMARC 판정이 없으므로 Splunk에서는 게이트웨이나 헤더 로그로 피벗해야 하고, EmailEvents는 이를 AuthenticationDetails에 JSON으로 제공합니다.
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
일치시키기 전에 디코딩하세요(urldecode vs url_decode). 그렇지 않으면 인코딩된 페이로드가 빠져나갑니다. 상태 코드도 확인하세요. 인젝션 페이로드에 대한 200이 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은 stats 전에 별도의 bin 명령으로 시간을 구간화하고, KQL은 summarize ... by 절 안에 bin()을 넣습니다.
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는 규칙 매개변수를 다중값 Parameters{}.Name/Value 필드로 제공하지만, OfficeActivity는 이를 JSON 문자열로 저장하므로 has_any로 검색하거나 parse_json으로 펼칠 수 있습니다.