OSSEC For Website Security: PART II – Distributed Architectures Using Agents and Managers
By Tony Perez | November 30, 2018
本文假设您已部署OSSEC。如需复习,请参考2013年3月写的OSSEC网站安全第一部分。
OSSEC是流行的开源主机入侵检测系统(HIDS),由Daniel Cid创建,目前由庞大的安全专业人士社区维护。请注意,我不使用官方仓库安装,而是直接使用Daniel的仓库(上篇文章中有说明)。
在本系列中,我将分享OSSEC部署的基础要素。本文重点介绍部署分布式架构的重要性,利用代理/管理器选项。后续文章将涵盖为WordPress等CMS应用程序配置的最佳方式、调整引擎以利用警报和通知。
如有疑问,请随时提出。
代理/管理器架构
主动监控、聚合和存储服务器活动(如日志)对安全专业人士至关重要。这是安全中不太性感的方面,但拥有此活动的真相源对于理解服务器上发生的情况至关重要——尤其是在入侵后。
事实上,如果您运营在线商店,您实际上有义务存储和管理此活动:
定期监控和测试网络
要求10:跟踪和监控所有对网络资源和持卡人数据的访问
日志机制和跟踪用户活动的能力对于预防、检测和最小化数据泄露的影响至关重要。所有环境中的日志存在允许在出现问题时进行彻底跟踪、警报和分析。如果没有系统活动日志,确定泄露原因非常困难(如果不是不可能的话)。(来源:要求和安全评估程序,版本3.2.1)
为协助此过程,我以分布式方式部署OSSEC,利用其代理和管理器架构。虽然我对Web服务器部署有一定信心,但我意识到总是存在可能遗漏某些东西的威胁。因此,我总是将活动推送到远程服务,该服务唯一负责管理、聚合和报告整个架构中的所有活动。
这为我提供以下保证:
- 降低攻击者尝试删除或修改活动的风险;
- 将整个环境的活动合并到一个真相记录中,尤其在管理多个服务器时非常重要;
- 促进为整个堆栈创建同步编排(即,所有工作并报告相同);
简而言之,此图突出显示了我的部署:
部署代理/管理器架构
如果您运行本地OSSEC实现,则需要重新运行OSSEC安装程序。有方法可以破解配置,但除非您有一个空闲的周末(它从来不仅仅是一件事…),否则不值得。
在您的Web服务器上:
选择您的语言,安装程序将开始。此时您将设置代理:
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
|
OSSEC HIDS r2016-04 Installation Script - http://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 dcid@ossec.net (or daniel.cid@gmail.com).
- System: Linux
- User: root
- Host: [webserver name]
-- Press ENTER to continue or Ctrl-C to abort. --
1- What kind of installation do you want (server, agent, local or help)? agent
|
下一步是提供管理器的IP,如果您在安装时不知道,没关系。您始终可以在ossec.conf文件中更新IP。
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
|
OSSEC HIDS r2016-04 Installation Script - http://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 dcid@ossec.net (or daniel.cid@gmail.com).
- System: Linux
- User: root
- Host: [webserver name]
-- Press ENTER to continue or Ctrl-C to abort. --
1- What kind of installation do you want (server, agent, local or help)? agent
- Agent(client) 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- What's the IP Address of the OSSEC HIDS server?: [Manager IP]
- Adding Server IP [Manager IP]
|
按照说明设置配置选项。完成后,最后一步是按键盘上的Enter完成安装。
这将配置您的本地代理,但现在您需要导航到OSSEC管理器以确保它准备好接受来自代理的通信。您通过创建密钥对来实现这一点,代理和管理器将使用该密钥对相互认证。
在您的OSSEC管理器上导航到Manage Agents应用程序:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# /var/ossec/bin/manage_agents
****************************************
* OSSEC HIDS v2016-04 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。然后它将询问一系列问题,这是您要考虑命名约定的地方。例如,见下文:
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
|
****************************************
* OSSEC HIDS v2016-04 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: pb.webserver1
* The IP Address of the new agent: any
* An ID for the new agent[001]: 01001
Agent information:
ID:01001
Name:pb.webserver1
IP Address:any
Confirm adding it?(y/n): y
|
您看到的是我使用PB(perezbox)来标识我负责的服务器(假设您可能管理不是您的服务器),并为每个Web服务器应用命名约定(例如,webserver1)。我可以选择使其更具描述性(也许使用该服务器上的域名)。
注意:我为“新代理的IP地址”选择ANY,这是故意的。我发现这比明确定义代理服务器的IP更有效。
如果一切看起来良好,选择Y。
如果全部成功,它将看起来像这样——询问您下一步要做什么:
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
|
Agent added.
****************************************
* OSSEC HIDS v2016-04 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
|
在我们的案例中,我们要提取新代理的密钥。因此我们输入E。
1
2
3
4
5
6
7
8
9
10
11
12
13
|
Available agents:
ID: 01001, Name: pb.webserver1, IP: any
ID: 01002, Name: pb.webserver2, IP: any
Provide the ID of the agent to extract the key (or '\q' to quit): 01001
Agent key information for '01001' is:
[Unique Key Will be Provided for the New Agent]
|
现在您要切换到代理服务器并将该密钥复制到该服务器。您通过在代理服务器上导航到Manage Agents应用程序来实现:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# /var/ossec/bin/manage_agents
****************************************
* OSSEC HIDS v2016-04 Agent manager. *
* The following options are available: *
****************************************
(I)mport key from the server (I).
(Q)uit.
Choose your action: I or Q:
|
选择I(导入)选项。这将使您有机会将密钥复制到新代理,并确认数据:
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
|
* 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):
[Copy the Unique Key Provided by the Manager]
Agent information:
ID:01001
Name:pb.webserver1
IP Address:any
Confirm adding it?(y/n):
|
您会注意到,当您输入密钥时,它将显示您在管理器上设置的代理信息,使用此机会确认配置。
现在您要重新启动代理服务器,在此之前在管理器服务器上运行TAIL命令以监视代理是否发送信息。您可以通过查看ossec.log文件或alerts.log来实现。我将监视alerts.log文件以查找任何对pb.webserver1的引用:
1
|
tail -F /var/ossec/logs/alerts/alerts.log | grep "pb.webserver1"
|
一旦我在管理器上读取,我将启动OSSEC代理。输出将如下所示:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
# /var/ossec/bin/ossec-control start
Starting OSSEC HIDS r2016-04 (by Daniel B. Cid)...
Started ossec-execd...
Started ossec-agentd...
Started ossec-logcollector...
Started ossec-syscheckd...
Completed.
|
在代理上,您寻找这个:
1
|
2018/11/30 19:22:42 ossec-agentd(4102): INFO: Connected to the server (your manager IP address).
|
在服务器上,您寻找这个:
1
2
3
4
5
6
7
|
** Alert 1543605762.8214223: mail - ossec,
2018 Nov 30 19:22:42 (pb.webserver1) any->ossec
Rule: 501 (level 3) -> 'New ossec agent connected.'
ossec: Agent started: 'pb.webserver1->any'.
|
就这样,您的新OSSEC部署全部设置完成。
发布在安全类别,并标记为入侵检测系统(IDS)、日志管理、OSSEC、Web托管和Web服务器。