2011. 11. 28. 19:36 Log/Linux

메일서비스(sendmail)

sendmail 주설정 파일

sendmail.cf : sendmail 설정파일
sendmail.mc : sendmail.cf 를 생성하기위한 m4 매크로파일

access : sendmail server access 제한 설정

access : sendmail server access 제한 설정
[root@centos1 mail]# cat access
# by default we allow relaying from localhost...
Connect:localhost.localdomain RELAY
Connect:localhost RELAY
Connect:127.0.0.1 RELAY

tag:ip또는 도메인 policy

tag
Connect: 주소 또는 도메인
From : 송신자 주소
To : 수신자 주소

ex)
Connect:localhost.localdomain RELAY
Connect:192.168.0.1 RELAY
Connect:192.168.10 RELAY
Connect:localhost RELAY
From: user1@myunix.co.kr OK
From: spam.com REJECT
To:root@ OK
TO:minki.co.kr REJECT

OK : 메일수신허용 RELAY는 불가
RELAY : 수신 및 RELAY 허용
REJECT : 수신거부



centos 5.x 버전에 설치되어 있는 sendmail 서버버전은 8.13.x 이며 과거버전에 비해서
설정문법이 조금 바뀌었다.

redhat9 버전에 설치되어 있는 sendmail 8.12.x 버전의 경우는 설정이 아래와 같다.
[root@mylinux root]# cd /etc/mail
[root@mylinux mail]# cat access
# by default we allow relaying from localhost...
localhost.localdomain RELAY
localhost RELAY
127.0.0.1 RELAY

[root@mylinux mail]#

수정하였을경우
# makemap hash /etc/mail/access.db < /etc/mail/access 로 갱신

local-host-names : sendmail 서버가 사용하는 메일서버도메인주소
virtusertable : 다른 이메일 도메인 주소를 갖는 같은 계정을 처리하는데
사용된다.
가상의 메일계정 시스템계정

수정하였을 경우
# makemap hash /etc/mail/virtusertable.db < /etc/mail/virtusertable
로 db 파일을 갱신해야 한다.


/etc/aliases : 메일 계정에 대한 alias 파일
- 이파일을 이용하여 메일링리스트를 구현할 수 있다.
대표계정 : 수신계정, 수신계정, ...

수정하였을경우
# newaliases 로 갱신한다.

[root@centos1 /etc/sysconfig]# cat sendmail
DAEMON=yes
QUEUE=1h => 메일큐에 남아있는 메일을 한시간 단위로 처리한다.

*. sendmail 설정파일

Cwlocalhost
메일서버호스트명을 localhost 로 지정.
ex)
Cwmyunix.co.kr
Cwlee.pe.kr
- 여러개의 도메인을 사용하는것도 가능하다.

Fw/etc/mail/local-host-names
Cw 명령어로 메일호스트를 등록하는대신 호스트명을 Fw 뒤에 적혀있는
파일로 설정.

Dj$w.Foo.COM
- sendmail 호스트명을 지정

FR-o /etc/mail/relay-domains
- 릴레이를 허용할 호스트명 설정
- 이부분을 주석처리하게 되면 모든 주소에 대해 relay 허용.

Kvirtuser hash -o /etc/mail/virtusertable.db
- virtusertable 설정

Kaccess hash -T<TMPF> -o /etc/mail/access.db
- access 설정

O AliasFile=/etc/aliases
- aliases 설정

O MaxMessageSize=0
- 최대 메일 크기 결정(첨부파일포함이며 byte 단위로 설정)

O DamonPortOptions=Port=smtp,Addr=127.0.0.1,Name=MTA
- relay를 제한하기 위해 로컬호스트에서 전송한 메일만 수신

local 호스트 이외의 곳에서도 relay 허용하려면 아래처럼 변경.
O DamonPortOptions=Port=smtp,Addr=0.0.0.0,Name=MTA

O QueueDirectory=/var/spool/mqueue

O Timeout.queuereturn=5d
여기에 설정된 시간동안 큐에 남아 있는 메일을 처리하지 못하게 되면
발송자에게 메일을 리턴한다.

O Timeout.queuewarn=4h
어떤 문제로 목적지 호스트로 지정한 시간동안 메일을 발송할 수 없는경우
발송자에게 경고메시지 보낸다.


POP3 및 IMAP 설정

dovecot 패키지가 설치되어 있어야 한다.
[root@centos1 /etc/sysconfig]# rpm -q dovecot
dovecot-1.0.7-7.el5
[root@centos1 /etc/sysconfig]#
설치되어 있지 않으면 yum 으로 설치할 수 있다.
ex) yum install dovecot

메일서비스 테스트

[root@centos1 mail]# mail user1@lee.pe.kr
Subject: hello
test again
hahahah
lee.pe.kr
.
Cc: [root@centos1 mail]#
[root@centos1 mail]#
[root@centos1 mail]# mail user1@lee.pe.kr
Subject: 안녕하세요?
반갑습니다.
...
그럼 이만...
.
Cc:
[root@centos1 mail]#

