LoginSignup
7

More than 5 years have passed since last update.

CentOS 7 Suricata 4.0.4のソースファイルからのインストール

Last updated at Posted at 2018-03-19

動作確認環境

事情によりバージョンをダウングレードしました。新しいバージョンでも動作するはずです。

  • 仮想環境 VMware Workstation Player 12.5.9
  • OS Windows 10 Pro 64bit

仮想環境

  • OS CentOS 7.4 (1708) minimalインストール
  • メモリ 2GB
  • HDD 250GB

前提条件

  • gcc 8.1.0
  • cmake 3.11.4
  • MySQL 5.7.22
  • OpenSSL 1.1.0.h
  • Apache 2.4.33
  • PHP 7.2.6

ユーザ作成

useradd suricata
passwd suricata
パスワードを入力
visudo

suricataユーザにsudo権限を与えるため、sudoersファイル(sudoコマンドのための設定ファイル)に以下の文を追記する。

suricata ALL=(ALL) ALL

ダウンロード・展開

最新バージョン確認
Download | Suricata

yum -y install epel-release
yum -y install libpcap-devel pcre-devel libyaml-devel file-devel zlib-devel jansson-devel nss-devel libcap-ng-devel libnet-devel tar make libnetfilter_queue-devel lua-devel

/usr/local/srcディレクトリに移動する。

cd /usr/local/src

ソースファイルをダウンロードする。

wget https://www.openinfosecfoundation.org/download/suricata-4.0.4.tar.gz

ダウンロードしたファイルを展開する。

tar xvzf suricata-4.0.4.tar.gz

展開したディレクトリに移動する。

cd suricata-4.0.4

コンパイル・インストール

./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --enable-nfqueue --enable-lua
make
make install

セットアップ

ディレクトリを作成する。

mkdir /var/log/suricata
mkdir /etc/suricata

ディレクトリの所有者・グループを変更する。

chown -R suricata:suricata /var/log/suricata/
chown -R suricata:suricata /etc/suricata/

必要なファイルをコピーする。

cp classification.config /etc/suricata
cp reference.config /etc/suricata
cp suricata.yaml /etc/suricata
cp -p /etc/suricata/suricata.yaml /etc/suricata/suricata.yaml.org

suricata.yamlを編集する。

vi /etc/suricata/suricata.yaml

HOME_NET: "[サーバのネットワーク]"を追記する。
HOME_NET: "[192.168.0.0/16,10.0.0.0/8,172.16.0.0/12]"はコメントアウトする。
サーバのネットワークは、サーバのIPアドレスが192.168.10.100の場合、192.168.10.0/24となる。

vars:
 address-groups:
 HOME_NET: "[192.168.10.0/24]"
 #HOME_NET: "[192.168.0.0/16,10.0.0.0/8,172.16.0.0/12]"

続けてwindows: [0.0.0.0/0]をコメントアウトする。
linux: [192.168.10.0/24]にサーバのネットワークを追記する。

host-os-policy:
# Make the default policy windows.
# windows: [0.0.0.0/0]
windows: []
bsd: []
bsd-right: []
old-linux: []
linux: [192.168.10.0/24]
old-solaris: []
solaris: []
hpux10: []
hpux11: []
irix: []
macos: []
vista: []
windows2k3: []

ディレクトリの下層に移動する。

cd ..

ルールセットの設定

wget https://sourceforge.net/projects/oinkmaster/files/oinkmaster/2.0/oinkmaster-2.0.tar.gz

ダウンロードしたファイルを展開する。

tar -xvzf oinkmaster-2.0.tar.gz

展開したディレクトリに移動する。

cd oinkmaster-2.0

必要なファイルをコピーする。

cp -p oinkmaster.pl /usr/local/bin
cp -p oinkmaster.conf /etc/
cp -p oinkmaster.1 /usr/share/man/man1/
cp -p /etc/oinkmaster.conf /etc/oinkmaster.conf.org

oinkmaster.confを編集する。

vi /etc/oinkmaster.conf

url = http://rules.emergingthreats.net/open/suricata/emerging.rules.tar.gzを追記する。

oinkmaster.conf
 # Example for Community rules
 # url = //Download/comm_rules/Community-Rules.tar.gz
  url = http://rules.emergingthreats.net/open/suricata/emerging.rules.tar.gz

ディレクトリを作成する。

mkdir /etc/suricata/rules

oinkmaster.plを実行する。

/usr/local/src/oinkmaster-2.0/oinkmaster.pl -C /etc/oinkmaster.conf -o /etc/suricata/rules

ディレクトリを移動する。

cd /etc/suricata

ファイルをダウンロードする。

wget http://rules.emergingthreats.net/open/suricata/emerging.rules.tar.gz

ダウンロードしたファイルを展開する。

tar -xvzf emerging.rules.tar.gz

ディレクトリの所有者・グループを変更する。

chown -R suricata:suricata /etc/suricata/rules

suricata.yamlを編集します。

vi /etc/suricata/suricata.yaml

以下の文をコメントアウトする。

 # - http-events.rules    # available in suricata sources under rules dir
 # - smtp-events.rules    # available in suricata sources under rules dir
 # - dns-events.rules     # available in suricata sources under rules dir
 # - tls-events.rules     # available in suricata sources under rules dir

 # classification-file: /etc/suricata/classification.config
 # reference-config-file: /etc/suricata/reference.config

