Suricataのインストールと設定
IDSだとsnortが有名ですが、IPSとして動作させるのは導入が大変そうなので、Suricataと導入してみます。
Suricataは、リアルタイム侵入検知(IDS)、インライン侵入防止(IPS)、ネットワークセキュリティ監視(NSM)、およびオフラインpcap処理が可能だそうです。
公式サイトはhttps://suricata-ids.org/download/です
Suricataのインストール
epelリポジトリからインストールします。epelリポジトリの導入についてはこちらを参照ください。
# yum --enablerepo=epel install suricata 読み込んだプラグイン:fastestmirror Loading mirror speeds from cached hostfile * base: ftp.iij.ad.jp * epel: ftp.iij.ad.jp * extras: ftp.iij.ad.jp * remi-safe: ftp.riken.jp * updates: ftp.iij.ad.jp 依存性の解決をしています --> トランザクションの確認を実行しています。 ---> パッケージ suricata.x86_64 0:4.0.5-3.el7 を インストール --> 依存性の処理をしています: libyaml-0.so.2()(64bit) のパッケージ: suricata-4.0.5-3.el7.x86_64 --> 依存性の処理をしています: libprelude.so.23()(64bit) のパッケージ: suricata-4.0.5-3.el7.x86_64 --> 依存性の処理をしています: libnetfilter_queue.so.1()(64bit) のパッケージ: suricata-4.0.5-3.el7.x86_64 --> 依存性の処理をしています: libnet.so.1()(64bit) のパッケージ: suricata-4.0.5-3.el7.x86_64 --> 依存性の処理をしています: libltdl.so.7()(64bit) のパッケージ: suricata-4.0.5-3.el7.x86_64 --> 依存性の処理をしています: libhiredis.so.0.12()(64bit) のパッケージ: suricata-4.0.5-3.el7.x86_64 --> 依存性の処理をしています: libevent_pthreads-2.0.so.5()(64bit) のパッケージ: suricata-4.0.5-3.el7.x86_64 --> 依存性の処理をしています: libevent-2.0.so.5()(64bit) のパッケージ: suricata-4.0.5-3.el7.x86_64 --> トランザクションの確認を実行しています。 ---> パッケージ hiredis.x86_64 0:0.12.1-1.el7 を インストール ---> パッケージ libevent.x86_64 0:2.0.21-4.el7 を インストール ---> パッケージ libnet.x86_64 0:1.1.6-7.el7 を インストール ---> パッケージ libnetfilter_queue.x86_64 0:1.0.2-2.el7_2 を インストール ---> パッケージ libprelude.x86_64 0:4.1.0-2.el7 を インストール ---> パッケージ libtool-ltdl.x86_64 0:2.4.2-22.el7_3 を インストール ---> パッケージ libyaml.x86_64 0:0.1.4-11.el7_0 を インストール --> 依存性解決を終了しました。 依存性を解決しました ======================================================================================================== Package アーキテクチャー バージョン リポジトリー 容量 ======================================================================================================== インストール中: suricata x86_64 4.0.5-3.el7 epel 1.1 M 依存性関連でのインストールをします: hiredis x86_64 0.12.1-1.el7 epel 29 k libevent x86_64 2.0.21-4.el7 base 214 k libnet x86_64 1.1.6-7.el7 base 59 k libnetfilter_queue x86_64 1.0.2-2.el7_2 base 23 k libprelude x86_64 4.1.0-2.el7 epel 305 k libtool-ltdl x86_64 2.4.2-22.el7_3 base 49 k libyaml x86_64 0.1.4-11.el7_0 base 55 k トランザクションの要約 ======================================================================================================== インストール 1 パッケージ (+7 個の依存関係のパッケージ) 総ダウンロード容量: 1.8 M インストール容量: 6.1 M Is this ok [y/d/N]: y Downloading packages: (1/8): libnetfilter_queue-1.0.2-2.el7_2.x86_64.rpm | 23 kB 00:00:01 (2/8): hiredis-0.12.1-1.el7.x86_64.rpm | 29 kB 00:00:01 (3/8): libprelude-4.1.0-2.el7.x86_64.rpm | 305 kB 00:00:01 (4/8): libnet-1.1.6-7.el7.x86_64.rpm | 59 kB 00:00:01 (5/8): libevent-2.0.21-4.el7.x86_64.rpm | 214 kB 00:00:01 (6/8): libtool-ltdl-2.4.2-22.el7_3.x86_64.rpm | 49 kB 00:00:00 (7/8): libyaml-0.1.4-11.el7_0.x86_64.rpm | 55 kB 00:00:00 (8/8): suricata-4.0.5-3.el7.x86_64.rpm | 1.1 MB 00:00:00 -------------------------------------------------------------------------------------------------------- 合計 1.1 MB/s | 1.8 MB 00:00:01 Running transaction check Running transaction test Transaction test succeeded Running transaction インストール中 : libtool-ltdl-2.4.2-22.el7_3.x86_64 1/8 インストール中 : libprelude-4.1.0-2.el7.x86_64 2/8 インストール中 : libnet-1.1.6-7.el7.x86_64 3/8 インストール中 : libevent-2.0.21-4.el7.x86_64 4/8 インストール中 : libnetfilter_queue-1.0.2-2.el7_2.x86_64 5/8 インストール中 : hiredis-0.12.1-1.el7.x86_64 6/8 インストール中 : libyaml-0.1.4-11.el7_0.x86_64 7/8 インストール中 : suricata-4.0.5-3.el7.x86_64 8/8 検証中 : libyaml-0.1.4-11.el7_0.x86_64 1/8 検証中 : hiredis-0.12.1-1.el7.x86_64 2/8 検証中 : suricata-4.0.5-3.el7.x86_64 3/8 検証中 : libnetfilter_queue-1.0.2-2.el7_2.x86_64 4/8 検証中 : libprelude-4.1.0-2.el7.x86_64 5/8 検証中 : libevent-2.0.21-4.el7.x86_64 6/8 検証中 : libtool-ltdl-2.4.2-22.el7_3.x86_64 7/8 検証中 : libnet-1.1.6-7.el7.x86_64 8/8 インストール: suricata.x86_64 0:4.0.5-3.el7 依存性関連をインストールしました: hiredis.x86_64 0:0.12.1-1.el7 libevent.x86_64 0:2.0.21-4.el7 libnet.x86_64 0:1.1.6-7.el7 libnetfilter_queue.x86_64 0:1.0.2-2.el7_2 libprelude.x86_64 0:4.1.0-2.el7 libtool-ltdl.x86_64 0:2.4.2-22.el7_3 libyaml.x86_64 0:0.1.4-11.el7_0 完了しました! #
最低限の設定をしたうえで起動します
HOME_NETにsuricataでチェック対象外とさせるIPを記載します
#vi /etc/suricata/suricata.yaml ・ ・ vars: # more specifc is better for alert accuracy and performance address-groups: HOME_NET: "[192.168.0.0/16,10.0.0.0/8,172.16.0.0/12]" #HOME_NET: "[192.168.0.0/16]" #HOME_NET: "[10.0.0.0/8]" #HOME_NET: "[172.16.0.0/12]" #HOME_NET: "any" EXTERNAL_NET: "!$HOME_NET" #EXTERNAL_NET: "any" ・ ・
Interfaceの設定を行います
/etc/sysconfig/box-title
# The following parameters are the most commonly needed to configure # suricata. A full list can be seen by running /sbin/suricata --help # -i <network interface device> # --user <acct name> # --group <group name> # Add options to be passed to the daemon #OPTIONS="-i eth0 --user suricata " OPTIONS="-i enp0s3 --user suricata " #
suricataを起動させます。
なにやらエラーがでました
# systemctl status suricata ● suricata.service - Suricata Intrusion Detection Service Loaded: loaded (/usr/lib/systemd/system/suricata.service; disabled; vendor preset: disabled) Active: inactive (dead) # ps -ef|grep suricata root 4651 3735 0 21:56 pts/0 00:00:00 grep --color=auto suricata # systemctl start suricata # systemctl status suricata ● suricata.service - Suricata Intrusion Detection Service Loaded: loaded (/usr/lib/systemd/system/suricata.service; disabled; vendor preset: disabled) Active: active (running) since 土 2018-09-01 21:56:50 JST; 6s ago Main PID: 4658 (Suricata-Main) CGroup: /system.slice/suricata.service mq4658 /sbin/suricata -c /etc/suricata/suricata.yaml -i eth0 --user suricata 9月 01 21:56:51 www2.itkiban.net suricata[4658]: 1/9/2018 -- 21:56:51 - - [ERRCODE: SC...les 9月 01 21:56:51 www2.itkiban.net suricata[4658]: 1/9/2018 -- 21:56:51 - - [ERRCODE: SC...les 9月 01 21:56:51 www2.itkiban.net suricata[4658]: 1/9/2018 -- 21:56:51 - - [ERRCODE: SC...les 9月 01 21:56:51 www2.itkiban.net suricata[4658]: 1/9/2018 -- 21:56:51 - - [ERRCODE: SC...les 9月 01 21:56:51 www2.itkiban.net suricata[4658]: 1/9/2018 -- 21:56:51 - - [ERRCODE: SC...les 9月 01 21:56:51 www2.itkiban.net suricata[4658]: 1/9/2018 -- 21:56:51 - - [ERRCODE: SC...les 9月 01 21:56:51 www2.itkiban.net suricata[4658]: 1/9/2018 -- 21:56:51 - - [ERRCODE: SC...les 9月 01 21:56:51 www2.itkiban.net suricata[4658]: 1/9/2018 -- 21:56:51 - - [ERRCODE: SC...les 9月 01 21:56:51 www2.itkiban.net suricata[4658]: 1/9/2018 -- 21:56:51 - - [ERRCODE: SC...les 9月 01 21:56:51 www2.itkiban.net suricata[4658]: 1/9/2018 -- 21:56:51 - - all 2 packet ...ed. Hint: Some lines were ellipsized, use -l to show in full.
ルールファイルがないと・・・
# suricata -c /etc/suricata/suricata.yaml -i eth0 --init-errors-fatal 1/9/2018 -- 21:54:39 - - This is Suricata version 4.0.5 RELEASE 1/9/2018 -- 21:54:39 - - [ERRCODE: SC_ERR_NO_RULES(42)] - No rule files match the pattern /etc/suricata/rules/botcc.rules #
suricataにも記載されているoinkmasterを利用して、ルールを最新化するようにします。
ここから、oinkmasterをダウンロードします。
# curl -O https://jaist.dl.sourceforge.net/project/oinkmaster/oinkmaster/2.0/oinkmaster-2.0.tar.gz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 80111 100 80111 0 0 134k 0 --:--:-- --:--:-- --:--:-- 134k
# tar xvfz oinkmaster-2.0.tar.gz # cp oinkmaster.pl /usr/local/sbin # cp oinkmaster.conf /etc/suricata/ # cp oinkmaster.1 /usr/share/man/man1
oinkmasterの設定を行います。ルールをダウンロードするURLを追記します。
# vi /etc/suricata/oinkmaster.conf
# URL examples follows. Replace <oinkcode> with the code you get on the
# Snort site in your registered user profile.
# Example for Snort 2.4
# url = http://www.snort.org/pub-bin/oinkmaster.cgi/<oinkcode>/snortrules-snapshot-2.4.tar.gz
# Example for Snort-current ("current" means cvs snapshots).
# url = http://www.snort.org/pub-bin/oinkmaster.cgi/snortrules-snapshot-CURRENT.tar.gz
# Example for Community rules
# url = http://www.snort.org/pub-bin/downloads.cgi/Download/comm_rules/Community-Rules.tar.gz
# Example for rules from the Bleeding Snort project
# url = http://www.bleedingsnort.com/bleeding.rules.tar.gz
url = http://rules.emergingthreats.net/open/suricata/emerging.rules.tar.gz ←ここを追加する
suricata.yamlの設定を変更します。
# vi /etc/suricata/suricata.yaml #classification-file: /etc/suricata/classification.config ←コメントアウト
#reference-config-file: /etc/suricata/reference.config ←コメントアウト
# threshold-file: /etc/suricata/threshold.config
classification-file: /etc/suricata/rules/classification.config ←追記
reference-config-file: /etc/suricata/rules/reference.config ←追記
ルールをダウンロードします。
# /usr/local/sbin/oinkmaster.pl -C /etc/suricata/oinkmaster.conf -o /etc/suricata/rules Loading /etc/suricata/oinkmaster.conf Downloading file from http://rules.emergingthreats.net/open/suricata/emerging.rules.tar.gz... Can't exec "wget": そのようなファイルやディレクトリはありません at /usr/local/sbin/oinkmaster.pl line 910. /usr/local/sbin/oinkmaster.pl: Error: could not open /tmp/oinkmaster.Dd2V56LOaT/wget.log for reading: そのようなファイルやディレクトリはありません Oink, oink. Exiting... #
wgetがないと上記のように怒られるのでwgetをインストールして再実行します。
# /usr/local/sbin/oinkmaster.pl -C /etc/suricata/oinkmaster.conf -o /etc/suricata/rules Loading /etc/suricata/oinkmaster.conf Downloading file from http://rules.emergingthreats.net/open/suricata/emerging.rules.tar.gz... done. Archive successfully downloaded, unpacking... done. Setting up rules structures... done. Processing downloaded rules... disabled 0, enabled 0, modified 0, total=25868 Setting up rules structures... done. Comparing new files to the old ones... done. Updating local rules files... done. [***] Results from Oinkmaster started 20180908 22:34:03 [***] [*] Rules modifications: [*] None. [*] Non-rule line modifications: [*] None. [+] Added files (consider updating your snort.conf to include them if needed): [+] -> botcc.portgrouped.rules -> botcc.rules -> BSD-License.txt -> ciarmy.rules -> classification.config -> compromised-ips.txt -> compromised.rules -> drop.rules -> dshield.rules -> emerging-activex.rules -> emerging-attack_response.rules -> emerging-chat.rules -> emerging-current_events.rules -> emerging-deleted.rules -> emerging-dns.rules -> emerging-dos.rules -> emerging-exploit.rules -> emerging-ftp.rules -> emerging-games.rules -> emerging-icmp.rules -> emerging-icmp_info.rules -> emerging-imap.rules -> emerging-inappropriate.rules -> emerging-info.rules -> emerging-malware.rules -> emerging-misc.rules -> emerging-mobile_malware.rules -> emerging-netbios.rules -> emerging-p2p.rules -> emerging-policy.rules -> emerging-pop3.rules -> emerging-rpc.rules -> emerging-scada.rules -> emerging-scan.rules -> emerging-shellcode.rules -> emerging-smtp.rules -> emerging-snmp.rules -> emerging-sql.rules -> emerging-telnet.rules -> emerging-tftp.rules -> emerging-trojan.rules -> emerging-user_agents.rules -> emerging-voip.rules -> emerging-web_client.rules -> emerging-web_server.rules -> emerging-web_specific_apps.rules -> emerging-worm.rules -> emerging.conf -> gen-msg.map -> gpl-2.0.txt -> rbn-malvertisers.rules -> rbn.rules -> reference.config -> sid-msg.map -> suricata-2.0-enhanced-open.txt -> tor.rules -> unicode.map #
毎日自動で更新するための実行用のスクリプトを用意して、cronに実施させます。
# vi /etc/cron.daily/suricata-rule-update.sh ← Oinkmaster定期自動実行スクリプト作成 #!/bin/bash /usr/local/bin/oinkmaster.pl -C /etc/suricata/oinkmaster.conf -o /etc/suricata/rules 2>&1 | logger -t oinkmaster /usr/bin/systemctl restart suricata # chmod +x /etc/cron.daily/suricata-rule-update.sh ← Oinkmaster定期自動実行スクリプトへ実行権限付加
最後に自動起動させるようにします
# systemctl enable suricata
ログは /var/log/suricataに出力されますが、見づらいのでsnorbyなどを導入すると見やすくなります。