上次咱们介绍到USM之IDS suricata,今天我要与你们分享的是安全管理平台百宝箱中的主机IDS检测系统[HIDS],主机IDS检测系统是对网络IDS检测系统的补充。下面就让咱们一块儿聊一聊Ossec吧。php
OSSEC是一款开源的IDS检测系统,包括了日志分析、完整性检查、rook-kit检测,基于时间的警报和主动响应。OSSEC最大的优点在于它几乎能够运行在任何一种操做系统上,好比Windows, Linux, OpenBSD,FreeBSD, 以及 MacOS。html
环境:
server: centos 6.7 x86_64 172.31.30.100 【具说OpenBSD安全性最好】
agent: fedora 27 x86_64 172.31.30.101
ossec_version: 2.8.3
下载地址
wget https://codeload.github.com/ossec/ossec-hids/tar.gz/v2.8.3
源码最新版:https://codeload.github.com/ossec/ossec-hids/tar.gz/2.9.3node
1.关闭selinux,关闭iptablesmysql
2.解压安装# tar xvzf ossec-hids-2.8.3.tar.gz
# cd ossec-hids-2.8.3
# ./install.sh
linux
3.启动ossec# service ossec start
git
# ps -aux |grep ossec
# tar xvzf ossec-hids-2.8.3.tar.gz
# cd ossec-hids-2.8.3
# ./install.sh
1.服务器端操做# /var/ossec/bin/manage_agents
github
**************************************** * 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 【添加agent】 - Adding a new agent (use '\q' to return to the main menu). Please provide the following: * A name for the new agent: node1 【agent名称】 * The IP Address of the new agent: 172.31.30.101 【agentIP地址】 * An ID for the new agent[001]: Agent information: ID:001 Name:web IP Address:172.31.30.101 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 【建立KEY】 Available agents: ID: 001, Name: web, IP: 172.31.30.101 Provide the ID of the agent to extract the key (or '\q' to quit): 001 【输入agent ID】 这个key用于客户端链接服务器 Agent key information for '001' is: MDA2IG5vZGU1IDE3Mi4yOC4yMC4xMDcgOGIxZDc0MjgyZTFkZjRhZjE0ODU2MzAwMjc4ZTNlNjBhZWJiMmZhOTY3N2UxYjFhMGI2MmRlZmRjOGJkNmIzNQ== ** Press ENTER to return to the main menu. ****************************************
2.客户端操做
1)导入 key# /var/ossec/bin/manage_agents
web
**************************************** * OSSEC HIDS v2.6 Agent manager. * * The following options are available: * **************************************** (I)mport key from the server (I). (Q)uit. Choose your action: I or Q: I 【导入KEY】将服务端KEY复制到下面并按回车MDA2IG5vZGU1IDE3Mi4yOC4yMC4xMDcgOGIxZDc0MjgyZTFkZjRhZjE0ODU2MzAwMjc4ZTNlNjBhZWJiMmZhOTY3N2UxYjFhMGI2MmRlZmRjOGJkNmIzNQ==
2)启动ossec# /var/ossec/bin/ossec-control start
3)查看端口# netstat -antup|grep ossec
sql
配置完成!apache
# bin/ossec-control
> start: 启动各项服务 > stop: 中止各项服务 > restart: 重启各项服务 > status: 查看各项服务状态 > enable: [database|client-syslog|agentless|debug] 启动功能支持 > disable: [database|client-syslog|agentless|debug] 关闭功能支持
# bin/agent_control (仅服务端有)
-l 列举全部可用的agents,服务端会有一个local,表示自身也做为一个agent被监控 -lc 仅列举活跃的agents -i <id> 显示对应id的Agent的信息 -R <id> 重启对应id的Agent -r -a 在全部agents上当即运行完整性和rootkit检查 -r -u <id> 在指定的agent上当即运行完整性和rootkit检查 -b <ip> 阻止指定的ip地址 -f <ar> 配合-b使用,指定运行哪一个响应 -L 列举可用的联动 -s 更改输出到CSV(用,分隔)
# bin/manage_agents
-V 显示ossec版本信息 -l 列举可用的agents,这里不会显示local的信息 -e <id> 获得某个agent的key(服务器用) -r <id> 移除某个agent(服务器用) -i <id> 导入key(客户端用) -f <file> 从文件导入keys(服务器用),文件格式为IP,NAME
安装依赖包# yum -y install wget lrzsz gcc mysql mysql-server mysql-devel httpd php php-mysql postgresql
ossec-wui web界面# wget https://github.com/ossec/ossec-wui/archive/0.9.tar.gz
# tar -xf ossec-wui-0.9.tar.gz
# cd /var/www/html/ossec/ossec-wui
设置web用户名密码# ./setup.sh
Setting up ossec ui... Username: admin New password: Re-type new password: Adding password for user admin Setup completed successfuly.
添加web用户# vi /etc/group
ossec:x:500:apache
设置权限# chmod 770 tmp/
# chgrp apache tmp/
# vi /etc/httpd/conf.d/ossec.conf
<Directory /var/www/html/ossec/ossec-wui> Order deny,allow Deny from all Allow from 172.31.30.0/24 Options FollowSymLinks AllowOverride None Order deny,allow allow from all Options -MultiViews AuthName "OSSEC AUTH" AuthType Basic AuthUserFile /var/www/html/ossec/ossec-wui/.htpasswd Require valid-user </Directory>
OSSEC的图形界面
访问URL: http://172.31.30.100/ossec/ossec-wui/
如何深刻使用OSSEC,就须要对OSSEC的规则进行细分和梳理,配置好相应的事件报警规则,采集到主机报警信息后,咱们就能够进行安全防御和安全分析了。OSSEC除了主机检测系统功能外,通常还被用在SEM/SIM(安全事件管理(SEM: Security Event Management)/安全信息管理(SIM:SecurityInformation Management))解决方案中。从此咱们会把OSSEC应用到USM中,做为统一安全管理平台的核心插件之一。
1)agent未链接(Disconnected或Never connected)的状态# /var/ossec/bin/ossec-control restart
# /etc/init.d/ossec restart
用ngrep命令查看服务端的1514端口的流量信息,看看是否有日志传输过来,通常等10s左右。# ngrep -q -d any port 1514
2)查看ossec是否支持mysql# cd /u01/ossec-hids-2.8.3/src
# make setdb
Info: Compiled with MySQL support.
3)文件描述符限制
linux系统默认最大打开文件数为1024,须要修改内核参数为2048# ulimit -n 2048
# sysctl -w kern.maxfiles=2048
# sysctl -w net.core.rmem_default=5123840
# sysctl -w net.core.rmem_max = 5123840
设置开机自启动,在该文件最后添加# vi /etc/profile
ulimit -n 2048# vi /etc/security/limits.conf
ossec soft nofile 2048
ossec hard nofile 2048
ossecr soft nofile 2048
ossecr hard nofile 2048
设置完成以后,执行命令生效# source /etc/profile
# sysctl -p
查看是否成功设置open files为2048# ulimit -a