Archive for the ‘chkrootkit’ Category

2月
10

今回はクラッカー対策第二弾としてrootkit対策をします。

rootkitと言うのはクラッカーがサーバーに不正侵入してもシステム管理者にみつからないようにする為のツールやコマンドの事です。
例えばシステム管理者がLinuxとかUnixサーバー上で稼働しているプロセス一覧を見ようとしてpsコマンドを実行したとします。
サーバーが既にrootkitにやられている場合、psコマンドの結果のプロセス一覧にはクラッカーが実行している不正なプロセスが表示されないようになったりするそうです。

そういった普通には見つけられない不正なツールやコマンドを検知する為に「chkrootkit」を導入したいと思います。

1.非公式リポジトリを一時有効にする
2.chkrootkitのダウンロードとインストール
3.非公式リポジトリを無効にする
4.chkrootkit実行
5.chkrootkit定期自動実行スクリプト作成およびスケジューラ登録
6.chkrootkitで使用する安全なコマンドの確保

1.非公式リポジトリを一時有効にする
「chkrootkit」はアンチウィルスソフトの「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=1 0 から 1 へ変更
gpgkey=http://dag.wieers.com/packages/RPM-GPG-KEY.dag.txt

保存してviエディタを終了します

2.chkrootkitのダウンロードとインストール

[root@centos ~]# yum -y install chkrootkit
Loading “priorities” plugin
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
base 100% |=========================| 1.1 kB 00:00
updates 100% |=========================| 951 B 00:00
addons 100% |=========================| 951 B 00:00
extras 100% |=========================| 1.1 kB 00:00
0 packages excluded due to repository priority protections
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
–> Running transaction check
—> Package chkrootkit.i386 0:xx.xx-xx.xxx.rf set to be updated
–> Finished Dependency Resolution

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」と表示されるのでそれも併せて確認します。

[root@centos ~]# chkrootkit | grep 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 ~]# mkdir chkrootkitcmd

安全なコマンドをバックアップディレクトリにコピーします
[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

————————————————————————————————–
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その7 CentOS 5.2 にファイル改竄検知システムを導入する
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その6 CentOS 5.2 にアンチウィルスソフトを導入する
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その5 CentOS 5.2 ファイル転送準備
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その4 CentOS 5.2 インストール後の初期設定
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その3 インストールしたCentOS 5.2 にリモート接続準備
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その2 CentOS 5.2 をインストールする
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その1 導入を検討する

  • Search:
  • flashcastとは?

    東京を中心に、現在フリーランスとして活動しているITエンジニア、および、かつてフリーランスとして活動していた起業家達が立ち上げたコミュニティーです。

    みんなで集まって面白いことをやろう!形に残そう!ということで、ブログをはじめました。

    技術情報や、フリーエンジニアに役立つ情報などを、ご紹介できたらと思っています。

    お問い合わせ:
    info@flashcast.jp
  • カレンダー

    2010年7月
    日曜日 月曜日 火曜日 水曜日 木曜日 金曜日 土曜日
    « 6月    
     123
    45678910
    11121314151617
    18192021222324
    25262728293031
  • メンバー紹介

    もじゃもじゃ
    flashcastのリーダー

    3年ほどフリーのITエンジニアとして活動。現在は、社員2名の株式会社を経営しています。

    一攫千金を夢見る野心家です。

    ライブキャスト

    yasu
    ダイバー

    自宅サーバーでホームページを作り始めました。

    少しずつ記事を増やしていきますので足を運んでください。

    よろしくお願いします。

    sa-sa-ki.jp

    のら
    たびびと

    ねこ好きに悪人はいなーいっ!!

    バイクや車も好きです。

    めぐ
    デザイナーのたまご

    音楽とデザインとお酒をこよなく愛する永遠のダイエッター。

    現在ペンタブレットでイラストを勉強中。

    Hiro
    コンサル

    PMやSEの案件を業務委託で請けることが多いですが、小規模案件も受託でやっています。

    得意な分野はマイクロソフト製品や関連技術によるシステム構築です。

    KEI
    取締役の風格

    最年少なのに、メンバーで1番の貫禄の持ち主!?

    C#や.netなどサーバ側の開発が得意。

    ろっきー
    美食家★パパ

    自分にとっての息抜きは、ドライブして温泉に入って、美味しいご飯を食べる事。

    ココロとカラダのリフレッシュを大切にし、日々の仕事に励む一児の父親です。

    郵便番号検索

    my-hobby

    とのさま
    げーむのおうさま

    大人なのに好きなことしかやらない駄目人間。

    Web系が得意、アクセスは苦手><

    tonosamart.com

    セクレタリアト
    ギャンブラー

    フリーランス時代は仲間の現場を探すことが多く、それをきっかけに会社を設立。

    現在はSI業に特化せず、他の業種にも興味を持ち始めています。

    メドレー株式会社

  • 広告