eric
作者eric·2015-04-10 15:15
系统运维工程师·某金融单位

OSSEC入侵检测系统的安装部署

字数 89490阅读 7352评论 1赞 2

前言

OSSEC是一款开源的多平台的入侵检测系统,可以运行于Windows, Linux, OpenBSD/FreeBSD, 以及 MacOS等操作系统中。包括了日志分析,全面检测,root-kit检测。作为一款HIDS,OSSEC应该被安装在一台实施监控的系统中。另外有时候不需要安装完全版本得OSSEC,如果有多台电脑都安装了OSSEC,那么就可以采用C/S模式来运行。客户机通过客户端程序将数据发回到服务器端进行分析。

OSSEC服务端IP:192.168.1.107

OSSEC Agent IP:192.168.1.54

OSSEC 软件 包下载 地址 http://www.ossec.net/files/ossec-hids-2.8.1.tar.gz

OSSEC web下载  https://github.com/ECSC/analogi/archive/master.zip

一、OSSEC环境安装

1.1、安装基础环境

1
[root@tshare365 ~]# yum install wget gcc make mysql mysql-server mysql-devel httpd php php-mysql sendmail

1.2、启动服务

1
[root@tshare365 ~]# for i in {httpd,mysqld,sendmail};do service $i restart;done

1.3、数据库的授权

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@tshare365 ~]# mysql
mysql> create database ossec;
Query OK, 1 row affected (0.00 sec)
 
mysql> grant INSERT,SELECT,UPDATE,CREATE,DELETE,EXECUTE on ossec.* to ossec@localhost;
Query OK, 0 rows affected (0.00 sec)
 
mysql> set password for ossec@localhost=PASSWORD('ossec');
Query OK, 0 rows affected (0.00 sec)
 
mysql> flush privileges
    -> ;
Query OK, 0 rows affected (0.00 sec)
 
mysql> exit
Bye
[root@tshare365 ~]#

三、OSSEC服务端安装配置

3.1、安装OSSEC

1
2
3
4
5
6
7
[root@tshare365 ~]# tar xf ossec-hids-2.8.1.tar.gz 
[root@tshare365 ~]# cd ossec-hids-2.8.1
[root@tshare365 ossec-hids-2.8.1]# cd src/
[root@tshare365 src]# make setdb; cd  .. 
Error: PostgreSQL client libraries not installed.
 
Info: Compiled with MySQL support.

注意: 只要是出现 Mysql support 就说明是支持Mysql的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
[root@tshare365 ossec-hids-2.8.1]# ./install.sh 
  
 您将开始 OSSEC HIDS 的安装.
 请确认在您的机器上已经正确安装了 C 编译器.
 如果您有任何疑问或建议,请给 dcid@ossec.net (或 daniel.cid@gmail.com) 发邮件.
  
  - 系统类型: Linux tshare365 2.6.32-431.el6.x86_64
  - 用户: root
  - 主机: tshare365
  
1- 您希望哪一种安装 (server, agent, local or help)? server
 
  - 选择了 Server 类型的安装.
 
2- 正在初始化安装环境.
 
 - 请选择 OSSEC HIDS 的安装路径 [/var/ossec]: /user/local/ossec
 
    - OSSEC HIDS 将安装在  /user/local/ossec .
 
3- 正在配置 OSSEC HIDS.
 
  3.1- 您希望收到e-mail告警吗? (y/n) [y]: y
   - 请输入您的 e-mail 地址? 903914685@qq.com
   - 请输入您的 SMTP 服务器IP或主机名 ? 127.0.0.1
 
  3.2- 您希望运行系统完整性检测模块吗? (y/n) [y]: y
 
   - 系统完整性检测模块将被部署.
 
  3.3- 您希望运行 rootkit检测吗? (y/n) [y]: y
 
   - rootkit检测将被部署.
        
  3.4- 关联响应允许您在分析已接收事件的基础上执行一个
       已定义的命令.
       例如,你可以阻止某个IP地址的访问或禁止某个用户的访问权限.
       更多的信息,您可以访问:
       http://www.ossec.net/en/manual.html#active-response
   - 您希望开启联动(active response)功能吗? (y/n) [y]: y
 
 
     - 关联响应已开启
 
   - 默认情况下, 我们开启了主机拒绝和防火墙拒绝两种响应.
     第一种情况将添加一个主机到 /etc/hosts.deny.
     第二种情况将在iptables(linux)或ipfilter(Solaris,
     FreeBSD 或 NetBSD)中拒绝该主机的访问.
   - 该功能可以用以阻止 SSHD 暴力攻击, 端口扫描和其他
     一些形式的攻击. 同样你也可以将他们添加到其他地方,
     例如将他们添加为 snort 的事件.
 
   - 您希望开启防火墙联动(firewall-drop)功能吗? (y/n) [y]: y
 
     - 防火墙联动(firewall-drop)当事件级别 >= 6 时被启动
 
   - 联动功能默认的白名单是:
      - 202.99.166.4
      - 202.99.160.68
 
   - 您希望添加更多的IP到白名单吗? (y/n)? [n]: y
   - 请输入IP (用空格进行分隔): 8.8.8.8,4.4.4.4
 
  3.5- 您希望接收远程机器syslog吗 (port 514 udp)? (y/n) [y]: y
 
   - 远程机器syslog将被接收.
 
  3.6- 设置配置文件以分析一下日志:
    -- /var/log/messages
    -- /var/log/secure
    -- /var/log/maillog
    -- /var/log/httpd/error_log (apache log)
    -- /var/log/httpd/access_log (apache log)
                             
 -如果你希望监控其他文件, 只需要在配置文件ossec.conf中
  添加新的一项. 
  任何关于配置的疑问您都可以在 http://www.ossec.net 找到答案.
 
  --- 按 ENTER 以继续 ---
   
  ..........编译安装过程省略......
   
 - 系统类型是  Redhat Linux.
 - 修改启动脚本使 OSSEC HIDS 在系统启动时自动运行 
 
 - 已正确完成系统配置.
 
 - 要启动 OSSEC HIDS:
        /user/local/ossec/bin/ossec-control start
 
 - 要停止 OSSEC HIDS:
        /user/local/ossec/bin/ossec-control stop
 
 - 要查看或修改系统配置,请编辑  /user/local/ossec/etc/ossec.conf

3.2、启用数据库支持并导入数据

1
[root@tshare365 ossec-hids-2.8.1]# /user/local/ossec/bin/ossec-control enable database

1
[root@tshare365 ossec-hids-2.8.1]# mysql -uossec -p ossec < ./src/os_dbd/mysql.schema

3.3、修改部分配置文件的权限

1
[root@tshare365 ossec-hids-2.8.1]# chmod u+w /user/local/ossec/etc/ossec.conf

3.4、修改/user/local/ossec/etc/ossec.conf添加Mysql信息

1
2
3
4
5
6
7
8
9
<ossec_config>
    <database_output>
        <hostname>127.0.0.1</hostname>
        <username>ossec</username>
        <password>ossec</password>
        <database>ossec</database>
        <type>mysql</type>
    </database_output>
</ossec_config>

3.5、接收远端syslog信息

1
2
3
4
 <remote>
    <connection>syslog</connection>
    <allowed-ips>192.168.0.0/16</allowed-ips>
  </remote>

3.6、配置Agent信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
[root@tshare365 ossec-hids-2.8.1]# /user/local/ossec/bin/manage_agents 
****************************************
* OSSEC HIDS v2.8 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: ossec-agent
   * The IP Address of the new agent: 192.168.1.54
   * An ID for the new agent[001]: 
Agent information:
   ID:001
   Name:ossec-agent
   IP Address:192.168.1.54
 
Confirm adding it?(y/n): y
Agent added.
 
 
****************************************
* OSSEC HIDS v2.8 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: ossec-agent, IP: 192.168.1.54
Provide the ID of the agent to extract the key (or 'q' to quit): 001
 
Agent key information for '001' is: 
MDAxIG9zc2VjLWFnZW50IDE5Mi4xNjguMS41NCA5Nzc1N2I5NDk3ZDcwNTRkMGZkNzZhYTE0MzE4ZWZlOWNjZmNiZjM5NzhhYTVkMDA1NjE5OWE2ZDc5ZGRmNjgw
 
** Press ENTER to return to the main menu.

注意、需要将key记录到文本中,后面需要用到

3.7、启动OSSEC服务

1
[root@tshare365 ossec-hids-2.8.1]# /user/local/ossec/bin/ossec-control restart

四、安装OSSEC客户端

4.1、安装Agent端

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
[root@ossec-agent ~]# tar xf ossec-hids-2.8.1.tar.gz 
[root@ossec-agent ~]# cd ossec-hids-2.8.1
[root@ossec-agent ossec-hids-2.8.1]# ./install.sh 
which: no host in (/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin)
 
  ** Para instalação em português, escolha [br].
  ** 要使用中文进行安装, 请选择 [cn].
  ** Fur eine deutsche Installation wohlen Sie [de].
  ** Για εγκατάσταση στα Ελληνικά, επιλέξτε [el].
  ** For installation in English, choose [en].
  ** Para instalar en Español , eliga [es].
  ** Pour une installation en français, choisissez [fr]
  ** A Magyar nyelvű telepítéshez válassza [hu].
  ** Per l'installazione in Italiano, scegli [it].
  ** 日本語でインストールします.選択して下さい.[jp].
  ** Voor installatie in het Nederlands, kies [nl].
  ** Aby instalować w języku Polskim, wybierz [pl].
  ** Для инструкций по установке на русском ,введите [ru].
  ** Za instalaciju na srpskom, izaberi [sr].
  ** Türkçe kurulum için seçin [tr].
  (en/br/cn/de/el/es/fr/hu/it/jp/nl/pl/ru/sr/tr) [en]: cn
