Configure OSSEC vulnerability detection with CVE scanning and automated security alerts

Intermediate 25 min May 01, 2026 57 views
Ubuntu 24.04 Debian 12 AlmaLinux 9 Rocky Linux 9

Set up OSSEC Host Intrusion Detection System with vulnerability scanning capabilities, CVE database integration, and automated alerting for comprehensive security monitoring across your infrastructure.

Prerequisites

  • Root access to the server
  • Internet connectivity for CVE database updates
  • Email server for alert notifications
  • Minimum 2GB RAM and 10GB disk space

What this solves

OSSEC provides real-time vulnerability detection by comparing your system's installed packages against known CVE databases and security advisories. This tutorial shows you how to configure OSSEC with vulnerability scanning, automated CVE matching, and alert notifications to detect security issues before they can be exploited.

Step-by-step configuration

Install OSSEC HIDS

Start by installing OSSEC and its dependencies. We'll install the server version which includes the vulnerability detection module.

sudo apt update
wget -q -O - https://updates.atomicorp.com/installers/atomic | sudo bash
sudo apt install -y ossec-hids-server
sudo dnf update -y
wget -q -O - https://updates.atomicorp.com/installers/atomic | sudo bash
sudo dnf install -y ossec-hids-server

Run initial OSSEC configuration

Configure OSSEC with the setup script. Choose server mode and enable email notifications for vulnerability alerts.

sudo /var/ossec/bin/ossec-control stop
sudo /var/ossec/bin/install.sh

When prompted, select:

  • Installation type: server
  • Enable email notifications: yes
  • SMTP server: your mail server or localhost
  • Email from: ossec@example.com
  • Email to: admin@example.com

Configure vulnerability detection module

Enable and configure the vulnerability detection module in OSSEC's main configuration file.

<ossec_config>
  <global>
    <email_notification>yes</email_notification>
    <email_to>admin@example.com</email_to>
    <smtp_server>localhost</smtp_server>
    <email_from>ossec@example.com</email_from>
  </global>

  <vulnerability-detector>
    <enabled>yes</enabled>
    <interval>5m</interval>
    <min_full_scan_interval>6h</min_full_scan_interval>
    <run_on_start>yes</run_on_start>

    <provider name="canonical">
      <enabled>yes</enabled>
      <os>trusty</os>
      <os>xenial</os>
      <os>bionic</os>
      <os>focal</os>
      <os>jammy</os>
      <os>noble</os>
      <update_interval>1h</update_interval>
    </provider>

    <provider name="debian">
      <enabled>yes</enabled>
      <os>wheezy</os>
      <os>jessie</os>
      <os>stretch</os>
      <os>buster</os>
      <os>bullseye</os>
      <os>bookworm</os>
      <update_interval>1h</update_interval>
    </provider>

    <provider name="redhat">
      <enabled>yes</enabled>
      <os>5</os>
      <os>6</os>
      <os>7</os>
      <os>8</os>
      <os>9</os>
      <update_interval>1h</update_interval>
    </provider>

    <provider name="nvd">
      <enabled>yes</enabled>
      <update_interval>1h</update_interval>
    </provider>
  </vulnerability-detector>

  <wodle name="syscollector">
    <disabled>no</disabled>
    <interval>1h</interval>
    <scan_on_start>yes</scan_on_start>
    <hardware>yes</hardware>
    <os>yes</os>
    <network>yes</network>
    <packages>yes</packages>
    <ports all="no">yes</ports>
    <processes>yes</processes>
  </wodle>
</ossec_config>

Configure vulnerability alert rules

Create custom rules for vulnerability detection alerts with different severity levels.

