Tout d'abord nous allons installer les packages nécessaires à une installation correct de nos packages :
sudo apt update
sudo apt install cmake build-essential hwloc libpcap-dev libpcre3-dev pkg-config zlib1g-dev autoconf automake libtool check libssl-dev liblzma-dev
Attention, dans certains cas il vous faudra installer hwloc manuellement via la source officielle
A partir de là nous allons pouvoir récupérer les dépendances restantes à savoir si l'on se base sur le git :
git clone https://github.com/snort3/libdaq.git
cd libdaq/
(sudo if needed) ./bootstrap
(sudo if needed) ./configure
(sudo if needed) make
(sudo if needed) make install
git clone https://github.com/ofalk/libdnet.git
cd libdnet
(sudo if needed) ./configure
(sudo if needed) make
(sudo if needed) make install
Télédchargez le .tag.gz sur le github officiel, j'utiliserais le 2.6.4
(sudo if needed) tar -xzf flex-2.6.4.tar.gz
cd flex-2.6.4/
(sudo if needed) ./configure
(sudo if needed) make
(sudo if needed) make check
(sudo if needed) make install
git clone https://luajit.org/git/luajit.git
cd luajit/
(sudo if needed) make && (sudo if needed) make install
Téléchargez OpenSSL sur le site officiel, j'utiliserais la version 3.3.1
(sudo if needed) tar -xzf openssl-3.3.1.tar.gz
cd openssl-3.3.1
(sudo if needed) ./Configure --prefix=/usr/local/ssl --openssldir=/usr/local/ssl '-Wl,--enable-new-dtags,-rpath,$(LIBRPATH)'
(sudo if needed) make
(sudo if needed) make install
Une fois les dépendances installé, vous pouvez installer Snort, téléchargez la dernière version sur le github officiel.
(sudo if needed) tar -xzf snort3-3.3.4.0.tar.gz
export snort_path=/opt/snort
./configure_cmake.sh --prefix=$snort_path
Si à ce moment là, vous avez l'erreur suivante :
-- Package 'hwloc', required by 'virtual:world', not found
CMake Error at cmake/FindHWLOC.cmake:6 (message):
ERROR! hwloc library not found.
Get it from https://www.open-mpi.org/projects/hwloc/
Call Stack (most recent call first):
cmake/include_libraries.cmake:7 (find_package)
CMakeLists.txt:27 (include)
Installez hwloc manuellement comme expliqué au début du tutoriel.
Une fois l'installation terminée, vérifiez que snort fonctionne avec quelques commandes :
# Command
snort -V
# Result
,,_ -*> Snort++ <*-
o" )~ Version 3.3.4.0
'''' By Martin Roesch & The Snort Team
http://snort.org/contact#team
Copyright (C) 2014-2024 Cisco and/or its affiliates. All rights reserved.
Copyright (C) 1998-2013 Sourcefire, Inc., et al.
Using DAQ version 3.0.16
Using libpcap version 1.10.3 (with TPACKET_V3)
Using LuaJIT version 2.1.1724512491
Using LZMA version 5.4.1
Using OpenSSL 3.0.14 4 Jun 2024
Using PCRE version 8.39 2016-06-14
Using ZLIB version 1.2.13
# Command
snort --help-module suppress
# Result
suppress
Help: configure event suppressions
Type: basic
Usage: context
Configuration:
int suppress[].gid = 0: rule generator ID { 0:8129 }
int suppress[].sid = 0: rule signature ID { 0:max32 }
enum suppress[].track: suppress only matching source or destination addresses { 'by_src' | 'by_dst' }
string suppress[].ip: restrict suppression to these addresses according to track
# Command
snort --help-config | grep thread
# Result
int detection.offload_threads = 0: maximum number of simultaneous offloads (defaults to disabled) { 0:max32 }
int memory.prune_target = 1048576: bytes to prune per packet thread prune cycle { 1:max32 }
string process.threads[].cpuset: pin the associated thread to this cpuset
int process.threads[].thread: set cpu affinity for the <cur_thread_num> thread that runs { 0:65535 }
enum process.threads[].type: define which threads will have specified affinity, by their type { 'other|packet|main' }
string process.threads[].name: define which threads will have specified affinity, by thread name
int process.watchdog_timer = 0: watchdog timer for packet threads (seconds, 0 to disable) { 0:60 }
int process.watchdog_min_thread_count = 1: minimum unresponsive threads for watchdog to trigger { 1:65535 }
int snort.-z: <count> maximum number of packet threads (same as --max-packet-threads); 0 gets the number of CPU cores reported by the system; default is 1 { 0:max32 }
implied snort.--id-zero: use id prefix / subdirectory even with one packet thread
int snort.--max-packet-threads: <count> configure maximum number of packet threads (same as -z) { 0:max32 }
Créer le fichier
vim /etc/systemd/system/snort3-nic.service
Ajoutez le contenu suivant :
[Unit] Description=Set Snort 3 NIC in promiscuous mode and Disable GRO, LRO on boot
After=network.target
[Service] Type=oneshot
ExecStart=/usr/sbin/ip link set dev ens18 promisc on
ExecStart=/usr/sbin/ethtool -K ens18 gro off lro off
TimeoutStartSec=0
RemainAfterExit=yes
[Install]
WantedBy=default.target
J'active ensuite le service :
systemctl daemon-reload
systemctl start snort3-nic.service
systemctl enable --now snort3-nic.service
Dans mon cas snort est installé dans /opt/snort, adaptez la suite au dossier dans lequel votre snort est installé.
Modifier le fichier snort.lua :
vim /opt/snort/etc/snort/snort.lua
Ajoutez ensuite ceci dans la configuration (les -- sont des commentaires):
ips = {
enable_builtin_rules = true,
rules = [[
-- Emplacement du fichier de règle
include /opt/snort/etc/snort/rules/local.rules
]],
variables = default_variables
}
alert_fast = {
file = true,
limit = 100000,
}
alert_full = {
file = true,
limit = 10000,
}
interface = "<votre_interface"
Conformément a ce que nous avons renseigné dans le fichier de configuration, nous allons créer un fichier de règle dans /opt/snort/etc/snort/rules/local.rules qui contiendra nos règles personnalisés sur ce que nous souhaitons contrôler.
mkdir /opt/snort/etc/snort/rules
vim /opt/snort/etc/snort/rules/local.rules
Dans ce fichier de règle je vais en ajouter 3 basique pour tester :
Le template d'une règle ressemble a ceci :
alert <type connexion> <ip source> <port source> -> <ip destination> <port destination> (msg:"<message à afficher>"; sid:<identifiant de l'alerte; <option 1>; <option 2>;)
La première règle pour contrôler s'il y a du traffic ICMP entrant et sortant, je contrôle donc toutes les sources et toutes les destinations:
alert icmp any any -> any any (msg:"ICMP Packet Detected"; sid:1000001; rev:1;)
La seconde règle va me permettre de voir si une connexion SSH a été établie avec succès, je contrôle le flux venant de l'extérieur vers l'interieur port 22, pour un traffic stateless flaggué en SYN et + :
alert tcp $EXTERNAL_NET any -> $HOME_NET 22 (msg:"SSH Login"; flow:stateless; flags:S+; sid:9000001; rev:1;)
La troisième règle contrôle la même chose mais avec les connexions ratés (flag RESET)
alert tcp $EXTERNAL_NET any -> $HOME_NET 22 (msg:"SSH Connection Failed!"; flow:stateless; flags:R+; sid:100006927; rev:1;)
Je créer le dossier dans lequel mes logs vont se loger. Pour ma part ce sera /var/log/snort
mkdir /var/log/snort
chmod 666 /var/log/snort
A partir de là je vais lancer snort pour qu'il capture les paquets, je lui demande d'utiliser le fichier snort.lua paramétré plus haut, de capturer l'interface réseau adapté, d'utiliser le mode full paramétré dans snort.lua et de stocker les logs s'il y en a dans /var/log/snort :
sudo snort -c /opt/snort/etc/snort/snort.lua -i <votre_interface> -A full -l /var/log/snort
Une fois que la capture est en cours, si j'essaie de me ping et de me connecter en SSH, une fois snort fermé j'aurais ce résultat :
--------------------------------------------------
detection
analyzed: 62
hard_evals: 37
alerts: 16
total_alerts: 16
logged: 16
--------------------------------------------------
On peut voir que j'ai des alertes (ici un extrait), si je consulte le fichier de log, il a effectivement détécté du flux ICMP et SSH :
[**] [1:9000001:1] "SSH Login" [**]
[Priority: 0]
XXXXXXXXX XXXXXXXXX -> XXXXXXXXX
TCP TTL:116 TOS:0x0 ID:59809 IpLen:20 DgmLen:52 DF
******S* Seq: 0x3A9908E1 Ack: 0x0 Win: 0xFAF0 TcpLen: 32
TCP Options (6) => MSS: 1460 NOP WS: 8 NOP NOP SackOK
[**] [1:100006927:1] "SSH Connection Failed!" [**]
[Priority: 0]
XXXXXXXXX XXXXXXXXX -> XXXXXXXXX
TCP TTL:116 TOS:0x0 ID:59824 IpLen:20 DgmLen:40 DF
***A*R** Seq: 0x3A99108F Ack: 0x63D62DD0 Win: 0x0 TcpLen: 20
XXXXXXXXX XXXXXXXXX -> XXXXXXXXX
ICMP TTL:64 TOS:0x0 ID:25115 IpLen:20 DgmLen:84 DF
Type:8 Code:0 ID:23847 Seq:7 ECHO
[**] [1:1000001:1] "ICMP Packet Detected" [**]
[Priority: 0]
XXXXXXXXX XXXXXXXXX -> XXXXXXXXX
ICMP TTL:64 TOS:0x0 ID:19878 IpLen:20 DgmLen:84
Type:0 Code:0 ID:23847 Seq:7 ECHO REPLY