Home Server OSSEC


27-Mar-2012: initial release.
18-Jan-2013: adjusted for Slackware
19-Apr-2015: adjusted for LXC.



OSSEC is an Open Source Host-based Intrusion Detection System. It performs log analysis, file integrity checking, policy monitoring, rootkit detection, real-time alerting and active response. On our home server project a server package will be installed on the host, and client packages on the virtual servers. When an intrusion attempt is detected by the server, commands are sent to the virtual gateway to close the firewall for the offending IP address for a certain time. Because we are monitoring all our servers, it doesn’t matter which of our servers is being attacked, all information is processed and analyzed on our main server.

The official web site has all the documentation, you should really take a look at it to see how it works and how to adjust it to your own situation.



There are three different packages available from this site:

  • ossec-local
  • ossec-server
  • ossec-agent

The ossec-local package is for standalone systems, that is the one we will use. The other packages were build for networked systems that I don’t use anymore, in the future these will not be build again. We can do with just one instance of ossec because it can see all the file systems and so it can read every logfile you have.



All the configuration files are located under /var/ossec/etc. To parse all kinds of log files and messages, ossec uses rules files. These rules files are located under /var/ossec/rules. The only rule file that is not touched during a package upgrade is /var/ossec/rules/local_rules.xml so you should only make changes in that file.

The configuration file is /var/ossec/etc/ossec.conf, the diff should be something like this:

--- ossec.conf.new 2015-04-13 20:05:47.000000000 +0200
+++ ossec.conf 2015-04-13 22:07:08.215722966 +0200
@@ -1,6 +1,9 @@
- <email_notification>no</email_notification>
+ <email_notification>yes</email_notification>
+ <email_to>admin@wpl.uk</email_to>
+ <smtp_server>mail.wpl.ym</smtp_server>
+ <email_from>ossec@wpl.uk</email_from>

@@ -72,37 +75,32 @@
 <!-- Directories to check (perform all possible verifications) -->
- <directories check_all="yes">/etc,/usr/bin,/usr/sbin</directories>
- <directories check_all="yes">/bin,/sbin</directories>
+ <directories check_all="yes">/etc</directories>

 <!-- Files/directories to ignore -->
+ <ignore>/etc/ntp/ntp.drift</ignore>
+ <ignore>/etc/cups/subscriptions.conf</ignore>
+ <ignore>/etc/cups/subscriptions.conf.0</ignore>
+ <ignore>/etc/cups/printers.conf</ignore>
+ <ignore>/etc/cups/printers.conf.0</ignore>
+ <ignore>/etc/cups/classes.conf</ignore>
+ <ignore>/etc/cups/classes.conf.0</ignore>
+ <ignore>/etc/printcap</ignore>
+ <ignore>/etc/amanda/example</ignore>
+ <ignore>/etc/amanda/mbse/changer</ignore>
- <!-- Windows files to ignore -->
- <ignore>C:\WINDOWS/System32/LogFiles</ignore>
- <ignore>C:\WINDOWS/Debug</ignore>
- <ignore>C:\WINDOWS/WindowsUpdate.log</ignore>
- <ignore>C:\WINDOWS/iis6.log</ignore>
- <ignore>C:\WINDOWS/system32/wbem/Logs</ignore>
- <ignore>C:\WINDOWS/system32/wbem/Repository</ignore>
- <ignore>C:\WINDOWS/Prefetch</ignore>
- <ignore>C:\WINDOWS/PCHEALTH/HELPCTR/DataColl</ignore>
- <ignore>C:\WINDOWS/SoftwareDistribution</ignore>
- <ignore>C:\WINDOWS/Temp</ignore>
- <ignore>C:\WINDOWS/system32/config</ignore>
- <ignore>C:\WINDOWS/system32/spool</ignore>
- <ignore>C:\WINDOWS/system32/CatRoot</ignore>
+ <ignore>/etc/amanda/example</ignore>

@@ -117,16 +115,17 @@
- <white_list></white_list>
+ <white_list></white_list>
+ <white_list></white_list>
+ <white_list></white_list>
+ <white_list></white_list>
- <remote>
- <connection>syslog</connection>
- </remote>
- <remote>
+ <!-- <remote>
- </remote>
+ <allowed-ips></allowed-ips>
+ <local_ip></local_ip>
+ </remote> -->
@@ -147,6 +146,13 @@
+ <name>ipset-drop</name>
+ <executable>ipset.sh</executable>
+ <expect>srcip</expect>
+ <timeout_allowed>yes</timeout_allowed>
+ </command>
+ <command>
@@ -167,75 +173,54 @@
- <!-- Active Response Config -->
- <active-response>
- <!-- This response is going to execute the host-deny
- - command for every event that fires a rule with
- - level (severity) >= 6.
- - The IP is going to be blocked for 600 seconds.
- -->
- <command>host-deny</command>
- <location>local</location>
- <level>6</level>
- <timeout>600</timeout>
- </active-response>
+ <disabled>no</disabled>
 <!-- Firewall Drop response. Block the IP for
