CQURE Hacks #81: The Ultimate KQL Query Toolkit for Threat Hunters and Security Analysts
I’m going to show you eight essential queries that cover everything from daily baselining to advanced threat hunting. For each query, I’ll explain what it does, when to run it, and why it matters. Let’s jump right in.”
QUERY 1: Baseline Traffic Overview
First up – the morning routine. This daily traffic overview is what I run first thing every morning. It gives me a 10,000-foot view of what’s happening in my environment.
Here’s why this matters: you can’t spot anomalies if you don’t know your normal. This query shows me daily traffic volume, success rates, failed requests, intrusion attempts, and unique IPs. Look at these key outputs: Total Requests tells me if we’re experiencing unusual volume spikes. Success Rate shows if our services are healthy. Intrusion Attempts – this is my immediate attention flag.
I run this at 9 AM daily. If I see intrusion attempts doubled from yesterday, that’s my first investigation priority. Notice how I’m using a 1-day bin – perfect for daily trends. The key insight here: establish your baseline FIRST, then hunt for deviations.
QUERY 2: Top Attack Sources
Now, when Query 1 shows increased intrusions, I immediately pivot to this: Top Attack Sources. This isn’t a daily query – it’s an incident response query.
Look at what this gives me: the most active malicious IPs, when they first appeared, their last activity, attack types they’re using, target ports, and protocols. This is blocklist gold. See this ‘AttackTypes’ column using make_set()? That shows me all the different attack methods a single IP is using.
I run this after detecting increased intrusion activity. The output directly feeds into my firewall rules and threat intelligence. Notice I’m taking the top 20 – focus on the most impactful threats first. This query turns data into actionable intelligence for my response team.
QUERY 3: Failed Authentication Analysis
This is my go-to for suspicious authentication activity. Failed logins happen, but patterns of failed logins tell a story.
I run this during suspicious activity periods or when monitoring high-value accounts. Watch how I’m grouping by hour – perfect for spotting brute force patterns. The threshold here is key: FailureCount > 3. Adjust this based on your environment.
Look at these columns: Distinct Sources and Distinct Targets. If I see one source hitting many targets, that’s password spraying. Many sources hitting one target? That’s a targeted brute force. The CommonUserAgents field using take_any() gives me samples without overwhelming the output. This query finds what simple alerts miss.
QUERY 4: Port Scanning Detection
Port scanning is recon activity – attackers mapping your network. This continuous monitoring query looks for hosts scanning multiple ports in short timeframes.
The magic is in the time window: 15-minute bins. Why 15 minutes? It’s long enough to catch sustained scans but short enough to alert quickly. The port list here includes common scanning and backdoor ports – customize this for your environment.
Key threshold: PortsScanned >= 3. Scanning 3+ different ports in 15 minutes is suspicious. This query gives early warning – often before actual attacks begin. Run this continuously or every 30 minutes. It’s your early detection system.
QUERY 5: Botnet Command & Control Detection
This is advanced threat hunting. Botnets call home – we want to catch those calls.
I run this during proactive threat hunting or when investigating compromised systems. Look at the statistics here: median payload, 95th and 99th percentiles. Botnet C2 traffic often has distinctive payload sizes.
Grouping by User_Agent is key – many botnets have unique agents. The BotnetActivity > 3 threshold filters noise. This query isn’t just counting – it’s profiling. The percentile calculations help distinguish normal traffic from command traffic. Use this to find compromised systems before they cause damage.
QUERY 6: Protocol Anomaly Detection
This is my favorite for finding clever attackers. Protocol anomalies often indicate evasion techniques or data exfiltration.
The concept: combine protocol and port into a single field, then look for unusual patterns. HTTP on port 2222? SSH on port 443? Those get attention.
The join here compares normal traffic with known malicious traffic. The SuspicionScore uses a case statement to categorize risk. Notice how I’m looking for rare combinations (RequestCount < 10 and UniqueSources > 5) – that’s often discovery activity.
Run this weekly to establish what’s normal, then monitor deviations. This catches what signature-based detection misses.
QUERY 7: User Agent Analysis
Automated tools leave fingerprints in user agents. This query finds scanners and automated tools.
I run this regularly – at least weekly. The has_any operator looks for known tools: nmap, Nikto, curl, etc. But here’s the insight: not all tool usage is malicious. That’s why I calculate SuccessRate and IntrusionRate.
See a user agent with high tool usage but zero intrusions? Probably legitimate security testing. High tool usage with high intrusion rate? That’s an active attacker. The make_set() functions give me context without overwhelming detail. This query separates legitimate scanning from malicious reconnaissance.
QUERY 8: Internal Hosts Communicating Externally
Egress monitoring – catching data leaving your network. This shows which internal IPs are talking to external destinations.
The IP filter startswith “192.168” catches internal IPs – adjust for your subnet. The SuspicionIndex is clever: it weights intrusion attempts most heavily, then unique external IPs, then connection count.
Look for internal servers talking to many external IPs, or workstations sending large payloads outside. The PortsUsed and ProtocolsUsed columns using strcat_array() make the output readable. This catches data exfiltration, beaconing, and unauthorized external communications. Run this daily for critical assets.
Key takeaways
And there you have it – eight KQL queries that should be in every security analyst’s toolkit. Remember, the goal isn’t to write new queries every day, but to have reliable, reusable queries that let you focus on analysis, not syntax.
To recap: start with your daily baseline, drill down on attack sources when needed, monitor authentication patterns, watch for port scanning, hunt for botnets, check protocol anomalies, analyze user agents, and monitor egress traffic.
These queries work together as a system. Save them, customize them for your environment, and run them regularly. The time you save on typing is time you gain for thinking.
If you found this helpful, hit like and subscribe for more practical security content. What queries do you always keep handy? Share in the comments below. Thanks for watching, and stay secure!

Want to learn more about Threat Hunting?
Join our FREE live webinar:
Modern Threat Hunting with AI: 10 Skills for Detecting What Others Miss
Discover how AI is transforming threat hunting, learn advanced detection techniques, explore real-world attack scenarios, and gain practical skills that can help you uncover threats that traditional approaches often miss.
Register for free:
https://cqureacademy.com/webinar-modern-threat-hunting-with-ai-10-skills-for-detecting-what-others-miss/
Want to know more?
The post CQURE Hacks #81: The Ultimate KQL Query Toolkit for Threat Hunters and Security Analysts appeared first on CQURE Academy.