GNU/Linux >> Linux の 問題 >  >> Debian

Debian10にTripwireIDSをインストールして設定する方法

Tripwireは、無料のオープンソースのLinux侵入検知システムです。 Linux上のファイルとディレクトリの不正な変更を検出して報告するために使用されます。また、ファイル/ディレクトリの変更に関するアラートを電子メールで送信します。 Tripwireは、現在のファイルシステムの状態を既知のベースライン状態と比較することで機能し、変更が検出されたかどうかを報告します。

この投稿では、Debian10にTripwireをインストールして設定する方法を紹介します。

前提条件
  • Debian10を実行しているサーバー。
  • ルートパスワードはサーバーで構成されています。
はじめに

まず、次のコマンドを実行して、システムパッケージを更新されたバージョンに更新します。

apt-get update -y

すべてのパッケージが更新されたら、次のステップに進むことができます。

Tripwireをインストール

デフォルトでは、TripwireパッケージはDebian10のデフォルトリポジトリで利用できます。次のコマンドを使用してインストールできます:

apt-get install tripwire -y

インストール中に、以下に示すように電子メール構成を選択するように求められます。

目的のオプションを選択し、 ENTERを押します 。以下に示すように、システムメール名を設定するように求められます。

システムのメール名を入力し、 ENTERを押します 。以下に示すように、サイトキーパスフレーズを作成するように求められます。

[はい]を選択してENTERを押します 。以下に示すように、Tripwire構成ファイルを再構築するように求められます。

[はい]を選択してENTERを押します 。以下に示すように、Tripwireポリシーファイルを再構築するように求められます。

[はい]を選択してENTERを押します 。以下に示すように、サイトキーのパスフレーズを入力するように求められます。

パスワードを入力してENTERを押します 。以下に示すように、ローカルキーのパスフレーズを設定するように求められます。

パスワードを入力してENTERを押します 。 Tripwireをインストールすると、次の画面が表示されます。

OKをクリックします ボタンをクリックしてインストールを完了します。

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

TripwireIDSを確認する

この時点で、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を実行するようにcronジョブを設定することもできます。次のコマンドで実行できます:

crontab -e

次の行を追加します:

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

終了したら、ファイルを保存して閉じます。

上記のファイルは、毎朝06:00AMにTripwireを実行します。生成されたレポートは、 / var / lib / tripwire / report /で確認できます。 。

結論

おめでとう!これで、Debian10にTripwireIDSが正常にインストールおよび構成されました。これが、システムで変更されているファイルまたはディレクトリを確認するのに役立つことを願っています。


Debian
  1. Debian11にRedis6.0をインストールして設定する方法

  2. Debian11にdockerをインストールして設定する方法

  3. Debian11にMariadb10をインストールして設定する方法

  1. Debian9にVNCをインストールして設定する方法

  2. Debian11にMongoDB5をインストールして設定する方法

  3. Debian11にRedis6をインストールして設定する方法

  1. Debian9にRedisをインストールして設定する方法

  2. Debian9にNagiosをインストールして設定する方法

  3. Debian9にRedmineをインストールして設定する方法