Wazuh training for security engineers

1

Introduction

2

wazuh


_images/Wazuhlogo.png
3

What is Wazuh?

  • A situational awareness tool for your electronic assets
  • An important resource for achieving regulatory security compliance

Main Components

  • Log Collection
  • Log Analysis (customizable set of over 4000 HIDS rules)
  • File Integrity Monitoring
  • Host-based anomaly detection
  • Security compliance scanning for known vulnerabilities
  • Real time alerting (e-mail, SMS, Slack, etc)
  • Active Response (a HIDS-driven IPS implementation)
4

Agents available for many diverse platforms

5

Wazuh Architecture

6

Wazuh Architecture

_images/wazuh_architecture.png
7

Main Components

_images/main_components.svg
8

Wazuh Processes

Each process is executed with limited privileges.

  • Processes are run in a chroot environment where feasible.
  • Processes are executed as unprivileged users where feasible.

Wazuh processes on Linux systems are controlled using the relevant tool (i.e. systemctl, service, initctl)

C:\Program Files (x86)\ossec-agent\win32ui.exe is the Windows management tool for controlling the Wazuh service on Windows agents.

9

Network Communications

_images/network_communications.svg











10

Wazuh Secure Communication

It is still wise to limit access to the central components since:

  • It centralizes priviledged security information of all monitored assets.
  • It can trigger Active Responses or other remote commands if enabled.
11

Flood Protection

_images/leaky_bucket.svg

12

Flood Scenario

_images/flood_scenario.png
13

Lab Exercise Set

Lab Exercise 1A: Wazuh server Configuration

Lab Objective:Do some basic configuration of the Wazuh Manager and authenticate with and query the Wazuh API for the first time.

Lab Exercise 1B: Wazuh Web UI

Lab Objective:Briefly explore the Wazuh dashboard.
14

Agent Registration

15

Authd Registration Service

16

Agent Initiating Registration

  1. Agent auto-enrollment (default)
  2. Using agent-auth tool
  3. With agent installer via deployment variables
  4. Requesting registration directly from Wazuh API (rare)
17

Lab Exercise Set

Lab Exercise 1C: Auto enrollment

Lab Objective:Register your linux-agent with your Wazuh manager using auto enrollment.

Lab Exercise 1D: Deployment Variables

Lab Objective:Install and register your windows-agent with deployment variables.

Lab Exercise 1E: Agent-auth tool

Lab Objective:Register your indexer agent with the agent-auth tool.
18

Remotely upgrading Wazuh Agents

19

Ways to remotely upgrade Wazuh agents

Instead of manually upgrading Wazuh directly on agent systems, or using yum/apt repositories you can push Wazuh agent upgrades out from your Wazuh managers to connected agents, even to remote ones.

20

Lab Exercise

Lab Exercise 1F: Agent remote upgrade

Lab Objective:

From the Wazuh Manager, push an upgrade to the outdated Wazuh Agent on the indexer system.

Do this with the Wazuh API both through the command line and the web interface’s API Console.

21

General Configuration

22

ossec.conf

23

internal_options.conf

Low-level config file for managers and agents

24

Agent Configuration

25

Agent groups and profiles

Important tools for organizing the different configuration setting you will need use on different groups/types of agents.

  • agent groups
  • configuration profiles
26

Agent groups and profiles

In an agent’s ossec.conf, the <config-profile> line can include multiple profiles:

Example ossec.conf on agent
<client>
    <config-profile>amzn,amzn2,indexer</config-profile>
    <server>
      <address>wazuh-manager.company.com</address>
    </server>
</client>
Example agent.conf on manager (in sca agent group)
<agent_config profile="amzn">
  <sca>
    <policies>
      <policy>cis_amazon_linux_2.yml</policy>
    </policies>
  </sca>
</agent_config>
27

Agent.conf large example

agent.conf (on manager)
<agent_config>
  ...
</agent_config>

<agent_config os="Linux">
  ...
</agent_config>

<agent_config os="Windows">
  ...
</agent_config>

<agent_config profile="indexer">
  ...
</agent_config>

<agent_config name="linux-agentX5">
  ...
</agent_config>
28

Lab Exercise

Lab Exercise 1G - Centralized agent configuration

Lab Objective:Configure two agent groups, each with a multi-level agent.conf. Confirm agents are getting and using the config content relevant to them within their group.
29

