Instal dan Konfigurasikan Snort 3 NIDS di Ubuntu 20.04

Dalam tutorial ini, Anda akan belajar cara menginstal dan mengkonfigurasi Snort 3 NIDS di Ubuntu 20.04. Snort adalah sistem deteksi intrusi jaringan yang ringan. Ini fitur logging berbasis aturan dan dapat melakukan pencarian/pencocokan konten selain mendeteksi berbagai serangan dan probe lainnya, seperti buffer overflows, pemindaian port siluman, serangan CGI, probe SMB, dan banyak lagi. Snort memiliki kemampuan peringatan waktu nyata, dengan peringatan dikirim ke syslog, file “peringatan” terpisah, atau bahkan ke komputer Windows melalui Samba.

Beberapa fitur Snort 3 antara lain;

  • Mendukung beberapa utas pemrosesan paket
  • Konfigurasi bersama dan tabel atribut
  • Gunakan konfigurasi yang sederhana dan dapat dituliskan
  • Jadikan komponen utama dapat dipasang
  • Layanan deteksi otomatis untuk konfigurasi tanpa port
  • Mendukung buffer lengket dalam aturan
  • Buat dokumentasi referensi secara otomatis
  • Berikan dukungan lintas platform yang lebih baik

Instal dan Konfigurasikan Snort 3 NIDS di Ubuntu 20.04

Pada tulisan ini, Ubuntu 20.04 menyediakan snort 2.9 pada repo Universe default-nya;

apt show snort
Package: snort Version: 2.9.7.0-5build1 Priority: optional Section: universe/net Origin: Ubuntu Maintainer: Ubuntu Developers  Original-Maintainer: Javier Fernández-Sanguino Peña  Bugs: https://bugs.launchpad.net/ubuntu/+filebug Installed-Size: 1,987 kB Pre-Depends: adduser (>= 3.11) Depends: snort-common-libraries (>= 2.9.7.0-5build1), snort-rules-default (>= 2.9.7.0-5build1), snort-common (>= 2.9.7.0-5build1), debconf (>= 0.5) | debconf-2.0, rsyslog | system-log-daemon, logrotate, net-tools, libc6 (>= 2.16), libdaq2, libdumbnet1 (>= 1.8), liblzma5 (>= 5.1.1alpha+20120614), libpcap0.8 (>= 1.0.0), libpcre3, zlib1g (>= 1:1.1.4) Recommends: iproute2 Suggests: snort-doc Conflicts: snort-mysql, snort-pgsql Replaces: snort-common (<< 2.0.2-3) Homepage: http://www.snort.org/ Download-Size: 656 kB APT-Sources: http://ke.archive.ubuntu.com/ubuntu focal/universe amd64 Packages 

Bangun dan Instal Snort 3 dari Kode Sumber di Ubuntu 20.04

Untuk menginstal dan mengkonfigurasi Snort 3 NIDS di Ubuntu 20.04, Anda perlu membangunnya dari sumbernya.

Jalankan Pembaruan Sistem

Untuk memulainya, jalankan pembaruan cache paket sistem;

apt update
apt upgrade

Instal Alat Bangun yang Diperlukan

Untuk membangun dan menginstal Snort 3 dengan sukses di Ubuntu 20.04, ada sejumlah alat dan dependensi build yang perlu diinstal sebelum proses build seperti yang dijelaskan pada halaman Dependensi.

apt install build-essential libpcap-dev libpcre3-dev libnet1-dev zlib1g-dev luajit hwloc libdnet-dev libdumbnet-dev bison flex liblzma-dev openssl libssl-dev pkg-config libhwloc-dev cmake cpputest libsqlite3-dev uuid-dev libcmocka-dev libnetfilter-queue-dev libmnl-dev autotools-dev libluajit-5.1-dev libunwind-dev

Download dan install versi terbaru dari Snort DAQ ( Data Acquisition  library). DAQ tidak tersedia di repo Ubuntu default dan karenanya, Anda perlu membangun dan menginstalnya dari sumbernya;

mkdir snort-source-files cd snort-source-files
git clone https://github.com/snort3/libdaq.git cd libdaq./bootstrap./configure make make install 

