top of page

Snort 3: IDS/IPS Setup and Security Rules

33 minutes ago
11 min read
1. Introduction

Network security is not just about blocking unauthorized connections. It is also about understanding network behaviour, identifying suspicious activities, inspecting application traffic, and detecting potential threats before they compromise an infrastructure.

Snort is an open-source intrusion detection and prevention engine developed by Sourcefire and maintained by Cisco. Its detection technology is also used in Cisco Secure Firewall solutions.

In this article, we will explore how to install, configure, and operate Snort 3 natively on macOS, build custom detection rules, analyze network traffic, and implement practical cybersecurity monitoring policies.


2. What is Snort?

Snort is a network security engine capable of performing:

  • Network Intrusion Detection (IDS)

  • Network Intrusion Prevention (IPS)

  • Real-time traffic inspection

  • Deep Packet Inspection (DPI)

  • Protocol and application inspection

  • Signature-based threat detection

  • Network packet analysis

  • Security event logging

  • Offline PCAP analysis


Snort combines protocol inspection, traffic analysis, and customizable signatures to identify potentially malicious or unauthorized network activities.


3. How Snort Works

Snort processes network traffic through multiple components:

Component

Function

DAQ

Data acquisition and packet capture

Packet Decoder

Identifies packet structures and protocols

Stream Engine

Tracks network sessions and reconstructs traffic

Protocol Inspectors

Analyze application-layer protocols

Detection Engine

Evaluates traffic against security signatures

Event Logger

Generates and exports security alerts

Active Response

Executes prevention actions when supported

The detection engine determines whether network traffic matches the conditions defined in a security rule.


IDS vs. IPS:

Feature

IDS

IPS

Traffic monitoring

Yes

Yes

Threat detection

Yes

Yes

Security alerts

Yes

Yes

Packet dropping

No

Yes

Inline deployment required

No

Yes

Potential traffic disruption

Low

Depends on policy

An IDS monitors traffic passively, while an IPS operates in a position where it can enforce security decisions.

A passive Snort installation does not automatically become an IPS simply by creating a drop rule.


4. Installing Snort 3 on macOS

Update Homebrew:

brew update

Search for the Snort package:

brew search snort

Install Snort:

brew install snort

Verify the installed version:

snort -V

Laboratory output:

Snort++ Version 3.13.2.0

Using DAQ version 3.0.29.0
Using Hyperscan version 5.4.14
Using libpcap version 1.11.1
Using OpenSSL 4.1.0

Verify the executable location:

which snort
/opt/homebrew/bin/snort

Display installed DAQ modules:

snort --daq-list

Available modules in the laboratory:

bpf
divert
dump
fst
pcap
savefile
trace

These modules provide different capabilities for acquiring, processing, and handling network packets.


5. Understanding the Snort Configuration

Snort 3 uses Lua-based configuration files rather than the traditional snort.conf configuration used by Snort 2.

Locate the configuration directory:

ls -lah "$(brew --prefix)/etc/snort/"

Important configuration files include:

File

Purpose

snort.lua

Main configuration

snort_defaults.lua

Default configuration settings

balanced.lua

Balanced detection policy adjustments

security.lua

Security-focused policy adjustments

connectivity.lua

Connectivity-focused policy adjustments

max_detect.lua

Detection-focused policy adjustments

inline.lua

Inline configuration adjustments

file_magic.rules

File identification rules

Validate the default configuration:

snort -c "$(brew --prefix)/etc/snort/snort.lua" -T

Laboratory output:

total rules loaded: 219

pcap DAQ configured to passive.

Snort successfully validated the configuration
(with 0 warnings).

The initial 219 rules were file identification rules. They should not be confused with a comprehensive intrusion detection ruleset.


6. Creating the Laboratory Environment

Create an isolated working directory:

mkdir -p ~/snort-lab/{rules,logs,pcaps,config}
cd ~/snort-lab

Define the configuration path:

SNORT_CONF="$(brew --prefix)/etc/snort/snort.lua"

Directory structure:

snort-lab/
├── config/
├── logs/
├── pcaps/
└── rules/

Keeping custom configuration files separate from installation directories makes upgrades, troubleshooting, and configuration management easier.


7. Understanding Snort Rule Syntax

A typical Snort rule follows this structure:

ACTION PROTOCOL SOURCE_IP SOURCE_PORT
DIRECTION DESTINATION_IP DESTINATION_PORT
(OPTIONS)

Example:

