웹사이트 검색

Ubuntu 22.04에서 Snort 3 침입 감지 시스템 설치 및 구성


이 페이지에서

  1. 전제 조건
  2. 필수 종속성 설치\n
  3. Snort DAQ 설치
  4. Gperftools 설치
  5. Snort 설치
  6. Snort 구성
  7. Snort NIC용 Systemd 서비스 파일 생성
  8. Snort 규칙 설치
  9. Snort OpenAppID 설치
  10. Snort 맞춤 규칙 만들기
  11. Snort용 Systemd 서비스 파일 생성
  12. 결론

Snort는 DDoS 공격을 방어하기 위한 오픈 소스 침입 방지 및 탐지 시스템(IDS)입니다. 악의적인 네트워크 활동을 정의하는 데 도움이 되는 기본 제공 규칙을 사용하고 이러한 규칙을 사용하여 일치하는 패킷을 찾고 사용자에게 경고를 생성합니다. Snort는 최신 공격, 맬웨어 감염, 손상된 시스템 및 네트워크 정책 위반을 식별할 수 있습니다.

특징

  • 실시간 트래픽 모니터.\n
  • 패킷 로깅. 프로토콜 분석.\n
  • 콘텐츠 일치. OS 지문.
  • 모든 네트워크 환경에 설치가 가능합니다.\n
  • 로그를 생성합니다.\n

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

전제 조건

  • Ubuntu 22.04를 실행하는 서버.\n
  • 루트 암호는 서버에서 구성됩니다.\n

필수 종속성 설치

시작하기 전에 서버에 일부 종속 항목을 설치해야 합니다. 다음 명령을 실행하여 모두 설치할 수 있습니다.

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 libfl-dev -y

모든 종속성이 설치되면 다음 단계로 진행할 수 있습니다.

스노트 DAQ 설치

다음으로 시스템에 Data Acquisition 라이브러리를 설치해야 합니다. 기본적으로 Ubuntu 기본 리포지토리에서는 사용할 수 없습니다. 따라서 소스에서 컴파일해야 합니다.

먼저 다음 명령을 사용하여 Git에서 Snort DAQ를 다운로드합니다.

git clone https://github.com/snort3/libdaq.git

다운로드가 완료되면 다운로드한 디렉토리로 이동하여 다음 명령으로 구성합니다.

cd libdaq
./bootstrap
./configure

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

    cc:             gcc
    cppflags:       
    am_cppflags:     -fvisibility=hidden -Wall -Wmissing-declarations -Wpointer-arith -Wcast-align -Wcast-qual -Wformat -Wformat-nonliteral -Wformat-security -Wundef -Wwrite-strings -Wextra -Wsign-compare -Wno-unused-parameter -fno-strict-aliasing -fdiagnostics-show-option
    cflags:         -g -O2
    am_cflags:       -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -Wnested-externs
    ldflags:        
    am_ldflags:     
    libs:           

    code_coverage_enabled:  no
    code_coverage_cppflags: 
    code_coverage_cflags:   
    code_coverage_ldflags:  

    Build AFPacket DAQ module.. : yes
    Build BPF DAQ module....... : yes
    Build Divert DAQ module.... : no
    Build Dump DAQ module...... : yes
    Build FST DAQ module....... : yes
    Build netmap DAQ module.... : no
    Build NFQ DAQ module....... : yes
    Build PCAP DAQ module...... : yes
    Build Savefile DAQ module.. : yes
    Build Trace DAQ module..... : yes
    Build GWLB DAQ module...... : yes

그런 다음 다음 명령으로 설치하십시오.

make
make install

Gperftools 설치

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

cd
wget https://github.com/gperftools/gperftools/releases/download/gperftools-2.9.1/gperftools-2.9.1.tar.gz

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

tar xzf gperftools-2.9.1.tar.gz

그런 다음 다운로드한 디렉토리로 이동하여 다음 명령을 사용하여 컴파일합니다.

cd gperftools-2.9.1/
./configure

그런 다음 다음 명령으로 설치하십시오.

make
make install

스노트 설치

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

cd
wget https://github.com/snort3/snort3/archive/refs/tags/3.1.43.0.tar.gz

그런 다음 다음 명령을 사용하여 다운로드한 파일의 압축을 풉니다.

