jegong 2023. 7. 12. 11:37

인터넷 ---- 방화벽 ----WAN(라우터)LAN----IPS-------스위츠-------------호스트

                 ASA                                      pfsense    ScurityOnion        Selinux/iptables

                                                                                  N-IDS                firewalld / ufv 

                                                                                                           -------- H-IDS

                                                                                                            tcpwrapper 

                                                                                                            apache(httpd)+security

 

IDS ---> 솔루션 : Snort (정보보안기사 실기에도 나와요 ) 

우리 지금 2.0 쓸거야 , 3.0이 이미 2.0기반으로 만들어졌다

https://snort.org/downloads 

 

Snort Rules and IDS Software Download

Security Onion is a Linux distro for intrusion detection, network security monitoring, and log management. It's based on Ubuntu and contains Snort, Suricata, Bro, OSSEC, Sguil, Squert, Snorby, ELSA, Xplico, NetworkMiner, and many other security tools. The

snort.org

탐지만 하면 IDS 

차단하면 IPS 

snort 설치를 위한 기본 패키지 설치 (이 패킷들을 다 알고 정의해야돼) 

 sudo yum install -y gcc flex zlib libcap pcre libdnet tcpdump

Installed:
  flex.x86_64 0:2.5.37-6.el7                gcc.x86_64 0:4.8.5-44.el7
  libdnet.x86_64 0:1.12-13.1.el7

Dependency Installed:
  cpp.x86_64 0:4.8.5-44.el7
  glibc-devel.x86_64 0:2.17-326.el7_9
  glibc-headers.x86_64 0:2.17-326.el7_9
  kernel-headers.x86_64 0:3.10.0-1160.92.1.el7
  m4.x86_64 0:1.4.16-10.el7

Complete!
[root@localhost ~]#

epel-release 있는지 확인 

[root@localhost ~]# yum -y install epel-release
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror.kakao.com
 * centos-sclo-rh: mirror.kakao.com
 * centos-sclo-sclo: mirror.kakao.com
 * epel: mirror-icn.yuki.net.uk
 * extras: mirror.kakao.com
 * remi: cdn.centos.no
 * remi-php55: cdn.centos.no
 * remi-php56: cdn.centos.no
 * remi-php74: cdn.centos.no
 * remi-safe: cdn.centos.no
 * remi-test: cdn.centos.no
 * updates: mirror.kakao.com
Package epel-release-7-14.noarch already installed and latest version
Nothing to do
[root@localhost ~]#

http 프로토콜의 종류 동작 방식들 원래 공부해야돼 

yum -y install libnghttp2

에러 발생시 

yum makecache

하고 다시 하면 에러 안나 

이제 snort 설치 위한 기본 준비는 완료 

-DAQ 데이터 수집 

패키지들이 모여 있데 

rpm 패키지 다운로드 사이트 https://rpmfind.net/linux/rpm2html/search.php?query=daq&submit=Search+... 

 

RPM resource daq

 

rpmfind.net

설치 방법 1 

wget https://rpmfind.net/linux/epel/7/x86_64/Packages/d/daq-2.0.6-1.el7.x86_64.rpm

rpm -Uvh daq.............

이 방법을 안쓴다 

설치 방법 2 

yum -y install https://rpmfind.net/linux/epel/7/x86_64/Packages/d/daq-2.0.6-1.el7.x86_64.rpm

설치 방법 3 

yum 

진짜 snort 설치 

wget https://www.snort.org/downloads/snort/snort-2.9.20-1.centos.x86_64.rpm

yum -y install snort-2.9.20-1.centos.x86_64.rpm   

적용 sudo ldconfig

[root@localhost ~]# snort
snort: error while loading shared libraries: libdnet.1: cannot open shared object file: No such file or directory
[root@localhost ~]# find / -name "libdnet*"
find: ‘/run/user/1000/gvfs’: 허가 거부

/usr/lib64/libdnet.so.1.0.1
/usr/lib64/libdnet.so.1
/usr/share/doc/libdnet-1.12
^C
[root@localhost ~]#

