-
Notifications
You must be signed in to change notification settings - Fork 259
Block Reporting
Heisenbug edited this page Mar 5, 2026
·
1 revision
Home · Start Here · Reference Map
- LFD can execute external scripts on block and unblock events.
-
BLOCK_REPORTreceives a rich event payload (IP, ports, reason, logs, trigger). - Hooks run as root and are forcibly terminated if they exceed runtime limits.
Related guide: Security-Features-Guide
When LFD blocks an IP/CIDR (for example after login-failure detection), it can call an external executable defined by BLOCK_REPORT.
A companion hook, UNBLOCK_REPORT, can run when temporary blocks are removed.
LFD passes the following arguments in order:
-
IP address— IP/CIDR being blocked -
ports— port, list of ports, or* -
permanent—0temporary,1permanent -
inout— direction:in,out, orinout -
timeout— TTL seconds for temporary blocks, otherwise0 -
message— block reason/context -
logs— triggering log lines (multi-line payload) -
trigger— configuration setting that triggered action
For temporary unblock events:
-
IP address— IP/CIDR being unblocked -
port— port context if original temporary rule was port-specific
#!/bin/sh
# /usr/local/sbin/csf-block-report.sh
IP="$1"
PORTS="$2"
PERM="$3"
DIR="$4"
TTL="$5"
MSG="$6"
LOGS="$7"
TRIGGER="$8"
logger -t csf-block-report "ip=$IP ports=$PORTS permanent=$PERM dir=$DIR ttl=$TTL trigger=$TRIGGER"
exit 0#!/bin/sh
# /usr/local/sbin/csf-block-webhook.sh
IP="$1"
PERM="$3"
TTL="$5"
MSG="$6"
TRIGGER="$8"
TYPE="temporary"
[ "$PERM" = "1" ] && TYPE="permanent"
PAYLOAD=$(cat <<EOF
{"text":"CSF Block [$TYPE]: $IP — $MSG (trigger: $TRIGGER, ttl: ${TTL}s)"}
EOF
)
curl -s -m 5 -X POST -H 'Content-Type: application/json' \
-d "$PAYLOAD" \
"https://hooks.slack.com/services/YOUR/WEBHOOK/URL" >/dev/null 2>&1
exit 0#!/bin/sh
# /usr/local/sbin/csf-block-json.sh
IP="$1"
PORTS="$2"
PERM="$3"
DIR="$4"
TTL="$5"
MSG="$6"
TRIGGER="$8"
printf '{"ts":"%s","ip":"%s","ports":"%s","permanent":%s,"dir":"%s","ttl":%s,"trigger":"%s","msg":"%s"}\n' \
"$(date -u +%Y-%m-%dT%H:%M:%SZ)" "$IP" "$PORTS" "$PERM" "$DIR" "$TTL" "$TRIGGER" "$MSG" \
>> /var/log/csf-blocks.json
exit 0#!/bin/sh
# /usr/local/sbin/csf-block-siem.sh
IP="$1"
PERM="$3"
TRIGGER="$8"
logger -p local0.warning -t csf-block "ip=$IP permanent=$PERM trigger=$TRIGGER"
exit 0Then configure rsyslog/syslog-ng to forward local0.warning to your SIEM collector.
- Create your hook script and make it executable:
chmod 700 /usr/local/sbin/csf-block-report.sh
chown root:root /usr/local/sbin/csf-block-report.sh- Reference it in
csf.conf:
BLOCK_REPORT = "/usr/local/sbin/csf-block-report.sh"
UNBLOCK_REPORT = "/usr/local/sbin/csf-unblock-report.sh"- Restart LFD:
csf -lfTo verify your hook fires correctly:
# Temporarily block a test IP
csf -td 198.51.100.99 60 -d in "Block report test"
# Check your hook output (logger example):
journalctl -t csf-block-report --since "1 minute ago"
# or
grep csf-block-report /var/log/messages
# Clean up
csf -tr 198.51.100.99The test block will auto-expire after 60 seconds. Verify both the block hook and (after expiry or manual removal) the unblock hook.
- Hook is launched in a forked process.
- Runtime budget is approximately 10 seconds; longer tasks are terminated.
- Execution context is root — treat scripts as privileged code.
- Keep hook logic lightweight and non-blocking.
- Offload heavy processing to queues/workers (write to file/socket, let a separate process handle delivery).
- Validate/sanitize all arguments before using them in shell commands.
- Log failures explicitly for auditability.
- Use timeouts on external calls (
curl -m 5,timeout 5 ...) to stay within the 10-second budget.
- Long-running hook jobs that exceed the ~10s timeout and silently lose events.
- Unsanitized argument handling causing command-injection risk — always quote variables.
- No error logging when downstream integration fails — add explicit error handling.
- Assuming permanent and temporary workflows are identical — different triggers may send different argument combinations.
-
Hook script not executable — must have execute permission (
chmod +x). -
Forgetting to restart LFD after changing
BLOCK_REPORT/UNBLOCK_REPORTin csf.conf.
- Script Email Alerts — built-in email notification system
- External Pre and Post Scripts — hooks for firewall reload events
- LFD Clustering — block propagation across cluster nodes
Last reviewed: 2026-02-27
← Previous: Messenger Service · Next: Port Flood Protection
- Security Features Guide
- Cloud & Container Hardening
- Automation & IaC
- IPv6 Deployment & Hardening
- IP Block Lists
- Reference Map
- Introduction
- csf Principles
- lfd Principles
- csf CLI Options
- lfd CLI Options
- Login Tracking
- Regex Custom Cookbook
- Script Email Alerts
- Process Tracking
- Directory Watching
- Advanced Filters
- Multiple Ethernet
- Generic Linux
- FTP Issues
- Messenger Service
- Block Reporting
- Port Flood
- Pre/Post Scripts
- Port Knocking
- Connection Limit
- Port/IP Redirect
- Integrated UI
- RESTRICT_SYSLOG
- Exim SMTP AUTH
- UI Skinning
- InterWorx
- CentOS Web Panel