O、 閱讀要求
本教程并不適合初學(xué)者缩膝,大家在閱讀本文之前嚷堡,需具備CentOS 8 Linux、Snort 2.9的成功安裝經(jīng)驗(yàn)功氨。本次安裝對網(wǎng)絡(luò)依賴很大,所以大家一定要將網(wǎng)絡(luò)狀態(tài)調(diào)節(jié)好手幢,本指南介紹的內(nèi)容捷凄,僅在測試環(huán)境中使用。
一围来、環(huán)境
虛擬機(jī):VMware Workstation V15
安裝鏡像:CentOS 8 (CentOS-8.2.2004-x86_64-minimal.iso )
安裝方式:基于網(wǎng)絡(luò)安全方面的考慮跺涤,本實(shí)驗(yàn)采用最小化安裝CentOS 8、內(nèi)存(4G+)监透、CPU(4 core)桶错、磁盤空間(20G+)。
源碼位置:將各類安裝源碼包存放在/root/sources/,試驗(yàn)之初胀蛮,軟件包可從github克隆院刁。
二、CentOS8 mini系統(tǒng)初始化
當(dāng)CentOS8初次安裝完粪狼,系統(tǒng)還無法使用退腥。首先我們要配置網(wǎng)絡(luò)。這里我們?yōu)榫W(wǎng)卡配置靜態(tài)IP地址再榄。安裝系統(tǒng)時(shí)僅選擇Minimal Install最小化安裝狡刘,其他任何選項(xiàng)無需勾選。
三困鸥、啟用 EPEL 和 PowerTools軟件源
Snort編譯過程所需的某些開發(fā)包在CentOS 8默認(rèn)存儲庫中不可用嗅蔬,所以我們需要在系統(tǒng)中添加EPEL和PowerTools倉庫。
[root@localhost ~]#dnf config-manager --add-repo /etc/yum.repos.d/CentOS-PowerTools.repo
[root@localhost ~]# dnf config-manager --set-enabled PowerTools
[root@localhost ~]# dnf install epel-release
Tip:Centos7安裝了dnf也可以執(zhí)行這條命令。
安裝PowerTools存儲庫
啟用兩個存儲庫后澜术,請使用以下命令升級所有軟件包:
#dnf upgrade
Transaction Summary
===============================Install 13 Packages
Upgrade 259 Packages
Total download size: 291 M
Is this ok [y/N]:
大概升級內(nèi)容為291M艺蝴,更新結(jié)束后,重啟系統(tǒng)鸟废。
任務(wù)完成之后再次登錄系統(tǒng),在/etc/ld.so.conf.d/目錄下創(chuàng)建local.conf配置文件
#vi /etc/ld.so.conf.d/local.conf
添加下面內(nèi)容:
/usr/local/lib
/usr/local/lib64
保存退出
#ldconfig
四猜敢、安裝依賴包
安裝依賴包的環(huán)節(jié)非常重要。安裝依賴包比較多侮攀,我們先分解安裝
[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之前執(zhí)行锣枝。
安裝完所有軟件包后,下面需要從Git存儲庫下載LibDAQ兰英,并從下載的源代碼中進(jìn)行編譯撇叁。
五、安裝libDAQ
#cd sources
#git clone snort3/libdaq
#cd libdaq/
#./bootstrap // 該命令執(zhí)行完畢產(chǎn)生configure文件
#./configure
該命令執(zhí)行結(jié)果如下圖所示畦贸,如一致陨闹,方可繼續(xù)操作。
#make //make 是單核薄坏,make j$(nproc)可以互換趋厉。
#make install
這里安裝DAQ(數(shù)據(jù)采集庫)。Snort 3和Snort 2.9.x.x系列使用的是不同的DAQ胶坠。
六君账、安裝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包安裝不正確,會直接導(dǎo)致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”一條命令搞定。下面繼續(xù)編譯ragel
#make -j$(nproc) //多核編譯速度比單核快很多
#make -j$(nproc) install
#ldconfig
5.安裝boost
由于Hyperscan需要Boost C++ Libraries, 要安裝Hyperscan罩润,還需要boost庫版本為1.58或者更高版本玖翅,下面我們下載v1.72(這個包并不需要安裝)。
[root@localhost sources]# //當(dāng)前目錄在/root/sources/
下載解壓縮bootst
#tar xf boost_1_72_0.tar.gz
將bootst解壓到當(dāng)前目錄即可割以。
6.安裝hyperscan
經(jīng)過上面5個步驟的準(zhǔn)備工作之后金度,下面有請hyperscan正式出場。
#tar xf hyperscan-5.2.1.tar.gz
#mkdir hs-build && cd hs-build
創(chuàng)建軟鏈接文件
[root@localhost hs-build]# ln -s ~/sources/boost_1_72_0/boost ~/sources/hyperscan-5.2.1/include/boost
確保當(dāng)前目錄為/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時(shí)审姓,需要Boost頭文件引用的源目錄路徑。
安裝編譯過程中祝峻,出現(xiàn)以下顯示內(nèi)容,表示成功安裝:
Configuring done
-- Generating done
-- Build files have been written to: /root/sources/hs-build
下面繼續(xù)編譯Hyperscan (過程較慢)
[root@localhost hs-build]# make -j$(nproc) //nproc是讀取CPU的核心數(shù)量
見到以下內(nèi)容,表示成功莱找。
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
見到以下內(nèi)容表示安裝完成
-- 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
執(zhí)行完成上面的命令辞色,會在bin目錄下,將會產(chǎn)生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
首先看一下當(dāng)前目錄
[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
見到以下內(nèi)容表示成功
-- Configuring done
-- Generating done
-- Build files have been written to: /root/sources/fb-build
#make -j$(nproc) //編譯時(shí)間比較長
[100%] Built target flatsamplebinary
#make -j$(nproc) install //在 /usr/local/lib64目錄增加了四個文件桦卒。
#ldconfig
#cd ../
9.安裝Safec
安裝safec有兩種方法立美,我們?nèi)芜x其一即可:
方法1:
#dnf install libsafec libsafec-devel
#ln -s /usr/lib64/pkgconfig/safec-3.3.pc /usr/local/lib64/pkgconfig/libsafec.pc
注意上面這條命令,必須在Hyperscan正確安裝完成之后方灾,才能執(zhí)行建蹄。
方法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
解包后執(zhí)行下面命令
#./configure
#make
#make install
七、安裝Snort3
第六步中的10個分步驟是最難的一個環(huán)節(jié)裕偿,只有他們都安裝正確洞慎,才能進(jìn)行這一步的安裝。
[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 //查看環(huán)境變量
Snort 3需要配置幾個環(huán)境變量才能正確運(yùn)行嘿棘。我們將這些變量暫時(shí)存儲在當(dāng)前會話并且永久保存到本地.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
上面這個參數(shù)鸟妙,表示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 ../../
典型編譯報(bào)錯:
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%失敗,經(jīng)過調(diào)試后重新編譯圆仔,前面0~80%的部分會非忱疲快。
八坪郭、啟動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
九个从、安裝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), 完成.
進(jìn)行本實(shí)驗(yàn)如果是在線下載源碼,必須注冊github賬戶歪沃。
在構(gòu)建額外的插件之前嗦锐,必須設(shè)置環(huán)境變量PKG_CONFIG_PATH』κ铮可以通過列出Snort安裝目錄來驗(yàn)證路徑奕污。
[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擴(kuò)展為可選項(xiàng)液走,主要安裝就基本到這碳默,后期還有大量有關(guān)Snort3配置的話題贾陷,我們下期再聊吧。