Suricata
SURICATA IDS/IPS is an open source IDS that monitors communications on the network and detects suspicious traffic.
The basic mechanism is signature-based, so it can detect predefined unauthorized communications. Suricata is also characterized by its ability to provide protection as well as detection.
1.advance preparation
①Activate the EPEL Repository
1 |
# dnf -y install epel-release |
②System updates
1 |
# dnf update -y |
2.Suricata Installation and Configuration
①Suricata install
1 2 3 4 5 |
# dnf install suricata Check Version # suricata -V This is Suricata version 6.0.17 RELEASE |
②Determine interface and IP address where Suricata will inspect network packets
1 2 3 |
# ip --brief add lo UNKNOWN 127.0.0.1/8 ::1/128 ens160 UP 192.168.11.83/24 fe80::xxx:xxxx:xxxx:xxxx/64 |
③Edit configuration file
1 2 3 4 5 6 7 8 9 |
# vi /etc/suricata/suricata.yaml # Line 15 : In the "vars" section, define the network HOME_NET: "[192.168.11.0/24]" EXTRNAL_NET: "!$HOME_NET" # Line 595 : Set interface name in "af-packet" section af-packet: - interface: ens160 |
1 2 3 4 5 |
# vi /etc/sysconfig/suricata # Line 8 :Specify interface # Add options to be passed to the daemon OPTIONS="-i ens160 --user suricata " |
④Suricata rules update
1 |
# suricata-update |
⑤Activate Suricata
1 2 |
# systemctl enable --now suricata Created symlink /etc/systemd/system/multiuser.target.wants/suricata.service → /usr/lib/systemd/system/suricata.service. |
⑥Confirm Suricata startup
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# systemctl status suricata ● suricata.service - Suricata Intrusion Detection Service Loaded: loaded (/usr/lib/systemd/system/suricata.service; enabled; preset: disabled) Active: active (running) since Mon 2024-04-22 14:40:35 JST; 8s ago Docs: man:suricata(1) Process: 18948 ExecStartPre=/bin/rm -f /var/run/suricata.pid (code=exited, status=0/SUCCESS) Main PID: 18949 (Suricata-Main) Tasks: 1 (limit: 21868) Memory: 232.0M CPU: 8.714s CGroup: /system.slice/suricata.service mq18949 /sbin/suricata -c /etc/suricata/suricata.yaml --pidfile /var/run/suricata.pid -i ens160 --user suricata Apr 22 14:40:35 Lepard systemd[1]: Starting Suricata Intrusion Detection Service... Apr 22 14:40:35 Lepard systemd[1]: Started Suricata Intrusion Detection Service. Apr 22 14:40:35 Lepard suricata[18949]: 22/4/2024 -- 14:40:35 - <Notice> - This is Suricata version 6.0.17 RELEASE running in SYSTEM mode |
Check Log
1 2 3 4 5 6 7 8 9 10 11 |
# tail /var/log/suricata/suricata.log 22/4/2024 -- 14:40:35 - <Info> - stats output device (regular) initialized: stats.log 22/4/2024 -- 14:40:35 - <Info> - Running in live mode, activating unix socket 22/4/2024 -- 14:40:48 - <Info> - 1 rule files processed. 37232 rules successfully loaded, 0 rules failed 22/4/2024 -- 14:40:48 - <Info> - Threshold config parsed: 0 rule(s) found 22/4/2024 -- 14:40:48 - <Info> - 37235 signatures processed. 1192 are IP-only rules, 4890 are inspecting packet payload, 30946 inspect application layer, 108 are decoder event only 22/4/2024 -- 14:40:57 - <Info> - Going to use 2 thread(s) 22/4/2024 -- 14:40:57 - <Info> - Running in live mode, activating unix socket 22/4/2024 -- 14:40:57 - <Info> - Using unix socket file '/var/run/suricata/suricata-command.socket' 22/4/2024 -- 14:40:57 - <Notice> - all 2 packet processing threads, 4 management threads initialized, engine started. 22/4/2024 -- 14:40:57 - <Info> - All AFP capture threads are running. |
Check the stats.log file for statistics (updated every 8 seconds by default)
1 |
# tail -f /var/log/suricata/stats.log |
A more advanced output, EVE JSON, can be generated with the following command
1 |
# tail -f /var/log/suricata/eve.json |
3.Suricata Testing
①Run ping test with curl utility
1 2 |
# curl http://testmynids.org/uid/index.html uid=0(root) gid=0(root) groups=0(root) |
②Check the alert log to see if it has been logged
1 2 3 |
# cat /var/log/suricata/fast.log 04/22/2024-15:00:48.055164 [**] [1:2013028:7] ET POLICY curl User-Agent Outbound [**] [Classification: Attempted Information Leak] [Priority: 2] {TCP} 192.168.11.83:55200 -> 99.86.199.74:80 04/22/2024-15:00:48.060562 [**] [1:2100498:7] GPL ATTACK_RESPONSE id check returned root [**] [Classification: Potentially Bad Traffic] [Priority: 2] {TCP} 99.86.199.74:80 -> 192.168.11.83:55200 |
4.Setting Suricata Rules
①Display of rule sets packaged in Suricata
1 2 3 4 5 6 |
# ls -al /var/lib/suricata/rules/ total 27800 drwxr-s--- 2 root suricata 57 Apr 22 14:40 . drwxrws--- 4 suricata suricata 33 Apr 22 14:40 .. -rw-r--r-- 1 root suricata 3228 Apr 22 14:40 classification.config -rw-r--r-- 1 root suricata 28460928 Apr 22 14:40 suricata.rules |
②Index list of sources providing rule sets
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# suricata-update list-sources Name: et/open Vendor: Proofpoint Summary: Emerging Threats Open Ruleset License: MIT Name: et/pro Vendor: Proofpoint Summary: Emerging Threats Pro Ruleset License: Commercial Replaces: et/open Parameters: secret-code Subscription: https://www.proofpoint.com/us/threat-insight/et-pro-ruleset Name: oisf/trafficid Vendor: OISF Summary: Suricata Traffic ID ruleset License: MIT Name: scwx/enhanced Vendor: Secureworks Summary: Secureworks suricata-enhanced ruleset License: Commercial Parameters: secret-code Subscription: https://www.secureworks.com/contact/ (Please reference CTU Countermeasures) Name: scwx/malware Vendor: Secureworks Summary: Secureworks suricata-malware ruleset License: Commercial Parameters: secret-code Subscription: https://www.secureworks.com/contact/ (Please reference CTU Countermeasures) Name: scwx/security Vendor: Secureworks Summary: Secureworks suricata-security ruleset License: Commercial Parameters: secret-code Subscription: https://www.secureworks.com/contact/ (Please reference CTU Countermeasures) Name: sslbl/ssl-fp-blacklist Vendor: Abuse.ch Summary: Abuse.ch SSL Blacklist License: Non-Commercial Name: sslbl/ja3-fingerprints Vendor: Abuse.ch Summary: Abuse.ch Suricata JA3 Fingerprint Ruleset License: Non-Commercial Name: etnetera/aggressive Vendor: Etnetera a.s. Summary: Etnetera aggressive IP blacklist License: MIT Name: tgreen/hunting Vendor: tgreen Summary: Threat hunting rules License: GPLv3 Name: malsilo/win-malware Vendor: malsilo Summary: Commodity malware rules License: MIT Name: stamus/lateral Vendor: Stamus Networks Summary: Lateral movement rules License: GPL-3.0-only Name: stamus/nrd-30-open Vendor: Stamus Networks Summary: Newly Registered Domains Open only - 30 day list, complete License: Commercial Parameters: secret-code Subscription: https://www.stamus-networks.com/stamus-labs/subscribe-to-threat-intel-feed Name: stamus/nrd-14-open Vendor: Stamus Networks Summary: Newly Registered Domains Open only - 14 day list, complete License: Commercial Parameters: secret-code Subscription: https://www.stamus-networks.com/stamus-labs/subscribe-to-threat-intel-feed Name: stamus/nrd-entropy-30-open Vendor: Stamus Networks Summary: Newly Registered Domains Open only - 30 day list, high entropy License: Commercial Parameters: secret-code Subscription: https://www.stamus-networks.com/stamus-labs/subscribe-to-threat-intel-feed Name: stamus/nrd-entropy-14-open Vendor: Stamus Networks Summary: Newly Registered Domains Open only - 14 day list, high entropy License: Commercial Parameters: secret-code Subscription: https://www.stamus-networks.com/stamus-labs/subscribe-to-threat-intel-feed Name: stamus/nrd-phishing-30-open Vendor: Stamus Networks Summary: Newly Registered Domains Open only - 30 day list, phishing License: Commercial Parameters: secret-code Subscription: https://www.stamus-networks.com/stamus-labs/subscribe-to-threat-intel-feed Name: stamus/nrd-phishing-14-open Vendor: Stamus Networks Summary: Newly Registered Domains Open only - 14 day list, phishing License: Commercial Parameters: secret-code Subscription: https://www.stamus-networks.com/stamus-labs/subscribe-to-threat-intel-feed Name: pawpatrules Vendor: pawpatrules Summary: PAW Patrules is a collection of rules for IDPS / NSM Suricata engine License: CC-BY-SA-4.0 |
③Enable source (if et/open is enabled)
1 2 3 4 5 6 7 |
# suricata-update enable-source et/open 22/4/2024 -- 15:02:45 - <Info> -- Using data-directory /var/lib/suricata. 22/4/2024 -- 15:02:45 - <Info> -- Using Suricata configuration /etc/suricata/suricata.yaml 22/4/2024 -- 15:02:45 - <Info> -- Using /usr/share/suricata/rules for Suricata provided rules. 22/4/2024 -- 15:02:45 - <Info> -- Found Suricata version 6.0.17 at /usr/sbin/suricata. 22/4/2024 -- 15:02:45 - <Info> -- Creating directory /var/lib/suricata/update/sources 22/4/2024 -- 15:02:45 - <Info> -- Source et/open enabled |
Perform update
1 |
# suricata-update |
Restart Suricata service
1 |
# systemctl restart suricata |
5.Creating Suricata Custom Rules
①Create files containing customer rules
1 2 3 |
# vi /etc/suricata/rules/local.rules Include the following information alert icmp any any -> $HOME_NET any (msg:"ICMP Ping"; sid:1; rev:1;) |
②Edit configuration file (define new rule paths)
1 2 3 4 5 6 7 8 |
# vi /etc/suricata/suricata.yaml # Added around line 1969 default-rule-path: /var/lib/suricata/rules rule-files: - suricata.rules - /etc/suricata/rules/local.rules |
③Testing the configuration file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# suricata -T -c /etc/suricata/suricata.yaml -v 22/4/2024 -- 15:05:30 - <Info> - Running suricata under test mode 22/4/2024 -- 15:05:30 - <Notice> - This is Suricata version 6.0.17 RELEASE running in SYSTEM mode 22/4/2024 -- 15:05:30 - <Info> - CPUs/cores online: 2 22/4/2024 -- 15:05:30 - <Info> - Setting engine mode to IDS mode by default 22/4/2024 -- 15:05:30 - <Info> - master exception-policy set to: auto 22/4/2024 -- 15:05:30 - <Info> - fast output device (regular) initialized: fast.log 22/4/2024 -- 15:05:30 - <Info> - eve-log output device (regular) initialized: eve.json 22/4/2024 -- 15:05:30 - <Info> - stats output device (regular) initialized: stats.log 22/4/2024 -- 15:05:42 - <Info> - 2 rule files processed. 37233 rules successfully loaded, 0 rules failed 22/4/2024 -- 15:05:42 - <Info> - Threshold config parsed: 0 rule(s) found 22/4/2024 -- 15:05:42 - <Info> - 37236 signatures processed. 1193 are IP-only rules, 4890 are inspecting packet payload, 30946 inspect application layer, 108 are decoder event only 22/4/2024 -- 15:05:51 - <Notice> - Configuration provided was successfully loaded. Exiting. 22/4/2024 -- 15:05:51 - <Info> - cleaning up signature grouping structure... complete |
Restart Suricat service
1 |
# systemctl restart suricata |
④Testing the application of Custom Rules
Ping another device on the same local network to see if it was logged
1 2 3 4 |
# cat /var/log/suricata/fast.log 04/22/2024-15:07:04.755240 [**] [1:1:1] ICMP Ping [**] [Classification: (null)] [Priority: 3] {ICMP} 192.168.11.22:8 -> 192.168.11.83:0 04/22/2024-15:07:04.755313 [**] [1:1:1] ICMP Ping [**] [Classification: (null)] [Priority: 3] {ICMP} 192.168.11.83:0 -> 192.168.11.22:0 |
To get logs in JSON format, install jq on your system
1 |
# dnf install jq |
1 |
# systemctl restart suricata |
Execute the following command to ping another device on the same local network
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# tail -f /var/log/suricata/eve.json | jq 'select(.event_type=="alert")' When ping is executed, the following is displayed in the console { "timestamp": "2024-04-22T15:08:23.260359+0900", "flow_id": 520472707463431, "in_iface": "ens160", "event_type": "alert", "src_ip": "192.168.11.22", "src_port": 0, "dest_ip": "192.168.11.83", "dest_port": 0, "proto": "ICMP", "icmp_type": 8, "icmp_code": 0, "alert": { "action": "allowed", "gid": 1, "signature_id": 1, "rev": 1, "signature": "ICMP Ping", "category": "", "severity": 3 }, "flow": { "pkts_toserver": 1, "pkts_toclient": 0, "bytes_toserver": 74, "bytes_toclient": 0, "start": "2024-04-22T15:08:23.260359+0900" } } { "timestamp": "2024-04-22T15:08:23.260471+0900", "flow_id": 520472707463431, "in_iface": "ens160", "event_type": "alert", "src_ip": "192.168.11.83", "src_port": 0, "dest_ip": "192.168.11.22", "dest_port": 0, "proto": "ICMP", "icmp_type": 0, "icmp_code": 0, "alert": { "action": "allowed", "gid": 1, "signature_id": 1, "rev": 1, "signature": "ICMP Ping", "category": "", "severity": 3 }, "flow": { "pkts_toserver": 2, "pkts_toclient": 1, "bytes_toserver": 148, "bytes_toclient": 74, "start": "2024-04-22T15:08:23.260359+0900" } } { "timestamp": "2024-04-22T15:08:23.996387+0900", "flow_id": 814171161046067, "in_iface": "ens160", "event_type": "alert", "src_ip": "192.168.11.22", "src_port": 55538, "dest_ip": "192.168.11.82", "dest_port": 443, "proto": "TCP", "metadata": { "flowints": { "applayer.anomaly.count": 1 } }, "alert": { "action": "allowed", "gid": 1, "signature_id": 2260001, "rev": 1, "signature": "SURICATA Applayer Wrong direction first Data", "category": "Generic Protocol Command Decode", "severity": 3 }, "app_proto": "failed", "app_proto_tc": "tls", "flow": { "pkts_toserver": 5, "pkts_toclient": 3, "bytes_toserver": 370, "bytes_toclient": 424, "start": "2024-04-22T15:08:23.994355+0900" } } |
SNORT3
Snort is an open source network intrusion detection system that can perform real-time traffic analysis and packet logging on IP networks.
It can perform "protocol analysis," "content search," and "matching" and can be used to detect a variety of attacks such as buffer overflows, stealth port scans, CGI attacks, SMB probes, OS fingerprinting attempts, semantic URL attacks, and server message block probes. detection.
1.Advance preparation
1.1 Install Required Packages
1.openssl-devel install
1 |
# dnf install openssl-devel |
2.Enabling codeready repositories
1 |
# dnf config-manager --set-enabled ol9_codeready_builder |
Check the repository
1 2 |
# dnf repolist|grep ol9_codeready_builder ol9_codeready_builder Oracle Linux 9 CodeReady Builder (x86_64) - (Unsupported) |
3.cmake install
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# wget https://github.com/Kitware/CMake/releases/download/v3.19.6/cmake-3.19.6.tar.gz Extracting Files # tar xvf cmake-3.19.6.tar.gz Compile cmake # cd cmake-3.19.6/ # ./bootstrap && make && make install Version Check # cmake --version cmake version 3.19.6 CMake suite maintained and supported by Kitware (kitware.com/cmake). |
1.2 Install Dependent Packages
1 2 3 |
# dnf install libpcap-devel pcre-devel libdnet-devel hwloc-devel openssl-devel zlib-devel luajit-devel pkgconf libmnl-devel libunwind-devel # dnf install libnfnetlink-devel libnetfilter_queue |
1.3 LibDAQ install
1 2 3 4 5 6 7 8 9 10 |
# cd # git clone https://github.com/snort3/libdaq.git Cloning into 'libdaq'... remote: Enumerating objects: 2491, done. remote: Counting objects: 100% (226/226), done. remote: Compressing objects: 100% (94/94), done. remote: Total 2491 (delta 156), reused 176 (delta 132), pack-reused 2265 Receiving objects: 100% (2491/2491), 1.15 MiB | 10.82 MiB/s, done. Resolving deltas: 100% (1789/1789), done. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# cd libdaq/ # ./bootstrap + autoreconf -ivf --warnings=all autoreconf: Entering directory `.' autoreconf: configure.ac: not using Gettext autoreconf: running: aclocal --force --warnings=all -I m4 autoreconf: configure.ac: tracing autoreconf: running: libtoolize --copy --force libtoolize: putting auxiliary files in '.'. libtoolize: copying file './ltmain.sh' libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'. libtoolize: copying file 'm4/libtool.m4' libtoolize: copying file 'm4/ltoptions.m4' libtoolize: copying file 'm4/ltsugar.m4' libtoolize: copying file 'm4/ltversion.m4' libtoolize: copying file 'm4/lt~obsolete.m4' autoreconf: running: /usr/bin/autoconf --force --warnings=all autoreconf: running: /usr/bin/autoheader --force --warnings=all autoreconf: running: automake --add-missing --copy --force-missing --warnings=all configure.ac:29: installing './ar-lib' configure.ac:26: installing './compile' configure.ac:34: installing './config.guess' configure.ac:34: installing './config.sub' configure.ac:19: installing './install-sh' configure.ac:19: installing './missing' api/Makefile.am: installing './depcomp' parallel-tests: installing './test-driver' autoreconf: Leaving directory `.' |
1 2 |
# ./configure # make && make install |
1 2 3 4 5 6 |
# ln -s /usr/local/lib/libdaq.so.3 /lib/ Adding Shared Libraries # ldconfig Check the library # ldconfig -p|grep daq libdaq.so.3 (libc6,x86-64) => /lib/libdaq.so.3 |
1.4 Install optional packages
1. Installation of ZMA and UUID
1 |
# dnf install xz-devel libuuid-devel |
2.Installing Hyperscan
1 |
# dnf install hyperscan hyperscan-devel |
3.Safec Installation
1 2 3 4 5 |
# wget https://forensics.cert.org/cert-forensics-tools-release-el9.rpm # rpm -Uvh cert-forensics-tools-release*rpm # dnf --enablerepo=forensics install libsafec-devel |
4.Installing Tcmalloc
1 |
# dnf install gperftools-devel |
2. Snort3 Install
1 2 3 4 5 6 |
# git clone https://github.com/snort3/snort3.git # cd snort3/ # export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH # export PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:$PKG_CONFIG_PATH # export CFLAGS="-O3" # export CXXFLAGS="-O3 -fno-rtti" |
Execute configure
1 2 3 4 5 6 |
# ./configure_cmake.sh --prefix=/usr/local/snort --enable-tcmalloc ------------------------------------------------------- -- Configuring done -- Generating done -- Build files have been written to: /root/snort3/build |
Build, compile, and install
1 2 3 4 5 6 |
# cd build/ # pwd /root/snort3/build # make -j$(nproc) # make -j$(nproc) install |
Version Check
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# /usr/local/snort/bin/snort -V ,,_ -*> Snort++ <*- o" )~ Version 3.1.84.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.14 Using LuaJIT version 2.1.0-beta3 Using OpenSSL 3.0.7 1 Nov 2022 Using libpcap version 1.10.0 (with TPACKET_V3) Using PCRE version 8.44 2020-02-12 Using ZLIB version 1.2.11 Using Hyperscan version 5.4.1 2023-04-14 Using LZMA version 5.2.5 |
test run
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# /usr/local/snort/bin/snort -c /usr/local/snort/etc/snort/snort.lua -------------------------------------------------- search engine (ac_bnfa) instances: 2 patterns: 416 pattern chars: 2508 num states: 1778 num match states: 370 memory scale: KB total memory: 68.5879 pattern memory: 18.6973 match list memory: 27.3281 transition memory: 22.3125 appid: MaxRss diff: 3656 appid: patterns loaded: 300 -------------------------------------------------- pcap DAQ configured to passive. Snort successfully validated the configuration (with 0 warnings). o")~ Snort exiting |
Network interface settings
Check network interface
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 00:0c:29:80:4b:68 brd ff:ff:ff:ff:ff:ff altname enp3s0 inet 192.168.11.83/24 brd 192.168.11.255 scope global noprefixroute ens160 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe80:4b68/64 scope link noprefixroute valid_lft forever preferred_lft foreve |
The network interface name is ens160
Set the network interface to promiscuous mode. This way, the network device can capture and inspect all network packets.
1 |
# ip link set dev ens160 promisc on |
Confirm settings
1 2 3 |
# ip a | grep ens160 | grep mtu 2: ens160: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 |
Check the offload status of the network interface. If you need to monitor network traffic on an interface, you must disable offloading
1 2 3 |
# ethtool -k ens160 | grep receive-offload generic-receive-offload: on large-receive-offload: on |
Set LRO and GRO offload status to off state
1 |
# ethtool -K ens160 gro off lro off |
Create systemd service for Snort network interface
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# touch /etc/systemd/system/snort3-nic.service # vi /etc/systemd/system/snort3-nic.service Include the following [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 ens160 promisc on ExecStart=/usr/sbin/ethtool -K ens160 gro off lro off TimeoutStartSec=0 RemainAfterExit=yes [Install] WantedBy=default.target |
systemd daemon applies changes
1 2 3 4 |
# systemctl daemon-reload # systemctl enable snort3-nic.service Created symlink /etc/systemd/system/default.target.wants/snort3-nic.service → /etc/systemd/system/snort3-nic.service. # systemctl start snort3-nic.service |
Check Snort NIC Service Status
1 2 3 4 5 6 7 8 9 10 11 |
# systemctl status snort3-nic.service ● snort3-nic.service - Set Snort 3 NIC in promiscuous mode and Disable GRO, LRO> Loaded: loaded (/etc/systemd/system/snort3-nic.service; enabled; preset: d> Active: active (exited) since Tue 2024-04-23 13:04:21 JST; 42s ago Process: 42316 ExecStart=/usr/sbin/ip link set dev ens160 promisc on (code=> Process: 42317 ExecStart=/usr/sbin/ethtool -K ens160 gro off lro off (code=> Main PID: 42317 (code=exited, status=0/SUCCESS) CPU: 3ms Apr 23 13:04:21 Lepard systemd[1]: Starting Set Snort 3 NIC in promiscuous mode> Apr 23 13:04:21 Lepard systemd[1]: Finished Set Snort 3 NIC in promiscuous mode> |
Added Snort Community Ruleset
1.Create a folder for Snort rules, download the community ruleset from the Snort website, and place it in the designated rules directory
1 2 |
# mkdir /usr/local/snort/etc/snort/rules # wget -qO- https://www.snort.org/downloads/community/snort3-community-rules.tar.gz | tar xz -C /usr/local/snort/etc/snort/rules/ |
2.Edit Snort main configuration file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# vi /usr/local/snort/etc/snort/snort.lua Line 24 : change HOME_NET = '192.168.11.0/24' Line 28 : change EXTERNAL_NET = '!$HOME_NET' Add to the end of the ips item per line 183 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 -- (see also related path vars at the top of snort_defaults.lua) variables = default_variables, rules = [[ include /usr/local/snort/etc/snort/rules/snort3-community-rules/snort3-community.rules ]] } |
3.Test Snort's main configuration changes
1 2 3 4 5 6 7 8 |
# /usr/local/snort/bin/snort -c /usr/local/snort/etc/snort/snort.lua If all is well, the next is displayed at the end. -------------------------------------------------- pcap DAQ configured to passive. Snort successfully validated the configuration (with 0 warnings). o")~ Snort exiting |
Adding custom rules
1.Create a file in the Snort rules directory
1 2 3 |
# touch /usr/local/snort/etc/snort/rules/local.rules # vi /usr/local/snort/etc/snort/rules/local.rules alert icmp any any -> $HOME_NET any (msg:"Incoming ICMP"; sid:1000001; rev:1;) |
2.Edit Snort main configuration file
Edit Snort main configuration file to include custom rules file directory in main configuration
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# vi /usr/local/snort/etc/snort/snort.lua Add per line 195 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 -- (see also related path vars at the top of snort_defaults.lua) variables = default_variables, rules = [[ include /usr/local/snort/etc/snort/rules/local.rules include /usr/local/snort/etc/snort/rules/snort3-community-rules/snort3-community.rules ]] } |
3.Test Snort's main configuration changes
1 2 3 4 5 6 7 8 |
# /usr/local/snort/bin/snort -c /usr/local/snort/etc/snort/snort.lua If all is well, the next is displayed at the end. -------------------------------------------------- pcap DAQ configured to passive. Snort successfully validated the configuration (with 0 warnings). o")~ Snort exiting |
Install OpenAppID extension
Once the OpenAppID extension is installed, Snort can detect network threats at the application layer level
1.OpenAppID Extension Download and Deployment
1 2 |
# wget https://www.snort.org/downloads/openappid/33380 -O OpenAppId-33380.tgz # tar -xzvf OpenAppId-33380.tgz |
2.Copy the extracted folder (odp) to the following directory
1 |
# cp -R odp /usr/local/lib/ |
3.Edit the Snort main configuration file to define the location of the OpenAppID folder
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# vi /usr/local/snort/etc/snort/snort.lua Add per line 98 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, } appid_listener = { json_logging = true, file = "/var/log/snort/appid-output.log", } --[[ reputation = |
4.Test Snort's main configuration changes
1 2 3 4 5 6 7 8 |
# /usr/local/snort/bin/snort -c /usr/local/snort/etc/snort/snort.lua If all is well, the next is displayed at the end. -------------------------------------------------- pcap DAQ configured to passive. Snort successfully validated the configuration (with 0 warnings). o")~ Snort exiting |
Verify that all configurations are set up correctly
1 |
# /usr/local/snort/bin/snort -c /usr/local/snort/etc/snort/snort.lua -R /usr/local/snort/etc/snort/rules/local.rules -i ens160 -A alert_fast -s 65535 -k none |
Send a ping command from a remote computer to the IP address of the server. This will cause an alert log to appear in the console window of the host server
1 2 3 |
ID: ICMP] {ICMP} 192.168.11.22 -> 192.168.11.83 04/23-15:42:28.296376 [**] [1:1000001:1] "Incoming ICMP" [**] [Priority: 0] [AppID: ICMP] {ICMP} 192.168.11.22 -> 192.168.11.83 04/23-15:42:28.296437 [**] [1:1000001:1] "Incoming ICMP" [**] [Priority: 0] [AppID: ICMP] {ICMP} 192.168.11.83 -> 192.168.11.22 |
Configure Snort systemd service
1.Creating Users for the Snort Service
1 |
# useradd -r -s /usr/sbin/nologin -M snort |
2.Create log folder and set permissions
Create directory folder for Snort logs and set folder permissions
1 2 3 |
# mkdir /var/log/snort # chmod -R 5775 /var/log/snort # chown -R snort:snort /var/log/snort |
3.Create Systemd service file
1 2 3 4 5 6 7 8 9 10 11 12 13 |
# touch /etc/systemd/system/snort3.service # vi /etc/systemd/system/snort3.service [Unit] Description=Snort3 IDS Daemon Service After=syslog.target network.target [Service] Type=simple ExecStart=/usr/local/snort/bin/snort -c /usr/local/snort/etc/snort/snort.lua -s 65535 -k none -l /var/log/snort -D -i ens160 -m 0x1b -u snort -g snort ExecStop=/bin/kill -9 $MAINPID [Install] WantedBy=multi-user.target |
Reload and activate the Snort service.
1 2 3 |
# systemctl daemon-reload # systemctl enable --now snort3 Created symlink /etc/systemd/system/multi-user.target.wants/snort3.service → /etc/systemd/system/snort3.service. |
Launched Snort service
1 |
# systemctl restart snort3 |
Check Status
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# systemctl status snort3 ● snort3.service - Snort3 IDS Daemon Service Loaded: loaded (/etc/systemd/system/snort3.service; enabled; preset: disab> Active: active (running) since Tue 2024-04-23 16:24:14 JST; 36s ago Main PID: 49021 (snort3) Tasks: 2 (limit: 21868) Memory: 274.2M CPU: 1.110s CGroup: /system.slice/snort3.service mq49021 /usr/local/snort/bin/snort -c /usr/local/snort/etc/snort/s> Apr 23 16:24:14 Lepard snort[49021]: search engine (ac_bnfa) Apr 23 16:24:14 Lepard snort[49021]: instances: 338 Apr 23 16:24:14 Lepard snort[49021]: patterns: 10778 Apr 23 16:24:14 Lepard snort[49021]: pattern chars: 175278 Apr 23 16:24:14 Lepard snort[49021]: num states: 123344 Apr 23 16:24:14 Lepard snort[49021]: num match states: 10498 Apr 23 16:24:14 Lepard snort[49021]: memory scale: MB Apr 23 16:24:14 Lepard snort[49021]: total memory: 3.68713 Apr 23 16:24:14 Lepard snort[49021]: pattern memory: 0.577984 Apr 23 16:24:14 Lepard snort[49021]: match list memory: 1.33597 |
Snort IDS Logging
1.Configure Snort JSON logging
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# vi /usr/local/snort/etc/snort/snort.lua Per line 258 -- 7. Add alert_json at the end of the configure outputs section --------------------------------------------------------------------------- -- 7. configure outputs --------------------------------------------------------------------------- -- event logging -- you can enable with defaults from the command line with -A <alert_type> -- uncomment below to set non-default configs --alert_csv = { } --alert_fast = { } --alert_full = { } --alert_sfsocket = { } --alert_syslog = { } --unified2 = { } -- packet logging -- you can enable with defaults from the command line with -L <log_type> --log_codecs = { } --log_hext = { } --log_pcap = { } -- additional logs --packet_capture = { } --file_log = { } alert_json = { file = true, limit = 50, fields = 'timestamp msg pkt_num proto pkt_gen pkt_len dir src_addr src_port dst_addr dst_port service rule priority class action b64_data' } |
2.Snort restart
1 |
# systemctl restart snort3 |
3.Check log files
Ping command from a remote computer to the server, stored in the Snort alert_json.txt file.
1 2 3 4 5 6 |
# tail -f /var/log/snort/alert_json.txt { "timestamp" : "04/23-16:32:16.515780", "msg" : "Incoming ICMP", "pkt_num" : 1582, "proto" : "ICMP", "pkt_gen" : "raw", "pkt_len" : 60, "dir" : "C2S", "src_addr" : "192.168.11.22", "dst_addr" : "192.168.11.83", "service" : "unk nown", "rule" : "1:1000001:1", "priority" : 0, "class" : "none", "action" : "allow", "b64_data" : "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dndhYmNkZWZnaGk=" } { "timestamp" : "04/23-16:32:16.515780", "msg" : "Incoming ICMP", "pkt_num" : 1583, "proto" : "ICMP", "pkt_gen" : "raw", "pkt_len" : 60, "dir" : "C2S", "src_addr" : "192.168.11.22", "dst_addr" : "192.168.11.83", "service" : "unk nown", "rule" : "1:1000001:1", "priority" : 0, "class" : "none", "action" : "allow", "b64_data" : "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dndhYmNkZWZnaGk=" } { "timestamp" : "04/23-16:32:16.515835", "msg" : "Incoming ICMP", "pkt_num" : 1584, "proto" : "ICMP", "pkt_gen" : "raw", "pkt_len" : 60, "dir" : "S2C", "src_addr" : "192.168.11.83", "dst_addr" : "192.168.11.22", "service" : "unk nown", "rule" : "1:1000001:1", "priority" : 0, "class" : "none", "action" : "allow", "b64_data" : "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dndhYmNkZWZnaGk=" } { "timestamp" : "04/23-16:32:16.515914", "msg" : "Incoming ICMP", "pkt_num" : 1585, "proto" : "ICMP", "pkt_gen" : "raw", "pkt_len" : 60, "dir" : "S2C", "src_addr" : "192.168.11.83", "dst_addr" : "192.168.11.22", "service" : "unk nown", "rule" : "1:1000001:1", "priority" : 0, "class" : "none", "action" : "allow", "b64_data" : "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dndhYmNkZWZnaGk=" } |
This completes the installation and configuration of Snort 3.