In questa guida tratteremo l’installazione e la configurazione di OSSEC, un Host-based Intrusion Detection System (HIDS), software che si occupa di monitorare e prendere provvedimenti nel caso in cui rilevi un attacco di tipo informatico sul sistema dove viene installato. È disponibile per diversi sistemi operativi, ma in questo articolo vedremo come installarlo su una distribuzione GNU/Linux utilizzata come server, basata su Debian / Ubuntu. Il funzionamento di OSSEC si basa sull’architettura client/server, il client si occupa di analizzare i log di sistema, fare monitoring e controllare l’integrità dei file, rilevare rootkit, inviare e prendere decisioni in tempo reale.

Installazione

Per prima cosa aggiorniamo i pacchetti sul sistema, tramite i comandi:

sudo apt update && sudo apt upgrade -y

Dopodiché installiamo le dipendenze necessarie a compilare OSSEC.
Nota: su Debian 11 dalla 3.6.0 l’installazione fallisce in assenza del pacchetto libsystemd-dev. In questa guida, lo includiamo già nel comando di seguito:

sudo apt install build-essential gcc make unzip sendmail inotify-tools expect libevent-dev libpcre2-dev libz-dev libssl-dev zlib1g-dev libsystemd-dev -y

A questo punto scarichiamo l’ultima versione di OSSEC:

cd /opt
VERSION=$(curl -s https://api.github.com/repos/ossec/ossec-hids/releases/latest  | grep tag_name | cut -d '"' -f 4)
wget https://github.com/ossec/ossec-hids/archive/$VERSION.tar.gz

Estraiamo l’archivio appena scaricato contenente i sorgenti di OSSEC:

tar xvf $VERSION.tar.gz

E avviamo quindi il processo di installazione:

cd ossec-hids-${VERSION}
sudo sh install.sh

Selezioniamo la lingua con la quale configurare OSSEC. Per mantenere uno standard, in questa guida lo installeremo in lingua inglese, ma sentitevi liberi di specificare “it” per la lingua italiana:

(en/br/cn/de/el/es/fr/hu/it/jp/nl/pl/ru/sr/tr) [en]: en

Digitiamo il tasto INVIO:

You are about to start the installation process of the OSSEC HIDS.
You must have a C compiler pre-installed in your system.
- System: Linux www.risposteinformatiche.it 4.15.0-151-generic
- User: root
- Host: www.risposteinformatiche.it
-- Press ENTER to continue or Ctrl-C to abort. --

Digitiamo local e impartiamo INVIO:

1- What kind of installation do you want (server, agent, local, hybrid or help)? local
- Local installation chosen.

Diamo nuovamente INVIO per usare il percorso in cui installare OSSEC predefinito:

 - Choose where to install the OSSEC HIDS [/var/ossec]:
- Installation will be made at /var/ossec ./code>

Rispondiamo alle domande poste dallo script di installazione in base alle nostre esigenze, ad esempio, di default OSSEC ci propone di fargli inviare notifiche via e-mail in base ai controlli che effettua. Potete tranquillamente digitare il vostro indirizzo e-mail, se sul server avete configurato un server SMTP, altrimenti potete digitare un utente locale.

OSSEC fornisce anche una modalità di responso attivo che provvede a prendere decisioni in autonomia in base al rilevamento di attività sospette, per esempio da un indirizzo IP. Attivandola, potrebbe quindi provvedere a bloccarlo in automatico, è anche possibile aggiungere degli indirizzi IP esclusi dal blocco:

3.1- Do you want e-mail notification? (y/n) [y]: y
- What's your e-mail address? root@localhost
- We found your SMTP server as: 127.0.0.1
- Do you want to use it? (y/n) [y]: y
--- Using SMTP server: 127.0.0.1
3.2- Do you want to run the integrity check daemon? (y/n) [y]: y
- Running syscheck (integrity check daemon).
3.3- Do you want to run the rootkit detection engine? (y/n) [y]: y
- Running rootcheck (rootkit detection).
3.4- Active response allows you to execute a specific
command based on the events received. For example,
you can block an IP address or disable access for
a specific user.
More information at:
http://www.ossec.net/en/manual.html#active-response
- Do you want to enable active response? (y/n) [y]: y
- Active response enabled.
- By default, we can enable the host-deny and the
firewall-drop responses. The first one will add
a host to the /etc/hosts.deny and the second one
will block the host on iptables (if linux) or on
ipfilter (if Solaris, FreeBSD or NetBSD).
- They can be used to stop SSHD brute force scans,
portscans and some other forms of attacks. You can
also add them to block on snort events, for example.
- Do you want to enable the firewall-drop response? (y/n) [y]: y
- firewall-drop enabled (local) for levels >= 6
- Default white list for the active response:
- 127.0.0.1
- Do you want to add more IPs to the white list? (y/n)? [n]: n
3.6- Setting the configuration to analyze the following logs:
-- /var/log/auth.log
-- /var/log/syslog
-- /var/log/dpkg.log
- If you want to monitor any other file, just change
the ossec.conf and add a new localfile entry.
Any questions about the configuration can be answered
by visiting us online at http://www.ossec.net .
--- Press ENTER to continue ---

Lasciamogli quindi il tempo di completare l’installazione, alla fine, se tutto sarà andato bene, visualizzeremo:

- System is Debian (Ubuntu or derivative).
- Init script modified to start OSSEC HIDS during boot.
- Configuration finished properly.
- To start OSSEC HIDS:
/var/ossec/bin/ossec-control start
- To stop OSSEC HIDS:
/var/ossec/bin/ossec-control stop
- The configuration can be viewed or modified at /var/ossec/etc/ossec.conf
Thanks for using the OSSEC HIDS.
If you have any question, suggestion or if you find any bug,
contact us at https://github.com/ossec/ossec-hids or using
our public maillist at
https://groups.google.com/forum/#!forum/ossec-list
More information can be found at http://www.ossec.net
--- Press ENTER to finish (maybe more information below). ---

A questo punto avviamo OSSEC tramite:

/var/ossec/bin/ossec-control start

E con questo abbiamo concluso. Nel caso in cui si fossero verificati errori, sarà sufficiente comprendere quale libreria o pacchetto fosse mancante e aggiungerla al sistema tramite apt. Solitamente si tratta di fare una ricerca online o al più di recuperare la documentazione ufficiale disponibile qui per ciò che riguarda l’installazione.