如何在 Ubuntu 14.04 上安装 OSSEC

在本教程中,我们将向您展示如何在 Ubuntu 14.04 上安装和配置 OSSEC。 对于那些不知道的人,OSSEC 是一个免费的、开源的基于主机的入侵检测系统 (HIDS)。 它执行日志分析、完整性检查、Windows 注册表监控、rootkit 检测、基于时间的警报和主动响应。 它为大多数操作系统提供入侵检测,包括 Linux、OpenBSD、FreeBSD、Mac OS X、Solaris 和 Windows。 OSSEC 具有集中的跨平台架构,可以轻松监控和管理多个系统。

本文假设您至少具备 Linux 的基本知识,知道如何使用 shell,最重要的是,您将网站托管在自己的 VPS 上。 安装非常简单,假设您在 root 帐户下运行,如果不是,您可能需要添加 ‘sudo‘ 到命令以获取 root 权限。 我将向您展示在 Ubuntu 14.04 服务器上逐步安装 OSSEC。

先决条件

  • 运行以下操作系统之一的服务器:Ubuntu 14.04,以及任何其他基于 Debian 的发行版,如 Linux Mint。
  • 建议您使用全新的操作系统安装来防止任何潜在问题。
  • 对服务器的 SSH 访问(或者如果您在桌面上,则只需打开终端)。
  • 一种 non-root sudo user或访问 root user. 我们建议充当 non-root sudo user,但是,如果您在充当 root 时不小心,可能会损害您的系统。

在 Ubuntu 14.04 上安装 OSSEC

步骤 1. 首先,通过运行以下命令确保所有系统包都是最新的 apt-get 终端中的命令。

sudo apt-get update sudo apt-get upgrade

步骤 2. 安装 LAMP (Linux, ApacheMariaDB, PHP) 服务器。

需要 Ubuntu 14.04 LAMP 服务器。 如果您没有安装 LAMP,您可以在此处按照我们的指南进行操作。

步骤 3. 安装 OSSEC。

首先要做的就是去 OSSEC的下载页面 并下载 OSSEC 的最新稳定版本,在撰写本文时它是 2.8.3 版本:

wget https://bintray.com/artifact/download/ossec/ossec-hids/ossec-hids-2.8.3.tar.gz

将 OSSEC 存档解压缩到服务器中的文档根目录:

tar -xzf ossec-hids-2.8.3.tar.gz cd ossec-hids-2.8.3 cd src make setdb

回到上一个目录:

cd ../ ./install.sh

您可以选择启用/禁用哪些选项,但我们建议您遵循以下输出。 如果您想为每个询问的问题使用默认选项(放在括号中),您可以按 Enter:

OSSEC HIDS v2.8.3 Installation Script - https://www.ossec.net   You are about to start the installation process of the OSSEC HIDS.  You must have a C compiler pre-installed in your system.  If you have any questions or comments, please send an e-mail  to [email protected] (or [email protected]).    - System: Linux vps 2.6.32-042stab113.11   - User: root   - Host: vps.idroot.us    -- Press ENTER to continue or Ctrl-C to abort. --

按回车。

1- What kind of installation do you want (server, agent, local, hybrid or help)? server    - Server installation chosen.  2- Setting up the installation environment.   - Choose where to install the OSSEC HIDS [/var/ossec]:      - Installation will be made at  /var/ossec .  3- Configuring the OSSEC HIDS.    3.1- Do you want e-mail notification? (y/n) [y]:     - What's your e-mail address? [email protected]    - What's your SMTP server ip/host? smtp.example.com    3.2- Do you want to run the integrity check daemon? (y/n) [y]:     - Running syscheck (integrity check daemon).    3.3- Do you want to run the rootkit detection engine? (y/n) [y]:     - Running rootcheck (rootkit detection).    3.4- Active response allows you to execute a specific        command based on the events received. For example,        you can block an IP address or disable access for        a specific user.        More information at:        https://www.ossec.net/en/manual.html#active-response     - Do you want to enable active response? (y/n) [y]:       - Active response enabled.     - By default, we can enable the host-deny and the      firewall-drop responses. The first one will add      a host to the /etc/hosts.deny and the second one      will block the host on iptables (if linux) or on      ipfilter (if Solaris, FreeBSD or NetBSD).    - They can be used to stop SSHD brute force scans,      portscans and some other forms of attacks. You can      also add them to block on snort events, for example.     - Do you want to enable the firewall-drop response? (y/n) [y]:       - firewall-drop enabled (local) for levels >= 6     - Default white list for the active response:       - xxx.xxx.xxx.xx       - xx.xxx.xx.xxx     - Do you want to add more IPs to the white list? (y/n)? [n]:    3.5- Do you want to enable remote syslog (port 514 udp)? (y/n) [y]:     - Remote syslog enabled.    3.6- Setting the configuration to analyze the following logs:     -- /var/log/messages     -- /var/log/auth.log     -- /var/log/syslog     -- /var/log/mail.info     -- /var/log/dpkg.log     -- /var/log/apache2/error.log (apache log)     -- /var/log/apache2/access.log (apache log)   - If you want to monitor any other file, just change    the ossec.conf and add a new localfile entry.    Any questions about the configuration can be answered    by visiting us online at https://www.ossec.net .     --- Press ENTER to continue ---