alert tcp any any -> any 22 (
    msg:"SSH Connection Attempt";
    flags:S;
    sid:1000003;
    rev:1;
)

Rule components:

Component

Description

alert

Generate a security event

tcp

Network protocol

any

Match any source or destination

->

Traffic direction

22

Destination port

msg

Event description

flags

TCP flag conditions

sid

Unique signature identifier

rev

Signature revision

Common Snort actions:

Action

Behavior

alert

Generate an alert

drop

Drop the matching packet in IPS mode

block

Block the matching packet and subsequent flow traffic in IPS mode

pass

Mark matching traffic as passed

log

Log the matching packet

reject

Attempt to terminate the session

Use unique signature IDs for locally developed signatures and avoid conflicts with imported rulesets.


8. Creating Custom Security Signatures

Create the following rules file:

cat > rules/local.rules <<'EOF'
alert icmp any any -> any any (
    msg:"LAB - ICMP Echo Request Detected";
    itype:8;
    sid:1000001;
    rev:1;
)

alert tcp any any -> any 23 (
    msg:"LAB - Telnet Connection Attempt";
    flags:S;
    sid:1000002;
    rev:1;
)

alert tcp any any -> any 22 (
    msg:"LAB - SSH Connection Attempt";
    flags:S;
    sid:1000003;
    rev:1;
)

alert http any any -> any any (
    msg:"LAB - Custom HTTP Marker Detected";
    flow:to_server,established;
    http_uri;
    content:"snort-test";
    sid:1000004;
    rev:1;
)
EOF

Validate the custom rules:

snort -c "$SNORT_CONF" \
-R rules/local.rules \
-T

Laboratory output:

total rules loaded: 223

Snort successfully validated the configuration
(with 0 warnings).

The four custom signatures were successfully loaded alongside the default rules.


9. Monitoring Network Traffic in Real Time

Identify the active network interface:

route -n get default | grep interface

List hardware interfaces:

networksetup -listallhardwareports

In this laboratory, the active interface was:

Hardware Port: Wi-Fi
Device: en0

Start Snort:

sudo snort \
-c "$SNORT_CONF" \
-R rules/local.rules \
-i en0 \
-A alert_fast \
-q

Command options:

Option

Description

-c

Configuration file

-R

Additional rules file

-i

Capture interface

-A

Alert output format

-q

Quiet mode

-T

Validate configuration

-r

Analyze a PCAP file

-l

Logging directory

-Q

Request inline operation

Generate test traffic from a second terminal.

Only perform these tests against systems and networks that you own or are authorized to monitor.


Test 1 — ICMP Detection
ping -c 4 10.0.0.1

Laboratory result:

[1:1000001:1] "LAB - ICMP Echo Request Detected"
{ICMP} 10.0.0.114 -> 10.0.0.1

Test 2 — SSH Detection
nc -vz -w 3 10.0.0.1 22

Laboratory result:

[1:1000003:1] "LAB - SSH Connection Attempt"

Test 3 — Telnet Detection
nc -vz -w 3 10.0.0.1 23

Laboratory result:

[1:1000002:1] "LAB - Telnet Connection Attempt"

Test 4 — Deep Packet Inspection
curl -4 --max-time 10 \
"http://example.com/snort-test"

Laboratory result:

[1:1000004:1] "LAB - Custom HTTP Marker Detected"

Unlike basic port-based detection, the HTTP signature identifies specific content inside the application request.

The http_uri option instructs Snort to inspect the normalized HTTP URI.

Encrypted HTTPS content cannot be inspected in the same manner unless decrypted traffic is made available to the detection engine.


10. Real Laboratory Results

Detection

Signature ID

Events

ICMP Echo Request

1000001

4

Telnet Connection Attempt

1000002

6

SSH Connection Attempt

1000003

7

HTTP Marker Detection

1000004

1

Total


18

All four custom signatures were successfully triggered.

Multiple SSH and Telnet events were consistent with TCP SYN retransmissions. These events should not automatically be interpreted as independent attacks or successful connections.


11. Practical Cybersecurity Rules

Laboratory detection rules are useful for understanding the engine, but production security policies should reflect the organization's actual network architecture and security requirements.

The following examples provide a starting point for defensive monitoring.

These additional examples should be validated and tested before production deployment.


Rule 1 — Detect Insecure Telnet Connections

Telnet transmits information without encryption and should generally be replaced by SSH.