Mass deployment discussion

  • Map out necessary agent groups
  • If desired prepare a custom local agent configuration
  • Additional software to be installed alongside Wazuh
  • Supply custom configurations (SCA, Active Response, etc.)
  • If remote commands are desired adjust internal configuration files
30

Log Analysis

31

Log Analysis with Wazuh

Wazuh’s log analysis engine is capable of:

  • extracting important fields from a log message
  • identifying & evaluating the content of a log message
  • categorizing it by matching specific rules
  • and consequently generating an alert from it.
32

Log Flow

_images/network_communications.svg











  • wazuh-logcollector on the agent collects the logs
  • wazuh-analysisd on the manager analyzes the log entries
  • wazuh-maild sends out alerts
  • wazuh-execd used for Active Response
33

Stages of Log Analysis

34

Example <localfile> sections

Collecting a file, a Windows EventChannel and a set of files by using a wildcard:

<localfile>
   <log_format>syslog</log_format>
   <location>/var/log/messages</location>
</localfile>
<localfile>
  <log_format>eventchannel</log_format>
  <location>Application</location>
</localfile>
<localfile>
  <log_format>json</log_format>
  <location>/var/log/suricata/eve-*.json</location>
  <label key="@source">suricata</label>
</localfile>
35

Command type <localfile> sections

Configuration to collect the output of a command:

<localfile>
   <log_format>full_command</log_format>
   <command>netstat -natp | grep '^tcp .*LISTEN ' | sort | sed 's/LISTEN \+[0-9]\+\///g'
   | grep -v "127.0.0.1:" | awk '{print $4"\t"$6}'</command>
   <frequency>300</frequency>
   <alias>netstat listening ports</alias>
</localfile>
<rule id="533" level="7">
  <if_sid>530</if_sid>
  <match>ossec: output: 'netstat listening ports</match>
  <check_diff />
  <description>Listened ports status (netstat) changed (new port opened or closed).
  </description>
  <group>pci_dss_10.2.7,pci_dss_10.6.1,gpg13_10.1,gdpr_IV_35.7.d,hipaa_164.312.b,
  nist_800_53_AU.14,nist_800_53_AU.6,tsc_CC6.8,tsc_CC7.2,tsc_CC7.3,</group>
</rule>
36

Various log samples

pam / squid / apache log samples

2016-03-15T15:22:10.078830+01:00 tron su:pam_unix(su-l:auth)
:authentication  failure;logname=tm uid=500 euid=0 tty=pts/0
ruser=tm rhost= user=root
1265939281.764 1 172.16.167.228 TCP_DENIED/403 734 POST
"http://lbcore1.metacafe.com/test/SystemInfoManager.php"
- NONE/- text/html
[Sun Mar 06 08:52:16 2016] [error] [client 187.172.181.57]
Invalid URI in request GET: index.php HTTP/1.0
37

Example 1/2

Log:

Dec  5 00:08:49 manager6 sshd[25467]: Failed password for root from
113.195.145.13 port 19044 ssh2

Pre-decoding :

hostname: manager6
program_name: sshd
log: Failed password for root from 113.195.145.13 port 19044 ssh2
38

Example 2/2

Log:

Dec  5 00:08:49 manager6 sshd[25467]: Failed password for root from
113.195.145.13 port 19044 ssh2

Decoding :

decoder: sshd
dstuser: root
srcip: 113.195.145.13
srcport: 19044
39

Logging alerts to alerts.json

{"timestamp":"2020-12-07T21:44:37.313+0000","rule":{"level":5,
"description":"sshd: Reverse lookup error (bad ISP or attack).
","id":"5702","firedtimes":58,"mail":false,"groups":["syslog"
,"sshd"],"pci_dss":["11.4"],"gpg13":["4.12"],"gdpr":
["IV_35.7.d"],"nist_800_53":["SI.4"],"tsc":["CC6.1","CC6.8",
"CC7.2","CC7.3"]},"agent":{"id":"000","name":"manager1"},
"manager":{"name":"manager1"},"id":"1607377477.3731351",
"cluster":{"name":"wazuh","node":"master"},"full_log":"Dec
7 21:44:37 ip-10-0-1-1 sshd[22566]: reverse mapping checking
getaddrinfo for 190.202.147.253.estatic.cantv.net [190.202.147.253]
failed - POSSIBLE BREAK-IN ATTEMPT!","predecoder":
{"program_name":"sshd","timestamp":"Dec  7 21:44:37","hostname"
:"ip-10-0-1-1"},"decoder":{"parent":"sshd","name":"sshd"},"data"
:{"srcip":"190.202.147.253"},"location":"/var/log/secure"}
40

