For the complete documentation index, see llms.txt. This page is also available as Markdown.

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)

Unique identifier for the rule. Used in alert generation and logging.

Example: SSH_Bruteforce_Attempt

description (required)

Human-readable explanation of what the rule detects.

Example: Detect high frequency SSH connection attempts indicating possible brute force attack

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:

  • TCP or NC_TCP

  • HTTP or NC_HTTP

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)

Alert severity level.

Valid values: low, medium, high, critical (case-insensitive)

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)

Custom tags for organizing and categorizing rules.

Example: ["ssh", "bruteforce", "authentication"]

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

Technique ID
Name
Use Case

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

  1. Be Specific: Target specific behaviors rather than broad patterns

  2. Balance False Positives: Adjust thresholds to minimize false alerts

  3. Use Appropriate Severity: Match severity to actual threat level

    • low: Informational, minor anomalies

    • medium: Suspicious activity, requires investigation

    • high: Likely malicious activity

    • critical: Active attacks, immediate response needed

Rule Organization

  1. Group Related Rules: Create separate files for different categories

  2. Use Descriptive Names: Make rule purpose clear from name

  3. Add Comprehensive Tags: Enable filtering and analysis

Testing Rules

  1. Test Against Known Traffic: Verify rules work as expected

  2. Monitor Alert Volume: Ensure rules don't generate excessive alerts

  3. Review False Positives: Refine rules based on real-world results

Performance Optimization

  1. Limit Regex Complexity: Simple patterns are faster

  2. Order Conditions: Place fast checks first

  3. Use Helper Functions: Optimized native implementations

Troubleshooting

Rule Not Triggering

  1. Check rule is enabled: enabled: true

  2. Verify record type: Ensure rule type matches audit records

  3. Test expression: Use filter on dump command to test expression

  4. Check field names: Use -fields flag to see available fields

Too Many Alerts

  1. Increase specificity: Add more conditions to reduce false positives

  2. Adjust thresholds: Increase numeric thresholds

  3. Check deduplication: Ensure deduplication window is appropriate

Expression Errors

Next Steps

Last updated