Ricerca nel sito web

Come installare e configurare Tripwire IDS su Debian 10


Su questa pagina

  1. Prerequisiti
  2. Per iniziare
  3. Installa Tripwire
  4. Configura Tripwire
  5. Verifica gli ID di Tripwire
  6. Automatizza il report Tripwire
  7. Conclusione

Tripwire è un sistema di rilevamento delle intrusioni Linux gratuito e open source. Viene utilizzato per rilevare e segnalare eventuali modifiche non autorizzate a file e directory su Linux. Ti invierà anche un avviso via e-mail sui cambiamenti di file/directory. Tripwire funziona confrontando lo stato corrente del filesystem con uno stato di base noto e segnala se rileva eventuali modifiche.

In questo post, ti mostreremo come installare e configurare Tripwire su Debian 10.

Prerequisiti

  • Un server che esegue Debian 10.
  • Sul server è configurata una password di root.

Iniziare

Innanzitutto, aggiorna i pacchetti di sistema alla versione aggiornata eseguendo il seguente comando:

apt-get update -y

Una volta aggiornati tutti i pacchetti, puoi procedere al passaggio successivo.

Installa Tripwire

Per impostazione predefinita, il pacchetto Tripwire è disponibile nel repository predefinito di Debian 10. Puoi installarlo usando il seguente comando:

apt-get install tripwire -y

Durante l'installazione, ti verrà chiesto di selezionare la configurazione della posta elettronica come mostrato di seguito:

Seleziona l'opzione desiderata e premi INVIO. Ti verrà chiesto di impostare un nome di posta di sistema come mostrato di seguito:

Fornisci il tuo nome di posta di sistema e premi INVIO. Ti verrà chiesto di creare la passphrase della chiave del sito come mostrato di seguito:

Seleziona Sì e premi INVIO. Ti verrà chiesto di ricostruire il file di configurazione di Tripwire come mostrato di seguito:

Seleziona Sì e premi INVIO. Ti verrà chiesto di ricostruire il tuo file di policy di Tripwire come mostrato di seguito:

Seleziona Sì e premi INVIO. Ti verrà chiesto di fornire la passphrase della chiave del sito come mostrato di seguito:

Fornisci la tua password e premi INVIO. Ti verrà chiesto di impostare la passphrase della chiave locale come mostrato di seguito:

Fornisci la tua password e premi INVIO. Una volta installato Tripwire, dovresti vedere la seguente schermata:

Fare clic sul pulsante Ok per terminare l'installazione.

Configura Tripwire

Successivamente, dovrai generare le chiavi Tripwire e inizializzare il database. Innanzitutto, cambia la directory in Tripwire ed elenca tutte le chiavi e i file con il seguente comando:

cd /etc/tripwire/
ls

Dovresti vedere il seguente output:

debian10-local.key  site.key  tw.cfg  twcfg.txt  tw.pol  twpol.txt

Successivamente, modifica il file di configurazione di Tripwire e imposta REPORTLEVEL su 4

nano /etc/tripwire/twcfg.txt

Modifica la riga seguente:

REPORTLEVEL   =4

Salva e chiudi il file quando hai finito.

Successivamente, genera un nuovo file di configurazione con il seguente comando:

twadmin -m F -c tw.cfg -S site.key twcfg.txt

Ti verrà chiesto di fornire la passphrase del tuo sito come mostrato di seguito:

Please enter your site passphrase: 
Wrote configuration file: /etc/tripwire/tw.cfg

Successivamente, crea un file twpolmake.pl per ottimizzare la politica di Tripwire.

nano twpolmake.pl

Aggiungi le seguenti righe:

#!/usr/bin/perl
$POLFILE=$ARGV[0];

open(POL,"$POLFILE") or die "open error: $POLFILE" ;
my($myhost,$thost) ;
my($sharp,$tpath,$cond) ;
my($INRULE) = 0 ;