<?xml version="1.0" encoding="UTF-8"?>
<group name="vulnerability,">
  <rule id="23502" level="7" frequency="1">
    <if_sid>23500</if_sid>
    <field name="vulnerability.severity">High</field>
    <description>High severity vulnerability found: $(vulnerability.cve)</description>
    <group>vulnerability,pci_dss_6.2,gdpr_IV_35.7.d,</group>
  </rule>

  <rule id="23503" level="10" frequency="1">
    <if_sid>23500</if_sid>
    <field name="vulnerability.severity">Critical</field>
    <description>Critical vulnerability found: $(vulnerability.cve)</description>
    <group>vulnerability,pci_dss_6.2,gdpr_IV_35.7.d,</group>
  </rule>

  <rule id="23504" level="5" frequency="1">
    <if_sid>23500</if_sid>
    <field name="vulnerability.severity">Medium</field>
    <description>Medium severity vulnerability found: $(vulnerability.cve)</description>
    <group>vulnerability,pci_dss_6.2,gdpr_IV_35.7.d,</group>
  </rule>

  <rule id="23505" level="12" frequency="1">
    <if_sid>23500</if_sid>
    <field name="vulnerability.cvss">^[9-9]\.|^10\.0</field>
    <description>Very high CVSS score vulnerability: $(vulnerability.cve) (CVSS: $(vulnerability.cvss))</description>
    <group>vulnerability,pci_dss_6.2,gdpr_IV_35.7.d,</group>
  </rule>
</group>

Set up automated CVE database updates

Configure automatic updates for CVE databases to ensure you're always checking against the latest vulnerability information.

  <wodle name="vulnerability-detector">
    <disabled>no</disabled>
    <interval>5m</interval>
    <run_on_start>yes</run_on_start>
    <update_interval>60m</update_interval>
    <provider name="nvd">
      <enabled>yes</enabled>
      <update_from_year>2016</update_from_year>
      <update_interval>1h</update_interval>
    </provider>
  </wodle>

Configure email alerting for vulnerabilities

Set up email notifications that trigger immediately when vulnerabilities are detected.

  <email_alerts>
    <email_to>security-team@example.com</email_to>
    <level>7</level>
    <rule_id>23502,23503,23504,23505</rule_id>
    <do_not_delay>yes</do_not_delay>
    <do_not_group>yes</do_not_group>
  </email_alerts>

  <email_alerts>
    <email_to>critical-alerts@example.com</email_to>
    <level>10</level>
    <rule_id>23503,23505</rule_id>
    <do_not_delay>yes</do_not_delay>
    <do_not_group>yes</do_not_group>
  </email_alerts>

Enable active response for critical vulnerabilities

Configure automatic responses to isolate systems when critical vulnerabilities are detected.

  <command>
    <name>vulnerability-quarantine</name>
    <executable>vulnerability-response.sh</executable>
    <expect>srcip</expect>
    <timeout_allowed>yes</timeout_allowed>
  </command>

  <active-response>
    <disabled>no</disabled>
    <command>vulnerability-quarantine</command>
    <location>local</location>
    <rules_id>23503,23505</rules_id>
    <timeout>3600</timeout>
  </active-response>

Create vulnerability response script

Create a script that handles critical vulnerability responses by logging details and optionally isolating affected systems.

#!/bin/bash

OSSEC Vulnerability Response Script

LOGFILE="/var/ossec/logs/active-responses.log" ACTION=$1 USER=$2 IP=$3 ALERT_ID=$4 RULE_ID=$5 echo "$(date '+%Y-%m-%d %H:%M:%S') - Vulnerability Response: Action=$ACTION, User=$USER, IP=$IP, Alert=$ALERT_ID, Rule=$RULE_ID" >> $LOGFILE case "$ACTION" in add) echo "$(date '+%Y-%m-%d %H:%M:%S') - CRITICAL VULNERABILITY DETECTED on $IP" >> $LOGFILE # Log to syslog for external monitoring logger -p local0.crit "OSSEC: Critical vulnerability detected on $IP - Alert ID: $ALERT_ID" # Optional: Send SNMP trap # snmptrap -v2c -c public monitoring-server '' 1.3.6.1.4.1.12345.1 1.3.6.1.4.1.12345.1.1 s "Critical vulnerability: $IP" ;; delete) echo "$(date '+%Y-%m-%d %H:%M:%S') - Vulnerability response timeout for $IP" >> $LOGFILE ;; esac exit 0
sudo chmod 750 /var/ossec/active-response/bin/vulnerability-response.sh
sudo chown root:ossec /var/ossec/active-response/bin/vulnerability-response.sh

Configure vulnerability scan scheduling

