前回(RPMforgeリポジトリ導入@CentOS5のメモ - blog@longkey1.net)に引き続きchkrootkitを導入してみた。
で、いつものサイトを参考にchkrootkitの設定をしてみる。
rootkit検知ツール導入(chkrootkit) - CentOSで自宅サーバー構築
rootkitという存在をはじめて知った。
ルートキット - Wikipedia
名前はなんだか便利そうだが、それはクラッカーにとってはだな。
常駐するタイプでも無さそうなので、導入してみても良いかなという判断。
まあ、仮にrootkitを入れられたらどうやら終わりらしいので。
早速chkrootkitコマンドを使ってチェックしてみる。
ちなみにgrepをかませないと、こんな感じになる。
なるー。
で、このchkrootkitコマンドを定期的に実行して、なんか問題あればメールで送信ってことをやる。
んー、至れり尽くせりでございます。
システムログに書き込むコマンドかな。
-tはTagで、今回の場合は「chkrootkit」って文字列も一緒に記録してくれるらしい。
いやー、これをうまく使えば自分で作ったシェルでどんどんログに書き込めちゃうのか。
なるほどなー、ちょっと楽しいかも、これ。
■SMTPSのbindshell誤検知対応
postfix絡みでSMTPSで誤検知してしまうことがあるらしい。
んで、ポート番号(465)でgrepしてるのなー。
あとは、grepで'INFECTED'を検索して、メールしてるだけね。
厳重ね。
実際のところ、サーバ再構築した方が良いかなと思うけど、再構築するは良いけど進入方法調べるの大変そう・・・。
■which
コマンドの場所を調べる為のコマンド。
こんなのあるのかー。
--skip-aliasはそのまんまだろうね。
コマンドの場所を調べるには
cpコマンドみたいなものはパイプで渡すというより、こういう使い方なんだろうねえ。
■chkrootkit -p
ディレクトリを指定する場合くさい。
@IT:chkrootkitで指定できるオプション
■zip -r
-rは再帰的に圧縮ってオプション。
linuxのサンプルサイトでzipが出てくるのは新鮮だ。
zipコマンドのオプション一覧(linux) - Knowledge Database IT
技術/sharutilsのuuencode,uudecodeによるBASE64エンコード,デコード - Glamenv-Septzen.net
ちなみにsharutilsと検索するとやたらセキュリティホールとか出てくるんだけど、大丈夫だろうか?
んで、作業ファイルであるzipファイルを削除。
これをgmailで受け取ると添付ファイルと認識されない。
どうやらメールソフト側がuudecodeに対応して無いくさい。
んー、デコード出来るんなら別に良いんだけど、どうなんだろ。
試してみないといけないな。
とりあえず疲れたのでchkrootkitのインストール関連はこれにて終了。
3時間以上書くのに費やしているけど、意外にこうやって細かくブログに書くのは良いかもしれない。
やっぱブログに書こうとすると調べなくちゃいけないし。
まあ、みんなに有意義な情報とはいかないけど、自分の勉強にはなるな。
続けるべし。
で、いつものサイトを参考にchkrootkitの設定をしてみる。
rootkit検知ツール導入(chkrootkit) - CentOSで自宅サーバー構築
rootkitという存在をはじめて知った。
ルートキット - Wikipedia
名前はなんだか便利そうだが、それはクラッカーにとってはだな。
なお、chkrootkitが検知できるのは既知のrootkitのみであり、新たなrootkitの検知はできない。ってことは、んー無いよりあった方が良いけど・・・って程度なのかな。
また、rootkitが設置されていないにもかかわらず、chkrootkitが誤ってrootkitを検知したとアラームをあげる場合もあるので、chkrootkitによるrootkitの検知結果は参考程度としておく。
常駐するタイプでも無さそうなので、導入してみても良いかなという判断。
まあ、仮にrootkitを入れられたらどうやら終わりらしいので。
yum -y install chkrootkit今度は無事インストール完了。早速chkrootkitコマンドを使ってチェックしてみる。
chkrootkit | grep INFECTED特に何も表示されなければ、問題ないらしい。ちなみにgrepをかませないと、こんな感じになる。
Checking `amd'... not found
Checking `basename'... not infected
Checking `biff'... not found
Checking `chfn'... not infected
Checking `chsh'... not infected
Checking `cron'... not infected
Checking `crontab'... not infected
Checking `date'... not infected
Checking `du'... not infected
Checking `dirname'... not infected
Checking `echo'... not infected
Checking `egrep'... not infected
Checking `env'... not infected
Checking `find'... not infected
Checking `fingerd'... not found
Checking `gpm'... not infected
Checking `grep'... not infected
Checking `hdparm'... not infected
Checking `su'... not infected
Checking `ifconfig'... not infected
Checking `inetd'... not found
Checking `inetdconf'... not found
Checking `identd'... not found
Checking `init'... not infected
Checking `killall'... not infected
Checking `ldsopreload'... not infected
Checking `login'... not infected
Checking `ls'... not infected
Checking `lsof'... not infected
Checking `mail'... not infected
Checking `mingetty'... not infected
Checking `netstat'... not infected
Checking `named'... not found
Checking `passwd'... not infected
Checking `pidof'... not infected
Checking `pop2'... not found
Checking `pop3'... not found
Checking `ps'... not infected
Checking `pstree'... not infected
Checking `rpcinfo'... not infected
Checking `rlogind'... not found
Checking `rshd'... not found
Checking `slogin'... not infected
Checking `sendmail'... not infected
Checking `sshd'... not infected
Checking `syslogd'... not infected
Checking `tar'... not infected
Checking `tcpd'... not infected
Checking `tcpdump'... not infected
Checking `top'... not infected
Checking `telnetd'... not found
Checking `timed'... not found
Checking `traceroute'... not infected
Checking `vdir'... not infected
Checking `w'... not infected
Checking `write'... not infected
Checking `aliens'... no suspect files
Searching for sniffer's logs, it may take a while... nothing found
Searching for HiDrootkit's default dir... nothing found
Searching for t0rn's default files and dirs... nothing found
Searching for t0rn's v8 defaults... nothing found
Searching for Lion Worm default files and dirs... nothing found
Searching for RSHA's default files and dir... nothing found
Searching for RH-Sharpe's default files... nothing found
Searching for Ambient's rootkit (ark) default files and dirs... nothing found
Searching for suspicious files and dirs, it may take a while...
/usr/lib/perl5/5.8.8/i386-linux-thread-multi/.packlist
/usr/lib/gtk-2.0/immodules/.relocation-tag
/lib/.libcrypto.so.0.9.8e.hmac /lib/.libcrypto.so.6.hmac
Searching for LPD Worm files and dirs... nothing found
Searching for Ramen Worm files and dirs... nothing found
Searching for Maniac files and dirs... nothing found
Searching for RK17 files and dirs... nothing found
Searching for Ducoci rootkit... nothing found
Searching for Adore Worm... nothing found
Searching for ShitC Worm... nothing found
Searching for Omega Worm... nothing found
Searching for Sadmind/IIS Worm... nothing found
Searching for MonKit... nothing found
Searching for Showtee... nothing found
Searching for OpticKit... nothing found
Searching for T.R.K... nothing found
Searching for Mithra... nothing found
Searching for OBSD rk v1... nothing found
Searching for LOC rootkit... nothing found
Searching for Romanian rootkit... nothing found
Searching for HKRK rootkit... nothing found
Searching for Suckit rootkit... nothing found
Searching for Volc rootkit... nothing found
Searching for Gold2 rootkit... nothing found
Searching for TC2 Worm default files and dirs... nothing found
Searching for Anonoying rootkit default files and dirs... nothing found
Searching for ZK rootkit default files and dirs... nothing found
Searching for ShKit rootkit default files and dirs... nothing found
Searching for AjaKit rootkit default files and dirs... nothing found
Searching for zaRwT rootkit default files and dirs... nothing found
Searching for Madalin rootkit default files... nothing found
Searching for Fu rootkit default files... nothing found
Searching for ESRK rootkit default files... nothing found
Searching for rootedoor... nothing found
Searching for ENYELKM rootkit default files... nothing found
Searching for anomalies in shell history files... nothing found
Checking `asp'... not infected
Checking `bindshell'... not infected
Checking `lkm'... chkproc: nothing detected
Checking `rexedcs'... not found
Checking `sniffer'... eth0: PF_PACKET(/sbin/dhclient)
Checking `w55808'... not infected
Checking `wted'... chkwtmp: nothing deleted
Checking `scalper'... not infected
Checking `slapper'... not infected
Checking `z2'... chklastlog: nothing deleted
Checking `chkutmp'... chkutmp: nothing deletedこれは長い。なるー。
で、このchkrootkitコマンドを定期的に実行して、なんか問題あればメールで送信ってことをやる。
んー、至れり尽くせりでございます。
#vi chkrootkit
#!/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■loggerシステムログに書き込むコマンドかな。
-tはTagで、今回の場合は「chkrootkit」って文字列も一緒に記録してくれるらしい。
いやー、これをうまく使えば自分で作ったシェルでどんどんログに書き込めちゃうのか。
なるほどなー、ちょっと楽しいかも、これ。
■SMTPSのbindshell誤検知対応
postfix絡みでSMTPSで誤検知してしまうことがあるらしい。
んで、ポート番号(465)でgrepしてるのなー。
あとは、grepで'INFECTED'を検索して、メールしてるだけね。
# chmod 700 chkrootkit
# mv chkrootkit /etc/cron.daily/実行権限つけて、cronに登録。# mkdir chkrootkitcmd
# cp `which --skip-alias awk cut echo egrep find head id ls netstat ps strings sed uname` chkrootkitcmd/
# chkrootkit -p /root/chkrootkitcmd|grep INFECTED
# zip -r chkrootkitcmd.zip chkrootkitcmd/
adding: chkrootkitcmd/ (stored 0%)
adding: chkrootkitcmd/head (deflated 53%)
adding: chkrootkitcmd/netstat (deflated 58%)
adding: chkrootkitcmd/find (deflated 50%)
adding: chkrootkitcmd/sed (deflated 54%)
adding: chkrootkitcmd/strings (deflated 53%)
adding: chkrootkitcmd/ps (deflated 59%)
adding: chkrootkitcmd/cut (deflated 53%)
adding: chkrootkitcmd/uname (deflated 54%)
adding: chkrootkitcmd/ls (deflated 53%)
adding: chkrootkitcmd/echo (deflated 56%)
adding: chkrootkitcmd/id (deflated 55%)
adding: chkrootkitcmd/egrep (deflated 50%)
adding: chkrootkitcmd/awk (deflated 52%)
# rm -rf chkrootkitcmdrootkitをいれられちゃった場合、コマンド自体が書き換えられたりするらしいので、正常なコマンド達のバックアップを取っておこうって話だな。厳重ね。
実際のところ、サーバ再構築した方が良いかなと思うけど、再構築するは良いけど進入方法調べるの大変そう・・・。
■which
コマンドの場所を調べる為のコマンド。
こんなのあるのかー。
--skip-aliasはそのまんまだろうね。
コマンドの場所を調べるには
cpコマンドみたいなものはパイプで渡すというより、こういう使い方なんだろうねえ。
■chkrootkit -p
ディレクトリを指定する場合くさい。
@IT:chkrootkitで指定できるオプション
■zip -r
-rは再帰的に圧縮ってオプション。
linuxのサンプルサイトでzipが出てくるのは新鮮だ。
zipコマンドのオプション一覧(linux) - Knowledge Database IT
# yum -y install sharutilsコメントではmailコマンドでzipファイル添付メールを送信するのに必要なuuencodeコマンドインストールsharutilsとはなんじゃならほいと検索したら、こんなの出てきた。
技術/sharutilsのuuencode,uudecodeによるBASE64エンコード,デコード - Glamenv-Septzen.net
メールの添付ファイルの形式として、UNIX世界では昔から Unix to Unix encode というエンコードツールが使われて来ました。現在も多くのディストリビューションで "sharutils" というパッケージ名で提供されています。なるほどー。
ちなみにsharutilsと検索するとやたらセキュリティホールとか出てくるんだけど、大丈夫だろうか?
# uuencode chkrootkitcmd.zip chkrootkitcmd.zip|mail root
# rm -f chkrootkitcmd.zipzipファイルをエンコードして、解凍時にはchkrootkitcmd.zipというファイル名で解凍したくて、それをrootへメールを送っている。んで、作業ファイルであるzipファイルを削除。
これをgmailで受け取ると添付ファイルと認識されない。
どうやらメールソフト側がuudecodeに対応して無いくさい。
んー、デコード出来るんなら別に良いんだけど、どうなんだろ。
試してみないといけないな。
とりあえず疲れたのでchkrootkitのインストール関連はこれにて終了。
3時間以上書くのに費やしているけど、意外にこうやって細かくブログに書くのは良いかもしれない。
やっぱブログに書こうとすると調べなくちゃいけないし。
まあ、みんなに有意義な情報とはいかないけど、自分の勉強にはなるな。
続けるべし。
コメント