以下の文を追記します。

 classification-file: /etc/suricata/rules/classification.config
 reference-config-file: /etc/suricata/rules/reference.config

エラー対策

threshold.configのエラー

suricata -c /etc/suricata/suricata.yaml -i eth0でsuricataを実行するが、threshold.configのファイルが無くエラーで停止する。

19/3/2018 -- 17:09:29 - <Notice> - This is Suricata version 4.0.4 RELEASE
19/3/2018 -- 17:09:31 - <Warning> - [ERRCODE: SC_ERR_FOPEN(44)] - Error opening file: "/etc/suricata//threshold.config": No such file or directory
19/3/2018 -- 17:09:32 - <Notice> - all 1 packet processing threads, 4 management threads initialized, engine started.

対策として、空のファイルthreshold.configを作成する。

vi /etc/suricata//threshold.config

再度、suricataを実行する。

suricata -c /etc/suricata/suricata.yaml -i eth0

ログが表示される。Ctrl+Cで動作を停止させる。

libhtp.so.2のエラー

suricata -c /etc/suricata/suricata.yaml -i eth0でsuricataを実行するが、libhtp.so.2のエラーで停止する。

suricata: error while loading shared libraries: libhtp.so.2: cannot open shared object file: No such file or directory

対策として、ldconfigを実行してから、再度、suricataを実行する。

suricata -c /etc/suricata/suricata.yaml -i eth0

ログが表示される。Ctrl+Cで動作を停止させる。

Suricataのログを確認

ディレクトリを移動する。

cd /var/log/suricata

ログを表示する。

tail -n 50 stats.log

stats.logのログの内容。

stats.log
decoder.udp                                | Total                     | 46
decoder.icmpv4                             | Total                     | 1
decoder.icmpv6                             | Total                     | 12
decoder.avg_pkt_size                       | Total                     | 358
decoder.max_pkt_size                       | Total                     | 1468
flow.tcp                                   | Total                     | 26
flow.udp                                   | Total                     | 10
flow.icmpv6                                | Total                     | 6
app_layer.flow.dns_udp                     | Total                     | 4
app_layer.tx.dns_udp                       | Total                     | 4
app_layer.flow.failed_udp                  | Total                     | 6
flow.spare                                 | Total                     | 10000
flow_mgr.flows_checked                     | Total                     | 9
flow_mgr.flows_notimeout                   | Total                     | 9
flow_mgr.rows_checked                      | Total                     | 65536
flow_mgr.rows_skipped                      | Total                     | 65527
flow_mgr.rows_maxlen                       | Total                     | 1
tcp.memuse                                 | Total                     | 573440
tcp.reassembly_memuse                      | Total                     | 81920
dns.memuse                                 | Total                     | 1264
flow.memuse                                | Total                     | 7086400
------------------------------------------------------------------------------------
Date: 3/19/2018 -- 17:10:47 (uptime: 0d, 00h 00m 18s)
------------------------------------------------------------------------------------
Counter                                    | TM Name                   | Value
------------------------------------------------------------------------------------
(以下略)

自動起動できるようファイルを作成する。

vi /usr/lib/systemd/system/suricata@.service
suricata@.service
[Unit]
Description=Suricata Intrusion Detection Service listening on '%I'
After=network.target

[Service]
Type=forking
ExecStart=/usr/bin/suricata -c /etc/suricata/suricata.yaml -i %i -D
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target

作成後、更新する。

systemctl daemon-reload

システム再起動時の自動起動設定

systemctl enable suricata@eth0.service

以下のような表示をする。

Created symlink from /etc/systemd/system/multi-user.target.wants/suricata@eth0.service to /usr/lib/systemd/system/suricata@.service.

起動

systemctl start suricata@eth0.service

ステータス確認

systemctl status suricata@eth0.service

以下のような表示をする。

● suricata@eth0.service - Suricata Intrusion Detection Service listening on 'eth0'
   Loaded: loaded (/usr/lib/systemd/system/suricata@.service; enabled; vendor preset: disabled)
   Active: active (running) since 月 2018-03-19 17:13:21 JST; 13s ago
  Process: 13350 ExecStart=/usr/bin/suricata -c /etc/suricata/suricata.yaml -i %i -D (code=exited, status=0/SUCCESS)
 Main PID: 13351 (Suricata-Main)
   CGroup: /system.slice/system-suricata.slice/suricata@eth0.service
           mq13351 /usr/bin/suricata -c /etc/suricata/suricata.yaml -i eth0 -...

 3月 19 17:13:21 knut systemd[1]: Starting Suricata Intrusion Detection Se.....
 3月 19 17:13:21 knut suricata[13350]: 19/3/2018 -- 17:13:21 - <Notice> - T...E
 3月 19 17:13:21 knut systemd[1]: Started Suricata Intrusion Detection Ser...'.
Hint: Some lines were ellipsized, use -l to show in full.

参考

【初心者向け】オープンソースのIPS「Suricata」をCentOSに構築した話 - Qiita
Suricata - ArchWiki
Suricata/Installation-and-basic-configuration - aldeid
suricata: error while loading shared libraries: libhtp-0.5.10.so.1 - Google グループ


目次

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7