What Are the Best Splunk Queries for Cybersecurity Monitoring?

Imagine you are a security analyst at 2 a.m. An alert lights up your screen. Your heart races. Is this a real attack, or just another false alarm? You open Splunk and type a single query. Within seconds, you see the full story: a user failing login 87 times from three different countries in five minutes. You block the account, notify the team, and stop a breach before it begins. That is the power of a great Splunk query. Splunk is the go-to platform for security teams because it collects logs from everywhere: firewalls, servers, cloud services, endpoints, and more. But raw logs are just noise. The real value comes from asking the right questions. The best Splunk queries turn chaos into clarity. They detect threats fast, reduce false positives, and give you proof to act. In this guide, we share 20 of the most effective, real-world Splunk queries used by SOC teams every day. These are not random searches. They are proven, beginner-friendly, and explained in plain English. Whether you are new to Splunk or a seasoned pro, these queries will level up your security monitoring.

Nov 6, 2025 - 12:49
Nov 6, 2025 - 15:44
 7
What Are the Best Splunk Queries for Cybersecurity Monitoring?

Table of Contents

Why Splunk Queries Are Critical for Cybersecurity

Cybersecurity is a data problem. Attackers leave traces in logs: failed logins, strange file access, odd network traffic. But most organizations generate millions of log events per day. You cannot read them all.

Splunk queries let you ask precise questions like:

  • Who is trying to log in too many times?
  • Is anyone downloading files at midnight?
  • Why is this server talking to Russia?

A good query finds the needle in the haystack. A great query finds it before the attacker strikes again.

Understanding SPL: Splunk’s Search Language

SPL (Search Processing Language) is how you talk to Splunk. It is simple, powerful, and works like a pipeline.

Every query has three parts:

  • Search: What data to look at (e.g., index=security)
  • Pipe (|): Send results to the next command
  • Commands: Filter, count, group, or chart (stats, where, timechart)

Example:

index=security EventCode=4625 
| stats count by user 
| where count > 20

This finds users with more than 20 failed logins.

You do not need to be a coder. Just learn a few commands, and you are ready.

20 Must-Know Splunk Queries for Security Monitoring

1. Brute Force Login Attempts

index=security sourcetype=WinEventLog:Security EventCode=4625 
| stats count by Account_Name 
| where count > 15 
| sort -count

Detects users with too many failed logins. Adjust 15 based on your environment.

2. Successful Login After Many Failures

index=security (EventCode=4625 OR EventCode=4624) 
| transaction Account_Name maxspan=5m 
| where eventcount > 10 AND searchmatch(EventCode=4624)

Finds brute-force attacks that eventually work. transaction groups related events.

3. Traffic to High-Risk Countries

index=firewall action=allowed dest_country IN ("CN", "RU", "IR") 
| stats count by src_ip, dest_ip 
| sort -count

Flags allowed connections to countries you do not trust.

4. Malware Beaconing (Regular Outbound Calls)

index=proxy 
| stats count, values(url) by src_ip 
| where count > 40 
| eval calls_per_min = round(count / 60, 2) 
| where calls_per_min > 0.9 AND calls_per_min < 1.1

Detects malware checking in every minute. Look for near-perfect timing.

5. Ransomware: Rapid File Renaming

index=endpoint sourcetype="WinEventLog:Microsoft-Windows-Sysmon/Operational" EventCode=11 
| stats count, values(TargetFilename) by Computer 
| where count > 150 
| sort -count

Uses Sysmon to catch processes renaming hundreds of files fast.

6. Privilege Escalation with sudo

index=linux sourcetype=linux_secure "sudo:" 
| regex _raw="sudo:.*COMMAND=.*(passwd|useradd|chown)" 
| stats count, values(user) by host, _raw

Tracks dangerous sudo commands that modify users or permissions.

7. Cleartext Passwords in Logs

index=* (password OR pwd OR passwd) 
| regex _raw=".*(password|pwd)=[^[:space:]]{4,}.*" 
| table _time, host, sourcetype, _raw

Finds logs accidentally storing passwords. Fix the app, not just the alert.

8. Web Shell Access

index=web url=*.php (url=*cmd* OR url=*shell* OR url=*eval* OR url=*system*) 
| stats count, values(clientip) by url 
| where count > 2

Detects access to common web shell files or dangerous PHP functions.

