달력

42024  이전 다음

  • 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
tripwire설치 및 운영가이드

2001. 11.

장윤숙, jys@certcc.or.kr

 

1. 개요

공격자가 시스템 침입에 성공하면 다음번 침입을 쉽게 하기위해 루트킷(rootkit)이나 트로이잔 목마(trojan horse)프로그램을 설치하는 경우가 대부분이다.

루트킷에 포함되는 프로그램으로는 ps, ls, netstat, login등의 시스템 프로그램들이 있는데, 이런 루트킷은 시스템에 원래 있었던 프로그램들과 바꿔치기되서 관리자가 시스템을 점검해도 이상없게 보이도록 하고 공격자의 행동을 숨기기도 한다.

예를 들어 ps를 바꿔치기 해서 시스템 관리자가 ps를 실행시켜도 공격자가 실행한 프로그램은 보이지 않게 한다든지, ls를 바꿔치기 해서 ls로 보더라도 공격자가 만든 파일은 보이지 않도록 하는 것이다.

또한 공격자는 공격이 성공한 후 시스템의 취약점을 찾아서 패치를 해서 다른 공격자가 들어오는 것을 막기도 한다.

이렇게 침입 당한 시스템에서 어떤 파일이나 디렉토리가 수정, 변조되었는지 등을 찾는 것이 쉽지만은 않다. 혹 파일의 크기나 수정된 시간, 생성된 시간 등을 비교하여 알아낸다고 할지라도 파일의 크기나 시간정보 조차도 변조가 가능하므로 이를 믿을 수 없다.

따라서 원래 파일의 무결성을 체크할 수 있는 프로그램이 필요할 것이고, 이를 효율적으로 해주는 도구가 바로 tripwire이다.

tripwire는 MD5, SHA, CRC-32등의 다양한 해쉬 함수를 제공하고, 파일들에 대한 데이터베이스를 만들어 이를 통해 해커들에 의한 파일들의 변조여부를 판별하므로 관리자들이 유용하게 사용할 수 있다.

tripwire는 먼저 시스템에 존재하는 파일에 대해 데이터 베이스를 만들어 저장한 후 생성된 데이터베이스와 비교하여 추가·삭제되거나 변조된 파일이 있는지 점검하고 관리자에게 레포팅해주는 무결성 검사도구이다.

Top

2. tripwire 구하기

tripwire는 1992년 Purdue University의 Dr. Eugene Spafford와 Gene Kim에 의해 개발되었다. 초기의 tripwire 1.x는 오픈소스이었으나 2.x로 오면서 tripwire사에서 상용화하여 발표하고 tripwire 1.3대의 ASR(Academic Source Release)에 대해서는 공개로 배포하고 있다.

