Amazon EC2でマルウェアであるルートキットを検出する – chkrootkit / rkhunter –

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

マルウェアとは

マルウェアは、悪意のあるソフトウェアのことで、例として、ウィルス、バックドア、キーロガー、トロイの木馬、スパイウェア等が挙げられます。これらのマルウェアは日々進化しており、今日の対策が明日から無効になる可能性もあります。多くは、OSやミドルウェアの弱点を突いて侵入したり、ユーザーのPCに感染してからキーロガーを通してパスワード等を入手し侵入したり、あるいは電話やメールでパソコン修理担当を装ってパスワードを直接聞いてきたりと様々な方法があります。今回は、トロイの木馬の一種であるルートキットを検出するchkrootkitを試してみます。

ルートキットとは

ルートキットは、第三者が不正に侵入した後に実行するソフトウェア群のことです。ログオン履歴、プロセス、ファイル、ログ等の侵入検知に必要な情報を隠蔽するので、IDS単体では対策できません。多くの場合、外部との通信用にバックドアを用意して、管理者に見えない形で様々なスパイウェアを送り込んだり、キーロガーからサーバー情報を収集したり、他のサーバーへ攻撃するための踏み台になります。ルートキットには、大きく分けてカーネルレベルとアプリケーションレベルがあり、前者はアクセス範囲と権限が大きいため危険です。

ルートキットを検出する

既にルートキットが組み込まれていないかチェックするツールで、Amazon Linuxのパッケージから直ぐにインストールできるソフトウェアは、chkrootkitとrkhunterです。早速インストールしてみましょう。

$ yum install chkrootkit
$ yum install rkhunter

chkrootkitを使ってみる

何をチェックしてくれるのか確認してみましょう。基本的なプロセスの改竄とトロイの木馬の存在を確認してくれます。

$ chkrootkit -l
/usr/lib64/chkrootkit-0.49/chkrootkit: tests: aliens asp bindshell lkm rexedcs sniffer w55808 wted scalper slapper z2 chkutmp OSX_RSPLUG amd basename biff chfn chsh cron crontab date du dirname echo egrep env find fingerd gpm grep hdparm su ifconfig inetd inetdconf identd init killall  ldsopreload login ls lsof mail mingetty netstat named passwd pidof pop2 pop3 ps pstree rpcinfo rlogind rshd slogin sendmail sshd syslogd tar tcpd tcpdump top telnetd timed traceroute vdir w write

実際にチェックします。サクッと終わりました。ログに INFECTED と出力されるとルートキットに感染している疑いがあるということです。ただし、亜種のルートキットは検出できません。さらに、chkrootkitは、検出だけですので検閲や修復はしてくれません。ただちにサーバーを止める必要があると思います。chkrootkitは有名なツールではありますが、2年近く更新されていませんので、最新のルートキットには対応してなく少々不安ですね。。。次は継続的にメンテナンスされているrkhunterを使ってみます。

$ chkrootkit
ROOTDIR is `/'
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 found
Checking `grep'... not infected
Checking `hdparm'... not found
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 found
Checking `rlogind'... not found
Checking `rshd'... not found
Checking `slogin'... not infected
Checking `sendmail'... not infected
Checking `sshd'... not infected
Checking `syslogd'... not tested
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/.libssl.so.10.hmac /usr/lib/.libssl.so.1.0.0g.hmac /lib/.libcrypto.so.1.0.0g.hmac /lib/.libcrypto.so.10.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 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 common ssh-scanners 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
chkdirs: nothing detected
Checking `rexedcs'... not found
Checking `sniffer'... eth0: PROMISC 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
Checking `OSX_RSPLUG'... not infected

rkhunterを使ってみる

rkhunterは、ルートキットに関するデータベースを更新することができ、比較的メンテナンスが行われているルートキット検知ツールです。特徴として、以下の5点があります。ルートキットハンターという名前も機能も心強いですね。

  • MD5ハッシュを比較する
  • ルートキットで使われる標準的なファイルを検出する
  • 不正なアクセス権が与えられたバイナリファイルを検出する
  • LKM/KLDモジュール(読み込み可能カーネルモジュール)に疑わしい文字列を検出する
  • 隠しファイルを探す

まずは、最新のパターンファイルにアップデートするためにデータベースを更新します。

$ rkhunter --update                                                     
[ Rootkit Hunter version 1.3.8 ]

Checking rkhunter data files...
  Checking file mirrors.dat                                  [ No update ]
  Checking file programs_bad.dat                             [ Updated ]
  Checking file backdoorports.dat                            [ No update ]
  Checking file suspscan.dat                                 [ Updated ]
  Checking file i18n/cn                                      [ No update ]
  Checking file i18n/de                                      [ Updated ]
  Checking file i18n/en                                      [ No update ]
  Checking file i18n/zh                                      [ Updated ]
  Checking file i18n/zh.utf8                                 [ Updated ]

次にスキャンを始めます。大量のログが出るので、キー入力確認なし、レポート表示はWarningのみ、メールによる警告なしで設定しています。かなり時間が掛かります。t1.microインスタンスで20分程掛かりました。

$ rkhunter --check --skip-keypress --report-warnings-only --no-mail-on-warning

まとめ

chkrootkitとrkhunterによって、侵入者が仕込んだルートキットを検出できる可能性が高くなりました。特にカーネルモジュール型のルートキットはユーザーから見えない仕掛けで情報を盗んだり悪事を働きますので継続的な危険性が高く、ファイアウォール内のデータベースサーバーへの攻撃の踏み台になる可能性もあります。基本的な知識と良く知られたツールを使いこなして最低限のセキュリティを確保しましょう。今日から君もルートキットハンターだ!!

参考資料

chkrootkit

Rootkit Hunter Project

マルウェア - Wikipedia

ルートキット - Wikipedia