alert tcp $HOME_NET any -> any 23 (
    msg:"POLICY - Telnet Connection Attempt";
    flags:S;
    classtype:policy-violation;
    sid:1000101;
    rev:1;
)

Security recommendation: Disable unnecessary Telnet services and enforce restrictions at the network firewall.


Rule 2 — Detect Repeated SSH Connection Attempts
alert tcp any any -> $HOME_NET 22 (
    msg:"SECURITY - Repeated SSH Connection Attempts";
    flags:S;
    detection_filter:track by_src,count 10,seconds 60;
    sid:1000102;
    rev:1;
)

This signature detects repeated TCP SYN packets directed toward SSH services.

It does not confirm a brute-force authentication attack, because SSH authentication takes place inside an encrypted session.


Security recommendation:

  • Disable SSH password authentication where appropriate.

  • Use public-key authentication.

  • Restrict SSH access to authorized management networks.

  • Monitor authentication logs.

  • Investigate repeated connections and correlate them with host events.


Rule 3 — Detect External RDP Connection Attempts
alert tcp $EXTERNAL_NET any -> $HOME_NET 3389 (
    msg:"SECURITY - External RDP Connection Attempt";
    flags:S;
    classtype:policy-violation;
    sid:1000103;
    rev:1;
)

Security recommendation: Avoid exposing RDP directly to the internet. Use restricted VPN access, secure gateways, MFA, and network segmentation.


Rule 4 — Detect Suspicious SMB Connections
alert tcp $EXTERNAL_NET any -> $HOME_NET 445 (
    msg:"SECURITY - External SMB Connection Attempt";
    flags:S;
    classtype:policy-violation;
    sid:1000104;
    rev:1;
)

Security recommendation: Restrict external SMB access and segment internal file-sharing services to reduce exposure and lateral movement.


Rule 5 — Detect Cleartext FTP Connections
alert tcp $HOME_NET any -> any 21 (
    msg:"POLICY - FTP Connection Detected";
    flags:S;
    classtype:policy-violation;
    sid:1000105;
    rev:1;
)

Security recommendation: Replace traditional FTP with secure alternatives such as SFTP or appropriately configured FTPS.


Rule 6 — Detect Communication with Blacklisted IP Addresses
alert ip $HOME_NET any ->
[192.0.2.10,198.51.100.20] any (
    msg:"THREAT-INTEL - Blacklisted Destination";
    sid:1000106;
    rev:1;
)

The IP addresses above are reserved documentation addresses and are included only as placeholders.

In a production environment, use validated threat intelligence indicators from trusted sources.


Security recommendation: Maintain indicator expiration dates, allowlists, source reputation, and regular feed updates. IP addresses may be reassigned or shared by legitimate services.


Rule 7 — Detect Potential SQL Injection Indicators
alert http any any -> $HOME_NET any (
    msg:"WEB - Possible SQL Injection Indicator";
    flow:to_server,established;
    http_uri;
    content:"UNION SELECT",nocase;
    classtype:web-application-attack;
    sid:1000107;
    rev:1;
)

This is a simplified detection example, not a comprehensive SQL injection protection mechanism.


Security recommendation: Use parameterized database queries, input validation, application security testing, and maintained intrusion detection signatures.


Rule 8 — Detect Suspicious HTTP Executable Downloads
alert http any any -> $HOME_NET any (
    msg:"POLICY - Windows Executable File Indicator";
    flow:to_client,established;
    file_data;
    content:"MZ",depth 2;
    sid:1000108;
    rev:1;
)

This signature detects a common Windows executable file header within inspected HTTP response data. Legitimate software may also match this rule.


Security recommendation: Correlate executable downloads with endpoint protection, file reputation, application allowlisting, and sandbox analysis rather than automatically blocking every executable.


12. Defining the Protected Network

One of the most important configuration decisions is identifying the network that Snort is responsible for protecting.

The HOME_NET variable represents protected networks.

The EXTERNAL_NET variable represents traffic originating outside those networks when configured accordingly.


For this laboratory:

HOME_NET = '10.0.0.0/24'
EXTERNAL_NET = '!$HOME_NET'

First, create a separate configuration copy:

cp -RL "$(brew --prefix)/etc/snort/." config/

Edit the laboratory configuration:

nano config/snort.lua

Locate and replace the existing HOME_NET and EXTERNAL_NET definitions before the default configuration is included.


For segmented enterprise networks, the configuration could contain multiple protected networks:

HOME_NET = [[
    10.10.10.0/24
    ,10.10.20.0/24
    ,10.10.30.0/24
]]