[root@centos1 mail]# cat /etc/mail/local-host-names
# local-host-names - include all aliases for your machine here.
lee.pe.kr
minki.co.kr
[root@centos1 mail]#

읽지 않은 메일은 이곳에 수신 계정명으로 저장되어 있다.
[root@centos1 /var/spool/mail]# ls
cuser1 mysql p2 root samuser1 samuser3 suser1 sysuser1 sysuser3 sysuser5 u10 u12 u2 user10
lee p1 p3 rpc samuser2 smuser1 suser2 sysuser2 sysuser4 u1 u11 u13 user1 user2
[root@centos1 /var/spool/mail]#
여기 있는 메일은 보안상 수신자만 볼수 있게 퍼미션 설정이 되어 있다. 편집기등으로 볼수 있다.

user1 계정이 로그인 하게 되면
You have new mail in /var/spool/mail/user1
[user1@centos1 ~]$
새로운 메일이 있다는 메시지를 출력해준다.

[user1@centos1 ~]$ mail
Mail version 8.1 6/6/93. Type ? for help.
"/var/spool/mail/user1": 1 message 1 unread
>U 1 root@localhost.local Sun Jul 4 23:54 20/710 "hello"
&

& 1
Message 1:
From root@localhost.localdomain Sun Jul 4 23:54:46 2010
Date: Sun, 4 Jul 2010 23:54:46 +0900
From: root <root@localhost.localdomain>
To: user1@lee.pe.kr
Subject:hello

반갑습니다.
잘 지내시나요?
한번 만납시다.
이만...

& help <= 이곳에서 사용할수 있는 명령어를 보여준다.

& quit
Saved 1 message in mbox <= 읽은 메일은 $HOME/mbox 파일로 저장된다.
[user1@centos1 ~]$

메일이 전송되지 못한경우 clientmqueue 나 mqueue 디렉토리에 남으며
한개의 메일이 헤더와 본문으로 두개의 파일로 나뉘어 저장된다.
*. 목적지주소를 알 수없는 경우는 송신자한테 바로 돌아온다.

[root@centos1 spool]# cd mqueue/
[root@centos1 mqueue]# ls
dfo64EiQ5G023647 qfo64EiQ5G023647

'Log > Linux' 카테고리의 다른 글

OpenSSh 및 SELinux  (0) 2011.11.28
ACL (Access Control List)  (0) 2011.11.28
samba 서비스  (0) 2011.11.28
IDS - snort 1  (0) 2011.11.28
tcpdump - packet capture / 분석  (0) 2011.11.28
Posted by logwatch

2011. 11. 28. 19:36 Log/Linux

samba 서비스


마이크로소프트와 인텔은 윈도우시스템이 다른 시스템의 디스크나 프린터 자원을 공유할 수 있도록
SMB(Server Message Block) 프로토콜을 개발하였는데 삼바란 이 SMB 를 이용하여 윈도우와 다른 시스템간의 프린터및 자료를 공유할 수 있도록 해주는 서비스

현재 마이크로소프트에서는 SMB 라는 이름대신 좀 더 범위가 큰 CIFS(Common Internet Filesystem)
이라는 프로토콜로 부른다. 이프로토콜은 SMB 프로토콜에 LanManager 와 NetBios 프로토콜까지
포함한다.

삼바구성
samba 서비스는 두개의 데몬을 구성된다.
1. smbd : 파일 및 프린터 공유, 사용자 확인 및 권한부여
2. nmbd : 클라이언트를 위해 NetBios nameserver를 지원하고 서비스를 알린다.

서비스구동

/etc/init.d/smb start 또는 service smb start

삼바서비스를 위한 패키지
[root@centos2 samba]# rpm -qa | grep samba
samba-swat-3.0.33-3.28.el5 ; GUI 환경에서의 삼바설정툴
system-config-samba-1.2.41-3.el5 ; GUI 환경에서의 삼바 설정툴
samba-common-3.0.33-3.28.el5 ; 삼바 설정파일, 유틸리티, 메뉴얼 페이지
samba-3.0.33-3.28.el5 ; 삼바 서버
samba-client-3.0.33-3.28.el5 ; 삼바 클라이언트
[root@centos1 samba]#


