天天看點

在 Ubuntu 15.04 中如何安裝和使用 Snort

對于網絡安全而言入侵檢測是一件非常重要的事。入侵檢測系統(ids)用于檢測網絡中非法與惡意的請求。snort是一款知名的開源的入侵檢測系統。其 web界面(snorby)可以用于更好地分析警告。snort使用iptables/pf防火牆來作為入侵檢測系統。本篇中,我們會安裝并配置一個開源的入侵檢測系統snort。

在 Ubuntu 15.04 中如何安裝和使用 Snort

<a target="_blank"></a>

snort所使用的資料采集庫(daq)用于一個調用包捕獲庫的抽象層。這個在snort上就有。下載下傳過程如下截圖所示。

在 Ubuntu 15.04 中如何安裝和使用 Snort

downloading_daq

解壓并運作./configure、make、make install來安裝daq。然而,daq要求其他的工具,是以,./configure腳本會生成下面的錯誤。

flex和bison錯誤

在 Ubuntu 15.04 中如何安裝和使用 Snort

flexandbison_error

libpcap錯誤

在 Ubuntu 15.04 中如何安裝和使用 Snort

libpcap error

是以在安裝daq之前先安裝flex/bison和libcap。

在 Ubuntu 15.04 中如何安裝和使用 Snort

install_flex

如下所示安裝libpcap開發庫

在 Ubuntu 15.04 中如何安裝和使用 Snort

libpcap-dev installation

安裝完必要的工具後,再次運作./configure腳本,将會顯示下面的輸出。

在 Ubuntu 15.04 中如何安裝和使用 Snort

without_error_configure

make和make install 指令的結果如下所示。

在 Ubuntu 15.04 中如何安裝和使用 Snort

make install

在 Ubuntu 15.04 中如何安裝和使用 Snort

make

成功安裝daq之後,我們現在安裝snort。如下圖使用wget下載下傳它。

在 Ubuntu 15.04 中如何安裝和使用 Snort

downloading_snort

使用下面的指令解壓安裝包。

<code>#tar -xvzf snort-2.9.7.3.tar.gz</code>

在 Ubuntu 15.04 中如何安裝和使用 Snort

snort_extraction

建立安裝目錄并在腳本中設定prefix參數。同樣也建議啟用包性能監控(ppm)的sourcefire标志。

<code>#mkdir /usr/local/snort</code>

<code></code>

<code>#./configure --prefix=/usr/local/snort/ --enable-sourcefire</code>

在 Ubuntu 15.04 中如何安裝和使用 Snort

snort_installation

配置腳本會由于缺少libpcre-dev、libdumbnet-dev 和zlib開發庫而報錯。

配置腳本由于缺少libpcre庫報錯。

在 Ubuntu 15.04 中如何安裝和使用 Snort

pcre-error

配置腳本由于缺少dnet(libdumbnet)庫而報錯。

在 Ubuntu 15.04 中如何安裝和使用 Snort

libdnt error

配置腳本由于缺少zlib庫而報錯

在 Ubuntu 15.04 中如何安裝和使用 Snort

zlib error

如下所示,安裝所有需要的開發庫。

<code># aptitude install libpcre3-dev</code>

在 Ubuntu 15.04 中如何安裝和使用 Snort

libpcre3-dev install

<code># aptitude install libdumbnet-dev</code>

在 Ubuntu 15.04 中如何安裝和使用 Snort

libdumnet-dev installation

<code># aptitude install zlib1g-dev</code>

在 Ubuntu 15.04 中如何安裝和使用 Snort

zlibg-dev installation

安裝完snort需要的庫之後,再次運作配置腳本就不會報錯了。

運作make和make install指令在/usr/local/snort目錄下完成安裝。

<code># make</code>

在 Ubuntu 15.04 中如何安裝和使用 Snort

make snort

<code># make install</code>

在 Ubuntu 15.04 中如何安裝和使用 Snort

make install snort

最後,從/usr/local/snort/bin中運作snort。現在它對eth0的所有流量都處在promisc模式(包轉儲模式)。

在 Ubuntu 15.04 中如何安裝和使用 Snort

snort running

如下圖所示snort轉儲流量。

在 Ubuntu 15.04 中如何安裝和使用 Snort

traffic

