Threat Hunting
Threat hunting is the proactive practice of searching for cyber threats that have evaded traditional security controls. This guide provides methodologies, techniques, and practical queries for conducting effective threat hunting operations using Wazuh, Elasticsearch, and other SOC tools.Threat Hunting Fundamentals
Threat hunting is hypothesis-driven investigation. Start with a question or assumption about potential adversary behavior, then use data to prove or disprove it.
Threat Hunting vs. Incident Response
| Aspect | Threat Hunting | Incident Response |
|---|---|---|
| Trigger | Proactive hypothesis | Alert or detection |
| Goal | Find unknown threats | Respond to known incident |
| Approach | Exploratory analysis | Structured process |
| Timeline | Continuous/scheduled | Reactive/time-sensitive |
| Outcome | New detections, IOCs | Remediation, containment |
The Threat Hunting Loop
Hypothesize
Develop a hypothesis about potential threats:
- Based on threat intelligence (TTPs from recent campaigns)
- Inspired by security gaps or blind spots
- Following anomalies in baseline behavior
- Investigating new attack techniques
- “Attackers may be using PowerShell to download and execute malware”
- “Lateral movement may be occurring via SMB connections”
- “Data exfiltration could be happening via DNS tunneling”
Investigate
Use data to test your hypothesis:
- Query Elasticsearch for relevant events
- Analyze Wazuh endpoint data
- Review IDS/IPS logs from Snort/Suricata
- Correlate events across multiple data sources
- Apply statistical analysis to identify outliers
Uncover
Analyze findings:
- Identify suspicious patterns or anomalies
- Distinguish between benign and malicious activity
- Trace attack paths and timelines
- Collect indicators of compromise (IOCs)
Threat Hunting Methodologies
- Intelligence-Driven
- Hypothesis-Driven
- Baseline Anomaly
- Crown Jewel
Intelligence-Driven Hunting
Hunt based on external threat intelligence about adversary TTPs.Sources:- MITRE ATT&CK Framework
- Threat intelligence feeds
- Vendor security advisories
- Security research publications
- Information sharing communities (ISACs)
- Identify relevant TTPs from threat intel
- Map TTPs to data sources in your environment
- Develop queries to detect those TTPs
- Execute hunt and analyze results
- Create permanent detection rules
- Spearphishing attachments (T1566.001)
- PowerShell execution (T1059.001)
- Credential dumping (T1003)
- Lateral movement via RDP (T1021.001)
Using Wazuh for Threat Hunting
Wazuh Query Techniques
Wazuh provides powerful search and filtering capabilities for endpoint data:File Integrity Monitoring (FIM) Hunting
File Integrity Monitoring (FIM) Hunting
Hunt for unauthorized file modifications:Query: Recent changes to system directoriesQuery: Suspicious file additionsWhat to look for:
- New executables in user temp directories
- Modifications to system binaries
- Changes to startup folders
- New files in web server directories
Process Execution Hunting
Process Execution Hunting
Identify suspicious process activity:Query: PowerShell with download capabilitiesQuery: Encoded PowerShell commandsQuery: Living off the Land binaries (LOLBins)What to look for:
- Suspicious parent-child process relationships
- Execution from unusual locations
- Command-line obfuscation
- Use of system utilities for malicious purposes
Network Connection Hunting
Network Connection Hunting
Investigate suspicious network activity:Query: Outbound connections to rare destinationsQuery: Internal lateral movementWhat to look for:
- Beaconing patterns (regular intervals)
- Connections to newly registered domains
- Large data transfers
- Unusual ports for common services
Authentication Hunting
Authentication Hunting
Hunt for credential compromise and abuse:Query: Failed login patternsQuery: Successful login after failures (potential brute force success)Query: Privilege escalation eventsWhat to look for:
- Logins from impossible locations (geographically)
- Logins at unusual times
- Service account interactive logins
- Multiple account logins from single source
Wazuh API for Automated Hunting
Example: Find agents with suspicious processesUsing Elasticsearch for Threat Hunting
Advanced Elasticsearch Queries
DNS Tunneling Detection
DNS Tunneling Detection
Detect potential DNS tunneling for data exfiltration:Indicators of DNS tunneling:
- High query volume to single domain
- Unusually long subdomain names
- High entropy in subdomain strings
- Regular query intervals (beaconing)
Lateral Movement Detection
Lateral Movement Detection
Identify potential lateral movement across the network:What to investigate:
- Single source connecting to many destinations
- Workstation-to-workstation SMB/RDP
- Unusual times for administrative protocols
- Accounts used across multiple systems
Data Exfiltration Detection
Data Exfiltration Detection
Hunt for large or unusual data transfers:Red flags:
- Large transfers outside business hours
- Data sent to cloud storage services
- Encrypted protocols to unknown destinations
- Transfers from database servers directly to internet
Persistence Mechanism Detection
Persistence Mechanism Detection
Search for common persistence techniques:Common persistence locations:
- Registry Run keys
- Startup folders
- Scheduled tasks
- Services
- WMI event subscriptions
Time-Based Analysis
Many malicious activities occur outside normal business hours when detection is less likely.
Common Threat Hunting Queries and Techniques
PowerShell Abuse Detection
Hunting Techniques:-
Download Cradles: Look for PowerShell downloading files
-
Encoded Commands: Base64 encoded commands to evade detection
-
Execution Policy Bypass: Attempts to bypass execution restrictions
-
Suspicious Modules: Loading of potentially malicious modules
Credential Theft Detection
LSASS Memory Dumping:Reconnaissance Detection
Network Scanning:Indicators of Compromise (IOC) Management
Collecting IOCs
Extract from Investigations
Collect IOCs during incident response and threat hunting:
- File hashes (MD5, SHA1, SHA256)
- IP addresses
- Domain names
- URLs
- Email addresses
- File paths
- Registry keys
- Mutex names
- User agents
Document in TheHive
Store IOCs as observables in TheHive cases:
- Tag IOCs by threat actor or campaign
- Set confidence levels
- Add context and analysis
- Mark for threat intelligence sharing
Operationalize IOCs
Turn IOCs into active detections:
- Create Wazuh CDB lists for known bad indicators
- Add IP blocks to firewall
- Update IDS/IPS signatures
- Configure DNS blocking
- Add to SIEM correlation rules
IOC Hunting Workflow
Automated IOC Hunting:- Maintain IOC Database: Keep updated list of IOCs from threat intel
- Schedule Searches: Daily/weekly searches across Elasticsearch
- Alert on Matches: Automatic alert creation for IOC hits
- Context Enrichment: Add threat intelligence context to matches
- Investigate Hits: Determine if match is historical or active threat
Threat Hunting Schedule
Daily Hunts
Quick focused hunts (30-60 minutes):
- Review anomalous authentication events
- Check for new persistence mechanisms
- Scan for unusual PowerShell activity
- Verify crown jewel access patterns
Weekly Hunts
In-depth investigations (2-4 hours):
- Network behavior analysis
- Process execution pattern review
- Lateral movement detection
- Data exfiltration hunting
Monthly Hunts
Comprehensive campaigns (1-2 days):
- Full threat actor TTP mapping
- Advanced persistent threat hunting
- Historical IOC sweeps
- Baseline validation and updates
Triggered Hunts
Based on new intelligence:
- New vulnerability disclosures
- Emerging threat campaigns
- Industry-specific threats
- Custom threat intelligence
Threat Hunting Tools and Resources
Essential Queries Library
Maintain a library of proven hunting queries:- MITRE ATT&CK Navigator: Map queries to ATT&CK techniques
- Query Repository: Git repository of Elasticsearch and Wazuh queries
- Playbook Documentation: Step-by-step hunting procedures
- Results Database: Historical hunt results for trend analysis
External Resources
Leverage the security research community’s collective knowledge for hunting ideas and techniques.
- MITRE ATT&CK Framework: Comprehensive adversary tactics database
- Cyber Kill Chain: Attack phase modeling for hunt focus
- SIGMA Rules: Generic detection rules convertible to your SIEM
- Threat intelligence feeds: Current IOCs and TTPs
- Security research blogs: Latest attack techniques
Measuring Hunting Effectiveness
Key Metrics
Track hunting program success:- Threats Discovered: Number of undetected threats found through hunting
- New Detections Created: Permanent detection rules created from hunts
- Coverage Improvement: ATT&CK technique coverage increase
- Time to Detection: Reduction in dwell time for threats
- False Positive Rate: Quality of new detection rules
- Hunt Frequency: Consistency of hunting activities
Continuous Improvement
Document Findings
Maintain detailed hunt logs:
- Hypothesis tested
- Queries used
- Results found
- Actions taken
- Lessons learned
Create Detections
Convert successful hunts to automated detection:
- Write Wazuh rules
- Update correlation logic
- Add IDS signatures
- Implement alerting
Expand Coverage
Continuously improve detection coverage:
- Map to MITRE ATT&CK
- Identify coverage gaps
- Prioritize hunt campaigns
- Test detection effectiveness
Related Resources
- Monitoring Guide - Daily monitoring operations and alert management
- Incident Handling - Procedures for responding to discovered threats
- Maintenance - System maintenance and tuning procedures
