【合肥清默】ossec规则设置,以及常规问题释疑
规则 Syscheck是OSSEC内部完整性检测进程的名称。它周期性检查是否有任何配置文件(或者windows注册表)发生改变。配置文件地址为# pwd /var/ossec/etc # vim ossec.conf 它的工作方法是:“代理每几个小时扫描一次系统,并发送所有的校验和到server端。Server端存储这些校验和文件并查找他们的不同。如果发现任何改变将会发送报警。基本概况多长时间运行一次默认每6小时运行一次,但是这个频率可以自己设定数据存放位置在server端的/var/ossec/queue/syscheckCPU使用情况慢慢地进行扫描,以避免使用过多的CPU /内存。如何处理误报文件能够通过手工指定配置文件或使用规则到忽略不记,默认一个文件修改超过3次会自动忽略。配置选项 下面的配置选项可以指定在每一个代理的ossec.conf文件,除了应用到manager和本地安装类型的auto_ignore 和 alert_new_file. 如果ignore选项指定在manage,所有代理都会使用相同的设置。目录 使用这个选项增加或者移除被监控的目录(目录这间用逗号分开)所有的文件和子目录也会被监控。没有目录的驱动器字母是无效的。至少“。”应包括(D:\.)。默认:/etc,/sur/bin,/usr/sbin,/bin,/sbinAttributes: 属性realtime: Value=yesThis will enable realtime/continuous monitoring on Linux (using the inotify system calls) and Windows systems. (启用实时、连续的监控)report_changes: Value=yesReport diffs of file changes. This is limited to text files at this time. (文件改变比较报告,只能用文本文件)check_all: Value=yesAll the following check_* options are used together. (所有下面的check_*选项共同起作用)check_sum: Value=yesCheck the md5 and sha1 hashes of the of the files will be checked.This is the same as using both check_sha1sum=”yes” and check_md5sum=”yes”check_sha1sum: Value=yesWhen used only the sha1 hash of the files will be checked.check_md5sum: Value=yesThe md5 hash of the files will be checked.check_size: Value=yesThe size of the files will be checked. (检查文件大小)check_owner: Value=yesCheck the owner of the files selected. (文件所有者检查)check_group: Value=yesCheck the group owner of the files/directories selected. (文件和目录所属的用户组检查)check_perm: Value=yesCheck the UNIX permission of the files/directories selected. On windows this will only check the POSIX permissions. 文件和目录权限检查restrict: Value=stringA string that will limit checks to files containing that string in the file name. (文件内容中包含文件名的字符串将限制检查。Allowed: Any directory or file nameignoreList of files or directories to be ignored (one entry per element).列出的文件和目录将不被检查Default: /etc/mtabAttributes:type: Value=sregexThis is a simple regex pattern to filter out files so alerts are not generated. 这个简单的表达式过虑掉输出文件,所以报警不会生成。Allowed: Any directory or file namefrequencyFrequency that the syscheck is going to be executed (in seconds).(syscheck多长时间执行一次,默认是21600秒,也就是6个小时)The default is 6 hours or 21600 secondsDefault: 21600Allowed: Time in secondsscan_timeTime to run the scans (can be in the formats of 21pm, 8:30, 12am, etc) 扫描系统的时间格式(21pm晚上9点),8:30,(12am上午12点)。Allowed: Time to run scanscan_dayDay of the week to run the scans (can be in the format of sunday, saturday, monday, etc)在每周的那一天执行扫描Allowed: Day of the weekauto_ignoreSpecifies if syscheck will ignore files that change too often (after the third change)指定忽略频繁改变的文件Default: noAllowed: yes/noalert_new_filesSpecifies if syscheck should alert on new files created.指定新文件被创建时是否报警Default: noAllowed: yes/noscan_on_startSpecifies if syscheck should do the first scan as soon as it is started.(syscheck启动后是否立即做第一次扫描。Default: yesAllowed: yes/nowindows_registryUse this option to add Windows registry entries to be monitored (Windows-only).增加windows注册表监控Default: HKEY_LOCAL_MACHINESoftwareAllowed: Any registry entry (one per element)registry_ignoreList of registry entries to be ignored.(不监控列出的注册表条目)Default: ..CryptographyRNGAllowed: Any registry entry (one per element)配置例子配置 syscheck,提供一个要被监控的目录和文件列表,check_all 选项会检查文件的md5, sha1,owner,和权限。例如: /etc,/usr/bin,/usr/sbin /root/users.txt,/bsd,/root/db.html 如果不想监控某些文件和目录,可以用ignore选项(或者registry_ignore 为windows注册表输入) /etc/random-seed /root/dir .log$|.tmp ??在ignore选项,这个类型属性可以设置sregex指定一个正则表达式语法。 ^/opt/application/log 一个本地规则可以更严格的修改你想要更改的指定文件和目录。 syscheck /var/www/htdocs 在上边的例子中,当htdocs directory目录中的文件有改变时将会产生一个高严重级别的报警。实时监控在linux 和windows中OSSEC支持实时监控文件完整性检查(linux内核2.6.13以上板本支持)配置很简单,在directories选项那里你可以指定要监控那些文件和目录,增加realtime=”yes”到启用。 /etc,/usr/bin,/usr/sbin /bin,/sbin 在这个例子中,目录/etc, /usr/bin and /usr/sbin会被实时监控,同样的方法也实用与windows.提示:实时监控并不会立即开始。首先ossec-syscheckd需要扫描文件系统并添加每一个了目录到实时队列。要完成这些工作需要30分钟时间。(等待log文件出现如下信息:“ossec-syscheckd: INFO: Starting real time file monitoring”)注解:实时监控仅对目录有效,所以你可以监控 /etc 或者c:\program files 目录,但不能是个别的文件,像/etc/file.txt。比较不同并生成报告 在linux 和unix系统比较所后的改变生成一个文本文件,OSSEC支持发送比较报告,配置syscheck显示文件比较的不同很简单,添加report_changes=”yse”到directories选项。 /etc /bin,/sbin 二、F&QQuestion 1.当按照上一篇安装之后web端后访问出现:Unable to retrieve alerts.请查看/var/ossec/logs/alerts/alerts.log 权限是否有web服务器能访问的权限Question 2我smtp server设置正确,但为何我收不到ossec主机所发的邮件,在邮件日志中老显示连接超时。A: ossec原则上不要求在本地架设mta服务器,但我们知道,为了防止垃圾,基本上所有邮件服务器都关闭了open relay,然我们的ossec并没有为smtp认证提供username与password设置选项,这就使我们在选择其它smtp 服务器时无法指定用户名与密码,因此我的做法是设置ossec发信给root@localhost,然后在本地邮件服务器别名列表中,将所有转发给 root的信件再转发给我所希望的email地址。Question 3如何设置ossec同时去监检多个日志文件A:有时,我们同时有多个日志文件希望被监测,但又不想一个个输入ossec.conf配置文中。其实我可以利用ossec的posix规则表达示来达到你的目的。如假如你有如下几个日志文件:/var/log/host1/xx.log,yy.log,zz.log/var/log/host2/xx.log,aa.log/var/log/host3/zz.log,abc.log/var/log/hostn/bb.log,xyz.log我们可以这样设置 syslog /var/log/host*/*.log Question 4我采用的是S/C安装方式,并且巳按正确方法在服务器上注册的客户机,但ossec服务器与客户无法还是无法通信A:针对这个问题,a.首先我们要确定安装顺序是否正确,一般我们是先安装server,然后是agent,并且在服务器给agent生成密匙,再在agent上导入密匙,注意在server上生成密匙时agent的ip地址千万不能写错,否则无法通信。 b.使用netstat -ntlup查看本机是否开启了514,1514端口接受agent连接,如果端口还没有打开,先/etc/init.d/syslog restart再查看。请随时查阅/var/ossec/logs/ossec.conf日志文件中的是志。 c.如果你启了防火墙,请一定要将514,1514的数据放行,否则agent无法与server正常通信。以上是我们个人使用ossec来一点实际经验,欢迎大家继续加精Question 5如何检测apache日志我们可以这样设置 apache 你的apache日志目录 Question 6 代理和服务器见的连接不畅通,怎么办日志出现2012/10/16 16:40:56 ossec-agentd(1218): ERROR: Unable to send message to server. 2012/10/16 16:41:08 ossec-agentd(1218): ERROR: Unable to send message to server. 请查看agent 和server是否有防火墙,以及是否方形了1514 和514端口以及查看服务器端是否开启了1514端口Question 6 启动了ossec 没有监听1514 查看ossec-remoted是否启动,查看日志能否看到ossec-remoted相关信息.可能需要开启debug模式
./ossec-control enable debug [*]./ossec-control restart
看日志
# tail -f ossec.log |grep remo 2012/10/18 16:36:15 ossec-remoted: DEBUG: Starting ... 2012/10/18 16:36:15 ossec-remoted: INFO: Started (pid: 9246). 2012/10/18 16:36:15 ossec-remoted: DEBUG: Forking remoted: '0'. 2012/10/18 16:36:15 ossec-remoted: Remote syslog allowed from: '10.10.10.0/24' 2012/10/18 16:36:15 ossec-remoted: Remote syslog allowed from: '10.10.10.0/24' 2012/10/18 16:36:15 ossec-remoted: DEBUG: Forking remoted: '1'. [*]2012/10/18 16:36:15 ossec-remoted(1206): ERROR: Unable to Bind port '514'
很明显是因为514端口被rsyslog 占用,所以需要修改端口. 查看ossec.conf是不是添加了一下内容
<</span>remote> <</span>connection>secure</</span>connection> <</span>allowed-ips>10.10.10.0/24</</span>allowed-ips> <</span>port>1514</</span>port> <</span>local_ip>10.10.10.137</</span>local_ip> [*] </</span>remote>
Question 7如果还是启动不来,查看ossec.log有如下日志
2012/10/17 13:51:11 ossec-remoted: INFO: Started (pid: 4477). 2012/10/17 13:51:11 ossec-remoted: Remote syslog allowed from: '10.10.10.0/24' [*]2012/10/17 13:51:11 ossec-remoted(1206): ERROR: Unable to Bind port '514'
因为514被rsyslog占用,先停掉rsyslog再启动ossec-control restart Question 7agent的消息不能发送到server1.检查$OSSEC_HOME/queue/agent-info/下面是否有文件2.检查ossec的服务器日志cat /$OSSEC_HOME/logg/ossec.log | grep remote
# cat /var/ossec/logs/ossec.log |grep remote 2012/10/17 14:46:21 ossec-remoted: INFO: Started (pid: 7850). 2012/10/17 14:46:21 ossec-remoted(1501): ERROR: No IP or network allowed in the access list for syslog. No reason for running it. Exiting. 2012/10/17 14:46:21 ossec-remoted: INFO: Started (pid: 7853). 2012/10/17 14:46:22 ossec-remoted(4111): INFO: Maximum number of agents allowed: '256'. 2012/10/17 14:46:22 ossec-remoted(1410): INFO: Reading authentication keys \ [*]file.
页:
[1]