基於CentOS 8 系統環境下的 Snort 3 安裝指南

O、 閱讀要求
本教程並不適合初學者,你們在閱讀本文以前,需具有CentOS 8 Linux、Snort 2.9的成功安裝經驗。本次安裝對網絡依賴很大,因此你們必定要將網絡狀態調節好,本指南介紹的內容,僅在測試環境中使用。python

1、環境

虛擬機:VMware Workstation V15c++

安裝鏡像:CentOS 8 (CentOS-8.2.2004-x86_64-minimal.iso )git

安裝方式:基於網絡安全方面的考慮,本實驗採用最小化安裝CentOS 八、內存(4G+)、CPU(4 core)、磁盤空間(20G+)。github

源碼位置:將各種安裝源碼包存放在/root/sources/,試驗之初,軟件包可從github克隆。sql

2、CentOS8 mini系統初始化

當CentOS8初次安裝完,系統還沒法使用。首先咱們要配置網絡。這裏咱們爲網卡配置靜態IP地址。安裝系統時僅選擇Minimal Install最小化安裝,其餘任何選項無需勾選。
基於CentOS 8 系統環境下的 Snort 3 安裝指南bootstrap

3、啓用 EPEL 和 PowerTools軟件源

Snort編譯過程所需的某些開發包在CentOS 8默認存儲庫中不可用,因此咱們須要在系統中添加EPEL和PowerTools倉庫。安全

[root@localhost ~]#dnf config-manager --add-repo /etc/yum.repos.d/CentOS-PowerTools.repobash

[root@localhost ~]# dnf config-manager --set-enabled PowerTools網絡

[root@localhost ~]# dnf install epel-releasecurl

Tip:Centos7安裝了dnf也能夠執行這條命令。

安裝PowerTools存儲庫

啓用兩個存儲庫後,請使用如下命令升級全部軟件包:

#dnf upgrade

Transaction Summary

===============================Install 13 Packages

Upgrade 259 Packages

Total download size: 291 M

Is this ok [y/N]:

大概升級內容爲291M,更新結束後,重啓系統。

任務完成以後再次登陸系統,在/etc/ld.so.conf.d/目錄下建立local.conf配置文件

#vi /etc/ld.so.conf.d/local.conf

添加下面內容:

/usr/local/lib

/usr/local/lib64

保存退出

#ldconfig

4、安裝依賴包

安裝依賴包的環節很是重要。安裝依賴包比較多,咱們先分解安裝

[root@localhost ~]# dnf install flex bison gcc gcc-c++ make cmake automake autoconf libtool

[root@localhost ~]# dnf install libpcap-devel pcre-devel libdnet-devel hwloc-devel openssl-devel zlib-devel luajit-devel pkgconfig libmnl-devel

[root@localhost ~]# dnf install libnfnetlink-devel libnetfilter_queue-devel

這行命令必須在安裝DAQ以前執行。

安裝完全部軟件包後,下面須要從Git存儲庫下載LibDAQ,並從下載的源代碼中進行編譯。

5、安裝libDAQ

#cd sources

#git clone snort3/libdaq

#cd libdaq/

#./bootstrap // 該命令執行完畢產生configure文件

#./configure

該命令執行結果以下圖所示,如一致,方可繼續操做。

#make //make 是單核,make j$(nproc)能夠互換。

#make install

這裏安裝DAQ(數據採集庫)。Snort 3和Snort 2.9.x.x系列使用的是不一樣的DAQ。

6、安裝Hyperscan

Snort3將使用Hyperscan快速模式匹配。Hyperscan須要Ragel和Boost頭文件,因此咱們不能直接安裝Hyperscan,爲了一次性安裝Hyperscan分爲下面10個分步:

1.安裝 LZMA and UUID

#dnf install xz-devel libuuid-devel

2.安裝Python 和 Sqlite

#dnf install python3 sqlite-devel

3.安裝colm

[root@localhost sources]# pwd

/root/sources

#tar zxvf colm-0.13.0.7.tar.gz && cd colm-0.13.0.7

#./configure

#make -j$(nproc)

#make -j$(nproc) install

#ldconfig

4.安裝ragel

若是ragel包安裝不正確,會直接致使hyperscan沒法編譯。

curl -LO http://www.colm.net/files/ragel/ragel-7.0.0.12.tar.gz

#tar zxvf ragel-7.0.0.12.tar.gz && cd ragel-7.0.0.12

./configure

若是遇到錯誤configure: error: check colm: expected version 0.13.0.7, but is installed

多是colm沒安裝正確,可經過「dnf install colm」一條命令搞定。下面繼續編譯ragel

#make -j$(nproc) //多核編譯速度比單核快不少

#make -j$(nproc) install

#ldconfig

5.安裝boost

因爲Hyperscan須要Boost C++ Libraries, 要安裝Hyperscan,還須要boost庫版本爲1.58或者更高版本,下面咱們下載v1.72(這個包並不須要安裝)。

[root@localhost sources]# //當前目錄在/root/sources/

下載解壓縮bootst

