wazuh-notify/Writerside/topics/Wazuh-notifier.md

340 lines
10 KiB
Markdown
Raw Normal View History

2024-05-22 21:03:47 +02:00
# Wazuh notify
2024-05-31 17:57:20 +02:00
*version 1.0*
2024-05-04 22:24:42 +02:00
2024-05-31 20:31:59 +02:00
<img alt="Darius-logo-black.svg" src="../../Darius-logo-black.svg" align="left" width="300" height="300"/>
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)
2024-05-31 17:57:20 +02:00
- [Step 1: download](#step-1-download)
- [Step 2: copy files](#step-2-copy-files)
2024-05-23 20:56:21 +02:00
- [Python](#python_1)
- [Golang](#golang_1)
2024-05-31 17:57:20 +02:00
- [Step 3: copy the TOML file](#step-3-copy-the-toml-configuration-file)
- [Step 4: create .env file](#step-4-create-env-file)
- [Wazuh configuration](#wazuh-configuration)
2024-05-23 20:56:21 +02:00
- [Golang](#golang_2)
- [Python](#python_2)
- [Note](#note)
2024-05-31 17:57:20 +02:00
- [The TOML configuration file](#the-toml-configuration)
2024-05-23 20:56:21 +02:00
- [Setting up the platforms](#setting-up-the-platforms-receiving-the-notifications)
2024-05-04 22:24:42 +02:00
2024-05-23 17:32:58 +02:00
## Introduction
2024-05-31 17:57:20 +02:00
Wazuh notifier enables the Wazuh manager to be notified when Wazuh selected events occur, using 3 messaging platforms:
2024-05-23 20:56:21 +02:00
[ntfy.sh](https://ntfy.sh), [Discord](https://discord.com) and [Slack](https://slack.com).
2024-05-23 17:32:58 +02:00
2024-05-31 17:57:20 +02:00
There are 2 implementations of Wazuh notify. One written in Golang, the other in Python. Both implementations have
similar functionality, but the Python version is slightly more configurable for testing purposes.
2024-05-23 17:32:58 +02:00
2024-05-31 17:57:20 +02:00
Wazuh notify is a stateless implementation and only notifies: triggered by specific rules, agents, or threat levels.
2024-05-04 22:24:42 +02:00
2024-05-31 17:57:20 +02:00
Wazuh notify is executed 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
```
2024-05-31 17:57:20 +02:00
### Step 3: copy the TOML configuration file
2024-05-23 17:32:58 +02:00
2024-05-31 17:57:20 +02:00
Copy the TOML file to /var/ossec/etc/
2024-05-23 17:32:58 +02:00
```
2024-05-31 17:57:20 +02:00
$ sudo cp <download folder>/wazuh-notify-config.toml /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-31 17:57:20 +02:00
$ sudo chown root:wazuh /var/ossec/etc/wazuh-notify-config.toml
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-31 17:57:20 +02:00
$ sudo chmod uog+r /var/ossec/etc/wazuh-notify-config.toml
2024-05-04 22:24:42 +02:00
```
2024-05-31 17:57:20 +02:00
### Step 4: create .env file
2024-05-23 17:32:58 +02:00
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-31 17:57:20 +02:00
$ sudo chown root:wazuh /var/ossec/etc/wazuh-notify-config.toml
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-31 17:57:20 +02:00
$ sudo chmod uog+r /var/ossec/etc/wazuh-notify-config.toml
2024-05-04 22:24:42 +02:00
```
2024-05-31 17:57:20 +02:00
## Wazuh 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-31 17:57:20 +02:00
#### NOTE: <format color="OrangeRed">!</format>
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
2024-05-31 17:57:20 +02:00
comma's.
Example: ```<rules_id>5402, 3461, 8777</rules_id>```.
2024-05-23 20:56:21 +02:00
Please refer to
the [Wazuh online documentation](https://documentation.wazuh.com/current/user-manual/capabilities/active-response/index.html)
for more information.
2024-05-04 22:24:42 +02:00
2024-05-31 17:57:20 +02:00
## The TOML configuration
2024-05-04 22:24:42 +02:00
2024-05-31 17:57:20 +02:00
This is the toml configuration file for wazuh-notify (for both the Python and Golang 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.
2024-05-31 17:57:20 +02:00
Platforms in this comma-separated string will receive notifications, if and when they are set up.
Refer to [setting up the platforms](#setting-up-the-platforms-receiving-the-notifications).
2024-05-23 17:32:58 +02:00
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-31 17:57:20 +02:00
full_alert: ""
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-23 19:43:33 +02:00
These settings provide an easier way to disable event notifications 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
2024-05-31 17:57:20 +02:00
[The threat levels used in Wazuh](https://documentation.wazuh.com/current/user-manual/ruleset/rules-classification.html)
(0-15) are mapped to notification priority levels (1-5), and their respective colors (Discord only).
The Wazuh threat level scale runs from 0-15, where 15 is the most severe threat. It corresponds to the
[HSAS](https://en.wikipedia.org/wiki/Homeland_Security_Advisory_System) threat scale that runs from 5-1, whereby 1 is
the highest threat level. The configuration allows for customized mapping: in some use cases the mapping could be different.
2024-05-23 19:43:33 +02:00
2024-05-31 17:57:20 +02:00
The mention threshold defines when Discord users receive a DM, next to the common messages they receive in their channel.
Often these common channels are muted and DM's will draw more attention. 1 means that for every notification a DM will be sent.
A mention threshold of 5 means that for every 5th occurrence of this specific event, a DM will be sent also.
2024-05-23 19:43:33 +02:00
2024-05-31 17:57:20 +02:00
The notify threshold is somewhat similar to the mention threshold. A notify threshold of 1 will send each notification,
a notify threshold of 4 will only send each 4th notification triggered by a specific event. This will reduce high amounts
of notifications for the same event. The fired_times value in the message will show the actual number of the times this
specific event was generated.
2024-05-23 17:32:58 +02:00
2024-05-31 17:57:20 +02:00
Enter a threat_map as a list of integers,
color as a hex RGB color values,
mention/notify_threshold as integers.
2024-05-22 21:03:47 +02:00
```
2024-05-31 17:57:20 +02:00
[[priority_map]] # Priority 1 on the HSAS scale
threat_map = [15, 14, 13, 12] # Wazuh threat levels -> priority 2
color = 0xec3e40 # Red, SEVERE on the HSAS scale
mention_threshold = 1
notify_threshold = 1
[[priority_map]] # Priority 2 on the HSAS scale
threat_map = [11, 10, 9] # Wazuh threat levels -> priority 2
color = 0xff9b2b # Orange, HIGH on the HSAS scale
mention_threshold = 1
notify_threshold = 1
[[priority_map]] # Priority 3 on the HSAS scale
threat_map = [8, 7, 6] # Wazuh threat levels -> priority 3
color = 0xf5d800 # Yellow, ELEVATED on the HSAS scale
mention_threshold = 5
notify_threshold = 5
[[priority_map]] # Priority 4 on the HSAS scale
threat_map = [5, 4] # Wazuh threat levels -> priority 4
color = 0x377fc7 # Blue, GUARDED on the HSAS scale
mention_threshold = 20
notify_threshold = 5
[[priority_map]] # Priority 5 on the HSAS scale
threat_map = [3, 2, 1, 0] # Wazuh threat levels -> priority 5
color = 0x01a465 # Green, LOW on the HSAS scale
mention_threshold = 20
notify_threshold = 1
2024-05-04 22:24:42 +02:00
```
2024-05-23 17:32:58 +02:00
2024-05-31 17:57:20 +02:00
The next settings are used to add information to the messages.
```Sender``` translate to the ``` username ``` field in Discord and Slack and to the ```title``` field in ntfy.sh.
The ```click``` parameter adds an arbitrary URL to the message.
2024-05-23 17:32:58 +02:00
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-31 17:57:20 +02:00
Enter ```excluded_hours``` as a tuple of string values.
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
2024-05-31 17:57:20 +02:00
messages (Markdown style). This is a dictionary 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.
2024-05-31 17:57:20 +02:00
```Test mode``` will add an example event (```wazuh-notify-test-event.json```) instead of the message received through Wazuh.
This enables customization for testing of a particular event.
2024-05-23 17:32:58 +02:00
2024-05-22 21:03:47 +02:00
```
test_mode: False
```
2024-05-23 17:32:58 +02:00
2024-05-31 17:57:20 +02:00
Setting the ```extended_logging``` and ```extended_print``` parameters provides more logging to the wazuh-notifier log
and console. The possible values are:
2024-05-23 17:32:58 +02:00
2024-05-31 17:57:20 +02:00
0-> limited logging
1-> basic logging
2-> verbose logging
2024-05-23 17:32:58 +02:00
2024-05-22 21:03:47 +02:00
```
2024-05-31 17:57:20 +02:00
extended_logging: 2
2024-05-22 21:03:47 +02:00
extended_print: 0
```
2024-05-23 20:56:21 +02:00
2024-05-31 17:57:20 +02:00
### Setting up the platforms receiving the notifications
2024-05-23 20:56:21 +02:00
Each of the 3 platforms make use of webhooks or similar API's. In order to have the right information in the ```.env```
file, please refer to the platform's documentation.
[Slack](https://api.slack.com/) API documentation
[ntfy.sh](https://docs.ntfy.sh/subscribe/api/) API documentation
[ntfy.sh](https://docs.ntfy.sh/examples/) examples
2024-05-31 20:31:59 +02:00
[Discord](https://discord.com/developers/docs/intro) developers documentation