Logging alerts/events to archives.json

{"timestamp":"2017-12-05T02:51:36+0000","rule":{},"agent":{"id":"000"
,"name":"manager6"},"manager":{"name":"manager6"},"id":"1512442296.
149532","full_log":"Dec  5 02:51:35 manager6 sshd[382]: Disconnected
from 113.195.145.13 port 48727 [preauth]","predecoder":{"program_name"
:sshd","hostname":"manager6"},"decoder":{"name":"sshd"},"location":
"/var/log/secure"}
41

Log retention considerations

Considerations regarding alerts.json and archives.json

  • These files are rotated and compressed daily by default.
  • They accumulate indefinitely unless you add a process to delete old files.
  • Sample cron one-liner to daily remove 7+ day old rotated files:
0 2 * * * root find /var/ossec/logs/{alerts,archives} -mtime +7 -exec rm {} \;
  • The archives.json file contains both alerts and non alerting events.
  • To split the routing of archives.json across multiple index patterns, the Wazuh Filebeat module must be customized.
  • Rotated files can be used to reinject one or more past day’s worth of alerts.json or archives.json files back to the Wazuh indexer. See: https://wazuh.com/blog/recover-your-data-using-wazuh-alert-backups/
42

Log Analysis and Regulatory Compliance

  • Computer-aided log analysis is a powerful tool for identifying threats or potential problems within a vast stream of collected log events.
  • Many regulatory compliance requirements call for regular review of security logs.
    • This is generally not feasible nor sustainable without the aid of machine analysis and categorization.
  • It can also help classify which events need to be stored in order to comply with regulatory requirements.
    • This translates to reduced storage costs.
43

Why analyze logs?

_images/PCI.png _images/GDPR.png _images/NIST.png
_images/SOX.png _images/SOC2.png _images/HIPAA.png
_images/FIS.png _images/ISO.svg  
44

Compliance mapping in Wazuh rules

PCI-tagged Wazuh rule :

<rule id="5402" level="3">
 <if_sid>5400</if_sid>
 <regex> ; USER=root ; COMMAND=| ; USER=root ; TSID=\S+ ; COMMAND=</regex>
 <description>Successful sudo to ROOT executed.</description>
 <group>pci_dss_10.2.5,pci_dss_10.2.2,gpg13_7.6,gpg13_7.8,gpg13_7.13,
 gdpr_IV_32.2,hipaa_164.312.b,nist_800_53_AU.14,nist_800_53_AC.7
 nist_800_53_AC.6,</group>
</rule>
45

Lab Exercise Set

Lab Exercise 2A: Generate a brute-force attack

Lab Objective:Repeatedly attempt to use a wrong password with an agent. Monitor the alerts.log, watching for the generation of the brute-force alert.

Lab Exercise 2B: Log Analysis

Lab Objective:Analyze the log entries resulting from the previous exercise. What is shown and what does it mean? How can you distinguish an attack from a harmless log event?

Lab Exercise 2C: Looking up rules

Lab Objective:Looking up and tracing Wazuh rules for better understanding of alerts.
46

Wazuh indexer, dashboard and Filebeat

_images/Indexer.svg
The Wazuh indexer is a highly scalable full-text search and analytics engine, that receives data shipped by Filebeat, indexes it and allows the Wazuh dashboard
access as its primary data source. It is a version of OpenSearch built and maintained by the Wazuh team.
_images/Dashboard.svg
The Wazuh dashboard is the web front-end to the data in the Wazuh indexer. This customized package forked from OpenSearch dashboards includes the Wazuh plugin which on top of solution specific dashboards interacts with the Wazuh API to provide visibility and control over the solution’s configuration and status.
_images/beats.png
Beats is a family of data shippers. Using Filebeat specifically, Wazuh’s alerts.json or archives.json data can be sent to the Wazuh indexer. It also can do data transformation and enrichment, like parsing strings, normalizing field names, and doing geoip lookups.
47

Wazuh indexer, dashboard and Filebeat

_images/indexer_integration.svg
48

Indexer and dashboards integration demo

49

Considerations for the Wazuh indexer

Considerations regarding the Wazuh indexer

50

Questions

51