Rules Engine
The NETCAP Rules Engine allows you to define detection rules that automatically generate alerts when specific network patterns are observed. Rules use expr-lang expressions to match audit records and can be configured to detect various attack patterns, anomalies, and policy violations.
Table of Contents
Overview
Features
Expression-based matching: Use powerful expr-lang expressions to define detection logic
MITRE ATT&CK mapping: Associate rules with MITRE ATT&CK techniques
Alert deduplication: Automatic deduplication within configurable time windows
Rate limiting: Prevent alert flooding with per-rule rate limits
Multiple severity levels: Categorize alerts as low, medium, high, or critical
Flexible tagging: Organize rules with custom tags
Audit record output: Alerts are written as NETCAP audit records for analysis
Architecture
Rule Configuration
Rules are defined in YAML files with the following structure:
Field Reference
name (required)
name (required)Unique identifier for the rule. Used in alert generation and logging.
Example: SSH_Bruteforce_Attempt
description (required)
description (required)Human-readable explanation of what the rule detects.
Example: Detect high frequency SSH connection attempts indicating possible brute force attack
type (required)
type (required)The audit record type this rule applies to. Can be specified with or without the NC_ prefix.
Valid values: TCP, UDP, HTTP, DNS, TLS, IPv4, IPv6, ICMP, etc.
Examples:
TCPorNC_TCPHTTPorNC_HTTP
expression (required)
expression (required)An expr-lang expression that evaluates to true when the rule matches. Has access to all fields of the audit record type.
Example: DstPort == 22 && SYN && !ACK
severity (required)
severity (required)Alert severity level.
Valid values: low, medium, high, critical (case-insensitive)
mitre (optional)
mitre (optional)Array of MITRE ATT&CK technique IDs associated with this detection.
Format: ["T####.###", ...]
Example: ["T1110.001", "T1021.004"]
Find technique IDs at: https://attack.mitre.org/
tags (optional)
tags (optional)Custom tags for organizing and categorizing rules.
Example: ["ssh", "bruteforce", "authentication"]
enabled (required)
enabled (required)Whether the rule is active. Disabled rules are not evaluated.
Valid values: true, false
Writing Rules
Basic Rule Structure
Using Helper Functions
Rules have access to all helper functions available in filtering:
Complex Expressions
Combine multiple conditions for sophisticated detections:
Field Access
Access nested fields using dot notation:
Alert Structure
When a rule matches, an alert is generated with the following information:
Alerts are written to Alert.ncap.gz in the output directory and can be analyzed like any other audit record:
MITRE ATT&CK Integration
NETCAP rules can be mapped to MITRE ATT&CK tactics and techniques to provide context about detected threats.
Common Technique Mappings
T1046
Network Service Scanning
Port scans, service enumeration
T1071.001
Web Protocols
HTTP/HTTPS C2 communication
T1071.004
DNS
DNS tunneling, exfiltration
T1110
Brute Force
Password guessing attacks
T1190
Exploit Public-Facing Application
Web application attacks
T1021.004
SSH
Remote access via SSH
T1041
Exfiltration Over C2 Channel
Data exfiltration
T1048
Exfiltration Over Alternative Protocol
Non-standard exfiltration methods
T1572
Protocol Tunneling
Encapsulation for evasion
Example with MITRE Mapping
Example Rules
Network Reconnaissance
Data Exfiltration
Malware Communication
Web Attacks
Best Practices
Rule Design
Be Specific: Target specific behaviors rather than broad patterns
Balance False Positives: Adjust thresholds to minimize false alerts
Use Appropriate Severity: Match severity to actual threat level
low: Informational, minor anomaliesmedium: Suspicious activity, requires investigationhigh: Likely malicious activitycritical: Active attacks, immediate response needed
Rule Organization
Group Related Rules: Create separate files for different categories
Use Descriptive Names: Make rule purpose clear from name
Add Comprehensive Tags: Enable filtering and analysis
Testing Rules
Test Against Known Traffic: Verify rules work as expected
Monitor Alert Volume: Ensure rules don't generate excessive alerts
Review False Positives: Refine rules based on real-world results
Performance Optimization
Limit Regex Complexity: Simple patterns are faster
Order Conditions: Place fast checks first
Use Helper Functions: Optimized native implementations
Troubleshooting
Rule Not Triggering
Check rule is enabled:
enabled: trueVerify record type: Ensure rule type matches audit records
Test expression: Use filter on dump command to test expression
Check field names: Use
-fieldsflag to see available fields
Too Many Alerts
Increase specificity: Add more conditions to reduce false positives
Adjust thresholds: Increase numeric thresholds
Check deduplication: Ensure deduplication window is appropriate
Expression Errors
Next Steps
Review example rules for more patterns
See FILTERING.md for expression syntax details
Check the expr-lang documentation
Explore MITRE ATT&CK framework at https://attack.mitre.org/
Last updated