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處理,比如:
- 磁盤使用(
df -h
),磁盤滿時會報警; - 系統負載(
uptime
),值超過2時會報警; - 命令輸出發生變化時,比如監控
netstat -tan |grep LISTEN
,若有新端口開啓監聽模式時就會報警; - 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顯示有一定延時):