Utilizzare Snort

Se non avete installato Snort, potete leggere questo nostro articolo su come installarlo su Raspberry Pi.

Se lo avete installato con il comando

apt-get install snort

Allora vi basta diminuire solamente il numero di max_tcp e lanciare il comando (vedi sotto)

snort -dev -l ./log -h 192.168.1.0/24 -c /etc/snort/snort.conf

Se lo avete installato compilando i sorgenti invece, la questione diventa più briosa in quanto occorre settare bene lo snort.config come di seguito.

Una volta installato occorre però aggiornarlo.

Seguiamo quindi i passi che ci dice la guida ufficiale su Snort.org allo Step 3:

0. Creare se non esistono le directory
root@kali:~/tmp# mkdir /etc/snort
root@kali:~/tmp# mkdir /etc/snort/rules
1. Community Rules
wget https://www.snort.org/rules/community
tar -xvfz community.tar.gz -C /etc/snort/rules
2. Registered Rules
wget https://www.snort.org/rules/snortrules-snapshot-2962.tar.gz?oinkcode=
wget https://www.snort.org/rules/snortrules-snapshot-2970.tar.gz?oinkcode=
wget https://www.snort.org/rules/snortrules-snapshot-2972.tar.gz?oinkcode=
tar -xvfz snortrules-snapshot-.tar.gz -C /etc/snort/rules
3. Subscriber Rules
... sono a pagamento ...

Creare la directory:

/usr/local/lib/snort_dynamicrules

Ridurre il max_tcp altrimenti il Raspberry non ce la fa… poverone! 😀

# Target-Based stateful inspection/stream reassembly.  For more inforation, see README.stream5
preprocessor stream5_global: track_tcp yes, \
   track_udp yes, \
   track_icmp no, \
   max_tcp 26214, \
   max_udp 131072, \
   max_active_responses 2, \
   min_response_seconds 5

cambiare i file di whitelist e blacklist:

white_list.rules -> whitelist.rule
black_list.rules -> blacklist.rule

# Reputation preprocessor. For more information see README.reputation
preprocessor reputation: \
   memcap 500, \
   priority whitelist, \
   nested_ip inner, \
   whitelist $WHITE_LIST_PATH/whitelist.rule, \
   blacklist $BLACK_LIST_PATH/blacklist.rule  

portarsi nella directory

/etc/snort/rules/etc

e lanciare il comando

snort -d -h 192.168.0.0/24 -l ./log -c snort.conf 

I parametri dipendono ovviamente dal tipo di LAN che volete monitorare.

Per i dettagli leggere il manuale di Snort su Snort.org.

A questo punto per testarlo andiamo a mettere in

/etc/snort/rules/local.rules 

la seguente regola

# $Id: local.rules,v 1.11 2004/07/23 20:15:44 bmc Exp $
# ----------------
# LOCAL RULES
# ----------------
# This file intentionally does not come with signatures.  Put your local
# additions here.

# Test ping
#alert ip any any -> any any (msg: "IP Packet detected"; sid: 8888888)
alert icmp any any -> any any (msg: "TEST PING *** ^^ *** ICMP Packet found"; sid: 888888)

Che testa anche il PING essendo una richiesta echo ICMP.

Lanciamo snort e pinghiamo il nostro gateway:

ping 192.168.0.1

andiamo quindi ad analizzare i nostri alert

more ./log/alert

e vediamo che la nostra regola ha fatto scattare l’allarme!!! 😀

[**] [1:888888:0] TEST PING *** ^^ *** ICMP Packet found [**]
[Priority: 0] 
03/27-21:14:27.294037 A8:20:66:27:D5:F6 -> E0:91:F5:F9:2D:4E type:0x800 len:0x62
192.168.0.6 -> 192.168.0.1 ICMP TTL:64 TOS:0x0 ID:12623 IpLen:20 DgmLen:84
Type:8  Code:0  ID:3591   Seq:0  ECHO
Utilizzare Snort

IDS: Snort on Raspberry PI

In questo articolo vedremo come installare un software per l’intrusion detection della nostra rete sul nostro Raspberry Pi.

Per prima cosa ci serve un sistema operativo opportuno da installare sul nostro Raspberry PI. Per questo tipo di applicazione ho scelto Kali linux il successore della distro linux BackTrack, famosissima nel campo della sicurezza IT.

Scarichiamo quindi l’immagine per processore ARM dal sito ufficiale:

https://www.kali.org/downloads/

che ci rimanda per il porting su Raspberry PI al sito

https://www.offensive-security.com/kali-linux-vmware-arm-image-download/

