Suricata là phần mềm phân tích mạng và phát hiện mối đe dọa miễn phí và mã nguồn mở do OSIF phát triển. Nó có thể được sử dụng như một hệ thống phát hiện xâm nhập (IDS) và một hệ thống ngăn chặn xâm nhập (IPS). Nó sử dụng một bộ quy tắc và ngôn ngữ chữ ký để phát hiện và ngăn chặn các mối đe dọa. Nó là một giải pháp thay thế cho Snort và có thể cung cấp cái nhìn sâu sắc tuyệt vời về những gì đang xảy ra trên mạng của bạn từ góc độ bảo mật.
Trong hướng dẫn này, tôi sẽ chỉ cho bạn cách cài đặt Suricata trên máy chủ Ubuntu 22.04.
Sau khi tất cả các gói được cập nhật, hãy chạy lệnh sau để cài đặt tất cả các phụ thuộc cần thiết:
Sau khi hoàn tất, bạn có thể tiến hành bước tiếp theo.
Sau khi tải xuống hoàn tất, giải nén tệp đã tải xuống bằng lệnh sau:
Tiếp theo, điều hướng đến thư mục đã giải nén và định cấu hình thư mục đó bằng lệnh sau:
Bạn sẽ nhận được thông tin sau đầu ra:
Tiếp theo, cài đặt Suricata bằng lệnh sau:
Bạn sẽ nhận được thông tin sau đầu ra:
Tiếp theo, hãy thêm kho lưu trữ Suricata bằng lệnh sau:
Tiếp theo, hãy cập nhật bộ đệm kho lưu trữ bằng lệnh sau lệnh:
Tiếp theo, xác minh gói Suricata bằng lệnh sau:
Bạn sẽ nhận được thông báo sau đầu ra:
Cuối cùng, cài đặt Suricata bằng lệnh sau:
Bây giờ bạn có thể xác minh thông tin gói Suricata bằng cách sử dụng lệnh sau lệnh:
Bạn sẽ nhận được kết quả sau:
Thay đổi các mục sau dòng:
Lưu và đóng tệp sau đó cập nhật cấu hình Suricata bằng lệnh sau:
Tiếp theo, xác minh tệp cấu hình Suricata bằng lệnh sau lệnh:
Bạn sẽ nhận được kết quả sau:
Tiếp theo, hãy khởi động và kích hoạt dịch vụ Suricata bằng lệnh sau lệnh:
Bạn cũng có thể kiểm tra dịch vụ Suricata bằng lệnh sau:
Bạn sẽ thấy thông báo sau đầu ra:
Bạn cũng có thể xem nhiều chế độ chạy khác nhau bằng lệnh sau:
Bạn sẽ nhận được đầu ra sau:
Bạn có thể tắt tính năng này bằng lệnh sau:
Tiếp theo, dừng Suricata bằng lệnh sau lệnh:
Tiếp theo, chạy Suricata theo cách thủ công bằng lệnh sau:
Tiếp theo, đăng nhập vào hệ thống từ xa và chạy lệnh hping3 để thực hiện một cuộc tấn công DDoS đơn giản vào Suricata máy chủ:
Tiếp theo, quay lại máy chủ Suricata và kiểm tra tệp nhật ký Suricata:
Bạn sẽ thấy thông báo sau output:
Trong hướng dẫn này, tôi sẽ chỉ cho bạn cách cài đặt Suricata trên máy chủ Ubuntu 22.04.
Yêu cầu
- Một máy chủ chạy Ubuntu 22.04.
- Mật khẩu gốc được cấu hình trên máy chủ của bạn.
Bắt đầu
Trước khi bắt đầu, bạn nên cập nhật các gói hệ thống của mình lên phiên bản mới nhất. Bạn có thể cập nhật tất cả chúng bằng cách chạy lệnh sau:
Mã:
apt update -y
apt upgrade -y
Mã:
apt install libpcre3 libpcre3-dbg libpcre3-dev build-essential autoconf automake libtool libpcap-dev libnet1-dev libyaml-0-2 libyaml-dev zlib1g zlib1g-dev libcap-ng-dev libcap-ng0 make libmagic-dev libjansson-dev libjansson4 pkg-config libnspr4-dev libnss3-dev liblz4-dev rustc cargo python3-pip python3-distutils
apt install libnetfilter-queue-dev libnetfilter-queue1 libnfnetlink-dev libnfnetlink0
Cài đặt Suricata từ Source
Trước tiên, hãy tải xuống phiên bản Suricata mới nhất bằng lệnh sau:
Mã:
wget https://www.openinfosecfoundation.org/download/suricata-6.0.8.tar.gz
Mã:
tar xzf suricata-6.0.8.tar.gz
Mã:
cd suricata-6.0.8
./configure --enable-nfqueue --prefix=/usr --sysconfdir=/etc --localstatedir=/var
Mã:
Host: x86_64-pc-linux-gnu Compiler: gcc (exec name) / g++ (real) GCC Protect enabled: no GCC march native enabled: yes GCC Profile enabled: no Position Independent Executable enabled: no CFLAGS -g -O2 -std=c11 -march=native -I${srcdir}/../rust/gen -I${srcdir}/../rust/dist PCAP_CFLAGS -I/usr/include SECCFLAGS
To build and install run 'make' and 'make install'.
You can run 'make install-conf' if you want to install initial configuration
files to /etc/suricata/. Running 'make install-full' will install configuration
and rules and provide you a ready-to-run suricata.
To install Suricata into /usr/bin/suricata, have the config in
/etc/suricata and use /var/log/suricata as log dir, use:
./configure --prefix=/usr/ --sysconfdir=/etc/ --localstatedir=/var/
Mã:
make
make install-full
Mã:
You can now start suricata by running as root something like: /usr/bin/suricata -c /etc/suricata/suricata.yaml -i eth0
If a library like libhtp.so is not found, you can run suricata with: LD_LIBRARY_PATH=/usr/lib /usr/bin/suricata -c /etc/suricata/suricata.yaml -i eth0
The Emerging Threats Open rules are now installed. Rules can be
updated and managed with the suricata-update tool.
For more information please see: https://suricata.readthedocs.io/en/latest/rule-management/index.html
make[1]: Leaving directory '/root/suricata-6.0.8'
Cài đặt Suricata từ Kho lưu trữ Ubuntu
Bạn cũng có thể cài đặt Suricata từ kho lưu trữ Ubuntu. Trước tiên, hãy cài đặt tất cả các phần phụ thuộc bằng lệnh sau:
Mã:
apt install gnupg2 software-properties-common curl wget git unzip -y
Mã:
add-apt-repository ppa:oisf/suricata-stable --yes
Mã:
apt update
Mã:
apt-cache policy suricata
Mã:
suricata: Installed: (none) Candidate: 1:6.0.4-3 Version table: 1:6.0.4-3 500 500 http://us.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
Mã:
apt install suricata jq
Mã:
suricata --build-info
Mã:
This is Suricata version 6.0.8 RELEASE
Features: NFQ PCAP_SET_BUFF AF_PACKET HAVE_PACKET_FANOUT LIBCAP_NG LIBNET1.1 HAVE_HTP_URI_NORMALIZE_HOOK PCRE_JIT HAVE_NSS HAVE_LIBJANSSON TLS TLS_C11 MAGIC RUST
SIMD support: SSE_3
Atomic intrinsics: 1 2 4 8 16 byte(s)
64-bits, Little-endian architecture
GCC version 11.2.0, C version 201112
compiled with _FORTIFY_SOURCE=2
L1 cache line size (CLS)=64
thread local storage method: _Thread_local
compiled with LibHTP v0.5.41, linked against LibHTP v0.5.41
Suricata Configuration: AF_PACKET support: yes eBPF support: no XDP support: no PF_RING support: no NFQueue support: yes NFLOG support: no IPFW support: no Netmap support: no DAG enabled: no Napatech enabled: no WinDivert enabled: no Unix socket enabled: yes Detection enabled: yes
Cấu hình Suricata
Tiếp theo, chỉnh sửa tệp cấu hình Suricata và xác định giao diện mạng và mạng của bạn:
Mã:
nano /etc/suricata/suricata.yaml
Mã:
HOME_NET: "[10.0.2.0/24]" EXTERNAL_NET: "!$HOME_NET"
af-packet: - interface: eth0
# - sip sip: enabled: no
Mã:
suricata-update
Mã:
suricata -T -c /etc/suricata/suricata.yaml -v
Mã:
18/10/2022 -- 13:45:14 - - fast output device (regular) initialized: fast.log
18/10/2022 -- 13:45:14 - - eve-log output device (regular) initialized: eve.json
18/10/2022 -- 13:45:14 - - stats output device (regular) initialized: stats.log
18/10/2022 -- 13:45:14 - - SSSE3 support not detected, disabling Hyperscan for SPM
18/10/2022 -- 13:45:16 - - 1 rule files processed. 28624 rules successfully loaded, 0 rules failed
18/10/2022 -- 13:45:16 - - Threshold config parsed: 0 rule(s) found
18/10/2022 -- 13:45:16 - - 28627 signatures processed. 1219 are IP-only rules, 5166 are inspecting packet payload, 22038 inspect application layer, 108 are decoder event only
18/10/2022 -- 13:45:19 - - Configuration provided was successfully loaded. Exiting.
18/10/2022 -- 13:45:19 - - cleaning up signature grouping structure... complete
Mã:
systemctl enable --now suricata
Mã:
systemctl status suricata
Mã:
? suricata.service - LSB: Next Generation IDS/IPS Loaded: loaded (/etc/init.d/suricata; generated) Active: active (running) since Tue 2022-10-18 13:38:52 UTC; 6min ago Docs: man:systemd-sysv-generator(8) Process: 16504 ExecStart=/etc/init.d/suricata start (code=exited, status=0/SUCCESS) Tasks: 7 (limit: 2242) Memory: 40.0M CPU: 4.073s CGroup: /system.slice/suricata.service ??16514 /usr/bin/suricata -c /etc/suricata/suricata.yaml --pidfile /var/run/suricata.pid --af-packet -D -vvv
Oct 18 13:38:52 ubuntu2204 systemd[1]: Starting LSB: Next Generation IDS/IPS...
Oct 18 13:38:52 ubuntu2204 suricata[16504]: Starting suricata in IDS (af-packet) mode... done.
Oct 18 13:38:52 ubuntu2204 systemd[1]: Started LSB: Next Generation IDS/IPS.
Mã:
suricata --list-runmodes
Mã:
------------------------------------- Runmodes ------------------------------------------
| RunMode Type | Custom Mode | Description
|----------------------------------------------------------------------------------------
| PCAP_DEV | single | Single threaded pcap live mode
| ---------------------------------------------------------------------
| | autofp | Multi threaded pcap live mode. Packets from each flow are assigned to a single detect thread, unlike "pcap_live_auto" where packets from the same flow can be processed by any detect thread
| ---------------------------------------------------------------------
| | workers | Workers pcap live mode, each thread does all tasks from acquisition to logging
|----------------------------------------------------------------------------------------
| PCAP_FILE | single | Single threaded pcap file mode
| ---------------------------------------------------------------------
| | autofp | Multi threaded pcap file mode. Packets from each flow are assigned to a single detect thread, unlike "pcap-file-auto" where packets from the same flow can be processed by any detect thread
|----------------------------------------------------------------------------------------
| PFRING(DISABLED) | autofp | Multi threaded pfring mode. Packets from each flow are assigned to a single detect thread, unlike "pfring_auto" where packets from the same flow can be processed by any detect thread
| ---------------------------------------------------------------------
| | single | Single threaded pfring mode
| ---------------------------------------------------------------------
| | workers | Workers pfring mode, each thread does all tasks from acquisition to logging
|----------------------------------------------------------------------------------------
Xác minh Suricata
Trước khi xác minh Suricata, bạn sẽ cần tắt tính năng chuyển gói tin trên giao diện mạng.Bạn có thể tắt tính năng này bằng lệnh sau:
Mã:
ethtool -K eth0 gro off lro off
Mã:
systemctl stop suricata
rm -rf /var/run/suricata.pid
Mã:
suricata -D -c /etc/suricata/suricata.yaml -i eth0
Mã:
hping3 -S -p 80 --flood --rand-source suricata-ip -I eth0 -c 50
Mã:
tail -f /var/log/suricata/fast.log
Mã:
10/18/2022-14:01:38.569298 [**] [1:2210008:2] SURICATA STREAM 3way handshake SYN resend different seq on SYN recv [**] [Classification: Generic Protocol Command Decode] [Priority: 3] {TCP} 157.32.37.21:59188 -> 209.23.10.188:80
10/18/2022-14:01:38.569304 [**] [1:2210004:2] SURICATA STREAM 3way handshake SYNACK resend with different ack [**] [Classification: Generic Protocol Command Decode] [Priority: 3] {TCP} 209.23.10.188:80 -> 157.32.37.21:59188
10/18/2022-14:01:38.569649 [**] [1:2210008:2] SURICATA STREAM 3way handshake SYN resend different seq on SYN recv [**] [Classification: Generic Protocol Command Decode] [Priority: 3] {TCP} 157.32.37.21:53343 -> 209.23.10.188:80
10/18/2022-14:01:38.569655 [**] [1:2210004:2] SURICATA STREAM 3way handshake SYNACK resend with different ack [**] [Classification: Generic Protocol Command Decode] [Priority: 3] {TCP} 209.23.10.188:80 -> 157.32.37.21:53343
10/18/2022-14:01:38.570762 [**] [1:2210008:2] SURICATA STREAM 3way handshake SYN resend different seq on SYN recv [**] [Classification: Generic Protocol Command Decode] [Priority: 3] {TCP} 157.32.37.21:62070 -> 209.23.10.188:80
10/18/2022-14:01:38.570770 [**] [1:2210004:2] SURICATA STREAM 3way handshake SYNACK resend with different ack [**] [Classification: Generic Protocol Command Decode] [Priority: 3] {TCP} 209.23.10.188:80 -> 157.32.37.21:62070
10/18/2022-14:01:38.571748 [**] [1:2210008:2] SURICATA STREAM 3way handshake SYN resend different seq on SYN recv [**] [Classification: Generic Protocol Command Decode] [Priority: 3] {TCP} 157.32.37.21:5001 -> 209.23.10.188:80