Install and Setup Wazuh Server in CentOS 8/Fedora 32

0
2504

In this tutorial, you will learn how to install and setup Wazuh server in CentOS 8/Fedora 32. Wazuh is an open-source tool for visibility, security detection, and compliance. It is a fork of OSSEC HIDS with additional integration with ELK stack and OpenSCAP. The Wazuh stack consists of the Wazuh server (manager), the ELK stack, and the Wazuh agents as shown in the image below.

Install and Setup Wazuh Server in CentOS 8/Fedora 32

As of this writing, the current version is 4.1.

Install and Setup Wazuh Server in CentOS 8/Fedora 32

The Wazuh server has the primary functions of agent registration, data analysis, and managing of agents.

Deployment Architecture

There are two different deployment architectures for Wazuh server;

  • All-in-one: The Wazuh server and Elastic Stack are installed on the same host.
  • Distributed: Each component is installed on a separate host as a single-node or multi-node cluster. This type of deployment provides high availability and scalability of the product, and it is convenient for large working environments.

In this tutorial, we will use the All-in-one deployment architecture.

System Requirements

Consult the documentation for the recommended system requirements.

Install and Setup Wazuh Server in CentOS 8/Fedora 32

Add Wazuh to repository

You first have to add Wazuh repository to the server by running the command below.

cat > /etc/yum.repos.d/wazuh.repo << 'EOL'
[wazuh_repo]
gpgcheck=1
gpgkey=https://packages.wazuh.com/key/GPG-KEY-WAZUH
enabled=1
name=Wazuh repository
baseurl=https://packages.wazuh.com/4.x/yum/
protect=1
EOL

Import the Wazuh repository GPG key

rpm --import https://packages.wazuh.com/key/GPG-KEY-WAZUH

Install Wazuh Server on CentOS 8/Fedora 32

Run the following command to install wazuh server. on CentOS 8/Fedora 32

dnf -y install wazuh-manager

When the installation process is complete, start Wazuh Manager.

systemctl start wazuh-manager

You can check the status as shown below;

systemctl status wazuh-manager
● wazuh-manager.service - Wazuh manager
   Loaded: loaded (/usr/lib/systemd/system/wazuh-manager.service; disabled; vendor preset: disabled)
   Active: active (running) since Sat 2021-07-10 09:40:01 EAT; 4min 33s ago
  Process: 2847 ExecStart=/usr/bin/env ${DIRECTORY}/bin/ossec-control start (code=exited, status=0/SUCCESS)
    Tasks: 104 (limit: 11388)
   Memory: 522.8M
   CGroup: /system.slice/wazuh-manager.service
           ├─2902 /var/ossec/framework/python/bin/python3 /var/ossec/api/scripts/wazuh-apid.py
           ├─2944 /var/ossec/bin/ossec-authd
           ├─2960 /var/ossec/bin/wazuh-db
           ├─2984 /var/ossec/bin/ossec-execd
           ├─2999 /var/ossec/bin/ossec-analysisd
           ├─3043 /var/ossec/bin/ossec-syscheckd
           ├─3060 /var/ossec/bin/ossec-remoted
           ├─3087 /var/ossec/bin/ossec-logcollector
           ├─3097 /var/ossec/bin/ossec-monitord
           └─3107 /var/ossec/bin/wazuh-modulesd

Jul 10 09:39:53 localhost.localdomain env[2847]: Started wazuh-db...
Jul 10 09:39:54 localhost.localdomain env[2847]: Started ossec-execd...
Jul 10 09:39:55 localhost.localdomain env[2847]: Started ossec-analysisd...
Jul 10 09:39:56 localhost.localdomain env[2847]: Started ossec-syscheckd...
Jul 10 09:39:58 localhost.localdomain env[2847]: Started ossec-remoted...
Jul 10 09:39:58 localhost.localdomain env[2847]: Started ossec-logcollector...
Jul 10 09:39:58 localhost.localdomain env[2847]: Started ossec-monitord...
Jul 10 09:39:59 localhost.localdomain env[2847]: Started wazuh-modulesd...
Jul 10 09:40:01 localhost.localdomain env[2847]: Completed.
Jul 10 09:40:01 localhost.localdomain systemd[1]: Started Wazuh manager.