samba 설정파일
[root@centos1 samba]# ls
lmhosts passdb.tdb secrets.tdb smb.conf smb.conf_orig smbusers
[root@centos1 samba

삼바서비스 주요설정

주석은 '#' 또는 ';' 이다.


[global]

# ----------------------- Network Related Options -------------------------
#
workgroup = MYGROUP
server string = Samba Server Version %v

; netbios name = MYSERVER

; interfaces = lo eth0 192.168.12.2/24 192.168.13.2/24
; hosts allow = 127. 192.168.12. 192.168.13.

# --------------------------- Logging Options -----------------------------
#
# Log File let you specify where to put logs and how to split them up.
#
# Max Log Size let you specify the max size log files should reach

# logs split per machine
; log file = /var/log/samba/%m.log
# max 50KB per log file, then rotate
; max log size = 50

# ----------------------- Standalone Server Options ------------------------
#
# Security can be set to user, share(deprecated) or server(deprecated)
#
# Backend to store user information in. New installations should
# use either tdbsam or ldapsam. smbpasswd is available for backwards
# compatibility. tdbsam requires no further configuration.

security = user ( user 대신 사용할 수 있는것은 share/server/domain/ads 가 있다)
passdb backend = tdbsam

*. 과거버전의 smbpasswd 를 사용하는 경우에는
passdb backend = smbpasswd:/etc/samba/smbpasswd 로 설정.

#============================ Share Definitions ==============================

[homes]
comment = Home Directories
browseable = no
writable = yes
; valid users = %S
; valid users = MYDOMAIN\%S

[homes]는 공유이름.
browseable : 공유자원을 보이게 하거나 숨길 수 있다.
writable : 공유자원에 대한 쓰기권한 설정
valid users : 공유자원에 대해서 access 가능한 사용자
두명이상이면 스페이스문자를 구분자로 하고 계정을 적는다.




[printers]
comment = All Printers
path = /var/spool/samba
browseable = no
guest ok = no
writable = no
printable = yes

# A publicly accessible directory, but read only, except for people in
# the "staff" group
[public]
comment = Public Stuff
path = /home/samba
public = yes
writable = yes
; printable = no
write list = +staff
[public] 공유이름
public : yes 로 설정될 경우 모든 사용자에게 공유자원 access를 허용
write list : 쓰기 가능한 사용자 리스트. +staff 는 그룹사용자를 의미한다.




[public22]
comment = Public Stuff
path = /home/samba1
public = yes
writable = yes
; printable = no
write list = +staff

[share2]
comment = Public Stuff
path = /home/samba2
public = yes
writable = yes
; printable = no
write list = +staff

*. magic cookies: 삼바의 smb.conf에서도 아래의 magic cookies를 사용할 수 있다.
%u : 현재 사용중인 유저
%g : 현재 사용중인 유저 그룹
%m : 클라이언트의 NetBIOS이름
%v : 버전
%h : 호스트이름
%p : 서버의 홈디렉토리 경로
%d : 서버의 프로세서ID
%S : 현재 사용되는 서비스 이름
%P : 현재 사용되는 서비스의 루트 디렉토리
%U : 세션의 유저
%G : 셔션의 유저그룹
%H : %u로 주어진 유저의 홈디렉토리
%L : 서버의 NetBIOS이름
%M : 클라이언트 머신 이름
%N : NIS 홈디렉토리 서버의 이름
%I : 클라이언트 머신 IP
%T : 날짜와 시간


TDB (Trivial DB)

passdb.tdb 파일에 삼바 사용자 계정과 패스워드가 기록된다.
이 파일을 보거나 설정하기위해서는 pdbedit 툴이 필요하다.

계정생성
[root@centos1 samba]# pdbedit -a -u sysuser2
new password:
retype new password:
Unix username: sysuser2
NT username:
Account Flags: [U ]
User SID: S-1-5-21-1841115434-4086067128-1488843553-1000
Primary Group SID: S-1-5-21-1841115434-4086067128-1488843553-513
Full Name:
Home Directory: \\centos1\sysuser2
HomeDir Drive:
Logon Script:
Profile Path: \\centos1\sysuser2\profile
Domain: CENTOS1
Account desc:
Workstations:
Munged dial:
Logon time: 0
Logoff time: never
Kickoff time: never
Password last set: 토, 26 6월 2010 13:56:54 KST
Password can change: 토, 26 6월 2010 13:56:54 KST
Password must change: never
Last bad password : 0
Bad password count : 0
Logon hours : FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
[root@centos1 samba]#

*. 삼바 계정을 추가할 경우 /etc/passwd 에 등록되어 있는 계정이라야 한다.

[root@centos1 samba]# pdbedit -L ; 계정정보보기
user2:1012:
suser1:1009:
user1:500:
smuser1:1011:
sysuser2:1016:
[root@centos1 samba]#
[root@centos1 samba]# pdbedit -x sysuser2 ; 삼바계정 삭제
[root@centos1 samba]# pdbedit -L sysuser2
Username not found!
[root@centos1 samba]#

암호를 변경하는 경우에는 smbpasswd 명령어로 한다.
계정 생성 및 삭제 변경은 smbpasswd 로도 할수 있다.
[root@centos1 samba]# smbpasswd -a sysuser4
New SMB password:
Retype new SMB password:
Added user sysuser4.
[root@centos1 samba]#

삼바계정 삭제하기.
[root@centos1 samba]# smbpasswd -x sysuser4
Deleted user sysuser4.
[root@centos1 samba]#

삼바계정 disable 하기
[root@centos1 samba]# smbpasswd -d sysuser3
Disabled user sysuser3.
[root@centos1 samba]#

disable 상태의 삼바계정 enable 상태로 설정하기
[root@centos1 samba]# smbpasswd -e sysuser3
Enabled user sysuser3.
[root@centos1 samba]#

mswindows 공유자원 보기

[root@centos1 ~]# smbclient -L //192.168.203.1 -U lee
Password:
Domain=[UNIXUNIX-LEE] OS=[Windows 5.1] Server=[Windows 2000 LAN Manager]

Sharename Type Comment
--------- ---- -------
ms_share Disk
E$ Disk Default share
IPC$ IPC Remote IPC
D$ Disk Default share
I$ Disk Default share
G$ Disk Default share
F$ Disk Default share
ADMIN$ Disk Remote Admin
H$ Disk Default share
C$ Disk Default share
J$ Disk Default share
session request to 192.168.203.1 failed (Called name not present)
session request to 192 failed (Called name not present)
Domain=[UNIXUNIX-LEE] OS=[Windows 5.1] Server=[Windows 2000 LAN Manager]

Server Comment
--------- -------

Workgroup Master
--------- -------
[root@centos1 ~]#


[root@centos1 ~]# smbclient //192.168.203.1/ms_share -U lee
Password:
Domain=[UNIXUNIX-LEE] OS=[Windows 5.1] Server=[Windows 2000 LAN Manager]
smb: \>

명령어 리스트는 help 로 볼수 있다.
smb: \> help
? altname archive blocksize cancel
case_sensitive cd chmod chown close
del dir du exit get
getfacl hardlink help history lcd
link lock lowercase ls mask
md mget mkdir more mput
newer open posix posix_open posix_mkdir
posix_rmdir posix_unlink print prompt put
pwd q queue quit rd
recurse reget rename reput rm
rmdir showacls setmode stat symlink
tar tarmode translate unlock volume
vuid wdel logon listconnect showconnect
!
smb: \> help pwd
HELP pwd:
show current remote directory (same as 'cd' with no args)

smb: \>

* ftp 명령어와 비슷한것이 많다.
cd ; remote 디렉토리 이동
lcd : local 디렉토리 이동
put,mput : 파일 upload
get,mget : 파일 download
prompt : 파일전송시 interactive mode on/off

/tmp 디렉토리에 파일을 다운 받는 예.
smb: \> ! pwd
/root
smb: \> lcd /tmp
smb: \> ! pwd
/tmp
smb: \> get abc.txt
getting file \abc.txt of size 7 as abc.txt (0.6 kb/s) (average 0.6 kb/s)
smb: \>

삼바공유자원 mount

mount.cifs

[root@centos1 ~]# mount.cifs //192.168.203.1/ms_share /mnt/mswin1 -o user=lee
Password:
[root@centos1 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 4956284 4394240 306212 94% /
/dev/sda5 497829 10544 461583 3% /data
/dev/sda2 1649488 684620 879724 44% /home
tmpfs 257720 0 257720 0% /dev/shm
//192.168.203.1/ms_share
81923432 78173908 3749524 96% /mnt/mswin1
[root@centos1 ~]#

부팅할때 자동으로 마운트되게 하거나 마운트할때 마다 옵션을 사용하기 싫으면
/etc/fstab 파일에 아래처럼 등록한다.

[root@centos1 mswin1]# tail -1 /etc/fstab
//192.168.203.1/ms_share /mnt/mswin1 cifs noauto,user=lee,pass=1234,dir_mode=0755,file_mode=0644,noexec 0 0
[root@centos1 mswin1]#
noauto 옵션은 부팅할때 자동 마운트 하지 않는다.
dir_mode 및 file_mode 는 윈도우 자원을 마운트 했을때 퍼미션이 비정상적으로 표시될 수 있는데
그것을 제대로 설정하기 위한것이다.
ex)
[root@centos1 mswin1]# ls -l
합계 2
-rwxrwSrwx 1 root root 5 6월 26 11:23 2.txt
-rwxrwSrwx 1 root root 7 6월 26 12:26 abc.txt
-rwxrwSrwx 1 root root 26 6월 26 11:07 testfile.txt

*. 연결 상태는 linux 에서는 smbstatus 그리고 mswindows cmd 에서는 net use 로 확인할 수 있다.

[root@centos1 home]#
[root@centos1 mswin1]# mount.cifs //192.168.203.1/d$/ms_share /mnt/mswin1 -o user=lee,pass=xxxx
[root@centos1 mswin1]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 4956284 4530284 170168 97% /
/dev/sda5 497829 10544 461583 3% /data
/dev/sda2 1649488 684416 879928 44% /home
tmpfs 257720 0 257720 0% /dev/shm
//192.168.203.1/d$/ms_share
81923432 73597756 8325676 90% /mnt/mswin1
[root@centos1 mswin1]#

[root@centos1 mnt]# mount.cifs //192.168.203.1/d$/ms_share /mnt/mswin1 -o user=lee
Password:

root@centos1 home]# smbstatus
[root@centos1 samba]# smbstatus

