chkrootkit導入

 rootkitとは、攻撃者がハッキングに成功した後、次に侵入しやすくするためバックドア及びトロイの木馬プログラムを設置するがこのようなプログラムをrootkitと言います。システムに元々あったプログラムを入れ替えられ、管理者がシステムを点検しても異常が無いように見せて攻撃者の行動を隠したりします。
 このような不正なツールが外部より設置されているのかを簡単にチェックできるプログラムがchkrootkitです。chkrootkitは一般的にrootkitだけでなく、カーネル基盤のrootkit、wormまでも探知が可能です。

 chkrootkitが使用するコマンド自体を改竄された後に導入すると、rootkitを検出できなくなるため、Linuxのインストール直後の早い段階で導入しましょう。



chkrootkitのインストール

[root@localhost user1]# wget ftp://ftp.pangeia.com.br/pub/seg/pac/chkrootkit.tar.gz @
--09:27:37-- ftp://ftp.pangeia.com.br/pub/seg/pac/chkrootkit.tar.gz
=> `chkrootkit.tar.gz'
ftp.pangeia.com.br をDNSに問いあわせています... 200.239.53.35
ftp.pangeia.com.br[200.239.53.35]:21 に接続しています... 接続しました。
anonymous としてログインしています... ログインしました!
==> SYST ... 完了しました。 ==> PWD ... 完了しました。
==> TYPE I ... 完了しました。 ==> CWD /pub/seg/pac ... 完了しました。
==> PASV ... 完了しました。 ==> RETR chkrootkit.tar.gz ... 完了しました。
長さ: 34,163 (確証はありません)

100%[====================================>] 34,163 7.30K/s ETA 00:00

09:27:49 (6.90 KB/s) - `chkrootkit.tar.gz' saved [34,163]

[root@localhost user1]# cd /usr/local/
[root@localhost local]# tar zxvf /home/user1/chkrootkit.tar.gz A
chkrootkit-0.44
chkrootkit-0.44/ACKNOWLEDGMENTS
chkrootkit-0.44/chkrootkit
chkrootkit-0.44/chkproc.c
chkrootkit-0.44/README
chkrootkit-0.44/chklastlog.c
chkrootkit-0.44/README.chkwtmp
chkrootkit-0.44/COPYRIGHT
chkrootkit-0.44/Makefile
chkrootkit-0.44/check_wtmpx.c
chkrootkit-0.44/strings.c
chkrootkit-0.44/ifpromisc.c
chkrootkit-0.44/chkdirs.c
chkrootkit-0.44/chkrootkit.lsm
chkrootkit-0.44/chkwtmp.c
chkrootkit-0.44/README.chklastlog

[root@localhost local]# cd chkrootkit-0.44/
[root@localhost chkrootkit-0.44]# make sense B
gcc -DHAVE_LASTLOG_H -o chklastlog chklastlog.c
gcc -DHAVE_LASTLOG_H -o chkwtmp chkwtmp.c
gcc -DHAVE_LASTLOG_H -o ifpromisc ifpromisc.c
gcc -o chkproc chkproc.c
gcc -o chkdirs chkdirs.c
gcc -o check_wtmpx check_wtmpx.c
gcc -static -o strings-static strings.c

[root@localhost chkrootkit-0.44]# rm -f /home/user1/chkrootkit.tar.gz C


@ chkrootkitのダウンロード
A ダウンロードファイルの展開
B chkrootkitのインストール(コンパイル)
C ダウンロードファイルの削除



chkrootkit実行