which: no host in (/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin)
 OSSEC HIDS v2.8 安装脚本 - http://www.ossec.net
  
 您将开始 OSSEC HIDS 的安装.
 请确认在您的机器上已经正确安装了 C 编译器.
 如果您有任何疑问或建议,请给 dcid@ossec.net (或 daniel.cid@gmail.com) 发邮件.
  
  - 系统类型: Linux ossec-agent 2.6.32-431.el6.x86_64
  - 用户: root
  - 主机: ossec-agent
 
 
  -- 按 ENTER 继续或 Ctrl-C 退出. --
 
 
1- 您希望哪一种安装 (server, agent, local or help)? agent
 
  - 选择了 Agent(client) 类型的安装.
 
2- 正在初始化安装环境.
 
 - 请选择 OSSEC HIDS 的安装路径 [/var/ossec]: /user/local/ossec
 
    - OSSEC HIDS 将安装在  /user/local/ossec .
 
3- 正在配置 OSSEC HIDS.
 
  3.1- 请输入 OSSEC HIDS 服务器的IP地址或主机名: 192.168.1.107
 
   - 添加服务器IP  192.168.1.107
 
  3.2- 您希望运行系统完整性检测模块吗? (y/n) [y]: y
 
   - 系统完整性检测模块将被部署.
 
  3.3- 您希望运行 rootkit检测吗? (y/n) [y]: y
 
   - rootkit检测将被部署.
 
  3.4 - 您希望开启联动(active response)功能吗? (y/n) [y]: y
 
 
  3.5- 设置配置文件以分析一下日志:
    -- /var/log/messages
    -- /var/log/secure
    -- /var/log/maillog
 
                             
 -如果你希望监控其他文件, 只需要在配置文件ossec.conf中
  添加新的一项. 
  任何关于配置的疑问您都可以在 http://www.ossec.net 找到答案.
 
 
  --- 按 ENTER 以继续 ---
 
 
5- 正在安装系统
 - 正在运行Makefile
 编译安装输出省略....
  
 - 系统类型是  Redhat Linux.
 - 修改启动脚本使 OSSEC HIDS 在系统启动时自动运行 
 
 - 已正确完成系统配置.
 
 - 要启动 OSSEC HIDS:
        /user/local/ossec/bin/ossec-control start
 
 - 要停止 OSSEC HIDS:
        /user/local/ossec/bin/ossec-control stop
 
 - 要查看或修改系统配置,请编辑  /user/local/ossec/etc/ossec.conf
 
 
 
    感谢使用 OSSEC HIDS.
    如果您有任何疑问,建议或您找到任何bug,
    请通过 contact@ossec.net 或邮件列表 ossec-list@ossec.net 联系我们.    
    ( http://www.ossec.net/en/mailing_lists.html ).
 
    您可以在 http://www.ossec.net 获得更多信息
 
    --- 请按 ENTER 结束安装 (下面可能有更多信息). ---
 
    
 - 您必须首先将该代理添加到服务器端以使他们能够相互通信.
   这样做了以后,您可以运行'manage_agents'工具导入
   服务器端产生的认证密匙.
   /user/local/ossec/bin/manage_agents
 
   详细信息请参考: 
   http://www.ossec.net/en/manual.html#ma
 
[root@ossec-agent ossec-hids-2.8.1]#

4.2、配置Agent

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[root@ossec-agent ossec-hids-2.8.1]# /user/local/ossec/bin/manage_agents  
 
****************************************
* OSSEC HIDS v2.8 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): MDAxIG9zc2VjLWFnZW50IDE5Mi4xNjguMS41NCA5Nzc1N2I5NDk3ZDcwNTRkMGZkNzZhYTE0MzE4ZWZlOWNjZmNiZjM5NzhhYTVkMDA1NjE5OWE2ZDc5ZGRmNjgw
 
Agent information:
   ID:001
   Name:ossec-agent
   IP Address:192.168.1.54
 
Confirm adding it?(y/n): y
Added.
** Press ENTER to return to the main menu.

4.3、启动Agent服务

1
[root@ossec-agent ossec-hids-2.8.1]# /user/local/ossec/bin/ossec-control start

 

四、安装web界面服务

4.1、安装web

1
2
3
4
[root@tshare365 ~]# mv analogi-master /var/www/html/tshare365
[root@tshare365 ~]# chown -R apache.apache /var/www/html/tshare365/
[root@tshare365 ~]# cd /var/www/html/tshare365/
[root@tshare365 tshare365]# cp db_ossec.php.new db_ossec.php

4.2、编辑db_ossec.php文件,修改MySQL的配置信息

1
2
3
4
define ('DB_USER_O', 'ossec');
define ('DB_PASSWORD_O', 'ossec');
define ('DB_HOST_O', '127.0.0.1');
define ('DB_NAME_O', 'ossec');

4.3、修改 apache 配置,增加虚拟目录

1
2
3
4
5
6
7
[root@tshare365 tshare365]# vim /etc/httpd/conf.d/tshare365.conf
 
<Directory /var/www/html/tshare365>
    Order deny,allow
    Deny from all
    Allow from 192.168.0.0/16
</Directory>

4.4、重启http服务

1
[root@tshare365 tshare365]# /etc/init.d/httpd restart

五、客户端访问测试

5.1、游览器访问

OSSEC入侵检测系统的安装部署

本博客到此结束,如有什么问题,求留言!

前言

OSSEC是一款开源的多平台的入侵检测系统,可以运行于Windows, Linux, OpenBSD/FreeBSD, 以及 MacOS等操作系统中。包括了日志分析,全面检测,root-kit检测。作为一款HIDS,OSSEC应该被安装在一台实施监控的系统中。另外有时候不需要安装完全版本得OSSEC,如果有多台电脑都安装了OSSEC,那么就可以采用C/S模式来运行。客户机通过客户端程序将数据发回到服务器端进行分析。

OSSEC服务端IP:192.168.1.107

OSSEC Agent IP:192.168.1.54

OSSEC 软件 包下载 地址 http://www.ossec.net/files/ossec-hids-2.8.1.tar.gz

OSSEC web下载  https://github.com/ECSC/analogi/archive/master.zip

一、OSSEC环境安装

1.1、安装基础环境

1
[root@tshare365 ~]# yum install wget gcc make mysql mysql-server mysql-devel httpd php php-mysql sendmail

1.2、启动服务

1
[root@tshare365 ~]# for i in {httpd,mysqld,sendmail};do service $i restart;done

1.3、数据库的授权

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@tshare365 ~]# mysql
mysql> create database ossec;
Query OK, 1 row affected (0.00 sec)
 
mysql> grant INSERT,SELECT,UPDATE,CREATE,DELETE,EXECUTE on ossec.* to ossec@localhost;
Query OK, 0 rows affected (0.00 sec)
 
mysql> set password for ossec@localhost=PASSWORD('ossec');
Query OK, 0 rows affected (0.00 sec)
 
mysql> flush privileges
    -> ;
Query OK, 0 rows affected (0.00 sec)
 
mysql> exit
Bye
[root@tshare365 ~]#

三、OSSEC服务端安装配置

3.1、安装OSSEC

1
2
3
4
5
6
7
[root@tshare365 ~]# tar xf ossec-hids-2.8.1.tar.gz 
[root@tshare365 ~]# cd ossec-hids-2.8.1
[root@tshare365 ossec-hids-2.8.1]# cd src/
[root@tshare365 src]# make setdb; cd  .. 
Error: PostgreSQL client libraries not installed.
 
Info: Compiled with MySQL support.

注意: 只要是出现 Mysql support 就说明是支持Mysql的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
[root@tshare365 ossec-hids-2.8.1]# ./install.sh 
  
 您将开始 OSSEC HIDS 的安装.
 请确认在您的机器上已经正确安装了 C 编译器.
 如果您有任何疑问或建议,请给 dcid@ossec.net (或 daniel.cid@gmail.com) 发邮件.
  
  - 系统类型: Linux tshare365 2.6.32-431.el6.x86_64
  - 用户: root
  - 主机: tshare365
  
1- 您希望哪一种安装 (server, agent, local or help)? server
 
  - 选择了 Server 类型的安装.
 
2- 正在初始化安装环境.
 
 - 请选择 OSSEC HIDS 的安装路径 [/var/ossec]: /user/local/ossec
 
    - OSSEC HIDS 将安装在  /user/local/ossec .
 
