基于CentOS 8 系統(tǒng)環(huán)境下的 Snort 3 安裝指南


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配置的話題贾陷,我們下期再聊吧。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末嘱根,一起剝皮案震驚了整個濱河市髓废,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌该抒,老刑警劉巖慌洪,帶你破解...
    沈念sama閱讀 216,372評論 6 498
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異凑保,居然都是意外死亡冈爹,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,368評論 3 392
  • 文/潘曉璐 我一進(jìn)店門欧引,熙熙樓的掌柜王于貴愁眉苦臉地迎上來频伤,“玉大人,你說我怎么就攤上這事维咸〖谅颍” “怎么了?”我有些...
    開封第一講書人閱讀 162,415評論 0 353
  • 文/不壞的土叔 我叫張陵癌蓖,是天一觀的道長瞬哼。 經(jīng)常有香客問我,道長租副,這世上最難降的妖魔是什么坐慰? 我笑而不...
    開封第一講書人閱讀 58,157評論 1 292
  • 正文 為了忘掉前任,我火速辦了婚禮用僧,結(jié)果婚禮上结胀,老公的妹妹穿的比我還像新娘。我一直安慰自己责循,他們只是感情好糟港,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,171評論 6 388
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著院仿,像睡著了一般秸抚。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上歹垫,一...
    開封第一講書人閱讀 51,125評論 1 297
  • 那天剥汤,我揣著相機(jī)與錄音,去河邊找鬼排惨。 笑死吭敢,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的暮芭。 我是一名探鬼主播鹿驼,決...
    沈念sama閱讀 40,028評論 3 417
  • 文/蒼蘭香墨 我猛地睜開眼欲低,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了蠢沿?” 一聲冷哼從身側(cè)響起伸头,我...
    開封第一講書人閱讀 38,887評論 0 274
  • 序言:老撾萬榮一對情侶失蹤匾效,失蹤者是張志新(化名)和其女友劉穎舷蟀,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體面哼,經(jīng)...
    沈念sama閱讀 45,310評論 1 310
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡野宜,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,533評論 2 332
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了魔策。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片匈子。...
    茶點(diǎn)故事閱讀 39,690評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖闯袒,靈堂內(nèi)的尸體忽然破棺而出虎敦,到底是詐尸還是另有隱情,我是刑警寧澤政敢,帶...
    沈念sama閱讀 35,411評論 5 343
  • 正文 年R本政府宣布其徙,位于F島的核電站,受9級特大地震影響喷户,放射性物質(zhì)發(fā)生泄漏唾那。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,004評論 3 325
  • 文/蒙蒙 一褪尝、第九天 我趴在偏房一處隱蔽的房頂上張望闹获。 院中可真熱鬧,春花似錦河哑、人聲如沸避诽。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,659評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽沙庐。三九已至,卻和暖如春睬罗,著一層夾襖步出監(jiān)牢的瞬間轨功,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,812評論 1 268
  • 我被黑心中介騙來泰國打工容达, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留古涧,地道東北人。 一個月前我還...
    沈念sama閱讀 47,693評論 2 368
  • 正文 我出身青樓花盐,卻偏偏與公主長得像羡滑,于是被迫代替她去往敵國和親菇爪。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,577評論 2 353

推薦閱讀更多精彩內(nèi)容

  • 泛黃的留言冊 寧靜花開 昨天收拾書櫥柒昏,翻出了泛黃的留言冊凳宙,讀著讀著不禁淚眼婆娑。留言冊是我們那個時(shí)代的...
    寧靜花開閱讀 175評論 0 0
  • 疫情期間龍崗區(qū)圖書館龍嶺學(xué)校分館開放通知 親愛的各位讀者: 為滿足廣大讀者借還書需求职祷,根據(jù)校新冠肺炎疫情防控工作領(lǐng)...
    燕兒在云梢閱讀 289評論 0 0
  • 這個假期從當(dāng)當(dāng)網(wǎng)買了兩次書氏涩,第一次買了當(dāng)年明月的《明朝那些事兒》,一共九本有梆,花了156元是尖。第二次買了蘇霍姆林斯基的...
    鵬飛翔閱讀 112評論 0 0
  • 勿以小節(jié)而不拘 近來欣聞研究生院為了進(jìn)一步提高研究生教學(xué)質(zhì)量,推出課程教學(xué)工作大檢查的舉措泥耀。效果顯著饺汹,公共課的出勤...
    魚漁語文劉十六閱讀 125評論 0 2
  • 久違的晴天,家長會痰催。 家長大會開好到教室時(shí)兜辞,離放學(xué)已經(jīng)沒多少時(shí)間了。班主任說已經(jīng)安排了三個家長分享經(jīng)驗(yàn)夸溶。 放學(xué)鈴聲...
    飄雪兒5閱讀 7,520評論 16 22