OSSEC ist ein Open-Source Host-based Intrusion Detection System. Es analysiert Logs, überwacht Dateiintegrität und kann auf Bedrohungen automatisch reagieren.

Was ist OSSEC?

Funktionen

- Log-Analyse und Korrelation
- Dateiintegritätsprüfung (FIM)
- Rootkit-Erkennung
- Aktive Reaktion (Active Response)
- Zentrales Management
- Agent-basierte Überwachung
- Compliance-Monitoring

Architektur

| Komponente | Beschreibung | |------------|--------------| | Server | Zentraler Manager | | Agent | Auf überwachten Systemen | | Agentless | Ohne Installation | | Local | Standalone-Modus |

Installation

Server (Manager)

# Debian/Ubuntu
apt install build-essential gcc make libssl-dev

# Download
wget https://github.com/ossec/ossec-hids/archive/3.7.0.tar.gz
tar xzf 3.7.0.tar.gz
cd ossec-hids-3.7.0

# Installation
./install.sh

Installationstyp wählen

(en/br/cn/de/el/es/fr/hu/it/jp/nl/pl/ru/sr/tr) [en]: de
1- Was für eine Installation möchten Sie (server, agent, local, hybrid or help)? server

- Server installation chosen.

Wichtige Fragen

- E-Mail-Benachrichtigungen aktivieren? (y/n) [y]: y
- E-Mail-Adresse: admin@example.de
- SMTP-Server: localhost
- Integritätsprüfung aktivieren? (y/n) [y]: y
- Rootkit-Erkennung aktivieren? (y/n) [y]: y
- Active Response aktivieren? (y/n) [y]: y
- Firewall-Drop Response aktivieren? (y/n) [y]: y

Agent installieren

# Auf dem zu überwachenden Server
./install.sh
# Installation type: agent
# Server IP: 192.168.1.100

Konfiguration

Hauptkonfiguration

<!-- /var/ossec/etc/ossec.conf -->

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

  <alerts>
    <log_alert_level>1</log_alert_level>
    <email_alert_level>7</email_alert_level>
  </alerts>

  <syscheck>
    <frequency>7200</frequency>
    <directories check_all="yes">/etc,/usr/bin,/usr/sbin</directories>
    <directories check_all="yes">/bin,/sbin</directories>
    <ignore>/etc/mtab</ignore>
    <ignore>/etc/hosts.deny</ignore>
    <ignore>/etc/mail/statistics</ignore>
    <ignore>/etc/random-seed</ignore>
    <ignore>/etc/adjtime</ignore>
    <ignore>/etc/prelink.cache</ignore>
  </syscheck>

  <rootcheck>
    <frequency>36000</frequency>
    <rootkit_files>/var/ossec/etc/shared/rootkit_files.txt</rootkit_files>
    <rootkit_trojans>/var/ossec/etc/shared/rootkit_trojans.txt</rootkit_trojans>
  </rootcheck>

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

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

  <localfile>
    <log_format>apache</log_format>
    <location>/var/log/nginx/access.log</location>
  </localfile>

  <localfile>
    <log_format>apache</log_format>
    <location>/var/log/nginx/error.log</location>
  </localfile>
</ossec_config>

Agent-Verwaltung

# Agent hinzufügen
/var/ossec/bin/manage_agents

****************************************
* OSSEC HIDS v3.7.0 Agent manager.     *
****************************************

(A)dd an agent (A).
(E)xtract key for an agent (E).
(L)ist already added agents (L).
(R)emove an agent (R).
(Q)uit.

Choose your action: A,E,L,R or Q: A

Agent-Key exportieren

# Auf Server
/var/ossec/bin/manage_agents
# Option E, Agent-ID eingeben
# Key kopieren

# Auf Agent
/var/ossec/bin/manage_agents
# Option I, Key einfügen

Dienste starten

Server

/var/ossec/bin/ossec-control start

Agent

/var/ossec/bin/ossec-control start

Status prüfen

/var/ossec/bin/ossec-control status

Dateiintegritätsprüfung

Konfiguration

<syscheck>
  <!-- Prüfintervall in Sekunden -->
  <frequency>7200</frequency>

  <!-- Echtzeit-Überwachung -->
  <directories realtime="yes" check_all="yes">/etc</directories>
  <directories realtime="yes" check_all="yes">/var/www</directories>

  <!-- Report Changes -->
  <directories report_changes="yes" check_all="yes">/etc</directories>

  <!-- Ausschlüsse -->
  <ignore>/etc/mtab</ignore>
  <ignore>/etc/hosts.deny</ignore>
  <ignore type="sregex">.log$</ignore>
</syscheck>

Prüfoptionen

| Option | Beschreibung | |--------|--------------| | check_all | Alle Attribute prüfen | | check_sum | MD5/SHA1 Checksummen | | check_size | Dateigröße | | check_owner | Besitzer | | check_group | Gruppe | | check_perm | Berechtigungen | | realtime | Echtzeit-Überwachung | | report_changes | Änderungen protokollieren |

Baseline aktualisieren

/var/ossec/bin/syscheck_update -u local

Log-Analyse

Logs hinzufügen

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

<localfile>
  <log_format>apache</log_format>
  <location>/var/log/apache2/access.log</location>
</localfile>

<localfile>
  <log_format>mysql_log</log_format>
  <location>/var/log/mysql/error.log</location>
</localfile>

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

Log-Formate