Set up regular vulnerability scans and configure scan exclusions for development systems.

  <vulnerability-detector>
    <enabled>yes</enabled>
    <interval>5m</interval>
    <min_full_scan_interval>6h</min_full_scan_interval>
    <run_on_start>yes</run_on_start>
    
    <ignore_time>6h</ignore_time>
    <max_queue_size>16384</max_queue_size>
    
    <feed name="ubuntu-18">
      <disabled>no</disabled>
      <update_interval>60m</update_interval>
    </feed>
    
    <feed name="redhat-9">
      <disabled>no</disabled>
      <update_interval>60m</update_interval>
    </feed>
  </vulnerability-detector>

Start OSSEC and enable services

Start the OSSEC service and enable it to run automatically on system boot.

sudo /var/ossec/bin/ossec-control start
sudo systemctl enable ossec

Verify the vulnerability detector is running:

sudo /var/ossec/bin/ossec-control status
tail -f /var/ossec/logs/ossec.log | grep vulnerability

Verify your setup

Check that OSSEC is properly detecting vulnerabilities and the CVE database is updating:

# Check OSSEC status
sudo /var/ossec/bin/ossec-control status

Verify vulnerability detector is active

grep "vulnerability-detector" /var/ossec/logs/ossec.log

Check CVE database updates

ls -la /var/ossec/wodles/vulnerability-detector/

Test vulnerability detection manually

sudo /var/ossec/bin/ossec-logtest

Check recent vulnerability alerts

tail -20 /var/ossec/logs/alerts/alerts.log | grep vulnerability

Verify email configuration

sudo /var/ossec/bin/ossec-maild -t
Note: The initial CVE database download can take 15-30 minutes. Monitor /var/ossec/logs/ossec.log for download progress.

Configure advanced vulnerability filtering

Create severity-based filtering

Configure OSSEC to only alert on specific CVSS scores or vulnerability types to reduce noise.

  <vulnerability-detector>
    <enabled>yes</enabled>
    
    <filters>
      <cvss_score>7.0</cvss_score>
      <severity>High,Critical</severity>
      <ignore_package>test-package,dev-tools</ignore_package>
    </filters>
    
    <alerts>
      <format>json</format>
      <severity_levels>medium,high,critical</severity_levels>
    </alerts>
  </vulnerability-detector>

Set up JSON output for external tools

Configure OSSEC to output vulnerability data in JSON format for integration with SIEM systems or monitoring tools.

  <global>
    <jsonout_output>yes</jsonout_output>
    <alerts_log>yes</alerts_log>
    <logall>no</logall>
    <logall_json>no</logall_json>
  </global>
  
  <remote>
    <connection>syslog</connection>
    <port>514</port>
    <protocol>udp</protocol>
    <allowed-ips>203.0.113.10</allowed-ips>
  </remote>

Common issues

SymptomCauseFix
Vulnerability detector not startingMissing CVE database or network issuesCheck /var/ossec/logs/ossec.log and verify internet connectivity
No vulnerability alerts generatedNo vulnerable packages found or filtering too restrictiveLower CVSS threshold or check /var/ossec/logs/vulnerability-detector.log
CVE database download failsFirewall blocking HTTPS or insufficient disk spaceAllow HTTPS outbound and check df -h /var/ossec
Email alerts not sendingSMTP configuration incorrectTest with sudo /var/ossec/bin/ossec-maild -t
High false positive rateDefault rules too sensitiveAdjust severity levels in vulnerability detector config
Performance issues during scansScan interval too frequentIncrease min_full_scan_interval to 12h or 24h

Integration with monitoring systems

OSSEC vulnerability data can be integrated with external systems for centralized monitoring. You can configure OSSEC integration with Splunk or set up OSSEC with fail2ban integration for comprehensive threat response.

For production environments, consider implementing OSSEC active response to automatically respond to critical vulnerabilities.

Next steps

Running this in production?

Want this handled for you? Setting this up once is straightforward. Keeping it patched, monitored, backed up and performant across environments is the harder part. See how we run infrastructure like this for European teams.

Automated install script

Run this to automate the entire setup

Need help?

Don't want to manage this yourself?

We handle infrastructure security hardening for businesses that depend on uptime. From initial setup to ongoing operations.