3- 正在配置 OSSEC HIDS.
 
  3.1- 您希望收到e-mail告警吗? (y/n) [y]: y
   - 请输入您的 e-mail 地址? 903914685@qq.com
   - 请输入您的 SMTP 服务器IP或主机名 ? 127.0.0.1
 
  3.2- 您希望运行系统完整性检测模块吗? (y/n) [y]: y
 
   - 系统完整性检测模块将被部署.
 
  3.3- 您希望运行 rootkit检测吗? (y/n) [y]: y
 
   - rootkit检测将被部署.
        
  3.4- 关联响应允许您在分析已接收事件的基础上执行一个
       已定义的命令.
       例如,你可以阻止某个IP地址的访问或禁止某个用户的访问权限.
       更多的信息,您可以访问:
       http://www.ossec.net/en/manual.html#active-response
   - 您希望开启联动(active response)功能吗? (y/n) [y]: y
 
 
     - 关联响应已开启
 
   - 默认情况下, 我们开启了主机拒绝和防火墙拒绝两种响应.
     第一种情况将添加一个主机到 /etc/hosts.deny.
     第二种情况将在iptables(linux)或ipfilter(Solaris,
     FreeBSD 或 NetBSD)中拒绝该主机的访问.
   - 该功能可以用以阻止 SSHD 暴力攻击, 端口扫描和其他
     一些形式的攻击. 同样你也可以将他们添加到其他地方,
     例如将他们添加为 snort 的事件.
 
   - 您希望开启防火墙联动(firewall-drop)功能吗? (y/n) [y]: y
 
     - 防火墙联动(firewall-drop)当事件级别 >= 6 时被启动
 
   - 联动功能默认的白名单是:
      - 202.99.166.4
      - 202.99.160.68
 
   - 您希望添加更多的IP到白名单吗? (y/n)? [n]: y
   - 请输入IP (用空格进行分隔): 8.8.8.8,4.4.4.4
 
  3.5- 您希望接收远程机器syslog吗 (port 514 udp)? (y/n) [y]: y
 
   - 远程机器syslog将被接收.
 
  3.6- 设置配置文件以分析一下日志:
    -- /var/log/messages
    -- /var/log/secure
    -- /var/log/maillog
    -- /var/log/httpd/error_log (apache log)
    -- /var/log/httpd/access_log (apache log)
                             
 -如果你希望监控其他文件, 只需要在配置文件ossec.conf中
  添加新的一项. 
  任何关于配置的疑问您都可以在 http://www.ossec.net 找到答案.
 
  --- 按 ENTER 以继续 ---
   
  ..........编译安装过程省略......
   
 - 系统类型是  Redhat Linux.
 - 修改启动脚本使 OSSEC HIDS 在系统启动时自动运行 
 
 - 已正确完成系统配置.
 
 - 要启动 OSSEC HIDS:
        /user/local/ossec/bin/ossec-control start
 
 - 要停止 OSSEC HIDS:
        /user/local/ossec/bin/ossec-control stop
 
 - 要查看或修改系统配置,请编辑  /user/local/ossec/etc/ossec.conf

3.2、启用数据库支持并导入数据

1
[root@tshare365 ossec-hids-2.8.1]# /user/local/ossec/bin/ossec-control enable database

1
[root@tshare365 ossec-hids-2.8.1]# mysql -uossec -p ossec < ./src/os_dbd/mysql.schema

3.3、修改部分配置文件的权限

1
[root@tshare365 ossec-hids-2.8.1]# chmod u+w /user/local/ossec/etc/ossec.conf

3.4、修改/user/local/ossec/etc/ossec.conf添加Mysql信息

1
2
3
4
5
6
7
8
9
<ossec_config>
    <database_output>
        <hostname>127.0.0.1</hostname>
        <username>ossec</username>
        <password>ossec</password>
        <database>ossec</database>
        <type>mysql</type>
    </database_output>
</ossec_config>

3.5、接收远端syslog信息

1
2
3
4
 <remote>
    <connection>syslog</connection>
    <allowed-ips>192.168.0.0/16</allowed-ips>
  </remote>

3.6、配置Agent信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
[root@tshare365 ossec-hids-2.8.1]# /user/local/ossec/bin/manage_agents 
****************************************
* OSSEC HIDS v2.8 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: ossec-agent
   * The IP Address of the new agent: 192.168.1.54
   * An ID for the new agent[001]: 
Agent information:
   ID:001
   Name:ossec-agent
   IP Address:192.168.1.54
 
Confirm adding it?(y/n): y
Agent added.
 
 
****************************************
* OSSEC HIDS v2.8 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: ossec-agent, IP: 192.168.1.54
Provide the ID of the agent to extract the key (or 'q' to quit): 001
 
Agent key information for '001' is: 
MDAxIG9zc2VjLWFnZW50IDE5Mi4xNjguMS41NCA5Nzc1N2I5NDk3ZDcwNTRkMGZkNzZhYTE0MzE4ZWZlOWNjZmNiZjM5NzhhYTVkMDA1NjE5OWE2ZDc5ZGRmNjgw
 
** Press ENTER to return to the main menu.

注意、需要将key记录到文本中,后面需要用到

3.7、启动OSSEC服务

1
[root@tshare365 ossec-hids-2.8.1]# /user/local/ossec/bin/ossec-control restart

四、安装OSSEC客户端

4.1、安装Agent端

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
[root@ossec-agent ~]# tar xf ossec-hids-2.8.1.tar.gz 
[root@ossec-agent ~]# cd ossec-hids-2.8.1
[root@ossec-agent ossec-hids-2.8.1]# ./install.sh 
which: no host in (/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin)
 
  ** Para instalação em português, escolha [br].
  ** 要使用中文进行安装, 请选择 [cn].
  ** Fur eine deutsche Installation wohlen Sie [de].
  ** Για εγκατάσταση στα Ελληνικά, επιλέξτε [el].
  ** For installation in English, choose [en].
  ** Para instalar en Español , eliga [es].
  ** Pour une installation en français, choisissez [fr]
  ** A Magyar nyelvű telepítéshez válassza [hu].
  ** Per l'installazione in Italiano, scegli [it].
  ** 日本語でインストールします.選択して下さい.[jp].
  ** Voor installatie in het Nederlands, kies [nl].
  ** Aby instalować w języku Polskim, wybierz [pl].
  ** Для инструкций по установке на русском ,введите [ru].
  ** Za instalaciju na srpskom, izaberi [sr].
  ** Türkçe kurulum için seçin [tr].
  (en/br/cn/de/el/es/fr/hu/it/jp/nl/pl/ru/sr/tr) [en]: cn
which: no host in (/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin)
 OSSEC HIDS v2.8 安装脚本 - http://www.ossec.net
  
 您将开始 OSSEC HIDS 的安装.
 请确认在您的机器上已经正确安装了 C 编译器.
 如果您有任何疑问或建议,请给 dcid@ossec.net (或 daniel.cid@gmail.com) 发邮件.
  
  - 系统类型: Linux ossec-agent 2.6.32-431.el6.x86_64
  - 用户: root
  - 主机: ossec-agent
 
 
  -- 按 ENTER 继续或 Ctrl-C 退出. --
 
 
1- 您希望哪一种安装 (server, agent, local or help)? agent
 
  - 选择了 Agent(client) 类型的安装.
 
2- 正在初始化安装环境.
 
 - 请选择 OSSEC HIDS 的安装路径 [/var/ossec]: /user/local/ossec
 
    - OSSEC HIDS 将安装在  /user/local/ossec .
 
3- 正在配置 OSSEC HIDS.
 
  3.1- 请输入 OSSEC HIDS 服务器的IP地址或主机名: 192.168.1.107
 
   - 添加服务器IP  192.168.1.107
 
  3.2- 您希望运行系统完整性检测模块吗? (y/n) [y]: y
 
   - 系统完整性检测模块将被部署.
 
  3.3- 您希望运行 rootkit检测吗? (y/n) [y]: y
 
   - rootkit检测将被部署.
 
  3.4 - 您希望开启联动(active response)功能吗? (y/n) [y]: y
 
 
  3.5- 设置配置文件以分析一下日志:
    -- /var/log/messages
    -- /var/log/secure
    -- /var/log/maillog
 
                             
 -如果你希望监控其他文件, 只需要在配置文件ossec.conf中
  添加新的一项. 
  任何关于配置的疑问您都可以在 http://www.ossec.net 找到答案.
 
 
  --- 按 ENTER 以继续 ---
 
 
5- 正在安装系统
 - 正在运行Makefile
 编译安装输出省略....
  
 - 系统类型是  Redhat Linux.
 - 修改启动脚本使 OSSEC HIDS 在系统启动时自动运行 
 
 - 已正确完成系统配置.
 
 - 要启动 OSSEC HIDS:
        /user/local/ossec/bin/ossec-control start
 
 - 要停止 OSSEC HIDS:
        /user/local/ossec/bin/ossec-control stop
 
 - 要查看或修改系统配置,请编辑  /user/local/ossec/etc/ossec.conf
 
 
 
    感谢使用 OSSEC HIDS.
    如果您有任何疑问,建议或您找到任何bug,
    请通过 contact@ossec.net 或邮件列表 ossec-list@ossec.net 联系我们.    
    ( http://www.ossec.net/en/mailing_lists.html ).
 
    您可以在 http://www.ossec.net 获得更多信息
 
    --- 请按 ENTER 结束安装 (下面可能有更多信息). ---
 
    
 - 您必须首先将该代理添加到服务器端以使他们能够相互通信.
   这样做了以后,您可以运行'manage_agents'工具导入
   服务器端产生的认证密匙.
   /user/local/ossec/bin/manage_agents
 
   详细信息请参考: 
   http://www.ossec.net/en/manual.html#ma
 
[root@ossec-agent ossec-hids-2.8.1]#

4.2、配置Agent

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[root@ossec-agent ossec-hids-2.8.1]# /user/local/ossec/bin/manage_agents  
 
****************************************
* OSSEC HIDS v2.8 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): MDAxIG9zc2VjLWFnZW50IDE5Mi4xNjguMS41NCA5Nzc1N2I5NDk3ZDcwNTRkMGZkNzZhYTE0MzE4ZWZlOWNjZmNiZjM5NzhhYTVkMDA1NjE5OWE2ZDc5ZGRmNjgw
 