[root@localhost chkrootkit-0.44]# ./chkrootkit @
ROOTDIR is `/'
Checking `amd'... not found
Checking `basename'... not infected A
Checking `biff'... not found
Checking `chfn'... not infected
Checking `chsh'... not infected
Checking `cron'... not infected
Checking `date'... not infected
Checking `du'... not infected



Checking `sniffer'... eth0: PF_PACKET(/sbin/dhclient)
Checking `w55808'... not infected
Checking `wted'... nothing deleted
Checking `scalper'... not infected
Checking `slapper'... not infected
Checking `z2'... nothing deleted


[root@localhost chkrootkit-0.44]# ./chkrootkit -q B

/usr/lib/perl5/vendor_perl/5.8.3/i386-linux-thread-multi/auto/NKF/.packlist /usr/lib/perl5/5.8.5/i386-linux-thread-multi/.packlist /lib/modules/2.6.9-1.667/build/.config /lib/modules/2.6.9-1.667/build/scripts/kconfig/.mconf.o.cmd /lib/modules/2.6.9-1.667/build/scripts/kconfig/.conf.o.cmd /lib/modules/2.6.9-1.667/build/scripts/kconfig/.libkconfig.so.cmd /lib/modules/2.6.9-1.667/build/scripts/kconfig/.conf.cmd /lib/modules/2.6.9-1.667/build/scripts/kconfig/.zconf.tab.o.cmd /lib/modules/2.6.9-1.667/build/scripts/basic/.split-include.cmd /lib/modules/2.6.9-1.667/build/scripts/basic/.docproc.cmd /lib/modules/2.6.9-1.667/build/scripts/basic/.fixdep.cmd /lib/modules/2.6.9-1.667/build/scripts/.kallsyms.cmd /lib/modules/2.6.9-1.667/build/scripts/.conmakehash.cmd /lib/modules/2.6.9-1.667/build/scripts/genksyms/.lex.o.cmd /lib/modules/2.6.9-1.667/build/scripts/genksyms/.genksyms.cmd /lib/modules/2.6.9-1.667/build/scripts/genksyms/.genksyms.o.cmd /lib/modules/2.6.9-1.667/build/scripts/genksyms/.parse.o.cmd /lib/modules/2.6.9-1.667/build/scripts/mod/.modpost.cmd /lib/modules/2.6.9-1.667/build/scripts/mod/.elfconfig.h.cmd /lib/modules/2.6.9-1.667/build/scripts/mod/.file2alias.o.cmd /lib/modules/2.6.9-1.667/build/scripts/mod/.sumversion.o.cmd /lib/modules/2.6.9-1.667/build/scripts/mod/.mk_elfconfig.cmd /lib/modules/2.6.9-1.667/build/scripts/mod/.empty.o.cmd /lib/modules/2.6.9-1.667/build/scripts/mod/.modpost.o.cmd /lib/modules/2.6.9-1.667/build/scripts/.pnmtologo.cmd C

eth0: PF_PACKET(/sbin/dhclient) D


@ chkrootkitの実行
A 「INFECTED」が無い事を確認
B エラー表示のみでのchkrootkitの実行
C /usr/lib、/libディレクトリ内の隠しファイル/ディレクトリ
D プロミスキャストモード(自ホスト宛以外のパケットも受信する状態)で動作しているプロセス
  「/sbin/dhclient」はDHCPクライアントである為、問題無し



chkrootkit定期自動実行設定

[root@localhost chkrootkit-0.44]# vi /root/chkrootkit.sh @

#!/bin/sh
cd /usr/local/chkrootkit-0.44/
./chkrootkit > /var/log/chkrootkit.log
chmod 600 /var/log/chkrootkit.log
grep INFECTED /var/log/chkrootkit.log

[root@localhost chkrootkit-0.44]# chmod 700 /root/chkrootkit.sh A

[root@localhost chkrootkit-0.44]# crontab -e B

00 06 * * * /root/chkrootkit.sh C


@ chkrootkit実行スクリプトの作成
A スクリプトに実行権限付加
B cron編集
C 毎日6:00にchkrootkit実行スクリプトを実行



安全なコマンドの確保

 chkrootkitが使用するコマンド群が改竄された場合、正常に検出できなくなるので、その様な場合に備えてchkrootkitが使用するコマンド群をコピーしておく。必要な場合にはそのコマンド群を使用してchkrootkitを実行する。
 必要なコマンド群は以下の通り。
    awk、cut、echo、egrep、find、head、id、ls、 netstat、ps、strings、sed、uname


[root@localhost ~]# mkdir cmd
[root@localhost ~]# cp `which --skip-alias awk cut echo egrep find head id ls netstat ps strings sed uname` ./cmd/

 上記は「cmd」ディレクトリを作成し、その中にコピーを行う場合。


[root@localhost ~]# mount -t vfat /dev/fd0 /floppy
[root@localhost ~]# cp -rp chkrootkit-0.44 /floppy/
[root@localhost ~]# cp -rp cmd /floppy/

 こちらはフロッピーに抜き取る場合の例。