To avoid issues on version control and updates, it is recommended you disable the repository.

 sed -i "s/enabled=1/enabled=0/" /etc/yum.repos.d/wazuh.repo

Install Elastic Stack on CentOS 8/Fedora 32

Next, you need to install Elasticsearch, Kibana, Filebeat and Wazuh APP to get the most out of Wazuh-manager.

Before you can proceed, you need to ensure that the Elastic components being installed are compatible with the version of Wazuh-manager installed.

In this demo, Wazuh-manager 4.1.5 is installed:

rpm -qa wazuh-manager
wazuh-manager-4.1.5-1.x86_64

Based on the Wazuh compatibility matrix, Wazuh 4.1.5 is compatible with Elastic 7.11.2, as of this writing.

Create Elastic Repository

cat > /etc/yum.repos.d/elasticstack.repo << EOL
[elasticsearch]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
EOL

Install Elasticsearch, Kibana and Filebeat

Based on the compatibility matrix for Wazuh 4.1.5, install Elasticsearch 7.11.2, Kibana 7.11.2 and Filebeat 7.11.2 by running the command below;

dnf install elasticsearch-7.11.2 kibana-7.11.2 filebeat-7.11.2

Sample output;

Dependencies resolved.
============================================================================================================================================================================
 Package                                     Architecture                         Version                                 Repository                                   Size
============================================================================================================================================================================
Installing:
 elasticsearch                               x86_64                               7.11.2-1                                elasticsearch                               308 M
 filebeat                                    x86_64                               7.11.2-1                                elasticsearch                                33 M
 kibana                                      x86_64                               7.11.2-1                                elasticsearch                               244 M

Transaction Summary
============================================================================================================================================================================
Install  3 Packages

Total download size: 584 M
Installed size: 1.2 G
Is this ok [y/N]: y

Configuring Elasticsearch

There are only a few changes we are going to make in regards to configuring Elasticsearch.

You can optionally set the Elastic cluster name;

sed -i 's/#cluster.name: my-application/cluster.name: wazuh-elastic/' /etc/elasticsearch/elasticsearch.yml

Next, configure JVM heap size to no more than half the size of your memory. In this case, our test server has 2G RAM and the heap size is set to 512M for both maximum and minimum sizes.

sed -i -e '/4g/s/^## //' -e '/4g/s//512m/' /etc/elasticsearch/jvm.options

The config now looks like;

...
################################################################

# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space

-Xms512m
-Xmx512m
...

Start and enable ES to run on system boot.

systemctl daemon-reload
systemctl enable --now elasticsearch

Verify that Elasticsearch is running as expected.