Agent information:
   ID:001
   Name:ossec-agent
   IP Address:192.168.1.54
 
Confirm adding it?(y/n): y
Added.
** Press ENTER to return to the main menu.

4.3、启动Agent服务

1
[root@ossec-agent ossec-hids-2.8.1]# /user/local/ossec/bin/ossec-control start

 

四、安装web界面服务

4.1、安装web

1
2
3
4
[root@tshare365 ~]# mv analogi-master /var/www/html/tshare365
[root@tshare365 ~]# chown -R apache.apache /var/www/html/tshare365/
[root@tshare365 ~]# cd /var/www/html/tshare365/
[root@tshare365 tshare365]# cp db_ossec.php.new db_ossec.php

4.2、编辑db_ossec.php文件,修改MySQL的配置信息

1
2
3
4
define ('DB_USER_O', 'ossec');
define ('DB_PASSWORD_O', 'ossec');
define ('DB_HOST_O', '127.0.0.1');
define ('DB_NAME_O', 'ossec');

4.3、修改 apache 配置,增加虚拟目录

1
2
3
4
5
6
7
[root@tshare365 tshare365]# vim /etc/httpd/conf.d/tshare365.conf
 
<Directory /var/www/html/tshare365>
    Order deny,allow
    Deny from all
    Allow from 192.168.0.0/16
</Directory>

4.4、重启http服务

1
[root@tshare365 tshare365]# /etc/init.d/httpd restart

五、客户端访问测试

5.1、游览器访问

OSSEC入侵检测系统的安装部署

本博客到此结束,如有什么问题,求留言!

前言

OSSEC是一款开源的多平台的入侵检测系统,可以运行于Windows, Linux, OpenBSD/FreeBSD, 以及 MacOS等操作系统中。包括了日志分析,全面检测,root-kit检测。作为一款HIDS,OSSEC应该被安装在一台实施监控的系统中。另外有时候不需要安装完全版本得OSSEC,如果有多台电脑都安装了OSSEC,那么就可以采用C/S模式来运行。客户机通过客户端程序将数据发回到服务器端进行分析。

OSSEC服务端IP:192.168.1.107

OSSEC Agent IP:192.168.1.54

OSSEC 软件 包下载 地址 http://www.ossec.net/files/ossec-hids-2.8.1.tar.gz

OSSEC web下载  https://github.com/ECSC/analogi/archive/master.zip

一、OSSEC环境安装

1.1、安装基础环境

1
[root@tshare365 ~]# yum install wget gcc make mysql mysql-server mysql-devel httpd php php-mysql sendmail

1.2、启动服务

1
[root@tshare365 ~]# for i in {httpd,mysqld,sendmail};do service $i restart;done

1.3、数据库的授权

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@tshare365 ~]# mysql
mysql> create database ossec;
Query OK, 1 row affected (0.00 sec)
 
mysql> grant INSERT,SELECT,UPDATE,CREATE,DELETE,EXECUTE on ossec.* to ossec@localhost;
Query OK, 0 rows affected (0.00 sec)
 
mysql> set password for ossec@localhost=PASSWORD('ossec');
Query OK, 0 rows affected (0.00 sec)
 
mysql> flush privileges
    -> ;
Query OK, 0 rows affected (0.00 sec)
 
mysql> exit
Bye
[root@tshare365 ~]#

三、OSSEC服务端安装配置

3.1、安装OSSEC

1
2
3
4
5
6
7
[root@tshare365 ~]# tar xf ossec-hids-2.8.1.tar.gz 
[root@tshare365 ~]# cd ossec-hids-2.8.1
[root@tshare365 ossec-hids-2.8.1]# cd src/
[root@tshare365 src]# make setdb; cd  .. 
Error: PostgreSQL client libraries not installed.
 
Info: Compiled with MySQL support.

注意: 只要是出现 Mysql support 就说明是支持Mysql的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
[root@tshare365 ossec-hids-2.8.1]# ./install.sh 
  
 您将开始 OSSEC HIDS 的安装.
 请确认在您的机器上已经正确安装了 C 编译器.
 如果您有任何疑问或建议,请给 dcid@ossec.net (或 daniel.cid@gmail.com) 发邮件.
  
  - 系统类型: Linux tshare365 2.6.32-431.el6.x86_64
  - 用户: root
  - 主机: tshare365
  
1- 您希望哪一种安装 (server, agent, local or help)? server
 
  - 选择了 Server 类型的安装.
 
2- 正在初始化安装环境.
 
 - 请选择 OSSEC HIDS 的安装路径 [/var/ossec]: /user/local/ossec
 
    - OSSEC HIDS 将安装在  /user/local/ossec .
 
3- 正在配置 OSSEC HIDS.
 
  3.1- 您希望收到e-mail告警吗? (y/n) [y]: y
   - 请输入您的 e-mail 地址? 903914685@qq.com
   - 请输入您的 SMTP 服务器IP或主机名 ? 127.0.0.1
 
  3.2- 您希望运行系统完整性检测模块吗? (y/n) [y]: y
 
   - 系统完整性检测模块将被部署.
 
  3.3- 您希望运行 rootkit检测吗? (y/n) [y]: y
 
   - rootkit检测将被部署.
        
  3.4- 关联响应允许您在分析已接收事件的基础上执行一个
       已定义的命令.
       例如,你可以阻止某个IP地址的访问或禁止某个用户的访问权限.
       更多的信息,您可以访问:
       http://www.ossec.net/en/manual.html#active-response
   - 您希望开启联动(active response)功能吗? (y/n) [y]: y
 
 
     - 关联响应已开启
 
   - 默认情况下, 我们开启了主机拒绝和防火墙拒绝两种响应.
     第一种情况将添加一个主机到 /etc/hosts.deny.
     第二种情况将在iptables(linux)或ipfilter(Solaris,
     FreeBSD 或 NetBSD)中拒绝该主机的访问.
   - 该功能可以用以阻止 SSHD 暴力攻击, 端口扫描和其他
     一些形式的攻击. 同样你也可以将他们添加到其他地方,
     例如将他们添加为 snort 的事件.
 
   - 您希望开启防火墙联动(firewall-drop)功能吗? (y/n) [y]: y
 
     - 防火墙联动(firewall-drop)当事件级别 >= 6 时被启动
 
   - 联动功能默认的白名单是:
      - 202.99.166.4
      - 202.99.160.68
 
   - 您希望添加更多的IP到白名单吗? (y/n)? [n]: y
   - 请输入IP (用空格进行分隔): 8.8.8.8,4.4.4.4
 
  3.5- 您希望接收远程机器syslog吗 (port 514 udp)? (y/n) [y]: y
 
   - 远程机器syslog将被接收.
 
  3.6- 设置配置文件以分析一下日志:
    -- /var/log/messages
    -- /var/log/secure
    -- /var/log/maillog
    -- /var/log/httpd/error_log (apache log)
    -- /var/log/httpd/access_log (apache log)
                             
 -如果你希望监控其他文件, 只需要在配置文件ossec.conf中
  添加新的一项. 
  任何关于配置的疑问您都可以在 http://www.ossec.net 找到答案.
 
  --- 按 ENTER 以继续 ---
   
  ..........编译安装过程省略......
   
 - 系统类型是  Redhat Linux.
 - 修改启动脚本使 OSSEC HIDS 在系统启动时自动运行 
 
 - 已正确完成系统配置.
 
 - 要启动 OSSEC HIDS:
        /user/local/ossec/bin/ossec-control start
 
 - 要停止 OSSEC HIDS:
        /user/local/ossec/bin/ossec-control stop
 
 - 要查看或修改系统配置,请编辑  /user/local/ossec/etc/ossec.conf

3.2、启用数据库支持并导入数据

1
[root@tshare365 ossec-hids-2.8.1]# /user/local/ossec/bin/ossec-control enable database

1
[root@tshare365 ossec-hids-2.8.1]# mysql -uossec -p ossec < ./src/os_dbd/mysql.schema

3.3、修改部分配置文件的权限

1
[root@tshare365 ossec-hids-2.8.1]# chmod u+w /user/local/ossec/etc/ossec.conf

3.4、修改/user/local/ossec/etc/ossec.conf添加Mysql信息

1
2
3
4
5
6
7
8
9
<ossec_config>
    <database_output>
        <hostname>127.0.0.1</hostname>
        <username>ossec</username>
        <password>ossec</password>
        <database>ossec</database>
        <type>mysql</type>
    </database_output>
</ossec_config>

3.5、接收远端syslog信息

1
2
3
4
 <remote>
    <connection>syslog</connection>
    <allowed-ips>192.168.0.0/16</allowed-ips>
  </remote>

3.6、配置Agent信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
[root@tshare365 ossec-hids-2.8.1]# /user/local/ossec/bin/manage_agents 
****************************************
* OSSEC HIDS v2.8 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: ossec-agent
   * The IP Address of the new agent: 192.168.1.54
   * An ID for the new agent[001]: 
Agent information:
   ID:001
   Name:ossec-agent
   IP Address:192.168.1.54
 
