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

Đang mở
#5,849 0 bình luận 1 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
58/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
php, python
Lĩnh vực
backend, security

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
PHP
Star
1.2k
Fork
932
Merge trung bình
1 ngày 11 giờ
Pull request đã merge (30 ngày)
22

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của opnsense/plugins

Tất cả issue của opnsense/plugins

Issue tương tự

Thêm issue về PHP

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.