Samba version 3.0.33-3.28.el5
PID Username Group Machine
-------------------------------------------------------------------

Service pid machine Connected at
-------------------------------------------------------
share2 3522 unixunix-lee Fri Jun 25 20:24:30 2010
public 3522 unixunix-lee Fri Jun 25 20:11:42 2010
public22 3522 unixunix-lee Fri Jun 25 20:24:31 2010
IPC$ 3522 unixunix-lee Fri Jun 25 20:12:40 2010

Locked files:
Pid Uid DenyMode Access R/W Oplock SharePath Name Time
------------------------------------------------------------------------------------------------------------------------------------
3522 99 DENY_NONE 0x100001 RDONLY NONE /home/samba . Fri Jun 25 20:16:18 2010


C:\Documents and Settings\lee>net use
새 연결 정보가 저장됩니다.

상태 로컬 원격 네트워크

-------------------------------------------------------------------------------
OK \\Centos1\public Microsoft Windows 네트워크
OK \\CENTOS1\PUBLIC22 Microsoft Windows 네트워크
OK \\CENTOS1\SHARE2 Microsoft Windows 네트워크
명령을 잘 실행했습니다.


C:\Documents and Settings\lee>
C:\Documents and Settings\lee>net use \\Centos1\public22
로컬 이름
원격 이름 \\Centos1\public22
리소스 유형 Disk
상태 OK
열린 수 1
연결 수 12
명령을 잘 실행했습니다.


