웹사이트 검색

Debian 10에서 Tripwire IDS를 설치하고 구성하는 방법


이 페이지에서

  1. 전제 조건
  2. 시작하기\n
  3. Tripwire 설치
  4. 트립와이어 구성
  5. Tripwire IDS 확인\n
  6. Tripwire 보고서 자동화\n
  7. 결론

Tripwire는 무료 오픈 소스 Linux 침입 탐지 시스템입니다. Linux에서 파일 및 디렉토리의 무단 변경을 감지하고 보고하는 데 사용됩니다. 또한 파일/디렉토리 변경에 대한 이메일 알림을 보냅니다. Tripwire는 현재 파일 시스템 상태를 알려진 기본 상태와 비교하여 작동하며 변경 사항이 감지되면 보고합니다.

이 게시물에서는 Debian 10에서 Tripwire를 설치하고 구성하는 방법을 보여줍니다.

전제 조건

  • Debian 10을 실행하는 서버.\n
  • 루트 암호는 서버에서 구성됩니다.\n

시작하기

먼저 다음 명령을 실행하여 시스템 패키지를 업데이트된 버전으로 업데이트합니다.

apt-get update -y

모든 패키지가 업데이트되면 다음 단계로 진행할 수 있습니다.

트립와이어 설치

기본적으로 Tripwire 패키지는 Debian 10 기본 리포지토리에서 사용할 수 있습니다. 다음 명령을 사용하여 설치할 수 있습니다.

apt-get install tripwire -y

설치하는 동안 아래와 같이 이메일 구성을 선택하라는 메시지가 표시됩니다.

원하는 옵션을 선택하고 ENTER를 누르십시오. 아래와 같이 시스템 메일 이름을 설정하라는 메시지가 표시됩니다.

시스템 메일 이름을 입력하고 ENTER를 누르십시오. 아래와 같이 사이트 키 암호를 생성하라는 메시지가 표시됩니다.

예를 선택하고 ENTER를 누르십시오. 아래와 같이 Tripwire 구성 파일을 다시 빌드하라는 메시지가 표시됩니다.

예를 선택하고 ENTER를 누르십시오. 아래와 같이 Tripwire 정책 파일을 다시 작성하라는 메시지가 표시됩니다.

예를 선택하고 ENTER를 누르십시오. 아래와 같이 사이트 키 암호를 제공하라는 메시지가 표시됩니다.

암호를 입력하고 ENTER를 누르십시오. 아래와 같이 로컬 키 암호를 설정하라는 메시지가 표시됩니다.

암호를 입력하고 ENTER를 누르십시오. Tripwire가 설치되면 다음 화면이 표시됩니다.

확인 버튼을 클릭하여 설치를 마칩니다.

Tripwire 구성

다음으로 Tripwire 키를 생성하고 데이터베이스를 초기화해야 합니다. 먼저 디렉터리를 Tripwire로 변경하고 다음 명령을 사용하여 모든 키와 파일을 나열합니다.

cd /etc/tripwire/
ls

다음 출력이 표시되어야 합니다.

debian10-local.key  site.key  tw.cfg  twcfg.txt  tw.pol  twpol.txt

다음으로 Tripwire 구성 파일을 편집하고 REPORTLEVEL을 4로 설정합니다.

nano /etc/tripwire/twcfg.txt

다음 줄을 변경합니다.

REPORTLEVEL   =4

완료되면 파일을 저장하고 닫습니다.

다음으로 다음 명령을 사용하여 새 구성 파일을 생성합니다.

twadmin -m F -c tw.cfg -S site.key twcfg.txt

아래와 같이 사이트 암호를 제공하라는 메시지가 표시됩니다.

Please enter your site passphrase: 
Wrote configuration file: /etc/tripwire/tw.cfg

다음으로 twpolmake.pl 파일을 만들어 Tripwire 정책을 최적화합니다.

nano twpolmake.pl

다음 줄을 추가합니다.

#!/usr/bin/perl
$POLFILE=$ARGV[0];

open(POL,"$POLFILE") or die "open error: $POLFILE" ;
my($myhost,$thost) ;
my($sharp,$tpath,$cond) ;
my($INRULE) = 0 ;

