2月26日にiPhone/iPod touch プログラミング入門セミナーへ行ってきました。
セミナーの内容はblog等への掲載を禁じられているので詳しく書けませんが、参加人数も多く改めてiPhoneアプリの開発が注目されているのだなぁと感じました。
最近自宅サーバー構築にどっぷりだったので、そろそろiPhoneアプリの勉強を再開しなきゃですね。
2月26日にiPhone/iPod touch プログラミング入門セミナーへ行ってきました。
セミナーの内容はblog等への掲載を禁じられているので詳しく書けませんが、参加人数も多く改めてiPhoneアプリの開発が注目されているのだなぁと感じました。
最近自宅サーバー構築にどっぷりだったので、そろそろiPhoneアプリの勉強を再開しなきゃですね。
今回はSSHサーバーを公開鍵暗号で認証するように設定をして、より安全に外部からリモート接続したりファイル転送できるようにしたいと思います。
公開鍵暗号を使った認証はSSHサーバーデフォルト認証のパスワード認証と比べて、鍵ファイル持っていてかつパスワードを知らないとログインできませんのでパスワード認証より安全です。
またrootユーザーで直接ログインできないようにしてセキュリティを上げたいと思います。
公開鍵暗号はSSHプロトコルバージョン1の暗号方式RSAとSSHプロトコルバージョン2の暗号方式RSAとDSAが利用可能です。
SSHプロトコルバージョン1は脆弱性が発見されているため使用しません。
SSHプロトコルバージョン2には暗号方式がRSAとDSAがありますが、RSAは2000年以前までは特許の関係でDSAしか一般公開されていなかったのですが、特許の期限が切れてRSAも一般公開されるようになりました。
今回はSSHプロトコルバージョン2の暗号方式RSAで鍵ファイルを作ります。
SSHプロトコルバージョン2の暗号方式RSAで公開鍵・秘密鍵を作成します
[centos@centos ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
秘密鍵の保存先を入力します。ここではデフォルトの保存先に保存するので何も入力をせずにEnterキーを押下します
Enter file in which to save the key (/home/centos/.ssh/id_rsa):何も入力をせずにEnterキーを押下
Created directory '/home/centos/.ssh'.
Enter passphrase (empty for no passphrase):秘密鍵のパスフレーズを入力
Enter same passphrase again:秘密鍵のパスフレーズを再入力
Your identification has been saved in /home/centos/.ssh/id_rsa.
Your public key has been saved in /home/centos/.ssh/id_rsa.pub.
The key fingerprint is:
xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx centos@centos.centos.com
作成された鍵ファイルを確認します
[centos@centos ~]$ ls -l .ssh
合計 32
-rw------- 1 centos centos 1743 2月 23 11:55 id_rsa 秘密鍵
-rw-r--r-- 1 centos centos 406 2月 23 11:55 id_rsa.pub 公開鍵
公開鍵ファイルの名前を変更します。
※SSHサーバーの設定ファイルに公開鍵ファイル名を明示的に指定すればファイル名を変更する必要はないのですが、ここでは公開鍵ファイルの名前を変更する手順で進めます
[centos@centos ~]$ mv .ssh/id_rsa.pub .ssh/authorized_keys
公開鍵ファイルのアクセス権限をcentosユーザー読み取り専用に変更します
[centos@centos ~]$ chmod 400 .ssh/authorized_keys
公開鍵ファイルの名前とアクセス権限が変わったか確認します
※左端の表示が「-r--------」となっていればアクセス権限は問題ありません
[centos@centos ~]$ ls -l .ssh
合計 32
-r-------- 1 centos centos 406 2月 23 11:55 authorized_keys
-rw------- 1 centos centos 1743 2月 23 11:55 id_rsa
秘密鍵ファイル(id_rsa)をサーバーに接続したいクライアント端末にコピーします。
※まだSSHサーバーはパスワード認証で接続可能なので、自宅サーバー再構築 その5 CentOS 5.2 ファイル転送準備 » sa-sa-ki.jpのblogでご紹介したWinSCPもしくはSFTPコマンドで秘密鍵ファイルをクライアント端末にコピーします
秘密鍵ファイルをサーバー上から削除します
[centos@centos ~]$ rm -f .ssh/id_rsa
秘密鍵ファイルが削除されたか確認します
[centos@centos ~]$ ls -l .ssh
合計 32
-r-------- 1 centos centos 406 2月 23 11:55 authorized_keys
こちらはrootユーザーで作業を行います。
SSHサーバー設定ファイル編集
[root@centos ~]# vi /etc/ssh/sshd_config
viエディタが起動するので設定ファイルを変更します
# $OpenBSD: sshd_config,v 1.73 2005/12/06 22:38:28 reyk Exp $
# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
# This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin
# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options change a
# default value.
#Port 22
#Protocol 2,1
Protocol 2
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
# HostKey for protocol version 1
#HostKey /etc/ssh/ssh_host_key
# HostKeys for protocol version 2
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key
# Lifetime and size of ephemeral version 1 server key
#KeyRegenerationInterval 1h
#ServerKeyBits 768
# Logging
# obsoletes QuietMode and FascistLogging
#SyslogFacility AUTH
SyslogFacility AUTHPRIV
#LogLevel INFO
# Authentication:
#LoginGraceTime 2m
PermitRootLogin no 先頭の#を削除してコメントを解除し、yes から no に変更します。rootユーザでログインができなくなります。
#StrictModes yes
#MaxAuthTries 6
#RSAAuthentication yes
#PubkeyAuthentication yes
#AuthorizedKeysFile .ssh/authorized_keys
# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#RhostsRSAAuthentication no
# similar for protocol version 2
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# RhostsRSAAuthentication and HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes
# To disable tunneled clear
text passwords, change to no here!
#PasswordAuthentication yes
先頭の#を削除してコメントを解除します。パスワードなしでのログインを禁止します。
PermitEmptyPasswords no
PasswordAuthentication no yes から no に変更します。パスワード認証から公開鍵暗号認証に変更します。
# Change to no to disable s/key passwords
#ChallengeResponseAuthentication yes
ChallengeResponseAuthentication no
# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no
# GSSAPI options
#GSSAPIAuthentication no
GSSAPIAuthentication yes
#GSSAPICleanupCredentials yes
GSSAPICleanupCredentials yes
# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication mechanism.
# Depending on your PAM configuration, this may bypass the setting of
# PasswordAuthentication, PermitEmptyPasswords, and
# "PermitRootLogin without-password". If you just want the PAM account and
# session checks to run without PAM authentication, then enable this but set
# ChallengeResponseAuthentication=no
#UsePAM no
UsePAM yes
# Accept locale-related environment variables
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL
#AllowTcpForwarding yes
#GatewayPorts no
X11 Port Forwarding の設定をOFFにします
先頭の#を削除してコメントを解除します。
X11Forwarding no
先頭の#を追加してコメント化します。
#X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#UsePrivilegeSeparation yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#ShowPatchLevel no
#UseDNS yes
#PidFile /var/run/sshd.pid
#MaxStartups 10
#PermitTunnel no
# no default banner path
#Banner /some/path
# override default of no subsystems
Subsystem sftp /usr/libexec/openssh/sftp-server
※変更箇所は5箇所です
内容を保存しviエディタを終了します
SSHサーバーを再起動します
[root@centos ~]# /etc/rc.d/init.d/sshd restart
sshd を停止中: [ OK ]
sshd を起動中: [ OK ]
アクセス制御ファイルにローカルホスト・ローカルネットワーク・指定した外部ネットワーク以外からアクセスされてもアクセスを拒否するように設定します。
ローカルホストのアクセスを許可します
[root@centos ~]# echo "sshd: 127.0.0.1" >> /etc/hosts.allow
ローカルネットワークのPCのアクセスを許可します
※以下のように第四オクテッドを入力しない場合、第四オクテッドのアドレスはワイルドカード扱いになります
[root@centos ~]# echo "sshd: 192.168.0." >> /etc/hosts.allow
外部からのアクセスを許可します
※セキュリティ上接続可能なアドレスは公開しませんが、自宅サーバーに接続する外部のネットワークアドレスを「xx.xx.xx.xx」の部分に記載してください
[root@centos ~]# echo "sshd: xx.xx.xx.xx" >> /etc/hosts.allow
これで設定作業は終了です。
まだルーターのポートをオープンしていないので外部からの接続はできません。まずはローカルネットワーク内のPCからサーバーにログインしてみます。
PCがWindowsの場合、Tera Termで接続します。
ホストにはサーバーのIPアドレスを入力して、サービスはデフォルトのSSHを選択して[OK]ボタンをクリックします。

セキュリティ警告が表示されたら、「このホストをknown hostsリストに追加する」にチェックをつけて[続行(C)]ボタンをクリックします。

ユーザ名は一般ユーザー名(ここではcentos)を、パスフレーズは公開鍵暗号の鍵ファイルを作成した時に入力したパスフレーズを入力します。
「RSA/DSA鍵を使う」を選択し、[秘密鍵]ボタンをクリックしクライアント端末にコピーした秘密鍵ファイル(id_rsa)を選択して[OK]ボタンをクリックします。

ちなみに一般ユーザーでパスワード認証のままログインしようとすると・・・

「認証に失敗しました。再試行してください」と表示されま
す。
※公開鍵暗号認証に変更しているのでパスワード認証はエラーになるのが正しいです

rootユーザーでパスワード認証のままログインしようとすると・・・

「認証に失敗しました。再試行してください」と表示されます。
※公開鍵暗号認証に変更しているのでパスワード認証はエラーになるのが正しいです

rootユーザーでRSA/DSA鍵を使った認証をしようとすると・・・

「認証に失敗しました。再試行してください」と表示されます。
※rootユーザーのログインを禁止しているのでエラーになるのが正しいです

またPCがWindowsでファイル転送を行うには以前ご紹介したWinSCPを使うのですが、サーバーからコピーした秘密鍵をPuTTY Key Generatorで変換する必要があるのでその手順をご紹介します。
[スタート]-[プログラム]-[WinSCP]-[鍵関連ツール]-[PuTTY gen]を選択します。
PuTTY Key Generatorが起動しますので、[Load]ボタンをクリックします。

秘密鍵ファイル(id_rsa)を選択して[開く]ボタンをクリックします。

秘密鍵のパスフレーズを聞かれるので、パスフレーズを入力して[OK]ボタンをクリックします。

[Save private key]ボタンをクリックします。

WinSCPを起動します。
ホスト名には自宅サーバーのアドレス(ここでは192.168.0.20)を、ユーザ名には一般ユーザー名(ここではcentos)を、秘密鍵には変換した秘密鍵ファイルを選択して[ログイン]ボタンをクリックします。

PCがMacの場合、ターミナルで接続します。
以下のダイアログが表示されるのでパスワードに公開鍵暗号の鍵ファイルを作成した時に入力したパスフレーズを入力して[OK]ボタンをクリックします

Last login: Mon Feb 23 10:03:32 2009 from 192.168.0.51
[centos@centos ~]$
公開鍵暗号で認証する事ができました
またPCがMacでファイル転送を行う場合もターミナルで接続します。
以下のダイアログが表示されるのでパスワードに公開鍵暗号の鍵ファイルを作成した時に入力したパスフレーズを入力して[OK]ボタンをクリックします

Connecting to 192.168.0.20
sftp>
公開鍵暗号で認証する事ができました
PCがUbuntuの場合、端末で接続します。
またPCがUbuntuでファイル転送を行う場合も端末で接続します。
最後にルータの設定を変更して22番ポートを開放してください。
開放方法はルータの設定手順に従って実施してください。
これで外部から自宅サーバーの操作をしたりファイル転送ができるようになります。
■ 参考サイト ■
SSHサーバー構築(OpenSSH) - CentOSで自宅サーバー構築
はじめての自宅サーバ構築 Fedora/CentOS - SSHサーバの構築(OpenSSH)
「OpenSSH」の設定
Secure Shell - Wikipedia
X-Windowの利用 - PukiWiki
■関連記事
自宅サーバー再構築 その1 導入を検討する
自宅サーバー再構築 その2 CentOS 5.2 をインストールする
自宅サーバー再構築 その3 インストールしたCentOS 5.2 にリモート接続準備
自宅サーバー再構築 その4 CentOS 5.2 インストール後の初期設定
自宅サーバー再構築 その5 CentOS 5.2 ファイル転送準備
自宅サーバー再構築 その6 CentOS 5.2 にアンチウィルスソフトを導入する
自宅サーバー再構築 その7 CentOS 5.2 にファイル改竄検知システムを導入する
自宅サーバー再構築 その8 CentOS 5.2 にrootkit検知ツールを導入する
自宅サーバー再構築 その9 CentOS 5.2 にバッファオーバーフロー攻撃対策を行う
自宅サーバー再構築 その10 CentOS 5.2 SSHサーバーを構築して外部からリモート接続&リモートファイル転送
自宅サーバー再構築 その11 CentOS 5.2 にDNSサーバーを導入して名前解決(設定編)
自宅サーバー再構築 その12 CentOS 5.2 にDNSサーバーを導入して名前解決(確認編)
自宅サーバー再構築 その13 CentOS 5.2 にLAMP環境構築(Apache、PHP編)
自宅サーバー再構築 その14 CentOS 5.2 にLAMP環境構築(MySQL編)
自宅サーバー再構築 その15 Apacheにサーバー証明書を導入する
自宅サーバー再構築 その16 CentOS 5.2 にWordPressを導入してブログサイトを構築する
自宅サーバー再構築 その17 WordPressのセキュリティ対策
自宅サーバー再構築 その18 CentOS 5.3 にNTPサーバーを導入して自動時間合わせ
自宅サーバー再構築 その19 CentOS 5.3 アンチウィルスソフトのバージョンアップ
自宅サーバー再構築 その20 CentOS 5.3 メールサーバー構築(Postfix設定編)
自宅サーバー再構築 その21 CentOS 5.3 メールサーバー構築(Dovecot設定編)
自宅サーバー再構築 その22 CentOS 5.3 メールサーバー構築(公開編)
自宅サーバー再構築 その23 CentOS 5.3 メールサーバー構築(SSL導入編)
自宅サーバー再構築 その24 CentOS 5.3 メールサーバー構築(メールアカウント作成編)
自宅サーバー再構築 その25 CentOS 5.3 メールサーバー構築(Thunderbird設定編)
自宅サーバー再構築 番外編その1 CentOS 5.3 のリリースと導入済みソフトウェアのアップデート
VMWare Playerとqemuで作ったUbuntu8.10 Desktop版の環境があるのですが、USB無線LANアダプタを使ってインターネット接続をするにはVMWare Player自体を動かしているOSがWindowsでもLinuxに対応した無線LANアダプタをチョイスする必要があります。
Planex社のGW-US54GXSがLinux対応しているようで、これをUSBに刺し無線LANでインターネットに接続してみたのですが、とにかく無線接続が頻繁に切れてまともにインターネットができませんでした。
何で無線接続が頻繁に切れてしまうのか、全然当たりがつきませんでした。
最初に疑ったのはUbuntu 8.10のドライバとGW-US54GXSの相性がよくないのではないかと思い、ドライバを探してみたけど見つからず。
GW-US54GXSがおかしいのかとかUSBの調子が悪いのかななんて思ってOS起動時のログを調べてみました。
メニューバーの[アプリケーション]-[アクセサリ]-[端末]からコマンド入力画面を起動して、以下のように入力します。
USBの起動状況に2.0といった表示がありません
どうやら自分のVMWare Player の設定ファイルの指定が、USB2.0ではなく1.0なのではないかと思い、VMWare Player の設定ファイル設定について調べて見たところやっぱり設定がUSB1.0になっていました。。
VMWare Player の設定ファイルの指定方法についてはこちらのサイトを参考にしました。
VMware Player 2.0でUSB 2.0の有効化 / Tips / Cycle of 5th
UbuntuのVMware Player設定ファイル(拡張子vmx形式)をテキストエディタで開き、以下1行を追加して保存します。
ehci.present = "TRUE"
ちなみにehciとは「Enhanced Host Controller Interface、USB2.0規格に対応したUSBコントローラーの仕様を定義したもの。」だそうです。
UbuntuのVMware Player設定ファイルの修正が終わったらVMWare PlayerからUbuntuを起動します。
再度コマンド入力画面からOS起動時のログを確認します。
3行目に「USB 2.0 started」と表示されるようになりました!
実際にUSB無線LANアダプタでインターネットをしましたが、接続が切れなくなりました。
今回はクラッカー対策第三弾としてバッファオーバーフロー攻撃対策をします。
バッファオーバーフロー攻撃と言うのは、脆弱性をもつプログラムに対して許容量以上のデータを送り込み、そのプログラムが使用するメモリ領域を意図的にオーバーフローさせ、システムを機能停止にしたり、悪意のあるプログラムを実行する攻撃のことです。
バッファオーバーフロー攻撃を防ぐために「Exec-Shield」で対策したいと思います。
「Exec-Shield」はCentOS導入時にインストール済みですので、設定を変更して反映していきます。
現在の設定は1でした。なお設定値の意味ですが
0 : 無効
1 : 無効(実行ファイルごとに有効にする)
2 : 有効(実行ファイルごとに無効にする)
3 : 常に有効
です。
ここでは2の「有効(実行ファイルごとに無効にする)」に変更します
[root@CentOS ~]# echo 2 > /proc/sys/kernel/exec-shield
これで設定が変更されましたが、OSの再起動をすると値が元に戻ってしまうので設定ファイルから変更します。
# Controls IP packet forwarding
net.ipv4.ip_forward = 0
# Controls source route verification
net.ipv4.conf.default.rp_filter = 1
# Do not accept source routing
net.ipv4.conf.default.accept_source_route = 0
# Controls the System Request debugging functionality of the kernel
kernel.sysrq = 0
# Controls whether core dumps will append the PID to the core filename
# Useful for debugging multi-threaded applications
kernel.core_uses_pid = 1
# Controls the use of TCP syncookies
net.ipv4.tcp_syncookies = 1
# Controls the maximum size of a message, in bytes
kernel.msgmnb = 65536
# Controls the default maxmimum size of a mesage queue
kernel.msgmax = 65536
# Controls the maximum shared segment size, in bytes
kernel.shmmax = 4294967295
# Controls the maximum number of shared memory segments, in pages
kernel.shmall = 268435456
# exec-shield
kernel.exec-shield = 2 追加します
内容を保存しviエディタを終了します
設定が終わったのでバッファオーバーフロー攻撃をしてExec-Shieldの動作確認をします。
Exec-Shieldの動作確認を行うためにlibsafeというツールを使用します。
libsafeとはLinux用に開発されているバッファオーバーフローによる攻撃を防止するためのライブラリなのですがこの中に、テスト用のバッファオーバーフロー攻撃ツールがありますのでそれを使います。
100%[=======================================>] 374,371 39.2K/s in 9.6s
23:01:32 (37.9 KB/s) - `libsafe-2.0-16.i386.rpm' を保存しました [374371/374371]
libsafeのインストールします
[root@centos ~]# rpm -ivh libsafe-2.0-16.i386.rpm
準備中... ########################################### [100%]
1:libsafe ########################################### [100%]
Adding libsafe to ld.so.preload for system wide protection
テスト用のバッファオーバーフロー攻撃ツールをホームディレクトリにコピーします
[root@centos ~]# cp -p /usr/doc/libsafe-2.0/exploits/t1 ./
テスト用のバッファオーバーフロー攻撃ツールを実行します
[root@centos ~]# ./t1
This program tries to use strcpy() to overflow the buffer.
If you get a /bin/sh prompt, then the exploit has worked.
Press any key to continue...a 何か文字を入力して[Enter]キーを押下します。ここでは a と入力します。
セグメンテーション違反です
「Exec-Shield」が有効になっている為、「セグメンテーション違反です」のメッセージとともにテスト用バッファオーバーフロー攻撃ツールが停止されます。
テスト用バッファオーバーフロー攻撃ツールを削除します
[root@centos ~]# rm -f ./t1
libsafeをアンインストールします
[root@centos ~]# rpm -e libsafe
Removing libsafe from /etc/ld.so.preload (if exists)
これでバッファオーバーフローを利用して悪意のあるプログラムを実行される危険はなくなりました。
■関連記事
自宅サーバー再構築 その1 導入を検討する
自宅サーバー再構築 その2 CentOS 5.2 をインストールする
自宅サーバー再構築 その3 インストールしたCentOS 5.2 にリモート接続準備
自宅サーバー再構築 その4 CentOS 5.2 インストール後の初期設定
自宅サーバー再構築 その5 CentOS 5.2 ファイル転送準備
自宅サーバー再構築 その6 CentOS 5.2 にアンチウィルスソフトを導入する
自宅サーバー再構築 その7 CentOS 5.2 にファイル改竄検知システムを導入する
自宅サーバー再構築 その8 CentOS 5.2 にrootkit検知ツールを導入する
自宅サーバー再構築 その9 CentOS 5.2 にバッファオーバーフロー攻撃対策を行う
自宅サーバー再構築 その10 CentOS 5.2 SSHサーバーを構築して外部からリモート接続&リモートファイル転送
自宅サーバー再構築 その11 CentOS 5.2 にDNSサーバーを導入して名前解決(設定編)
自宅サーバー再構築 その12 CentOS 5.2 にDNSサーバーを導入して名前解決(確認編)
自宅サーバー再構築 その13 CentOS 5.2 にLAMP環境構築(Apache、PHP編)
自宅サーバー再構築 その14 CentOS 5.2 にLAMP環境構築(MySQL編)
自宅サーバー再構築 その15 Apacheにサーバー証明書を導入する
自宅サーバー再構築 その16 CentOS 5.2 にWordPressを導入してブログサイトを構築する
自宅サーバー再構築 その17 WordPressのセキュリティ対策
自宅サーバー再構築 その18 CentOS 5.3 にNTPサーバーを導入して自動時間合わせ
自宅サーバー再構築 その19 CentOS 5.3 アンチウィルスソフトのバージョンアップ
自宅サーバー再構築 その20 CentOS 5.3 メールサーバー構築(Postfix設定編)
自宅サーバー再構築 その21 CentOS 5.3 メールサーバー構築(Dovecot設定編)
自宅サーバー再構築 その22 CentOS 5.3 メールサーバー構築(公開編)
自宅サーバー再構築 その23 CentOS 5.3 メールサーバー構築(SSL導入編)
自宅サーバー再構築 その24 CentOS 5.3 メールサーバー構築(メールアカウント作成編)
自宅サーバー再構築 その25 CentOS 5.3 メールサーバー構築(Thunderbird設定編)
自宅サーバー再構築 番外編その1 CentOS 5.3 のリリースと導入済みソフトウェアのアップデート
今回はクラッカー対策第二弾としてrootkit対策をします。
rootkitと言うのはクラッカーがサーバーに不正侵入してもシステム管理者にみつからないようにする為のツールやコマンドの事です。
例えばシステム管理者がLinuxとかUnixサーバー上で稼働しているプロセス一覧を見ようとしてpsコマンドを実行したとします。
サーバーが既にrootkitにやられている場合、psコマンドの結果のプロセス一覧にはクラッカーが実行している不正なプロセスが表示されないようになったりするそうです。
そういった普通には見つけられない不正なツールやコマンドを検知する為に「chkrootkit」を導入したいと思います。
1.非公式リポジトリを一時有効にする
2.chkrootkitのダウンロードとインストール
3.非公式リポジトリを無効にする
4.chkrootkit実行
5.chkrootkit定期自動実行スクリプト作成およびスケジューラ登録
6.chkrootkitで使用する安全なコマンドの確保
1.非公式リポジトリを一時有効にする
「chkrootkit」はアンチウィルスソフトの「Clam AntiVirus」と同じく公式リポジトリからダウンロードできませんので、非公式リポジトリを一時有効にします。
viエディタが起動するので設定ファイルを変更します
[dag]
name=CentOS-$releasever - Dag
baseurl=http://ftp.riken.jp/Linux/dag/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
enabled=1 0 から 1 へ変更
gpgkey=http://dag.wieers.com/packages/RPM-GPG-KEY.dag.txt
保存してviエディタを終了します
2.chkrootkitのダウンロードとインストール
Dependencies Resolved
=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
chkrootkit i386 xx.xx-xx.xxx.rf dag 272 k
Transaction Summary
=============================================================================
Install 1 Package(s)
Update 0 Package(s)
Remove 0 Package(s)
Total download size: 272 k
Downloading Packages:
(1/1): chkrootkit-xx.xx-x. 100% |=========================| 272 kB 00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: chkrootkit ######################### [1/1]
Installed: chkrootkit.i386 0:xx.xx-xx.xxx.rf
Complete!
3.非公式リポジトリを無効にする
[root@centos ~]# vi /etc/yum.repos.d/CentOS-Dag.repo
viエディタが起動するので設定ファイルを変更します
[dag]
name=CentOS-$releasever - Dag
baseurl=http://ftp.riken.jp/Linux/dag/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
enabled=0 1 から 0 へ変更
gpgkey=http://dag.wieers.com/packages/RPM-GPG-KEY.dag.txt
保存してviエディタを終了します
4.chkrootkit実行
インストールしたchkrootkitを実行します。
rootkitに感染している場合、実行結果に「INFECTED」と表示されるのでそれも併せて確認します。
5.chkrootkit定期自動実行スクリプト作成およびスケジューラ登録
chkrootkit定期自動実行スクリプト作成 [root@centos ~]# vi chkrootkit.sh viエディタが起動するので定期自動実行スクリプトを作成します #!/bin/bash PATH=/usr/bin:/bin TMPLOG=`mktemp` # chkrootkit実行 chkrootkit > $TMPLOG # ログ出力 cat $TMPLOG | logger -t chkrootkit # SMTPSのbindshell誤検知対応 if [ ! -z "$(grep 465 $TMPLOG)" ] && [ -z $(/usr/sbin/lsof -i:465|grep bindshell) ]; then sed -i '/465/d' $TMPLOG fi # rootkit検知時のみroot宛メール送信 [ ! -z "$(grep INFECTED $TMPLOG)" ] && grep INFECTED $TMPLOG | mail -s "chkrootkit report in `hostname`" root rm -f $TMPLOG
保存してviエディタを終了します
chkrootkit定期自動実行スクリプトへ実行権限付加
[root@centos ~]# chmod 700 chkrootkit.sh
chkrootkit定期自動実行スクリプトをスケジューラに登録
[root@centos ~]# crontab -e
viエディタが起動するので定期自動実行スクリプトを午前2時にスケジュール設定します
00 05 * * * /root/systemupdate.sh > /root/systemupdate.log 2>&1
00 01 * * * /root/clamav.sh
00 03 * * * /root/tripwire.sh
00 02 * * * /root/chkrootkit.sh
保存してviエディタを終了します
6.chkrootkitで使用する安全なコマンドの確保
rootkitに感染する前の安全なコマンドをバックアップして、rootkit感染時にリカバリできるようにしておきます。
安全なコマンドをバックアップディレクトリにコピーします
[root@centos ~]# cp `which --skip-alias awk cut echo egrep find head id ls netstat ps strings sed uname` chkrootkitcmd/
バックアップ用ディレクトリに退避したコマンドもrootkitに感染していないか確認します
[root@centos ~]# chkrootkit -p /root/chkrootkitcmd|grep INFECTED
バックアップ用ディレクトリを圧縮します
[root@centos ~]# zip -r chkrootkitcmd.zip chkrootkitcmd/
adding: chkrootkitcmd/ (stored 0%)
adding: chkrootkitcmd/sed (deflated 54%)
adding: chkrootkitcmd/awk (deflated 51%)
adding: chkrootkitcmd/head (deflated 52%)
adding: chkrootkitcmd/uname (deflated 55%)
adding: chkrootkitcmd/ls (deflated 53%)
adding: chkrootkitcmd/ps (deflated 59%)
adding: chkrootkitcmd/id (deflated 55%)
adding: chkrootkitcmd/echo (deflated 54%)
adding: chkrootkitcmd/netstat (deflated 58%)
adding: chkrootkitcmd/strings (deflated 53%)
adding: chkrootkitcmd/cut (deflated 52%)
adding: chkrootkitcmd/find (deflated 50%)
adding: chkrootkitcmd/egrep (deflated 49%)
/root直下にバックアップしたコマンドの圧縮ファイル(chkrootkitcmd.zip)を作成したので、バックアップ用ディレクトリを削除します
[root@centos ~]# rm -rf chkrootkitcmd
mailコマンドでzipファイル添付メールを送信するのに必要なuuencodeコマンドをインストールします
[root@centos ~]# yum -y install sharutils
Loading "priorities" plugin
Loading "fastestmirror" plugin
Loading mirror speeds from cached hostfile
* base: rsync.atworks.co.jp
* updates: rsync.atworks.co.jp
* addons: rsync.atworks.co.jp
* extras: rsync.atworks.co.jp
0 packages excluded due to repository priority protections
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package sharutils.i386 0:xx.xx.xx-xx set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
sharutils i386 xx.xx.xx-xx base 201 k
Transaction Summary
=============================================================================
Install 1 Package(s)
Update 0 Package(s)
Remove 0 Package(s)
Total download size: 201 k
Downloading Packages:
(1/1): sharutils-xx.xx.xx-xx. 100% |=========================| 201 kB 00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: sharutils ######################### [1/1]
Installed: sharutils.i386 0:xx.xx.xx-xx
Complete!
uuencodeコマンドでrootユーザ宛に/root直下にバックアップしたコマンドの圧縮ファイル(chkrootkitcmd.zip)をメール送信します
[root@centos ~]# uuencode chkrootkitcmd.zip chkrootkitcmd.zip|mail root
/root直下にバックアップしたコマンドの圧縮ファイル(chkrootkitcmd.zip)を削除します
[root@centos ~]# rm -f chkrootkitcmd.zip
■関連記事
自宅サーバー再構築 その1 導入を検討する
自宅サーバー再構築 その2 CentOS 5.2 をインストールする
自宅サーバー再構築 その3 インストールしたCentOS 5.2 にリモート接続準備
自宅サーバー再構築 その4 CentOS 5.2 インストール後の初期設定
自宅サーバー再構築 その5 CentOS 5.2 ファイル転送準備
自宅サーバー再構築 その6 CentOS 5.2 にアンチウィルスソフトを導入する
自宅サーバー再構築 その7 CentOS 5.2 にファイル改竄検知システムを導入する
自宅サーバー再構築 その8 CentOS 5.2 にrootkit検知ツールを導入する
自宅サーバー再構築 その9 CentOS 5.2 にバッファオーバーフロー攻撃対策を行う
自宅サーバー再構築 その10 CentOS 5.2 SSHサーバーを構築して外部からリモート接続&リモートファイル転送
自宅サーバー再構築 その11 CentOS 5.2 にDNSサーバーを導入して名前解決(設定編)
自宅サーバー再構築 その12 CentOS 5.2 にDNSサーバーを導入して名前解決(確認編)
自宅サーバー再構築 その13 CentOS 5.2 にLAMP環境構築(Apache、PHP編)
自宅サーバー再構築 その14 CentOS 5.2 にLAMP環境構築(MySQL編)
自宅サーバー再構築 その15 Apacheにサーバー証明書を導入する
自宅サーバー再構築 その16 CentOS 5.2 にWordPressを導入してブログサイトを構築する
自宅サーバー再構築 その17 WordPressのセキュリティ対策
自宅サーバー再構築 その18 CentOS 5.3 にNTPサーバーを導入して自動時間合わせ
自宅サーバー再構築 その19 CentOS 5.3 アンチウィルスソフトのバージョンアップ
自宅サーバー再構築 その20 CentOS 5.3 メールサーバー構築(Postfix設定編)
自宅サーバー再構築 その21 CentOS 5.3 メールサーバー構築(Dovecot設定編)
自宅サーバー再構築 その22 CentOS 5.3 メールサーバー構築(公開編)
自宅サーバー再構築 その23 CentOS 5.3 メールサーバー構築(SSL導入編)
自宅サーバー再構築 その24 CentOS 5.3 メールサーバー構築(メールアカウント作成編)
自宅サーバー再構築 その25 CentOS 5.3 メールサーバー構築(Thunderbird設定編)
自宅サーバー再構築 番外編その1 CentOS 5.3 のリリースと導入済みソフトウェアのアップデート
今回はクラッカー対策としてファイルを監視して変化があった場合にはそれを通知するソフト「Tripwire」を導入したいと思います。
1.Tripwireダウンロード・コンパイル・インストール
2.Tripwire設定ファイル(テキスト版)修正
3.Tripwire設定ファイル(テキスト版)を元に
Tripwire設定ファイル(暗号署名版)作成
4.ポリシーファイル最適化スクリプト作成
5.ポリシーファイル最適化スクリプトを使い
ポリシーファイル最適化(テキスト版)を作成
6.ポリシーファイル最適化(テキスト版)と
Tripwire設定ファイル(暗号署名版)を
元にポリシーファイル(暗号署名版)作成
7.データベース作成
8.ファイル監視の確認
9.Tripwire定期自動実行スクリプト作成およびスケジューラ登録
1.Tripwireダウンロード・コンパイル・インストール
いつもはyumでパッケージのダウンロードからインストールまで全自動でやってますが、「Tripwire」はソースファイルをダウンロードして、自分でコンパイルとインストールを実施します。
tripwireダウンロードします
[root@centos ~]# wget http://jaist.dl.sourceforge.net/sourceforge/tripwire/tripwire-2.4.1.2-src.tar.bz2
ダウンロードしたtripwireを解凍展開します
[root@centos ~]# tar jxvf tripwire-2.4.1.2-src.tar.bz2
tripwire展開先ディレクトリへ移動します
[root@centos ~]# cd tripwire-2.4.1.2-src
tripwireをコンパイル、インストールします
[root@centos tripwire-2.4.1.2-src]# ./configure --prefix=/usr/local/tripwire sysconfdir=/etc/tripwire
〜 configureのログは省略 〜
[root@centos tripwire-2.4.1.2-src]# make
〜 makeのログは省略 〜
[root@centos tripwire-2.4.1.2-src]# make install
〜 make install の冒頭のログは省略 〜
Installer program for:
Tripwire(R) 2.4 Open Source
Copyright (C) 1998-2000 Tripwire (R) Security Systems, Inc. Tripwire (R)
is a registered trademark of the Purdue Research Foundation and is
licensed exclusively to Tripwire (R) Security Systems, Inc.
LICENSE AGREEMENT for Tripwire(R) 2.4 Open Source
〜 中略 〜
Press ENTER to view the License Agreement. [Enter]キーを押下する
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
〜 中略 〜
Please type "accept" to indicate your acceptance of this
license agreement. [do not accept] accept
Using configuration file ./install/install.cfg
Checking for programs specified in install configuration file....
/usr/sbin/sendmail -oi -t exists. Continuing installation.
/bin/vi exists. Continuing installation.
----------------------------------------------
Verifying existence of binaries...
./bin/siggen found
./bin/tripwire found
./bin/twprint found
./bin/twadmin found
This program will copy Tripwire files to the following directories:
TWBIN: /usr/local/tripwire/sbin
TWMAN: /usr/local/tripwire/man
TWPOLICY: /etc/tripwire
TWREPORT: /usr/local/tripwire/lib/tripwire/report
TWDB: /usr/local/tripwire/lib/tripwire
TWSITEKEYDIR: /etc/tripwire
TWLOCALKEYDIR: /etc/tripwire
CLOBBER is false.
Continue with installation? [y/n] y
----------------------------------------------
Creating directories...
/usr/local/tripwire/sbin: already exists
/etc/tripwire: created
/usr/local/tripwire/lib/tripwire/report: created
/usr/local/tripwire/lib/tripwire: already exists
/etc/tripwire: already exists
/etc/tripwire: already exists
/usr/local/tripwire/man: created
/usr/local/tripwire/doc/tripwire: created
----------------------------------------------
Copying files...
/usr/local/tripwire/doc/tripwire/COPYING: copied
/usr/local/tripwire/doc/tripwire/TRADEMARK: copied
/usr/local/tripwire/doc/tripwire/policyguide.txt: copied
/etc/tripwire/twpol-Linux.txt: copied
----------------------------------------------
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: サイトキーパスフレーズを再入力
サイトパスフレーズは、Tripewire の設定、ポリシーファイルの暗号化に使用します
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.
----------------------------------------------
Generating Tripwire configuration file...
----------------------------------------------
Creating signed 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.
----------------------------------------------
Customizing default policy file...
----------------------------------------------
Creating signed 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.
----------------------------------------------
The installation succeeded.
make install 最後のログは省略
ホームディレクトリ(rootユーザなので/root)へ移動
[root@centos tripwire-2.4.1.2-src]# cd
tripwire展開先ディレクトリを削除
[root@centos ~]# rm -rf tripwire-2.4.1.2-src
ダウンロードしたtripwireを削除
[root@centos ~]# rm -f tripwire-2.4.1.2-src.tar.bz2
tripwire実行ファイル格納ディレクトリへパスを通す
[root@centos ~]# echo PATH=$PATH:/usr/local/tripwire/sbin >> .bashrc ; source .bashrc
tripwireインストール直後の設定ファイル格納ディレクトリの一覧を表示します
[root@centos ~]# ls -la /etc/tripwire
合計 84
drwxr-x--- 2 root root 4096 1月 26 23:56 .
drwxr-xr-x 80 root root 4096 1月 26 23:52 ..
-rw-r----- 1 root root 931 1月 26 23:54 centos.centos.com-local.key
-rw-r----- 1 root root 931 1月 26 23:54 site.key
-rw-r----- 1 root root 4586 1月 26 23:55 tw.cfg
-rw-r----- 1 root root 4159 1月 26 23:56 tw.pol
-rw-r----- 1 root root 537 1月 26 23:54 twcfg.txt
-rw-r----- 1 root root 13745 1月 26 23:55 twpol.txt
2.Tripwire設定ファイル(テキスト版)修正
Tripwire設定ファイル(暗号署名版)を作成する為のTripwire設定ファイル(テキスト版)を修正します。
3.Tripwire設定ファイル(テキスト版)を元にTripwire設定ファイル(暗号署名版)作成
修正したTripwire設定ファイル(テキスト版)を元にTripwire設定ファイル(暗号署名版)を作成します。
Tripwire設定ファイル(テキスト版)削除
[root@centos ~]# rm -f /etc/tripwire/twcfg.txt
※Tripwire設定ファイル(テキスト版)を復元する場合
[root@centos ~]# twadmin -m f -c /etc/tripwire/tw.cfg > /etc/tripwire/twcfg.txt
[root@centos ~]# ls -la /etc/tripwire
合計 88
drwxr-x--- 2 root root 4096 1月 27 00:25 .
drwxr-xr-x 80 root root 4096 1月 26 23:52 ..
-rw-r----- 1 root root 931 1月 26 23:54 centos.centos.com-local.key
-rw-r----- 1 root root 931 1月 26 23:54 site.key
-rw-r----- 1 root root 4586 1月 27 00:20 tw.cfg 今回作成したTripwire設定ファイル(暗号署名版)
-rw-r----- 1 root root 4586 1月 27 00:20 tw.cfg.bak 元々あったTripwire設定ファイル(暗号署名版)が自動リネームされた
-rw-r----- 1 root root 4159 1月 26 23:56 tw.pol
-rw-r----- 1 root root 13745 1月 26 23:55 twpol.txt
4.ポリシーファイル最適化スクリプト作成
ポリシーファイル最適化スクリプト作成 [root@centos ~]# vi /etc/tripwire/twpolmake.pl viエディタが起動するので以下のテキストを入力します #!/usr/bin/perl # Tripwire Policy File customize tool # ---------------------------------------------------------------- # Copyright (C) 2003 Hiroaki Izumi # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # ---------------------------------------------------------------- # Usage: # perl twpolmake.pl {Pol file} # ---------------------------------------------------------------- # $POLFILE=$ARGV[0]; open(POL,"$POLFILE") or die "open error: $POLFILE" ; my($myhost,$thost) ; my($sharp,$tpath,$cond) ; my($INRULE) = 0 ; while (<POL>) { chomp; if (($thost) = /^HOSTNAMEs*=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) ; 保存してviエディタを終了します
5.ポリシーファイル最適化スクリプトを使いポリシーファイル最適化(テキスト版)を作成
6.ポリシーファイル最適化(テキスト版)とTripwire設定ファイル(暗号署名版)を
元にポリシーファイル(暗号署名版)作成
ポリシーファイル(テキスト版)削除
[root@centos ~]# rm -f /etc/tripwire/twpol.txt*
※ポリシーファイル(テキスト版)を復元する場合
[root@centos ~]# twadmin -m p -c /etc/tripwire/tw.cfg -p /etc/tripwire/tw.pol -S /etc/tripwire/site.key > /etc/tripwire/twpol.txt
[root@centos ~]# ls -la /etc/tripwire
合計 88
drwxr-x--- 2 root root 4096 1月 27 00:31 .
drwxr-xr-x 80 root root 4096 1月 26 23:52 ..
-rw-r----- 1 root root 931 1月 26 23:54 centos.centos.com-local.key
-rw-r----- 1 root root 931 1月 26 23:54 site.key
-rw-r----- 1 root root 4586 1月 27 00:20 tw.cfg
-rw-r----- 1 root root 4586 1月 27 00:20 tw.cfg.bak
-rw-r----- 1 root root 4159 1月 27 00:30 tw.pol 今回作成したポリシーファイル(暗号署名版)
-rw-r----- 1 root root 4159 1月 27 00:30 tw.pol.bak 元々あったポリシーファイル(暗号署名版)が自動リネームされた
-rw-r--r-- 1 root root 1908 1月 27 00:30 twpolmake.pl
7.データベース作成
8.ファイル監視の確認
Report generated by: root
Report created on: 2009年01月27日 00時34分55秒
Database last updated on: Never
===============================================================================
Report Summary:
===============================================================================
Host name: centos.centos.com
Host IP address: 127.0.0.1
Host ID: None
Policy file used: /etc/tripwire/tw.pol
Configuration file used: /etc/tripwire/tw.cfg
Database file used: /usr/local/tripwire/lib/tripwire/centos.centos.com.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
--------- -------------- ----- ------- --------
* Tripwire Data Files 0 1 0 0
Monitor Filesystems 0 0 0 0
User Binaries and Libraries 0 0 0 0
Tripwire Binaries 0 0 0 0
OS Binaries and Libraries 0 0 0 0
Temporary Directories 0 0 0 0
Global Configuration Files 0 0 0 0
System Boot Changes 0 0 0 0
RPM Checksum Files 0 0 0 0
OS Boot Files and Mount Points 0 0 0 0
OS Devices and Misc Directories 0 0 0 0
Root Directory and Files 0 0 0 0
Total objects scanned: 65125
Total violations found: 1
===============================================================================
Object Summary:
===============================================================================
-------------------------------------------------------------------------------
# Section: Unix File System
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
Rule Name: Tripwire Data Files (/usr/local/tripwire/lib/tripwire)
Severity Level: 0
-------------------------------------------------------------------------------
Added:
"/usr/local/tripwire/lib/tripwire/centos.centos.com.twd"
===============================================================================
Error Report:
===============================================================================
No Errors
-------------------------------------------------------------------------------
*** End of report ***
Open Source Tripwire 2.4 Portions copyright 2000 Tripwire, Inc. Tripwire is a registered
trademark of Tripwire, Inc. This software comes with ABSOLUTELY NO WARRANTY;
for details use --version. This is free software which may be redistributed
or modified only under certain conditions; see COPYING for details.
All rights reserved.
ファイルが追加された時の検証をしてみます
[root@centos ~]# echo test > test.txt
Tripwireチェック再実行
[root@centos ~]# tripwire -m c -s -c /etc/tripwire/tw.cfg
Open Source Tripwire(R) 2.4.1 Integrity Check Report
Report generated by: root
Report created on: 2009年01月27日 00時37分07秒
Database last updated on: Never
===============================================================================
Report Summary:
===============================================================================
Host name: centos.centos.com
Host IP address: 127.0.0.1
Host
ID: None
Policy file used: /etc/tripwire/tw.pol
Configuration file used: /etc/tripwire/tw.cfg
Database file used: /usr/local/tripwire/lib/tripwire/centos.centos.com
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
--------- -------------- ----- ------- --------
* Tripwire Data Files 0 1 0 0
Monitor Filesystems 0 0 0 0
User Binaries and Libraries 0 0 0 0
Tripwire Binaries 0 0 0 0
OS Binaries and Libraries 0 0 0 0
Temporary Directories 0 0 0 0
Global Configuration Files 0 0 0 0
System Boot Changes 0 0 0 0
RPM Checksum Files 0 0 0 0
OS Boot Files and Mount Points 0 0 0 0
OS Devices and Misc Directories 0 0 0 0
* Root Directory and Files 0 1 0 0
Total objects scanned: 65126
Total violations found: 2
===============================================================================
Object Summary:
===============================================================================
-------------------------------------------------------------------------------
# Section: Unix File System
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
Rule Name: Tripwire Data Files (/usr/local/tripwire/lib/tripwire)
Severity Level: 0
-------------------------------------------------------------------------------
Added:
"/usr/local/tripwire/lib/tripwire/centos.centos.com.twd"
-------------------------------------------------------------------------------
Rule Name: Root Directory and Files (/root)
Severity Level: 0
-------------------------------------------------------------------------------
Added:
"/root/test.txt" (※追加されたファイルが表示されます)
===============================================================================
Error Report:
===============================================================================
No Errors
-------------------------------------------------------------------------------
*** End of report ***
Open Source Tripwire 2.4 Portions copyright 2000 Tripwire, Inc. Tripwire is a registered
trademark of Tripwire, Inc. This software comes with ABSOLUTELY NO WARRANTY;
for details use --version. This is free software which may be redistributed
or modified only under certain conditions; see COPYING for details.
All rights reserved.
※過去のチェック結果を参照したい場合は以下のコマンドを入力します。
[root@centos ~]# twprint -m r -c /etc/tripwire/tw.cfg -r /usr/local/tripwire/lib/tripwire/report/centos.centossrv.com-20060331-202128.twr
9.Tripwire定期自動実行スクリプト作成およびスケジューラ登録
PATH=/usr/sbin:/usr/bin:/bin:/usr/local/tripwire/sbin
# パスフレーズ設定
LOCALPASS=xxxxxxxx
cd /etc/tripwire
# Tripwireチェック実行
tripwire -m c -s -c tw.cfg|mail -s "Tripwire(R) Integrity Check Report in `hostname`" root
# ポリシーファイル最新化
twadmin -m p -c tw.cfg -p tw.pol -S site.key > twpol.txt
perl twpolmake.pl twpol.txt > twpol.txt.new
twadmin -m P -c tw.cfg -p tw.pol -S site.key -Q $SITEPASS twpol.txt.new > /dev/null
rm -f twpol.txt* *.bak
# データベース最新化
rm -f /usr/local/tripwire/lib/tripwire/*.twd*
tripwire -m i -s -c tw.cfg -P $LOCALPASS
保存してviエディタを終了します
Tripwire定期自動実行スクリプトへ実行権限を付与します
[root@centos ~]# chmod 700 tripwire.sh
Cron(スケジューラ)に午前3時にTripwire定期自動実行スクリプトが起動するように設定します
[root@centos ~]# crontab -e
viエディタが起動するので以下のテキストを入力します
00 05 * * * /root/systemupdate.sh > /root/systemupdate.log 2>&1
00 01 * * * /root/clamav.sh
00 03 * * * /root/tripwire.sh 追加します
保存してviエディタを終了します
■関連記事
自宅サーバー再構築 その1 導入を検討する
自宅サーバー再構築 その2 CentOS 5.2 をインストールする
自宅サーバー再構築 その3 インストールしたCentOS 5.2 にリモート接続準備
自宅サーバー再構築 その4 CentOS 5.2 インストール後の初期設定
自宅サーバー再構築 その5 CentOS 5.2 ファイル転送準備
自宅サーバー再構築 その6 CentOS 5.2 にアンチウィルスソフトを導入する
自宅サーバー再構築 その7 CentOS 5.2 にファイル改竄検知システムを導入する
自宅サーバー再構築 その8 CentOS 5.2 にrootkit検知ツールを導入する
自宅サーバー再構築 その9 CentOS 5.2 にバッファオーバーフロー攻撃対策を行う
自宅サーバー再構築 その10 CentOS 5.2 SSHサーバーを構築して外部からリモート接続&リモートファイル転送
自宅サーバー再構築 その11 CentOS 5.2 にDNSサーバーを導入して名前解決(設定編)
自宅サーバー再構築 その12 CentOS 5.2 にDNSサーバーを導入して名前解決(確認編)
自宅サーバー再構築 その13 CentOS 5.2 にLAMP環境構築(Apache、PHP編)
自宅サーバー再構築 その14 CentOS 5.2 にLAMP環境構築(MySQL編)
自宅サーバー再構築 その15 Apacheにサーバー証明書を導入する
自宅サーバー再構築 その16 CentOS 5.2 にWordPressを導入してブログサイトを構築する
自宅サーバー再構築 その17 WordPressのセキュリティ対策
自宅サーバー再構築 その18 CentOS 5.3 にNTPサーバーを導入して自動時間合わせ
自宅サーバー再構築 その19 CentOS 5.3 アンチウィルスソフトのバージョンアップ
自宅サーバー再構築 その20 CentOS 5.3 メールサーバー構築(Postfix設定編)
自宅サーバー再構築 その21 CentOS 5.3 メールサーバー構築(Dovecot設定編)
自宅サーバー再構築 その22 CentOS 5.3 メールサーバー構築(公開編)
自宅サーバー再構築 その23 CentOS 5.3 メールサーバー構築(SSL導入編)
自宅サーバー再構築 その24 CentOS 5.3 メールサーバー構築(メールアカウント作成編)
自宅サーバー再構築 その25 CentOS 5.3 メールサーバー構築(Thunderbird設定編)
自宅サーバー再構築 番外編その1 CentOS 5.3 のリリースと導入済みソフトウェアのアップデート
今回はCentOS 5.2 にアンチウィルスソフトをインストールしていきます。
ソフトはubuntuの時にもインストールしたClam AntiVirusです。
Clam AntiVirusはCentOSの標準リポジトリには含まれていないので、非公式のリポジトリを一時的に有効にしてClam AntiVirusをインストールしていきます。
Clam AntiVirus をインストールします
[root@centos ~]# yum -y install clamav
Loading "fastestmirror" plugin
Loading mirror speeds from cached hostfile
* dag: ftp.riken.jp
* base: rsync.atworks.co.jp
* updates: rsync.atworks.co.jp
* addons: rsync.atworks.co.jp
* extras: rsync.atworks.co.jp
dag 100% |=========================| 1.1 kB 00:00
primary.xml.gz 100% |=========================| 3.0 MB 00:00
dag : ################################################## 8297/8297
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package clamav.i386 0:0.94.2-1.el5.rf set to be updated
--> Processing Dependency: clamav-db for package: clamav
--> Running transaction check
---> Package clamav-db.i386 0:0.94.2-1.el5.rf set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
clamav i386 0.94.2-1.el5.rf dag 2.5 M
Installing for dependencies:
clamav-db i386 0.94.2-1.el5.rf dag 18 M
Transaction Summary
=============================================================================
Install 2 Package(s)
Update 0 Package(s)
Remove 0 Package(s)
Total download size: 21 M
Downloading Packages:
(1/2): clamav-0.94.2-1.el 100% |=========================| 2.5 MB 00:00
(2/2): clamav-db-0.94.2-1 100% |=========================| 18 MB 00:04
warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID 6b8d79e6
Importing GPG key 0x6B8D79E6 "Dag Wieers (Dag Apt Repository v1.0)
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: clamav-db ######################### [1/2]
Installing: clamav ######################### [2/2]
Installed: clamav.i386 0:0.94.2-1.el5.rf
Dependency Installed: clamav-db.i386 0:0.94.2-1.el5.rf
Complete!
Clam AntiVirusのインストールが終了したので、非公式リポジトリを無効にします。
[root@centos ~]# vi /etc/yum.repos.d/CentOS-Dag.repo
viエディタが起動するので、以下テキストを変更する
[dag]
name=CentOS-$releasever - Dag
baseurl=http://ftp.riken.jp/Linux/dag/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
enabled=0 値を1 から 0 に変更します
gpgkey=http://dag.wieers.com/packages/RPM-GPG-KEY.dag.txt
入力内容を保存してviエディタを終了します
Clam AntiVirusのウィルス定義ファイルをアップデートします
ウィルス定義ファイルをアップデートするfreshclamの設定ファイルである/etc/freshclam.confに NotifyClamd /etc/clamd.conf と記載されている箇所があり /etc/clamd.confファイルがない為に警告が表示されているようです。
clamd.confを検索してみたのですが、見つからなかったのでひとまずコメント化します
2009年04月09日追記
後日アンチウィルスソフトのバージョンアップをした際にClamdパッケージを導入したらclamd.confも導入されました。
詳細はflashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その19 CentOS 5.3 アンチウィルスソフトのバージョンアップをご覧ください。
[root@centos ~]# vi /etc/freshclam.conf
viエディタが起動するので NotifyClamd /etc/clamd.conf の行をコメント化します
# Send the RELOAD command to clamd.
# Default: no
#NotifyClamd /etc/clamd.conf コメント
入力内容を保存してviエディタを終了します
再度Clam AntiVirusのウィルス定義ファイルをアップデートします
[root@centos ~]# freshclam
ClamAV update process started at Mon Jan 26 17:56:41 2009
main.cvd is up to date (version: 49, sigs: 437972, f-level: 35, builder:sven)
daily.cvd is up to date (version: 8902, sigs: 61189, f-level: 38,builder: guitar)
ワーニング・エラーが表示されなければ正常にアップデートが終了しています
le="font-weight:bold;">ウィルススキャンを行います
[root@centos ~]# clamscan --log=/var/log/clamav.log --infected --remove --recursive /home/centos/
----------- SCAN SUMMARY -----------
Known viruses: 498690
Engine version: 0.94.2
Scanned directories: 2
Scanned files: 8
Infected files: 0
Data scanned: 0.00 MB
Time: 3.823 sec (0 m 3 s)
Infected files: が検知したウィルスの件数になります。今回ウィルスは0件でした
無害なウィルスファイルを/home/centos/にダウンロードしてウィルススキャンを行います。
100%[=====================================================================================>]
68 --.-K/s in 0s
18:11:49 (4.22 MB/s) - `/home/centos/eicar.com' を保存しました [68/68]
[root@centos log]# wget -P /home/centos/ http://www.eicar.org/download/eicarcom2.zip
--18:12:20-- http://www.eicar.org/download/eicarcom2.zip
www.eicar.org をDNSに問いあわせています... 88.198.38.136
www.eicar.org|88.198.38.136|:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 308 [application/zip]
Saving to: `/home/centos/eicarcom2.zip'
100%[=====================================================================================>]
308 --.-K/s in 0s
18:12:41 (21.0 MB/s) - `/home/centos/eicarcom2.zip' を保存しました [308/308]
[root@centos ~]# ls -l/home/centos
合計 32
-rw-r--r-- 1 root root 68 7月 4 2008 eicar.com
-rw-r--r-- 1 root root 308 7月 4 2008 eicarcom2.zip
ウィルススキャンを行います
[root@centos ~]# clamscan --log=/var/log/clamav.log --infected --remove --recursive /home/centos/
/home/centos/eicar.com: Eicar-Test-Signature FOUND
/home/centos/eicar.com: Removed
/home/centos/eicarcom2.zip: Eicar-Test-Signature FOUND
/home/centos/eicarcom2.zip: Removed
----------- SCAN SUMMARY -----------
Known viruses: 498690
Engine version: 0.94.2
Scanned directories: 2
Scanned files: 10
Infected files: 2
Data scanned: 0.00 MB
Time: 3.932 sec (0 m 3 s)
今回ウィルスは2件検知・削除しました
[root@centos ~]# ls -l /home/centos
合計 0
ウィルス定義ファイルの自動アップデートと自動ウィルススキャンのシェルを作り、スケジューラに設定します。
ウィルス定義ファイルの自動アップデートと自動ウィルススキャンのシェルを作ります [root@centos ~]# vi /root/clamav.sh #!/bin/sh echo "Job Name (clamav.sh)" echo " 開始(`date +"%k時%M分%S秒"`)" rm -f /var/log/clamav.log > /dev/null 2>&1 freshclam --quiet clamscan --log=/var/log/clamav.log --infected --remove --recursive / > /dev/null 2>&1 grep FOUND /var/log/clamav.log echo " 終了(`date +"%k時%M分%S秒"`)" 作ったシェルに実行権限を付与します [root@centos ~]# chmod 700 /root/clamav.sh 毎日1時にシェルが動くようにスケジューラーに組み込みます。 [root@centos ~]# crontab -e viエディタが起動します 00 05 * * * /root/systemupdate.sh > /root/systemupdate.log 2>&1 00 01 * * * /root/clamav.sh 追記します ファイルを保存しviエディタを終了してください。
さて、これでアンチウィルスソフトの導入は終わりです。
こちらを参考にしました。
はじめての自宅サーバ構築 Fedora/CentOS - アンチウィルスソフトの導入(Clam AntiVirus)
こちらのサイト凄いです。
Fedora Core 1 から Fedora 10、CentOS4とCentOS5 それぞれ手順がまとまっていました。
■関連記事
自宅サーバー再構築 その1 導入を検討する
自宅サーバー再構築 その2 CentOS 5.2 をインストールする
自宅サーバー再構築 その3 インストールしたCentOS 5.2 にリモート接続準備
自宅サーバー再構築 その4 CentOS 5.2 インストール後の初期設定
自宅サーバー再構築 その5 CentOS 5.2 ファイル転送準備
自宅サーバー再構築 その6 CentOS 5.2 にアンチウィルスソフトを導入する
自宅サーバー再構築 その7 CentOS 5.2 にファイル改竄検知システムを導入する
自宅サーバー再構築 その8 CentOS 5.2 にrootkit検知ツールを導入する
自宅サーバー再構築 その9 CentOS 5.2 にバッファオーバーフロー攻撃対策を行う
自宅サーバー再構築 その10 CentOS 5.2 SSHサーバーを構築して外部からリモート接続&リモートファイル転送
自宅サーバー再構築 その11 CentOS 5.2 にDNSサーバーを導入して名前解決(設定編)
自宅サーバー再構築 その12 CentOS 5.2 にDNSサーバーを導入して名前解決(確認編)
自宅サーバー再構築 その13 CentOS 5.2 にLAMP環境構築(Apache、PHP編)
自宅サーバー再構築 その14 CentOS 5.2 にLAMP環境構築(MySQL編)
自宅サーバー再構築 その15 Apacheにサーバー証明書を導入する
自宅サーバー再構築 その16 CentOS 5.2 にWordPressを導入してブログサイトを構築する
自宅サーバー再構築 その17 WordPressのセキュリティ対策
自宅サーバー再構築 その18 CentOS 5.3 にNTPサーバーを導入して自動時間合わせ
自宅サーバー再構築 その19 CentOS 5.3 アンチウィルスソフトのバージョンアップ
自宅サーバー再構築 その20 CentOS 5.3 メールサーバー構築(Postfix設定編)
自宅サーバー再構築 その21 CentOS 5.3 メールサーバー構築(Dovecot設定編)
自宅サーバー再構築 その22 CentOS 5.3 メールサーバー構築(公開編)
自宅サーバー再構築 その23 CentOS 5.3 メールサーバー構築(SSL導入編)
自宅サーバー再構築 その24 CentOS 5.3 メールサーバー構築(メールアカウント作成編)
自宅サーバー再構築 その25 CentOS 5.3 メールサーバー構築(Thunderbird設定編)
自宅サーバー再構築 番外編その1 CentOS 5.3 のリリースと導入済みソフトウェアのアップデート