Snort 3 Build 270 CentOS 8 PDF
Snort 3 Build 270 CentOS 8 PDF
Snort 3 Build 270 CentOS 8 PDF
Generated: 2020-03-14
Table of Contents
1. Introduction ...................................................................................................................................................................... 2
2. Preparation ...................................................................................................................................................................... 3
3. Installing Snort 3 Dependencies .............................................................................................................................. 4
3.1 Required Dependencies...................................................................................................................................... 4
3.2 Optional Dependencies....................................................................................................................................... 5
4. Installing Snort 3 ............................................................................................................................................................ 7
5. Installing Snort 3 Extra for Additional Capabilities ........................................................................................... 8
6. Configuring Snort 3 ....................................................................................................................................................... 8
6.1 Global Paths for Rules, AppID, and IP Reputation ................................................................................... 8
6.2 Configuring HOME_NET and EXTERNAL_NET ........................................................................................10
6.3 Configuring ips Module .....................................................................................................................................10
6.4 Configuring reputation Inspector (Optional) .............................................................................................11
6.5 Configuring appid Inspector (Optional) ......................................................................................................11
6.6 Configuring file and file_log Inspectors (Optional) .................................................................................11
6.7 Configuring data_log Inspector (Optional) ................................................................................................12
6.8 Configuring Logger Module (Optional)........................................................................................................12
7. Running and Testing Snort 3 ..................................................................................................................................13
7.1 Running against PCAP Files ...........................................................................................................................13
7.2 Running against an Interface .........................................................................................................................13
7.3 Running Snort 3 Demo......................................................................................................................................13
8. Configuring Snort Network Interfaces, User and Service .............................................................................14
8.1 Configuring Network Capturing Interfaces ...............................................................................................14
8.2 Creating Snort User and Systemd Startup Service ................................................................................16
1. Introduction
This guide walks through installing, configuring and testing Snort 3 on CentOS version 8.1. Some of the
configurations may not be applicable to production sensors. The steps in this guide should be tested first.
LibDAQ version
Build : 3.0.0
Source : git
Configuration changes
2. Preparation
Starting from CentOS 8, several development libraries required for successfully building LibDAQ and Snort are
not in the default repositories – AppStream, Base, or Extras. Instead, these libraries exist in the PowerTools
repository, which is disabled by default. Hence, the PowerTools repository is enabled first.
Additional development libraries exist in the EPEL repository. Enabling the EPEL repository reduces build time
and streamlines the installation and updates of these libraries. Otherwise, packages from the EPEL repository
can be built from their source code.
Now that all of the repositories enabled, it is time to ensure that the operating system and existing packages are
up to date. This may require a reboot, especially if the updates included kernel upgrades.
# dnf upgrade
# reboot now
Since some of the packages maybe built from source, a directory is created to house the source codes.
Next, some helper packages are installed, which are not required by Snort and can be removed later.
Red Hat based operating systems do not include the /usr/local/lib and /usr/local/lib64 in the linker
caching paths, resulting in build errors since the referenced libraries cannot be found. This is corrected by
creating a configuration file under /etc/ld.so.conf.d containing the required paths and updating the cache.
# vi /etc/ld.so.conf.d/local.conf
Add the below two lines to the newly created configuration file.
/usr/local/lib
/usr/local/lib64
# ldconfig
Info: The error message typically generated by the missing linker caching paths is presented as:
cannot open shared object file: no such file or directory
The final step in the preparation is to install the build tools from the repository. These include: flex (flex), bison
(bison), gcc (gcc), c++ (gcc-c++), make (make), and cmake (cmake). Additionally, autoconf (autoconf),
automake (automake) and libtool (libtool) packages are installed to build LibDAQ.
# dnf install flex bison gcc gcc-c++ make cmake automake autoconf libtool
3. Installing Snort 3 Dependencies
The following table summarizes the required and optional packages for building Snort and LibDAQ.
Building LibDAQ with NFQ support requires additional packages to be installed before configuration: libnfnetlink
(libnfnetlink-devel), libnetfilter_queue (libnetfilter_queue-devel).
LibDAQ
Snort 3 requires LibDAQ (>=3.0.0). Clone it and generate the configuration script.
Info: Review LibDAQ configuration options to disable modules via --disable-<name>-module option
Example: ./configure --disable-netmap-module --disable-divert-module
Proceed with configuring LibDAQ, which should result in a similar output (omitted) as demonstrated below.
# ./configure
...
Build AFPacket DAQ module.. : yes
Build BPF DAQ module....... : yes
Build Divert DAQ module.... : no
Build Dump DAQ module...... : yes
Build FST DAQ module....... : yes
Build NFQ DAQ module....... : yes
Build PCAP DAQ module...... : yes
Build netmap DAQ module.... : no
Build Trace DAQ module..... : yes
# make
# make install
# ldconfig
# cd ../
3.2 Optional Dependencies
lzma is used for decompression of SWF and PDF files, while uuid is a library for generating/parsing Universally
Unique IDs for tagging/identifying objects across a network.
Hyperscan
While hyperscan is an optional requirement, it is highly recommended to install it. Prior to installing hyperscan,
the following dependencies should be installed: Ragel, Boost and sqlite3 (sqlite-devel). CentOS 8 does not
come with Python preinstalled. Building hyperscan requires a python interpreter, python3 (python3) installed.
Info: Installing Ragel version >= 7.x requires installing colm first. Ragel version 6.1.0 does not require installing colm.
The remaining dependency is boost, which is downloaded and decompressed without building it.
There are two methods to make hyperscan aware of the Boost headers: 1) Symlink, or 2) Passing BOOST_ROOT
pointing to the root directory of the boost headers to cmake. Both methods are shown below.
Method 1 – Symlink:
# ln -s ~/sources/boost_1_72_0 /boost ~/sources/hyperscan-5.2.1/include/boost
# cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local ../hyperscan-5.2.1
Method 2 – BOOST_ROOT:
# cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local -
DBOOST_ROOT=../boost_1_72_0 ../hyperscan-5.2.1
# make -j$(nproc)
# make -j$(nproc) install
# cd ../
Flatbuffers
Flatbuffers is a cross-platform serialization library for memory-constrained apps. It allows direct access of
serialized data without unpacking/parsing it first.
Safec
Safec is used for runtime bounds checks on certain legacy C-library calls. Safec package is available in the
EPEL repository.
Note: An additional step is required when installing the package version of Safec because the Safec EPEL package
deploys a pkg-config file named safec-version.pc while Snort expects the pkg-config file to be named
libsafec.pc. This additional step is not required if Safec is built from source.
Tcmalloc
tcmalloc is a library created by Google (PerfTools) for improving memory handling in threaded programs. The
use of the library may lead to performance improvements and memory usage reduction. The gperftools
(gperftools-devel) package version 2.7 is available from the EPEL repository.
Now that all of the dependencies are installed, clone Snort 3 repository from GitHub.
Before configuring Snort, export the PKG_CONFIG_PATH to include the LibDAQ pkgconfig path, as well as other
packages’ pkgconfig paths, otherwise, the build process may fail.
# export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
# export PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:$PKG_CONFIG_PATH
Note: If LibDAQ or other packages were installed to a custom, non-system path, then that path should be exported to
PKG_CONFIG_PATH, for example:
# export PKG_CONFIG_PATH=/opt/libdaq/lib/pkgconfig:$PKG_CONFIG_PATH
-------------------------------------------------------
snort version 3.0.0
Install options:
prefix: /usr/local/snort
includes: /usr/local/snort/include/snort
plugins: /usr/local/snort/lib64/snort
...
Feature options:
DAQ Modules: Static (afpacket;bpf;dump;fst;nfq;pcap;trace)
Flatbuffers: ON
Hyperscan: ON
ICONV: ON
LZMA: ON
RPC DB: Built-in
SafeC: ON
TCMalloc: ON
UUID: ON
-------------------------------------------------------
# cd build/
# make -j$(nproc)
# make -j$(nproc) install
# cd ../../
Once the installation is complete, verify that Snort 3 reports the expected version and library names
# /usr/local/snort/bin/snort –V
Snort 3 Extra is a set of C++ or Lua plugins to extend the functionality of Snort 3 in terms network traffic
decoding, inspection, actions, and logging. One particular plugin is emphasized and configured in this guide is the
data_log inspector plugin. The emphasis of this inspector is detailed in a later section.
Before building the extra plugins, the environment variable PKG_CONFIG_PATH must be set. The path can be
verified by listing Snort installation directory.
# cd snort3_extra
# export PKG_CONFIG_PATH=/usr/local/snort/lib64/pkgconfig:$PKG_CONFIG_PATH
# ./configure_cmake.sh --prefix=/usr/local/snort/extra
# cd build/
# make -j$(nproc)
# make -j$(nproc) install
# cd ../../
6. Configuring Snort 3
Snort 3 includes two main configuration files, snort_defaults.lua and snort.lua. The file
snort_defaults.lua contains default values for rules paths, networks, ports, wizards, and inspectors, etc.
Info: The snort.lua file contains Snort’s main configuration, allowing the implementation and configuration of Snort
inspectors (preprocessors), rules files inclusion, event filters, output, etc.
Info: The snort_defaults.lua file contains default values such as paths to rules, AppID, intelligence lists, and network
variables.
Info: An additional file file_magic.lua exists in the etc/snort/ directory. This file contains pre-defined file identities
based on the hexadecimal representation of the files magic headers. These help Snort identify the file types traversing the
network when applicable. This file is also used by Snort main configuration file snort.lua and does not require any
modifications.
The configuration changes and the respective Snort 3 Lua files are as follows.
# mkdir -p /usr/local/snort/{builtin_rules,rules,appid,intel}
Snort Rules
Snort rules consist of text-based rules, and Shared Object (SO) rules and their associated text-based stubs. At
the time of writing this guide, the Shared Object rules are not available yet. The rules tarball also contains Snort
configuration files. The configuration files from the rules tarball will be copied to the etc/snort/ directory, and
will be used in favor of the configuration files in from Snort 3 source tarball.
Proceed by creating a directory to contain the files extracted from the rules tarball downloaded from Snort.org.
Replacing the oinkcode placeholder in the below command with the official and dedicated oinkcode.
Extract the rules tarball and copy the rules to the rules/ directory created earlier.
# tar xf snortrules-snapshot-3000.tar.gz
├── builtins
├── etc
└── rules
Copy the files to their respective directories of the Snort installation paths.
# cp rules/*.rules /usr/local/snort/rules/
# cp builtins/builtins.rules /usr/local/snort/builtin_rules/
# cp etc/snort_defaults.lua etc/snort.lua /usr/local/snort/etc/snort/
# cd ../
OpenAppID (Optional)
Download and extract the OpenAppID package, and move the extracted odp/ directory to the appid/ directory.
# curl -Lo snort-openappid-12159.tar.gz https://snort.org/downloads/openappid/12159
# tar xf snort-openappid-12159.tar.gz
# mv odp/ /usr/local/snort/appid/
IP Reputation (Optional)
Download the IP Blacklist generated by Talos and move it to the intel/ directory created earlier. An empty file
for the IP address whitelist is also created to be configured along with the IP address blacklist.
Snort configuration file snort_defaults.lua needs to be modified to point to the correction locations of rules,
AppID and reputation blacklists. The paths shown below follow the conventions from the beginning of this guide.
Change from:
-- Path to your rules files (this can be a relative path)
RULE_PATH = '../rules'
BUILTIN_RULE_PATH = '../builtin_rules'
PLUGIN_RULE_PATH = '../so_rules'
-- If you are using reputation preprocessor set these
WHITE_LIST_PATH = '../lists'
BLACK_LIST_PATH = '../lists'
Change to:
-- Path to your rules files (this can be a relative path)
RULE_PATH = '../../rules'
BUILTIN_RULE_PATH = '../../builtin_rules'
PLUGIN_RULE_PATH = '../so_rules'
Change from:
-- setup the network addresses you are protecting
HOME_NET = 'any'
Change to:
-- setup the network addresses you are protecting
HOME_NET = [[ 10.0.0.0/8 192.168.0.0/16 172.16.0.0/12 ]]
Change from:
ips =
{
-- use this to enable decoder and inspector alerts
--enable_builtin_rules = true,
-- The following include syntax is only valid for BUILD_243 (13-FEB-2018) and later
-- RULE_PATH is typically set in snort_defaults.lua
rules = [[
include $RULE_PATH/snort3-app-detect.rules
include $RULE_PATH/snort3-browser-chrome.rules
.....
include $RULE_PATH/snort3-sql.rules
include $RULE_PATH/snort3-x11.rules
]]
}
Change to:
ips =
{
mode = tap,
-- The following include syntax is only valid for BUILD_243 (13-FEB-2018) and later
-- RULE_PATH is typically set in snort_defaults.lua
rules = [[
include $RULE_PATH/snort3-app-detect.rules
include $RULE_PATH/snort3-browser-chrome.rules
.....
include $RULE_PATH/snort3-sql.rules
include $RULE_PATH/snort3-x11.rules
]]
}
6.4 Configuring reputation Inspector (Optional)
The reputation inspector is disabled (commented) by default. Uncomment its section and change the values of
the --blacklist and --whitelist variables to point to the paths IP address lists.
Change from:
--[[
reputation =
{
-- configure one or both of these, then uncomment reputation
--blacklist = 'blacklist file name with ip lists'
--whitelist = 'whitelist file name with ip lists'
}
--]]
Change to:
reputation =
{
-- configure one or both of these, then uncomment reputation
blacklist = BLACK_LIST_PATH .. '/ip-blacklist',
whitelist = WHITE_LIST_PATH .. '/ip-whitelist'
}
Info: Enabling the Reputation inspector while in IDS mode will generate blacklist hit alert when a match occurs, and
traffic may not be inspected further.
Change from:
appid =
{
-- appid requires this to use appids in rules
--app_detector_dir = 'directory to load appid detectors from'
}
Change to:
appid =
{
-- appid requires this to use appids in rules
app_detector_dir = APPID_PATH,
log_stats = true
}
The file inspector is configured to enable file type identification (enable_type = true) and file magic signature
calculation (enable_signature = true). Finally, a file policy is configured to log all file types identified in the
network traffic regardless of their type.
Change from:
file_id = { file_rules = file_magic }
Change to:
file_id =
{
enable_type = true,
enable_signature = true,
file_rules = file_magic,
file_policy =
{
{ use = { verdict = 'log', enable_file_type = true, enable_file_signature = true } }
}
}
The final step is to enable event logging for the inspector. This is accomplished with the file_log inspector. This
inspector has two Boolean options that allow logging of packet and system time of file events.
file_log =
{
log_pkt_time = true,
log_sys_time = false
}
Info: The file policy can include multiple configurations. The below example file policy will log file identification only when
a file of type PDF id = 22 or when a file with the specified SHA256 hash is observed traversing the network or capture.
file_policy =
{
{ when = { file_type_id = 22 }, use = { verdict = 'log', enable_file_signature = true } },
{ when = { sha256 = "E65ECCC.....DDF3233355007" }, use = { verdict = 'log' } }
}
In order to enable the data_log inspector, it must be defined in snort.lua. The below example will log HTTP
request headers into the data_log file and limit the size of the log file to 100MB before a new log file is
generated.
data_log =
{
key = 'http_request_header_event',
limit = 100
}
Change from:
--alert_fast = { }
Change to:
alert_fast =
{
file = true
}
7. Running and Testing Snort 3
Running Snort requires setting two environment variables, LUA_PATH and SNORT_LUA_PATH. These variables point
to the lua and configuration directories within the Snort installation prefix.
# export LUA_PATH=/usr/local/snort/include/snort/lua/\?.lua\;\;
# export SNORT_LUA_PATH=/usr/local/snort/etc/snort
Snort can also process multiple PCAP files stored in a specific directory in bulk. This involves specifying the
directory containing the PCAP files via the --pcap-dir option and filtering only the PCAP files in that directory
via the --pcap-filter option.
Info: Snort can run and process network from more than one network interface via the -i option, while taking
advantage of Snort’s multiple packets processing threads via --max-packet-threads or –z options:
Multiple Interfaces:
snort –c snort.lua –i eth0 eth1 –z 2
Inline Pairs:
snort –c snort.lua –i eth0:eth1 –z 2
The network capture interface that Snort will utilize to inspect traffic is setup with minimal configurations as
shown below. Replace the ifname with the actual interface name
TYPE=Ethernet
BOOTPROTO=none
IPV4_FAILURE_FATAL=no
IPV6INIT=no
IPV6_FAILURE_FATAL=no
NAME=ifname
DEVICE=ifname
ONBOOT=yes
If an existing interface is modified, ensure that NetworkManager can read the changes and have them applied.
NIC offloads are options that allow the stack to transmit packets that are larger than the normal MTU for
resources optimization. In doing so, network traffic is potentially altered – (re)segmentation, IP fragmentation,
reassembly, etc. – by the receiving host’s network interface instead of the CPU. This could lead to packet errors
potentially allowing IDS evasion scenarios. In order to avoid these issues and allow Snort to monitor the same
packets destined to the receiving host, it is recommended to disable NIC offloading options.
Info: Network scripts are deprecated in CentOS 8 and are replaced with NetworkManager through the nmcli tool. The
deprecated network scripts will not be used in this guide.
In CentOS 8 with NetworkManager present, this can be achieved with the following command, replacing the
ifname with the capturing interface name.
# nmcli con mod ifname ethtool.feature-lro off ethtool.feature-gro off ethtool.feature-tso off
ethtool.feature-gso off ethtool.feature-sg off ethtool.feature-rx off ethtool.feature-tx off
ethtool.feature-rxvlan off ethtool.feature-txvlan off
This permanently modifies the interface’s configuration file ifcfg-ifname with the ETHTOOL_OPTS parameter.
ETHTOOL_OPTS="-K ifname gro off gso off lro off rx off rxvlan off sg off tso off tx off txvlan off"
Depending on the hardware and interface type and driver, it is possible to increase the size of the receive ring
buffer, rx, to the maximum value the interface is capable of, increasing the number of stored incoming packets,
thus, potentially improving capture performance. Determining the ring buffer size can be done using ethtool
with the –g option as shown in the below example, replacing the ifname with the capturing interface name.
# ethtool –g ifname
# vi /etc/sysconfig/network-scripts/ifcfg-ifname
ETHTOOL_OPTS="-K ifname gro off gso off lro off rx off rxvlan off sg off tso off tx off txvlan off"
ETHTOOL_CMD="-G ifname rx 4096"
Second, an executable network dispatcher script is created, which will pass the configured ETHTOOL_CMD string
from the interface’s configuration file to the ethtool program.
# vi /etc/NetworkManager/dispatcher.d/99-ethtool.sh
#!/bin/bash
# BEGIN 99-ethtool.sh
if [[ $2 == up ]]; then
SCRIPT="$(basename "$0")"
if [[ -e $CONNECTION_FILENAME ]]; then
source $CONNECTION_FILENAME
if [[ -n $ETHTOOL_CMD ]]; then
ETHTOOL_CMD="/usr/sbin/ethtool $ETHTOOL_CMD"
if $ETHTOOL_CMD; then
logger "$SCRIPT: success: $ETHTOOL_CMD"
else
logger "$SCRIPT: failed: $ETHTOOL_CMD"
fi
else
logger "$SCRIPT: ETHTOOL_CMD not in $CONNECTION_FILENAME, skipping"
fi
else
logger "$SCRIPT: $CONNECTION_FILENAME does not exist?"
fi
fi
# chmod +x /etc/NetworkManager/dispatcher.d/99-ethtool.sh
Another task involves setting up the interface in promiscuous mode permanently using a custom oneshot
systemd service. The service will also disable ARP. Once the service is created, reload systemd and enable it.
# vi /etc/systemd/system/promisc.service
[Unit]
Description=Snort 3 interface promiscuous mode during boot service
After=network.target
[Service]
Type=oneshot
ExecStart=/usr/sbin/ip link set dev ifname arp off
ExecStart=/usr/sbin/ip link set dev ifname promisc on
TimeoutStartSec=0
RemainAfterExit=yes
[Install]
WantedBy=default.target
# systemctl daemon-reload
# systemctl enable promisc.service
Finally, reboot the host and verify that all of the changes were successfully applied. The below outputs
demonstrate the expected behavior of the above tasks, replacing the ifname with the capturing interface name.
# ethtool –g ifname
Ring parameters for ifname:
Pre-set maximums:
RX: 4096
...
Current hardware settings:
RX: 4096
...
8.2 Creating Snort User, Logging Directory and Systemd Startup Service
Preparing Snort for production also involves running Snort with a regular system user and not as root. The
following steps will create a group and a user under which the Snort process will run.
# groupadd snort
# useradd snort -r -M -g snort -s /sbin/nologin -c SNORT_SERVICE_ACCOUNT
By default, Snort writes the generated logs into /var/log/snort directory. The following steps involved creating the
directory and then assigning its ownership to the Snort user and group created in the previous step along with
appropriate permissions.
# mkdir /var/log/snort
# chmod -R 5700 /var/log/snort
# chown -R snort:snort /var/log/snort
Note: If a custom logging directory is created outside of /var/log, then SELINUX may block Snort from writing logs to
the custom directory. The label for the directory can be viewed using the ls –Z command as demonstrated below.
In this case, the SELINUX label and context must be configured for the custom logging directory. The example below
replicates the SELINUX label and context of the directory /var/log to the custom Snort logging directory without having
to disable SELINUX.
In order to run Snort as a startup service, a systemd unit file is created. The unit file specifies the environment
variables required for running Snort via the Environment option (one per line), the user and group that the
service and ultimately Snort will be running as, and the capabilities that will be granted to the service and user.
Info: Programs running with a regular user (non-root) must have capabilities granted externally, such as granting the
Snort user network-capturing capabilities. This is achieved by using the CapabilityBoundingSet and
AmbientCapabilities in Snort’s systemd unit file. The AmbientCapabilities grants the configured capabilities
automatically while the CapabilityBoundingSet limits the capabilities to only those configured.
[Unit]
Description=Snort 3 Intrusion Detection and Prevention service
After=syslog.target network.target
[Service]
Type=simple
Environment="LUA_PATH=/usr/local/snort/include/snort/lua/?.lua;;"
Environment="SNORT_LUA_PATH=/usr/local/snort/etc/snort"
ExecStart=/usr/local/snort/bin/snort -c /usr/local/snort/etc/snort/snort.lua –i ifname –l
/var/log/snort –D –u snort –g snort –k none
ExecReload=/bin/kill -SIGHUP $MAINPID
User=snort
Group=snort
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_RAW CAP_IPC_LOCK
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_RAW CAP_IPC_LOCK
[Install]
WantedBy=multi-user.target
Reload systemd to pick up the new service and then enable the service.
# systemctl daemon-reload
# systemctl enable snort.service
Many of Snort configurations can be supplied either at run-time via the command line or via its configuration file.
For example, in Snort’s systemd unit file, the command line options –D, -u snort, and –g snort were supplied to
run Snort process in daemon mode under the user and group snort, respectively. The same can configured in
snort.lua via the process module (optional) as the below example demonstrates.
process =
{
--same as -D
daemon = true,
--same as -u
set_uid = 'snort',
--same as -g
set_gid = 'snort',
utc = true
}
The last option, utc, configures Snort to log timestamps in UTC instead of the host’s configured time zone.