Confirm adding it?(y/n): y
Agent added.
 
 
****************************************
* OSSEC HIDS v2.8 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: ossec-agent, IP: 192.168.1.54
Provide the ID of the agent to extract the key (or 'q' to quit): 001
 
Agent key information for '001' is: 
MDAxIG9zc2VjLWFnZW50IDE5Mi4xNjguMS41NCA5Nzc1N2I5NDk3ZDcwNTRkMGZkNzZhYTE0MzE4ZWZlOWNjZmNiZjM5NzhhYTVkMDA1NjE5OWE2ZDc5ZGRmNjgw
 
** Press ENTER to return to the main menu.

注意、需要将key记录到文本中,后面需要用到

3.7、启动OSSEC服务

1
[root@tshare365 ossec-hids-2.8.1]# /user/local/ossec/bin/ossec-control restart

四、安装OSSEC客户端

4.1、安装Agent端

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
[root@ossec-agent ~]# tar xf ossec-hids-2.8.1.tar.gz 
[root@ossec-agent ~]# cd ossec-hids-2.8.1
[root@ossec-agent ossec-hids-2.8.1]# ./install.sh 
which: no host in (/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin)
 
  ** Para instalação em português, escolha [br].
  ** 要使用中文进行安装, 请选择 [cn].
  ** Fur eine deutsche Installation wohlen Sie [de].
  ** Για εγκατάσταση στα Ελληνικά, επιλέξτε [el].
  ** For installation in English, choose [en].
  ** Para instalar en Español , eliga [es].
  ** Pour une installation en français, choisissez [fr]
  ** A Magyar nyelvű telepítéshez válassza [hu].
  ** Per l'installazione in Italiano, scegli [it].
  ** 日本語でインストールします.選択して下さい.[jp].
  ** Voor installatie in het Nederlands, kies [nl].
  ** Aby instalować w języku Polskim, wybierz [pl].
  ** Для инструкций по установке на русском ,введите [ru].
  ** Za instalaciju na srpskom, izaberi [sr].
  ** Türkçe kurulum için seçin [tr].
  (en/br/cn/de/el/es/fr/hu/it/jp/nl/pl/ru/sr/tr) [en]: cn
which: no host in (/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin)
 OSSEC HIDS v2.8 安装脚本 - http://www.ossec.net
  
 您将开始 OSSEC HIDS 的安装.
 请确认在您的机器上已经正确安装了 C 编译器.
 如果您有任何疑问或建议,请给 dcid@ossec.net (或 daniel.cid@gmail.com) 发邮件.
  
  - 系统类型: Linux ossec-agent 2.6.32-431.el6.x86_64
  - 用户: root
  - 主机: ossec-agent
 
 
  -- 按 ENTER 继续或 Ctrl-C 退出. --
 
 
1- 您希望哪一种安装 (server, agent, local or help)? agent
 
  - 选择了 Agent(client) 类型的安装.
 
2- 正在初始化安装环境.
 
 - 请选择 OSSEC HIDS 的安装路径 [/var/ossec]: /user/local/ossec
 
    - OSSEC HIDS 将安装在  /user/local/ossec .
 
3- 正在配置 OSSEC HIDS.
 
  3.1- 请输入 OSSEC HIDS 服务器的IP地址或主机名: 192.168.1.107
 
   - 添加服务器IP  192.168.1.107
 
  3.2- 您希望运行系统完整性检测模块吗? (y/n) [y]: y
 
   - 系统完整性检测模块将被部署.
 
  3.3- 您希望运行 rootkit检测吗? (y/n) [y]: y
 
   - rootkit检测将被部署.
 
  3.4 - 您希望开启联动(active response)功能吗? (y/n) [y]: y
 
 
  3.5- 设置配置文件以分析一下日志:
    -- /var/log/messages
    -- /var/log/secure
    -- /var/log/maillog
 
                             
 -如果你希望监控其他文件, 只需要在配置文件ossec.conf中
  添加新的一项. 
  任何关于配置的疑问您都可以在 http://www.ossec.net 找到答案.
 
 
  --- 按 ENTER 以继续 ---
 
 
5- 正在安装系统
 - 正在运行Makefile
 编译安装输出省略....
  
 - 系统类型是  Redhat Linux.
 - 修改启动脚本使 OSSEC HIDS 在系统启动时自动运行 
 
 - 已正确完成系统配置.
 
 - 要启动 OSSEC HIDS:
        /user/local/ossec/bin/ossec-control start
 
 - 要停止 OSSEC HIDS:
        /user/local/ossec/bin/ossec-control stop
 
 - 要查看或修改系统配置,请编辑  /user/local/ossec/etc/ossec.conf
 
 
 
    感谢使用 OSSEC HIDS.
    如果您有任何疑问,建议或您找到任何bug,
    请通过 contact@ossec.net 或邮件列表 ossec-list@ossec.net 联系我们.    
    ( http://www.ossec.net/en/mailing_lists.html ).
 
    您可以在 http://www.ossec.net 获得更多信息
 
    --- 请按 ENTER 结束安装 (下面可能有更多信息). ---
 
    
 - 您必须首先将该代理添加到服务器端以使他们能够相互通信.
   这样做了以后,您可以运行'manage_agents'工具导入
   服务器端产生的认证密匙.
   /user/local/ossec/bin/manage_agents
 
   详细信息请参考: 
   http://www.ossec.net/en/manual.html#ma
 
[root@ossec-agent ossec-hids-2.8.1]#

4.2、配置Agent

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[root@ossec-agent ossec-hids-2.8.1]# /user/local/ossec/bin/manage_agents  
 
****************************************
* OSSEC HIDS v2.8 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): MDAxIG9zc2VjLWFnZW50IDE5Mi4xNjguMS41NCA5Nzc1N2I5NDk3ZDcwNTRkMGZkNzZhYTE0MzE4ZWZlOWNjZmNiZjM5NzhhYTVkMDA1NjE5OWE2ZDc5ZGRmNjgw
 
Agent information:
   ID:001
   Name:ossec-agent
   IP Address:192.168.1.54
 
Confirm adding it?(y/n): y
Added.
** Press ENTER to return to the main menu.

4.3、启动Agent服务

1
[root@ossec-agent ossec-hids-2.8.1]# /user/local/ossec/bin/ossec-control start

 

四、安装web界面服务

4.1、安装web

1
2
3
4
[root@tshare365 ~]# mv analogi-master /var/www/html/tshare365
[root@tshare365 ~]# chown -R apache.apache /var/www/html/tshare365/
[root@tshare365 ~]# cd /var/www/html/tshare365/
[root@tshare365 tshare365]# cp db_ossec.php.new db_ossec.php

4.2、编辑db_ossec.php文件,修改MySQL的配置信息

1
2
3
4
define ('DB_USER_O', 'ossec');
define ('DB_PASSWORD_O', 'ossec');
define ('DB_HOST_O', '127.0.0.1');
define ('DB_NAME_O', 'ossec');

4.3、修改 apache 配置,增加虚拟目录

1
2
3
4
5
6
7
[root@tshare365 tshare365]# vim /etc/httpd/conf.d/tshare365.conf
 
<Directory /var/www/html/tshare365>
    Order deny,allow
    Deny from all
    Allow from 192.168.0.0/16
</Directory>

4.4、重启http服务

1
[root@tshare365 tshare365]# /etc/init.d/httpd restart

五、客户端访问测试

5.1、游览器访问

OSSEC入侵检测系统的安装部署

本博客到此结束,如有什么问题,求留言!

前言

OSSEC是一款开源的多平台的入侵检测系统,可以运行于Windows, Linux, OpenBSD/FreeBSD, 以及 MacOS等操作系统中。包括了日志分析,全面检测,root-kit检测。作为一款HIDS,OSSEC应该被安装在一台实施监控的系统中。另外有时候不需要安装完全版本得OSSEC,如果有多台电脑都安装了OSSEC,那么就可以采用C/S模式来运行。客户机通过客户端程序将数据发回到服务器端进行分析。

OSSEC服务端IP:192.168.1.107

OSSEC Agent IP:192.168.1.54

OSSEC 软件 包下载 地址 http://www.ossec.net/files/ossec-hids-2.8.1.tar.gz

OSSEC web下载  https://github.com/ECSC/analogi/archive/master.zip

一、OSSEC环境安装

1.1、安装基础环境

1
[root@tshare365 ~]# yum install wget gcc make mysql mysql-server mysql-devel httpd php php-mysql sendmail

1.2、启动服务

1
[root@tshare365 ~]# for i in {httpd,mysqld,sendmail};do service $i restart;done

1.3、数据库的授权

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@tshare365 ~]# mysql
mysql> create database ossec;
Query OK, 1 row affected (0.00 sec)
 
mysql> grant INSERT,SELECT,UPDATE,CREATE,DELETE,EXECUTE on ossec.* to ossec@localhost;
Query OK, 0 rows affected (0.00 sec)
 
mysql> set password for ossec@localhost=PASSWORD('ossec');
Query OK, 0 rows affected (0.00 sec)
 
mysql> flush privileges
    -> ;
Query OK, 0 rows affected (0.00 sec)
 
mysql> exit
Bye
[root@tshare365 ~]#

三、OSSEC服务端安装配置

3.1、安装OSSEC

1
2
3
4
5
6
7
[root@tshare365 ~]# tar xf ossec-hids-2.8.1.tar.gz 
[root@tshare365 ~]# cd ossec-hids-2.8.1
[root@tshare365 ossec-hids-2.8.1]# cd src/
[root@tshare365 src]# make setdb; cd  .. 
Error: PostgreSQL client libraries not installed.
 