Download dan instal malloc thread-caching google, Tcmalloc, pengalokasi memori yang dioptimalkan untuk situasi konkurensi tinggi yang akan memberikan kecepatan yang lebih baik untuk pertukaran useran memori yang lebih tinggi. Ini adalah ketergantungan opsional tetapi sangat disarankan.

cd../ wget wget https://github.com/gperftools/gperftools/releases/download/gperftools-2.8/gperftools-2.8.tar.gz tar xzf gperftools-2.8.tar.gz cd gperftools-2.8/./configure make make install 

Instal Snort 3 dari Kode Sumber di Ubuntu 20.04

Sekarang setelah kita memiliki semua dependensi yang diperlukan, download dan instal Snort 3 di Ubuntu 20.04;

Klon Snort 3 kode sumber Github;

cd../ git clone git://github.com/snortadmin/snort3.git

Arahkan ke direktori sumber Snort 3, kompilasi dan instal;

cd snort3/
./configure_cmake.sh --prefix=/usr/local --enable-tcmalloc
... ------------------------------------------------------- snort version 3.0.2 Install options: prefix: /usr/local includes: /usr/local/include/snort plugins: /usr/local/lib/snort Compiler options: CC: /usr/bin/cc CXX: /usr/bin/c++ CFLAGS: -fvisibility=hidden -DNDEBUG -g -ggdb -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free CXXFLAGS: -fvisibility=hidden -DNDEBUG -g -ggdb -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free EXE_LDFLAGS: MODULE_LDFLAGS: Feature options: DAQ Modules: Static (afpacket;bpf;dump;fst;nfq;pcap;trace) Flatbuffers: OFF Hyperscan: OFF ICONV: ON Libunwind: ON LZMA: ON RPC DB: Built-in SafeC: OFF TCMalloc: ON UUID: ON ------------------------------------------------------- -- Configuring done -- Generating done -- Build files have been written to: /root/snort-source-files/snort3/build 

Arahkan ke direktori build dan kompilasi serta instal Snort 3 di Ubuntu 20.04;

cd build make make install

Setelah penginstalan selesai, perbarui pustaka bersama;

ldconfig

Verifikasi Instalasi Snort 3 dengan memeriksa versi;

snort -V
,,_ -*> Snort++ <*- o" )~ Version 3.0.2 (Build 5) '''' By Martin Roesch & Snort Team http://snort.org/contact#team Copyright (C) 2014-2020 Cisco and/or its affiliates. All rights reserved. Copyright (C) 1998-2013 Sourcefire, Inc., et al. Using DAQ version 3.0.0 Using LuaJIT version 2.1.0-beta3 Using OpenSSL 1.1.1f 31 Mar 2020 Using libpcap version 1.9.1 (with TPACKET_V3) Using PCRE version 8.39 2016-06-14 Using ZLIB version 1.2.11 Using LZMA version 5.2.4 

Di atas mengkonfirmasi bahwa instalasi Snort 3 berhasil dan berfungsi dengan baik.

Mendapatkan Bantuan Baris Perintah Snort

Untuk mendapatkan bantuan command line Snort, cukup jalankan salah satu dari perintah di bawah ini dan periksa perbedaannya;

snort --help
snort -?
-? <option prefix> output matching command line option quick help (same as --help-options) (optional) -A <mode> set alert mode: none, cmg, or alert_* -B <mask> obfuscated IP addresses in alerts and packet dumps using CIDR mask -C print out payloads with character data only (no hex) -c <conf> use this configuration -D run Snort in background (daemon) mode -d dump the Application Layer -e display the second layer header info -f turn off fflush() calls after binary log writes -G <0xid> (same as --logid) (0:65535) -g <gname> run snort gid as <gname> group (or gid) after initialization -H make hash tables deterministic -i <iface>... list of interfaces -k <mode> checksum mode; default is all (all|noip|notcp|noudp|noicmp|none) -L <mode> logging mode (none, dump, pcap, or log_*) -l <logdir> log to this directory instead of current directory -M log messages to syslog (not alerts) -m <umask> set the process file mode creation mask (0x000:0x1FF) -n <count> stop after count packets (0:max53) -O obfuscate the logged IP addresses -Q enable inline mode operation -q quiet mode - suppress normal logging on stdout -R <rules> include this rules file in the default policy -r <pcap>... (same as --pcap-list) -S <x=v> set config variable x equal to value v -s <snap> (same as --snaplen); default is 1518 (68:65535) -T test and report on the current Snort configuration -t <dir> ch
roots process to <dir> after initialization -U use UTC for timestamps -u <uname> run snort as <uname> or <uid> after initialization -V (same as --version) -v be verbose -X dump the raw packet data starting at the link layer -x same as --pedantic -y include year in timestamp in the alert and log files -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)... 

