~3m32:46
Taylor Walton

Actively Blocking Attackers with Wazuh - Let's Deploy a Host Intrusion Detection System #7

Mar 2, 2021

Read: ~3m · You save: 30 min

Actively Blocking Attackers with Wazuh: Deploying a Host Intrusion Detection System

Learn to automatically block attackers with Wazuh! Deploy a proactive Host Intrusion Detection System using active response.

Wazuh's active response capabilities enable a proactive defense strategy by automatically blocking malicious IP addresses upon detection of specific security events. This approach significantly reduces the window of opportunity for attackers to gain persistence or spread malware within a network, moving beyond a purely reactive stance.

How Active Response Works

The core of Wazuh's active response functionality relies on the interaction between the Wazuh agent and manager. When a Wazuh agent detects a suspicious activity, such as multiple failed login attempts indicative of a brute-force attack, it forwards this information to the Wazuh manager. The manager, configured with specific rules, can then trigger an active response.

For Linux systems, this response typically involves executing an iptables command. iptables acts as a local firewall, allowing administrators to define rules for network traffic. By default, a newly provisioned Linux server might allow connections to port 22 (SSH) from any IP address. Active response dynamically creates an iptables rule to block the identified malicious IP address, preventing further login attempts.

On Windows systems, a similar mechanism is employed using the route null command, which adds the offending IP address to a null route, effectively dropping traffic from that source.

Configuration and Scripting

Wazuh provides pre-built scripts for active responses, located in the /var/ossec/active-response/bin/ directory on both the manager and agents. The firewall_drop.sh script is commonly used for blocking IP addresses on Linux. These scripts are written in Bash and can be customized or extended to suit specific needs. Administrators can also develop their own scripts for unique response actions.

The configuration for active response is managed within the Wazuh manager's ossec.conf file, which can be accessed and edited directly or through the more user-friendly web interface.

Key Configuration Parameters:

  • Whitelisting: Global whitelisting can be configured to exempt specific IP addresses or CIDR blocks from active response actions. This is crucial for ensuring legitimate users or services are not inadvertently blocked.
  • Commands: This section defines the active response commands, linking a command name to its executable script (e.g., firewall_drop.sh).
  • Active Response Tag: This is where the active response rules are defined.
    • Command Name: The name of the script to execute (e.g., firewall_drop).
    • Location: Specifies where the script should run:
      • local: Runs on the agent where the alert originated.
      • server: Runs on the Wazuh manager.
      • defined-agent: Runs on specific agent IDs. This offers granular control and is recommended for sensitive environments to prevent widespread disruption.
      • all: Runs on all agents. This option requires extreme caution.
    • Rules: Defines which alerts trigger the active response. This can be based on:
      • Level: Severity level of the alert (1-16).
      • Rule Groups: Alerts belonging to a specific group (e.g., authentication failures).
      • Rule ID: A specific alert rule ID.

Introduction: From Reactive to Proactive Defense

The video begins by establishing the context: a deployed Wazuh and ELK stack architecture for host intrusion detection. It highlights the limitations of a purely reactive defense, where alerts are received only after an incident occurs, leaving a window for attackers to gain persistence or spread malware. The introduction of Wazuh's active response capabilities is presented as the solution for a more proactive defense.

  • Wazuh and ELK stack are deployed for host intrusion detection.
  • Current defense is reactive: alerts are received after an incident.
  • Reactive defense allows attackers time to gain persistence or spread malware.
  • Wazuh's active response capabilities enable proactive defense.

Understanding Wazuh Active Response and iptables

This section explains the core concept of active response: configuring Wazuh to automatically block malicious IP addresses upon detecting specific rule violations, such as brute-force attacks. It details how Wazuh agents send logs to the manager, which then triggers actions. The demonstration uses `iptables` on Linux as the mechanism for blocking IPs, explaining its function as a local firewall.

  • Active response allows Wazuh to take proactive actions.
  • Example: Block IP addresses involved in brute-force attacks.
  • Wazuh agents forward logs to the manager.
  • Wazuh manager triggers active response scripts.
  • On Linux, iptables is used to block IP addresses.
  • iptables acts as a local firewall to control network access.

