메뉴 건너뛰기

2016.04.22 12:11

IDS - snort 1

조회 수 5025 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
패킷 필터링- 방화벽 IDS ( 침입탐지 시스템 ) - 시스템에 공격이 들어왔을때 누가 공격했는지 찾아주는 것. snort IDS , 목적이 침입탐지이다. 패킷 스니퍼(모니터로 캡쳐)와 패킷 로거는 tcpdump로도 가능하기 때문에 라우터와 방화벽 사이에 snort 설치 및 구성, snort 만으로는 패킷을 차단할수 는 없기 때문에 방화벽 전에 설치하는 것이다. ##################################################################################

설치

cd /tmp
#wget -c http://twoseven.kr/snort.tar.gz

- 소스파일을 설치해야 한다. 바이너리 패키지로 제공이 되지 않기 때문.
- www.snort.org (공식 사이트)에서 관련 패키지를 다 다운 받아야 한다.
- mysql 서버는 반드시 필요한 것은 아니다. 하지만 설치를 하지 않으면 파일로 저장이 가능하다.
- snort는 패킷 캡쳐를 한다음에 불법적인 패킷을 찾아내는 것이다.
- 패킷 캡쳐를 위해 libPcaP을 설치 해야 한다. 




 ./configure ; make ; make install  //  libpcap 소스는 prefix 를 주지 않아도 설치 되게끔 되어있다. 


DMZ (서버가 설치되는 위치)

 yum list snort
 1011  ls
 1012  cd /usr/local/
 1013  ls
 1014  cd mysql/
 1015  ls
 1016  cd bin/
 1017  ls
 1018  ./mysqlcheck
 1019  ls
 1020  ./mysql_install_db
 1021  cd /tmp
 1022  ls
 1023  tar -tf snort.tar.gz
 1024  tar xvfz snort.tar.gz
 1025  ls
 1026  cd snort
 1027  ls
 1028  rm libn*
 1029  ls
 1030  tar xvfz libpcap-0.9.4.tar.gz
 1031  ls
 1032  cd libpcap-0.9.4
 1033  ls
 1034  vi INSTALL.txt
 1035  cd //
 1036  cd /tmp
 1037  ls
 1038  cd snort
 1039  ls
 1040  cd libpcap-0.9.4
 1041  ls
 1042  ./configure ; make ; make install
 1043  date
 1044  ls
 1045  make && make install
 1046  cd ..
 1047  ls
 1048  tar xvfj pcre-8.02.tar.bz2
 1049  ls
 1050  cd pcre-8.02
 1051  ls
 1052  ./configure ; make ; make install
 1053  ls
 1054  cd ..
 1055  ls
 1056  tar xvfz snort-2.8.6.tar.gz
 1057  ls
 1058  cd snort
 1059  cd snort-2.8.6
 1060  ls
 1061  ./configure --prefix=/usr/local/snort-2.8.6 --with-mysql=/usr/local/mysql
 1062  make && make install
 1063  mysql -u root -p
 1064  cd /usr/local/mysql/
 1065  ls
 1066  ls -al
 1067  cd mysql-test/
 1068  ls
 1069  cd ..
 1070  ls
 1071  cd /tmp
 1072  ls
 1073  cd snort
 1074  ls
 1075  cd /usr/local
 1076  ls
 1077  cd mysql/
 1078  ls
 1079  ./configure --prefix=/usr/local/mysql \
 1080  > --localstatedir=/usr/local/mysql/data --with-charset=utf8 --with-readline 
 1081  cd bin
 1082  ls
 1083  cd ..
 1084  cd ..
 1085  ls
 1086  cd ..
 1087  ls
 1088  find / -name mysql
 1089  cd /
 1090  ls
 1091  cd mysql-5.0.67
 1092  ls
 1093  ./configure --prefix=/usr/local/mysql \
 1094  > --localstatedir=/usr/local/mysql/data --with-charset=utf8 --with-readline
 1095  ./configure --prefix=/usr/local/mysql --localstatedir=/usr/local/mysql/data --with-charset=utf8 --with-readline
 1096  make && make install
 1097  cp support-files/my-medium.cnf /etc/my.cnf
 1098  cd /usr/local/mysql/bin
 1099  ls
 1100  ./mysql_install_db
 1101  ls ../date/
 1102  ls ../data
 1103  cd ..
 1104  ls
 1105  echo "/usr/local/mysql/lib" >> /etc/ld.so.conf
 1106  cat /etc/ld.so.conf
 1107  useradd -r mysql
 1108  useradd -M -s /sbin/nologin mysql
 1109  chown -R root.mysql /usr/local/mysql
 1110  chown -R mysql.mysql /usr/localmysql/date
 1111  chown -R mysql.mysql /usr/localmysql/data
 1112  chown -R mysql.mysql /usr/local/mysql/date
 1113  cd bin/
 1114  ./mysqld_safe &
 1115  ps -ef | grep mysqld
 1116  ./mysql
 1117  history


