A snort is NIDS(Network Intrusion Detection System).
This document is snort with acid of database analyze tool and snortsnarf of log statistics tool.
I. Snort 및 ACID Snortsnarf 설치 준비 작업
1. 설치환경
가. 리눅스 버전
Red Hat Linux release 9 (Shrike)
가. 커널버전
2.4.20-8
2. 다운로드
모두 /usr/local 디렉토리에 다운로드 한다.
Libpcap http://www.tcpdump.org/release/libpcap-0.7.2.tar.gz (리눅스 시스템에 기본적으로 설치)
Snort 2.0 http://www.snort.org/dl/snort-2.0.0.tar.gz
Snort Rule http://www.snort.org/dl/rules/snortrules-current.tar.gz
ACID http://www.andrew.cmu.edu/~rdanyliw/snort/acid-0.9.6b23.tar.gz
Snortsnarf http://www.silicondefense.com/software/snortsnarf/SnortSnarf-021111.1.tar.gz
II. SNORT 설치 및 세팅
1. libpcap 설치
가. snort는 패킷을 수집하기 위해 네트워크 패킷 수집 라이브러리인 libpcap을 필요로 함
나. libpcap 설치 확인
[root@lab504 local]# rpm -q libpcap
libpcap-0.7.2-1
다. 설치되어 있지 않았을 경우 위 다운로드 사이트에서 다운로드 받는다.
[root@lab504 local]# tar ?zxvf libpcap.tar.Z
[root@lab504 local]# cd /usr/local/libpcap-0.4
[root@lab504 libpcap-0.4]# ./configure
creating cache ./config.cache
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
.
. (중략)
.
checking for a BSD compatible install... /usr/bin/install -c
updating cache ./config.cache
creating ./config.status
[root@lab504 libpcap-0.4]# make
gcc -O2 -I. -Ilinux-include -DHAVE_MALLOC_H=1 -DHAVE_ETHER_HOSTTON=1 -DHAVE_STRERROR=1 -DHAVE_NET_IF_ARP_H=1 -c ./pcap-linux.c
gcc -O2 -I. -Ilinux-include -DHAVE_MALLOC_H=1 -DHAVE_ETHER_HOSTTON=1 -DHAVE_STRERROR=1 -DHAVE_NET_IF_ARP_H=1 -c ./pcap.c
gcc -O2 -I. -Ilinux-include -DHAVE_MALLOC_H=1 -DHAVE_ETHER_HOSTTON=1 -DHAVE_STRERROR=1 -DHAVE_NET_IF_ARP_H=1 -c ./inet.c
.
. (중략)
.
gcc -O2 -I. -Ilinux-include -DHAVE_MALLOC_H=1 -DHAVE_ETHER_HOSTTON=1 -DHAVE_STRERROR=1 -DHAVE_NET_IF_ARP_H=1 -c ./version.c
ar rc libpcap.a pcap-linux.o pcap.o inet.o gencode.o optimize.o nametoaddr.o etherent.o savefile.o bpf_filter.o bpf_image.o scanner.o grammar.o version.o
ranlib libpcap.a
[root@lab504 libpcap-0.4]# make install
/usr/bin/install -c -m 444 -o bin -g bin libpcap.a /usr/local/lib/libpcap.a
ranlib /usr/local/lib/libpcap.a
[root@lab504 libpcap-0.4]# make install-incl
/usr/bin/install -c -m 444 -o bin -g bin ./pcap.h \
/usr/local/include/pcap.h
/usr/bin/install -c -m 444 -o bin -g bin ./pcap-namedb.h \
/usr/local/include/pcap-namedb.h
/usr/bin/install -c -m 444 -o bin -g bin ./net/bpf.h \
/usr/local/include/net/bpf.h
/usr/bin/install: cannot create regular file `/usr/local/include/net/bpf.h': 그런 파일이나 디렉토리가 없음
make: *** [install-incl] 오류 1
[root@lab504 libpcap-0.4]# cd bpf
[root@lab504 bpf]# cp ?R net /usr/local/include
[root@lab504 bpf]# cd ..
[root@lab504 libpcap-0.4]# make install-incl
/usr/bin/install -c -m 444 -o bin -g bin ./pcap.h \
/usr/local/include/pcap.h
/usr/bin/install -c -m 444 -o bin -g bin ./pcap-namedb.h \
/usr/local/include/pcap-namedb.h
/usr/bin/install -c -m 444 -o bin -g bin ./net/bpf.h \
/usr/local/include/net/bpf.h
2. snort 설치
가. snort 압축 파일이 있는 디렉토리로 이동 및 압축풀기
[root@lab504 libpcap-0.4]# cd..
[root@lab504 local]# tar ?zxvf snort-2.0.0.tar.gz
나. 압축풀린 디렉토리로 이동
[root@lab504 local]# cd snort-2.0.0
[root@lab504 snort-2.0.0]# ./configure --prefix=/usr/local/snort
[root@lab504 snort-2.0.0]# make
[root@lab504 snort-2.0.0]# make install
다. snort가 설치 된 디렉토리는 /usr/local/snort에 설치 됨
3. snort rule 설치
가. snort 탐지 rule을 최근 것으로 업데이트 함
[root@lab504 snort-2.0.0]# cd ..
[root@lab504 local]# tar -zxvf snortrules-current.tar.gz
나. 압축을 푼 디렉토리를 아래의 snort 디렉토리에 rules 디렉토리로 overwrite 함.
[root@lab504 snort-2.0.0]# mv -f rules /usr/local/snort-2.0.0
4. snort.conf 파일 수정
가. snort 환경설정 파일에서 몇 가지 변수들을 자신의 환경에 맞게 바꿈
[root@lab504 snort-2.0.0]# cd rules
[root@lab504 rules]# vi snort.conf
나. snort.conf 내용
(1) var HOME_NET 210.110.152.200/32
IP : snort로 공격당하는 것을 감시할 IP 주소나 네트워크 주소
subnet : 서브넷 마스크를 설정하여 네트워크를 감시
형 식 : IP/subnet
C 클래스 : /24
B 클래스 : /16
A 클래스 : /8
호스트 지정: /32
5. 로그 디렉토리 생성
[root@lab504 rules]# mkdir /varl/log/snort
[root@lab504 rules]# chmod 700 /var/log/snort
III. Snort 실행
1. USAGE 파일에 snort에서 제공되는 여러가지 옵션 설명 참고
2. [root@lab504 rules]# cd /usr/local/snort/bin
3. [root@lab504 bin]# ./snort -D -d -l /var/log/snort -c /usr/local/snort-2.0.0/rules/snort.conf
4. 부팅시 자동 실행 설정
[root@lab504 bin]# vi /etc/rc.d/rc.local
#snort 2.0.0
snort -D -d -l /var/log/snort -c /usr/local/snort-2.0.0/rules/snort.conf
IV. SnortSnarf 설치
1. snort에서 생성된 로그 파일들을 웹페이지로 바꾸는 로그 관리 툴
2. 압축풀기 및 설정
[root@lab504 bin]# cd /usr/local
[root@lab504 local]# tar -zxvf SnortSnarf-021111.1.tar.gz
[root@lab504 local]# cd SnortSnarf-021111.1
[root@lab504 SnortSnarf-021111.1]# cd include
[root@lab504 include]# cp * /usr/lib/perl5/site_perl/5.8.0/
[root@lab504 include]# cd ..
[root@lab504 SnortSnarf-021111.1]# cd cgi
[root@lab504 cgi]# cp * /usr/local/apache/cig-bin/
[root@lab504 cgi]# cd ..
[root@lab504 SnortSnarf-021111.1]# ./snortsnarf.pl -rulesdir /usr/local/snort-2.0.0/rules
-rulesfile /usr/local/snort-2.0.0/rules/snort.conf -d /usr/local/apache/htdoc/snort /var/log/snort/alert
Can't locate Time/ParseDate.pm in @INC (@INC contains: ./include /usr/lib/perl5/5.8.0/i386-linux-
thread-multi /usr/lib/perl5/5.8.0 /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-
multi /usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl5/vendor_perl .
/usr/lib/perl5/site_perl/5.8.0/SnortSnarf) at /usr/lib/perl5/site_perl/5.8.0/SnortSnarf/TimeFilters.pm line
18.
BEGIN failed--compilation aborted at /usr/lib/perl5/site_perl/5.8.0/SnortSnarf/TimeFilters.pm line 18.
Compilation failed in require at /usr/lib/perl5/site_perl/5.8.0/SnortSnarf/Filter.pm line 19.
BEGIN failed--compilation aborted at /usr/lib/perl5/site_perl/5.8.0/SnortSnarf/Filter.pm line 19.
Compilation failed in require at ./snortsnarf.pl line 87.
BEGIN failed--compilation aborted at ./snortsnarf.pl line 87.
이와 같은 에러가 보이지 않는다면.. 제대로 설치가 다 된 것임. 하지만 거의 이 에러가 남.
이것은 Time::ParseDate 가 설치되지 않아서 그런 것이다. 이 문제를 해결하기 위해서는 아래와 같이
Time::ParseDate를 설치해야 함.
설치하는 방법엔 직접 설치하는 방법과 사이트에 가서 소스 파일을 가지고와서 카피해 두는 방법이 있슴.
1. 직접 설치하기
[root@rnlab504 SnortSnarf-021111.1]# perl -MCPAN -e shell
/usr/lib/perl5/5.8.0/CPAN/Config.pm initialized.
CPAN is the world-wide archive of perl resources. It consists of about
100 sites that all replicate the same contents all around the globe.
Many countries have at least one CPAN site already. The resources
found on CPAN are easily accessible with the CPAN.pm module. If you
want to use CPAN.pm, you have to configure it properly.
If you do not want to enter a dialog now, you can answer 'no' to this
question and I'll try to autoconfigure. (Note: you can revisit this
dialog anytime later by typing 'o conf init' at the cpan prompt.)
Are you ready for manual configuration? [yes] no
[color='oliver']yes를 입력하면.. 수동으로 설정을 잡는 것이고.. no를 하면 자동으로 설정을 잡아준다.
아래는 no를 했을경우 자동으로 경로를 잡는 내용입니다..[/color]
------------------------------------------------------------------------------
The following questions are intended to help you with the
configuration. The CPAN module needs a directory of its own to cache
important index files and maybe keep a temporary mirror of CPAN files.
This may be a site-wide directory or a personal directory.
I see you already have a directory
/root/.cpan
Shall we use it as the general CPAN build and cache directory?
CPAN build and cache directory? [/root/.cpan]
중간 생략 ......
Your favorite WAIT server?
[wait://ls6-www.informatik.uni-dortmund.de:1404]
commit: wrote /usr/lib/perl5/5.8.0/CPAN/Config.pm
cpan shell -- CPAN exploration and modules installation (v1.61)
ReadLine support available (try 'install Bundle::CPAN')
------------------------------------------------------------------------------
설정이 끝나면 아래와 같이 프럼프트가 뜨는데.. 이곳에다 install Time::ParseDate 를 입력한다..
cpan> install Time:ParseDate <== 하면 perl.org에 가서 해당 파일을 받아서 자동으로 설치를 한다.
CPAN: Storable loaded ok
Going to read /root/.cpan/Metadata
Database was generated on Tue, 11 Mar 2003 08:41:21 GMT
Running install for module Time::ParseDate
Running make for M/MU/MUIR/modules/Time-modules-2003.0211.tar.gz
CPAN: LWP::UserAgent loaded ok
Fetching with LWP:
ftp://ftp.perl.org/pub/CPAN/authors/id/M/MU/MUIR/modules/Time-modules-2003.0211.tar.gz
CPAN: Digest::MD5 loaded ok
Fetching with LWP:
ftp://ftp.perl.org/pub/CPAN/authors/id/M/MU/MUIR/modules/CHECKSUMS
Checksum for /root/.cpan/sources/authors/id/M/MU/MUIR/modules/Time-modules-2003.0211.tar.gz ok
..... 중간 생략.......
Appending installation info to /usr/lib/perl5/5.8.0/i386-linux-thread-multi/perllocal.pod
/usr/bin/make install -- OK
cpan> quit
Lockfile removed.
[ root@rnlab504 5.8.0]# find /usr/lib/perl5/ -name 'ParseDate.pm' -print
/usr/lib/perl5/site_perl/5.8.0/Time/ParseDate.pm <=== 정상적으로 설치되어 있는 것을 볼수 있을것이 다..
[root@rnlab504 SnortSnarf-021111.1]# mkdir /usr/local/apache/htdoc/snort
[root@rnlab504 SnortSnarf-021111.1]# ./snortsnarf.pl -rulesdir /usr/local/snort-2.0.0 -rulesfile /usr/local/snort-2.0.0/rules/snort.conf -d /usr/local/apache/htdoc/snort /var/log/snort/alert /var/log/snort/portscan.log
Using an array as a reference is deprecated at /usr/lib/perl5/site_perl/5.8.0/SnortSnarf/HTMLMemStorage.pm line 290.
Using an array as a reference is deprecated at /usr/lib/perl5/site_perl/5.8.0/SnortSnarf/HTMLAnomMemStorage.pm line 266.
could not open /usr/local/snort-1.9.1/snort.conf to read rules from -- skipping
could not open /usr/local/snort-1.9.1/snort.conf to read rules from -- skipping
could not open /usr/local/snort-1.9.1/snort.conf to read rules from -- skipping
could not open /usr/local/snort-1.9.1/snort.conf to read rules from -- skipping
could not open /usr/local/snort-1.9.1/snort.conf to read rules from -- skipping
could not open /usr/local/snort-1.9.1/snort.conf to read rules from -- skipping
SnortFileInput: input file /var/log/snort/portscan.log exists but is length 0; skipping it
2. 카피해서 가지고 오기
구버전이거나 Time:ParseDate가 제대로 설치가 안된다면.. 직접 사이트에서 가서 카피해 와도 된다.
http://search.cpan.org/dist/Time-modules/
이곳에 가면..
Time::CTime format times ala POSIX asctime 99.062201
Time::DaysInMonth simply report the number of days in a month 99.1117
Time::JulianDay Julian calendar manipulations 99.061501
Time::ParseDate date parsing both relative and absolute 2003.0211
Time::Timezone
5개의 모듈이 있다.. 각각을 클릭해 들어가 Source 를 클릭하면 소스가 보이는데.. 카피해서
동일한 파일명으로 생성해서
/usr/lib/perl5/각 버전/Time 밑으로 카피해 준다..
그리고 snortsnarf.pl 를 실행하면.. Time:PasrseDate에 관한 에러는 잡을수 있다.
옵션 설명
-rulesdir : 룰의 디렉토리명
-rulesfile : snort.conf 파일의 위치
-d : 로그파일이 있는 위치
이제 이것을 cron으로 돌려서 주기적으로 html화를 시켜 주어야 한다.
하지만, 로그기록이 많이 질수록 시스템의 부하를 많이 주기 때문에.. cron 주기 시간을 되도록 길게 잡아 주는 것이 좋다.
[ root@rnlab504 SnortSnarf-021111.1]# vi snort.cron
./snortsnarf.pl -rulesdir /usr/local/snort-2.0.0 -rulesfile /usr/local/snort-1.0.0/rules/snort.conf
-d /usr/local/apache/htdocs/snort /var/log/snort/alert
[ root@dream html]# vi /etc/crontab
50 6 * * * root /usr/local/SnortSnarf-021111.1/snort.cron>/dev/null 2>&1
매일 6시 50분에 실행을 한다.
모든 설치가 끝나고 브라우저로 가면.. 아래와 같이 snort의 기록 들을 웹상에서 볼수 있게 될것이다.
작성자 : 이성진
작성일 : 2006.05.22
원본 : http://www.rnlab.re.kr

Comments List