C:\Documents and Settings\lee>net use \\Centos1\public
로컬 이름
원격 이름 \\Centos1\public
리소스 유형 Disk
상태 OK
열린 수 1
연결 수 12
명령을 잘 실행했습니다.

* 연결을 끊는경우
C:\Documents and Settings\lee>net use \\Centos1\public /del

* 연결을 전부 끊는경우
C:\Documents and Settings\lee>net use * /del
새 연결 정보가 저장됩니다.

*. pdbedit 로 삼바 계정을 관리할 수 있다.
[root@centos1 mswin1]# pdbedit -L
user2:1012:
suser1:1009:
user1:500:
smuser1:1011:
[root@centos1 mswin1]#

*. windows 에서 삼바서버 접속시 한글파일명이 깨져서 보이는 경우에는
다음과 같이 smb.conf 파일에 문자셋 설정을 하여야 한다.
# ----------------------- Network Related Options -------------------------
dos charset=euckr
unix charset=UTF-8

*. MSwindos 에서 웹페이지를 작성하여 /usr/local/apache/htdocs 디렉토리에 저장하는 경우
에는 아래처럼 하면 된다.
htdocs 에 파일을 저장할 수 있는 권한을 smbuser1 이라는 삼바계정으로 하고자 한다면
[root /etc/samba]# chown -R smbuser1 /usr/local/apache/htdocs
그리고 smbuser1의 계정으로 자신의 홈디렉토리에 htodcs 디렉토리를 심볼릭 링크 걸면된다.
[smbuser1@centos1 ~]$ ln -s /usr/local/apache/htdocs htdocs
여기까지 작업이 끝나면 mswindows 에서 쉽게 리눅스의 htdocs 에 파일을 저장할 수 있다.

*. iptables 을 사용하는 경우 remote에서 삼바서버에 접속하기 위해서 삼바서버포트를
열어둬야 한다.
[root@centhost ~]# vi /etc/sysconfig/iptables
아래 내용 추가

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 137:139 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m udp -p udp --dport 137:139 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 445 -j ACCEPT

'Log > Linux' 카테고리의 다른 글

ACL (Access Control List)  (0) 2011.11.28
메일서비스(sendmail)  (0) 2011.11.28
IDS - snort 1  (0) 2011.11.28
tcpdump - packet capture / 분석  (0) 2011.11.28
포트스캔 및 차단  (0) 2011.11.28
Posted by logwatch

2011. 11. 28. 19:35 Log/Linux

IDS - snort 1

