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

Abierto
#5,849 0 comentarios 1 reacción 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
58/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
php, python
Área
backend, security

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
PHP
Estrellas
1.2k
Forks
932
Merge medio
1 d 11 h
PR fusionados (30 d)
22

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de opnsense/plugins

Todos los issues de opnsense/plugins

Issues similares

Más issues de PHP

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.