接下来,按 Enter 继续安装,安装时间不会超过 3 分钟。 一切完成后,您将获得:

- System is Debian (Ubuntu or derivative).  - Init script modified to start OSSEC HIDS during boot.   - Configuration finished properly.   - To start OSSEC HIDS:                 /var/ossec/bin/ossec-control start   - To stop OSSEC HIDS:                 /var/ossec/bin/ossec-control stop   - The configuration can be viewed or modified at /var/ossec/etc/ossec.conf      Thanks for using the OSSEC HIDS.     If you have any question, suggestion or if you find any bug,     contact us at [email protected] or using our public maillist at     [email protected]     ( https://www.ossec.net/main/support/ ).      More information can be found at https://www.ossec.net      ---  Press ENTER to finish (maybe more information below). ---      - In order to connect agent and server, you need to add each agent to the server.    Run the 'manage_agents' to add or remove them:     /var/ossec/bin/manage_agents

启动 OSSEC:

/var/ossec/bin/ossec-control start

步骤 4. 为 OSSEC 配置 MariaDB。

默认情况下,MariaDB 未加固。 您可以使用 mysql_secure_installation 脚本。 您应该仔细阅读以下每个步骤,这些步骤将设置 root 密码、删除匿名用户、禁止远程 root 登录、删除测试数据库和访问安全 MariaDB:

mysql_secure_installation

像这样配置它:

- Set root password? [Y/n] y - Remove anonymous users? [Y/n] y - Disallow root login remotely? [Y/n] y - Remove test database and access to it? [Y/n] y - Reload privilege tables now? [Y/n] y

接下来,我们需要登录 MariaDB 控制台并为 OSSEC 创建一个数据库。 运行以下命令:

mysql -u root -p

这将提示您输入密码,因此输入您的 MariaDB 根密码并点击 Enter. 登录到数据库服务器后,您需要为 OSSEC 安装创建一个数据库:

create database ossec; grant all privileges on ossec.* to [email protected] identified by 'your_password'; flush privileges; exit

默认情况下,OSSEC 为数据库提供了一个模式,它位于 src/os_dbd/ 目录中。 将其导入新创建的 oOSSECssec 数据库:

mysql -u ossecuser -p ossec < src/os_dbd/mysql.schema

现在将数据库配置添加到 OSSEC 配置文件:

nano /var/ossec/etc/ossec.conf

您可以将上述行放在 块中的任何位置:

<database_output>         <hostname>127.0.0.1</hostname>         <username>ossecuser</username>         <password>your_password</password>         <database>ossec</database>         <type>mysql</type> </database_output>

Save 并退出文件。 然后,启用数据库并重新启动 OSSEC:

/var/ossec/bin/ossec-control enable database /var/ossec/bin/ossec-control restart

步骤 5. 安装 OSSEC Web UI。

将 OSSEC Web UI 安装在 Apache的默认文档根目录。 Enter 目录:

cd /var/www/html/ wget https://github.com/ossec/ossec-wui/archive/master.zip unzip master.zip mv ossec-wui-master/ ossec/

创建一个 tmp 里面的目录并设置正确文件的所有权和权限:

mkdir ossec/tmp/ chown www-data: -R ossec/ chmod 666 /var/www/html/ossec/tmp

步骤 6. 访问 OSSEC。

默认情况下,OSSEC 将在 HTTP 端口 80 上可用。 打开您喜欢的浏览器并导航到 https://yourdomain.com/ossec 或者 https://server-ip/ossec. 如果您使用防火墙,请打开端口 80 以启用对控制面板的访问。

恭喜! 您已成功安装 OSSEC。 感谢您使用本教程在 Ubuntu 14.04 系统上安装 OSSEC。 如需更多帮助或有用信息,我们建议您查看 OSSEC 官方网站.