SQL injection in Wazuh wazuh-dbd PostgreSQL output
Key facts
- Attack vector
- Network
- Privileges required
- None
- User interaction
- None
- Attack complexity
- High
- Impact type
- Code execution, SQL injection
- Confidentiality · integrity · availability
- High · High · High
- Fix status
- Fixed
Attack profile from CVSS 3.1 · GHSA-6j39-726h-fx6p. Fix status from GitHub. Impact type from CWE-78 and CWE-89.
Summary
Wazuh manager (wazuh-manager) from 1.0.0 before 4.14.7 is affected only when it is self-compiled with the PostgreSQL database output for wazuh-dbd. The alert INSERT statement concatenates the srcip, dstip and srcgeoip fields without escaping, which allows SQL injection (CWE-89). An unauthenticated remote attacker can send a forged syslog datagram that injects a second statement and runs an OS command as the postgres user when the database role is a superuser. Default installs are not exploitable.
Written with Claude Haiku 5.5 from the sources below · 2026-11-12
Description from the GitHub advisory
https://github.com/user-attachments/assets/0d9a5012-3764-496a-a70e-1a185ddb8338 ## Summary `wazuh-dbd` writes alerts to a SQL database. On the PostgreSQL backend it builds the `INSERT` by string-concatenation, and the `srcip` / `dstip` / `srcgeoip` fields are inserted **without escaping** (unlike `user` / `location` / `full_log`, which are escaped). Because the PostgreSQL path runs the query with `PQexec()`, an attacker-controlled `srcip` can close the string literal and **stack a second statement**, reaching `COPY … TO PROGRAM` — which executes an OS command as the `postgres` user. The malicious `srcip` can arrive in a **forged firewall syslog datagram** parsed by a default decoder, so no authentication is required to inject. ## Affected / not affected - **Affected:** Wazuh **4.x** (confirmed on 4.14.5), **only** when the manager is self-compiled with `make DATABASE=pgsql` and a `<database_output>` PostgreSQL backend is configured. The unescaped handling is long-standing (inherited from OSSEC). - **Not affected:** **5.0** — `wazuh-dbd` was removed (CHANGELOG #30922). - **Default installs are NOT exploitable:** the official RPM/DEB ship `wazuh-dbd` compiled **without** a DB backend, so it clean-exits. This only affects the small population of self-compiled, DB-output-enabled 4.x managers. ## Root cause (tag v4.14.5) 1. **`src/os_dbd/alert.c`** — `srcip`/`dstip`/`srcgeoip` interpolated raw into the `INSERT` (PostgreSQL path ~line 192); `user`/`location`/`full_log` are escaped, these are not. 2. **`src/os_dbd/db_op.c`** (~line 294) — the PostgreSQL query runs via `PQexec()`, which permits **stacked queries**. (The MySQL path uses `mysql_query` — single statement only, so data tampering rather than RCE.) 3. **`src/analysisd/decoders/decoder.c`** (~line 280) — the decoded `srcip` is stored with **no IP validation**; `OS_IsValidIP()` is never applied. 4. **`ruleset/decoders/0100-fortigate_decoders.xml`** — the stock Fortigate decoder captures `srcip` with `(\.*)` (in Wazuh's `os_regex`, `\.` = **any character**), so a single quote survives. Cisco-ASA and other device decoders capture with `(\S+)` and are equally injectable with a whitespace-free payload. Decoders that pin `srcip` to an IP-literal class (`\d+.\d+.\d+.\d+`) are correctly not injectable. ## How it is reached In a **real** device log, `srcip` is the address the device recorded — not attacker-set. The attack works because the attacker **forges a whole syslog datagram** to the manager's syslog listener; in a forged message `srcip="…"` is just text the attacker chooses. Preconditions (all must hold): 1. Manager self-compiled `make DATABASE=pgsql`. 2. `<database_output>` → PostgreSQL configured. 3. PostgreSQL role is a **superuser** (required by `COPY … TO PROGRAM`; a non-superuser role degrades this to SQL injection / data tampering without command execution). 4. Remote **syslog** enabled — not default (stock config ships only `<connection>secure</connection>`). Collecting firewall logs is, however, a common reason to add it. 5. `<allowed-ips>` permits the sender (default-deny). On UDP/514 an attacker can spoof the source IP into the allowed range and fire blind (no reply needed). ## Proof of concept Send one forged Fortigate syslog datagram to `udp/514` with `srcip` carrying the payload: ``` <134>... type="utm" subtype="ips" ... srcip="1.1.1.1','1','1.1.1.1','1','1','u','log');COPY (SELECT '') TO PROGRAM '(id;uname -n) > /tmp/PROOF 2>&1';SELECT('" dstip="10.0.0.5" action="dropped" attack="Backdoor" ``` The stock `fortigate-firewall-v5` decoder captures `srcip` with the quote intact (rule 81629, level 6 → written to `alerts.log`) → `wazuh-dbd` builds the unescaped `INSERT` → `PQexec` runs the stacked `COPY … TO PROGRAM` → `/tmp/PROOF` is created on the PostgreSQL host owned by `postgres` (`id`/`uname` output) = command execution. A full end-to-end run (real stock manager + indexer + dashboard → genuine `make DATABASE=pgsql` `wazuh-dbd`) is provided as an attached video and witness file. The injected `srcip` is visible in the Wazuh dashboard alert, and the marker is created by `COPY … TO PROGRAM` as the `postgres` OS user. (`${IFS}` / `/**/` give a whitespace-free variant for `(\S+)` decoders.) ## Impact Arbitrary command execution as the **`postgres` OS user** on the database host, from a single unauthenticated forged log message. If the database is co-located with the manager (common in small deployments), the attacker lands on the manager host next to `client.keys` and manager secrets. Even with a separate DB host, it is full compromise of the database server reachable from an unauthenticated forged log. ## Fix One line in `src/os_dbd/alert.c`: apply `osdb_escapestr()` to `al_data->srcip`, `al_data->dstip`, and `al_data->srcgeoip` before the `snprintf`, exactly as already done for `user`/`location`/`full_log`. Better: switch `wazuh-dbd` to parameterized queries (`PQexecParams`) and connect with a non-superuser role so `COPY … TO PROGRAM` is unavailable. Defense in depth: validate decoded `srcip`/`dstip` with `OS_IsValidIP()` in `analysisd`. This is **moot in 5.0** (the daemon is removed), so the ask is a **4.x backport** for maintained branches — or a formal disable/removal of the deprecated daemon on 4.x. --- [W02_FULLCHAIN_witness.txt](https://github.com/user-attachments/files/28663893/W02_FULLCHAIN_witness.txt) [poc.sh](https://github.com/user-attachments/files/28663896/poc.sh) [os_regex_anychar_proof.txt](https://github.com/user-attachments/files/28663898/os_regex_anychar_proof.txt)
Why it matters now
SSVC decision points
Not available: CISA has not published SSVC decision points for this record.
Affected products
| Vendor | Product | Affected versions | Fixed in | Status | Source |
|---|---|---|---|---|---|
| — | wazuh-manager | >= 1.0.0 | 4.14.7 | Patch available | GHSA-6j39-726h-fx6p |
- wazuh-manager Vendor— Affected >= 1.0.0 Fixed in 4.14.7 Patch available GHSA-6j39-726h-fx6p
Remediation
Upgrade wazuh-manager to version 4.14.7.
Written with Claude Haiku 5.5 from the sources below · 2026-11-12
- Fix · GHSA-6j39-726h-fx6p wazuh-manager Fixed in 4.14.7 Advisory →
Timeline
- 2026-11-12 Threatist record created from GHSA-6j39-726h-fx6p
References
Sources
This product uses the NVD API but is not endorsed or certified by the NVD. Sources and licences