while () {
    chomp;
    if (($thost) = /^HOSTNAME\s*=\s*(.*)\s*;/) {
        $myhost = `hostname` ; chomp($myhost) ;
        if ($thost ne $myhost) {
            $_="HOSTNAME=\"$myhost\";" ;
        }
    }
    elsif ( /^{/ ) {
        $INRULE=1 ;
    }
    elsif ( /^}/ ) {
        $INRULE=0 ;
    }
    elsif ($INRULE == 1 and ($sharp,$tpath,$cond) = /^(\s*\#?\s*)(\/\S+)\b(\s+->\s+.+)$/) {
        $ret = ($sharp =~ s/\#//g) ;
        if ($tpath eq '/sbin/e2fsadm' ) {
            $cond =~ s/;\s+(tune2fs.*)$/; \#$1/ ;
        }
        if (! -s $tpath) {
            $_ = "$sharp#$tpath$cond" if ($ret == 0) ;
        }
        else {
            $_ = "$sharp$tpath$cond" ;
        }
    }
    print "$_\n" ;
}
close(POL) ;

파일을 저장하고 닫은 후 다음 명령을 사용하여 구성 파일을 만듭니다.

perl twpolmake.pl twpol.txt > twpol.txt.new 
twadmin -m P -c tw.cfg -p tw.pol -S site.key twpol.txt.new

다음 출력이 표시되어야 합니다.

Please enter your site passphrase: 
Wrote policy file: /etc/tripwire/tw.pol

다음으로 다음 명령을 사용하여 Tripwire 데이터베이스를 생성합니다.

tripwire -m i -s -c tw.cfg

다음 출력이 표시되어야 합니다.

Please enter your local passphrase: 
### Warning: File system error.
### Filename: /var/lib/tripwire/debian10.twd
### No such file or directory
### Continuing...

다음 명령을 사용하여 생성된 데이터베이스를 표시할 수도 있습니다.

twprint -m d -d /var/lib/tripwire/debian10.twd

다음 출력이 표시되어야 합니다.

Open Source Tripwire(R) 2.4.3.7 Database

Database generated by:        root
Database generated on:        Sun 09 May 2021 08:39:18 AM UTC
Database last updated on:     Never

===============================================================================
Database Summary: 
===============================================================================

Host name:                    debian10
Host IP address:              45.58.38.142
Host ID:                      None
Policy file used:             /etc/tripwire/tw.pol
Configuration file used:      /etc/tripwire/tw.cfg
Database file used:           /var/lib/tripwire/debian10.twd
Command line used:            tripwire -m i -s -c tw.cfg 

===============================================================================
Object Summary: 
===============================================================================

-------------------------------------------------------------------------------
# Section: Unix File System
-------------------------------------------------------------------------------

Tripwire 데이터베이스를 업데이트하려면 다음 명령을 실행하십시오.

tripwire --update --accept-all

다음 출력이 표시되어야 합니다.

### Error: File could not be opened.
### Filename: /var/lib/tripwire/report/debian10-20210509-084141.twr
### No such file or directory
### Exiting...

이제 다음 명령을 사용하여 Tripwire를 테스트합니다.

tripwire -m c -s -c /etc/tripwire/tw.cfg

다음 출력이 표시되어야 합니다.

Open Source Tripwire(R) 2.4.3.7 Integrity Check Report

Report generated by:          root
Report created on:            Sun 09 May 2021 08:42:15 AM UTC
Database last updated on:     Never

===============================================================================
Report Summary:
===============================================================================

Host name:                    debian10
Host IP address:              45.58.38.142
Host ID:                      None
Policy file used:             /etc/tripwire/tw.pol
Configuration file used:      /etc/tripwire/tw.cfg
Database file used:           /var/lib/tripwire/debian10.twd
Command line used:            tripwire -m c -s -c /etc/tripwire/tw.cfg 

===============================================================================
Rule Summary: 
===============================================================================

-------------------------------------------------------------------------------
  Section: Unix File System
-------------------------------------------------------------------------------

  Rule Name                       Severity Level    Added    Removed  Modified 
  ---------                       --------------    -----    -------  -------- 
  Other binaries                  66                0        0        0        
  Tripwire Binaries               100               0        0        0        
  Other libraries                 66                0        0        0        
  Root file-system executables    100               0        0        0        
* Tripwire Data Files             100               1        0        0        
  System boot changes             100               0        0        0        
  Root file-system libraries      100               0        0        0        
  (/lib)
  Critical system boot files      100               0        0        0        
* Other configuration files       66                0        0        1        
  (/etc)
  Boot Scripts                    100               0        0        0        
  Security Control                66                0        0        0        
  Root config files               100               0        0        0        
  Devices & Kernel information    100               0        0        0        
  (/dev)
  Invariant Directories           66                0        0        0        

Total objects scanned:  27975
Total violations found:  2

===============================================================================
Object Summary: 
===============================================================================

-------------------------------------------------------------------------------
# Section: Unix File System
-------------------------------------------------------------------------------

-------------------------------------------------------------------------------
Rule Name: Tripwire Data Files (/var/lib/tripwire/debian10.twd)
Severity Level: 100
-------------------------------------------------------------------------------

기본적으로 Tripwire 보고서 파일은 /var/lib/tripwire/report/에 있습니다.

ls /var/lib/tripwire/report/

산출:

debian10-20210509-084215.twr

다음 명령을 사용하여 이 보고서를 확인할 수 있습니다.

twprint -m r -t 4 -r /var/lib/tripwire/report/debian10-20210509-084215.twr

트립와이어 IDS 확인

이 시점에서 Tripwire가 설치되고 구성됩니다. 이제 Tripwire가 작동하는지 여부를 확인할 시간입니다.

먼저 다음 명령을 사용하여 시스템에 일부 파일을 만듭니다.

touch fil1 file2 file3 file4 file5

이제 Tripwire를 실행하여 Tripwire가 이러한 파일을 감지하는지 여부를 확인하십시오.

tripwire --check --interactive

다음 출력에 새로 생성된 파일이 표시되어야 합니다.

Open Source Tripwire(R) 2.4.3.7 Integrity Check Report

Report generated by:          root
Report created on:            Sun 09 May 2021 08:46:36 AM UTC
Database last updated on:     Never

===============================================================================
Report Summary:
===============================================================================

Host name:                    debian10
Host IP address:              45.58.38.142
Host ID:                      None
Policy file used:             /etc/tripwire/tw.pol
Configuration file used:      /etc/tripwire/tw.cfg
Database file used:           /var/lib/tripwire/debian10.twd
Command line used:            tripwire --check --interactive

===============================================================================
-------------------------------------------------------------------------------
Rule Name: Other configuration files (/etc)
Severity Level: 66
-------------------------------------------------------------------------------

Remove the "x" from the adjacent box to prevent updating the database
with the new values for this object.

Modified:
[x] "/etc/tripwire"

-------------------------------------------------------------------------------
Rule Name: Root config files (/root)
Severity Level: 100
-------------------------------------------------------------------------------

Remove the "x" from the adjacent box to prevent updating the database
with the new values for this object.

Added:
[x] "/root/file4"
[x] "/root/file3"
[x] "/root/fil1"
[x] "/root/file2"
[x] "/root/file5"

Modified:
[x] "/root"

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

다음 명령을 사용하여 나중에 생성된 보고서를 확인할 수도 있습니다.

twprint --print-report --twrfile /var/lib/tripwire/report/debian10-20210509-084636.twr

Tripwire 보고서 자동화

특정 시간에 Tripwire를 실행하도록 cron 작업을 설정할 수도 있습니다. 다음 명령으로 수행할 수 있습니다.

crontab -e

다음 줄을 추가합니다.

00 06 * * * /usr/sbin/tripwire --check

완료되면 파일을 저장하고 닫습니다.

위의 파일은 매일 아침 06:00 AM에 Tripwire를 실행합니다. /var/lib/tripwire/report/에서 생성된 보고서를 확인할 수 있습니다.

결론

축하합니다! Debian 10에 Tripwire IDS를 성공적으로 설치하고 구성했습니다. 이것이 시스템에서 수정된 파일 또는 디렉토리를 확인하는 데 도움이 되기를 바랍니다.