In base alla versione di Raspberry PI che avete scaricate la iso opportuna.

Io ho il Raspberry PI versione B e quindi ho scelto la distro Raspberry Pi A/B+

Una volta scaricato occorre copiare l’immagine sull’SD card che volete utilizzare sul Raspberry con i comandi che trovare anche sull’articolo in questo blog relativo al backup e ripristino del vostro Raspberry PI.

Riporto qui i passi fatti sul mio MacBook Air:

Fabios-MacBook-Air:~ shadowsheep$ diskutil list
/dev/disk0
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *121.3 GB   disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:                  Apple_HFS Macintosh HD            75.0 GB    disk0s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3
   4:       Microsoft Basic Data BOOTCAMP                45.5 GB    disk0s4
/dev/disk1
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *8.1 GB     disk1
   1:                 DOS_FAT_32 CHIAVINA                8.1 GB     disk1s1
Fabios-MacBook-Air:~ shadowsheep$ diskutil unmountDisk /dev/disk1
Unmount of all volumes on disk1 was successful
Fabios-MacBook-Air:~ shadowsheep$ cd Downloads/
Fabios-MacBook-Air:Downloads shadowsheep$ xz -d kali-1.1.0-rpi.img.xz
Fabios-MacBook-Air:Downloads shadowsheep$ sudo dd bs=1m if=kali-1.1.0-rpi.img of=/dev/disk1
Password:
3000+0 records in
3000+0 records out
3145728000 bytes transferred in 2055.895717 secs (1530101 bytes/sec)
Fabios-MacBook-Air:Downloads shadowsheep$

Il comando dd ci metterà un po’ a terminare. Una volta terminato avremo la nostra immagine installata sull’SD.
Una volta installata la nostra distro possiamo inseriamo l’SD card sul Raspberry e accendiamolo.

In questo tutorial io accederò al nostro Raspberry Pi solamente tramite SSH.

Ma prima occorre verificare che la dietro abbia ottenuto un IP valido e inoltre voglio ricreare una signature SSH differente da quella standard.

Per utilizzare il mio nuovo Raspberry Pi con Kali quindi attacchiamo una tastiera USB e un monitor che abbia l’ingresso HDMI.

L’utente root ha password “toor”. Cambiamola subito con “passwd”

root@kali:~# passwd
Enter new UNIX password:

Rigeneriamo quindi anche le chiave per l’SSH server

root@kali:~# cd /etc/ssh
root@kali:/etc/ssh# mkdir ssh_default_keys
root@kali:/etc/ssh# mv ssh_host* ssh_default_keys/
root@kali:/etc/ssh# dpkg-reconfigure openssh-server
Creating SSH2 RSA key; this may take some time ...
Creating SSH2 DSA key; this may take some time ...
Creating SSH2 ECDSA key; this may take some time ...
[ ok ] Restarting OpenBSD Secure Shell server: sshd.
root@kali:/etc/ssh#

Da adesso possiamo collegarci tramite SSH.

Non avendo installato una versione di linux apposta per il Raspberry ci viene a mancare la comoda utility raspi-config. Andiamo quindi ad aggiungerla manualmente alla nostra installazione di Kali linux.

wget http://archive.raspberrypi.org/debian/pool/main/r/raspi-config/raspi-config_20121028_all.deb
wget http://ftp.acc.umu.se/mirror/cdimage/snapshot/Debian/pool/main/l/lua5.1/lua5.1_5.1.5-4_armel.deb
wget http://http.us.debian.org/debian/pool/main/t/triggerhappy/triggerhappy_0.3.4-2_armel.deb
dpkg -i triggerhappy_0.3.4-2_armel.deb
dpkg -i lua5.1_5.1.5-4_armel.deb
dpkg -i raspi-config_20121028_all.deb

Una volta installato lanciamolo per espandere il nostro filesystem. Infatti l’immagine di Kali linux installata è stata fatta per essere ospitata da una SD da 4GB e quindi se ne abbiamo una più grande (come nel mio caso 8GB) dobbiamo appropriarci dello spazio mancante! 🙂

root@kali:~# df
Filesystem     1K-blocks    Used Available Use% Mounted on
rootfs           2896624 1570816   1158952  58% /
/dev/root        2896624 1570816   1158952  58% /
devtmpfs           89804       0     89804   0% /dev
tmpfs              18796     488     18308   3% /run
tmpfs               5120       0      5120   0% /run/lock
tmpfs              37580       0     37580   0% /run/shm

Screen Shot 2015-03-22 at 11.48.27 Screen Shot 2015-03-22 at 11.48.47