從源碼安裝的snort還需要設定規則和配置,是以我們需要複制規則和配置到/etc/snort下面。我們已經建立了單獨的bash腳本來用于設定規則和配置。它會設定下面這些snort設定。

在linux中建立用于snort ids服務的snort使用者。

在/etc下面建立snort的配置檔案和檔案夾。

權限設定并從源代碼的etc目錄中複制資料。

從snort檔案中移除規則中的#(注釋符号)。

<code>#!/bin/bash#</code>

<code># snort源代碼的路徑</code>

<code>snort_src="/home/test/downloads/snort-2.9.7.3"</code>

<code>echo "adding group and user for snort..."</code>

<code>groupadd snort &amp;&gt; /dev/null</code>

<code>useradd snort -r -s /sbin/nologin -d /var/log/snort -c snort_idps -g snort &amp;&gt; /dev/null#snort configuration</code>

<code>echo "configuring snort..."mkdir -p /etc/snort</code>

<code>mkdir -p /etc/snort/rules</code>

<code>touch /etc/snort/rules/black_list.rules</code>

<code>touch /etc/snort/rules/white_list.rules</code>

<code>touch /etc/snort/rules/local.rules</code>

<code>mkdir /etc/snort/preproc_rules</code>

<code>mkdir /var/log/snort</code>

<code>mkdir -p /usr/local/lib/snort_dynamicrules</code>

<code>chmod -r 775 /etc/snort</code>

<code>chmod -r 775 /var/log/snort</code>

<code>chmod -r 775 /usr/local/lib/snort_dynamicrules</code>

<code>chown -r snort:snort /etc/snort</code>

<code>chown -r snort:snort /var/log/snort</code>

<code>chown -r snort:snort /usr/local/lib/snort_dynamicrules</code>

<code>###copy configuration and rules from etc directory under source code of snort</code>

<code>echo "copying from snort source to /etc/snort ....."</code>

<code>echo $snort_src</code>

<code>echo "-------------"</code>

<code>cp $snort_src/etc/*.conf* /etc/snort</code>

<code>cp $snort_src/etc/*.map /etc/snort##enable rules</code>

<code>sed -i 's/include \$rule\_path/#include \$rule\_path/' /etc/snort/snort.conf</code>

<code>echo "---done---"</code>

改變腳本中的snort源目錄路徑并運作。下面是成功的輸出。

在 Ubuntu 15.04 中如何安裝和使用 Snort

running script

上面的腳本從snort源中複制下面的檔案和檔案夾到/etc/snort配置檔案中

在 Ubuntu 15.04 中如何安裝和使用 Snort

files copied

snort的配置非常複雜,要讓ids能正常工作需要進行下面必要的修改。

<code>ipvar home_net 192.168.1.0/24 # lan side</code>

<code>ipvar external_net !$home_net # wan side</code>

在 Ubuntu 15.04 中如何安裝和使用 Snort

veriable set

<code>var rule_path /etc/snort/rules # snort signature path</code>

<code>var so_rule_path /etc/snort/so_rules #rules in shared libraries</code>

<code>var preproc_rule_path /etc/snort/preproc_rules # preproces path</code>

<code>var white_list_path /etc/snort/rules # dont scan</code>

<code>var black_list_path /etc/snort/rules # must scan</code>

在 Ubuntu 15.04 中如何安裝和使用 Snort

main path

<code>include $rule_path/local.rules # file for custom rules</code>

移除ftp.rules、exploit.rules前面的注釋符号(#)。

在 Ubuntu 15.04 中如何安裝和使用 Snort

path rules

在 Ubuntu 15.04 中如何安裝和使用 Snort

wget_rules

在 Ubuntu 15.04 中如何安裝和使用 Snort

community rules

進行了上面的更改後,運作下面的指令來檢驗配置檔案。

<code># snort -t -c /etc/snort/snort.conf</code>

在 Ubuntu 15.04 中如何安裝和使用 Snort

本篇中,我們關注了開源idps系統snort在ubuntu上的安裝和配置。通常它用于監控事件,然而它可以被配置成用于網絡保護的線上模式。snort規則可以在離線模式中可以使用pcap捕獲檔案進行測試和分析

本文來自雲栖社群合作夥伴“linux中國”,原文釋出日期:2015-09-03