Mengkonfigurasi Snort 3 NIDS di Ubuntu 20.04

Konfigurasi Kartu Interface Jaringan

Pertama, atur interface tempat Snort mendengarkan lalu lintas jaringan pada promiscuousmode sehingga dapat melihat semua lalu lintas jaringan yang dikirim ke sana daripada hanya melihat lalu lintas yang berasal dari dalam server Snort 3 saja.

ip link set dev enp0s8 promisc on

Memeriksa;

ip add sh enp0s8
3: enp0s8: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 08:00:27:7f:84:15 brd ff:ff:ff:ff:ff:ff inet 192.168.57.3/24 brd 192.168.57.255 scope global dynamic enp0s8 valid_lft 446sec preferred_lft 446sec inet6 fe80::a00:27ff:fe7f:8415/64 scope link valid_lft forever preferred_lft forever

Nonaktifkan Interface Offloading untuk mencegah Snort memotong paket besar yang lebih besar dari 1518 byte. Anda dapat memeriksa apakah fitur ini diaktifkan;

ethtool -k enp0s8 | grep receive-offload
generic-receive-offload: on large-receive-offload: off [fixed]

GRO diaktifkan saat LRO diperbaiki dan karenanya tidak dapat diubah.

Kemudian nonaktifkan;

ethtool -K enp0s8 gro off lro off

Kedua perubahan NIC bersifat sementara. Untuk memastikan perubahan tetap ada di seluruh sistem reboot, buat dan aktifkan unit service systemd untuk mengimplementasikan perubahan;

