業務用エアコン関連の技術情報、エラーコード、環境問題対策に関する別サイト「エアコンの安全な修理・適切なフロン回収」

MiracleLinux9.6 : Tripwire , Chkrootkit , Logwatch , DiCE , ディスク使用率チェックスクリプト

Tripwire

1.インストール

2.パスフレーズ設定

サイトパスフレーズとローカルパスフレーズを設定する

----------------------------------------------------------------------------------------------
The Tripwire site and local passphrases are used to sign a variety of
files, such as the configuration, policy, and database files.

Passphrases should be at least 8 characters in length and contain both
letters and numbers.

See the Tripwire manual for more information.

-----------------------------------------------------------------------------------------------
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.)

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.)

Enter the local keyfile passphrase: [任意の「ローカルパスフレーズ」を入力]
Verify the local keyfile passphrase: [再度「ローカルパスフレーズ」を入力]
Generating key (this may take several minutes)…Key generation complete.

-----------------------------------------------------------------------------------------------
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
move this file to a secure location and/or encrypt it in place (using a
tool such as GPG, for example) after you have examined it.

------------------------------------------------------------------------------------------------
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.

Once you have a satisfactory Tripwire policy file, you should move the
clear-text version to a secure location and/or encrypt it in place
(using a tool such as GPG, for example).

Now run "tripwire --init" to enter Database Initialization Mode. This
reads the policy file, generates a database based on its contents, and
then cryptographically signs the resulting database. Options can be
entered on the command line to specify which policy, configuration, and
key files are used to create the database. The filename for the
database can be specified as well. If no options are specified, the
default values from the current configuration file are used.

3.Tripwire の設定

①設定ファイル編集

②Tripwire 設定ファイル(暗号署名版)を作成

③Tripwire 設定ファイル(テキスト版)削除

④ポリシーファイル設定

twpolmake.plの内容

⑤ポリシーファイル最適化

⑥最適化済ポリシーファイルを元に、ポリシーファイル(暗号署名版)作成

⑦データベースを作成、動作確認

テスト用ファイルを作成

Tripwire の動作確認

テスト用ファイルを削除

⑧Tripwire 定期実行スクリプト

tripwire.shの内容

参考: メールで結果報告用スクリプト

下記コマンドを実行し、指定したメールアドレスにtripwire実行結果が通知されることを確認

Chkrootkit

chkrootkitというrootkit検知ツールを導入して、rootkitがLinuxサーバーにインストールされてしまっていないかチェックする。
chkrootkitは、以下のコマンドを使用してチェックするため、コマンド自体がrootkitを検知できないように改竄されてからでは意味がないので、Linuxインストール後の初期の段階で導入しておくのが望ましい。

【chkrootkitが使用するコマンド】
awk, cut, echo, egrep, find, head, id, ls, netstat, ps, strings, sed, uname

なお、chkrootkitが検知できるのは既知のrootkitのみであり、新たなrootkitの検知はできない。

①chkrootkit をダウンロード、インストール

➁/root/bin ディレクトリを作成し、そのディレクトリにchkrootkit コマンドを移動

➂chkrootkit を確認

Checking `chsh'... INFECTED
chshコマンドはシェルを変更するコマンドで、使わない場合 /usr/bin/chshをchsh.bakにファイル名を変更すると表示が消える。
ファイル名を変更しなくても問題はありません。

④chkrootkit 定期実行スクリプトの作成と権限変更
chkrootkit実行スクリプトを毎日自動実行されるディレクトリへ作成

定期実行スクリプトの内容

chkrootkit実行スクリプトへ実行権限付加

⑤chkrootkit が使用するコマンドをバックアップ

chkrootkit が使用するコマンドが改ざんされた場合、rootkit を検出できなくなるので、
これらのコマンドをバックアップしておきます。
必要な場合は、バックアップしたコマンドを使用してchkrootkit を実行します

⑥コピーしたコマンドにchkrootkit を実行

何も表示されなければ問題ありません

⑦バックアップしたコマンドを圧縮

⑧chkrootkit使用コマンド(圧縮版)をroot宛にメール送信

⑨Windows にchkrootkit_cmd.tar.gz ファイルをダウンロードして退避

⑩バックアップしたサーバー上のコマンドを削除

Logwatch

①インストール

②設定ファイルの編集

③Logwatch のレポートを出力

下記のようなメッセージが出ます

④設定したアドレスにレポートが届くかテストを行います。上記の様なログレポートメールが届いているか確認

DiCE

ネットが切断されたり、ルーターが切断再起動したときにおこるグローバルIPの変更の度に、ダイナミックDNSにアクセスしグローバルIPが変更されたことを知らせなくてはいけません。その作業を自動的にやってくれるのがDiCEです

①Diceのダウンロード、インストール

②DiCEの設定
DiCEの出力文字はEUCのため、文字化けしてしまう。UTF-8に変換するために、nkfをインストールしておく

64bitOSで32bitソフトのDiceを動かすため下記をインストール

③DiCEを起動する

④イベントの追加
DNSサービスはVALUEDOMAINとした場合

⑤Diceの自動実行
DiCEデーモンを起動する

起動しているか確認

自動で起動するよう設定

ディスク使用率チェックスクリプト

3.1 スクリプト作成

disk_capacity_check.shの内容

3.2 実行確認

①現在の使用率を確認

次のように表示される

②使用率80%以上になるようダミーファイルを作成(例ではdummyfile という名前で6G程度)

③再度確認
下記を実行して80%以上になっていることを確認

④ディスク容量チェックスクリプトを実行

設定したメールアドレスに本文の内容として「Disk usage alert: 89 %」のように記載のメールが届きます

⑤作成した「dummyfile」を削除

⑥定期実行設定

タイトルとURLをコピーしました