========================
# tcpdump
# 컨트롤 C 눌러서 죽지않으면

# kill %(PID)
#mkdir /var/log/snort

==================
centos[root /usr/local/snort-2.8.6/bin]#\
> ./snort -vde -l /var/log/snort -K pcap
Running in packet logging mode    ------------------------------------> 패킷로거

        --== Initializing Snort ==--
Initializing Output Plugins!
Log directory = /var/log/snort
***
*** interface device lookup found: eth0
***
Initializing Network Interface eth0
Decoding Ethernet on interface eth0

        --== Initialization Complete ==--

   ,,_     -*> Snort! <*-
  o"  )~   Version 2.8.6 (Build 38)
   ''''    By Martin Roesch & The Snort Team: http://www.snort.org/snort/snort-team
           Copyright (C) 1998-2010 Sourcefire, Inc., et al.
           Using PCRE version: 8.02 2010-03-19

Not Using PCAP_FRAMES

여기서 컨트롤 C 누르면 끝나고 다음 화면이 나온다.

Breakdown by protocol (includes rebuilt packets):
      ETH: 1962       (100.000%)
  ETHdisc: 0          (0.000%)
     VLAN: 0          (0.000%)
     IPV6: 145        (7.390%)
  IP6 EXT: 0          (0.000%)
  IP6opts: 0          (0.000%)
  IP6disc: 0          (0.000%)
      IP4: 742        (37.819%)
  IP4disc: 0          (0.000%)
    TCP 6: 0          (0.000%)
    UDP 6: 0          (0.000%)
    ICMP6: 0          (0.000%)
  ICMP-IP: 0          (0.000%)
      TCP: 1          (0.051%)
      UDP: 737        (37.564%)
     ICMP: 1          (0.051%)
  TCPdisc: 0          (0.000%)
  UDPdisc: 0          (0.000%)
  ICMPdis: 0          (0.000%)
     FRAG: 0          (0.000%)
   FRAG 6: 0          (0.000%)
      ARP: 947        (48.267%)
    EAPOL: 0          (0.000%)
  ETHLOOP: 0          (0.000%)
      IPX: 0          (0.000%)
    OTHER: 131        (6.677%)
  DISCARD: 0          (0.000%)
InvChkSum: 0          (0.000%)
   S5 G 1: 0          (0.000%)
   S5 G 2: 0          (0.000%)
    Total: 1962
===============================================================================
Action Stats:
ALERTS: 0
LOGGED: 1962
PASSED: 0


tcpdump와는 조금 다르다.

./snort -vde -l /var/log/snort -K pcap    //바이너리로 캡쳐한것 
이렇게 봐야한다.
cd /var/log/snort 로가서

centos[root /var/log/snort]#tcpdump -r snort.log.1357178029

====================================

칩임탐지모드 IDS 방식으로 .
/etc/snort.conf 
IDS 방식으로 운영시 꼭 필요, snortrules 설치 이것은 그냥 소스코드가 아닌 아스키 파일(현재)
-rule을 이용한 패킷 캡쳐. ( 해킹패턴, 공격패턴 감지-RULE)

 cd /tmp
 1033  ls
 1034  cd snort
 1035  ls
 1036  mv snortrules-snapshot-2860.tar.gz /usr/local/snort-2.8.6/
 1037  ls
 1038  cd /usr/local/snort-2.8.6/
 1039  ls
 1040  tar xvfz snortrules-snapshot-2860.tar.gz
 1041  ls


이제 IDS 방식으로 운영할 수 있다.

1061  cd snort-2.8.6/
 1062  cd etc/
 1063  ls
 1064  cp snort.conf snort.conf.bak
 1065  ls
 1066  vi snort.conf



161 dynamicpreprocessor directory /usr/local/snort-2.8.6/lib/snort_dynamicprepro    cessor/


============

centos[root /root]#vi .bash_profile


  9
 10 PATH=$PATH:$HOME/bin:/usr/local/snort-2.8.6/bin


#source .bash_profile


=============
#vi snort.conf

다시 열어서

다운로드 받은후 룰파일 설치후 ids 모드로 운영시 snort.conf 파일중 고쳐야 할내용. 
(* snort 를 /usr/local/snort-2.8.6 디렉토리에 설치했다고 가정할경우) 
161 dynamicpreprocessor directory /usr/local/snort-2.8.6/lib/snort_dynamicpreprocessor/ 

164 dynamicengine /usr/local/snort-2.8.6/lib/snort_dynamicengine/libsf_engine.so 

167 # dynamicdetection directory /usr/local/lib/snort_dynamicrules <== 주석처리 

193 preprocessor http_inspect: global iis_unicode_map unicode.map 1252 "compress_depth 20    480 decompress_depth 20480"  <== 큰 따옴표 안에 있는 부분 삭제 

206    inspect_gzip \ ===> 삭제

확인


#snort -c snort.conf

-c : configure

어느정도 돌려놓아서 캡쳐를 했으면

cd /var/log/snort 로 이동해서
ls
alert 이라는 파일이 생성됨을 확인할수 있는데

공격이라고 생각되는 패킷을 따로 저장하는 것이다.

vi alert

물론, 여기 저장되어있다고 해서 다 잘못된 패킷은 아니다.

priority 가 클수록 심각한 패킷은 아니다.
priority :1 은 가장 심각한 패킷

Xref : x 레퍼런스는 이것을 참고 해보라는 의미.

=====================================

클론머신 키고

날짜 맞추고 방화벽 풀기

포트스캔공격해보기

해킹하기 위한 전단계로 쓰는 것이 포트스캔

1. 호스트가 존재하는지 검사
2. 어떤 서비스가 실행중인지 검사
3. 운영체제 검사.

Nmap 이 가장 널리 알려져있다. 영화에도 나왔다.


vi snort.conf 열어서

port scan 하는 부분 주석 풀어주기

 1141  cd /usr/local/snort-2.8.6/
43  cd etc/
 1144  snort -c snort.conf

클론에서
centos2[root /root]#nmap -sT -T5 -p 1-65530 172.20.20.15

다시 마스터에서 
취소하고
145  cd /var/log/snort/
 1146  ls
 1147  grep -i scan alert

확인할 수 있다.

rm alert 
지우고 다시.

또 snort 실행하고

이번엔 클론에서

centos2[root /root]#nmap -sS -T4 -v -p 1-65535 172.20.20.15

다시 snort 취소 하고 alert  파일 확인하면 포트스캔한 것을 확인


===============================

이제 마스터에서 방화벽 설정을 한다.

#iptables -A INPUT -s 172.20.20.115 -p all -j REJECT

다시 클론에서 포트스캔을 하면 차단이 되어 포트스캔을 할 수 없음을 확인 할 수있다.

****  또, rule 파일에 적용되어 있는 규칙에 해당되는 패킷이 발견되면 alert 파일을 만든다는 것이다.


============================================================

List of Articles
번호 제목 날짜 조회 수
6 리눅스보안 - 필수 보안 조치법 2015.07.23 5199
5 SYN-Flooding 공격 방어 2016.04.22 5510
4 linux Network Filter - IPTABLES 2016.04.22 5340
3 GeoIP 모듈을 이용한 해외 IP 차단 관리하기( centos 5.x ) - 구버전 2016.04.22 6650
2 iptables 실무 적용 팁 file 2016.04.22 5226
» IDS - snort 1 2016.04.22 5025
Board Pagination Prev 1 Next
/ 1

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved