웹사이트 검색

Ubuntu 22.04에 Suricata IDS를 설치하는 방법


이 페이지에서

  1. 요구 사항\n
  2. 시작하기\n
  3. 소스에서 Suricata 설치
  4. Ubuntu 저장소에서 Suricata 설치
  5. Suricata 구성
  6. Suricata 확인\n
  7. 결론

Suricata는 OSIF에서 개발한 무료 오픈 소스 네트워크 분석 및 위협 탐지 소프트웨어입니다. 침입탐지시스템(IDS)과 침입방지시스템(IPS)으로 활용할 수 있다. 규칙 집합과 서명 언어를 사용하여 위협을 탐지하고 방지합니다. 이것은 Snort의 대안이며 보안 관점에서 네트워크에서 발생하는 상황에 대한 뛰어난 통찰력을 제공할 수 있습니다.

이 튜토리얼에서는 Ubuntu 22.04 서버에 Suricata를 설치하는 방법을 보여줍니다.

요구 사항

  • Ubuntu 22.04를 실행하는 서버.\n
  • 서버에 루트 암호가 구성되어 있습니다.\n

시작하기

시작하기 전에 시스템 패키지를 최신 버전으로 업데이트하는 것이 좋습니다. 다음 명령을 실행하여 모두 업데이트할 수 있습니다.

apt update -y
apt upgrade -y

모든 패키지가 업데이트되면 다음 명령을 실행하여 필요한 모든 종속성을 설치합니다.

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

완료되면 다음 단계로 진행할 수 있습니다.

소스에서 Suricata 설치

먼저 다음 명령을 사용하여 최신 버전의 Suricata를 다운로드합니다.

wget https://www.openinfosecfoundation.org/download/suricata-6.0.8.tar.gz

다운로드가 완료되면 다음 명령을 사용하여 다운로드한 파일의 압축을 풉니다.

tar xzf suricata-6.0.8.tar.gz

그런 다음 추출된 디렉터리로 이동하고 다음 명령을 사용하여 구성합니다.

cd suricata-6.0.8
./configure --enable-nfqueue --prefix=/usr --sysconfdir=/etc --localstatedir=/var

다음과 같은 결과가 표시됩니다.

  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/

다음으로 다음 명령을 사용하여 Suricata를 설치합니다.

make
make install-full

다음과 같은 결과가 표시됩니다.

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'

우분투 리포지토리에서 Suricata 설치

Ubuntu 리포지토리에서 Suricata를 설치할 수도 있습니다. 먼저 다음 명령을 사용하여 모든 종속 항목을 설치합니다.

apt install gnupg2 software-properties-common curl wget git unzip -y

다음으로 다음 명령을 사용하여 Suricata 리포지토리를 추가합니다.

add-apt-repository ppa:oisf/suricata-stable --yes

다음으로 다음 명령을 사용하여 리포지토리 캐시를 업데이트합니다.

apt update

다음으로 다음 명령을 사용하여 Suricata 패키지를 확인합니다.

apt-cache policy suricata

다음과 같은 결과가 표시됩니다.

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

마지막으로 다음 명령을 사용하여 Suricata를 설치합니다.

apt install suricata jq

이제 다음 명령을 사용하여 Suricata 패키지 정보를 확인할 수 있습니다.

suricata --build-info

다음 출력이 표시되어야 합니다.

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

Suricata 구성

다음으로 Suricata 구성 파일을 편집하고 네트워크 인터페이스와 네트워크를 정의합니다.

nano /etc/suricata/suricata.yaml

다음 줄을 변경합니다.

    HOME_NET: "[10.0.2.0/24]"

    EXTERNAL_NET: "!$HOME_NET"

af-packet:
  - interface: eth0
#        - sip
    sip:
    enabled: no

파일을 저장하고 닫은 후 다음 명령을 사용하여 Suricata 구성을 업데이트합니다.

suricata-update

다음으로 다음 명령을 사용하여 Suricata 구성 파일을 확인합니다.

suricata -T -c /etc/suricata/suricata.yaml -v

다음과 같은 결과가 표시됩니다.

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

그런 다음 다음 명령을 사용하여 Suricata 서비스를 시작하고 활성화합니다.

systemctl enable --now suricata

다음 명령을 사용하여 Suricata 서비스를 확인할 수도 있습니다.

systemctl status suricata

다음 출력이 표시되어야 합니다.

? 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.

다음 명령을 사용하여 다양한 실행 모드를 볼 수도 있습니다.

suricata --list-runmodes

다음과 같은 결과가 표시됩니다.

------------------------------------- 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 
|----------------------------------------------------------------------------------------

Suricata 확인

Suricata를 확인하기 전에 네트워크 인터페이스에서 패킷 오프로드 기능을 비활성화해야 합니다.

다음 명령으로 비활성화할 수 있습니다.

ethtool -K eth0 gro off lro off

그런 다음 다음 명령을 사용하여 Suricata를 중지합니다.

systemctl stop suricata
rm -rf /var/run/suricata.pid

다음으로 다음 명령을 사용하여 Suricata를 수동으로 실행합니다.

suricata -D -c /etc/suricata/suricata.yaml -i eth0

다음으로 원격 시스템에 로그인하고 hping3 명령을 실행하여 Suricata 서버에 대해 간단한 DDoS 공격을 수행합니다.

hping3 -S -p 80 --flood --rand-source suricata-ip -I eth0 -c 50

그런 다음 Suricata 서버로 돌아가 Suricata 로그 파일을 확인합니다.

tail -f /var/log/suricata/fast.log

다음 출력이 표시되어야 합니다.

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

결론

이 게시물에서는 Ubuntu 22.04에 Suricata를 설치하는 방법을 배웠습니다. 이제 조직에서 Suricata를 구현하여 DDoS 공격으로부터 서버를 보호할 수 있습니다. 궁금한 점이 있으면 언제든지 문의해 주세요.