- - 600 seconds on the firewall (iptables,
+ - 1800 seconds on the firewall (iptables,
 - ipfilter, etc).
- <command>firewall-drop</command>
+ <command>ipset-drop</command>
- <timeout>600</timeout> 
+ <timeout>1800</timeout> 
 <!-- Files to monitor (localfiles) -->
- <location>/var/log/messages</location>
- </localfile>
 <!-- Files to monitor (localfiles) -->
- <location>/var/log/messages</location>
- </localfile>
- <localfile>
- <log_format>syslog</log_format>
- <location>/var/log/syslog</location>
+ <location>/var/lib/lxc/*/rootfs/var/log/secure</location>
- <location>/var/adm/syslog</location>
+ <location>/var/log/messages</location>
- <location>/var/adm/messages</location>
+ <location>/var/lib/lxc/*/rootfs/var/log/messages</location>
- <log_format>command</log_format>
- <command>df -h</command>
+ <log_format>syslog</log_format>
+ <location>/var/lib/lxc/*/rootfs/var/log/maillog</location>
- <log_format>full_command</log_format>
- <command>netstat -tan |grep LISTEN |grep -v | sort</command>
+ <log_format>mysql_log</log_format>
+ <location>/var/lib/mysql/homsrv.err</location>
- <log_format>full_command</log_format>
- <command>last -n 5</command>
+ <log_format>apache</log_format>
+ <location>/var/lib/lxc/11-nginx/rootfs/var/log/nginx/*access.log</location>


The most changes you need are logfile names and locations. To change an existing rule, copy that rule to local_rules.xml and add a overwrite=”yes” statement and make the desired change to the rule. Use for example the following /var/ossec/rules/local_rules.xml:

<!-- /var/ossec/rules/local_rules.xml at homsrv -->
<!-- Modify it at your will. -->

<group name="local,syslog,">

  <!-- Frequency was 6, but only allow 2 bad names
    -  Timeframe from 120 to 600 for slow scanners
  <rule id="5712" level="10" frequency="2" timeframe="600" ignore="60" overwrite="yes">
    <description>SSHD brute force trying to get access to </description>
    <description>the system.</description>
    <same_source_ip />

  <!-- Frequency was 6, but only allow 2 bad passwords
  <rule id="5720" level="10" frequency="2" overwrite="yes">
    <same_source_ip />
    <description>Multiple SSHD authentication failures.</description>

  <rule id="100201" level="0">
    <description>Ignored transmission-daemon event.</description>

  <rule id="100202" level="0">
    <description>Ignored nagios event.</description>

  <rule id="100301" level="2">
    <description>SMART event, please finish this rule.</description>

  <rule id="100401" level="2">
    <description>AICCU event, please finish this rule.</description>

  <rule id="100402" level="0">
    <description>Ignore error in a word.</description>

  <rule id="100501" level="0">
    <regex>open failed: administratively prohibited</regex>
    <description>Ignore sshd error.</description>

  <rule id="100601" level="0">
    <regex>Failed to activate service 'org.freedesktop.Avahi': timed out</regex>
    <description>Ignore dbus error starting inactive avahi.</description>

  <!-- Override existing rules -->
  <rule id="31102" level="0" overwrite="yes">
    <description>Ignored extensions on 400 error codes.</description>

  <rule id="31151" level="10" frequency="5" timeframe="120" overwrite="yes">
    <same_source_ip />
    <description>Mutiple web server 400 error codes </description>
    <description>from same source ip.</description>

  <rule id="31153" level="10" frequency="4" timeframe="120" overwrite="yes">
    <same_source_ip />
    <description>Multiple common web attacks from same souce ip.</description>

</group> <!-- SYSLOG,LOCAL -->

<group name="syslog,postfix,">

  <rule id="3357" level="10" frequency="3" timeframe="120" overwrite="yes">
    <same_source_ip />
    <description>Multiple SASL authentication failures.</description>

</group> <!-- SYSLOG,POSTFIX -->

<!-- EOF -->


After this start ossec and check it:

root@homsrv:~# /etc/rc.d/init.d/ossec start
Starting OSSEC-HIDS 
root@homsrv:~# /etc/rc.d/init.d/ossec status
ossec-monitord is running...
ossec-logcollector is running...
ossec-remoted is running...
ossec-syscheckd is running...
ossec-analysisd is running...
ossec-maild is running...
ossec-execd is running...



When an intruders or other bad system is detected, ossec runs the script  /var/ossec/active-response/bin/ipset.sh. This script is not part of the package but it is written to block systems in the firewall at the gateway server. It does this by adding and removing the offending systems in the ipset table global-blk4 or global-blk6. You will find this script in the download package.



See the download page for the script and configuration files.