또한 tripwire사에서는 tripwire 오픈소스 프로젝트를 추진하여 Linux 시스템에서는 Open Source로 2.3대의 tripwire를 다운받아 설치할수 있다. (http://www.tripwire.org) 그러나 Solaris, Windows NT, HP-UX, IBM AIX 시스템에서 2.x를 설치하려면 상업용 버전을 이용하여야 한다. (http://www.tripwire.com)

Linux 7.x 시스템의 경우 대부분 tripwire가 설치되어 있기 때문에 다운받지 않고 설치할수 있으며, 본인은 리눅스 Linux7.0 환경에서 tripwire-2.3 버전을 설치 및 테스트하였다.

설치여부나 설치된 버전을 확인하고자 하는 경우에는 다음 명령을 이용한다.

rpm -qa | grep tripwire

만약 시스템에 설치되어 있지 않다면 tripwire 프로그램(http://www.tripwire.org)을 다운받아 설치한다.

Top

3. tripwire 설치

여기서는 rpm로 제공되는 2.3버전을 Linux 7.0에 설치할것이다.

tripwire를 rpm으로 설치할 경우 설치과정은 크게 다음의 4단계로 볼 수 있다.

1. tripwire 설정파일·정책파일 생성하기(twinstall.sh)
2. 데이터베이스 초기화 (tripwire --init)
3. 무결성 검사 (tripwire --check)
4. 데이터베이스 갱신(tripwire --update)

이제 본격적인 설치에 대해 살펴보도록 하자.

tripwire다운받기

http://www.tripwire.org에서 운영하는 시스템에 맞는 tripwire를 rpm으로 다운받는다.

압축풀기

다운로드받은 압축 파일을 푼다
# tar -xzvf tripwire-2.3-47.i386.tar.gz
압축을 풀어 생긴 tripwire-2.3-47.i386.rpm 패키지 파일을 설치한다.
# rpm -Uvh tripwire-2.3-47.i386.rpm
기본적으로 tripwire는 /etc/tripwire디렉토리에 설치된다.
/etc/tripwire 디렉토리에 생성되는 파일의 내용을 보면 다음과 같다.
-rwxr-xr-x 1 root root 603 6월 22 03:02 twcfg.txt ======> 설치를 위한 환경설정파일
-rwxr-xr-x 1 root root 10100 6월 22 03:02 twinstall.sh ======> 설치스크립트
-rwxr-xr-x 1 root root 41255 6월 22 03:02 twpol.txt ======> 정책파일

Top

tripwire 설정파일·정책파일 생성하기

# ./twinstall.sh
twinstall.sh를 실행시키면 tripwire는 site keyfile과 local keyfile을 생성하기 위한 Passphrases를 입력하도록 한다.
site keyfile은 정책파일과 환경파일을 설정하는데 사용되고, local keyfile은 tripwire 데이터베이스와 레포트 파일을 초기화하고 보호하는데 사용되는 일종의 암호의 일종이다. (passphrases는 최소 8자 이상의 문자열이어야 한다.)
설정파일·정책파일을 생성하는 과정을 살펴보면 아래와 같다.

1) keyfile passphrase를 생성하기 위해 몇 개의 passphrase를 요구한다.

Creating key files...
(When selecting a passphrase, keep in mind that good passphrases typically
have upper and lower case letters, digits and punctuation marks, and are
at least 8 characters in length.)

2) site keyfile passphrase를 입력하면 다시 한번 확인하고 키를 생성한다.

Enter the site keyfile passphrase:
Verify the site keyfile passphrase:
Generating key (this may take several minutes)...Key generation complete.
(When selecting a passphrase, keep in mind that good passphrases typically
have upper and lower case letters, digits and punctuation marks, and are
at least 8 characters in length.)

Top

3) local keyfile passphrase를 입력하면 다시 한번 확인하고 키를 생성한다.

Enter the local keyfile passphrase:
Verify the local keyfile passphrase:
Generating key (this may take several minutes)...Key generation complete.
----------------------------------------------

4) site passphrase를 이용하여 configuration file을 완성한다.

Signing configuration file...
Please enter your site passphrase:
Wrote configuration file: /etc/tripwire/tw.cfg
A clear-text version of the Tripwire configuration file
/etc/tripwire/twcfg.txt
has been preserved for your inspection. It is recommended
that you delete this file manually after you have examined it.
----------------------------------------------

5) site passphrase를 이용하여 policy file을 완성한다.

다음의 policy file이 생성되었다는 메시지와 함께 설치가 끝나게 된다.
Signing policy file...
Please enter your site passphrase:
Wrote policy file: /etc/tripwire/tw.pol
A clear-text version of the Tripwire policy file
/etc/tripwire/twpol.txt
has been preserved for your inspection. This implements
a minimal policy, intended only to test essential
Tripwire functionality. You should edit the policy file
to describe your system, and then use twadmin to generate
a new signed copy of the Tripwire policy.

Top

데이터베이스 초기화

다음의 명령어를 실행하여 데이터베이스를 초기화한다. (/usr/sbin에서)

# ./tripwire --init

이때 tripwire는 local passphrase를 요구한다.

