|
| 1 | +--- |
| 2 | +title: Install Snort3 along with all its required dependencies. |
| 3 | +weight: 2 |
| 4 | + |
| 5 | +### FIXED, DO NOT MODIFY |
| 6 | +layout: learningpathall |
| 7 | +--- |
| 8 | + |
| 9 | +Multithreading in Snort 3 refers to the ability to associate multiple threads with a single Snort instance enabling the concurrent processing of multiple packet files. This optimization frees up additional memory for further packet processing. |
| 10 | + |
| 11 | +In order to enable multithreading in Snort3, specify the quantity of threads designated for processing network traffic using either the '--max-packet-threads' or '-z' option. |
| 12 | + |
| 13 | +{{%notice Note%}} |
| 14 | + The instruction provided have been tested on AWS EC2 Graviton4 metal instance (Neoverse V2) |
| 15 | +{{%/notice%}} |
| 16 | + |
| 17 | +## Compile and build Snort3 |
| 18 | +Run the script to download and install Snort3 and its dependent libraries. |
| 19 | +Skip this step if Snort3 is already installed. |
| 20 | + |
| 21 | +<!-- add github link for the below file [build_snort3.sh]() --> |
| 22 | +``` bash |
| 23 | +#!/usr/bin/env bash |
| 24 | + |
| 25 | +# Copyright (c) 2022-2024, Arm Limited. |
| 26 | +# |
| 27 | +# SPDX-License-Identifier: Apache-2.0 |
| 28 | + |
| 29 | + |
| 30 | +# Define a list of dependency package URLs |
| 31 | +declare -a PACKAGE_URLS=( |
| 32 | +"https://github.com/snort3/snort3/archive/refs/tags/3.3.5.0.tar.gz" |
| 33 | +"https://sourceforge.net/projects/pcre/files/pcre/8.45/pcre-8.45.tar.gz" |
| 34 | +"https://github.com/VectorCamp/vectorscan/archive/refs/tags/vectorscan/5.4.11.tar.gz" |
| 35 | +"https://github.com/snort3/libdaq/archive/refs/tags/v3.0.16.tar.gz" |
| 36 | +"https://boostorg.jfrog.io/artifactory/main/release/1.86.0/source/boost_1_86_0.tar.gz" |
| 37 | +"https://github.com/rurban/safeclib/releases/download/v3.8.1/safeclib-3.8.1.tar.gz" |
| 38 | +"https://github.com/gperftools/gperftools/releases/download/gperftools-2.13/gperftools-2.13.tar.gz" |
| 39 | +) |
| 40 | + |
| 41 | +downlaodPackages() |
| 42 | +{ |
| 43 | + for url in "${PACKAGE_URLS[@]}"; do |
| 44 | + # Extract the file name from the URL |
| 45 | + fname=$(basename "$url") |
| 46 | + fpath="${ROOT_DIR}/${fname}" |
| 47 | + # Check if the file already exists |
| 48 | + if [[ -f "$fpath" ]]; then |
| 49 | + echo "File $fname already exists. Skipping download." |
| 50 | + else |
| 51 | + # Download the file using wget |
| 52 | + |
| 53 | + echo "File $fname not found. Downloading..." |
| 54 | + |
| 55 | + wget -O "$fpath" "$url" |
| 56 | + if [[ $? -eq 0 ]]; then |
| 57 | + echo "$fname download complete" |
| 58 | + else |
| 59 | + echo "ERROR:$fname download Fail." |
| 60 | + fi |
| 61 | + fi |
| 62 | + done |
| 63 | +} |
| 64 | + |
| 65 | +installPackages() |
| 66 | +{ |
| 67 | + echo "@@@@@@@@@@@@@@@@@@ Installing packages ... @@@@@@@@@@@@@@@@@@@@" |
| 68 | + if [[ -r /etc/os-release ]]; then |
| 69 | + OS_NAME=$(grep -w "NAME" /etc/os-release | cut -d= -f2 | tr -d '"') |
| 70 | + OS_VERSION_ID=$(grep -w "VERSION_ID" /etc/os-release | cut -d= -f2 | tr -d '"') |
| 71 | + if [[ "${OS_NAME}" == "Ubuntu" ]]; then |
| 72 | + echo "OS: ${OS_NAME} ${OS_VERSION_ID}" |
| 73 | + else |
| 74 | + echo "Error: This script is only for ubuntu" |
| 75 | + exit 1 |
| 76 | + fi |
| 77 | + if [[ "${OS_VERSION_ID}" != "22.04" ] || [ "${OS_VERSION_ID}" != "20.04" ]];then |
| 78 | + echo "Warning: OS: ${OS_NAME} ${OS_VERSION_ID}" |
| 79 | + echo "Warning: Ubuntu 20.04 or 22.04 is recommended" |
| 80 | + fi |
| 81 | + else |
| 82 | + echo "Error: OS information detection failed" |
| 83 | + exit 1 |
| 84 | + fi |
| 85 | + |
| 86 | + apt-get update |
| 87 | + apt-get install -y $LIST_OF_APPS |
| 88 | + |
| 89 | + # required to get optimised result from Snort3 |
| 90 | + downlaodPackages |
| 91 | + mkdir -p ${ROOT_DIR}/snort3 |
| 92 | + tar -xzf 3.3.5.0.tar.gz --directory ${ROOT_DIR}/snort3 --strip-components=1 |
| 93 | + echo "@@@@@@@@@@@@@@@@@@ Installing Snort3 Dependencies ... @@@@@@@@@@@@@@@@@@@@" |
| 94 | + mkdir -p ${SNORT_DIR} |
| 95 | + mkdir -p $SNORT_DIR/pcre |
| 96 | + tar -xvf pcre-8.45.tar.gz --directory $SNORT_DIR/pcre --strip-components=1 |
| 97 | + #vector scan |
| 98 | + mkdir -p $SNORT_DIR/vectorscan |
| 99 | + tar -xzvf 5.4.11.tar.gz --directory $SNORT_DIR/vectorscan --strip-components=1 |
| 100 | + |
| 101 | + #libdaq |
| 102 | + mkdir -p $SNORT_DIR/libdaq |
| 103 | + tar -xvzf v3.0.16.tar.gz --directory $SNORT_DIR/libdaq --strip-components=1 |
| 104 | + |
| 105 | + #required to get optimized result from vectorscan |
| 106 | + mkdir -p $SNORT_DIR/boost |
| 107 | + tar -xvf boost_1_86_0.tar.gz -C $SNORT_DIR/boost --strip-components=1 |
| 108 | + |
| 109 | + #safeclib |
| 110 | + mkdir -p $SNORT_DIR/safeclib |
| 111 | + tar -xzvf safeclib-3.8.1.tar.gz --directory $SNORT_DIR/safeclib --strip-components=1 |
| 112 | + |
| 113 | + #gperftools |
| 114 | + mkdir -p $SNORT_DIR/gperftools |
| 115 | + tar -xzvf gperftools-2.13.tar.gz --directory $SNORT_DIR/gperftools --strip-components=1 |
| 116 | + |
| 117 | + echo "@@@@@@@@@@@@@@@@@@ Packages installed @@@@@@@@@@@@@@@@@@@@" |
| 118 | +} |
| 119 | + |
| 120 | +buildInstall() |
| 121 | +{ |
| 122 | + echo "@@@@@@@@@@@@@@@@@@ Build & Installation ... Start @@@@@@@@@@@@@@@@@@@@" |
| 123 | + cd $SNORT_DIR/libdaq |
| 124 | + mkdir -p ${SNORT_DIR}/libdaq/install |
| 125 | + ./bootstrap |
| 126 | + ./configure --prefix=${SNORT_DIR}/libdaq/install |
| 127 | + make -j${NUM_JOBS} |
| 128 | + make install |
| 129 | + |
| 130 | + cd ${SNORT_DIR}/safeclib |
| 131 | + ./configure |
| 132 | + make -j${NUM_JOBS} |
| 133 | + make -j${NUM_JOBS} install |
| 134 | + |
| 135 | + cd $SNORT_DIR/gperftools |
| 136 | + ./configure --with-tcmalloc-pagesize=64 |
| 137 | + make -j${NUM_JOBS} |
| 138 | + make -j${NUM_JOBS} |
| 139 | + |
| 140 | + cd $SNORT_DIR/pcre |
| 141 | + ./configure |
| 142 | + make -j${NUM_JOBS} |
| 143 | + make -j${NUM_JOBS} |
| 144 | + |
| 145 | + cd ${SNORT_DIR}/vectorscan |
| 146 | + cmake -DBOOST_ROOT=$(SNORT_DIR)/boost -DCMAKE_BUILD_TYPE=Release . |
| 147 | + make -j${NUM_JOBS} |
| 148 | + make -j${NUM_JOBS} |
| 149 | + |
| 150 | + cd ${ROOT_DIR}/snort3 |
| 151 | + ./configure_cmake.sh --build-type=Release --with-daq-includes=${SNORT_DIR}/libdaq/install/include/ --with-daq-libraries=${SNORT_DIR}/libdaq/install/lib/ --enable-unit-tests --enable-tcmalloc |
| 152 | + cd ${ROOT_DIR}/snort3/build |
| 153 | + make -j$NUM_JOBS |
| 154 | + make -j$NUM_JOBS install |
| 155 | + echo "@@@@@@@@@@@@@@@@@@ Build & Installation ... Done @@@@@@@@@@@@@@@@@@@@" |
| 156 | +} |
| 157 | + |
| 158 | +#------ Execution Start ----------# |
| 159 | +# provide nproc count to the scripts , it will be used as -j for make |
| 160 | +if [[ $# -ne 2 ]]; then |
| 161 | + echo "Usage: $0 <current_working_directory> <nprc>" |
| 162 | + exit 1 |
| 163 | +fi |
| 164 | + |
| 165 | +ROOT_DIR=$(pwd)/"$1" |
| 166 | +NUM_JOBS="$2" |
| 167 | +SNORT_DIR=${ROOT_DIR}/snort3/dependencies |
| 168 | +set -e |
| 169 | + |
| 170 | +LIST_OF_APPS="sudo net-tools build-essential manpages-dev libnuma-dev python3 |
| 171 | + python3-venv cmake meson pkg-config python3-pyelftools lshw |
| 172 | + util-linux iperf3 nginx libboost-all-dev ragel libsqlite3-dev |
| 173 | + libpcap-dev libdumbnet-dev libluajit-5.1-dev zlib1g-dev |
| 174 | + libhwloc-dev liblzma-dev libssl-dev libgoogle-perftools-dev |
| 175 | + libpcre++-dev flex openssl libunwind-dev autotools-dev |
| 176 | + libhugetlbfs-bin autoconf libmnl-dev bats wget unzip iproute2 |
| 177 | + git pkg-config cpputest libtool bison libcmocka-dev |
| 178 | + libnetfilter-queue-dev ethtool" |
| 179 | + |
| 180 | +# nprc should be a positive integer) |
| 181 | +if ! [[ "$NUM_JOBS" =~ ^[0-9]+$ ]] || [[ "$NUM_JOBS" -le 0 ]]; then |
| 182 | + echo "Error: nprc should be a positive integer." |
| 183 | + exit 1 |
| 184 | +fi |
| 185 | + |
| 186 | +mkdir -p ${ROOT_DIR} |
| 187 | +cd ${ROOT_DIR} |
| 188 | +installPackages |
| 189 | +buildInstall |
| 190 | +``` |
| 191 | + |
| 192 | +To check if the installation is complete, run the command below. |
| 193 | +```bash{ output_lines = "2-20" } |
| 194 | + snort -V |
| 195 | +,,_ -*> Snort++ <*- |
| 196 | + o" )~ Version 3.3.5.0 |
| 197 | + '''' By Martin Roesch & The Snort Team |
| 198 | + http://snort.org/contact#team |
| 199 | + Copyright (C) 2014-2024 Cisco and/or its affiliates. All rights reserved. |
| 200 | + Copyright (C) 1998-2013 Sourcefire, Inc., et al. |
| 201 | + Using DAQ version 3.0.16 |
| 202 | + Using Hyperscan version 5.4.11 2024-09-12 |
| 203 | + Using libpcap version 1.10.1 (with TPACKET_V3) |
| 204 | + Using LuaJIT version 2.1.0-beta3 |
| 205 | + Using LZMA version 5.2.5 |
| 206 | + Using OpenSSL 3.0.2 15 Mar 2022 |
| 207 | + Using PCRE version 8.45 2021-06-15 |
| 208 | + Using ZLIB version 1.2.11 |
| 209 | +
|
| 210 | +``` |
| 211 | + |
| 212 | + |
0 commit comments