EXTERNAL_NET = '!$HOME_NET'

Adapt these ranges to the actual infrastructure.

Defining EXTERNAL_NET as the inverse of HOME_NET excludes internal-to-internal traffic from signatures that specifically use EXTERNAL_NET as their source. Dedicated lateral movement rules may therefore be required.


Validate the configuration after every modification:

snort -c config/snort.lua \
-R rules/local.rules \
-T
13. Installing Community Intrusion Detection Rules

Custom signatures should complement maintained intrusion detection rules rather than replace them.

Snort provides a freely available Community Ruleset reviewed by Cisco Talos.


Download the Snort 3 Community Ruleset:

mkdir -p community

curl -fL \
https://www.snort.org/downloads/community/snort3-community-rules.tar.gz \
-o community/snort3-community-rules.tar.gz

Extract the package:

tar -xzf community/snort3-community-rules.tar.gz \
-C community/

Locate the extracted rules:

find community -name "*.rules"

Review the downloaded signatures, license, and package documentation before enabling them.


The community rules can be combined with local signatures through the ips configuration section or a dedicated rules manifest.

Create a manifest:

cat > rules/active.rules <<EOF
include $HOME/snort-lab/rules/local.rules
include $HOME/snort-lab/community/snort3-community-rules/snort3-community.rules
EOF

Adjust the community rule path if the extracted directory structure differs.


Validate both rulesets:

snort -c config/snort.lua \
-R rules/active.rules \
-T

The validation output should confirm that the expected rules have been loaded.


14. Keeping Security Rules Active

Creating a rule does not automatically enable it.

The rule must be included in the active Snort configuration, successfully loaded, and evaluated by a running detection engine.


Create a dedicated monitoring script:

cat > start-ids.sh <<'EOF'
#!/bin/bash

set -euo pipefail

LAB="$HOME/snort-lab"
SNORT="$(brew --prefix)/bin/snort"

"$SNORT" \
    -c "$LAB/config/snort.lua" \
    -R "$LAB/rules/active.rules" \
    -T

sudo "$SNORT" \
    -c "$LAB/config/snort.lua" \
    -R "$LAB/rules/active.rules" \
    -i en0 \
    -A alert_json \
    -l "$LAB/logs" \
    --lua "alert_json = {file = true, fields = 'timestamp proto src_ap dst_ap rule action msg class'}" \
    -q
EOF

Make the script executable:

chmod +x start-ids.sh

Start monitoring:

Monitor the generated alerts from another terminal:

tail -F ~/snort-lab/logs/alert_json.txt

The script validates the configuration before starting network monitoring.


For unattended production operation, use a properly configured service manager such as systemd on Linux or launchd on macOS, with restricted privileges, absolute paths, log rotation, and process health monitoring.


15. Network Forensics — Offline PCAP Analysis

Snort can analyze previously captured network traffic without requiring live packet acquisition.

Capture traffic:

sudo tcpdump -i en0 -s 0 -c 8 \
-w pcaps/test.pcap \
'icmp and host 10.0.0.1'

Generate network traffic:

ping -c 4 10.0.0.1

Laboratory capture result:

8 packets captured
0 packets dropped by kernel

Inspect the captured packets:

tcpdump -nn -r pcaps/test.pcap

Analyze the PCAP using Snort:

snort \
-c "$SNORT_CONF" \
-R rules/local.rules \
-r pcaps/test.pcap \
-A alert_fast \
-q

This approach is useful for:

  • Incident response

  • Network forensics

  • Detection engineering

  • Signature validation

  • Security regression testing

  • False-positive investigation


16. Exporting Security Events in JSON

Structured security events simplify integration with monitoring tools, dashboards, and SIEM solutions.

snort \
-c "$SNORT_CONF" \
-R rules/local.rules \
-r pcaps/test.pcap \
-A alert_json \
-l logs \
--lua "alert_json = {file = true, fields = 'timestamp proto src_ap dst_ap rule action msg class'}" \
-q

Inspect the generated file:

cat logs/alert_json.txt

Process the JSON events using Python:

import json
from pathlib import Path

log_file = Path("logs/alert_json.txt")

with log_file.open() as events:
    for line in events:
        if not line.strip():
            continue

        event = json.loads(line)

        print(
            event.get("timestamp"),
            event.get("src_ap"),
            event.get("dst_ap"),
            event.get("rule"),
            event.get("msg")
        )

