OSSEC文件监控和命令监控(附文件监控测试用例)

OSSEC的log文件监控(LIDS,log-based intrusion detection),能检测攻击、误用、系统错误等。

agent端不产生alerts,全部由server集中分析处理。

具体参考官方文档:Log monitoring/analysis

文件监控

ossec-logcollector进程负责监控log文件和事件,有新的日志消息时就转发到server。

配置文件为ossec.conf,通过配置<localfile>标签指定监控的log文件。具体参考:localfile syntax page

agent默认localfile设置如下:

  <!-- Files to monitor (localfiles) -->

  <localfile>
    <log_format>syslog</log_format>
    <location>/var/log/auth.log</location>
  </localfile>

  <localfile>
    <log_format>syslog</log_format>
    <location>/var/log/syslog</location>
  </localfile>

  <localfile>
    <log_format>syslog</log_format>
    <location>/var/log/dpkg.log</location>
  </localfile>

  <localfile>
    <log_format>command</log_format>
    <command>df -P</command>
  </localfile>

  <localfile>
    <log_format>full_command</log_format>
    <command>netstat -tan |grep LISTEN |egrep -v '(127.0.0.1| ::1)' | sort</command>
  </localfile>

  <localfile>
    <log_format>full_command</log_format>
    <command>last -n 5</command>
  </localfile>

<log_format>标签用来设置格式,默认是syslog(只要格式是每行一条的纯文本,都可以用syslog)。另外还有snort-full、snort-fast、squid、iis、mysql_log、nmapg、apache、command等类型。

命令监控

<log_format>是command时,表示命令监控。

OSSEC善于处理log,但有些信息在log中没有,于是额外增加了监控命令输出的功能,将其也视为log处理,比如:

  1. 磁盘使用(df -h),磁盘满时会报警;
  2. 系统负载(uptime),值超过2时会报警;
  3. 命令输出发生变化时,比如监控netstat -tan |grep LISTEN,若有新端口开启监听模式时就会报警;
  4. USB设备,接入新USB设备时会报警;

具体参考:Process Monitoring

自定义文件监控测试

在Agent端新建文件:

sudo vim /var/test.log

打开ossec.conf文件:

sudo vim /var/ossec/etc/ossec.conf

<ossec_config>标签内添加:

<localfile>
    <location>/var/test.log</location>
    <log_format>syslog</log_format>
</localfile>

保存退出。

重启agent:

sudo /var/ossec/bin/ossec-control restart

agent的日志中应该会有:

ossec-logcollector(1950): INFO: Analyzing file: '/var/test.log'.

这时任意修改test.log,在server端的Web UI上即可看到alert(web显示有一定延时):
server成功捕获alert

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章