OSSEC:ビッグブラザーはあなたを見ています

画像



おそらく、プロのシステム管理者が自分のサーバーで何がいつ起こっているかを知ることが重要だと言っても、私は誤解しないでしょう。 この問題は、情報セキュリティの分野で特に深刻です。

この投稿では、OSSECと呼ばれるホストベースのIDSの展開を同僚に紹介したいと思います。 猫の下でお願いします...





理論



侵入検知システム(IDS) -コンピューターシステムまたはネットワークへの不正アクセス(侵入またはネットワーク攻撃)を検出するように設計されたソフトウェア(この場合のように)またはハードウェア。



IDSで達成された目標:





IDSシステムは、 ネットワークベースホスト ベースに分けられます



ネットワークベースのIDSは、ネットワークパケットをキャプチャして分析することにより、攻撃を検出します。 ネットワークセグメントをリッスンすることにより、NIDSはネットワークセグメントに接続されている複数のホストからのネットワークトラフィックを表示し、これらのホストを保護できます。



ホストベースのIDSは、単一のコンピューター内で収集された情報を処理します。 このような好ましい場所により、HIDSはアクティビティを優れた信頼性と精度で分析し、OSの特定の攻撃に関連するプロセスとユーザーのみを識別できます。 NIDSは通常、OS監査結果とシステムログの2種類の情報ソースを使用します。



OSSECはHIDSですが、 サーバー<->エージェントのアーキテクチャで機能する能力があります 。 私たちの場合、まさにそのようなスキームを検討します。



ソースデータ



サーバーを含むDMZゾーンが存在する特定の企業ネットワークがあり、それらを綿密に監視するとします。

すべてのサーバーがCentOS 6.xで動作するようにします(実際、Windowsなどの他のOSを含め、どのディストリビューションでもインストールが可能です)

DMZにはサーバーがありません。このサーバーでは、OSSECエージェントからすべての情報を収集します。



設置



まず、OSSECサーバー自体をインストールしましょう。



wget -q -O - https://www.atomicorp.com/installers/atomic |sh && yum install ossec-hids ossec-hids-server
      
      





すべての質問に肯定的に答えます。yumが完了すると、OSSSECが正常にインストールされます。

すべてのOSSECファイルは/ var / ossecに保存されます。 ファイル/var/ossec/ossec.confを開き、次の形式にします。



 <ossec_config> <global> <email_notification>yes</email_notification> <email_to>root@domain.local</email_to> <smtp_server>smtp.domain.local</smtp_server> <email_from>osssec@domain.local</email_from> <email_maxperhour>200</email_maxperhour> </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> <include>smbd_rules.xml</include> <include>vsftpd_rules.xml</include> <include>pure-ftpd_rules.xml</include> <include>proftpd_rules.xml</include> <include>ms_ftpd_rules.xml</include> <include>ftpd_rules.xml</include> <include>hordeimp_rules.xml</include> <include>roundcube_rules.xml</include> <include>wordpress_rules.xml</include> <include>cimserver_rules.xml</include> <include>vpopmail_rules.xml</include> <include>vmpop3d_rules.xml</include> <include>courier_rules.xml</include> <include>web_rules.xml</include> <include>web_appsec_rules.xml</include> <include>apache_rules.xml</include> <include>nginx_rules.xml</include> <include>php_rules.xml</include> <include>mysql_rules.xml</include> <include>postgresql_rules.xml</include> <include>ids_rules.xml</include> <include>squid_rules.xml</include> <include>firewall_rules.xml</include> <include>cisco-ios_rules.xml</include> <include>netscreenfw_rules.xml</include> <include>sonicwall_rules.xml</include> <include>postfix_rules.xml</include> <include>sendmail_rules.xml</include> <include>imapd_rules.xml</include> <include>mailscanner_rules.xml</include> <include>dovecot_rules.xml</include> <include>ms-exchange_rules.xml</include> <include>racoon_rules.xml</include> <include>vpn_concentrator_rules.xml</include> <include>spamd_rules.xml</include> <include>msauth_rules.xml</include> <include>mcafee_av_rules.xml</include> <include>trend-osce_rules.xml</include> <include>ms-se_rules.xml</include> <!-- <include>policy_rules.xml</include> --> <include>zeus_rules.xml</include> <include>solaris_bsm_rules.xml</include> <include>vmware_rules.xml</include> <include>ms_dhcp_rules.xml</include> <include>asterisk_rules.xml</include> <include>ossec_rules.xml</include> <include>attack_rules.xml</include> <include>openbsd_rules.xml</include> <include>clam_av_rules.xml</include> <include>bro-ids_rules.xml</include> <include>dropbear_rules.xml</include> <include>local_rules.xml</include> </rules> <syscheck> <!-- Frequency that syscheck is executed - default to every 22 hours --> <frequency>79200</frequency> <!-- Directories to check (perform all possible verifications) --> <directories check_all="yes">/etc,/usr/bin,/usr/sbin</directories> <directories check_all="yes">/bin,/sbin</directories> <!-- 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> </syscheck> <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_rhel_linux_rcl.txt</system_audit> <system_audit>/var/ossec//etc/shared/cis_rhel5_linux_rcl.txt</system_audit> </rootcheck> <global> <white_list>127.0.0.1</white_list> <white_list>^localhost.localdomain$</white_list> </global> <remote> <connection>syslog</connection> </remote> <remote> <connection>secure</connection> </remote> <alerts> <log_alert_level>1</log_alert_level> <email_alert_level>7</email_alert_level> </alerts> <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> <!-- 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> <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/xferlog</location> </localfile> <localfile> <log_format>syslog</log_format> <location>/var/log/maillog</location> </localfile> <localfile> <log_format>apache</log_format> <location>/var/log/httpd/error_log</location> </localfile> <localfile> <log_format>apache</log_format> <location>/var/log/httpd/access_log</location> </localfile> </ossec_config>
      
      