Please enter your local passphrase:
Parsing policy file: /etc/tripwire/tw.pol

tripwire는 데이터베이스를 생성하고 그 결과를 출력한다.

Generating the database...
*** Processing Unix File System ***
Wrote database file: /var/lib/tripwire/cyber118.twd
The database was successfully generated.

설정과정이 끝났으면 twcfg.txt과 twpol.txt 파일을 삭제하거나 안전한 장소에 보관하여야 한다.

Top

무결성 검사

다음의 명령으로 시스템에 있는 파일들에 대한 무결성을 검사할수 있다.

# ./tripwire --check
Parsing policy file: /etc/tripwire/tw.pol
*** Processing Unix File System ***
Performing integrity check...
Wrote report file: /var/lib/tripwire/report/cyber118-20010629-005928.twr

무결성 검사가 끝나면 /var/lib/tripwire/report 아래에 결과 파일이 생성된다.

Top

데이터베이스 갱신

무결성 검사 후 발견되어진 변경 파일 중 침입에 의한 것이 아니라 정상적인 변화라면 기존에 만들어져 있던 데이터베이스를 갱신하여야한다.

# ./tripwire --update또는 # ./tripwire -m u

tripwire --update mode을 이용하면 데이터베이스의 재초기화 없이도 데이터베이스를 갱신할수 있다.

■ 정책파일 갱신

정책파일을 갱신하는 방법에는 tripwire --update-police과 twadmin --creat-polfile 두가지가 있다.

# ./tripwire --update-police 또는 # ./tripwire -m p /etc/tripwire/policy.txt

tripwire --update-police mode는 이전의 rule과 비교하여 새로운 rule에 대한 정보를 업데이트하는 것이므로 데이터베이스를 재초기화 하지 않아도 된다.

# ./twadmin --creat-polfile # ./twadmin --creat-polfile mypol.txt (여기서mypol.txt는 새로운 정책파일의 이름이다.)

twadmin --creat-polfile mode는 새로운 정책파일을 만드는 명령으로 이를 위해서는 데이터베이스의 재초기화가 필요하다.

Top

4. Tripwire Configuration File & Policy File Reference

4-1. 환경설정파일(Configuration File-twcfg.txt)

환경설정파일(twcfg.txt)은 tripwire유틸리티와 설정파일들이 어디에 설치되어 있는지 등에 대한 정보를 저장하고 있는데 내용을 살펴보면 다음과 같다.

ROOT =/usr/sbin
POLFILE =/etc/tripwire/tw.pol
DBFILE =/var/lib/tripwire/$(HOSTNAME).twd
REPORTFILE =/var/lib/tripwire/report/$(HOSTNAME)-$(DATE).twr
SITEKEYFILE =/etc/tripwire/site.key
LOCALKEYFILE =/etc/tripwire/$(HOSTNAME)-local.key
EDITOR =/bin/vi
LATEPROMPTING =false
LOOSEDIRECTORYCHECKING =false
MAILNOVIOLATIONS =true
EMAILREPORTLEVEL =3
REPORTLEVEL =3
MAILMETHOD =SENDMAIL
SYSLOGREPORTING =false
MAILPROGRAM =/usr/sbin/sendmail -oi -t

Top

아래의 표는 설정파일 변수들과 그 변수들이 무엇을 나타내는지 등에 대해 요약한 것이다.

설정파일 변수들

설명

Required

Variables

POLFILE

정책파일의 위치 지정 Initial value: /etc/tripwire/tw.pol

DBFILE

데이터베이스 파일의 위치 지정 Initial value: /etc/tripwire/$(HOSTNAME).twd

REPORTFILE

생성된 결과 파일의 위치 지정 Initial value: /var/lib/report/$(HOSTNAME)-$(DATE).twr

SITEKEYFILE

사이트키 파일의 위치 지정 Initial value: /etc/tripwire/site.key

LOCALKEYFILE

로컬키 파일의 위치 지정 Initial value: /etc/tripwire/$(HOSTNAME)-local.key