tar -xvzf 3.1.43.0.tar.gz

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

cd snort3-3.1.43.0
./configure_cmake.sh --prefix=/usr/local --enable-tcmalloc

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

snort version 3.1.43.0

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  -O2 -g -DNDEBUG
    CXXFLAGS:          -fvisibility=hidden   -DNDEBUG -g -ggdb  -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free  -O2 -g -DNDEBUG
    EXE_LDFLAGS:        
    MODULE_LDFLAGS:     

Feature options:
    DAQ Modules:    Static (afpacket;bpf;dump;fst;gwlb;nfq;pcap;savefile;trace)
    libatomic:      System-provided
    Hyperscan:      OFF
    ICONV:          ON
    Libunwind:      ON
    LZMA:           ON
    RPC DB:         Built-in
    SafeC:          OFF
    TCMalloc:       ON
    JEMalloc:       OFF
    UUID:           ON
-------------------------------------------------------

-- Configuring done
-- Generating done
-- Build files have been written to: /root/snort3-3.1.43.0/build

다음으로 디렉터리를 빌드 디렉터리로 변경하고 다음 명령을 사용하여 Snort를 설치합니다.

cd build
make
make install
ldconfig

이제 다음 명령을 사용하여 Snort 버전을 확인할 수 있습니다.

