# ossec/ossec-hids architecture

> Architecture diagram of the GitHub repository ossec/ossec-hids, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ossec/ossec-hids
- Repository: https://github.com/ossec/ossec-hids

## Overview

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: [`src/analysisd`](https://github.com/ossec/ossec-hids/tree/main/src/analysisd) (Analysisd), [`src/client-agent`](https://github.com/ossec/ossec-hids/tree/main/src/client-agent) (Agent), [`src/shared`](https://github.com/ossec/ossec-hids/tree/main/src/shared) (Shared libs), [`src/remoted`](https://github.com/ossec/ossec-hids/tree/main/src/remoted) (Remoted)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_endpoint["Endpoint"]
  node_client_agent["Agent<br/>endpoint daemon"]
  node_logcollector["Log collector"]
  node_syscheckd["Syscheck<br/>integrity monitor"]
  node_rootcheck["Rootcheck<br/>policy scanner"]
  node_agentlessd["Agentless<br/>polling daemon"]
end

subgraph group_group_manager["Manager"]
  node_enrollment["Enrollment<br/>auth boundary"]
  node_remoted["Remoted<br/>transport daemon"]
  node_analysisd["Analysisd<br/>detection engine"]
  node_decoders["Decoders<br/>parse layer"]
  node_rules["Rules<br/>correlation logic<br/>[rules.c]"]
  node_output["Outputs<br/>alert fanout"]
  node_alerting["Alerting<br/>alert hooks"]
  node_csyslogd["Syslog relay<br/>forwarder"]
  node_reportd["Reportd<br/>report generator"]
  node_maildb_monit["Mail/DB/Monitor<br/>ops services"]
end

subgraph group_group_shared["Shared runtime"]
  node_shared["Shared libs<br/>common runtime"]
  node_crypto_regex_xml["Crypto/Parse libs<br/>portability libs"]
end

subgraph group_group_policy["Policy layer"]
  node_policy["Policy assets<br/>config and rules"]
end

subgraph group_group_response["Response"]
  node_osexecd["Execd<br/>response runtime"]
  node_responses["Responses<br/>script set"]
end

subgraph group_group_platform["Platform"]
  node_platform["Platform support<br/>init and packaging"]
end

subgraph group_group_tooling["Tooling"]
  node_tooling["Build & tests<br/>validation"]
end

node_repo{{"OSSEC<br/>security suite"}}

node_repo -->|"endpoint runtime"| node_client_agent
node_repo -->|"collect logs"| node_logcollector
node_repo -->|"integrity check"| node_syscheckd
node_repo -->|"policy scan"| node_rootcheck
node_repo -->|"agentless polling"| node_agentlessd
node_repo -->|"enroll agents"| node_enrollment
node_repo -->|"transport"| node_remoted
node_repo -->|"detect"| node_analysisd
node_repo -->|"fan out"| node_output
node_repo -->|"hooks"| node_alerting
node_repo -->|"relay"| node_csyslogd
node_repo -->|"report"| node_reportd
node_repo -->|"remediate"| node_osexecd
node_repo -->|"scripts"| node_responses
node_repo -->|"notify/store"| node_maildb_monit
node_repo -->|"reuse runtime"| node_shared
node_repo -->|"portability libs"| node_crypto_regex_xml
node_repo -->|"driven by"| node_policy
node_repo -->|"packaging"| node_platform
node_repo -->|"validated by"| node_tooling
node_client_agent -->|"send telemetry"| node_remoted
node_logcollector -->|"forward events"| node_client_agent
node_syscheckd -->|"send changes"| node_client_agent
node_rootcheck -->|"send findings"| node_client_agent
node_remoted -->|"deliver events"| node_analysisd
node_analysisd -->|"produce alerts"| node_output
node_analysisd -->|"trigger response"| node_osexecd
node_analysisd -->|"store notify"| node_maildb_monit
node_output -->|"integrate"| node_responses
node_policy -->|"rules & decoders"| node_analysisd
node_policy -->|"dbs"| node_rootcheck
node_shared -->|"helpers"| node_client_agent
node_shared -->|"helpers"| node_analysisd
node_shared -->|"helpers"| node_remoted
node_crypto_regex_xml -->|"parse/format"| node_analysisd
node_platform -->|"services"| node_client_agent
node_platform -->|"services"| node_remoted
node_tooling -->|"validate"| node_policy
node_tooling -->|"test"| node_shared

click node_client_agent "https://github.com/ossec/ossec-hids/tree/main/src/client-agent"
click node_logcollector "https://github.com/ossec/ossec-hids/tree/main/src/logcollector"
click node_syscheckd "https://github.com/ossec/ossec-hids/tree/main/src/syscheckd"
click node_rootcheck "https://github.com/ossec/ossec-hids/tree/main/src/rootcheck"
click node_agentlessd "https://github.com/ossec/ossec-hids/tree/main/src/agentlessd"
click node_remoted "https://github.com/ossec/ossec-hids/tree/main/src/remoted"
click node_analysisd "https://github.com/ossec/ossec-hids/tree/main/src/analysisd"
click node_decoders "https://github.com/ossec/ossec-hids/tree/main/src/analysisd/decoders"
click node_rules "https://github.com/ossec/ossec-hids/blob/main/src/analysisd/rules.c"
click node_output "https://github.com/ossec/ossec-hids/tree/main/src/analysisd/output"
click node_alerting "https://github.com/ossec/ossec-hids/tree/main/src/analysisd/alerts"
click node_csyslogd "https://github.com/ossec/ossec-hids/tree/main/src/os_csyslogd"
click node_reportd "https://github.com/ossec/ossec-hids/tree/main/src/reportd"
click node_osexecd "https://github.com/ossec/ossec-hids/tree/main/src/os_execd"
click node_responses "https://github.com/ossec/ossec-hids/tree/main/active-response"
click node_shared "https://github.com/ossec/ossec-hids/tree/main/src/shared"
click node_crypto_regex_xml "https://github.com/ossec/ossec-hids/tree/main/src/os_crypto"
click node_policy "https://github.com/ossec/ossec-hids/tree/main/etc"
click node_platform "https://github.com/ossec/ossec-hids/tree/main/src/systemd"
click node_tooling "https://github.com/ossec/ossec-hids/tree/main/src/Makefile"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_client_agent,node_logcollector,node_syscheckd,node_rootcheck,node_agentlessd,node_tooling toneBlue
class node_enrollment,node_remoted,node_analysisd,node_decoders,node_rules,node_output,node_alerting,node_csyslogd,node_reportd,node_maildb_monit toneAmber
class node_shared,node_crypto_regex_xml toneMint
class node_policy toneRose
class node_osexecd,node_responses toneIndigo
class node_platform toneTeal
class node_repo toneNeutral
```

## Components

### Endpoint

Agent-side collection and local checks on monitored hosts.

- [Agent](https://github.com/ossec/ossec-hids/tree/main/src/client-agent): endpoint daemon · Agent runtime that collects local telemetry and forwards normalized events to the manager. · `src/client-agent`
- [Log collector](https://github.com/ossec/ossec-hids/tree/main/src/logcollector): collector · Tails and parses diverse log sources such as syslog, journald, Windows events, multiline logs, and database logs. · `src/logcollector`
- [Syscheck](https://github.com/ossec/ossec-hids/tree/main/src/syscheckd): integrity monitor · Performs file integrity monitoring and realtime change detection on endpoints. · `src/syscheckd`
- [Rootcheck](https://github.com/ossec/ossec-hids/tree/main/src/rootcheck): policy scanner · Runs rootkit and policy checks using bundled databases under the rootcheck tree. · `src/rootcheck`
- [Agentless](https://github.com/ossec/ossec-hids/tree/main/src/agentlessd): polling daemon · 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**: auth boundary · Agent registration, key exchange, and authentication between agents and manager.
- [Remoted](https://github.com/ossec/ossec-hids/tree/main/src/remoted): transport daemon · Central inbound transport for agent messages and manager-to-agent coordination. · `src/remoted`
- [Analysisd](https://github.com/ossec/ossec-hids/tree/main/src/analysisd): detection engine · Parses events, applies decoders and rules, correlates state, and produces security alerts. · `src/analysisd`
- [Decoders](https://github.com/ossec/ossec-hids/tree/main/src/analysisd/decoders): parse layer · Log-specific parsing, plugin decoders, and event normalization before rule evaluation. · `src/analysisd/decoders`
- [Rules](https://github.com/ossec/ossec-hids/blob/main/src/analysisd/rules.c): correlation logic · Rule loading, compilation, and event classification used by the analysis engine. · `src/analysisd/rules.c`
- [Outputs](https://github.com/ossec/ossec-hids/tree/main/src/analysisd/output): alert fanout · Alert emission paths including JSON, Prelude, and ZeroMQ integrations. · `src/analysisd/output`
- [Alerting](https://github.com/ossec/ossec-hids/tree/main/src/analysisd/alerts): alert hooks · Alert logging and execution hooks inside the analysis pipeline. · `src/analysisd/alerts`
- [Syslog relay](https://github.com/ossec/ossec-hids/tree/main/src/os_csyslogd): forwarder · Forwards alerts to remote syslog-style destinations. · `src/os_csyslogd`
- [Reportd](https://github.com/ossec/ossec-hids/tree/main/src/reportd): report generator · Produces report artifacts from alert data. · `src/reportd`
- **Mail/DB/Monitor**: ops services · Email notifications, alert persistence to databases, and monitoring/report artifacts.

### Shared runtime

Common libraries and portability layers used across daemons.

- [Shared libs](https://github.com/ossec/ossec-hids/tree/main/src/shared): common runtime · Filesystem, hashing, lists, queues, privilege separation, regex, report, and message helpers shared by most daemons. · `src/shared`
- [Crypto/Parse libs](https://github.com/ossec/ossec-hids/tree/main/src/os_crypto): portability 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](https://github.com/ossec/ossec-hids/tree/main/etc): config and rules · Runtime configuration, decoders, rules, templates, and rootcheck databases that shape detection behavior. · `etc`

### Response

Active response scripts and execution boundary.

- [Execd](https://github.com/ossec/ossec-hids/tree/main/src/os_execd): response runtime · Executes active-response actions triggered by analysis. · `src/os_execd`
- [Responses](https://github.com/ossec/ossec-hids/tree/main/active-response): script set · Shell and Windows response scripts for blocking, account control, firewall changes, routing, and external integrations. · `active-response`

### Platform

Packaging, init, systemd, and Windows service surface.

- [Platform support](https://github.com/ossec/ossec-hids/tree/main/src/systemd): init and packaging · systemd units, init scripts, Windows support, and distribution packaging artifacts. · `src/systemd`

### Tooling

Build, test, and validation assets.

- [Build & tests](https://github.com/ossec/ossec-hids/tree/main/src/Makefile): validation · Primary build entry point plus unit/regression tests, log validation harnesses, and CI workflows. · `src/Makefile`

### Other components

- **OSSEC**: security suite · Multi-process host security platform built around agent, manager, shared runtime, and policy-driven detection.

## Connections

- 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.