何があるか見てみましょう。 最初に、サーバーアドレス、郵送先住所、および1時間あたりの文字の最大数を示すアラートをメールに送信します。 デフォルトでは、OSSECはイベントをグループ化して、文字の流れであふれないようにします。

次にルールブロックがあります 。これは、OSSECが何をどのように応答するかを説明します-私の観察によれば、すべてをその速度のままにしておくことができます。 syscheckセクションは、いわゆる整合性チェックの設定です。 その意味は、IDSが指定されたディレクトリ内の各ファイルのハッシュを計算し、定期的にチェックすることです。 ここで、制御するディレクトリと、チェックを実行する期間を設定します。 コマンドセクションでは、特定の条件が発生したときにIDSが使用できるスクリプトについて説明しています。 アクティブ応答セクションでは、これらのコマンドのみを使用します。 たとえば、特定のルールがトリガーされると、 firewall-blockはsrc ipをiptablesに600秒間入れます。 総当たりで使用すると便利です。 最後に、分析してルールと比較する必要がある実際のログファイルがあります。

これで、OSSECのサーバー部分の大まかな構成が完了し、実行できます。



 service ossec-hids start
      
      





成功した場合は、起動に関するメッセージとともに指定した住所に手紙が送信されます。



 OSSEC HIDS Notification. 2013 Sep 06 13:10:35 Received From: server.domain.local->ossec-monitord Rule: 502 fired (level 3) -> "Ossec server started." Portion of the log(s): ossec: Ossec started. --END OF NOTIFICATION
      
      





起動に失敗した場合は、構成にエラーがないか再度確認してください。 これに関するヘルプは、ファイル/var/ossec/logs/ossec.logです。



Webベースのインストール


Webインターフェースは非常に原始的ですが、便宜上、インストールできます



 wget –c http://www.ossec.net/files/ossec-wui-0.3.tar.gz tar xzvf ossec-wui-0.3.tar.gz mv ossec-wui-0.3 /var/www/html/ossec cd /var/www/html/ossec/ ./setup.sh
      
      





ここで、ユーザー名とパスワードを入力する必要があります。それぞれ.htaccessファイルが作成されます。 ossecユーザーをapacheグループに追加します



 nano /etc/group ossec:x:494:ossec,ossecr,ossecm,ossece,apache service httpd restart
      
      





ブラウザーでページに移動し、tmpフォルダーに権限を付与します。



 chmod 770 /var/www/html/ossec/tmp chgrp apache /var/www/html/ossec/tmp
      
      





これで、OSSECに記録されたイベントを確認し、シンプルなインターフェイスを使用できます。



エージェントのインストール


DMZのサーバーにエージェントをインストールする



 wget -q -O - https://www.atomicorp.com/installers/atomic |sh && yum install ossec-hids ossec-hids-client
      
      





ファイル/var/ossec/ossec.confを編集して、次の形式にします。



 <ossec_config> <client> <server-ip><b>server.domain.local</b></server-ip> </client> <syscheck> <!-- Frequency that syscheck is executed -- default every 2 hours --> <frequency>7200</frequency> <!-- Directories to check (perform all possible verifications) --> <directories check_all="yes">/etc,/usr/bin,/usr/sbin</directories> <directories check_all="yes">/bin,/sbin</directories> <!-- 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> </syscheck> <rootcheck> <rootkit_files>/var/ossec/etc/shared/rootkit_files.txt</rootkit_files> <rootkit_trojans>/var/ossec/etc/shared/rootkit_trojans.txt</rootkit_trojans> </rootcheck> <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> <localfile> <log_format>apache</log_format> <location>/var/log/httpd/error_log</location> </localfile> <localfile> <log_format>apache</log_format> <location>/var/log/httpd/access_log</location> </localfile> <localfile> <log_format>syslog</log_format> <location>/var/log/proftpd/error.log</location> </localfile> </ossec_config>
      
      