Optional

Variables

EDITOR

사용하고자 하는 편집기의 위치 지정 Initial value: /bin/vi

LATEPROMPTING

tripwire가 패스워드 요구하는 것을 가장 마지막에 하도록 설정 Initial value: false

SYSLOGREPORTING

SYSLOGREPORTING이 true로 설정되면 database initializations, integrity checks, database updates, and policy file등의 update 을 syslog에 알림. Initial value: true.

LOOSEDIRECTORYCHECKING

디렉토리 변경사항이 있는지를 출력해야 하는 것을 나타냄. 설정되어 있지 않으면 변화된 파일뿐만 아니라 그 파일이 있는 디렉토리도 결과에 출력되고 설정되면 파일의 변화만을 출력함. Initial value: false

REPORTLEVEL

twprint --print-report command로 report를 출력할 때의 레벨로서 0-4까지의 레포트레벨이 있음. Initial value: 3

Email

Notification

Variables

MAILNOVIOLATIONS

무결성 검사시 아무런 변화가 없을 때에도 email notification을 할지를 나타냄. Initial value: true

EMAILREPORTLEVEL

email report level로 0-4
Initial value: 3

MAILMETHOD

email notification을 위해 사용할 protocol명시 Initial value: SENDMAIL

MAILPROGRAM

특정 메일 프로그램의 위치 지정 Initial value: /usr/sbin/sendmail -oi -t

Top

4-2. tripwire 정책파일 (twpol.txt)

tripwire 정책파일(twpol.txt)은 tripwire가 감시할 대상(파일, 디렉토리)과 그 위치를 명시한다.

관리하는 시스템에 맞게 정책파일(twpol.txt)을 수정할 수 있는데 이는 불필요하게 들어있는 파일을 제거하고 필요한 파일은 추가함으로써 tripwire에서 쓸모 없는 결과물이 나오는 경우를 상당히 줄일수 있도록 한다.

또한 configuration script를 실행시킨 후에 정책파일을 수정하면 데이터베이스파일을 초기화하기 전에 configuration file을 재실행해야하는 번거로움이 있으므로 tripwire를 설치하기 전에 시스템에 맞게 설정하는 것이 좋다.

① policy file의 구성요소

policy file의 기본적인 구성요소는 다음과 같다.

policy file component

meaning

Rules

policy file의 기본구성요소로
무결성 검사시 시스템의 object에 대해 monitor할 properity를 명시해주는것

Stop points

무결성 검사시 스캔하지 않을 시스템의 object 명시

Attributs

이메일을 보내거나 recursion을 조정하는 rule을 수정하는 부분

Directive

하나의 policy파일을 네트웍 서버에서 사용할 때.

Variable

관리자가 편리하게 정보를 바꾸도록 설정

Top

1) rules

rules의 기본형식은 다음과 같다.

object name -> property mask;
object name 은 스캔할 디렉토리나 파일의 경로이고
property mask는 실행 혹은 실행하지 않을 object property에 대해 설정해주는 부분이다.
(여기서 ->는 object name 과 property mask를 구별해주는 기호이고 ;은 rule의 끝을 나타낸다.)
예1) 예를 들어 /etc 디렉토리 전부에 대해서 +pinug라는 property mask로 스캔하려면 다음과 같이 기술해준다.
/etc -> +pinug;
※여기서 +pinug 라는 property mask는 관리자가 정의한것으로 이렇게 관리자가 정의해서 사용할수도 있고 이미 정해져 있는 viriable을 이용할수도 있다.
이미 정해져 있는 viriable에 대해서는 5) viriable를 참고하라.
예2) /etc 디렉토리에 대해서는 관리자가 정의한 mask1으로 스캔하고 /etc/passwd 파일에 대해서만 mask2를 써서 스캔하도록 설정할 때
/etc -> $(mask1) ;
/etc/passwd -> $(mask2) ;
property mask에 대한 표는 아래와 같다.