Info: Compiled with MySQL support.

注意: 只要是出现 Mysql support 就说明是支持Mysql的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
[root@tshare365 ossec-hids-2.8.1]# ./install.sh 
  
 您将开始 OSSEC HIDS 的安装.
 请确认在您的机器上已经正确安装了 C 编译器.
 如果您有任何疑问或建议,请给 dcid@ossec.net (或 daniel.cid@gmail.com) 发邮件.
  
  - 系统类型: Linux tshare365 2.6.32-431.el6.x86_64
  - 用户: root
  - 主机: tshare365
  
1- 您希望哪一种安装 (server, agent, local or help)? server
 
  - 选择了 Server 类型的安装.
 
2- 正在初始化安装环境.
 
 - 请选择 OSSEC HIDS 的安装路径 [/var/ossec]: /user/local/ossec
 
    - OSSEC HIDS 将安装在  /user/local/ossec .
 
3- 正在配置 OSSEC HIDS.
 
  3.1- 您希望收到e-mail告警吗? (y/n) [y]: y
   - 请输入您的 e-mail 地址? 903914685@qq.com
   - 请输入您的 SMTP 服务器IP或主机名 ? 127.0.0.1
 
  3.2- 您希望运行系统完整性检测模块吗? (y/n) [y]: y
 
   - 系统完整性检测模块将被部署.
 
  3.3- 您希望运行 rootkit检测吗? (y/n) [y]: y
 
   - rootkit检测将被部署.
        
  3.4- 关联响应允许您在分析已接收事件的基础上执行一个
       已定义的命令.
       例如,你可以阻止某个IP地址的访问或禁止某个用户的访问权限.
       更多的信息,您可以访问:
       http://www.ossec.net/en/manual.html#active-response
   - 您希望开启联动(active response)功能吗? (y/n) [y]: y
 
 
     - 关联响应已开启
 
   - 默认情况下, 我们开启了主机拒绝和防火墙拒绝两种响应.
     第一种情况将添加一个主机到 /etc/hosts.deny.
     第二种情况将在iptables(linux)或ipfilter(Solaris,
     FreeBSD 或 NetBSD)中拒绝该主机的访问.
   - 该功能可以用以阻止 SSHD 暴力攻击, 端口扫描和其他
     一些形式的攻击. 同样你也可以将他们添加到其他地方,
     例如将他们添加为 snort 的事件.
 
   - 您希望开启防火墙联动(firewall-drop)功能吗? (y/n) [y]: y
 
     - 防火墙联动(firewall-drop)当事件级别 >= 6 时被启动
 
   - 联动功能默认的白名单是:
      - 202.99.166.4
      - 202.99.160.68
 
   - 您希望添加更多的IP到白名单吗? (y/n)? [n]: y
   - 请输入IP (用空格进行分隔): 8.8.8.8,4.4.4.4
 
  3.5- 您希望接收远程机器syslog吗 (port 514 udp)? (y/n) [y]: y
 
   - 远程机器syslog将被接收.
 
  3.6- 设置配置文件以分析一下日志:
    -- /var/log/messages
    -- /var/log/secure
    -- /var/log/maillog
    -- /var/log/httpd/error_log (apache log)
    -- /var/log/httpd/access_log (apache log)
                             
 -如果你希望监控其他文件, 只需要在配置文件ossec.conf中
  添加新的一项. 
  任何关于配置的疑问您都可以在 http://www.ossec.net 找到答案.
 
  --- 按 ENTER 以继续 ---
   
  ..........编译安装过程省略......
   
 - 系统类型是  Redhat Linux.
 - 修改启动脚本使 OSSEC HIDS 在系统启动时自动运行 
 
 - 已正确完成系统配置.
 
 - 要启动 OSSEC HIDS:
        /user/local/ossec/bin/ossec-control start
 
 - 要停止 OSSEC HIDS:
        /user/local/ossec/bin/ossec-control stop
 
 - 要查看或修改系统配置,请编辑  /user/local/ossec/etc/ossec.conf

3.2、启用数据库支持并导入数据

1
[root@tshare365 ossec-hids-2.8.1]# /user/local/ossec/bin/ossec-control enable database

1
[root@tshare365 ossec-hids-2.8.1]# mysql -uossec -p ossec < ./src/os_dbd/mysql.schema

3.3、修改部分配置文件的权限

1
[root@tshare365 ossec-hids-2.8.1]# chmod u+w /user/local/ossec/etc/ossec.conf

3.4、修改/user/local/ossec/etc/ossec.conf添加Mysql信息

1
2
3
4
5
6
7
8
9
<ossec_config>
    <database_output>
        <hostname>127.0.0.1</hostname>
        <username>ossec</username>
        <password>ossec</password>
        <database>ossec</database>
        <type>mysql</type>
    </database_output>
</ossec_config>

3.5、接收远端syslog信息

1
2
3
4
 <remote>
    <connection>syslog</connection>
    <allowed-ips>192.168.0.0/16</allowed-ips>
  </remote>

3.6、配置Agent信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
[root@tshare365 ossec-hids-2.8.1]# /user/local/ossec/bin/manage_agents 
****************************************
* OSSEC HIDS v2.8 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: ossec-agent
   * The IP Address of the new agent: 192.168.1.54
   * An ID for the new agent[001]: 
Agent information:
   ID:001
   Name:ossec-agent
   IP Address:192.168.1.54
 
Confirm adding it?(y/n): y
Agent added.
 
 
****************************************
* OSSEC HIDS v2.8 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: ossec-agent, IP: 192.168.1.54
Provide the ID of the agent to extract the key (or 'q' to quit): 001
 
Agent key information for '001' is: 
MDAxIG9zc2VjLWFnZW50IDE5Mi4xNjguMS41NCA5Nzc1N2I5NDk3ZDcwNTRkMGZkNzZhYTE0MzE4ZWZlOWNjZmNiZjM5NzhhYTVkMDA1NjE5OWE2ZDc5ZGRmNjgw
 
** Press ENTER to return to the main menu.

注意、需要将key记录到文本中,后面需要用到

3.7、启动OSSEC服务

1
[root@tshare365 ossec-hids-2.8.1]# /user/local/ossec/bin/ossec-control restart

四、安装OSSEC客户端

4.1、安装Agent端

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
[root@ossec-agent ~]# tar xf ossec-hids-2.8.1.tar.gz 
[root@ossec-agent ~]# cd ossec-hids-2.8.1
[root@ossec-agent ossec-hids-2.8.1]# ./install.sh 
which: no host in (/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin)
 
  ** Para instalação em português, escolha [br].
  ** 要使用中文进行安装, 请选择 [cn].
  ** Fur eine deutsche Installation wohlen Sie [de].
  ** Για εγκατάσταση στα Ελληνικά, επιλέξτε [el].
  ** For installation in English, choose [en].
  ** Para instalar en Español , eliga [es].
  ** Pour une installation en français, choisissez [fr]
  ** A Magyar nyelvű telepítéshez válassza [hu].
  ** Per l'installazione in Italiano, scegli [it].
  ** 日本語でインストールします.選択して下さい.[jp].
  ** Voor installatie in het Nederlands, kies [nl].
  ** Aby instalować w języku Polskim, wybierz [pl].
  ** Для инструкций по установке на русском ,введите [ru].
  ** Za instalaciju na srpskom, izaberi [sr].
  ** Türkçe kurulum için seçin [tr].
  (en/br/cn/de/el/es/fr/hu/it/jp/nl/pl/ru/sr/tr) [en]: cn
which: no host in (/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin)
 OSSEC HIDS v2.8 安装脚本 - http://www.ossec.net
  
 您将开始 OSSEC HIDS 的安装.
 请确认在您的机器上已经正确安装了 C 编译器.
 如果您有任何疑问或建议,请给 dcid@ossec.net (或 daniel.cid@gmail.com) 发邮件.
  
  - 系统类型: Linux ossec-agent 2.6.32-431.el6.x86_64
  - 用户: root
  - 主机: ossec-agent
 
 
  -- 按 ENTER 继续或 Ctrl-C 退出. --
 
 
1- 您希望哪一种安装 (server, agent, local or help)? agent
 
  - 选择了 Agent(client) 类型的安装.
 
2- 正在初始化安装环境.
 
 - 请选择 OSSEC HIDS 的安装路径 [/var/ossec]: /user/local/ossec
 
    - OSSEC HIDS 将安装在  /user/local/ossec .
 
3- 正在配置 OSSEC HIDS.
 
  3.1- 请输入 OSSEC HIDS 服务器的IP地址或主机名: 192.168.1.107
 
   - 添加服务器IP  192.168.1.107
 
  3.2- 您希望运行系统完整性检测模块吗? (y/n) [y]: y
 
   - 系统完整性检测模块将被部署.
 
  3.3- 您希望运行 rootkit检测吗? (y/n) [y]: y
 
   - rootkit检测将被部署.
 
  3.4 - 您希望开启联动(active response)功能吗? (y/n) [y]: y
 
 
  3.5- 设置配置文件以分析一下日志:
    -- /var/log/messages
    -- /var/log/secure
    -- /var/log/maillog
 
                             
 -如果你希望监控其他文件, 只需要在配置文件ossec.conf中
  添加新的一项. 
  任何关于配置的疑问您都可以在 http://www.ossec.net 找到答案.
 
 
  --- 按 ENTER 以继续 ---
 
 
