はじめに
AmazonLinux2にインストールしたOSSECのコンフィグ設定ファイル(/var/ossec/etc/ossec.conf)について、内容を確認してみます。今回は、OSSECのエージェントとマネージャーのコンフィグ設定ファイルの内容を比較することで、エージェントとマネージャーの機能の違いも理解していければと思います。
なお、OSSECのインストール手順にご興味のある方は以下の記事を参照ください。
- Amazon Linux2にOSSECをインストールした(OSSEC-Serverインストール)
- Amazon Linux2にOSSECをインストールした(OSSEC-Agentインストール)
- Amazon Linux2にOSSECをインストールした(OSSEC-Localインストール)
概要
OSSECは、マネージャーとエージェントがあり、マネージャーはルールに基づいた不正の検知、通知を行うのが主な仕事です。一方、エージェントは監視対象のログファイルやシステム情報をマネージャーに通知します。簡単にいうと、エージェントは、せっせと監視している内容をマネージャーに伝えるのが仕事で、内容の判断や判断に基づく行動はマネージャーの仕事です。エージェントへの行動の指示もマネージャーのお仕事です。今回は、そういったOSSECエージェントとマネージャーの具体的な動作について、コンフィグ設定から分かる内容と思い、記事にしています。
コンフィグ設定
OSSECエージェント
- OSSECマネージャーのサーバIPアドレス
- systemcheck対象のディレクトリ
- rootkit検知設定
- 監視対象ファイル
- 監視対象コマンド
OSSECマネージャー
- メール通知設定
- ルール設定
- ホワイトリスト設定
- remote設定
- alert設定
- ActiveResponse設定(発動条件と実行コマンド)
以下、エージェントと同じ - systemcheck対象のディレクトリ
- rootkit検知設定
- 監視対象ファイル
- 監視対象コマンド
OSSECエージェントのコンフィグ設定ファイル(/var/ossec/etc/ossec.conf)について
OSSECマネージャーのサーバIPアドレス
<ossec_config>
<client>
<server-ip>xxx.xxx.xxx.xxx</server-ip>
<config-profile></config-profile>
</client>
syscheckのコンフィグ設定
syscheckを実施する頻度
79200秒 ÷ 3600秒 = 22時間おきにチェックする
<syscheck>
<!-- Frequency that syscheck is executed - default to every 22 hours -->
<frequency>79200</frequency>
syschek対象ディレクトリ
<!-- Directories to check (perform all possible verifications) -->
<directories check_all="yes">/etc,/usr/bin,/usr/sbin</directories>
<directories check_all="yes">/bin,/sbin,/boot</directories>
syschek対象ディレクトリ配下でチェック対象から除外するディレクトリ
<!-- Files/directories to ignore -->
<ignore>/etc/mtab</ignore>
<ignore>/etc/mnttab</ignore>
<ignore>/etc/hosts.deny</ignore>
<ignore>/etc/mail/statistics</ignore>
<ignore>/etc/random-seed</ignore>
<ignore>/etc/adjtime</ignore>
<ignore>/etc/httpd/logs</ignore>
<ignore>/etc/utmpx</ignore>
<ignore>/etc/wtmpx</ignore>
<ignore>/etc/cups/certs</ignore>
<ignore>/etc/dumpdates</ignore>
<ignore>/etc/svc/volatile</ignore>
<!-- Windows files to ignore -->
<ignore>C:\WINDOWS/System32/LogFiles</ignore>
<ignore>C:\WINDOWS/Debug</ignore>
<ignore>C:\WINDOWS/WindowsUpdate.log</ignore>
<ignore>C:\WINDOWS/iis6.log</ignore>
<ignore>C:\WINDOWS/system32/wbem/Logs</ignore>
<ignore>C:\WINDOWS/system32/wbem/Repository</ignore>
<ignore>C:\WINDOWS/Prefetch</ignore>
<ignore>C:\WINDOWS/PCHEALTH/HELPCTR/DataColl</ignore>
<ignore>C:\WINDOWS/SoftwareDistribution</ignore>
<ignore>C:\WINDOWS/Temp</ignore>
<ignore>C:\WINDOWS/system32/config</ignore>
<ignore>C:\WINDOWS/system32/spool</ignore>
<ignore>C:\WINDOWS/system32/CatRoot</ignore>
rootcheckのコンフィグ設定
<rootcheck>
<rootkit_files>/var/ossec/etc/shared/rootkit_files.txt</rootkit_files>
<rootkit_trojans>/var/ossec/etc/shared/rootkit_trojans.txt</rootkit_trojans>
<system_audit>/var/ossec/etc/shared/system_audit_rcl.txt</system_audit>
<system_audit>/var/ossec/etc/shared/cis_debian_linux_rcl.txt</system_audit>
<system_audit>/var/ossec/etc/shared/cis_rhel_linux_rcl.txt</system_audit>
<system_audit>/var/ossec/etc/shared/cis_rhel5_linux_rcl.txt</system_audit>
</rootcheck>
localfileチェックのコンフィグ設定
チェック対象のファイル
<localfile>
<log_format>syslog</log_format>
<location>/var/log/messages</location>
</localfile>
<localfile>
<log_format>syslog</log_format>
<location>/var/log/secure</location>
</localfile>
<localfile>
<log_format>syslog</log_format>
<location>/var/log/maillog</location>
</localfile>
チェック対象のコマンド
- df -P : ディスク容量表示
- netstat -tan : ネットワークに関する情報表示 -t:tcp, -a:全て, -n:名前解決せず数字で表示
- last -n 5 : 最近ログインしたユーザリストを表示
<localfile>
<log_format>command</log_format>
<command>df -P</command>
</localfile>
<localfile>
<log_format>full_command</log_format>
<command>netstat -tan |grep LISTEN |egrep -v '(127.0.0.1| ::1)' | sort</command>
</localfile>
<localfile>
<log_format>full_command</log_format>
<command>last -n 5</command>
</localfile>
OSSECマネージャーのコンフィグ設定ファイル(/var/ossec/etc/ossec.conf)について
メール通知設定
<global>
<email_notification>yes</email_notification>
<email_to>通知先メールアドレス</email_to>
<smtp_server>メール送信するSMTPサーバ</smtp_server>
<email_from>メール送信元に設定するFromアドレス</email_from>
</global>
ルール設定
<rules>
<include>rules_config.xml</include>
<include>pam_rules.xml</include>
<include>sshd_rules.xml</include>
<include>telnetd_rules.xml</include>
<include>syslog_rules.xml</include>
<include>arpwatch_rules.xml</include>
<include>symantec-av_rules.xml</include>
<include>symantec-ws_rules.xml</include>
<include>pix_rules.xml</include>
<include>named_rules.xml</include>
省略
syscheckのコンフィグ設定
syscheckを実施する頻度
79200秒 ÷ 3600秒 = 22時間おきにチェックする
<syscheck>
<!-- Frequency that syscheck is executed - default to every 22 hours -->
<frequency>79200</frequency>
syscheck対象ディレクトリ
<!-- Directories to check (perform all possible verifications) -->
<directories check_all="yes">/etc,/usr/bin,/usr/sbin</directories>
<directories check_all="yes">/bin,/sbin,/boot</directories>
syscheck対象ディレクトリ配下でチェック対象から除外するディレクトリ
<!-- Files/directories to ignore -->
<ignore>/etc/mtab</ignore>
<ignore>/etc/mnttab</ignore>
<ignore>/etc/hosts.deny</ignore>
<ignore>/etc/mail/statistics</ignore>
<ignore>/etc/random-seed</ignore>
<ignore>/etc/adjtime</ignore>
<ignore>/etc/httpd/logs</ignore>
<ignore>/etc/utmpx</ignore>
<ignore>/etc/wtmpx</ignore>
<ignore>/etc/cups/certs</ignore>
<ignore>/etc/dumpdates</ignore>
<ignore>/etc/svc/volatile</ignore>
<!-- Windows files to ignore -->
<ignore>C:\WINDOWS/System32/LogFiles</ignore>
<ignore>C:\WINDOWS/Debug</ignore>
<ignore>C:\WINDOWS/WindowsUpdate.log</ignore>
<ignore>C:\WINDOWS/iis6.log</ignore>
<ignore>C:\WINDOWS/system32/wbem/Logs</ignore>
<ignore>C:\WINDOWS/system32/wbem/Repository</ignore>
<ignore>C:\WINDOWS/Prefetch</ignore>
<ignore>C:\WINDOWS/PCHEALTH/HELPCTR/DataColl</ignore>
<ignore>C:\WINDOWS/SoftwareDistribution</ignore>
<ignore>C:\WINDOWS/Temp</ignore>
<ignore>C:\WINDOWS/system32/config</ignore>
<ignore>C:\WINDOWS/system32/spool</ignore>
<ignore>C:\WINDOWS/system32/CatRoot</ignore>
rootcheckのコンフィグ設定
<rootcheck>
<rootkit_files>/var/ossec/etc/shared/rootkit_files.txt</rootkit_files>
<rootkit_trojans>/var/ossec/etc/shared/rootkit_trojans.txt</rootkit_trojans>
<system_audit>/var/ossec/etc/shared/system_audit_rcl.txt</system_audit>
<system_audit>/var/ossec/etc/shared/cis_debian_linux_rcl.txt</system_audit>
<system_audit>/var/ossec/etc/shared/cis_rhel_linux_rcl.txt</system_audit>
<system_audit>/var/ossec/etc/shared/cis_rhel5_linux_rcl.txt</system_audit>
</rootcheck>
ホワイトリスト設定
<global>
<allow_list>127.0.0.1</allow_list>
<allow_list>::1</allow_list>
<allow_list>localhost.localdomain</allow_list>
<allow_list>xxx.xxx.xxx.xxx</allow_list>
<allow_list>yyy.yyy.yyy.yyy</allow_list>
</global>
remote設定
<remote>
<connection>syslog</connection>
</remote>
<remote>
<connection>secure</connection>
</remote>
alert設定
検知した不正のレベルに対して、アラートを通知するレベルとメール通知するレベルを設定
<alerts>
<log_alert_level>1</log_alert_level>
<email_alert_level>7</email_alert_level>
</alerts>
ActiveResponseで実行するコマンド(Shell)の設定
<command>
<name>host-deny</name>
<executable>host-deny.sh</executable>
<expect>srcip</expect>
<timeout_allowed>yes</timeout_allowed>
</command>
<command>
<name>firewall-drop</name>
<executable>firewall-drop.sh</executable>
<expect>srcip</expect>
<timeout_allowed>yes</timeout_allowed>
</command>
<command>
<name>disable-account</name>
<executable>disable-account.sh</executable>
<expect>user</expect>
<timeout_allowed>yes</timeout_allowed>
</command>
<command>
<name>restart-ossec</name>
<executable>restart-ossec.sh</executable>
<expect></expect>
</command>
<command>
<name>route-null</name>
<executable>route-null.sh</executable>
<expect>srcip</expect>
<timeout_allowed>yes</timeout_allowed>
</command>
ActiveResponseの実行条件の設定
<!-- Active Response Config -->
<active-response>
<!-- This response is going to execute the host-deny
- command for every event that fires a rule with
- level (severity) >= 6.
- The IP is going to be blocked for 600 seconds.
-->
<command>host-deny</command>
<location>local</location>
<level>6</level>
<timeout>600</timeout>
</active-response>
<active-response>
<!-- Firewall Drop response. Block the IP for
- 600 seconds on the firewall (iptables,
- ipfilter, etc).
-->
<command>firewall-drop</command>
<location>local</location>
<level>6</level>
<timeout>600</timeout>
</active-response>
localfileチェックのコンフィグ設定
チェック対象のファイル
<localfile>
<log_format>syslog</log_format>
<location>/var/log/messages</location>
</localfile>
<localfile>
<log_format>syslog</log_format>
<location>/var/log/secure</location>
</localfile>
<localfile>
<log_format>syslog</log_format>
<location>/var/log/maillog</location>
</localfile>
チェック対象のコマンド
- df -P : ディスク容量表示
- netstat -tan : ネットワークに関する情報表示 -t:tcp, -a:全て, -n:名前解決せず数字で表示
- last -n 5 : 最近ログインしたユーザリストを表示
<localfile>
<log_format>command</log_format>
<command>df -P</command>
</localfile>
<localfile>
<log_format>full_command</log_format>
<command>netstat -tan |grep LISTEN |egrep -v '(127.0.0.1| ::1)' | sort</command>
</localfile>
<localfile>
<log_format>full_command</log_format>
<command>last -n 5</command>
</localfile>
おわりに
今回の記事は以上です。では、また。