# 60 DAYS DETECTION BACKLOG FOR A COMPUTER
ExternalApiType=Event_DetectionSummaryEvent ComputerName=
#
# 60 DAYS DETECTION BACKLOG FOR COMPUTERS SCOPE
ExternalApiType=Event_DetectionSummaryEvent
| where like (ComputerName,”UK%”)
cql-enum
enum-configbuild
earliest=-7d event_platform=win event_simpleName=SensorHeartbeat ComputerName=
| fields timestamp aid ComputerName ConfigBuild
| stats first(timestamp) AS firstSeen by aid, ComputerName, ConfigBuild
| eval firstSeen=firstSeen/1000
| convert ctime(firstSeen)
| stats values(firstSeen) values(ConfigBuild) by aid, ComputerName
| sort + ComputerName
cql-exe
exe-lolbas-1
event_simpleName=ProcessRollup2 AND FileName="bcdedit.exe"
| where like(ComputerName,"DC%")
| table aid, ComputerName, ParentBaseFileName, ImageFileName, CommandLine
exe-lolbas-2
event_simpleName=ProcessRollup2 AND FileName="msedge.exe"
| WHERE like(ComputerName,"DC%") AND like(CommandLine,"%msedge.exe%network.mojom.NetworkService%")
| table aid, ComputerName, ParentBaseFileName, ImageFileName, CommandLine
# FilePath and FileName randomized
# Pattern found from the commandline detected / blocked
ComputerName= sourcetype=ImageHashV6-v02
| where like (ImageFileName,"%\ProgramData\%Driver%")
| table _time, MD5HashData, FileName, FilePath
ComputerName= event_simpleName=ProcessRollup2 AND( FileName="msedge.exe" OR FileName="chrome.exe" OR FileName="firefox.exe")
| table aid, ComputerName, ParentBaseFileName, ImageFileName, CommandLine
| stats count by ParentBaseFileName
cql-fs-io
fs-conns-usb
CQL 1 : get connected usb media
# the 'RemovableMediaVolumeMounted' events confirm the volume name and drive letter
ComputerName= event_simpleName=RemovableMedia* OR event_simpleName IN (DcUsbDeviceDisconnected,DcUsbDeviceConnected)
| table _time aid event_simpleName ComputerName VolumeDriveLetter DiskParentDeviceInstanceId DeviceManufacturer DeviceProduct DeviceInstanceId DeviceSerialNumber VolumeName
| rename DiskParentDeviceInstanceId as "Device Hardware/Vendor ID", VolumeDriveLetter as "Volume Drive Letter", ComputerName as "Hostname", aid as AID, DeviceInstanceId as "Device Hardware/Vendor ID (External HDD)", DeviceSerialNumber as "Serial Number"
| sort _time
CQL 2 : get files written to usb media
ComputerName= (((event_simpleName=DcUsbDeviceConnected AND DevicePropertyDeviceDescription="USB Mass Storage Device" AND DeviceInstanceId="USB*" )) OR (event_simpleName="*written*" AND DiskParentDeviceInstanceId="USB*"))| eval matchfield=coalesce(DeviceInstanceId,DiskParentDeviceInstanceId) | table _time, ComputerName, event_simpleName, DeviceManufacturer, DeviceProduct, DeviceSerialNumber, DiskParentDeviceInstanceId, TargetFileName
# INITIAL ACCESS / ONE TARGET / Files downloaded from the Internet
#
# Useful for: the Zone identifier stores whether the file was downloaded from the internet.
# Type 3 Zone Identifiers show the URL the file was downloaded from.
#
ComputerName= event_simpleName=MotwWritten ZoneIdentifier_decimal=3
| table _time event_simpleName FileName Zone* HostUrl ReferrerUrl
fs-dl-files-bulk
# INITIAL ACCESS (ia) / ON MANY ASSETS (bulk) / File downloaded (pdf, word, tar, zip, etc.)
#
# Description: Useful to determine the scope targeted that may require further investigations.
# For a file related to a phishing campain, if the client (used for the download) is a web browser, should have an ADS with Zone.identifier = 3. If the client (used for the download) is the “outlook heavy client”, it remains to check.
#
# Event simple name for file: PngFileWritten, PdfFileWritten RtfFileWritten MSXlsxFileWritten MSDocxFileWritten
# RarFileWritten SevenZipFileWritten TarFileWritten ZipFileWritten NewExecutableWritten PeFileWritten
#
FileName= event_simpleName=PdfFileWritten
| rename ContextTimeStamp_decimal as writtenTime
| eval fileSizeMB=round(((Size_decimal/1024)/1024),2)
| table ComputerName FileName FilePath writtenTime fileSizeMB
| convert ctime(writtenTime)
cql-net
net-conns-krb
ComputerName= event_platform=win event_simpleName=UserLogon
| eval LogonType = case(LogonType_decimal==2 , "Interactive, ex: typing user name and password on Windows logon prompt", LogonType_decimal==3, "Network;access from the network", LogonType_decimal==4, "Batch,processes executing on behalf of a user; ex : scheduled task", LogonType_decimal==5, "Service; service configured to log on as a user started by the Service Control Manage.",LogonType_decimal==7, "Workstation Unlocked", LogonType_decimal==8, "Network_ClearText; ex : IIS", LogonType_decimal==9, "New_Credentials", LogonType_decimal==10, "RemoteInteractive; remote connection using Terminal Services or Remote Desktop",LogonType_decimal==11, "Cached Interactive ; network credentials stored locally used, not DC", LogonType_decimal==12, "Cached Remote Interactive", LogonType_decimal==13, "Cached Unlock")
| table _time ComputerName UserName ClientComputerName LogonDomain RemoteAddressIP4 LogonType_decimal LogonType
| sort - _time
net-conns-ssh-lin
event_platform=lin event_simpleName=CriticalEnvironmentVariableChanged, EnvironmentVariableName IN (SSH_CONNECTION, USER)
| eventstats list(EnvironmentVariableName) as EnvironmentVariableName,list(EnvironmentVariableValue) as EnvironmentVariableValue by aid, ContextProcessId_decimal
| eval tempData=mvzip(EnvironmentVariableName,EnvironmentVariableValue,":")
| rex field=tempData "SSH_CONNECTION\:((?<clientIP>\d+\.\d+\.\d+\.\d+)\s+(?<rPort>\d+)\s+(?<serverIP>\d+\.\d+\.\d+\.\d+)\s+(?<lPort>\d+))"
| rex field=tempData "USER\:(?<userName>.*)"
| where isnotnull(clientIP)
| search NOT clientIP IN (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 127.0.0.1)
| iplocation clientIP
| lookup local=true aid_master aid OUTPUT Version as osVersion, Country as sshServerCountry
| fillnull City, Country, Region value="-"
| table _time aid ComputerName sshServerCountry osVersion serverIP lPort userName clientIP rPort City Region Country
| where isnotnull(userName)
| sort +ComputerName, +_time
| search NOT clientIP IN (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 127.0.0.1)
net-conns-teamviewer
(RPort=5938 OR RPort=5939) event_simpleName=NetworkConnectIP4
| where cidrmatch("192.168.110.0/24",LocalIP) AND like(ComputerName,"DC%")
| table _time, ComputerName, LPort, LocalIP, RemoteIP, RPort
| sort _time
net-conns-smb
RPort=445 event_simpleName=NetworkConnectIP4
| where cidrmatch("192.168.110.0/24",LocalIP) AND like(ComputerName,"DC%")
| table _time, ComputerName, LPort, LocalIP, RemoteIP, RPort
| sort _time
net-conns-www
ComputerName= event_simpleName=NetworkConnectIP4
| where not (cidrmatch("192.168.0.0/16",RemoteIP) OR cidrmatch("172.16.0.0/12",RemoteIP) OR cidrmatch("10.0.0.0/8",RemoteIP) OR cidrmatch("224.0.0.0/4",RemoteIP))
| table _time, LPort, LocalIP, RemoteIP, RPort
ComputerName= sourcetype="DnsRequest*"
| where not like(DomainName,"%in-addr.arpa")
| dedup DomainName
| table DomainName
net-scans-internal
event_simpleName=networkConnectIP4 NOT ContextBaseFileName IN ("Ntrtscan.exe", "ACCS FTP.exe", "CSFalcon*", "rpcbind") RemoteAddressIP4 IN ("10.*", "172.*", "192.168.*")
| where RPort < 1024
| eval mitre=Tactic."/".Technique
| stats dc(RPort) as number_rport values(RPort) as remote_port_list values(mitre) by ContextBaseFileName
| where number_rport > 5