9. Lateral Movement via RDP

index=security EventCode=4624 logon_type=10 
| stats dc(WorkstationName) as sources, count by Account_Name 
| where sources > 3 
| sort -sources

Logon type 10 is RDP. Multiple sources using one account suggests credential reuse.

10. DNS Tunneling (Large Queries)

index=dns 
| stats sum(length(query)) as bytes, count by query, src_ip 
| where bytes > 1200 
| table src_ip, query, bytes, count

Attackers hide data in long DNS subdomains. This finds suspicious queries.

11. Rare or New Executables

index=security EventCode=4688 
| stats count, earliest(_time) as first_seen by ProcessName, Computer 
| eventstats avg(count) as avg, stdev(count) as std 
| where count < (avg - 2*std) OR first_seen > relative_time(now(), "-7d")

Finds processes running rarely or for the first time.

12. PowerShell Download Cradles

index=security sourcetype=WinEventLog:PowerShell/Operational EventCode=4104 
| regex ScriptBlockText=".*(WebClient|DownloadFile|IEX|Invoke-Expression).*" 
| table _time, Computer, User, ScriptBlockText

Catches one-line PowerShell scripts that download and run code.

13. Account Used from Many IPs

index=security EventCode=4624 
| stats dc(src_ip) as ip_count, values(src_ip) by Account_Name 
| where ip_count > 6 
| sort -ip_count

One user logging in from many IPs may mean stolen credentials.

14. New Service Installation

index=security EventCode=7045 
| stats values(ServiceName), values(ImagePath) by Computer 
| where ImagePath="*temp*" OR ImagePath="*downloads*" 
| table _time, Computer, ServiceName, ImagePath

New services from user-writable folders are often malicious.

15. Excessive Failed VPN Logins

index=vpn "fail" OR "denied" 
| stats count by user, src_ip 
| where count > 25 
| sort -count

Detects VPN brute-force or misconfigured clients.

16. Unusual Outbound Ports

index=firewall action=allowed dest_port NOT IN (80, 443, 53, 22, 3389) 
| stats count by src_ip, dest_port 
| where count > 50 
| sort -count

Most traffic uses standard ports. Others may be C2 or exfiltration.

17. Fileless Malware (Script in Memory)

index=endpoint EventCode=4688 ProcessName="*powershell.exe" 
| regex CommandLine=".*-WindowStyle Hidden.*|.*-EncodedCommand.*" 
| stats count by Computer, CommandLine

PowerShell running hidden or with encoded commands is suspicious.

18. Data Exfiltration via HTTP POST

index=proxy method=POST bytes_out>100000 
| stats sum(bytes_out) as total, values(url) by src_ip 
| where total > 500000 
| sort -total

Large outbound POSTs may mean data upload to attacker servers.

19. Login Outside Business Hours

index=security EventCode=4624 
| eval hour=strftime(_time, "%H") 
| where hour < 7 OR hour > 18 
| stats count by Account_Name, hour 
| where count > 5

Logins at 3 a.m. may be legitimate, but worth checking.

20. Disabled Antivirus

index=endpoint "disabled" OR "stopped" "antivirus" OR "defender" 
| stats values(_raw) by host, sourcetype 
| table _time, host, _raw

Finds events where AV is turned off, often before an attack.

Quick Reference Table of All Queries

Threat Type Key SPL Command Data Source Recommended Threshold
Brute Force EventCode=4625 | stats count by user Windows Security 15+ failures
Successful Brute Force transaction | searchmatch(4624) Windows 10+ events
High-Risk Geo dest_country IN (...) Firewall Any allowed
Beaconing eval calls_per_min Proxy ~1/min
Ransomware EventCode=11 | stats count Sysmon 150+ files
sudo Abuse regex COMMAND=(passwd|...) Linux Any match
Password in Logs regex password=[^ ]{4,} All Any
Web Shell url=*cmd* OR *eval* Web 2+ hits
RDP Lateral logon_type=10 | dc(src) Windows 3+ sources
DNS Tunnel sum(length(query)) > 1200 DNS 1200+ bytes
Rare Exe eventstats stdev 4688 Outlier
PowerShell Download "IEX" OR "WebClient" PowerShell Any
Account from Many IPs dc(src_ip) > 6 Windows 6+ IPs
New Service ImagePath="*temp*" 7045 Any
VPN Brute "fail" | stats count VPN 25+ fails
Unusual Ports dest_port NOT IN (80,443...) Firewall 50+ hits
Fileless Malware -EncodedCommand 4688 Any
Exfiltration method=POST bytes_out>100000 Proxy 500KB+
Off-Hours Login hour < 7 OR hour > 18 Windows 5+ logins
AV Disabled "disabled" "antivirus" Endpoint Any

