security/wazuh-agent: active response silently fails when /var/ossec/logs/active-responses.log becomes a symlink loop

Aperta
#5,849 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
58/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
php, python
Ambito
backend, security

Direzione di ricerca

Start with /usr/local/opnsense/scripts/wazuh/opnsense-fw and its send_log() function, then read /usr/local/opnsense/scripts/wazuh/setup.php where the active response log symlink is created. Reproduce the self-referencing symlink described in the issue and check that logging failure no longer blocks the firewall action and setup restores a regular log file with the stated ownership and permissions.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Important notices

Describe the bug
Active response with the opnsense-fw command did not block anything. Investigation showed that /var/ossec/logs/active-responses.log had become a symbolic link pointing to itself. send_log() in /usr/local/opnsense/scripts/wazuh/opnsense-fw opens that file in append mode without error handling:

def send_log(line):
    with open('/var/ossec/logs/active-responses.log', 'a') as handle:

so the script dies on the first send_log('Started') (OSError: [Errno 62] Too many levels of symbolic links) before the address is added to the __wazuh_agent_drop table. On the firewall nothing happens and nothing is logged.

/usr/local/opnsense/scripts/wazuh/setup.php creates symlinks around this file ("temporary solution to link log files"):

@symlink("/var/ossec/logs/active-responses.log", "/var/log/wazuhagent/activeresponses/activeresponses_99991231.log");

We could not determine exactly which step turned the target itself into a self-referencing link (log housekeeping of /var/log/wazuhagent/* is our main suspect), so we report the observation and the effect.

To Reproduce

  1. ln -sf /var/ossec/logs/active-responses.log /var/ossec/logs/active-responses.log (simulates the broken state we found).
  2. Trigger an active response for opnsense-fw (or run the script with a test event on stdin).
  3. The source address is not added to __wazuh_agent_drop; no error is visible.

Expected behavior

  • A logging failure should never prevent the firewall action.
  • setup.php should repair the log file if it is not a regular file.

Suggested fix

  1. In opnsense-fw, make send_log() tolerant: wrap it in try/except OSError (fall back to syslog).
  2. In setup.php, before creating the debug symlinks: if /var/ossec/logs/active-responses.log is a link, unlink() it and touch() a regular file (owner root:wazuh, 0660).

We are happy to submit a PR for both points.

Relevant log files
None — which is the problem: the failure is silent. Fixed on our side by replacing the link with a regular file; active response then worked immediately (manual test with agent_control -b <ip> -f opnsense-fw3600 -u <agent id>).

Environment
OPNsense 26.7.x (amd64), os-wazuh-agent 1.3_1, wazuh-agent 4.14.8, manager Wazuh 4.14.x

Lingua principale
PHP
Stelle
1.2k
Fork
932
Merge medio
1g 11h
PR unite (30g)
22

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di opnsense/plugins

Tutte le issue di opnsense/plugins

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.