#tar xf boost_1_72_0.tar.gz

將bootst解壓到當前目錄便可。

6.安裝hyperscan

通過上面5個步驟的準備工做以後,下面有請hyperscan正式出場。

#tar xf hyperscan-5.2.1.tar.gz

#mkdir hs-build && cd hs-build

建立軟連接文件

[root@localhost hs-build]# ln -s ~/sources/boost_1_72_0/boost ~/sources/hyperscan-5.2.1/include/boost

確保當前目錄爲/root/sources/hs-build/再輸入下列命令。

[root@localhost hs-build]# cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local/ ../hyperscan-5.2.1

咱們在安裝Hyperscan 5.1.1時,須要Boost頭文件引用的源目錄路徑。

安裝編譯過程當中,出現如下顯示內容,表示成功安裝:

Configuring done

-- Generating done

-- Build files have been written to: /root/sources/hs-build

下面繼續編譯Hyperscan (過程較慢)

[root@localhost hs-build]# make -j$(nproc) //nproc是讀取CPU的核心數量

見到如下內容,表示成功。

Scanning dependencies of target simplegrep

[ 99%] Building C object examples/CMakeFiles/simplegrep.dir/simplegrep.c.o

[100%] Linking CXX executable ../bin/simplegrep

[100%] Built target simplegrep

若是到這一步,表示編譯經過,安裝就很是簡單了。

#make -j$(nproc) install

見到如下內容表示安裝完成

-- Install configuration: "RELEASE"

-- Installing: /usr/local/lib64/pkgconfig/libhs.pc

-- Installing: /usr/local/include/hs/hs.h

-- Installing: /usr/local/include/hs/hs_common.h

-- Installing: /usr/local/include/hs/hs_compile.h

-- Installing: /usr/local/include/hs/hs_runtime.h

-- Installing: /usr/local/lib64/libhs_runtime.a

-- Installing: /usr/local/lib64/libhs.a

-- Installing: /usr/local/share/doc/hyperscan/examples/simplegrep.c

-- Installing: /usr/local/share/doc/hyperscan/examples/http://pcapscan.cc

-- Installing: /usr/local/share/doc/hyperscan/examples/http://patbench.cc

-- Installing: /usr/local/share/doc/hyperscan/examples/README.md

執行完成上面的命令,會在bin目錄下,將會產生7個文件

[root@localhost bin]# pwd

/root/sources/hs-build/bin

[root@localhost bin]# ls

hsbench hscheck hscollider patbench pcapscan simplegrep unit-hyperscan

7.測試Hyperscan

安裝好很差,測試說了算。下面咱們來測試一下安裝Hyperscan的成果吧。

[root@localhost bin]# ./unit-hyperscan

[==========] Running 3746 tests from 33 test cases.

[----------] Global test environment set-up.

[----------] 9 tests from CustomAllocator

[ RUN ] CustomAllocator.DatabaseInfoBadAlloc

[ OK ] CustomAllocator.DatabaseInfoBadAlloc (0 ms)

8.安裝flatbuffers

首先看一下當前目錄

[root@localhost sources]# pwd

/root/sources

#curl -Lo flatbuffers-1.12.tar.gz https://github.com/google/flatbuffers/archive/v1.12.0.tar.gz

#tar xf flatbuffers-1.12.tar.gz

#mkdir fb-build && cd fb-build

[root@localhost fb-build]#cmake ../flatbuffers-1.12.0

見到如下內容表示成功

-- Configuring done

-- Generating done

-- Build files have been written to: /root/sources/fb-build

#make -j$(nproc) //編譯時間比較長

[100%] Built target flatsamplebinary

#make -j$(nproc) install //在 /usr/local/lib64目錄增長了四個文件。

#ldconfig

#cd ../

9.安裝Safec

安裝safec有兩種方法,咱們任選其一便可:

方法1:

#dnf install libsafec libsafec-devel

#ln -s /usr/lib64/pkgconfig/safec-3.3.pc /usr/local/lib64/pkgconfig/libsafec.pc

注意上面這條命令,必須在Hyperscan正確安裝完成以後,才能執行。

方法2:

若是首選從源碼安裝那麼下面步驟

#curl -LO https://github.com/rurban/safeclib/releases/download/v08112019/libsafec-08112019.0-gad76c7.tar.gz :

#tar xf libsafec-08112019.0-gad76c7.tar.gz

#cd libsafec-08112019.0-gad76c7

[root@localhost libsafec-08112019.0-gad76c7]# ./configure

#make

make install

cd ../

10.安裝Tcmalloc

#wget https://github.com/gperftools/gperftools/releases/download/gperftools-2.8/gperftools-2.8.tar.gz

解包後執行下面命令

#./configure

#make

#make install

7、安裝Snort3

第六步中的10個分步驟是最難的一個環節,只有他們都安裝正確,才能進行這一步的安裝。

[root@localhost sources]#tar xvf snort3.tar.gz cd snort3

[root@localhost sources]# export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH

[root@localhost sources]# export PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:$PKG_CONFIG_PATH

