Skip to content

Instantly share code, notes, and snippets.

@lukeswitz
Last active February 18, 2024 14:02
Show Gist options
  • Save lukeswitz/08ea69ad6047c5f0bd2388476b2fd189 to your computer and use it in GitHub Desktop.
Save lukeswitz/08ea69ad6047c5f0bd2388476b2fd189 to your computer and use it in GitHub Desktop.
NIDS using Snort v3 for Linux (Debian)

Snort 3 Installation and Configuration Guide for macOS

This guide outlines the process of installing and configuring Snort 3, an open-source Network Intrusion Detection System (NIDS), on macOS using Homebrew.

Install Homebrew

If you haven't already installed Homebrew, run the following command in the terminal:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Update Homebrew

Make sure your Homebrew is up-to-date:

brew update

Install Required Dependencies

Install the dependencies necessary for Snort 3 via Homebrew:

brew install daq libdnet openssl pcre libtool luajit hwloc cmake pkg-config libpcap

Download Snort 3

You can download the latest version of Snort 3 from the official Snort website or directly via Homebrew. To install Snort 3 using Homebrew, run:

brew install snort

Configure Snort 3

After installation, you'll need to configure Snort 3 for your specific needs. Snort 3's configuration file is located at /usr/local/etc/snort/snort.lua. You may need to adjust paths based on your Homebrew installation.

Copy the default configuration file and start editing it:

cp /usr/local/etc/snort/snort.lua /usr/local/etc/snort/snort.lua.bak
nano /usr/local/etc/snort/snort.lua

In the configuration file, set the HOME_NET and EXTERNAL_NET variables to match your network environment.

Rule Management

Download and configure Snort rules. Start with the Snort 3 community rules available on the Snort website:

curl -o community.tar.gz https://www.snort.org/downloads/community/snort3-community-rules.tar.gz
tar -xvzf community.tar.gz -C /usr/local/etc/snort/rules

Update your snort.lua configuration file to include the path to these rules.

Test Snort Configuration

To ensure your configuration is correct, run Snort in test mode:

snort -c /usr/local/etc/snort/snort.lua --warn-all

Run Snort in NIDS Mode

To start Snort in NIDS mode, specify the network interface you want to monitor (e.g., en0):

snort -c /usr/local/etc/snort/snort.lua -i en0 -A alert_fast -s 65535 -k none -q

Replace en0 with the actual interface you wish to monitor.

Monitoring and Logs

By default, Snort writes its logs to /var/log/snort/. Monitor these logs regularly to check for any alerts or potential threats.

This guide covers the basic steps for setting up Snort 3 on macOS using Homebrew. Depending on your specific requirements, further customization of the configuration and rules may be necessary.

Snort 3 Installation and Configuration Guide for Debian-Based Systems

This guide provides step-by-step instructions on how to set up Snort 3, an open-source Network Intrusion Detection System (NIDS), on a Debian-based Linux system.

Update System Packages

Ensure your system packages are up-to-date:

sudo apt-get update
sudo apt-get upgrade -y

Install Required Dependencies

Install the dependencies necessary for Snort 3:

sudo apt-get install -y build-essential libpcre3-dev libdumbnet-dev bison flex zlib1g-dev liblzma-dev libssl-dev libluajit-5.1-dev pkg-config libhwloc-dev cmake libpcap-dev libdaq-dev libnetfilter-queue-dev libmnl-dev libnghttp2-dev autoconf libtool

Download Snort 3

Navigate to the Snort website and find the latest version of Snort 3 or use wget with the direct link (replace the URL with the latest one available):

wget https://www.snort.org/downloads/snortplus/snort3-3.x.x.tar.gz

Compile and Install Snort 3

Extract the downloaded file and compile Snort 3:

tar -xvzf snort3-3.x.x.tar.gz
cd snort3-3.x.x
./configure --enable-sourcefire && make && sudo make install

Configure Snort 3

Copy the default configuration and tweak it as necessary:

sudo cp /usr/local/etc/snort/snort_defaults.lua /usr/local/etc/snort/snort.lua
sudo nano /usr/local/etc/snort/snort.lua

Set HOME_NET and EXTERNAL_NET according to your network. Configure paths to rule files and enable desired preprocessors and outputs.

Rule Management

Download Snort 3 rules. You can start with the community rules:

wget https://www.snort.org/downloads/community/snort3-community-rules.tar.gz
tar -xvzf snort3-community-rules.tar.gz -C /usr/local/etc/snort/rules

Update your snort.lua to include these rules.

Test Snort Configuration

Test your Snort configuration to ensure it's correct:

snort -c /usr/local/etc/snort/snort.lua --lint

Run Snort in NIDS Mode

Run Snort in NIDS mode to monitor network traffic:

sudo snort -c /usr/local/etc/snort/snort.lua -i <interface> -A alert_fast -s 65535 -k none

Replace <interface> with your network interface, e.g., eth0.

Automate Snort Startup

Consider automating Snort to start on boot using systemd or another init system. Create a systemd service file:

[Unit]
Description=Snort NIDS Daemon
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/snort -c /usr/local/etc/snort/snort.lua -i eth0 -A alert_fast -s 65535 -k none

[Install]
WantedBy=multi-user.target

Enable and start the Snort service:

sudo systemctl enable snort
sudo systemctl start snort

Monitoring and Logs

Snort alerts can be found in /var/log/snort/alert_fast.txt or wherever you've configured Snort to write its logs. Regularly monitor these logs for potential threats.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment