2024-05-22 21:03:47 +02:00
# Wazuh notify
2024-05-04 22:24:42 +02:00
2024-05-23 17:32:58 +02:00
## Table of Contents
2024-05-04 22:24:42 +02:00
2024-05-23 17:32:58 +02:00
- [Introduction ](#introduction )
- [Installation ](#installation )
- [Configuration ](#configuration )
- [The YAML configuration ](#the-yaml-configuration )
2024-05-04 22:24:42 +02:00
2024-05-23 17:32:58 +02:00
## Introduction
Wazuh notifier enables the Wazuh manager to be notified when selected events occur, using 3 messaging platforms:
ntfy.sh, Discord and Slack.
There are 2 implementations of Wazuh notify. One written in Golang and the other in Python. Both implementations have
similar functionality, but the Python version is slightly more configurable.
Wazuh notify is a stateless implementation and only notifies, triggered by selected rules, agents, or threat levels.
2024-05-04 22:24:42 +02:00
2024-05-22 21:03:47 +02:00
Wazuh notify is triggered by configuring the **ossec.conf** and adding an **active response configuration.**
2024-05-04 22:24:42 +02:00
2024-05-23 17:32:58 +02:00
## Installation
2024-05-04 22:24:42 +02:00
2024-05-23 17:32:58 +02:00
### Step 1: download
2024-05-04 22:24:42 +02:00
2024-05-22 21:03:47 +02:00
Download the files from https://github.com/kleinprojects/wazuh-notify to your server.
2024-05-04 22:24:42 +02:00
2024-05-23 17:32:58 +02:00
### Step 2: copy files
#### _Python_ {id="python_1"}
2024-05-23 18:51:30 +02:00
Copy the 2 Python scripts to the /var/ossec/active-response/bin/ folder
2024-05-04 22:24:42 +02:00
```
2024-05-23 17:32:58 +02:00
$ sudo cp < download folder > /wazuh-*.py /var/ossec/active-response/bin/
2024-05-04 22:24:42 +02:00
```
2024-05-23 17:32:58 +02:00
2024-05-23 18:51:30 +02:00
Set the correct ownership {id="set-the-correct-ownership_1"}
2024-05-23 17:32:58 +02:00
2024-05-04 22:24:42 +02:00
```
2024-05-23 17:32:58 +02:00
$ sudo chown root:wazuh /var/ossec/active-response/bin/wazuh-notify.py
$ sudo chown root:wazuh /var/ossec/active-response/bin/wazuh_notify_module.py
2024-05-04 22:24:42 +02:00
```
2024-05-23 17:32:58 +02:00
2024-05-23 18:51:30 +02:00
Set the correct permissions {id="set-the-correct-permissions_1"}
2024-05-23 17:32:58 +02:00
2024-05-22 21:03:47 +02:00
```
2024-05-23 17:32:58 +02:00
$ sudo chmod uog+rx /var/ossec/active-response/bin/wazuh-notify.py
$ sudo chmod uog+rx /var/ossec/active-response/bin/wazuh_notify_module.py
2024-05-22 21:03:47 +02:00
```
2024-05-04 22:24:42 +02:00
2024-05-23 17:32:58 +02:00
#### _Golang_ {id="golang_1"}
2024-05-23 18:51:30 +02:00
Copy the Go executable to the /var/ossec/active-response/bin/ folder
2024-05-23 17:32:58 +02:00
2024-05-22 21:03:47 +02:00
```
2024-05-23 17:32:58 +02:00
$ sudo cp < download folder > /wazuh-notify /var/ossec/active-response/bin/
```
2024-05-23 18:51:30 +02:00
Set the correct ownership {id="set-the-correct-ownership_2"}
2024-05-23 17:32:58 +02:00
```
$ sudo chown root:wazuh /var/ossec/active-response/bin/wazuh-notify
```
2024-05-23 18:51:30 +02:00
Set the correct permissions {id="set-the-correct-permissions_2"}
2024-05-23 17:32:58 +02:00
```
$ sudo chmod uog+rx /var/ossec/active-response/bin/wazuh-notify
```
### Step 3
2024-05-23 18:51:30 +02:00
Copy the YAML file to /var/ossec/etc/
2024-05-23 17:32:58 +02:00
```
$ sudo cp < download folder > /wazuh-notify-config.yaml /var/ossec/etc/
2024-05-04 22:24:42 +02:00
```
2024-05-23 17:32:58 +02:00
2024-05-23 18:51:30 +02:00
Set the correct ownership {id="set-the-correct-ownership_3"}
2024-05-23 17:32:58 +02:00
2024-05-22 21:03:47 +02:00
```
2024-05-23 17:32:58 +02:00
$ sudo chown root:wazuh /var/ossec/etc/wazuh-notify-config.yaml
2024-05-22 21:03:47 +02:00
```
2024-05-23 17:32:58 +02:00
2024-05-23 18:51:30 +02:00
Set the correct permissions {id="set-the-correct-permissions_3"}
2024-05-23 17:32:58 +02:00
2024-05-22 21:03:47 +02:00
```
2024-05-23 17:32:58 +02:00
$ sudo chmod uog+r /var/ossec/etc/wazuh-notify-config.yaml
2024-05-04 22:24:42 +02:00
```
2024-05-23 17:32:58 +02:00
### Step 4
2024-05-23 18:51:30 +02:00
Create an .env file in /var/ossec/etc/
2024-05-23 17:32:58 +02:00
2024-05-04 22:24:42 +02:00
```
2024-05-23 17:32:58 +02:00
$ sudo touch /var/ossec/etc/.env
2024-05-04 22:24:42 +02:00
```
2024-05-23 18:51:30 +02:00
Set the correct ownership {id="set-the-correct-ownership_4"}
2024-05-23 17:32:58 +02:00
2024-05-04 22:24:42 +02:00
```
2024-05-23 17:32:58 +02:00
$ sudo chown root:wazuh /var/ossec/etc/wazuh-notify-config.yaml
2024-05-04 22:24:42 +02:00
```
2024-05-23 18:51:30 +02:00
Set the correct permissions {id="set-the-correct-permissions_4"}
2024-05-23 17:32:58 +02:00
2024-05-04 22:24:42 +02:00
```
2024-05-23 17:32:58 +02:00
$ sudo chmod uog+r /var/ossec/etc/wazuh-notify-config.yaml
2024-05-04 22:24:42 +02:00
```
2024-05-23 17:32:58 +02:00
## Configuration
2024-05-04 22:24:42 +02:00
2024-05-23 18:51:30 +02:00
#### _Golang_ {id="golang_2"}
2024-05-22 21:03:47 +02:00
2024-05-23 18:51:30 +02:00
Modify the /var/ossec/etc/ossec.conf configuration file and add the following:< br / >
2024-05-23 17:32:58 +02:00
2024-05-23 18:51:30 +02:00
*Command section*
2024-05-23 17:32:58 +02:00
2024-05-22 21:03:47 +02:00
```
2024-05-23 17:32:58 +02:00
< command >
< name > wazuh-notify-go< / name >
< executable > wazuh-notify< / executable >
< timeout_allowed > yes< / timeout_allowed >
< / command >
2024-05-22 21:03:47 +02:00
```
2024-05-04 22:24:42 +02:00
2024-05-23 18:51:30 +02:00
*Active response section*
2024-05-23 17:32:58 +02:00
2024-05-22 21:03:47 +02:00
```
2024-05-23 17:32:58 +02:00
< active-response >
< command > wazuh-notify-go< / command >
< location > server< / location >
< level > < / level >
< rules_id > < / rules_id >
< / active-response >
2024-05-22 21:03:47 +02:00
```
2024-05-23 17:32:58 +02:00
2024-05-23 18:51:30 +02:00
#### _Python_ {id="python_2"}
2024-05-23 17:32:58 +02:00
2024-05-23 18:51:30 +02:00
*Command section*
2024-05-23 17:32:58 +02:00
2024-05-04 22:24:42 +02:00
```
2024-05-23 17:32:58 +02:00
< command >
< name > wazuh-notify-py< / name >
< executable > wazuh-notify.py< / executable >
< timeout_allowed > yes< / timeout_allowed >
< / command >
2024-05-04 22:24:42 +02:00
```
2024-05-23 18:51:30 +02:00
*Active response section*
2024-05-23 17:32:58 +02:00
2024-05-04 22:24:42 +02:00
```
2024-05-23 17:32:58 +02:00
< active-response >
< command > wazuh-notify-py< / command >
< location > server< / location >
< level > < / level >
< rules_id > < / rules_id >
< / active-response >
2024-05-04 22:24:42 +02:00
```
2024-05-23 18:51:30 +02:00
#### NOTE:
2024-05-23 17:32:58 +02:00
The ```<name>` `` in the ` ``<command>` `` section needs to be the same as the ` ``<command>` `` in
the ```<active-response>` `` section.
The ```<command>` `` section describes the program that is executed. The ` ``<active-response>` `` section describes the
trigger that runs the ```<command>` ``.
Add the rules you want to be informed about between the ```<rules_id></rules_id>` ``, with the rules id's separated by
comma's.
2024-05-22 21:03:47 +02:00
Example: ```<rules_id>5402, 3461, 8777</rules_id><br/>` ``
2024-05-23 18:51:30 +02:00
(Please refer to the [Wazuh online documentation ](https://documentation.wazuh.com/current/user-manual/capabilities/active-response/index.html ) for more information [^Wazuh docs])
2024-05-04 22:24:42 +02:00
[^Wazuh docs]: https://documentation.wazuh.com/current/user-manual/capabilities/active-response/index.html
2024-05-23 17:32:58 +02:00
## The YAML configuration
2024-05-04 22:24:42 +02:00
2024-05-22 21:03:47 +02:00
This is the yaml config file for wazuh-active-response (for both the Python and Go version)
2024-05-04 22:24:42 +02:00
2024-05-23 17:32:58 +02:00
The targets setting defines the platforms where notifications will be sent to.
Platforms in this comma-separated string will receive notifications.
2024-05-04 22:24:42 +02:00
```
2024-05-23 17:32:58 +02:00
targets: "slack, ntfy, discord"
2024-05-04 22:24:42 +02:00
```
2024-05-23 17:32:58 +02:00
Platforms in this comma-separated string will receive the full event information.
2024-05-04 22:24:42 +02:00
```
2024-05-23 17:32:58 +02:00
full_message: ""
2024-05-04 22:24:42 +02:00
```
2024-05-23 17:32:58 +02:00
Exclude_rules and excluded_agents will disable notification for these particular events or agents that are enabled in
the ossec.conf active response definition.
2024-05-22 21:03:47 +02:00
These settings provide an easier way to disable events from firing. No need to restart Wazuh-manager.
2024-05-23 17:32:58 +02:00
Enter rule numbers as a string with comma-separated values.
Enter numeric agent id's as a string with comma-separated values.
2024-05-22 21:03:47 +02:00
```
2024-05-23 17:32:58 +02:00
excluded_rules: "99999, 00000"
excluded_agents: "99999"
2024-05-22 21:03:47 +02:00
```
2024-05-23 17:32:58 +02:00
There is a mapping from Wazuh threat levels (0-15) to priorities (1-5) in notifications.
https://documentation.wazuh.com/current/user-manual/ruleset/rules-classification.html
Enter the values for the threat_map as lists of integers, mention_thresholds as integers and colors as Hex integers.
The mention_threshold, relates to the number of times a rule has been fired. When the times fired is equal to or greater
than the mention_threshold, the recipient will receive a Discord mention in addition to the normal message.
2024-05-22 21:03:47 +02:00
This is a list notation.
2024-05-23 17:32:58 +02:00
2024-05-22 21:03:47 +02:00
```
priority_map:
- threat_map: [ 15,14,13,12 ]
2024-05-23 17:32:58 +02:00
mention_threshold: 1
color: 0xcc3300
2024-05-22 21:03:47 +02:00
- threat_map: [ 11,10,9 ]
2024-05-23 17:32:58 +02:00
mention_threshold: 1
color: 0xff9966
2024-05-22 21:03:47 +02:00
- threat_map: [ 8,7,6 ]
2024-05-23 17:32:58 +02:00
mention_threshold: 5
color: 0xffcc00
2024-05-22 21:03:47 +02:00
- threat_map: [ 5,4 ]
2024-05-23 17:32:58 +02:00
mention_threshold: 20
color: 0x99cc33
2024-05-22 21:03:47 +02:00
- threat_map: [ 3,2,1,0 ]
2024-05-23 17:32:58 +02:00
mention_threshold: 20
color: 0x339900
2024-05-04 22:24:42 +02:00
```
2024-05-23 17:32:58 +02:00
2024-05-22 21:03:47 +02:00
The next 2 settings are used to add information to the messages.
2024-05-23 17:32:58 +02:00
Sender translate to the ``` username ` `` field in Discord and to the ` ``title` `` field in ntfy.sh. It is not used for
Slack.
Click adds an arbitrary URL to the message.
2024-05-05 14:47:28 +02:00
```
2024-05-22 21:03:47 +02:00
sender: "Wazuh (IDS)"
click: "https://documentation.wazuh.com/"
```
2024-05-23 17:32:58 +02:00
### From here on the settings are ONLY used by the Python version of wazuh-notify.
2024-05-05 14:47:28 +02:00
2024-05-22 21:03:47 +02:00
Below settings provide for a window that enable/disables events from firing the notifiers.
2024-05-05 14:47:28 +02:00
2024-05-22 21:03:47 +02:00
Enter ```excluded_days` `` as a string with comma separated values. Be aware of your regional settings.
2024-05-23 17:32:58 +02:00
2024-05-05 14:47:28 +02:00
```
2024-05-22 21:03:47 +02:00
excluded_days: ""
```
2024-05-23 17:32:58 +02:00
2024-05-22 21:03:47 +02:00
Enter ```excluded_hours` `` as a tuple of string values. Be aware of your regional settings.
2024-05-23 17:32:58 +02:00
2024-05-22 21:03:47 +02:00
```
2024-05-23 17:32:58 +02:00
excluded_hours: [ "23:59", "00:00" ]
2024-05-05 14:47:28 +02:00
```
2024-05-23 17:32:58 +02:00
The following parameters define the markdown characters used to emphasise the parameter names in the notification
messages (Markdown style)
2024-05-22 21:03:47 +02:00
This is a dictionary (object) notation.
2024-05-23 17:32:58 +02:00
2024-05-22 21:03:47 +02:00
```
markdown_emphasis:
slack: "*"
ntfy: "**"
discord: "**"
```
2024-05-05 14:47:28 +02:00
2024-05-23 17:32:58 +02:00
The next settings are used for testing purposes.
Test mode will add an example event (wazuh-notify-test-event.json) instead of the message received through Wazuh.
This enables testing for particular events when the test event is customized.
2024-05-22 21:03:47 +02:00
```
test_mode: False
```
2024-05-23 17:32:58 +02:00
Setting this parameter provides more logging to the wazuh-notifier log. Possible values are
0 (almost no logging),
1 (basic logging) and
2024-05-22 21:03:47 +02:00
2 (verbose logging)
2024-05-23 17:32:58 +02:00
2024-05-22 21:03:47 +02:00
```
extended_logging: 2
```
2024-05-23 17:32:58 +02:00
2024-05-22 21:03:47 +02:00
Enabling this parameter provides extended logging to the console (see extended logging).
2024-05-23 17:32:58 +02:00
2024-05-22 21:03:47 +02:00
```
extended_print: 0
```