How ossec/ossec-hids works
OSSEC v4.1.0 is a multi-process host security platform built as a classic agent/manager system. The repository is organized around long-running daemons in src/, shared runtime libraries in src/shared, bundled third-party code in src/external, and large policy/configuration datasets in etc/, active-response/, and src/rootcheck/db.
1. Two primary deployment roles
- Agents run on monitored endpoints and collect local telemetry.
- Manager/server receives agent data, analyzes it, stores or forwards alerts, and triggers responses.
- The same tree also supports local/standalone operation, where some components can run without a remote manager.
2. Agent-side collection pipeline
- src/client-agent implements the agent runtime and message forwarding.
- src/logcollector tails and parses many log sources: syslog, journald, Windows event channels, database logs, multiline logs, and application-specific formats.
- src/syscheckd performs file integrity monitoring and realtime change detection.
- src/rootcheck performs rootkit and policy checks using local databases under src/rootcheck/db.
- Collected events are normalized locally and sent onward rather than analyzed on the endpoint.
3. Agentless and enrollment paths
- src/agentlessd supports polling remote systems over SSH/Expect scripts when an agent cannot be installed.
- src/addagent and src/os_auth handle agent registration, key exchange, and authentication between agents and manager.
- These components form the onboarding boundary before telemetry enters the main analysis pipeline.
4. Manager intake and distribution
- src/remoted is the central inbound transport for agent messages and manager-to-agent coordination.
- It includes transport/security logic in secure.c, forwarding in ar-forward.c, and protocol handling for syslog-like inputs.
- Manager services also distribute configuration and control messages back to agents.
5. Core analysis engine
- src/analysisd is the heart of detection.
- It parses incoming events, decodes them, applies rules, correlates state, and builds alerts.
- Key subparts include:
- decoders/ for log-specific parsing and plugin decoders
- rules.c and related list/rule compilation code
- accumulator.c, fts.c, and event/list management for correlation and frequency tracking
- This subsystem is where raw telemetry becomes security alerts.
6. Alert output and enrichment
- analysisd/output/ emits alerts in multiple forms, including JSON and integrations such as Prelude and ZeroMQ.
- analysisd/alerts/ handles alert logging and execution hooks.
- src/os_csyslogd forwards alerts to remote syslog-style destinations.
- src/reportd produces report artifacts from alert data.
7. Active response and automated remediation
- active-response/ contains scripts for blocking hosts, disabling accounts, firewall updates, routing nulls, cloud WAF actions, and integrations like Slack, PagerDuty, and Twitter.
- src/os_execd is the runtime that executes these response actions when triggered by analysis.
- On Windows, analogous command scripts live under active-response/win/.
- This is the enforcement boundary: detection output can drive local or external mitigation.
8. Notification, storage, and reporting
- src/os_maild sends email notifications; the README calls out optional libcurl SMTP/TLS behavior when built with USE_CURL=yes.
- src/os_dbd persists alerts to MySQL or PostgreSQL schemas and supports database-backed reporting.
- src/monitord generates compressed logs, signs logs, manages files, monitors agents, and creates reports.
- These components turn alert streams into durable records and operator-facing outputs.
9. Shared platform libraries
- src/shared provides the common infrastructure used by most daemons: filesystem ops, hash/list utilities, regex wrappers, privilege separation, queues, string/memory helpers, and readers for alerts and agents.
- src/os_crypto, src/os_regex, src/os_xml, src/os_net, and src/os_zlib provide OSSEC-specific wrappers around cryptography, parsing, networking, and compression.
- This shared layer is the main internal boundary that keeps the daemons consistent across platforms.
10. Configuration and policy as first-class inputs
- Runtime behavior is driven by etc/ossec.conf, etc/ossec-server.conf, etc/ossec-agent.conf, etc/decoder.xml, and the large rule set under etc/rules/.
- Rule and decoder assets are not code; they are the policy layer that determines what the analysis engine recognizes and how it classifies events.
- etc/templates/ and src/init/ support installation-time generation of configs and service scripts.
11. Platform and packaging surface
- src/systemd/ contains systemd units for server and agent services.
- src/init/ contains init scripts for multiple Unix-like OS families.
- src/win32/ contains Windows installer, service, and UI support.
- contrib/ includes packaging artifacts for Debian, RPM/specs, Snap, SELinux, and assorted admin utilities.
12. Build, test, and CI
- src/Makefile is the primary build entry point for the C code.
- src/tests/ contains unit and regression tests for core utility libraries and historical bug fixes.
- contrib/ossec-testing/ and contrib/logtesting/ provide log/rule validation harnesses.
- GitHub Actions and older Travis/Coverity workflows cover multi-platform builds and static analysis.
13. Main data flow to diagram
- Endpoint logs, file changes, and integrity checks are gathered by agent-side daemons.
- Data is authenticated and transmitted to the manager via remoted/auth components.
- analysisd decodes and correlates events against rule/config assets.
- Alerts fan out to files, JSON/syslog/ZeroMQ-style outputs, email, database storage, reports, and active-response executors.
- Optional integrations extend from the active-response and output layers to external systems like SMTP, SIEMs, databases, and cloud security controls.
14. Architectural shape
- This is not a single application but a coordinated suite of daemons built around a shared C runtime.
- The most important boundaries are:
- endpoint collection vs manager analysis
- policy/configuration vs executable code
- alert generation vs alert delivery/remediation
- bundled portability libraries vs OSSEC-specific logic
Main entry points: analysisd Analysisd · client-agent Agent · shared Shared libs · remoted Remoted
Components 23
Endpoint
Agent-side collection and local checks on monitored hosts.
- Agent · Agent runtime that collects local telemetry and forwards normalized events to the manager.
src/client-agent - Log collector · Tails and parses diverse log sources such as syslog, journald, Windows events, multiline logs, and database logs.
src/logcollector - Syscheck · Performs file integrity monitoring and realtime change detection on endpoints.
src/syscheckd - Rootcheck · Runs rootkit and policy checks using bundled databases under the rootcheck tree.
src/rootcheck - Agentless · Checks remote systems over SSH and Expect scripts when an installed agent is not available.
src/agentlessd
Manager
Central intake, analysis, alerting, storage, and coordination services.
- Enrollment · Agent registration, key exchange, and authentication between agents and manager.
- Remoted · Central inbound transport for agent messages and manager-to-agent coordination.
src/remoted - Analysisd · Parses events, applies decoders and rules, correlates state, and produces security alerts.
src/analysisd - Decoders · Log-specific parsing, plugin decoders, and event normalization before rule evaluation.
src/analysisd/decoders - Rules · Rule loading, compilation, and event classification used by the analysis engine.
src/analysisd/rules.c - Outputs · Alert emission paths including JSON, Prelude, and ZeroMQ integrations.
src/analysisd/output - Alerting · Alert logging and execution hooks inside the analysis pipeline.
src/analysisd/alerts - Syslog relay · Forwards alerts to remote syslog-style destinations.
src/os_csyslogd - Reportd · Produces report artifacts from alert data.
src/reportd - Mail/DB/Monitor · Email notifications, alert persistence to databases, and monitoring/report artifacts.
Shared runtime
Common libraries and portability layers used across daemons.
- Shared libs · Filesystem, hashing, lists, queues, privilege separation, regex, report, and message helpers shared by most daemons.
src/shared - Crypto/Parse libs · OSSEC wrappers for cryptography, regex, XML, networking, and compression.
src/os_crypto
Policy layer
Configuration, decoders, rules, and databases that drive detection.
- Policy assets · Runtime configuration, decoders, rules, templates, and rootcheck databases that shape detection behavior.
etc
Response
Active response scripts and execution boundary.
Platform
Packaging, init, systemd, and Windows service surface.
- Platform support · systemd units, init scripts, Windows support, and distribution packaging artifacts.
src/systemd
Tooling
Build, test, and validation assets.
- Build & tests · Primary build entry point plus unit/regression tests, log validation harnesses, and CI workflows.
src/Makefile
Other components
- OSSEC · Multi-process host security platform built around agent, manager, shared runtime, and policy-driven detection.
Connections 39
- OSSEC → Agent: endpoint runtime · Agent-side daemon.
- OSSEC → Log collector: collect logs · Endpoint log ingestion.
- OSSEC → Syscheck: integrity check · File integrity monitoring.
- OSSEC → Rootcheck: policy scan · Rootkit and policy checks.
- OSSEC → Agentless: agentless polling · Remote host collection without installed agent.
- OSSEC → Enrollment: enroll agents · Registration and key/authentication boundary.
- OSSEC → Remoted: transport · Manager inbound transport and coordination.
- OSSEC → Analysisd: detect · Main analysis and correlation engine.
- OSSEC → Outputs: fan out · Alert formatting and forwarding.
- OSSEC → Alerting: hooks · Alert logging and execution hooks.
- OSSEC → Syslog relay: relay · Remote syslog-style forwarding.
- OSSEC → Reportd: report · Report artifact generation.
- OSSEC → Execd: remediate · Active response execution.
- OSSEC → Responses: scripts · Response and integration scripts.
- OSSEC → Mail/DB/Monitor: notify/store · Email, database persistence, and monitoring outputs.
- OSSEC → Shared libs: reuse runtime · Shared infrastructure.
- OSSEC → Crypto/Parse libs: portability libs · Cryptography, parsing, networking, and compression wrappers.
- OSSEC → Policy assets: driven by · Configuration, rules, and databases.
- OSSEC → Platform support: packaging · Service and installer integration.
- OSSEC → Build & tests: validated by · Build and test infrastructure.
- Agent → Remoted: send telemetry · Normalized endpoint events are forwarded to the manager.
- Log collector → Agent: forward events · Collector feeds the agent message path.
- Syscheck → Agent: send changes · Integrity events are sent onward.
- Rootcheck → Agent: send findings · Rootcheck results enter the agent pipeline.
- Remoted → Analysisd: deliver events · Inbound messages are handed to analysis.
- Analysisd → Outputs: produce alerts · Detection results fan out to outputs.
- Analysisd → Execd: trigger response · Alerts can invoke active response.
- Analysisd → Mail/DB/Monitor: store notify · Alerts can be logged, mailed, persisted, and reported.
- Outputs → Responses: integrate · Output pathways can extend to external response systems.
- Policy assets → Analysisd: rules & decoders · Analysis is driven by configuration and rule assets.
- Policy assets → Rootcheck: dbs · Rootcheck uses bundled policy databases.
- Shared libs → Agent: helpers · Common runtime support.
- Shared libs → Analysisd: helpers · Parsing and internal data structures.
- Shared libs → Remoted: helpers · Transport and security support.
- Crypto/Parse libs → Analysisd: parse/format · Shared parsing and encoding layers support analysis and outputs.
- Platform support → Agent: services · Agent startup and service wiring.
- Platform support → Remoted: services · Manager startup and service wiring.
- Build & tests → Policy assets: validate · Rule and log validation harnesses exercise policy assets.
- Build & tests → Shared libs: test · Core utility tests cover shared runtime code.