ご覧のとおり、この構成はトリミングされたサーバーに非常に似ています。 ここで指定する必要がある主なものは、OSSECサーバーとログファイルの実際のアドレスです。 たとえば、proftpdログファイルを追加しました。

クライアントとサーバー間の通信はUDP / 1514ポートで発生します。開くことを忘れないでください!



インストールと構成は完了しました。サーバーとエージェントを接続する必要があります。 これを行うには、サーバーで特別なユーティリティ/ var / ossec / bin / manage_agentsを実行します



 **************************************** * OSSEC HIDS v2.7 Agent manager. * * The following options are available: * **************************************** (A)dd an agent (A). (E)xtract key for an agent (E). (L)ist already added agents (L). (R)emove an agent (R). (Q)uit. Choose your action: A,E,L,R or Q: a - Adding a new agent (use '\q' to return to the main menu). Please provide the following: * A name for the new agent: ftp-server * The IP Address of the new agent: 192.168.0.2 * An ID for the new agent[001]: Agent information: ID:001 Name:ftp-server IP Address:192.168.0.2 Confirm adding it?(y/n): y Agent added. **************************************** * OSSEC HIDS v2.7 Agent manager. * * The following options are available: * **************************************** (A)dd an agent (A). (E)xtract key for an agent (E). (L)ist already added agents (L). (R)emove an agent (R). (Q)uit. Choose your action: A,E,L,R or Q: e Available agents: ID: 001, Name: ftp-server, IP: 192.168.0.2 Provide the ID of the agent to extract the key (or '\q' to quit): 001 Agent key information for '001' is: MDA3IGZ0cC1zZXJ1ZXIgMTkyLjE2OC4wLjIgOTQyODg5ODg2NDI5MGNiYTkzYTU1N2I5Yzg5OWTwNTJhNzQ2ZDdlYmNkNzM3NGYyZWQyZGQyZmFlNjdjMjZmOA== ** Press ENTER to return to the main menu. **************************************** * OSSEC HIDS v2.7 Agent manager. * * The following options are available: * **************************************** (A)dd an agent (A). (E)xtract key for an agent (E). (L)ist already added agents (L). (R)emove an agent (R). (Q)uit. Choose your action: A,E,L,R or Q: q ** You must restart OSSEC for your changes to take effect. manage_agents: Exiting ..
      
      







ご覧のとおり、すべてがシンプルです。 結果はBASE64文字列になります。これをコピーしてエージェントに貼り付ける必要があります。 サーバーを再起動することを忘れないでください:



 service ossec-hid restart
      
      





次に、エージェントでコマンド/ var / ossec / bin / manage_clientを実行します。



 **************************************** * OSSEC HIDS v2.7 Agent manager. * * The following options are available: * **************************************** (I)mport key from the server (I). (Q)uit. Choose your action: I or Q: i * Provide the Key generated by the server. * The best approach is to cut and paste it. *** OBS: Do not include spaces or new lines. Paste it here (or '\q' to quit): MDA3IGZ0cC1zZXJ1ZXIgMTkyLjE2OC4wLjIgOTQyODg5ODg2NDI5MGNiYTkzYTU1N2I5Yzg5OWTwNTJhNzQ2ZDdlYmNkNzM3NGYyZWQyZGQyZmFlNjdjMjZmOA== ** Press ENTER to return to the main menu. **************************************** * OSSEC HIDS v2.7 Agent manager. * * The following options are available: * **************************************** (I)mport key from the server (I). (Q)uit. Choose your action: I or Q: q manage_agents: Exiting ..
      
      





エージェントを再起動します。



 service ossec-hid restart
      
      





サーバーコンソールに移動し、エージェントが接続されていることを確認します。



 /var/ossec/bin/list_agents -a ftp-server-192.168.0.2 is available.
      
      







この設定では、完了と見なすことができます。 次に何をする? OSSECは非常に柔軟で強力なIDSです。 独自のルールを書くことができます-それらのフォーマットは非常にシンプルです。 サーバーからエージェントを管理し、同じ場所から構成を割り当て、IDSを別のIDS(NIDS Snortなど)に関連付けることができます。

すべてを正しく行った場合、ファイルレベルで発生するすべての変更と攻撃の可能性を制御できるようになりました。



参照資料






All Articles