snort (http://www.snort.org)

참고 문서 : snort.pdf

네트워크기반 IDS

Ineternet ---- Router ------------ firewall ------------------ intranet
| | |
IDS | IDS
|----- IDS
|
DMZ

- open source NIDS
실시간 네트워크 트랙픽 분석과 로깅을 할수 있다.
프로토콜 분석, 다양한 공격을 탐지할 수 있다.
버퍼오버플로오 스탤스 스캔 , CGI 공격, OS 핑거프린터 시도를 포함한 다양한 공격을 탐지해 낼수 있다.

- 설치

snort 설치전에 필요한 패키지를 먼저 설치하여야 한다.

1. mysql 서버 및 클라이언트를 설치하여야 한다.
2. libpcap 을 설치해야 한다. (yum 으로 설치가능하다)
- snort 를 설치하기위해서는 libpcap을 컴파일해서 설치하는것이 더 편리한거
같습니다.
http://www.tcpdump.org/release (여기서 libpcap 소스파일을 다운로드 받는다)
다운받아서 압축을 풀고 ./configure ; make ; make install

4. http://www.pcre.org 에서
pcre(Perl Compatible Regular Expressions)최신 소스 패키지를 다운로드 받는다.
압축을 풀고 ./confiugre 스크립트를 옵션없이 실행하고 컴파일 한다.
./configure ; make ; make install

5. snort 설치
http://www.snort.org
http://www.snort.org/downloads 여기서 소스파일을 받는다.
6월14일 현재 최신버전은 snort-2.8.6.tar.gz 이다.

압축을 풀고
./configure --prefix=/usr/local/snort-2.8.6 --with-mysql=/usr/local/mysql

옵션설명
--prefix ; make install 이 끝났을때 snort 가 설치될 디렉토리를 명시하기 위한것.
--with-mysql ; snort 가 mysql 과 연동되기 위한 옵션.
에러없이 configure 가 완료되면
make && make install

*. 아래내용은 snort 가 패킷을 table 에 저장하기 위해서
필요한 테이블을 생성하는 작업이다.

[root@centos1 libpcap-0.9.4]# mysql -u root -p
mysql> create database snort
mysql> use snort
Database changed
mysql> source /tmp/snort-2.8.6/schemas/create_mysql
mysql> show tables;
+------------------+
| Tables_in_snort |
+------------------+
| data |
| detail |
| encoding |
| event |
| icmphdr |
| iphdr |
| opt |
| reference |
| reference_system |
| schema |
| sensor |
| sig_class |
| sig_reference |
| signature |
| tcphdr |
| udphdr |
+------------------+
16 rows in set (0.01 sec)

mysql>

mysql> grant insert,select on snort.* to snort@localhost
-> identified by 'pass1234'; <= snort 계정을 만들고 암호는 pass1234 로 지정.
그리고 snort db 에 대해서 insert 권한과 select 권한을 허락함.
Query OK, 0 rows affected (0.06 sec)

mysql>flush privileges; <= user table reload

세가지 주 사용방법.
- tcpdump 와 같은 packet sniffer 로 사용.
- 패킷 logger 로 사용(network traffic 디버깅에 유용하다)
- 네트워크 탐지 시스템으로 사용.

snort 로그패킷은 database 또는 아스키코드 포맷으로 변환할 수 있다.

-b tcpdump 패킷처럼 바이너리형태로 캡처한다. 이 옵션은 text 형태의 변환과정이 필요없으므로
빠르다. 디폴트 파일명은 snort.log.timestamp 형식이다.
다른이름으로 캡처하려면 -L 옵션이 필요하다.

-c configfile
config 파일이 있는 rule 을 사용한다.

-e Display/log the link layer packet headers.

-b Log packets in tcpdump format (much faster!)
-c Use Rules File
-d Dump the Application Layer
-D Run Snort in background (daemon) mode
-T Test and report on the current Snort configuration
-v Be verbose
-V Show version number
-X Dump the raw packet data starting at the link layer


packet sniffer 방식

[root@centos1 snort]# snort -v
Running in packet dump mode

--== Initializing Snort ==--
Initializing Output Plugins!
***
*** 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
05/27-19:46:09.562589 ARP who-has 192.168.0.21 tell 192.168.0.1

05/27-19:46:09.565495 ARP reply 192.168.0.21 is-at 0:17:31:15:CD:E6

05/27-19:46:11.026841 192.168.0.1:3072 -> 239.255.255.250:1900
UDP TTL:1 TOS:0x0 ID:0 IpLen:20 DgmLen:293 DF
Len: 265
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
05/27-19:46:11.028662 192.168.0.1:3072 -> 239.255.255.250:1900
UDP TTL:1 TOS:0x0 ID:0 IpLen:20 DgmLen:365 DF
Len: 337
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+

05/27-19:46:11.030237 192.168.0.1:3072 -> 239.255.255.250:1900
UDP TTL:1 TOS:0x0 ID:0 IpLen:20 DgmLen:361 DF
Len: 333
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=

- 패킷 logging 방식 (패킷을 파일에 저장하는 방식)

먼저 패킷을 저장할 디렉토리를 생성한다.
mkdir /var/log/snort


[root@centos1 snort]# snort -vde -l /var/log/snort -K pcap

-v : verbose
-d : 애플리케이션 계층의 데이터를 Hex code나 아스키 코드로 출력한다.
-e : MAC 주소 정보도 출력한다.
-l : log를 저장할 디렉토리
-K [logging-mode] : default logging mode is pcap.
유효한 옵션은 pcap, ascii, none.
pcap : pcap(tcpdump) format 으로 저장
ascii : 아스키포맷으로 저장
none : 로깅하지 않음.
디폴트 로깅디렉토리는 /var/log/snort 임.

*. 기타옵션
snot -vde port 80 ; 웹 서비스 관련 패킷만 캡처
snot -vd host 192.168.100.1 ; 특정 호스트 관련 패킷만 캡쳐
snot -vde udp ; udp 프로토콜 관련 패킷만 캡쳐


[root@centos1 snort]# snort -vd -l /var/log
-l : logging 디렉토리 지정.

[root@centos1 snort]# ls /var/log/snort.log.*
/var/log/snort.log.1274959324
[root@centos1 snort]#

root@centos1 snort]# snort -vd -l /var/log -K ascii