5- 正在安装系统
 - 正在运行Makefile
 编译安装输出省略....
  
 - 系统类型是  Redhat Linux.
 - 修改启动脚本使 OSSEC HIDS 在系统启动时自动运行 
 
 - 已正确完成系统配置.
 
 - 要启动 OSSEC HIDS:
        /user/local/ossec/bin/ossec-control start
 
 - 要停止 OSSEC HIDS:
        /user/local/ossec/bin/ossec-control stop
 
 - 要查看或修改系统配置,请编辑  /user/local/ossec/etc/ossec.conf
 
 
 
    感谢使用 OSSEC HIDS.
    如果您有任何疑问,建议或您找到任何bug,
    请通过 contact@ossec.net 或邮件列表 ossec-list@ossec.net 联系我们.    
    ( http://www.ossec.net/en/mailing_lists.html ).
 
    您可以在 http://www.ossec.net 获得更多信息
 
    --- 请按 ENTER 结束安装 (下面可能有更多信息). ---
 
    
 - 您必须首先将该代理添加到服务器端以使他们能够相互通信.
   这样做了以后,您可以运行'manage_agents'工具导入
   服务器端产生的认证密匙.
   /user/local/ossec/bin/manage_agents
 
   详细信息请参考: 
   http://www.ossec.net/en/manual.html#ma
 
[root@ossec-agent ossec-hids-2.8.1]#

4.2、配置Agent

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[root@ossec-agent ossec-hids-2.8.1]# /user/local/ossec/bin/manage_agents  
 
****************************************
* OSSEC HIDS v2.8 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): MDAxIG9zc2VjLWFnZW50IDE5Mi4xNjguMS41NCA5Nzc1N2I5NDk3ZDcwNTRkMGZkNzZhYTE0MzE4ZWZlOWNjZmNiZjM5NzhhYTVkMDA1NjE5OWE2ZDc5ZGRmNjgw
 
Agent information:
   ID:001
   Name:ossec-agent
   IP Address:192.168.1.54
 
Confirm adding it?(y/n): y
Added.
** Press ENTER to return to the main menu.

4.3、启动Agent服务

1
[root@ossec-agent ossec-hids-2.8.1]# /user/local/ossec/bin/ossec-control start

 

四、安装web界面服务

4.1、安装web

1
2
3
4
[root@tshare365 ~]# mv analogi-master /var/www/html/tshare365
[root@tshare365 ~]# chown -R apache.apache /var/www/html/tshare365/
[root@tshare365 ~]# cd /var/www/html/tshare365/
[root@tshare365 tshare365]# cp db_ossec.php.new db_ossec.php

4.2、编辑db_ossec.php文件,修改MySQL的配置信息

1
2
3
4
define ('DB_USER_O', 'ossec');
define ('DB_PASSWORD_O', 'ossec');
define ('DB_HOST_O', '127.0.0.1');
define ('DB_NAME_O', 'ossec');

4.3、修改 apache 配置,增加虚拟目录

1
2
3
4
5
6
7
[root@tshare365 tshare365]# vim /etc/httpd/conf.d/tshare365.conf
 
<Directory /var/www/html/tshare365>
    Order deny,allow
    Deny from all
    Allow from 192.168.0.0/16
</Directory>

4.4、重启http服务

1
[root@tshare365 tshare365]# /etc/init.d/httpd restart

五、客户端访问测试

5.1、游览器访问

OSSEC入侵检测系统的安装部署

本博客到此结束,如有什么问题,求留言!

前言

OSSEC是一款开源的多平台的入侵检测系统,可以运行于Windows, Linux, OpenBSD/FreeBSD, 以及 MacOS等操作系统中。包括了日志分析,全面检测,root-kit检测。作为一款HIDS,OSSEC应该被安装在一台实施监控的系统中。另外有时候不需要安装完全版本得OSSEC,如果有多台电脑都安装了OSSEC,那么就可以采用C/S模式来运行。客户机通过客户端程序将数据发回到服务器端进行分析。

OSSEC服务端IP:192.168.1.107

OSSEC Agent IP:192.168.1.54

OSSEC 软件 包下载 地址 http://www.ossec.net/files/ossec-hids-2.8.1.tar.gz

OSSEC web下载  https://github.com/ECSC/analogi/archive/master.zip

一、OSSEC环境安装

1.1、安装基础环境

1
[root@tshare365 ~]# yum install wget gcc make mysql mysql-server mysql-devel httpd php php-mysql sendmail

1.2、启动服务

1
[root@tshare365 ~]# for i in {httpd,mysqld,sendmail};do service $i restart;done

1.3、数据库的授权

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@tshare365 ~]# mysql
mysql> create database ossec;
Query OK, 1 row affected (0.00 sec)
 
mysql> grant INSERT,SELECT,UPDATE,CREATE,DELETE,EXECUTE on ossec.* to ossec@localhost;
Query OK, 0 rows affected (0.00 sec)
 
mysql> set password for ossec@localhost=PASSWORD('ossec');
Query OK, 0 rows affected (0.00 sec)
 
mysql> flush privileges
    -> ;
Query OK, 0 rows affected (0.00 sec)
 
mysql> exit
Bye
[root@tshare365 ~]#

三、OSSEC服务端安装配置

3.1、安装OSSEC

1
2
3
4
5
6
7
[root@tshare365 ~]# tar xf ossec-hids-2.8.1.tar.gz 
[root@tshare365 ~]# cd ossec-hids-2.8.1
[root@tshare365 ossec-hids-2.8.1]# cd src/
[root@tshare365 src]# make setdb; cd  .. 
Error: PostgreSQL client libraries not installed.
 
Info: Compiled with MySQL support.

注意: 只要是出现 Mysql support 就说明是支持Mysql的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
[root@tshare365 ossec-hids-2.8.1]# ./install.sh 
  
 您将开始 OSSEC HIDS 的安装.
 请确认在您的机器上已经正确安装了 C 编译器.
 如果您有任何疑问或建议,请给 dcid@ossec.net (或 daniel.cid@gmail.com) 发邮件.
  
  - 系统类型: Linux tshare365 2.6.32-431.el6.x86_64
  - 用户: root
  - 主机: tshare365
  
1- 您希望哪一种安装 (server, agent, local or help)? server
 
  - 选择了 Server 类型的安装.
 
2- 正在初始化安装环境.
 
 - 请选择 OSSEC HIDS 的安装路径 [/var/ossec]: /user/local/ossec
 
    - OSSEC HIDS 将安装在  /user/local/ossec .
 
3- 正在配置 OSSEC HIDS.
 
  3.1- 您希望收到e-mail告警吗? (y/n) [y]: y
   - 请输入您的 e-mail 地址? 903914685@qq.com
   - 请输入您的 SMTP 服务器IP或主机名 ? 127.0.0.1
 
  3.2- 您希望运行系统完整性检测模块吗? (y/n) [y]: y
 
   - 系统完整性检测模块将被部署.
 
  3.3- 您希望运行 rootkit检测吗? (y/n) [y]: y
 
   - rootkit检测将被部署.
        
  3.4- 关联响应允许您在分析已接收事件的基础上执行一个
       已定义的命令.
       例如,你可以阻止某个IP地址的访问或禁止某个用户的访问权限.
       更多的信息,您可以访问:
       http://www.ossec.net/en/manual.html#active-response
   - 您希望开启联动(active response)功能吗? (y/n) [y]: y
 
 
     - 关联响应已开启
 
   - 默认情况下, 我们开启了主机拒绝和防火墙拒绝两种响应.
     第一种情况将添加一个主机到 /etc/hosts.deny.
     第二种情况将在iptables(linux)或ipfilter(Solaris,
     FreeBSD 或 NetBSD)中拒绝该主机的访问.
   - 该功能可以用以阻止 SSHD 暴力攻击, 端口扫描和其他
     一些形式的攻击. 同样你也可以将他们添加到其他地方,
     例如将他们添加为 snort 的事件.
 
   - 您希望开启防火墙联动(firewall-drop)功能吗? (y/n) [y]: y
 
     - 防火墙联动(firewall-drop)当事件级别 >= 6 时被启动
 
   - 联动功能默认的白名单是:
      - 202.99.166.4
      - 202.99.160.68
 
   - 您希望添加更多的IP到白名单吗? (y/n)? [n]: y
   - 请输入IP (用空格进行分隔): 8.8.8.8,4.4.4.4
 
  3.5- 您希望接收远程机器syslog吗 (port 514 udp)? (y/n) [y]: y
 
   - 远程机器syslog将被接收.
 
  3.6- 设置配置文件以分析一下日志:
    -- /var/log/messages
    -- /var/log/secure
    -- /var/log/maillog
    -- /var/log/httpd/error_log (apache log)
    -- /var/log/httpd/access_log (apache log)
                             
 -如果你希望监控其他文件, 只需要在配置文件ossec.conf中
  添加新的一项. 
  任何关于配置的疑问您都可以在 http://www.ossec.net 找到答案.
 
  --- 按 ENTER 以继续 ---
   
  ..........编译安装过程省略......
   
 - 系统类型是  Redhat Linux.
 - 修改启动脚本使 OSSEC HIDS 在系统启动时自动运行 
 
 - 已正确完成系统配置.
 
 - 要启动 OSSEC HIDS:
        /user/local/ossec/bin/ossec-control start
 
 - 要停止 OSSEC HIDS:
        /user/local/ossec/bin/ossec-control stop
 
 - 要查看或修改系统配置,请编辑  /user/local/ossec/etc/ossec.conf