snort -V

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

   ,,_     -*> Snort++ <*-
  o"  )~   Version 3.1.43.0
   ''''    By Martin Roesch & The Snort Team
           http://snort.org/contact#team
           Copyright (C) 2014-2022 Cisco and/or its affiliates. All rights reserved.
           Copyright (C) 1998-2013 Sourcefire, Inc., et al.
           Using DAQ version 3.0.9
           Using LuaJIT version 2.1.0-beta3
           Using OpenSSL 3.0.2 15 Mar 2022
           Using libpcap version 1.10.1 (with TPACKET_V3)
           Using PCRE version 8.39 2016-06-14
           Using ZLIB version 1.2.11
           Using LZMA version 5.2.5

스노트 구성

먼저, 전송된 모든 네트워크 트래픽을 볼 수 있도록 네트워크 인터페이스를 무차별 모드로 설정해야 합니다.

다음 명령을 사용하여 설정할 수 있습니다.

ip link set dev eth0 promisc on

이제 다음 명령으로 확인할 수 있습니다.

ip add sh eth0

다음으로 인터페이스 오프로딩도 비활성화해야 합니다. 먼저 다음 명령을 사용하여 이 기능이 활성화되어 있는지 확인합니다.

ethtool -k eth0 | grep receive-offload

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

generic-receive-offload: on
large-receive-offload: off [fixed]

이제 다음 명령을 사용하여 비활성화할 수 있습니다.

ethtool -K eth0 gro off lro off

Snort NIC용 Systemd 서비스 파일 생성

다음으로 Snort NIC용 systemd 서비스 파일을 생성해야 합니다.

nano /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 eth0 promisc on
ExecStart=/usr/sbin/ethtool -K eth0 gro off lro off
TimeoutStartSec=0
RemainAfterExit=yes

[Install]
WantedBy=default.target

파일을 저장하고 닫은 다음 systemd 데몬을 다시 로드하여 변경 사항을 적용합니다.

systemctl daemon-reload

다음으로 다음 명령을 사용하여 Snort를 시작하고 활성화합니다.

systemctl start snort3-nic.service
systemctl enable snort3-nic.service

다음 명령을 사용하여 Snort의 상태를 확인할 수 있습니다.

systemctl status snort3-nic.service

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

? snort3-nic.service - Set Snort 3 NIC in promiscuous mode and Disable GRO, LRO on boot
     Loaded: loaded (/etc/systemd/system/snort3-nic.service; disabled; vendor preset: enabled)
     Active: active (exited) since Tue 2022-10-11 16:24:15 UTC; 6s ago
    Process: 95745 ExecStart=/usr/sbin/ip link set dev eth0 promisc on (code=exited, status=0/SUCCESS)
    Process: 95746 ExecStart=/usr/sbin/ethtool -K eth0 gro off lro off (code=exited, status=0/SUCCESS)
   Main PID: 95746 (code=exited, status=0/SUCCESS)
        CPU: 11ms

Oct 11 16:24:15 ubuntu2204 systemd[1]: Starting Set Snort 3 NIC in promiscuous mode and Disable GRO, LRO on boot...
Oct 11 16:24:15 ubuntu2204 systemd[1]: Finished Set Snort 3 NIC in promiscuous mode and Disable GRO, LRO on boot.

Snort 규칙 설치

규칙은 Snorts 침입 탐지 엔진에 매우 중요합니다. 먼저 모든 규칙을 저장할 디렉터리를 만듭니다.

mkdir /usr/local/etc/rules

다음으로 다음 명령을 사용하여 커뮤니티 규칙을 다운로드합니다.

wget -qO- https://www.snort.org/downloads/community/snort3-community-rules.tar.gz | tar xz -C /usr/local/etc/rules/

다음으로 Snort 기본 구성 파일을 편집합니다.

nano /usr/local/etc/snort/snort.lua

아래와 같이 네트워크를 정의합니다.

HOME_NET = '192.168.56.124/32'
EXTERNAL_NET = '!$HOME_NET'

다음으로 Snort 규칙 경로를 정의합니다.

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/etc/rules/snort3-community-rules/snort3-community.rules
    ]]

}

완료되면 파일을 저장하고 닫습니다.

Snort OpenAppID 설치

OpenAppID는 Snort가 네트워크에서 사용되는 Facebook, Netflix, Twitter 및 Reddit과 같은 다양한 애플리케이션을 감지할 수 있도록 하는 플러그인입니다.

다음 명령으로 다운로드할 수 있습니다.

wget https://www.snort.org/downloads/openappid/26425 -O OpenAppId-26425.tgz

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

tar -xzvf OpenAppId-26425.tgz

다음으로 OpenAppID 바이너리 파일을 시스템 디렉터리에 복사합니다.

cp -R odp /usr/local/lib/

다음으로 Snort 구성 파일을 편집하고 OpenAppID 위치를 정의합니다.

nano /usr/local/etc/snort/snort.lua

다음 줄을 변경합니다.

appid =
{
    app_detector_dir = '/usr/local/lib',
    log_stats = true,

}

파일을 저장하고 닫은 다음 Snort 로그 디렉터리를 만듭니다.

mkdir /var/log/snort

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

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

모든 것이 정상이면 다음과 같은 결과가 표시됩니다.

--------------------------------------------------
fast pattern groups
                      src: 59
                      dst: 158
                      any: 4
                to_server: 56
                to_client: 39
--------------------------------------------------
search engine
                instances: 316
                 patterns: 10282
            pattern chars: 166369
               num states: 112212
         num match states: 9885
             memory scale: MB
             total memory: 3.42574
           pattern memory: 0.550588
        match list memory: 1.25256
        transition memory: 1.58402
        fast pattern only: 6822
--------------------------------------------------
pcap DAQ configured to passive.

Snort successfully validated the configuration (with 0 warnings).
o")~   Snort exiting

Snort 사용자 지정 규칙 만들기

요구 사항에 따라 고유한 사용자 지정 규칙을 만들 수도 있습니다. 들어오는 ICMP 요청에 대한 사용자 지정 규칙을 만들 수 있습니다.

nano /usr/local/etc/rules/local.rules

다음 줄을 추가합니다.

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

그런 다음 다음 명령을 사용하여 규칙을 확인합니다.

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

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

search engine
                instances: 316
                 patterns: 10282
            pattern chars: 166369
               num states: 112212
         num match states: 9885
             memory scale: MB
             total memory: 3.42574
           pattern memory: 0.550588
        match list memory: 1.25256
        transition memory: 1.58402
        fast pattern only: 6822
--------------------------------------------------
pcap DAQ configured to passive.

Snort successfully validated the configuration (with 0 warnings).
o")~   Snort exiting

그런 다음 다음 명령을 실행하여 사용자 지정 규칙을 사용하여 네트워크 인터페이스에서 Snort를 시작합니다.

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

그런 다음 다른 터미널 인터페이스를 열고 서버를 ping하십시오. 첫 번째 터미널에 ICMP 오류가 표시되어야 합니다.

10/11-16:45:23.848071 [**] [1:1000001:1] "ICMP connection test" [**] [Priority: 0] [AppID: ICMP] {ICMP} 157.32.34.228 -> 209.23.11.18
10/11-16:45:23.848071 [**] [1:384:8] "PROTOCOL-ICMP PING" [**] [Classification: Misc activity] [Priority: 3] [AppID: ICMP] {ICMP} 157.32.34.228 -> 209.23.11.18
10/11-16:45:24.323038 [**] [1:366:11] "PROTOCOL-ICMP PING Unix" [**] [Classification: Misc activity] [Priority: 3] [AppID: ICMP] {ICMP} 157.32.34.228 -> 209.23.11.18
10/11-16:45:24.323038 [**] [1:1000001:1] "ICMP connection test" [**] [Priority: 0] [AppID: ICMP] {ICMP} 157.32.34.228 -> 209.23.11.18
10/11-16:45:24.323038 [**] [1:384:8] "PROTOCOL-ICMP PING" [**] [Classification: Misc activity] [Priority: 3] [AppID: ICMP] {ICMP} 157.32.34.228 -> 209.23.11.18
^C** caught int signal
== stopping
10/11-16:45:25.353007 [**] [1:366:11] "PROTOCOL-ICMP PING Unix" [**] [Classification: Misc activity] [Priority: 3] [AppID: ICMP] {ICMP} 157.32.34.228 -> 209.23.11.18
10/11-16:45:25.353007 [**] [1:1000001:1] "ICMP connection test" [**] [Priority: 0] [AppID: ICMP] {ICMP} 157.32.34.228 -> 209.23.11.18
10/11-16:45:25.353007 [**] [1:384:8] "PROTOCOL-ICMP PING" [**] [Classification: Misc activity] [Priority: 3] [AppID: ICMP] {ICMP} 157.32.34.228 -> 209.23.11.18

Snort용 Systemd 서비스 파일 생성

다음으로 systemd를 통해 Snort를 관리할 systemd 서비스 파일을 만듭니다.

nano /etc/systemd/system/snort3.service

다음 구성을 추가합니다.

[Unit]
Description=Snort 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 eth0 -m 0x1b -u root -g root
ExecStop=/bin/kill -9 $MAINPID

[Install]
WantedBy=multi-user.target

파일을 저장하고 닫은 후 다음 명령을 사용하여 systemd 데몬을 다시 로드합니다.

systemctl daemon-reload

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

systemctl enable --now snort3

이제 다음 명령을 사용하여 Snort의 상태를 확인할 수 있습니다.

systemctl status snort3

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

? snort3.service - Snort Daemon
     Loaded: loaded (/etc/systemd/system/snort3.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2022-10-11 16:48:28 UTC; 17s ago
   Main PID: 95898 (snort)
      Tasks: 2 (limit: 4579)
     Memory: 233.6M
        CPU: 2.007s
     CGroup: /system.slice/snort3.service
             ??95898 /usr/local/bin/snort -c /usr/local/etc/snort/snort.lua -s 65535 -k none -l /var/log/snort -D -i eth0 -m 0x1b -u root -g >

Oct 11 16:48:29 ubuntu2204 snort[95898]:          num match states: 9885
Oct 11 16:48:29 ubuntu2204 snort[95898]:              memory scale: MB
Oct 11 16:48:29 ubuntu2204 snort[95898]:              total memory: 3.42574
Oct 11 16:48:29 ubuntu2204 snort[95898]:            pattern memory: 0.550588
Oct 11 16:48:29 ubuntu2204 snort[95898]:         match list memory: 1.25256
Oct 11 16:48:29 ubuntu2204 snort[95898]:         transition memory: 1.58402
Oct 11 16:48:29 ubuntu2204 snort[95898]:         fast pattern only: 6822
Oct 11 16:48:29 ubuntu2204 snort[95898]: --------------------------------------------------
Oct 11 16:48:29 ubuntu2204 snort[95898]: pcap DAQ configured to passive.
Oct 11 16:48:29 ubuntu2204 snort[95898]: Commencing packet processing

결론

축하합니다! Ubuntu 22.04에 Snort 3를 성공적으로 설치하고 구성했습니다. 이제 조직에서 Snort를 구현하고 DDoS 공격으로부터 보호할 수 있습니다. 궁금한 점이 있으면 언제든지 문의해 주세요.