James Griffiths – UtopianKnight

Cyber & Information Security Blog – Written with the help of AI (ish)

, ,

Advanced Security Related KQL Queries

Loading

Here are 10 advanced KQL (Kusto Query Language) queries that can be used in Microsoft Sentinel for enhanced security monitoring and threat detection. Each query is designed to address specific security scenarios and provide actionable insights.

1. Detecting Suspicious PowerShell Activity

This query identifies potentially malicious PowerShell commands that could indicate an attack.

SecurityEvent
| where EventID == 4104
| where CommandLine contains "Invoke-Mimikatz" or CommandLine contains "Invoke-Expression"
| project TimeGenerated, Computer, Account, CommandLine

Example Output:

TimeGeneratedComputerAccountCommandLine
2025-05-12 13:00:00PC1user1Invoke-Mimikatz
2025-05-12 12:30:00PC2adminInvoke-Expression -Command

2. Detecting Lateral Movement

This query detects lateral movement attempts by identifying unusual remote desktop protocol (RDP) connections.

SecurityEvent
| where EventID == 4624 and LogonType == 10
| summarize Count = count() by Account, Computer, bin(TimeGenerated, 1h)
| where Count > 5
| order by Count desc

Example Output:

AccountComputerTimeGeneratedCount
user2PC32025-05-12 13:00:0010
adminPC42025-05-12 12:00:008

3. Detecting Data Exfiltration via HTTP

This query identifies potential data exfiltration by monitoring large amounts of data sent over HTTP.

NetworkSession
| where Protocol == "HTTP" and BytesSent > 1000000
| summarize Count = count() by SourceIP, DestinationIP, bin(TimeGenerated, 1h)
| order by Count desc

Example Output:

SourceIPDestinationIPTimeGeneratedCount
192.168.1.210.0.0.22025-05-12 13:00:003
192.168.1.310.0.0.32025-05-12 12:00:002

4. Detecting Unusual VPN Connections

This query identifies unusual VPN connections that could indicate unauthorised access.

VPNLogs
| where Action == "Connect" and Location not in ("US", "UK")
| summarize Count = count() by User, Location, bin(TimeGenerated, 1h)
| order by Count desc

Example Output:

UserLocationTimeGeneratedCount
user3China2025-05-12 13:00:005
user4Russia2025-05-12 12:00:003

5. Detecting Privilege Escalation Attempts

This query identifies attempts to escalate privileges by monitoring changes to user roles.

AuditLogs
| where OperationName == "Add member to role" or OperationName == "Remove member from role"
| summarize Count = count() by TargetResources, bin(TimeGenerated, 1h)
| order by Count desc

Example Output:

TargetResourcesTimeGeneratedCount
user52025-05-12 13:00:004
user62025-05-12 12:00:002

6. Detecting Suspicious Process Execution

This query identifies suspicious processes that could indicate malware or unauthorised activity.

SecurityEvent
| where EventID == 4688
| where NewProcessName contains "cmd.exe" or NewProcessName contains "powershell.exe"
| project TimeGenerated, Computer, Account, NewProcessName

Example Output:

TimeGeneratedComputerAccountNewProcessName
2025-05-12 13:00:00PC5user7cmd.exe
2025-05-12 12:30:00PC6adminpowershell.exe

7. Detecting DDoS Attacks

This query identifies potential Distributed Denial of Service (DDoS) attacks by monitoring high volumes of network traffic.

NetworkSession
| where BytesReceived > 10000000
| summarize Count = count() by DestinationIP, bin(TimeGenerated, 1h)
| order by Count desc

Example Output:

DestinationIPTimeGeneratedCount
10.0.0.42025-05-12 13:00:006
10.0.0.52025-05-12 12:00:004

8. Detecting Suspicious File Modifications

This query identifies suspicious file modifications that could indicate tampering or unauthorised changes.

FileAuditLogs
| where ActionType == "FileModified"
| summarize Count = count() by FileName, bin(TimeGenerated, 1h)
| where Count > 10
| order by Count desc

Example Output:

FileNameTimeGeneratedCount
sensitive.docx2025-05-12 13:00:0015
report.xlsx2025-05-12 12:00:0012

9. Detecting Unauthorised Access to Sensitive Data

This query identifies unauthorised access attempts to sensitive data by monitoring access logs.

DataAccessLogs
| where ResourceType == "SensitiveData" and Action == "Access"
| summarize Count = count() by User, Resource, bin(TimeGenerated, 1h)
| order by Count desc

Example Output:

UserResourceTimeGeneratedCount
user8confidential2025-05-12 13:00:007
user9financial2025-05-12 12:00:005

10. Detecting Anomalous Network Traffic

This query identifies anomalous network traffic patterns that could indicate a security threat.

NetworkTraffic
| where BytesSent > 1000000 or BytesReceived > 1000000
| summarize Count = count() by SourceIP, DestinationIP, bin(TimeGenerated, 1h)
| order by Count desc

Example Output:

SourceIPDestinationIPTimeGeneratedCount
192.168.1.410.0.0.62025-05-12 13:00:004
192.168.1.510.0.0.72025-05-12 12:00:003

These advanced KQL queries provide powerful tools for security analysts to detect and respond to various security threats. By leveraging these queries, analysts can enhance their ability to monitor, detect, and mitigate potential security incidents effectively.