curl -XGET localhost:9200
{
  "name" : "localhost.localdomain",
  "cluster_name" : "wazuh-elastic",
  "cluster_uuid" : "G-GICWOxRH6U0y-MJ5omaw",
  "version" : {
    "number" : "7.11.2",
    "build_flavor" : "default",
    "build_type" : "rpm",
    "build_hash" : "3e5a16cfec50876d20ea77b075070932c6464c7d",
    "build_date" : "2021-03-06T05:54:38.141101Z",
    "build_snapshot" : false,
    "lucene_version" : "8.7.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

Configure Filebeat

Create a backup of the Filebeat configuration file.

mv /etc/filebeat/filebeat.yml{,.original}

In our setup, we use the Filebeat configuration file below. You can configure it to your liking.

cat > /etc/filebeat/filebeat.yml << 'EOL'
# Wazuh - Filebeat configuration file
output.elasticsearch:
  hosts: ["localhost:9200"]
setup.template.json.enabled: true
setup.template.json.path: '/etc/filebeat/wazuh-template.json'
setup.template.json.name: 'wazuh'
setup.ilm.overwrite: true
setup.ilm.enabled: false

filebeat.modules:
  - module: wazuh
    alerts:
      enabled: true
    archives:
      enabled: false
      
logging.level: info
logging.to_files: true
logging.files:
  path: /var/log/filebeat
  name: filebeat
  keepfiles: 7
  permissions: 0644
EOL

Then download the alerts template for ELK

curl -so /etc/filebeat/wazuh-template.json https://raw.githubusercontent.com/wazuh/wazuh/4.1/extensions/elasticsearch/7.x/wazuh-template.json
chmod go+r /etc/filebeat/wazuh-template.json

Test Filebeat connection to Elasticsearch

filebeat test output

Sample output;

elasticsearch: http://localhost:9200...
  parse url... OK
  connection...
    parse host... OK
    dns lookup... OK
    addresses: ::1, 127.0.0.1
    dial up... OK
  TLS... WARN secure connection disabled
  talk to server... OK
  version: 7.11.2

Install the Wazuh module for Filebeat:

curl -s https://packages.wazuh.com/4.x/filebeat/wazuh-filebeat-0.1.tar.gz | tar -xz -C /usr/share/filebeat/module

Start and enable Filebeat to run on system boot;

systemctl daemon-reload
systemctl enable --now filebeat

Filebeat will write logs to /var/log/filebeat/ just in case you need to check something.

Configure Kibana

Define the address to which the Kibana server will bind. By IP addresses and host names are both valid values. localhost is the default value.

In my case, the IP address of my Wazuh server is 192.168.56.145. Hence, I will configure Kibana to listen on this address.

sed -i -e '/server.host:/s/^#//' -e '/server.host:/s/localhost/192.168.56.145/' /etc/kibana/kibana.yml

Install Wazuh App Kibana Plugin

mkdir /usr/share/kibana/data
chown -R kibana: /usr/share/kibana/data
chown -R kibana: /usr/share/kibana/plugins

Before you download and install the plugin, get the tag for your specific version of Wazuh;

sudo -u kibana /usr/share/kibana/bin/kibana-plugin install https://packages.wazuh.com/4.x/ui/kibana/wazuh_kibana-4.1.5_7.11.2-1.zip

You can list installed plugins;

sudo -u kibana /usr/share/kibana/bin/kibana-plugin list

Output;

[email protected]

Start Kibana;

systemctl enable --now kibana

Restart Elasticsearch and Wazuh manager;

systemctl restart elasticsearch wazuh-manager

Open Ports on Firewall

Read about Wazuh Server ports on Required Wazuh Ports page.

You need to allow some ports on firewall. These include;

  • 5601/tcp for external access to Kibana
  • 1514/udp/tcp to allow collection of events from agents (when configured for UDP, TCP is used by default).
  • 1515/udp for Agents registration service
firewall-cmd --add-port=5601/tcp --permanent
firewall-cmd --add-port={1514,1515}/udp --permanent
firewall-cmd --add-port={1514,1515}/tcp --permanent

Then reload the firewall

firewall-cmd --reload

Accessing Kibana Web Interface

You can now access Kibana web interface via the address http://server-IP-or-hostname:5601.

Install and Setup Wazuh Server in CentOS 8/Fedora 32

Wazuh App dashboard

Install and Setup Wazuh Server in CentOS 8/Fedora 32

In the next section, we will learn how to push event data/logs to Elasticsearch via the Wazuh agents.

Sending Events/Data to Wazuh Server using Wazuh Agents

Wazuh agents can be installed on client servers or workstations from which logs are collected. Agents are available for both Windows and UNIX systems.

Install Wazuh Agent on CentOS 8/Fedora 32

In this tutorial, we are going to install the Wazuh agent in another CentOS 8 server acting at the end point from which we are collecting logs.

Create the Wazuh Repository

Copy and paste the following content to add Wazuh repository on a CentOS 8 agent.

rpm --import http://packages.wazuh.com/key/GPG-KEY-WAZUH
cat > /etc/yum.repos.d/wazuh.repo <<\EOF 
[wazuh_repo] 
gpgcheck=1 
gpgkey=https://packages.wazuh.com/key/GPG-KEY-WAZUH 
enabled=1 
name=Wazuh repository 
baseurl=https://packages.wazuh.com/4.x/yum/ 
protect=1 
EOF
Install Wazuh Agents on CentOS 8/Fedora 32

Once the repos are in place, you can install Wazuh agent by running the command below;

dnf -y install wazuh-agent

The installation is now complete. The next step is to enable the agent to communicate with the manager.

Add Wazuh Agent on Wazuh Server

On Wazuh manager, run the command:

/var/ossec/bin/manage_agents

Select add an agent (A) and press enter.

Wazuh v4.1.5 Agent manager. *
The following options are available: *

(A)dd an agent (A).
(E)xtract key for an agent (E).
(L)ist already added agents (L).
(R)emove an agent (R).
(Q)uit.
Choose your action: A,E,L,R or Q: A

Provide a name for the agent(in our case RHAgent) and IP of the agent and confirm.

Note the ID given to the agent.

Adding a new agent (use '\q' to return to the main menu).
Please provide the following:
A name for the new agent: RHAgent
The IP Address of the new agent: 192.168.56.130
Confirm adding it?(y/n): y
Agent added with ID 002.
Extract Wazuh Agent Key

For an agent to communicate with the manager, the agent needs a key. Proceed to extract agent key by typing E.Select the ID of the Agent (002 in this case).

Choose your action: A,E,L,R or Q: E
Available agents:
ID: 001, Name: centos8, IP: 192.168.56.103
ID: 002, Name: RHAgent, IP: 192.168.56.130
Provide the ID of the agent to extract the key (or '\q' to quit): 002
Agent key information for '002' is:
MDAyIFJIQWdlbnQgMTkyLjE2OC41Ni4xMzAgMzFjNTVjOGNiMzU2YmJkOTcyYzE2YjVhMDZiNzNkMGNmYTFhYmJlYWM4OTZmMGE0OWY3NzdjNjEwNTJiMGZjMQ==

Copy the key and paste it in an accessible place as we will be using in the next step.

Set the Wazuh Server Address on Wazuh Agent

On the agent, edit the file /var/ossec/etc/ossec.conf and add the Wazuh manager IP/resolvable hostname.

vim /var/ossec/etc/ossec.conf
... 
<server>
      <address>192.168.56.145</address>
      <port>1514</port>
      <protocol>udp</protocol>
    </server>
...

Save and quit

Navigate to /var/ossec/bin and run manage_agents script to import the agent key.

/var/ossec/bin/manage_agents

Press I to import the key previously generated from the manager.

Provide the Key generated by the server.
The best approach is to cut and paste it.
*** OBS: Do not include spaces or new lines.
Paste it here (or '\q' to quit): PASTE THE AGENT KEY HERE
Agent information:
ID:002
Name:RHAgent
IP Address:192.168.56.130
Confirm adding it?(y/n): y
Added.

Quit and restart the agent.

/var/ossec/bin/ossec-control restart
Verify Agent Data Reception on Kibana

The agent registration is complete. Let us check its data from the Wazuh module in Kibana.

Install and Setup Wazuh Server in CentOS 8/Fedora 32

Navigate to Wazuh>Modules>Security Events to view security related events and dashboards.

Install and Setup Wazuh Server in CentOS 8/Fedora 32

You can explore more on the modules such as Auditing and Policy Monitoring,Regulatory Compliance and Threat Detection and Response.

That marks the end of our tutorial on how to Install and setup Wazuh Server in CentOS 8/Fedora 32.

Further Reading

Installing Wazuh Server on CentOS

Related Tutorials

Install OSSEC Agent on CentOS 8

Installing ELK Stack on CentOS 8

Install Elastic Stack 7 on Fedora 30/Fedora 29/CentOS 7

LEAVE A REPLY

Please enter your comment!
Please enter your name here