| Format | Beschreibung | |--------|--------------| | syslog | Standard Syslog | | apache | Apache/Nginx Access | | mysql_log | MySQL Logs | | postgresql_log | PostgreSQL | | command | Befehlsausgabe | | full_command | Vollständige Ausgabe | | json | JSON-Format |

Regeln

Regel-Struktur

<!-- /var/ossec/rules/local_rules.xml -->

<group name="local,syslog,">

  <!-- Eigene Regel -->
  <rule id="100001" level="10">
    <if_sid>5716</if_sid>
    <srcip>!192.168.1.0/24</srcip>
    <description>SSH login from external network</description>
  </rule>

  <!-- Schwellwert-Regel -->
  <rule id="100002" level="10" frequency="5" timeframe="60">
    <if_matched_sid>5716</if_matched_sid>
    <same_source_ip/>
    <description>Multiple SSH logins from same IP</description>
  </rule>

</group>

Regel-Level

| Level | Beschreibung | |-------|--------------| | 0 | Ignoriert | | 1 | Keine Aktion | | 2 | System Low Priority | | 3 | Successful Events | | 4 | System Low Errors | | 5 | User Generated Errors | | 6 | Low Relevance Attacks | | 7 | Bad Word | | 8 | First Time Seen | | 9 | Error from Invalid Source | | 10 | Multiple User Errors | | 11 | Integrity Checking Warning | | 12 | High Importance Event | | 13 | Unusual Error | | 14 | High Importance Security Event | | 15 | Severe Attack |

Active Response

Konfiguration

<active-response>
  <!-- Firewall-Block -->
  <command>firewall-drop</command>
  <location>local</location>
  <level>6</level>
  <timeout>600</timeout>
</active-response>

<active-response>
  <!-- Host-Deny -->
  <command>host-deny</command>
  <location>local</location>
  <level>6</level>
  <timeout>600</timeout>
</active-response>

Eigene Reaktion

#!/bin/bash
# /var/ossec/active-response/bin/custom-response.sh

ACTION=$1
USER=$2
IP=$3
ALERTID=$4
RULEID=$5

# Log
echo "$(date) $ACTION $IP $RULEID" >> /var/log/ossec-response.log

# Aktion
if [ "$ACTION" = "add" ]; then
    # Block IP
    iptables -I INPUT -s $IP -j DROP
elif [ "$ACTION" = "delete" ]; then
    # Unblock IP
    iptables -D INPUT -s $IP -j DROP
fi
<command>
  <name>custom-block</name>
  <executable>custom-response.sh</executable>
  <expect>srcip</expect>
  <timeout_allowed>yes</timeout_allowed>
</command>

<active-response>
  <command>custom-block</command>
  <location>local</location>
  <rules_id>100001</rules_id>
  <timeout>3600</timeout>
</active-response>

Alerts und Reports

Alert-Logs

# Live-Alerts
tail -f /var/ossec/logs/alerts/alerts.log

# JSON-Format
tail -f /var/ossec/logs/alerts/alerts.json

Täglicher Report

/var/ossec/bin/ossec-reportd

Syscheck-Report

/var/ossec/bin/syscheck_control -l

Web-Interface (Wazuh)

Installation

# Wazuh ist der moderne OSSEC-Fork mit Web-UI
curl -sO https://packages.wazuh.com/4.7/wazuh-install.sh
bash wazuh-install.sh -a

Zugriff

URL: https://server-ip:443
User: admin
Password: (bei Installation angezeigt)

Agentless-Monitoring

SSH-basiert

<agentless>
  <type>ssh_integrity_check_linux</type>
  <frequency>36000</frequency>
  <host>admin@192.168.1.50</host>
  <state>periodic</state>
  <arguments>/etc /bin /sbin</arguments>
</agentless>

Gerät hinzufügen

/var/ossec/agentless/register_host.sh add admin@192.168.1.50 NOPASS

Troubleshooting

Logs prüfen

# OSSEC-Logs
tail -f /var/ossec/logs/ossec.log

# Alerts
tail -f /var/ossec/logs/alerts/alerts.log

# Archive
tail -f /var/ossec/logs/archives/archives.log

Agent-Verbindung

# Auf Server
/var/ossec/bin/agent_control -l

# Agent-Status
/var/ossec/bin/agent_control -i 001

Regel testen

# Regel mit Log-Eintrag testen
/var/ossec/bin/ossec-logtest

# Log-Zeile eingeben und Enter

Konfiguration prüfen

/var/ossec/bin/ossec-analysisd -t

Zusammenfassung

| Befehl | Funktion | |--------|----------| | ossec-control start/stop | Dienst steuern | | manage_agents | Agents verwalten | | agent_control -l | Agents auflisten | | ossec-logtest | Regeln testen | | syscheck_control | FIM-Status |

| Verzeichnis | Inhalt | |-------------|--------| | /var/ossec/etc | Konfiguration | | /var/ossec/rules | Regeln | | /var/ossec/logs | Logs | | /var/ossec/queue | Queues |

| Datei | Funktion | |-------|----------| | ossec.conf | Hauptkonfiguration | | local_rules.xml | Eigene Regeln | | agent.conf | Agent-Konfiguration | | internal_options.conf | Interne Optionen |

Fazit

OSSEC ist ein mächtiges HIDS für Linux-Server. Die Kombination aus Log-Analyse, Dateiintegritätsprüfung und aktiver Reaktion bietet umfassenden Schutz. Für größere Umgebungen empfiehlt sich der Wazuh-Fork mit modernem Web-Interface. Die Lernkurve ist steil, aber die Investition lohnt sich für sicherheitskritische Infrastrukturen.