vim /etc/systemd/system/snort3-nic.service
[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 enp0s8 promisc on ExecStart=/usr/sbin/ethtool -K enp0s8 gro off lro off TimeoutStartSec=0 RemainAfterExit=yes [Install] WantedBy=default.target 

Reload pengaturan konfigurasi systemd;

systemctl daemon-reload

Mulai dan aktifkan service saat boot;

systemctl enable --now snort3-nic.service

Instal Aturan Snort 3 di Ubuntu 20.04

Ruleset adalah arteri utama untuk engine pendeteksi intrusi Snorts. Ada tiga jenis Aturan Snort:

  • Aturan Komunitas
  • Aturan Terdaftar
  • Aturan Pelanggan

Dalam tutorial ini, kita akan menginstal aturan Snort komunitas;

Buat direktori Aturan Snort. Dalam/usr/local/etc/snort/snort_defaults.luaconfig, jalur aturan default (RULE_PATH), didefinisikan sebagai /usr/local/etc/rules.

mkdir /usr/local/etc/rules

Download aturan komunitas Snort 3 dari halaman downloadan Snort 3 ;

wget https://www.snort.org/downloads/community/snort3-community-rules.tar.gz

Ekstrak aturan dan simpan di direktori aturan Snort;

tar xzf snort3-community-rules.tar.gz -C /usr/local/etc/rules/
ls /usr/local/etc/rules/snort3-community-rules/
AUTHORS LICENSE sid-msg.map snort3-community.rules VRT-License.txt

Sekarang setelah kita memiliki aturan untuk memulai, Anda perlu mengkonfigurasi Snort 3. Buka file konfigurasi utama untuk diedit;

vim /usr/local/etc/snort/snort.lua

Atur jaringan untuk melindungi dari serangan sebagai nilai untuk HOME_NETvariabel. Untuk mempermudah, saya hanya mengatur ini ke subnet interface Snort 3. ItuEXTERNAL_NET adalah apa pun selain HOME_NET kami;

... -- HOME_NET and EXTERNAL_NET must be set now -- setup the network addresses you are protecting HOME_NET = '192.168.57.3/32' -- set up the external network addresses. -- (leave as "any" in most situations) -- EXTERNAL_NET = 'any' EXTERNAL_NET = '!$HOME_NET'... 

Anda dapat mengedit default Snort di /usr/local/etc/snort/snort_defaults.luafile konfigurasi.

Di bawah bagian IPS, tentukan lokasi sesuai aturan Anda;

ips = { -- use this to enable decoder and inspector alerts --enable_builtin_rules = true, -- use include for rules files; be sure to set your path -- note that rules files can include other rules files include = '/usr/local/etc/rules/snort3-community-rules/snort3-community.rules' }... 

Simpan dan keluar dari file konfigurasi.

Menginstal Snort OpenAppID

OpenAppID adalah plugin lapisan aplikasi yang memungkinkan Snort untuk mendeteksi berbagai aplikasi, Facebook, Netflix, Twitter, dan Reddit, yang digunakan dalam jaringan. Jalankan perintah di bawah ini download dari halaman downloadan Snort 3 dan instal Snort OpenAppID;

wget https://snort.org/downloads/openappid/12159 -O OpenAppId-12159.tgz tar -xzvf OpenAppId-12159.tgz cp -R odp /usr/local/lib/

Selanjutnya, edit file konfigurasi Snort 3 dan tentukan lokasi perpustakaan OpenAppID;

vim /usr/local/etc/snort/snort.lua
appid = { -- appid requires this to use appids in rules --app_detector_dir = 'directory to load appid detectors from' app_detector_dir = '/usr/local/lib', log_stats = true, }

Simpan dan keluar dari file konfigurasi.

Buat direktori Snorts Log;

mkdir /var/log/snort

Selanjutnya, jalankan pemeriksaan sintaks;

snort -c /usr/local/etc/snort/snort.lua
... Finished /usr/local/etc/snort/snort.lua: Loading /usr/local/etc/rules/snort3-community-rules/snort3-community.rules: Finished /usr/local/etc/rules/snort3-community-rules/snort3-community.rules: -------------------------------------------------- rule counts total rules loaded: 829 text rules: 829 option chains: 829 chain headers: 56 -------------------------------------------------- port rule counts tcp udp icmp ip any 63 3 0 0 src 124 2 0 0 dst 539 98 0 0 both 0 1 0 0 total 726 104 0 0 -------------------------------------------------- ips policies rule stats id loaded shared enabled file 0 829 0 829 /usr/local/etc/snort/snort.lua -------------------------------------------------- flowbits defined: 20 not checked: 11 not set: 3 -------------------------------------------------- service rule counts to-srv to-cli dns: 89 2 ftp: 7 2 ftp-data: 0 8 http: 489 92 http2: 489 92 imap: 0 8 irc: 4 1 netbios-ssn: 15 1 pop3: 0 8 smtp: 16 0 ssl: 14 31 telnet: 1 0 total: 1124 245 -------------------------------------------------- fast pattern port groups src dst any packet: 11 24 2 -------------------------------------------------- fast pattern service groups to-srv to-cli packet: 9 7 key: 2 0 header: 2 5 body: 2 0 file: 2 5 method: 2 0 -------------------------------------------------- search engine instances: 70 patterns: 1715 pattern chars: 36451 num states: 27885 num match states: 1724 memory scale: KB total memory: 785.997 pattern memory: 102.521 match list memory: 280.07 transition memory: 394.656 -------------------------------------------------- pcap DAQ configured to passive. Snort successfully validated the configuration (with 0 warnings). o")~ Snort exiting 

Buat aturan lokal Kustom untuk tujuan pengujian pengaturan Snort kami.

vim /usr/local/etc/rules/local.rules

Buat aturan untuk mendeteksi tes ping;

alert icmp any any -> $HOME_NET any (msg:"ICMP connection test"; sid:1000001; rev:1;)

Simpan dan keluar dari file aturan lokal. Periksa sintaks;

snort -c /usr/local/etc/snort/snort.lua -R /usr/loca
l/etc/rules/local.rules

Selanjutnya, jalankan tes dengan menjalankan perintah di bawah ini;

snort -c /usr/local/etc/snort/snort.lua -R /usr/local/etc/rules/local.rules -i enp0s8 -A alert_fast -s 65535 -k none

Di terminal lain, ping server Snort Anda. Saat ping berjalan, Anda akan melihat baris peringatan yang ditulis ke keluaran standar;

... -------------------------------------------------- search engine instances: 70 patterns: 1715 pattern chars: 36451 num states: 27885 num match states: 1724 memory scale: KB total memory: 785.997 pattern memory: 102.521 match list memory: 280.07 transition memory: 394.656 -------------------------------------------------- pcap DAQ configured to passive. Commencing packet processing ++ [0] enp0s8 08/22-19:20:23.502536 [**] [1:1000001:1] "ICMP connection test" [**] [Priority: 0] [AppID: ICMP] {ICMP} 192.168.57.1 -> 192.168.57.3 08/22-19:20:24.526491 [**] [1:1000001:1] "ICMP connection test" [**] [Priority: 0] [AppID: ICMP] {ICMP} 192.168.57.1 -> 192.168.57.3 08/22-19:20:25.550241 [**] [1:1000001:1] "ICMP connection test" [**] [Priority: 0] [AppID: ICMP] {ICMP} 192.168.57.1 -> 192.168.57.3 08/22-19:20:26.574652 [**] [1:1000001:1] "ICMP connection test" [**] [Priority: 0] [AppID: ICMP] {ICMP} 192.168.57.1 -> 192.168.57.3 08/22-19:20:27.598509 [**] [1:1000001:1] "ICMP connection test" [**] [Priority: 0] [AppID: ICMP] {ICMP} 192.168.57.1 -> 192.168.57.3... 

Konfigurasikan Snort 3 Logging

Untuk menulis acara Snort 3 ke file log, Anda harus mengaktifkan konfigurasikan pengaturan peringatan. Ada berbagai opsi Snort logging yang dijelaskan dengan baik di manual Snort 3, bagian Modul Logger. Untuk menampilkan data acara ke file, dalam format singkat (seperti yang didefinisikan dalam command line di atas dengan opsi -A alert_type), buka tombolsnort.lua konfigurasi dan menuju ke bagian output.

vim /usr/local/etc/snort/snort.lua
--------------------------------------------------------------------------- -- 7. configure outputs --------------------------------------------------------------------------- -- event logging -- you can enable with defaults from the command line with -A  -- uncomment below to set non-default configs --alert_csv = { } alert_fast = { file = true, packet = false, limit = 10, } --alert_full = { } --alert_sfsocket = { } --alert_syslog = { } --unified2 = { }

Pengaturan akan menyebabkan snort menulis log ke alert_fast.txtfile. Simpan dan keluar dari konfigurasi dan jalankan pemeriksaan sintaks.

snort -c /usr/local/etc/snort/snort.lua

Jalankan perintah lagi, kali ini, tanpa opsi, -A alert_fast, tetapi dengan opsi untuk menentukan direktori log, -l /var/log/snort.

snort -c /usr/local/etc/snort/snort.lua -R /usr/local/etc/rules/local.rules -i enp0s8 -s 65535 -k none -l /var/log/snort/

Jalankan tes ping lagi. Jika Anda memeriksa direktori log, Anda akan melihat alert_fast.txtfile yang dibuat. Anda dapat mengekor file ini;

tail -f /var/log/snort/alert_fast.txt
08/22-19:30:41.554941 [**] [1:1000001:1] "ICMP connection test" [**] [Priority: 0] [AppID: ICMP] {ICMP} 192.168.57.1 -> 192.168.57.3 08/22-19:30:42.578554 [**] [1:1000001:1] "ICMP connection test" [**] [Priority: 0] [AppID: ICMP] {ICMP} 192.168.57.1 -> 192.168.57.3 08/22-19:30:43.602594 [**] [1:1000001:1] "ICMP connection test" [**] [Priority: 0] [AppID: ICMP] {ICMP} 192.168.57.1 -> 192.168.57.3 08/22-19:30:44.626660 [**] [1:1000001:1] "ICMP connection test" [**] [Priority: 0] [AppID: ICMP] {ICMP} 192.168.57.1 -> 192.168.57.3 08/22-19:30:45.650654 [**] [1:1000001:1] "ICMP connection test" [**] [Priority: 0] [AppID: ICMP] {ICMP} 192.168.57.1 -> 192.168.57.3 08/22-19:30:46.674630 [**] [1:1000001:1] "ICMP connection test" [**] [Priority: 0] [AppID: ICMP] {ICMP} 192.168.57.1 -> 192.168.57.3... 

Anda dapat memasukkan aturan lokal di snort.lua;

ips = { -- use this to enable decoder and inspector alerts -- enable_builtin_rules = true, -- use include for rules files; be sure to set your path -- note that rules files can include other rules files include = '/usr/local/etc/rules/snort3-community-rules/snort3-community.rules', include = '/usr/local/etc/rules/local.rules' } 

Menjalankan Snort sebagai Layanan

Meskipun dimungkinkan untuk menjalankan Snort sebagai daemon di latar belakang dengan opsi command line -D, juga dimungkinkan untuk membuat unit service systemd untuk Snort.

Jika Anda akan menjalankan Snort sebagai service, adalah bijaksana untuk menjalankannya pada user sistem yang tidak memiliki hak istimewa. Oleh karena itu, buat akun user sistem non login untuk Snort;

useradd -r -s /usr/sbin/nologin -M -c SNORT_IDS snort

Buat unit service systemd untuk Snort untuk dijalankan sebagai user snort. Sesuaikan interface Anda.

vim /etc/systemd/system/snort3.service
[Unit] Description=Snort 3 NIDS Daemon After=syslog.target network.target [Service] Type=simple ExecStart=/usr/local/bin/snort -c /usr/local/etc/snort/snort.lua -s 65535 -k none -l /var/log/snort -D -i enp0s8 -m 0x1b -u snort -g snort [Install] WantedBy=multi-user.target 

Reload konfigurasi systemd;

systemctl daemon-reload

Atur kepemilikan dan izin pada file log;

chmod -R 5775 /var/log/snort
chown -R snort:snort /var/log/snort

Mulai dan aktifkan Snort untuk berjalan pada boot sistem. Layanan akan berjalan sebagai root dan kemudian menjatuhkan hak istimewa ke Snort yang dibuat user.

systemctl enable --now snort3

Periksa service untuk mengonfirmasi apakah itu berjalan;

systemctl status snort3
● snort3.service - Snort 3 NIDS Daemon Loaded: loaded (/etc/systemd/system/snort3.service; enabled; vendor preset: enabled) Active: active (running) since Sat 2020-08-22 20:50:26 UTC; 1min 14s ago Main PID: 43673 (snort) Tasks: 2 (limit: 2282) Memory: 145.3M CGroup: /system.slice/snort3.service └─43673 /usr/local/bin/snort -c /usr/local/etc/snort/snort.lua -s 65535 -k none -l /var/log/snort -D -i enp0s8 -m 0x1b -u snort -g snort Aug 22 20:50:26 ubuntu20 systemd[1]: Started Snort 3 NIDS Daemon. 

Itu menandai akhir dari tutorial kami tentang cara menginstal dan mengkonfigurasi Snort 3 NIDS di Ubuntu 20.04.

Note that we have just scratched the service on what the configuration and what Snort 3 is capable of.

Referensi

Instalasi Snort 3

Bacaan lebih lanjut

Panduan Pengguna Snort 3

Tutorial Terkait

Instal dan Konfigurasikan AIDE di Ubuntu 20.04

Instal dan Konfigurasi alat Pemantauan Keamanan Tripwire di CentOS 8

Instal dan Setup Suricata di CentOS 8

Instal dan Atur Suricata di Ubuntu 18.04