snort 할때 위처럼 에러 나면  libdnet 찾아줘야돼 

해결 방법 

ln -s /usr/lib64/libdnet.so.1.0.1 /usr/lib64/libdnet.1 (절대 경로로 만들어줘야돼 ) 

이건 링크 방식으로 하나도 더 만들어주는 거야 

[root@localhost ~]# snort
Running in packet dump mode

        --== Initializing Snort ==--
Initializing Output Plugins!
pcap DAQ configured to passive.
Acquiring network traffic from "virbr0".
Decoding Ethernet

        --== Initialization Complete ==--

   ,,_     -*> Snort! <*-
  o"  )~   Version 2.9.20 GRE (Build 82)
   ''''    By Martin Roesch & The Snort Team: http://www.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 libpcap version 1.5.3
           Using PCRE version: 8.32 2012-11-30
           Using ZLIB version: 1.2.7

Commencing packet processing (pid=11218)

정상적인 snort 설치 완료 

 

snort 위치 추적 

[root@localhost ~]# which snort
/usr/sbin/snort

여기 있다 

snort 는  snort:snort 라는 계정을 만든다 

[root@localhost ~]# cat /etc/passwd | grep snort
snort:x:1010:1010:Snort:/var/log/snort:/bin/false
[root@localhost ~]#  ---> 확인 

 

우리는 지금 패키지 설정 했는데 소스 설정을 하면 이 계정이 안될때가 있어 

그러면은 

useradd snort -s /bin/false -c Snort -g snort -d /var/log/snort   ---> 지금은 할 필요가 없어 

확인 사항 

 

etc/snort 확인 

[root@localhost ~]# cd /etc/snort
[root@localhost snort]# ll
합계 236
-rw-r--r-- 1 root root   3757  4월 20  2022 classification.config
-rw-r--r-- 1 root root  33339  4월 20  2022 gen-msg.map
-rw-r--r-- 1 root root    687  4월 20  2022 reference.config
drwxr-xr-x 2 root root      6  5월 24  2022 rules
-rw-r--r-- 1 root root  26812  5월 24  2022 snort.conf
-rw-r--r-- 1 root root   2335  4월 20  2022 threshold.conf
-rw-r--r-- 1 root root 160606  4월 20  2022 unicode.map
[root@localhost snort]#

 

없어서 만든다 

 

[root@localhost snort]# mkdir /usr/local/lib/snort_dynamicrules
[root@localhost snort]#

 

다 추가 

sudo chmod -R 5775 /usr/local/lib/snort_dynamicrules

    sudo chown -R snort:snort /etc/snort
    sudo chown -R snort:snort /var/log/snort
    sudo chown -R snort:snort /usr/local/lib/snort_dynamicrules

    sudo touch /etc/snort/rules/white_list.rules
    sudo touch /etc/snort/rules/black_list.rules
    sudo touch /etc/snort/rules/local.rules 

 

snort 설정 파일로 가보자 

vi  /etc/snort/snort.conf

 

ipvar HOME_NET 192.168.0.0/24
-----                            : 변수 선언
      --------                   : 변수의 이름
               ---------------   : 리터럴

선언된 변수를 호출하는 방법 :  $HOME_NET

ipvar EXTERNAL_NET any  <---> ipvar EXTERNAL_NET !$HOME_NET

buraya eklenecek seyler var 

 

검사 

 snort -T -c /etc/snort/snort.conf

 

 

yeni bir shell olusturduk bunu acmak icin 

cat >snort_start.sh 

snort -A console -i ens33 -u snort -g snort -c /etc/snort/snort.conf

 chmod +x snort_start.sh

 

 

[root@localhost rules]# ls
black_list.rules  local.rules  white_list.rules
[root@localhost rules]# vim local.rules
[root@localhost rules]#

local rules

alert icmp any any -> $HOME_NET any (msg : "ICMP Test"; sid : 10000001; rev : 001;)

 

snort -A console -i ens33 -c /etc/snort/snort.conf -b 

tcpdump -xX -i ens33 -w icmp.pcap (pcap 다음 세대가 pcapng 써 )