Active Response Scripts and Execution Flow

The tutorial delves into the practical implementation of active response, focusing on the scripts located in `/var/ossec/active-response/bin/`. It highlights the `firewall_drop.sh` script for Linux and mentions similar capabilities for Windows (`route null`). The process involves the Wazuh manager instructing the agent to execute these scripts with specific parameters, like the IP address to be blocked.

  • Active response scripts are located in /var/ossec/active-response/bin/.
  • The firewall_drop.sh script is used for Linux IP blocking.
  • Windows uses a route null command for blocking IPs.
  • Wazuh manager instructs agents to run active response scripts.
  • Scripts can be customized or custom scripts can be created.

Configuring and Modifying Detection Rules

This part focuses on configuring the specific rule that triggers the active response. The presenter modifies a 'brute force' rule (ID 5712) by lowering the failure threshold from 8 to 3 attempts within 120 seconds. It explains how to locate and edit rules in `/var/ossec/rules/` and the importance of restarting the Wazuh manager after rule changes. The process of updating local rules to avoid overwrites during upgrades is also mentioned.

  • Rules can be modified to trigger active responses.
  • Example: Lowering the brute-force detection threshold.
  • Rule ID 5712 ('brute force trying to get access to the system') was modified.
  • Threshold changed from 8 to 3 failed attempts within 120 seconds.
  • Rule files are located in /var/ossec/rules/.
  • Local rules should be placed in /var/ossec/etc/rules/local.d/ to persist across upgrades.
  • Wazuh manager must be restarted after rule changes.

Configuring Active Response via Wazuh Manager

The video guides viewers through configuring active response settings via the Wazuh manager's web interface. It covers editing the `ossec.conf` file, specifically the `<active-response>` section. Key configurations include defining commands (like `firewall_drop`), specifying the `location` (e.g., `defined-agent`), setting `agent_id`, linking to specific `rule_id`s (5712), and defining `timeout` periods for blocking (e.g., 60 seconds) and handling repeated offenders.

  • Active response can be configured via the Wazuh manager web interface or ossec.conf.
  • The <active-response> section in ossec.conf is used.
  • Commands like firewall_drop are defined with their executables.
  • Location options include local, server, defined-agent, and all.
  • Agent ID (e.g., 004) can be specified for defined-agent.
  • Active response can be triggered by rule_id, level, or rule_group.
  • Timeout parameter sets how long an IP remains blocked (e.g., 60 seconds).
  • Repeat offender settings allow for escalating block durations (e.g., 30, 60, 120 minutes).

Demonstration: Triggering and Verifying Active Response

This section demonstrates the practical outcome of the configuration. By simulating brute-force attempts, the video shows logs indicating IP addresses being blocked via `iptables` and recorded in `activeresponse.log`. It also shows IPs being unblocked after the timeout and subsequently re-blocked for longer periods due to repeat offender settings. The events are visible in the Wazuh dashboard, confirming the proactive blocking mechanism.

  • Simulated brute-force attacks trigger active response.
  • IP addresses are dynamically added to iptables block lists.
  • The activeresponse.log file records script executions.
  • Blocked IPs are removed from iptables after the timeout.
  • Repeat offenders receive longer blocking periods.
  • Blocked and unblocked events are visible in the Wazuh dashboard.
  • This provides proactive defense without human intervention.

Additional Use Cases and Final Considerations

The video briefly touches upon Windows-specific active response using the `route null` command and explores other use cases, such as isolating honeypot servers. It reiterates the power and caution required when using active response, emphasizing its ability to significantly reduce attacker dwell time and the importance of careful planning to avoid disrupting legitimate services.

  • Windows active response uses the route null command.
  • Active response can be used to isolate honeypot servers.
  • Example: Prevent a honeypot from attacking internal systems.
  • Active response significantly reduces attacker exploitation windows.
  • Caution is advised due to the potential for disrupting services.
  • Careful planning and configuration are essential.