Top

Property

Meaning

-

Ignore the following properties

+

Record and check the following properties

p

File permissions

i

Inode number

n

Number of links (i.e., inode reference count)

u

User id of owner

g

Group id of owner

t

File type

s

File size

d

Device number of the disk on which the inode associated with the file is stored

r

Device number of the device to which the inode points.
Valid only for device objects.

b

Number of blocks allocated

m

Modification timestamp

c

Inode creation/modification timestamp

l

Indicates that the file is expected to grow.
If the file is smaller than the last recorded size, it is a violation of this property.
This can be useful for log files.

a

Access timestamp
The +a property is incompatible with the hash properties(+CMSH).
To calculate the hash, the file must be opened and read,
which changes the access timestamp.
Specifying any of +CMSH will always cause a violation of the +a property.

C

CRC-32, POSIX 1003.2 compliant 32-bit Cyclic Redundancy Check.
Choose this hash for relatively high performance but relatively low security.

M

MD5, the RSA Data Security, Inc.® Message Digest Algorithm.
Choose this hash for high security.

S

SHA, part of the SHS/SHA algorithm.
Choose this hash for high security.

H

HAVAL, a strong 128-bit signature algorithm.
Choose this hash for high security.

Top

2) Stop Points

Stop Points는 무결성 검사를 하는 동안 스캔하지 않을 object에 대해 설정하는 부분이다.
기본형식은 다음과 같다.

! object name;

예) /etc/rc.d와 /etc/muttab에 대해서는 스캔하지 않고 나머지 /etc의 모든 부분에 대해서는 스캔할 때
/etc ->$(Readonly) -ar;
!/etc/rc.d;
!/etc/mnttab;

Top

3) Rule Attributes

Rule Attributes는 정책파일 전체로 무결성 검사를 하지 않고 몇 개의 rule name 에 대해서만 점검을 한다든지 policy file에 변화가 있는 부분에 대해 관리자가 이메일로 받을 수 있도록 설정하는 등의 설정을 하는 부분이다.

예1) /usr/lib rule에 변화가 있을때 email report를 xxx@xxx.com에게 보내려할때
/usr/lib -> $(ReadOnly) ( emailto = xxx@xxx.com ) ;

예2) “"rcfiles" 라는 rule에 대해서만 무결성 검사를 하고자 할때
tripwire --check --rule-name “"rcfiles"

Rule Attributes의 내용은 아래와 같다.

Attribute

Description

rulename

Associates a name with a rule.
The default value is the last element of the object name to which the rule applies.

emailto

Specifies email address(es) to which notification of any violations is sent.
The default value is none.

severity

Associates a numeric severity level with a rule.
The default value is 0. The valid range is from 0 to 1000000.

recurse

Controls recursive scanning of directories.
True (-1), false (0), and numerical values > 0 are valid.
The default value is true.

4) Directives

하나의 policy파일을 가지고 여러대의 시스템에 공유하여 사용하고자 할 때 설정해주는 부분이다.

Top

5) Variables

policy file에서는 두가지의 variable을 사용할수 있는데 Global variables은 policy file 전체에 대해서 사용할 수 있고 local variables은 정해진 section에서만 사용 가능하다.

기본 형식은 다음과 같다.

variable = value;

예1) # Define the variable
mask1 = +pinugC-a ;
# and now use it.
/home/projectA -> $(mask1) ;
/home/projectB -> $(mask1)+MSH-db ;

미리 정해놓은 Variables에 관한 표는 아래와 같다.

Variable

Definition

ReadOnly

This variable is good for files that are widely available but are intended to be read-only.
Expands to: +pinugsmtdbCM-raclSH

Dynamic

This variable is good for monitoring user directories and files that tend to change frequently.
Expands to: +pinugtd-rsacmblCMSH

Growing

This variable is useful for files that can grow, but not shrink, such as log files:
Expands to: +pinugtdl-rsacmbCMSH

IgnoreAll