침입탐지모드(NIDS mode)
- rule 을 이용한 패킷캡처.

*. snort rule 설치후 test ( 에러가 나면 아래처럼 에러를 수정한다)
==========================================================
root@centos1 /usr/local/snort-2.8.6/etc]# snort -c ./snort.conf
Running in IDS mode

--== Initializing Snort ==--
Initializing Output Plugins!
Initializing Preprocessors!
Initializing Plug-ins!
Parsing Rules file "./snort.conf"
PortVar 'HTTP_PORTS' defined : [ 80 1220 2301 3128 7777 7779 8000 8008 8028 8080 8180 8888 9999 ]
PortVar 'SHELLCODE_PORTS' defined : [ 0:79 81:65535 ]
PortVar 'ORACLE_PORTS' defined : [ 1024:65535 ]
PortVar 'SSH_PORTS' defined : [ 22 ]
Detection:
Search-Method = AC-Full-Q
Split Any/Any group = enabled
Search-Method-Optimizations = enabled
Maximum pattern length = 20
ERROR: parser.c(5161) Could not stat dynamic module path "/usr/local/lib/snort_dynamicpreprocessor/": No such file or directory.
Fatal Error, Quitting..
[root@centos1 /usr/local/snort-2.8.6/etc]#
설정 파일안에 경로가 잘못되어 에러가 발생했다.
정확한 파일경로를 찾아서 설정파일에서 해당파일 경로를 수정한다.

[root@centos1 /usr/local/snort-2.8.6]# find . -name snort_dynamic*
./lib/snort_dynamicengine
./lib/snort_dynamicpreprocessor
./src/snort_dynamicsrc
[root@centos1 /usr/local/snort-2.8.6]#

[root@centos1 /usr/local/snort-2.8.6/etc]# snort -c ./snort.conf
Running in IDS mode

--== Initializing Snort ==--
Initializing Output Plugins!
Initializing Preprocessors!
Initializing Plug-ins!
Parsing Rules file "./snort.conf"
PortVar 'HTTP_PORTS' defined : [ 80 1220 2301 3128 7777 7779 8000 8008 8028 8080 8180 8888 9999 ]
PortVar 'SHELLCODE_PORTS' defined : [ 0:79 81:65535 ]
PortVar 'ORACLE_PORTS' defined : [ 1024:65535 ]
PortVar 'SSH_PORTS' defined : [ 22 ]
Detection:
Search-Method = AC-Full-Q
Split Any/Any group = enabled
Search-Method-Optimizations = enabled
Maximum pattern length = 20
ERROR: parser.c(5161) Could not stat dynamic module path "/usr/local/snort-2.8.6/lib/snort_dynamicrules": No such file or directory.
Fatal Error, Quitting..
에러가 발생했다.
[root@centos1 /usr/local/snort-2.8.6/etc]# find . -name snort_dynamicrules
[root@centos1 /usr/local/snort-2.8.6/etc]# cd ..
[root@centos1 /usr/local/snort-2.8.6]# find . -name snort_dynamicrules
[root@centos1 /usr/local/snort-2.8.6]# ; 해당 파일이 없다.
설정파일에서 주석처리해야 한다.

[root@centos1 /usr/local/snort-2.8.6/etc]# snort -c ./snort.conf
...
...
...
161 client (Footprint)
443 client (Footprint) server (Footprint)
Stream5 UDP Policy config:
Timeout: 180 seconds
ERROR: ./snort.conf(193) => Invalid keyword 'compress_depth' for 'global' configuration.
Fatal Error, Quitting..
[root@centos1 /usr/local/snort-2.8.6/etc]# ; 193라인에서 에러 발생

파일열어서 주석처리한다. compress_depth 2048
========================================================



snort 를 실행하고 패킷이 수집되는 동안 잠시기다렸다가 끝내고 확인해보면
아래와 같이 패킷이 저장된 파일을 확인할 수 있다.

[root@centos1 snort]# pwd
/var/log/snort
[root@centos1 snort]# file snort.log.1274957588
snort.log.1274957588: tcpdump capture file (little-endian) - version 2.4 (Ethernet, capture length 1514)