The resulting events can be integrated with custom Python applications, security dashboards, and centralized monitoring platforms.


17. Moving from IDS to IPS

After validating a signature in detection mode, selected rules can be considered for enforcement.

Detection rule:

alert tcp $HOME_NET any -> any 23 (
    msg:"POLICY - Telnet Connection Attempt";
    flags:S;
    sid:1000101;
    rev:1;
)

Prevention version:

drop tcp $HOME_NET any -> any 23 (
    msg:"POLICY - Telnet Packet Dropped";
    flags:S;
    sid:1000101;
    rev:2;
)

Replace the previous signature rather than loading both versions with the same SID.

An inline-capable DAQ and appropriate network architecture are required for actual packet blocking.


Recommended Deployment Lifecycle
  1. Create or import a detection signature.

  2. Validate the configuration.

  3. Test the signature against authorized traffic and PCAP files.

  4. Enable it in passive monitoring mode.

  5. Review false positives.

  6. Refine network scope and detection conditions.

  7. Evaluate potential business impact.

  8. Obtain approval before enabling prevention.

  9. Deploy the blocking policy using a supported inline architecture.

  10. Monitor the results and maintain a rollback procedure.

Never enable every available signature in blocking mode without evaluating its operational impact.


18. Troubleshooting Snort on macOS

During the laboratory, monitoring the macOS loopback interface produced the following error:

No codec found for data link type 0

No codec for DAQ base protocol,
stopping packet processing

The macOS loopback interface uses a data-link format that was not supported by the active Snort decoder in this installation.

The issue was resolved by selecting the physical Wi-Fi interface:

-i en0

The Wi-Fi interface provided Ethernet-compatible packet data, allowing Snort to inspect network traffic successfully.

Avoid unnecessarily granting all local users access to packet capture devices. Use carefully controlled permissions and elevated privileges only where necessary.


19. Cybersecurity Best Practices

Security Practice

Recommendation

Network visibility

Position sensors where relevant traffic can be observed

Rule management

Maintain documented and version-controlled signatures

Network segmentation

Separate workstations, servers, IoT, and management networks

Threat intelligence

Use trusted and regularly updated indicator feeds

False positives

Tune signatures before enabling blocking

Logging

Centralize and protect security events

Updates

Maintain supported Snort versions and current rulesets

Least privilege

Restrict configuration and packet capture permissions

TLS inspection

Understand encrypted traffic visibility limitations

Incident response

Correlate network alerts with endpoint and authentication logs

Performance

Monitor packet loss, CPU utilization, and memory consumption

Change management

Validate and approve security policy changes

Availability

Maintain rollback and recovery procedures

Privacy

Restrict access to captured network traffic

A Snort instance running on an ordinary Wi-Fi-connected workstation generally observes traffic available to that workstation. It does not automatically monitor or protect every device on a switched network.

For enterprise-wide monitoring, consider a network TAP, switch SPAN port, dedicated monitoring sensor, or supported inline deployment architecture.

Snort should be part of a defense-in-depth strategy alongside firewalls, endpoint security, vulnerability management, secure authentication, and network segmentation.


20. Conclusion

Snort 3 provides a powerful platform for learning and implementing network intrusion detection, prevention, and traffic analysis.

This laboratory demonstrated that Snort can run natively on Apple Silicon and perform real-time security inspection without requiring Cisco Firewall Management Center or a virtualized firewall environment.

The successful installation, validation of 223 rules, and generation of 18 security events demonstrate the practical capabilities of the detection engine.

Beyond the laboratory, Snort can be integrated with threat intelligence feeds, security dashboards, SIEM platforms, and automated detection engineering workflows.

The objective of an effective intrusion detection system is not simply to generate alerts. It is to transform meaningful network visibility into reliable, actionable security intelligence.



Recent Posts

See All
Ed25519: A Modern Approach to SSH Authentication

SSH keys are one of the most effective ways to secure remote access to Linux servers. While RSA has been widely used for decades, Ed25519 has become an excellent choice for modern SSH environments. Wh

 
 
 
Portable AI

Have you ever imagined carrying your own AI assistant in your pocket, for free? With today's open-source AI models, it's entirely possible. By storing the required software and models on a USB flash d

 
 
 
Homebrew on macOS

If you use Homebrew to manage your development tools on macOS, keeping it updated is an important part of maintaining a reliable development environment. A simple maintenance routine helps keep packag

 
 
 

Comments


STENGE.info | Built with curiosity. Secured by knowledge.

bottom of page