os-wazuh-agent: active response fails to extract source IP from non-standard decoders (Caddy JSON, custom JSON) — silent no-op
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
- 50/100
Hướng nghiên cứu
The issue identifies the shipped opnsense-fw script and its source IP extraction logic at lines 72–80; start by locating that script in the os-wazuh-agent plugin and reading its existing tests or active response setup. Check how it handles the listed alert field paths and logging failures, then verify that Caddy and native Wazuh alert examples still reach the firewall action.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Important notices
Before you add a new report, we ask you kindly to acknowledge the following:
- [ X] I have read the contributing guide lines at https://github.com/opnsense/plugins/blob/master/CONTRIBUTING.md
- [ X] I have searched the existing issues, open and closed, and I'm convinced that mine is new.
- [ X] When the request is meant for an existing plugin, I've added its name to the title.
Summary
The opnsense-fw active response script currently extracts the source IP by following a single fixed token path:
parameters → alert → data → srcip
This works for native Wazuh decoders (Suricata, firewall rules, etc.) where the IP is stored in data.srcip, but silently fails for decoders that store the IP in a different location:
- Caddy JSON decoder — IP is in
data.request.remote_ip - Custom JSON decoders — IP may be in
data.source_ip,data.client_ip, etc.
When the srcip token is missing at any point in the chain, the script logs "srcip not found" and exits with return code -1. No IP is added to the __wazuh_agent_drop table and the attacker continues to be able to hit the target. The failure is silent from the manager's perspective — the alert fires, the active response is "executed", but nothing happens on the firewall.
Related issues
- #4738 (fixed in #5104) —
add/abortrace when multiple IPs share a rule-id-only key - #5849 (open) —
send_log()crashes silently whenactive-responses.logis a symlink loop
Environment
- OPNsense 26.7.x (amd64)
- os-wazuh-agent 1.3_1
- Wazuh manager 4.x, agent on the firewall
- Active response
opnsense-fwwithtimeout 3600,Repeated offenders 30,60,120,1440 - Caddy reverse proxy in front of ~14 vhosts, logs decoded via JSON decoder
Reproduction
- Deploy Wazuh agent on OPNsense with the
opnsense-fwactive response. - Trigger an alert from a Caddy JSON decoder (e.g., rule 996014 — "Caddy: Credential or private key file access", scanning
/.env*). - Check the active response log:
2026/11/09 15:33:22 opnsense-fw: Started
2026/11/09 15:33:22 opnsense-fw: Received : {"command": "add", "parameters": {"alert": {"data": {"request": {"remote_ip": "34.62.254.152"}}, "rule": {"id": "996014"}}}}
2026/11/09 15:33:22 opnsense-fw: srcip not found
The IP is not added to the __wazuh_agent_drop table. The same alert type worked correctly on 2026-11-03 (same rule 996014, IP 37.168.149.142 was successfully banned), indicating the regression was introduced by a plugin update.
Root Cause
The current extraction logic (lines 72–80 of the shipped script):
srcip = event
for token in ['parameters', 'alert', 'data', 'srcip']:
if type(srcip) is dict and token in srcip:
srcip = srcip[token]
else:
srcip = None
break
if srcip is None:
send_log('srcip not found')
return -1
Only works when data.srcip exists. For Caddy alerts, the IP is nested under data.request.remote_ip, so the token chain breaks at srcip and the script exits before reaching the pfctl call.
Proposed Fix
Replace the fixed token path with a multi-path extraction function that tries known field locations in order:
def extract_srcip(event):
"""Extract source IP from various alert formats.
Tries known field locations in priority order.
Returns the first valid IP string found, or None.
"""
paths = [
# Caddy JSON decoder (remote_ip in request object)
('parameters', 'alert', 'data', 'request', 'remote_ip'),
# Suricata / common decoders
('parameters', 'alert', 'data', 'source_ip'),
# Some JSON decoders (client_ip in request object)
('parameters', 'alert', 'data', 'request', 'client_ip'),
# Native Wazuh field (suricata, firewall, etc.)
('parameters', 'alert', 'data', 'srcip'),
]
for path in paths:
node = event
for token in path:
if isinstance(node, dict) and token in node:
node = node[token]
else:
break
else:
# All tokens matched — node is the IP candidate
candidate = str(node) if node is not None else None
if candidate:
return candidate
return None
And in main(), replace the fixed token loop:
# Before:
# srcip = event
# for token in ['parameters', 'alert', 'data', 'srcip']:
# ...
# After:
srcip = extract_srcip(event)
if srcip is None:
send_log('srcip not found in event: %s' % json.dumps(event))
return -1
The existing ipaddress.ip_address(srcip) validation immediately after remains unchanged, so non-IP values are still rejected.
Use Cases Covered
| Decoder | Field Path | Status Before | Status After |
|---|---|---|---|
| Caddy (JSON) | data.request.remote_ip |
❌ srcip not found — no ban | ✅ IP extracted, ban applied |
| Suricata | data.source_ip |
❌ srcip not found — no ban | ✅ IP extracted, ban applied |
| Custom JSON | data.client_ip |
❌ srcip not found — no ban | ✅ IP extracted, ban applied |
| Native Wazuh | data.srcip |
✅ Works | ✅ Still works (backward compatible) |
Additional Improvement: send_log() Robustness
Issue #5849 reports that send_log() crashes silently when /var/ossec/logs/active-responses.log becomes a symlink loop. The script dies on the first send_log('Started') before the firewall action. While that issue is about the symlink itself, the script should also be resilient to any logging failure:
def send_log(line):
try:
with open('/var/ossec/logs/active-responses.log', 'a') as handle:
handle.write(
str(datetime.datetime.now().strftime('%Y/%m/%d %H:%M:%S')) +
" " +
os.path.basename(__file__) +
": " +
line +
"\n"
)
except OSError as e:
# Fallback to syslog so a logging failure never blocks the firewall action
import syslog
syslog.syslog(syslog.LOG_WARNING,
"opnsense-fw: %s (log write failed: %s)" % (line, e))
Impact
- Backward compatible: Native Wazuh alerts (
data.srcip) still work. - New coverage: Caddy, Suricata (when IP is in
source_ip), and custom JSON decoders now work. - Reliability: Script no longer dies on logging failures — the firewall action always proceeds.
Test Case
# Simulate a Caddy alert
echo '{"command":"add","parameters":{"alert":{"data":{"request":{"remote_ip":"1.2.3.4"}},"rule":{"id":"996014"}}}}' | /var/ossec/active-response/bin/opnsense-fw
# Expected: 1.2.3.4 added to __wazuh_agent_drop
pfctl -t __wazuh_agent_drop -T list | grep 1.2.3.4
# Simulate a native Wazuh alert (backward compat)
echo '{"command":"add","parameters":{"alert":{"data":{"srcip":"5.6.7.8"},"rule":{"id":"996014"}}}}' | /var/ossec/active-response/bin/opnsense-fw
# Expected: 5.6.7.8 added to __wazuh_agent_drop
pfctl -t __wazuh_agent_drop -T list | grep 5.6.7.8
Context: Why this matters
We run Caddy as a reverse proxy in front of ~14 vhosts. The JSON decoder produces alerts where the IP is in data.request.remote_ip. Since the plugin update (around 2026-11-09), all Caddy-triggered active responses have been silently failing. The native Wazuh decoders (Suricata, firewall) still work because they use data.srcip.
The fix is small (one function + one call site) and fully backward compatible.
- 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
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của opnsense/plugins
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
www/squid: configctl proxy stop returns before Squid exits, so stop+start (e.g. Monit restart) failsĐang mởsupport
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
opnsense/plugins#5983 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
Maintainer thường phản hồi trong vòng 1 ngày
-
net/haproxy: IPv6 literal in real server "Source address" generates an invalid `source` directiveCó thể đã có người làm @fraenki đã nhận 6 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
opnsense/plugins#5973 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[dns/ddclient] Support hiding unused standard fields per service (optional_hiding)Có thể đã có người làm @bringha1 đã nhận 9 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của opnsense/plugins
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Automattic/blocks-engine#7881 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 86/100
iruzen-dono/workless#117 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
magicsunday/webtrees-docker#285 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Flaky browser test: AreaHeadersTest 'shows Counting on the way while deferred tab counts load'Đang mởarea/tests type/bug when/soon
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 1 ngày
-
WP-CLI 3.0 fixes the cron lock and core download bugs described in the handbookCó thể đã có người làm @mayankmajeji đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
WordPress/hosting-handbook#521 ·