3.2、启用数据库支持并导入数据

1
[root@tshare365 ossec-hids-2.8.1]# /user/local/ossec/bin/ossec-control enable database

1
[root@tshare365 ossec-hids-2.8.1]# mysql -uossec -p ossec < ./src/os_dbd/mysql.schema

3.3、修改部分配置文件的权限

1
[root@tshare365 ossec-hids-2.8.1]# chmod u+w /user/local/ossec/etc/ossec.conf

3.4、修改/user/local/ossec/etc/ossec.conf添加Mysql信息

1
2
3
4
5
6
7
8
9
<ossec_config>
    <database_output>
        <hostname>127.0.0.1</hostname>
        <username>ossec</username>
        <password>ossec</password>
        <database>ossec</database>
        <type>mysql</type>
    </database_output>
</ossec_config>

3.5、接收远端syslog信息

1
2
3
4
 <remote>
    <connection>syslog</connection>
    <allowed-ips>192.168.0.0/16</allowed-ips>
  </remote>

3.6、配置Agent信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
[root@tshare365 ossec-hids-2.8.1]# /user/local/ossec/bin/manage_agents 
****************************************
* OSSEC HIDS v2.8 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: ossec-agent
   * The IP Address of the new agent: 192.168.1.54
   * An ID for the new agent[001]: 
Agent information:
   ID:001
   Name:ossec-agent
   IP Address:192.168.1.54
 
Confirm adding it?(y/n): y
Agent added.
 
 
****************************************
* OSSEC HIDS v2.8 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: ossec-agent, IP: 192.168.1.54
Provide the ID of the agent to extract the key (or 'q' to quit): 001
 
Agent key information for '001' is: 
MDAxIG9zc2VjLWFnZW50IDE5Mi4xNjguMS41NCA5Nzc1N2I5NDk3ZDcwNTRkMGZkNzZhYTE0MzE4ZWZlOWNjZmNiZjM5NzhhYTVkMDA1NjE5OWE2ZDc5ZGRmNjgw
 
** Press ENTER to return to the main menu.

注意、需要将key记录到文本中,后面需要用到

3.7、启动OSSEC服务

1
[root@tshare365 ossec-hids-2.8.1]# /user/local/ossec/bin/ossec-control restart

四、安装OSSEC客户端

4.1、安装Agent端

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
[root@ossec-agent ~]# tar xf ossec-hids-2.8.1.tar.gz 
[root@ossec-agent ~]# cd ossec-hids-2.8.1
[root@ossec-agent ossec-hids-2.8.1]# ./install.sh 
which: no host in (/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin)
 
  ** Para instalação em português, escolha [br].
  ** 要使用中文进行安装, 请选择 [cn].
  ** Fur eine deutsche Installation wohlen Sie [de].
  ** Για εγκατάσταση στα Ελληνικά, επιλέξτε [el].
  ** For installation in English, choose [en].
  ** Para instalar en Español , eliga [es].
  ** Pour une installation en français, choisissez [fr]
  ** A Magyar nyelvű telepítéshez válassza [hu].
  ** Per l'installazione in Italiano, scegli [it].
  ** 日本語でインストールします.選択して下さい.[jp].
  ** Voor installatie in het Nederlands, kies [nl].
  ** Aby instalować w języku Polskim, wybierz [pl].
  ** Для инструкций по установке на русском ,введите [ru].
  ** Za instalaciju na srpskom, izaberi [sr].
  ** Türkçe kurulum için seçin [tr].
  (en/br/cn/de/el/es/fr/hu/it/jp/nl/pl/ru/sr/tr) [en]: cn
which: no host in (/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin)
 OSSEC HIDS v2.8 安装脚本 - http://www.ossec.net
  
 您将开始 OSSEC HIDS 的安装.
 请确认在您的机器上已经正确安装了 C 编译器.
 如果您有任何疑问或建议,请给 dcid@ossec.net (或 daniel.cid@gmail.com) 发邮件.
  
  - 系统类型: Linux ossec-agent 2.6.32-431.el6.x86_64
  - 用户: root
  - 主机: ossec-agent
 
 
  -- 按 ENTER 继续或 Ctrl-C 退出. --
 
 
1- 您希望哪一种安装 (server, agent, local or help)? agent
 
  - 选择了 Agent(client) 类型的安装.
 
2- 正在初始化安装环境.
 
 - 请选择 OSSEC HIDS 的安装路径 [/var/ossec]: /user/local/ossec
 
    - OSSEC HIDS 将安装在  /user/local/ossec .
 
3- 正在配置 OSSEC HIDS.
 
  3.1- 请输入 OSSEC HIDS 服务器的IP地址或主机名: 192.168.1.107
 
   - 添加服务器IP  192.168.1.107
 
  3.2- 您希望运行系统完整性检测模块吗? (y/n) [y]: y
 
   - 系统完整性检测模块将被部署.
 
  3.3- 您希望运行 rootkit检测吗? (y/n) [y]: y
 
   - rootkit检测将被部署.
 
  3.4 - 您希望开启联动(active response)功能吗? (y/n) [y]: y
 
 
  3.5- 设置配置文件以分析一下日志:
    -- /var/log/messages
    -- /var/log/secure
    -- /var/log/maillog
 
                             
 -如果你希望监控其他文件, 只需要在配置文件ossec.conf中
  添加新的一项. 
  任何关于配置的疑问您都可以在 http://www.ossec.net 找到答案.
 
 
  --- 按 ENTER 以继续 ---
 
 
5- 正在安装系统
 - 正在运行Makefile
 编译安装输出省略....
  
 - 系统类型是  Redhat Linux.
 - 修改启动脚本使 OSSEC HIDS 在系统启动时自动运行 
 
 - 已正确完成系统配置.
 
 - 要启动 OSSEC HIDS:
        /user/local/ossec/bin/ossec-control start
 
 - 要停止 OSSEC HIDS:
        /user/local/ossec/bin/ossec-control stop
 
 - 要查看或修改系统配置,请编辑  /user/local/ossec/etc/ossec.conf
 
 
 
    感谢使用 OSSEC HIDS.
    如果您有任何疑问,建议或您找到任何bug,
    请通过 contact@ossec.net 或邮件列表 ossec-list@ossec.net 联系我们.    
    ( http://www.ossec.net/en/mailing_lists.html ).
 
    您可以在 http://www.ossec.net 获得更多信息
 
    --- 请按 ENTER 结束安装 (下面可能有更多信息). ---
 
    
 - 您必须首先将该代理添加到服务器端以使他们能够相互通信.
   这样做了以后,您可以运行'manage_agents'工具导入
   服务器端产生的认证密匙.
   /user/local/ossec/bin/manage_agents
 
   详细信息请参考: 
   http://www.ossec.net/en/manual.html#ma
 
[root@ossec-agent ossec-hids-2.8.1]#

4.2、配置Agent

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[root@ossec-agent ossec-hids-2.8.1]# /user/local/ossec/bin/manage_agents  
 
****************************************
* OSSEC HIDS v2.8 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): MDAxIG9zc2VjLWFnZW50IDE5Mi4xNjguMS41NCA5Nzc1N2I5NDk3ZDcwNTRkMGZkNzZhYTE0MzE4ZWZlOWNjZmNiZjM5NzhhYTVkMDA1NjE5OWE2ZDc5ZGRmNjgw
 
Agent information:
   ID:001
   Name:ossec-agent
   IP Address:192.168.1.54
 
Confirm adding it?(y/n): y
Added.
** Press ENTER to return to the main menu.

4.3、启动Agent服务

1
[root@ossec-agent ossec-hids-2.8.1]# /user/local/ossec/bin/ossec-control start

 

四、安装web界面服务

4.1、安装web

1
2
3
4
[root@tshare365 ~]# mv analogi-master /var/www/html/tshare365
[root@tshare365 ~]# chown -R apache.apache /var/www/html/tshare365/
[root@tshare365 ~]# cd /var/www/html/tshare365/
[root@tshare365 tshare365]# cp db_ossec.php.new db_ossec.php

4.2、编辑db_ossec.php文件,修改MySQL的配置信息

1
2
3
4
define ('DB_USER_O', 'ossec');
define ('DB_PASSWORD_O', 'ossec');
define ('DB_HOST_O', '127.0.0.1');
define ('DB_NAME_O', 'ossec');

4.3、修改 apache 配置,增加虚拟目录

1
2
3
4
5
6
7
[root@tshare365 tshare365]# vim /etc/httpd/conf.d/tshare365.conf
 
<Directory /var/www/html/tshare365>
    Order deny,allow
    Deny from all
    Allow from 192.168.0.0/16
</Directory>

4.4、重启http服务

1
[root@tshare365 tshare365]# /etc/init.d/httpd restart

五、客户端访问测试

5.1、游览器访问

OSSEC入侵检测系统的安装部署

本博客到此结束,如有什么问题,求留言!

如果觉得我的文章对您有用,请点赞。您的支持将鼓励我继续创作!

2

添加新评论1 条评论

chenyueguchenyuegu研发工程师众生数据
2017-06-15 10:52
这是互联网风气吗?满互联网都是拷贝的东西,毫无探索的记录
Ctrl+Enter 发表

作者其他文章

相关文章

相关问题

相关资料

X社区推广