How to Use and Customize These Queries

Follow these steps:

  • Paste the query into Splunk’s search bar.
  • Set time: Use “Last 15 minutes” for alerts, “Last 7 days” for tuning.
  • Change index: Replace index=security with your index name.
  • Save as alert: Click Save As > Alert. Set trigger: “number of results > 0”.
  • Tune thresholds: Run over a week. Adjust counts to reduce noise.
  • Add exclusions: NOT src_ip="192.168.1.*" for internal IPs.

Pro Tip: Use | tstats for speed on large data: | tstats count where index=security EventCode=4625 by _time span=1m

Best Practices for Writing Splunk Security Queries

  • Start narrow: index=prod sourcetype=web, not index=*.
  • Filter early: Put where right after index.
  • Use stats to summarize, not table * .
  • Include _time in results for context.
  • Test with | head 50 to see sample output.
  • Add comments: # Brute force detection.
  • Schedule alerts every 1 to 5 minutes for real-time.
  • Link alerts to dashboards for context.
  • Review and tune weekly.

Conclusion

The best Splunk queries are simple, fast, and focused. They catch real attacks without drowning you in alerts. The 20 queries in this guide cover the most common threats: brute force, malware, privilege abuse, data theft, and more.

Start with one. Test it. Turn it into an alert. Then add another. Soon, you will have a full security monitoring program built on Splunk.

Because in cybersecurity, the right question at the right time can stop an attack cold. And with Splunk, you always have the answer.

What does SPL stand for?

SPL means Search Processing Language. It is Splunk’s query language for searching and analyzing data.

Do I need to code to use these queries?

No. Just copy, paste, and tweak. Learn a few commands like stats and where.

Where do I run Splunk queries?

In the Splunk web UI, go to the Search & Reporting app and use the search bar.

How often should I run these as alerts?

Every 1 to 5 minutes for critical threats. Every 15 to 60 minutes for others.

What index should I search?

Use the index where your logs are stored. Common: security, main, firewall.

Will these work in Splunk Cloud?

Yes. All queries work the same in Splunk Cloud and on-premises.

How do I reduce false alerts?

Add filters: NOT user="admin", or use baselines with eventstats.

What is the transaction command?

It groups related events (like failed and successful logins) by a common field.

Should I install Sysmon?

Yes. It adds detailed process and file events that Windows misses by default.

How do I save a query to a dashboard?

Run the search, click Save As > Dashboard Panel, and pick a dashboard.

Can Splunk detect unknown threats?

Yes. Behavioral queries (rare processes, beaconing) catch zero-days.

What is tstats and when to use it?

tstats is faster on data models. Use it for high-volume sources.

How do I find my sourcetypes?

Run: | tstats count where index=* by sourcetype

Is it safe to search for passwords?

Only with proper access. Never export full results with real credentials.

Can I schedule queries automatically?

Yes. Save as Report or Alert and set a schedule.

Where can I learn more SPL?

Visit docs.splunk.com or take Splunk Fundamentals 1 (free).

What is Splunk Enterprise Security?

An app that adds correlation rules, risk scoring, and incident tools on top of core Splunk.

Do these queries work on Linux or cloud?

Yes. Change sourcetypes: linux_secure, aws:cloudtrail, etc.

How do I export query results?

Click Export > CSV, JSON, or PDF after running a search.

Where can I get more queries?

Splunkbase: ESCU, Security Essentials, or vendor TAs (Palo Alto, Cisco).

What's Your Reaction?

like

dislike

love

funny

angry

sad

wow

Ishwar Singh Sisodiya I am focused on making a positive difference and helping businesses and people grow. I believe in the power of hard work, continuous learning, and finding creative ways to solve problems. My goal is to lead projects that help others succeed, while always staying up to date with the latest trends. I am dedicated to creating opportunities for growth and helping others reach their full potential.