0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ファイル改竄チェックと操作履歴取得

Last updated at Posted at 2020-12-26

外部公開しているので、セキュリティ対策をする。

  • centos7

導入候補

ファイル改竄チェック

があるが、trpiwireの方が小回りが効きそうなのでこれを利用する。ほとんどがここの通りです。

操作履歴取得

操作ログとして取得すべきログファイル

  • /USER/.bash/history
  • /var/log/cron
  • /var/log/secure
  • /var/log/messages

操作履歴

psacct
ログの保存先 : /var/account/pacct
このファイルの所有者はrootであり、バイナリ形式で保存されるため、簡単に改竄することはできないようになっています。実行されたコマンドを確認するには、次のようにlastcommコマンドを利用します(コマンドやユーザで絞り込むことも可能)。

tripwire

install&初期設定

この tripwire のreadmeの通り。

キーの作成

site-keyfileとlocal-keyfileを作成する。xxxx,yyyyはパスフレーズ。

# tripwiresetup-keyfiles 
Enter the site keyfile passphrase: xxxx
Enter the local keyfile passphrase: yyyyy

設定ファイルの作成

tripwire自体の設定ファイルを作成する。

# twadmin --create-cfgfile -S /path/to/site.key /path/to/twcfg.txt

ポリシーファイルの作成(初回)

どこを監視して、どこを監視しないかなどの設定、ポリシーを作成する。

# twadmin --create-polfile -S /path/to/site.key /etc/tripwire/twpol.txt

デフォルトで、テキスト版「/etc/tripwire/twpol.txt」とバイナリ版「/etc/tripwire/tw.pol」が作成された

ポリシーファイルのカスタマイズ(随時)

ポリシーファイルには、監視対象のディレクトリ(ファイル)、監視対象外のディレクトリ(ファイル)が記載されているが、実環境とあっていないとエラーになるので、(テキスト版の)ポリシーファイルをカスタマイズする。

初期化
データベースの初期化
# tripwire --init 2> tripwire.txt 
tripwire.txtを確認しながら、ポリシーファイルの修正
# vi /etc/tripwire/twpol.txt 
テキスト版からバイナリ版の作成
# twadmin --create-polfile --cfgfile /etc/tripwire/tw.cfg /etc/tripwire/twpol.txt
再度初期化してエラー確認
# tripwire --init 2> tripwire.txt 

Daily-Use

改竄チェック

改竄チェック tripwire --cheskをすると、/var/lib/tripwire/report/***.twrに結果格納されるので、レポート表示する。

改竄チェック
# tripwire --check
レポート表示
# twprint --print-report --twrfile /var/lib/tripwire/report/***.twr

ベースライン(データベース)の更新 = ファイル変更の受容。

ポリシーを変更せず、現在のファイルシステムの状態を正として、ベースラインを更新。

# tripwire --update --accept-all --twrfile /var/lib/tripwire/report/***.twr

ポリシー設定ファイルの再生成と、ベースラインの更新を行う

ポリシー変更の場合は、ベースライン(データベース)も更新する。

1. ポリシー変更
# vi /etc/tripwire/twpol.txt 
2. ベースラインを再度初期化
○ # twadmin --create-polfile --cfgfile /etc/tripwire/tw.cfg /etc/tripwire/twpol.txt
  # tripwire --init
3. この手順はNG
✖︎ # tripwire --update-policy /etc/tripwire/twpol.txt 

ベースラインの確認

ベースライン(データベース)の表示。

# twprint --print-dbfile | grep xxxxx

Daily-check, CRON

cron.dailyで、毎日チェックが起動される。/etc/cron.daily/tripwire-check

pacct

とてもシンプル

install psacct

yum install psacct
systemctl enable psacct
systemctl start psacct

Daily-Use

lastcomm --user=xxxx
lastcomm --command=yyyy
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?