{"id":12372,"date":"2022-04-28T23:05:13","date_gmt":"2022-04-28T20:05:13","guid":{"rendered":"https:\/\/kifarunix.com\/?p=12372"},"modified":"2024-03-09T11:45:39","modified_gmt":"2024-03-09T08:45:39","slug":"install-and-setup-suricata-on-ubuntu-22-04-ubuntu-20-04","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-and-setup-suricata-on-ubuntu-22-04-ubuntu-20-04\/","title":{"rendered":"Install and Setup Suricata on Ubuntu 22.04\/Ubuntu 20.04"},"content":{"rendered":"\n
In this tutorial, you will learn how to install and setup Suricata on Ubuntu 22.04\/Ubuntu 20.04. Suricata is an opensource network threat detection tool. Suricata uses rules and signatures to detect threat in network traffic. It also supports Lua scripting language that helps it unearth the most complex would be threats in the network. Suricata is a product of Open Information Security Foundation<\/a>. It is capable of providing NIDS, IPS, NSM and offline pcap processing. It can be integrated with other tools such as BASE, Snorby, Sguil, SQueRT, ELK, SIEM solutions etc.<\/p>\n\n\n\n To see a complete list of features supported by Suricata, you can check all features<\/a>.<\/p>\n\n\n\n There are two ways in which you can install Suricata on Ubuntu;<\/p>\n\n\n\n In this guide, we are going to cover both methods of installing Suricata on Ubuntu 22.04\/Ubuntu 20.04.<\/p>\n\n\n\n Confirm the available versions using the command;<\/p>\n\n\n\n Installation Suricata from the Source on Ubuntu 22.04\/Ubuntu 20.04 is the surest way to get the latest and stable version of Suricata up and running.<\/p>\n\n\n\n To install Suricata from the source, first install all the required dependencies installed.<\/p>\n\n\n\n Suricata function as an IDS out of the box. If you need to include the IPS funtionality, install the following libraries.<\/p>\n\n\n\n Next, download the latest and stable Suricata tarball<\/a>. You can simply download as shown below;<\/p>\n\n\n\n Once the download is complete, extract the tarball.<\/p>\n\n\n\n Navigate to Suricata tarball extract directory to configure Suricata engine for compilation. This ensures that Suricata is build with IPS capabilities.<\/p>\n\n\n\n Summary of the Suricata configuration;<\/p>\n\n\n\n Compile and install the Suricata engine<\/p>\n\n\n\n The If the installation is successful, you should see the output below;<\/p>\n\n\n\n The configuration file is set under Even though Suricata is available on the default Ubuntu 22.04\/Ubuntu 20.04 repositories, it may not be up-to-date.<\/p>\n\n\n\n On the other hand, the OISF PPA repos do not work on Ubuntu 22.04 as of this writing.<\/strong><\/p>\n\n\n\n Thus, the installation of the PPA below is applicable on Ubuntu 20.04 only.<\/strong><\/p>\n\n\n\n As a result, to ensure that you got the latest version installed, you need to add the following PPA repository.<\/p>\n\n\n\n Once the PPA repo is set, install Suricata with the package manager.<\/p>\n\n\n\n As you can see, we have the latest release version of Suricata.<\/p>\n\n\n\n You can then do the installation by executing the command;<\/p>\n\n\n\n jq enables you to read the Suricata eve.json logs<\/p>\n\n\n\n You can instead install Suricata with debugging enabled.<\/p>\n\n\n\n To install Suricata on Ubuntu 22.04 from the default repos, simply run;<\/p>\n\n\n\n That is all with installation.<\/p>\n\n\n\n You can check what configurations options are installed with Suricata;<\/p>\n\n\n\n The command also gets you the version of installed Suricata.<\/p>\n\n\n\n Sample output;<\/p>\n\n\n\n At the end of installation, you will have Suricata rules under The default Suricata configuration file commented well enough to provide a clear understanding of what every setting is for.<\/p>\n\n\n\n To begin with, you need to configure Suricata to differentiate between your internal network to be proctected and external network. This can be done by defining the correct values for the In my case, am using the IP address, You can define multiple networks.<\/p>\n\n\n\n Also, define the interface on which Suricata will use to inspect the traffic. By default, Suricata uses So get your interfaces using the ip command and determine which one to configure Suricata to use.<\/p>\n\n\n\n Sample output;<\/p>\n\n\n\n In my case, will use interface enp0s3. you can also see that the HOME_NET defined is on that interface.<\/p>\n\n\n\n The interfaces can be set by updating the value of interface under af-packets section;<\/p>\n\n\n\n Next, install Suricata Emerging Threat rules.<\/p>\n\n\n\n By default, the Suricata rules are placed under To list the default Suricata rules;<\/p>\n\n\n\n With the default rules, only less detection can be made. Emerging Threat rules are the most comprehensive rule set optimized for the Suricata open source IDS\/IPS engine<\/em><\/strong>.<\/p>\n\n\n\n The default rules will also be loaded by the suricata-update tool.<\/p>\n\n\n\n To install Suricata ET rules, use the NOTE that the ET Open rules are installed automatically when you build Suricata from source and install using the make install-full command.<\/strong><\/p>\n\n\n\n Sample output;<\/p>\n\n\n\n The ET rules are written to Note that Suricata is configured to load Suricata-Update managed rules by default.<\/p>\n\n\n\n If you want to write the ET rules under \/etc\/suricata\/rules\/, specify the output directory on suricata-update command.<\/p>\n\n\n\n You can now start and enable Suricata service to run on system boot.<\/p>\n\n\n\n However, always before you start Suricata, run the configuration check;<\/p>\n\n\n\n In case of any error, fix it before you can start Suricata<\/p>\n\n\n\n If there is no error, then start Suricata;<\/p>\n\n\n\n You can check the status;<\/p>\n\n\n\n We will use the downloaded ET rules to test Suricata detection.<\/p>\n\n\n\n As a test, we are going to demonstrate how to alert on a possible SYN flood using Hping3.<\/p>\n\n\n\n You can install hping3 tool on a separate system or on same system running Suricata;<\/p>\n\n\n\n Before you can proceed, you need to disable packet offload features on the network interface on which Suricata is listen.<\/p>\n\n\n\n If you get the Next, fire Suricata in PCAP live mode by executing the command below.<\/p>\n\n\n\n By the way, there are various modes in which Suricata can run. You can list them by running the command below;<\/p>\n\n\n\n So to run in live PCAP mode, run the commands below. You can change your monitoring interface.<\/p>\n\n\n\n You can omit option Perform a simple DDoS attack test against our Suricata host from a different host.<\/p>\n\n\n\n While Suricata is running on Suricata host and while the DDoS attack test against Suricata host is running p, tail the Suricata alert logs on Suricata host to see what is happening;<\/p>\n\n\n\n You should be able to get some sample alerts;<\/p>\n\n\n\n You can also read the Suricata Eve Json Logs. See examples below.<\/p>\n\n\n\n It is also possible to analyze network traffic packet captures using Suricata.<\/p>\n\n\n\nInstall and Setup Suricata on Ubuntu 22.04\/Ubuntu 20.04<\/h2>\n\n\n\n
\n
apt-cache policy suricata<\/code><\/pre>\n\n\n\n
Install Suricata from Source On Ubuntu 22.04\/Ubuntu 20.04<\/h3>\n\n\n\n
sudo apt -y install libpcre3 libpcre3-dbg libpcre3-dev \\\nbuild-essential autoconf automake libtool libpcap-dev \\\nlibnet1-dev libyaml-0-2 libyaml-dev zlib1g zlib1g-dev \\\nlibcap-ng-dev libcap-ng0 make libmagic-dev \\\nlibjansson-dev libjansson4 pkg-config libnspr4-dev \\\nlibnss3-dev liblz4-dev rustc cargo python3-pip python3-distutils\n<\/code><\/pre>\n\n\n\n
sudo apt -y install libnetfilter-queue-dev libnetfilter-queue1 libnfnetlink-dev libnfnetlink0<\/code><\/pre>\n\n\n\n
wget https:\/\/www.openinfosecfoundation.org\/download\/suricata-6.0.5.tar.gz<\/code><\/pre>\n\n\n\n
tar xzf suricata-6.0.5.tar.gz<\/code><\/pre>\n\n\n\n
cd suricata-6.0.5\n.\/configure --enable-nfqueue --prefix=\/usr --sysconfdir=\/etc --localstatedir=\/var<\/code><\/pre>\n\n\n\n
Suricata Configuration:\n AF_PACKET support: yes\n eBPF support: no\n XDP support: no\n PF_RING support: no\n NFQueue support: no\n NFLOG support: no\n IPFW support: no\n Netmap support: no \n DAG enabled: no\n Napatech enabled: no\n WinDivert enabled: no\n\n Unix socket enabled: yes\n Detection enabled: yes\n\n Libmagic support: yes\n libnss support: yes\n libnspr support: yes\n libjansson support: yes\n hiredis support: no\n hiredis async with libevent: no\n Prelude support: no\n PCRE jit: yes\n LUA support: no\n libluajit: no\n GeoIP2 support: no\n Non-bundled htp: no\n Hyperscan support: no\n Libnet support: yes\n liblz4 support: yes\n HTTP2 decompression: no\n\n Rust support: yes\n Rust strict mode: no\n Rust compiler path: \/usr\/bin\/rustc\n Rust compiler version: rustc 1.57.0\n Cargo path: \/usr\/bin\/cargo\n Cargo version: cargo 1.57.0\n Cargo vendor: yes\n\n Python support: yes\n Python path: \/usr\/bin\/python3\n Python distutils yes\n Python yaml yes\n Install suricatactl: yes\n Install suricatasc: yes\n Install suricata-update: yes\n\n Profiling enabled: no\n Profiling locks enabled: no\n\n Plugin support (experimental): yes\n\nDevelopment settings:\n Coccinelle \/ spatch: no\n Unit tests enabled: no\n Debug output enabled: no\n Debug validation enabled: no\n\nGeneric build parameters:\n Installation prefix: \/usr\n Configuration directory: \/etc\/suricata\/\n Log directory: \/varmake\/log\/suricata\/\n\n --prefix \/usr\n --sysconfdir \/etc\n --localstatedir \/varmake\n --datarootdir \/usr\/share\n\n Host: x86_64-pc-linux-gnu\n Compiler: gcc (exec name) \/ g++ (real)\n GCC Protect enabled: no\n GCC march native enabled: yes\n GCC Profile enabled: no\n Position Independent Executable enabled: no\n CFLAGS -g -O2 -std=c11 -march=native -I${srcdir}\/..\/rust\/gen -I${srcdir}\/..\/rust\/dist\n PCAP_CFLAGS -I\/usr\/include\n SECCFLAGS \n\nTo build and install run 'make' and 'make install'.\n\nYou can run 'make install-conf' if you want to install initial configuration\nfiles to \/etc\/suricata\/. Running 'make install-full' will install configuration\nand rules and provide you a ready-to-run suricata.\n\nTo install Suricata into \/usr\/bin\/suricata, have the config in\n\/etc\/suricata and use \/var\/log\/suricata as log dir, use:\n.\/configure --prefix=\/usr\/ --sysconfdir=\/etc\/ --localstatedir=\/var\/\n<\/code><\/pre>\n\n\n\n
make<\/code><\/pre>\n\n\n\n
make install-full<\/code><\/pre>\n\n\n\n
make install-full<\/code> command will simply install both Suricata initial configuration file and the Suricata rules using the new Suricata rule management tool,
suricata-update<\/code>.<\/p>\n\n\n\n
\ncopying \/root\/suricata-6.0.5\/suricata-update\/scripts-3.10\/suricata-update -> \/usr\/bin\nchanging mode of \/usr\/bin\/suricata-update to 755\nrunning install_egg_info\nWriting \/usr\/lib\/python3.10\/site-packages\/suricata_update-1.2.4-py3.10.egg-info\nmake[3]: Nothing to be done for 'install-data-am'.\nmake[3]: Leaving directory '\/root\/suricata-6.0.5\/suricata-update'\nmake[2]: Leaving directory '\/root\/suricata-6.0.5\/suricata-update'\nmake[2]: Entering directory '\/root\/suricata-6.0.5'\nmake[3]: Entering directory '\/root\/suricata-6.0.5'\nmake[3]: Nothing to be done for 'install-exec-am'.\nRun 'make install-conf' if you want to install initial configuration files. Or 'make install-full' to install configuration and rules\nmake[3]: Leaving directory '\/root\/suricata-6.0.5'\nmake[2]: Leaving directory '\/root\/suricata-6.0.5'\nmake[1]: Leaving directory '\/root\/suricata-6.0.5'\nmake install-conf\nmake[1]: Entering directory '\/root\/suricata-6.0.5'\ninstall -d \"\/etc\/suricata\/\"\ninstall -d \"\/var\/log\/suricata\/files\"\ninstall -d \"\/var\/log\/suricata\/certs\"\ninstall -d \"\/var\/run\/\"\ninstall -m 770 -d \"\/var\/run\/suricata\"\nmake[1]: Leaving directory '\/root\/suricata-6.0.5'\nmake install-rules\nmake[1]: Entering directory '\/root\/suricata-6.0.5'\nLD_LIBRARY_PATH=\/usr\/lib \/usr\/bin\/suricata-update \\\n\t--suricata \/usr\/bin\/suricata \\\n\t--suricata-conf \/etc\/suricata\/suricata.yaml \\\n\t--no-test --no-reload\n28\/4\/2022 -- 22:22:36 -
\/etc\/suricata\/suricata.yaml<\/code> while the default rules are written to
\/etc\/suricata\/rules\/<\/code> and the ET open rules written to
\/var\/lib\/suricata\/rules\/suricata.rules<\/code>.<\/p>\n\n\n\n
Install Suricata on Ubuntu 22.04\/Ubuntu 20.04 from PPA repository<\/h3>\n\n\n\n
sudo add-apt-repository ppa:oisf\/suricata-stable --yes<\/code><\/pre>\n\n\n\n
sudo apt update<\/code><\/pre>\n\n\n\n
apt-cache policy suricata<\/code><\/pre>\n\n\n\n
suricata:\n Installed: (none)\n Candidate: 6.0.5-0ubuntu2\n Version table:\n 6.0.5-0ubuntu2 500\n 500 http:\/\/ppa.launchpad.net\/oisf\/suricata-stable\/ubuntu bionic\/main amd64 Packages\n 3.2-2ubuntu3 500\n 500 http:\/\/us.archive.ubuntu.com\/ubuntu bionic\/universe amd64 Packages\n<\/code><\/pre>\n\n\n\n
sudo apt install suricata jq<\/code><\/pre>\n\n\n\n
sudo apt install suricata-dbg jq<\/code><\/pre>\n\n\n\n
apt install suricata jq<\/code><\/pre>\n\n\n\n
sudo suricata --build-info<\/code><\/pre>\n\n\n\n
This is Suricata version 6.0.5 RELEASE\nFeatures: NFQ PCAP_SET_BUFF AF_PACKET HAVE_PACKET_FANOUT LIBCAP_NG LIBNET1.1 HAVE_HTP_URI_NORMALIZE_HOOK PCRE_JIT HAVE_NSS HAVE_LUA HAVE_LUAJIT HAVE_LIBJANSSON TLS TLS_C11 MAGIC RUST \nSIMD support: none\nAtomic intrinsics: 1 2 4 8 byte(s)\n64-bits, Little-endian architecture\nGCC version 7.5.0, C version 201112\ncompiled with _FORTIFY_SOURCE=2\nL1 cache line size (CLS)=64\nthread local storage method: _Thread_local\ncompiled with LibHTP v0.5.40, linked against LibHTP v0.5.40\n\nSuricata Configuration:\n AF_PACKET support: yes\n eBPF support: no\n XDP support: no\n PF_RING support: no\n NFQueue support: yes\n NFLOG support: no\n IPFW support: no\n Netmap support: no \n DAG enabled: no\n Napatech enabled: no\n WinDivert enabled: no\n\n Unix socket enabled: yes\n Detection enabled: yes\n\n Libmagic support: yes\n libnss support: yes\n libnspr support: yes\n libjansson support: yes\n hiredis support: yes\n hiredis async with libevent: yes\n Prelude support: no\n PCRE jit: yes\n LUA support: yes, through luajit\n libluajit: yes\n GeoIP2 support: yes\n Non-bundled htp: yes\n Hyperscan support: yes\n Libnet support: yes\n liblz4 support: yes\n HTTP2 decompression: no\n\n Rust support: yes\n Rust strict mode: no\n Rust compiler path: \/usr\/bin\/rustc\n Rust compiler version: rustc 1.57.0\n Cargo path: \/usr\/bin\/cargo\n Cargo version: cargo 1.57.0\n Cargo vendor: yes\n\n Python support: yes\n Python path: \/usr\/bin\/python3\n Python distutils yes\n Python yaml yes\n Install suricatactl: yes\n Install suricatasc: yes\n Install suricata-update: yes\n\n Profiling enabled: no\n Profiling locks enabled: no\n\n Plugin support (experimental): yes\n\nDevelopment settings:\n Coccinelle \/ spatch: no\n Unit tests enabled: no\n Debug output enabled: no\n Debug validation enabled: no\n\nGeneric build parameters:\n Installation prefix: \/usr\n Configuration directory: \/etc\/suricata\/\n Log directory: \/var\/log\/suricata\/\n\n --prefix \/usr\n --sysconfdir \/etc\n --localstatedir \/var\n --datarootdir \/usr\/share\n\n Host: x86_64-pc-linux-gnu\n Compiler: gcc (exec name) \/ g++ (real)\n GCC Protect enabled: yes\n GCC march native enabled: no\n GCC Profile enabled: no\n Position Independent Executable enabled: yes\n CFLAGS -g -O2 -fdebug-prefix-map=\/build\/suricata-QUjETh\/suricata-6.0.5=. -fstack-protector-strong -Wformat -Werror=format-security -std=c11 -I${srcdir}\/..\/rust\/gen -I${srcdir}\/..\/rust\/dist\n PCAP_CFLAGS -I\/usr\/include\n SECCFLAGS -fstack-protector -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security\n<\/code><\/pre>\n\n\n\n
Configure Suricata on Ubuntu 22.04\/Ubuntu 20.04<\/h3>\n\n\n\n
\/etc\/suricata\/rules<\/code>\/ and the main configuration file under
\/etc\/suricata\/suricata.yaml<\/code>.<\/p>\n\n\n\n
HOME_NET<\/code> and
EXTERNAL_NET<\/code> variables respectively under the address groups.<\/p>\n\n\n\n
vim \/etc\/suricata\/suricata.yaml<\/code><\/pre>\n\n\n\n
HOME_NET: \"[10.0.2.0\/24]\"\n...\n EXTERNAL_NET: \"!$HOME_NET\"\n...<\/code><\/pre>\n\n\n\n
10.0.2.0\/24<\/code>, as my home network. The external networks are set to any that doesn’t match the home networks.<\/p>\n\n\n\n
eth0<\/code><\/strong> interfaces.<\/p>\n\n\n\n
ip a<\/code><\/pre>\n\n\n\n
\n1: lo:
af-packet:\n - interface: enp0s3<\/strong><\/code><\/pre>\n\n\n\n
\/etc\/suricata\/rules\/<\/strong><\/code> directory. <\/p>\n\n\n\n
ls -1 \/etc\/suricata\/rules\/<\/code><\/pre>\n\n\n\n
app-layer-events.rules\ndecoder-events.rules\ndhcp-events.rules\ndnp3-events.rules\ndns-events.rules\nfiles.rules\nhttp2-events.rules\nhttp-events.rules\nipsec-events.rules\nkerberos-events.rules\nmodbus-events.rules\nmqtt-events.rules\nnfs-events.rules\nntp-events.rules\nsmb-events.rules\nsmtp-events.rules\nstream-events.rules\ntls-events.rules\n<\/code><\/pre>\n\n\n\n
suricata-update<\/code><\/strong> command as shown below;<\/p>\n\n\n\n
sudo suricata-update<\/code><\/pre>\n\n\n\n
\n28\/4\/2022 -- 18:51:21 -
\/var\/lib\/suricata\/rules\/suricata.rules<\/code><\/strong>.<\/p>\n\n\n\n
vim \/etc\/suricata\/suricata.yaml<\/code><\/pre>\n\n\n\n
...\ndefault-rule-path: \/var\/lib\/suricata\/rules\n\nrule-files:\n - suricata.rules\n..<\/code><\/pre>\n\n\n\n
sudo suricata-update -o \/etc\/suricata\/rules\/<\/code><\/pre>\n\n\n\n
Running Suricata on Ubuntu<\/h3>\n\n\n\n
sudo suricata -T -c \/etc\/suricata\/suricata.yaml -v<\/code><\/pre>\n\n\n\n
sudo systemctl enable --now suricata<\/code><\/pre>\n\n\n\n
sudo systemctl status suricata<\/code><\/pre>\n\n\n\n
Testing Suricata Rules<\/h3>\n\n\n\n
sudo apt install hping3<\/code><\/pre>\n\n\n\n
ethtool -K enp0s3 gro off lro off<\/code><\/pre>\n\n\n\n
Cannot change large-receive-offload<\/code>, it means that your interface doesn’t support this feature and it is safe to ignore it. However, you can verify this by running the command below;<\/p>\n\n\n\n
ethtool -k enp0s3 | grep large<\/code><\/pre>\n\n\n\n
large-receive-offload: off [fixed]<\/code><\/pre>\n\n\n\n
suricata --list-runmodes<\/code><\/pre>\n\n\n\n
systemctl stop suricata<\/code><\/pre>\n\n\n\n
rm -rf \/var\/run\/suricata.pid<\/code><\/pre>\n\n\n\n
suricata -D -c \/etc\/suricata\/suricata.yaml -i enp0s3<\/code><\/pre>\n\n\n\n
-D<\/strong><\/code> to run in foreground.<\/p>\n\n\n\n
hping3 -S -p 80 --flood --rand-source 10.0.2.15 -I enp0s3 -c 50<\/code><\/pre>\n\n\n\n
tail -f \/var\/log\/suricata\/fast.log<\/code><\/pre>\n\n\n\n
04\/28\/2022-20:53:23.163746 [**] [1:2400001:3237] ET DROP Spamhaus DROP Listed Traffic Inbound group 2 [**] [Classification: Misc Attack] [Priority: 2] {TCP} 42.133.35.225:16743 -> 10.0.2.15:80\n04\/28\/2022-20:53:23.167683 [**] [1:2400011:3237] ET DROP Spamhaus DROP Listed Traffic Inbound group 12 [**] [Classification: Misc Attack] [Priority: 2] {TCP} 146.51.146.59:16820 -> 10.0.2.15:80\n04\/28\/2022-20:53:23.192930 [**] [1:2400001:3237] ET DROP Spamhaus DROP Listed Traffic Inbound group 2 [**] [Classification: Misc Attack] [Priority: 2] {TCP} 42.171.44.198:16969 -> 10.0.2.15:80\n04\/28\/2022-20:53:23.205414 [**] [1:2400001:3237] ET DROP Spamhaus DROP Listed Traffic Inbound group 2 [**] [Classification: Misc Attack] [Priority: 2] {TCP} 42.160.30.47:17115 -> 10.0.2.15:80\n04\/28\/2022-20:53:23.235223 [**] [1:2400001:3237] ET DROP Spamhaus DROP Listed Traffic Inbound group 2 [**] [Classification: Misc Attack] [Priority: 2] {TCP} 42.219.24.133:17293 -> 10.0.2.15:80\n04\/28\/2022-20:53:23.294544 [**] [1:2400025:3237] ET DROP Spamhaus DROP Listed Traffic Inbound group 26 [**] [Classification: Misc Attack] [Priority: 2] {TCP} 198.56.117.198:17846 -> 10.0.2.15:80\n04\/28\/2022-20:53:23.297399 [**] [1:2400015:3237] ET DROP Spamhaus DROP Listed Traffic Inbound group 16 [**] [Classification: Misc Attack] [Priority: 2] {TCP} 165.102.152.191:17899 -> 10.0.2.15:80\n04\/28\/2022-20:53:23.555831 [**] [1:2400001:3237] ET DROP Spamhaus DROP Listed Traffic Inbound group 2 [**] [Classification: Misc Attack] [Priority: 2] {TCP} 42.222.235.227:20024 -> 10.0.2.15:80\n04\/28\/2022-20:53:23.580783 [**] [1:2400009:3237] ET DROP Spamhaus DROP Listed Traffic Inbound group 10 [**] [Classification: Misc Attack] [Priority: 2] {TCP} 119.232.119.66:20190 -> 10.0.2.15:80\n....\n<\/code><\/pre>\n\n\n\n
Analysing PCAP files using Suricata<\/a><\/h3>\n\n\n\n