This variable tracks a file’s presence or absence, but doesn't check any other properties.
Expands to: -pinusgamctdrblCMSH

IgnoreNone*

This variable turns on all properties and provides a convenient starting point for defining your own property masks.
Expands to: +pinusgamctdrbCMSH-l

Device

This variable is useful for devices or other files that Tripwire software should not attempt to open.
Expands to : +pugsdr-intlbamcCMSH

Top

5. tripwire command

① tripwire test mode

tripwire의 email notification system의 작동을 체크하기 위해 test mode로 다음의 명령어를 쓸 수 있다.

# tripwire --test --email jys@certcc.or.kr

Sending a test message to: jys@certcc.or.kr

email notification이 올바르게 작동한다면 아래의 메시지를 받을 것이다.

Subject: Test email message from Tripwire
Date: Fri 29 Jun 2001 09:06:58 +0900
From: "Tripwire(R) 2.3.0.47" <tripwire@localhost.localdomain>
To: jys@cert.certcc.or.kr

If you receive this message, email notification from tripwire is working correctly.

Top

② crontab을 이용한 주기적인 자동점검 및 e-mail을 통해 레포트 받아보기

파일 시스템에 주기적인 점검이 없으면 tripwire는 소용이 없다. 그러므로 매일 밤 tripwire로 점검하고 이를 e-mail로 받아볼수 있도록 설정한다면 보다 편리하게 tripwire를 사용할수 있다.

1) tripwire 레포트를 만들기 위하여 shell script를 만든다.

/usr/local/bin밑에 "runtripwire.sh" 라는 파일에 아래의 내용을 포함하는 파일을 만든다.
[root@cyber118 bin]# vi runtripwire.sh
#!/bin/sh
/usr/sbin/tripwire -m c | mail -s "tripwire report from linux-1" jys@certcc.or.kr

2) crontab에 추가하기

crontab -e 명령을 써서 매일 밤 1:01에 위의 script를 실행하도록 설정한다.
1 1 * * * /usr/local/bin/runtripwire.sh
이와 같이 설정했으면 매일 밤 tripwire와 실행되어 e-mail로 결과 레포트를 받을 수 있다.

아래는 실제로 점검결과를 메일로 받은 화면이다.

아래의 결과메일에서 보면 ls, netstat, ps등이 변조되었음을 확인할수 있다.

Top

③ twprint

tripwire 데이터베이스 파일들과 바이너리들은 encode되고 sign되므로 twprint 명령어를 사용함으로써 database와 report file을 text 형식으로 볼수 있다.

예1) 데이터베이스 파일을 텍스트파일로 프린트할 때
#twprint --print-dbfile > db.txt

예2) report 결과 파일을 텍스트파일로 프린트할 때
#twprint -m r --twrfile cyber118-20010703-035644.twr

(여기서 cyber118은 machine name이고 20010703-035644은 무결성검사를 한 날짜와 시간)

■ tripwire설치를 마치며

tripwire는 생성된 데이터베이스와 비교하여서 파일에 변화가 있는지 점검한다.

그러므로 이미 해킹을 당한 후 루트킷이나 백도어 등이 설치되어 있는 상태에서 tripwire가 설치된다면 tripwire는 무용지물이다. 또한 데이터베이스를 변경할수 있는 침입자는 무결성 검사도구를 파괴할수 있으므로, 무결성 검사를 위해 사용되는 데이터베이스는 승인되지 않는 변경으로부터 보호되어야 할 것이다.

Top

참고자료

· http://www.linuxsecurity.com/feature_stories/feature_story-81.html
· http://sourceforge.net/project/showfiles.php?group_id=3130tripwire-2.3.0-docs-pdf.tar.gz
· 리눅스 보안의 모든 것 (인포 북)
· Security PLUS for UNIX (포항공대 유닉스 보안 연구회 저, 영진출판사)

Top

 

자료제공 : CERTCC-KR : 한국정보보호진흥원

Posted by tornado
|