[root@localhost sources]# echo $PKG_CONFIG_PATH //查看環境變量

Snort 3須要配置幾個環境變量才能正確運行。咱們將這些變量暫時存儲在當前會話而且永久保存到本地.bashrc文件中.直接添加到.bashrc文件中。例如:

#sh -c "echo 'export SNORT_LUA_PATH=/opt/snort/etc/snort' >> ~/.bashrc"

#./configure_cmake.sh --prefix=/usr/local/snort --enable-tcmalloc

其中/usr/local/snort就是snort3的安裝路徑。

--prefix=/usr/local/snort

上面這個參數,表示snort將文件安裝在/usr/local/snort目錄中。

#tree /usr/local/snort/ -Ld 3 //查看三層目錄

開始編譯snort3

[root@localhost snort3]# cd build/

[root@localhost snort3]#make -j$(nproc)

[root@localhost snort3]make -j$(nproc) install

[root@localhost snort3]cd ../../

典型編譯報錯:

Scanning dependencies of target rna

[ 80%] Building CXX object src/network_inspectors/rna/CMakeFiles/rna.dir/rna_event_handler.cc.o

[ 80%] Building CXX object src/network_inspectors/rna/CMakeFiles/rna.dir/rna_fingerprint_tcp.cc.o

In file included from /root/sources/snort3/src/network_inspectors/rna/rna_fingerprint_tcp.h:30,

from /root/sources/snort3/src/network_inspectors/rna/rna_fingerprint_tcp.cc:25:

/root/sources/snort3/src/network_inspectors/rna/rna_fingerprint.h:24:10: fatal error: uuid/uuid.h: No such file or directory

#include <uuid/uuid.h>

^~~~~

compilation terminated.

make[2]: *** [src/network_inspectors/rna/CMakeFiles/rna.dir/build.make:76: src/network_inspectors/rna/CMakeFiles/rna.dir/rna_fingerprint_tcp.cc.o] Error 1

make[1]: *** [CMakeFiles/Makefile2:5293: src/network_inspectors/rna/CMakeFiles/rna.dir/all] Error 2

make: *** [Makefile:152: all] Error 2

[root@localhost build]#

心得:若是編譯到80%失敗,通過調試後從新編譯,前面0~80%的部分會很是快。

8、啓動snort3

[root@localhost ~]# /usr/local/snort/bin/snort -V

,,_ -> Snort++ <-

o" )~ Version 3.0.2 (Build 5)

'''' By Martin Roesch & The Snort Team

Snort - Contact

Copyright (C) 2014-2020 Cisco and/or its affiliates. All rights reserved.

Copyright (C) 1998-2013 Sourcefire, Inc., et al.

Using DAQ version 3.0.0

Using LuaJIT version 2.0.4

Using OpenSSL 1.1.1c FIPS 28 May 2019

Using libpcap version 1.9.0-PRE-GIT (with TPACKET_V3)

Using PCRE version 8.42 2018-03-20

Using ZLIB version 1.2.11

Using FlatBuffers 1.12.0

Using Hyperscan version 5.2.1 2020-08-16

Using LZMA version 5.2.4

9、安裝snort3 Extra

[root@localhost sources]# git clone https://github.com/snort3/snort_extra.git

Cloning into 'snort_extra'...

Username for 'GitHub: Where the world builds software': ossimuser

Password for 'GitHub: Where the world builds software':

[root@192 ~]# git clone snort3/snort3_extra

正克隆到 'snort3_extra'...

remote: Enumerating objects: 545, done.

remote: Counting objects: 100% (545/545), done.

remote: Compressing objects: 100% (316/316), done.

remote: Total 3724 (delta 322), reused 433 (delta 227), pack-reused 3179

接收對象中: 100% (3724/3724), 713.88 KiB | 650.00 KiB/s, 完成.

處理 delta 中: 100% (2490/2490), 完成.

進行本實驗若是是在線下載源碼,必須註冊github帳戶。

在構建額外的插件以前,必須設置環境變量PKG_CONFIG_PATH。能夠經過列出Snort安裝目錄來驗證路徑。

[root@192 tmp]# cd snort3_extra/

[root@192 snort3_extra]# export PKG_CONFIG_PATH=/usr/local/snort/lib64/pkgconfig:$PKG_CONFIG_PATH

[root@192 snort3_extra]#

[root@192 snort3_extra]# ./configure_cmake.sh --prefix=/usr/local/snort/extra

見到下面輸出信息,表示成功

snort_extra version 1.0.0

Install options:

prefix: /usr/local/snort/extra

Compiler options:

CC: /usr/bin/cc

CXX: /usr/bin/c++

EXE_LDFLAGS:

MODULE_LDFLAGS:

-- Configuring done

-- Generating done

-- Build files have been written to: /root/snort3_extra/build

以上介紹的安裝Snort3.0擴展爲可選項,主要安裝就基本到這,後期還有大量有關Snort3配置的話題,咱們下期再聊吧。

相關文章
相關標籤/搜索