天天看點

ossec規則設定,以及正常問題釋疑 Question 7如果還是啟動不來,檢視ossec.logQuestion 7

規則 

    Syscheck是OSSEC内部完整性檢測程序的名稱。它周期性檢查是否有任何配置檔案(或者windows系統資料庫)發生改變。

配置檔案位址為

[root@logserver etc]# pwd 

/var/ossec/etc 

[root@logserver etc]# vim ossec.conf 

它的工作方法是:“代理每幾個小時掃描一次系統,并發送所有的校驗和到server端。Server端存儲這些校驗和檔案并查找他們的不同。如果發現任何改變将會發送報警。

基本概況

多長時間運作一次

預設每6小時運作一次,但是這個頻率可以自己設定

資料存放位置

在server端的/var/ossec/queue/syscheck

CPU使用情況

慢慢地進行掃描,以避免使用過多的CPU /記憶體。

如何處理誤報

檔案能夠通過手工指定配置檔案或使用規則到忽略不記,預設一個檔案修改超過3次會自動忽略。

配置選項

    下面的配置選項可以指定在每一個代理的ossec.conf檔案,除了應用到manager和本地安裝類型的auto_ignore 和 alert_new_file. 如果ignore選項指定在manage,所有代理都會使用相同的設定。

目錄

    使用這個選項增加或者移除被監控的目錄(目錄這間用逗号分開)所有的檔案和子目錄也會被監控。沒有目錄的驅動器字母是無效的。至少“。”應包括(D:\.)。

預設:/etc,/sur/bin,/usr/sbin,/bin,/sbin

Attributes: 屬性

realtime: Value=yes

This will enable realtime/continuous monitoring on Linux (using the inotify system calls) and Windows systems. (啟用實時、連續的監控)

report_changes: Value=yes

Report diffs of file changes. This is limited to text files at this time. (檔案改變比較報告,隻能用文本檔案)

check_all: Value=yes

All the following check_* options are used together. (所有下面的check_*選項共同起作用)

check_sum: Value=yes

Check 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=yes

When used only the sha1 hash of the files will be checked.

check_md5sum: Value=yes

The md5 hash of the files will be checked.

check_size: Value=yes

The size of the files will be checked. (檢查檔案大小)

check_owner: Value=yes

Check the owner of the files selected. (檔案所有者檢查)

check_group: Value=yes

Check the group owner of the files/directories selected. (檔案和目錄所屬的使用者組檢查)

check_perm: Value=yes

Check the UNIX permission of the files/directories selected. On windows this will only check the POSIX permissions. 檔案和目錄權限檢查

restrict: Value=string

A string that will limit checks to files containing that string in the file name. (檔案内容中包含檔案名的字元串将限制檢查。

Allowed: Any directory or file name

ignore

List of files or directories to be ignored (one entry per element).列出的檔案和目錄将不被檢查Default: /etc/mtab

Attributes:

type: Value=sregex

This is a simple regex pattern to filter out files so alerts are not generated. 這個簡單的表達式過慮掉輸出檔案,是以報警不會生成。

frequency

Frequency that the syscheck is going to be executed (in seconds).(syscheck多長時間執行一次,預設是21600秒,也就是6個小時)

The default is 6 hours or 21600 seconds

Default: 21600

Allowed: Time in seconds

scan_time

Time 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 scan

scan_day

Day of the week to run the scans (can be in the format of sunday, saturday, monday, etc)

在每周的那一天執行掃描

Allowed: Day of the week

auto_ignore

Specifies if syscheck will ignore files that change too often (after the third change)指定忽略頻繁改變的檔案

Default: no

Allowed: yes/no

alert_new_files

Specifies if syscheck should alert on new files created.指定新檔案被建立時是否報警

scan_on_start

Specifies if syscheck should do the first scan as soon as it is started.(syscheck啟動後是否立即做第一次掃描。

Default: yes

windows_registry

Use this option to add Windows registry entries to be monitored (Windows-only).增加windows系統資料庫監控

Default: HKEY_LOCAL_MACHINESoftware

Allowed: Any registry entry (one per element)

registry_ignore

List of registry entries to be ignored.(不監控列出的系統資料庫條目)

Default: ..CryptographyRNG

配置例子

配置 syscheck,提供一個要被監控的目錄和檔案清單,check_all 選項會檢查檔案的md5, sha1,owner,和權限。例如:

<syscheck>

   <directories check_all=yes>/etc,/usr/bin,/usr/sbin</directories>

 <directories check_all=yes>/root/users.txt,/bsd,/root/db.html</directories>

</syscheck>

如果不想監控某些檔案和目錄,可以用ignore選項(或者registry_ignore 為windows系統資料庫輸入)

   <ignore>/etc/random-seed</ignore>

 <ignore>/root/dir</ignore>

 <ignore type=sregex>.log$|.tmp</ignore>

??在ignore選項,這個類型屬性可以設定sregex指定一個正規表達式文法。

   <ignore type=sregex>^/opt/application/log</ignore>

一個本地規則可以更嚴格的修改你想要更改的指定檔案和目錄。

     <rule id=100345 level=12>

   <if_matched_group>syscheck</if_matched_group>

 <match>/var/www/htdocs</match>

</rule>

在上邊的例子中,當htdocs directory目錄中的檔案有改變時将會産生一個高嚴重級别的報警。

實時監控

在linux 和windows中OSSEC支援實時監控檔案完整性檢查(linux核心2.6.13以上闆本支援)

配置很簡單,在directories選項那裡你可以指定要監控那些檔案和目錄,增加realtime=”yes”到啟用。

   <directories realtime=yes check_all=yes>/etc,/usr/bin,/usr/sbin</directories>

 <directories check_all=yes>/bin,/sbin</directories>

在這個例子中,目錄/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選項。

 <directories report_changes=yes check_all=yes>/etc</directories>

二、F&Q

Question 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

我們可以這樣設定

<localfile>

   <log_format>syslog</log_format>

   <localtion>/var/log/host*/*.log</location>

   </localfile>

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日志

   <log_format>apache</log_format>

   <localtion>你的apache日志目錄</location>

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  

看日志

[root@logserver logs]# 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: DEBUG: Forking remoted: '1'. 

2012/10/18 16:36:15 ossec-remoted(1206): ERROR: Unable to Bind port '514' 

很明顯是因為514端口被rsyslog 占用,是以需要修改端口.

檢視ossec.conf是不是添加了一下内容

<remote> 

   <connection>secure</connection> 

   <allowed-ips>10.10.10.0/24</allowed-ips> 

   <port>1514</port> 

   <local_ip>10.10.10.137</local_ip> 

 </remote> 

有如下日志

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

agent的消息不能發送到server

1.檢查$OSSEC_HOME/queue/agent-info/下面是否有檔案

2.檢查ossec的伺服器日志cat /$OSSEC_HOME/logg/ossec.log | grep remote

[root@logserver etc]# 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. 

可以看到出了ossec-remoted的程序日志 沒有用戶端的日志,so

繼續往下走.

     本文轉自 珏石頭 51CTO部落格,原文連結:http://blog.51cto.com/gavinshaw/1020544,如需轉載請自行聯系原作者

繼續閱讀