while () {
    chomp;
    if (($thost) = /^HOSTNAME\s*=\s*(.*)\s*;/) {
        $myhost = `hostname` ; chomp($myhost) ;
        if ($thost ne $myhost) {
            $_="HOSTNAME=\"$myhost\";" ;
        }
    }
    elsif ( /^{/ ) {
        $INRULE=1 ;
    }
    elsif ( /^}/ ) {
        $INRULE=0 ;
    }
    elsif ($INRULE == 1 and ($sharp,$tpath,$cond) = /^(\s*\#?\s*)(\/\S+)\b(\s+->\s+.+)$/) {
        $ret = ($sharp =~ s/\#//g) ;
        if ($tpath eq '/sbin/e2fsadm' ) {
            $cond =~ s/;\s+(tune2fs.*)$/; \#$1/ ;
        }
        if (! -s $tpath) {
            $_ = "$sharp#$tpath$cond" if ($ret == 0) ;
        }
        else {
            $_ = "$sharp$tpath$cond" ;
        }
    }
    print "$_\n" ;
}
close(POL) ;

Salva e chiudi il file quindi crea un file di configurazione con il seguente comando:

perl twpolmake.pl twpol.txt > twpol.txt.new 
twadmin -m P -c tw.cfg -p tw.pol -S site.key twpol.txt.new

Dovresti vedere il seguente output:

Please enter your site passphrase: 
Wrote policy file: /etc/tripwire/tw.pol

Successivamente, crea un database Tripwire con il seguente comando:

tripwire -m i -s -c tw.cfg

Dovresti vedere il seguente output:

Please enter your local passphrase: 
### Warning: File system error.
### Filename: /var/lib/tripwire/debian10.twd
### No such file or directory
### Continuing...

È inoltre possibile visualizzare il database generato con il seguente comando:

twprint -m d -d /var/lib/tripwire/debian10.twd

Dovresti vedere il seguente output:

Open Source Tripwire(R) 2.4.3.7 Database

Database generated by:        root
Database generated on:        Sun 09 May 2021 08:39:18 AM UTC
Database last updated on:     Never

===============================================================================
Database Summary: 
===============================================================================

Host name:                    debian10
Host IP address:              45.58.38.142
Host ID:                      None
Policy file used:             /etc/tripwire/tw.pol
Configuration file used:      /etc/tripwire/tw.cfg
Database file used:           /var/lib/tripwire/debian10.twd
Command line used:            tripwire -m i -s -c tw.cfg 

===============================================================================
Object Summary: 
===============================================================================

-------------------------------------------------------------------------------
# Section: Unix File System
-------------------------------------------------------------------------------

Se vuoi aggiornare il database di Tripwire, esegui il seguente comando:

tripwire --update --accept-all

Dovresti ottenere il seguente output:

### Error: File could not be opened.
### Filename: /var/lib/tripwire/report/debian10-20210509-084141.twr
### No such file or directory
### Exiting...

Ora, prova il Tripwire usando il seguente comando:

tripwire -m c -s -c /etc/tripwire/tw.cfg

Dovresti vedere il seguente output:

Open Source Tripwire(R) 2.4.3.7 Integrity Check Report

Report generated by:          root
Report created on:            Sun 09 May 2021 08:42:15 AM UTC
Database last updated on:     Never

===============================================================================
Report Summary:
===============================================================================

Host name:                    debian10
Host IP address:              45.58.38.142
Host ID:                      None
Policy file used:             /etc/tripwire/tw.pol
Configuration file used:      /etc/tripwire/tw.cfg
Database file used:           /var/lib/tripwire/debian10.twd
Command line used:            tripwire -m c -s -c /etc/tripwire/tw.cfg 

===============================================================================
Rule Summary: 
===============================================================================

-------------------------------------------------------------------------------
  Section: Unix File System
-------------------------------------------------------------------------------

  Rule Name                       Severity Level    Added    Removed  Modified 
  ---------                       --------------    -----    -------  -------- 
  Other binaries                  66                0        0        0        
  Tripwire Binaries               100               0        0        0        
  Other libraries                 66                0        0        0        
  Root file-system executables    100               0        0        0        
* Tripwire Data Files             100               1        0        0        
  System boot changes             100               0        0        0        
  Root file-system libraries      100               0        0        0        
  (/lib)
  Critical system boot files      100               0        0        0        
* Other configuration files       66                0        0        1        
  (/etc)
  Boot Scripts                    100               0        0        0        
  Security Control                66                0        0        0        
  Root config files               100               0        0        0        
  Devices & Kernel information    100               0        0        0        
  (/dev)
  Invariant Directories           66                0        0        0        

Total objects scanned:  27975
Total violations found:  2

===============================================================================
Object Summary: 
===============================================================================

-------------------------------------------------------------------------------
# Section: Unix File System
-------------------------------------------------------------------------------

-------------------------------------------------------------------------------
Rule Name: Tripwire Data Files (/var/lib/tripwire/debian10.twd)
Severity Level: 100
-------------------------------------------------------------------------------

Per impostazione predefinita, i file di report di Tripwire si trovano in /var/lib/tripwire/report/:

ls /var/lib/tripwire/report/

Produzione:

debian10-20210509-084215.twr

Puoi controllare questo rapporto usando il seguente comando:

twprint -m r -t 4 -r /var/lib/tripwire/report/debian10-20210509-084215.twr

Verifica gli ID di Tripwire

A questo punto, Tripwire è installato e configurato. Ora è il momento di verificare se Tripwire funziona o meno.

Innanzitutto, crea alcuni file nel tuo sistema con il seguente comando:

touch fil1 file2 file3 file4 file5

Ora, esegui Tripwire per verificare se Tripwire rileva o meno questi file:

tripwire --check --interactive

Dovresti vedere i file appena creati nel seguente output:

Open Source Tripwire(R) 2.4.3.7 Integrity Check Report

Report generated by:          root
Report created on:            Sun 09 May 2021 08:46:36 AM UTC
Database last updated on:     Never

===============================================================================
Report Summary:
===============================================================================

Host name:                    debian10
Host IP address:              45.58.38.142
Host ID:                      None
Policy file used:             /etc/tripwire/tw.pol
Configuration file used:      /etc/tripwire/tw.cfg
Database file used:           /var/lib/tripwire/debian10.twd
Command line used:            tripwire --check --interactive

===============================================================================
-------------------------------------------------------------------------------
Rule Name: Other configuration files (/etc)
Severity Level: 66
-------------------------------------------------------------------------------

Remove the "x" from the adjacent box to prevent updating the database
with the new values for this object.

Modified:
[x] "/etc/tripwire"

-------------------------------------------------------------------------------
Rule Name: Root config files (/root)
Severity Level: 100
-------------------------------------------------------------------------------

Remove the "x" from the adjacent box to prevent updating the database
with the new values for this object.

Added:
[x] "/root/file4"
[x] "/root/file3"
[x] "/root/fil1"
[x] "/root/file2"
[x] "/root/file5"

Modified:
[x] "/root"

===============================================================================

Puoi anche controllare il rapporto generato in un secondo momento usando il seguente comando:

twprint --print-report --twrfile /var/lib/tripwire/report/debian10-20210509-084636.twr

Automatizza il report Tripwire

Puoi anche impostare un cron job per eseguire un Tripwire in un momento specifico. Puoi farlo con il seguente comando:

crontab -e

Aggiungi le seguenti righe:

00 06 * * * /usr/sbin/tripwire --check

Salva e chiudi il file quando hai finito.

Il file sopra eseguirà un Tripwire ogni mattina alle 06:00. Puoi controllare il report generato in /var/lib/tripwire/report/.

Conclusione

Congratulazioni! hai installato e configurato con successo Tripwire IDS su Debian 10. Spero che questo ti aiuti a controllare quali file o directory sono stati modificati sul tuo sistema.