[root@centos1 snort]# ls -F
111.67.211.105/ 192.168.0.21/ PACKET_NONIP snort.log.1274947830 snort.log.1274949793
192.168.0.1/ 192.168.100.100/ snort.log.1274943849 snort.log.1274949769 snort.log.1274957588
[root@centos1 snort]#

* alert 파일 내용
[**] [1:1002:13] WEB-IIS cmd.exe access [**]
[Classification: Web Application Attack] [Priority: 1]
05/28-09:03:28.187553 192.168.100.100:35845 -> 192.168.100.1:80
TCP TTL:64 TOS:0x10 ID:7084 IpLen:20 DgmLen:66 DF
***AP*** Seq: 0x2AF77A2 Ack: 0x610DE601 Win: 0x5C TcpLen: 32
TCP Options (3) => NOP NOP TS: 247890360 87338255

[**] [119:19:1] (http_inspect) LONG HEADER [**]
[Priority: 3]
05/28-09:05:22.604075 192.168.0.29:1402 -> 202.131.27.89:80
TCP TTL:128 TOS:0x0 ID:38217 IpLen:20 DgmLen:1454 DF
***A**** Seq: 0xAC6BD2D Ack: 0x9CA28C12 Win: 0x4470 TcpLen: 20

snort 가 남긴 alert 파일 내용이다.

snort.conf 파일에 보면
include $RULE_PATH/web-iis.rules

그리고 rule 파일은 rule 을 설치한 디렉토리에
web-iis.rules 파일에 보면

alert tcp $EXTERNAL_NET any -> $HTTP_SERVERS $HTTP_PORTS (msg:"WEB-IIS cmd.exe access"; flow:to_server,established; uricontent:" cmd.exe"; fast_pattern; nocase; metadata:policy balanced-ips drop, policy connectivity-ips drop, policy security-ips drop, servi ce http; classtype:web-application-attack; sid:1002; rev:13;)

이 rule 설정에 의해 위에 출력된것과 같은 alert 메세지가 남는다.


*. mysql db 와 연동이 되게 하기위해서는
운영중인 snort 를 종료시키고

=> killall snort

snort.conf 파일에서 아래내용을 확인하고 수정한다.

# database
# output database: alert, , user= password= test dbname= host=
# output database: log, , user= password= test dbname= host=

아래처럼 수정한다.

# database
output database: alert, mysql, user=snort password=pass1234 dbname=snort host=localhost
output database: log, mysql, user=snort password=pass1234 dbname=snort host=localhost

그런다음

다시 snort 를 구동한다.

snort -c 경로명/snort.conf

snort 가 구동될때 에러가 발생하면 에러를 잡고 다시 구동한다.


그리고 snort 계정으로 db 접속후 아래와 같이 확인해보면
table 에 로그가 잘 저장되어 있는것을 확인할 수 있다.

mysql> select * from signature
-> ;
+--------+----------------------------------------------------------------------+--------------+--------------+---------+---------+---------+
| sig_id | sig_name | sig_class_id | sig_priority | sig_rev | sig_sid | sig_gid |
+--------+----------------------------------------------------------------------+--------------+--------------+---------+---------+---------+
| 1 | (portscan) TCP Portscan | 0 | 3 | NULL | 1 | 122 |
| 2 | (portscan) Open Port | 0 | 3 | NULL | 27 | 122 |
| 3 | Consecutive TCP small segments exceeding threshold | 0 | 3 | 1 | 12 | 129 |
| 4 | WEB-IIS cmd.exe access | 1 | 1 | 13 | 1002 | 1 |
| 5 | ICMP Destination Unreachable Fragmentation Needed and DF bit was set | 2 | 3 | 7 | 396 | 1 |
| 6 | (http_inspect) LONG HEADER | 0 | 3 | 1 | 19 | 119 |
| 7 | Bad segment, adjusted size <= 0 | 0 | 3 | 1 | 5 | 129 |
+--------+----------------------------------------------------------------------+--------------+--------------+---------+---------+---------+
7 rows in set (0.03 sec)

mysql> select * from sig_class;
+--------------+------------------------+
| sig_class_id | sig_class_name |
+--------------+------------------------+
| 1 | web-application-attack |
| 2 | misc-activity |
+--------------+------------------------+
2 rows in set (0.02 sec)

mysql>

'Log > Linux' 카테고리의 다른 글

메일서비스(sendmail)  (0) 2011.11.28
samba 서비스  (0) 2011.11.28
tcpdump - packet capture / 분석  (0) 2011.11.28
포트스캔 및 차단  (0) 2011.11.28
로그서비스 - syslog / logrotate / logwatch  (0) 2011.11.28
Posted by logwatch

블로그 이미지
내가 나에게 확인 하는 블로그
logwatch

태그목록

공지사항

Yesterday
Today
Total

달력

 « |  » 2025.4
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30

최근에 올라온 글

최근에 달린 댓글

글 보관함