Facciamo il reboot del sistema e dopo averlo fatto ecco apparire tutti i nostri GB!

root@kali:~# df
Filesystem     1K-blocks    Used Available Use% Mounted on
rootfs           7633328 1573136   5701036  22% /
/dev/root        7633328 1573136   5701036  22% /
devtmpfs           89804       0     89804   0% /dev
tmpfs              18796     496     18300   3% /run
tmpfs               5120       0      5120   0% /run/lock
tmpfs              37580       0     37580   0% /run/shm

A questo punto installiamo tutti i pacchetti che la distribuzione Kali linux ci mette a disposizione per l’IT security:

root@kali:~# apt-get update && apt-cache search kali-linux
Get:1 http://http.kali.org kali Release.gpg [836 B]
Get:2 http://security.kali.org kali/updates Release.gpg [836 B]
Get:3 http://http.kali.org kali Release [21.1 kB]     
Get:4 http://security.kali.org kali/updates Release [11.0 kB]
Get:5 http://http.kali.org kali/main Sources [7570 kB]  
Ign http://security.kali.org kali/updates/contrib Translation-en            
Ign http://http.kali.org kali/contrib Translation-en                         
Ign http://security.kali.org kali/updates/main Translation-en                
Ign http://security.kali.org kali/updates/non-free Translation-en             
Ign http://http.kali.org kali/main Translation-en                              
Ign http://http.kali.org kali/non-free Translation-en                          
Get:6 http://security.kali.org kali/updates/main Sources [146 kB]              
Get:7 http://security.kali.org kali/updates/contrib Sources [20 B]             
Get:8 http://security.kali.org kali/updates/non-free Sources [20 B]            
Get:9 http://http.kali.org kali/non-free Sources [118 kB]                      
Get:10 http://security.kali.org kali/updates/main armel Packages [277 kB]      
Get:11 http://http.kali.org kali/contrib Sources [56.9 kB]                     
Hit http://security.kali.org kali/updates/contrib armel Packages               
Get:12 http://http.kali.org kali/main armel Packages [8284 kB]                 
Hit http://security.kali.org kali/updates/non-free armel Packages              
Get:13 http://http.kali.org kali/non-free armel Packages [91.2 kB]             
Hit http://http.kali.org kali/contrib armel Packages                           
Fetched 16.6 MB in 1min 55s (143 kB/s)                                         
Reading package lists... Done
kali-linux - Kali Linux base system
kali-linux-all - Kali Linux - all packages
kali-linux-forensic - Kali Linux forensic tools
kali-linux-full - Kali Linux complete system
kali-linux-gpu - Kali Linux GPU tools
kali-linux-pwtools - Kali Linux password cracking tools
kali-linux-rfid - Kali Linux RFID tools
kali-linux-sdr - Kali Linux SDR tools
kali-linux-top10 - Kali Linux Top 10 tools
kali-linux-voip - Kali Linux VoIP tools
kali-linux-web - Kali Linux webapp assessment tools
kali-linux-wireless - Kali Linux wireless tools
root@kali:~# apt-get install kali-linux-full

Andate a fare una bella passeggiata, prendete un buon aperitivo, incontrate degli amici in attesa che il sistema si installi completamente…

E infine installiamo Snort:

root@kali:~# apt-get install snort

Se voltete installare l’ultima versione di Snort a partire dai sorgenti ufficiali sul sito potete seguire le istruzioni sul sito snort.org:

Se la configurazione del daq vi da errore perché manca la libreria libpcap allora dovete installarla:

apt-get install libpcap-dev

Al termine della compilazione e installazione del daq dovreste vedere un report simile a questo.

----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/lib/daq

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Se la configurazione di snort vi da errore perché non trova le librerie libpcre e libante allora installatele con il comando:

apt-get install libpcre3 libpcre3-dev
apt-get install libdumbnet-dev

Al termine invece di snort dovreste vedere un report simile a questo assieme a molte altre cose (tante!)

----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/lib/snort/dynamic_output

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

A questo punto avete il vostro Snort installato!

root@kali:~/tmp/snort-2.9.7.2# snort -V

   ,,_     -*> Snort! <*-
  o"  )~   Version 2.9.7.2 GRE (Build 177) 
   ''''    By Martin Roesch & The Snort Team: http://www.snort.org/contact#team
           Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
           Copyright (C) 1998-2013 Sourcefire, Inc., et al.
           Using libpcap version 1.3.0
           Using PCRE version: 8.30 2012-02-04
           Using ZLIB version: 1.2.7
IDS: Snort on Raspberry PI