はじめに
本記事では、LPIC303出題範囲のchkrootkit/rkhunter/maldetによるRootkit・マルウェア検出をVirtualBox + Vagrantで構築した環境でハンズオン学習した記録を記載しています。
-
対象範囲
- chkrootkit
- rkhunter
- /etc/rkhunter.conf
- maldet (Linux Malware Detect)
- conf.maldet
- cronによるホストスキャンの自動化
- 参考 : LPIC-3 Exam 303 Content 332.2 ホストの侵入検知より抜粋
-
検証時利用環境
- ホストOS:Ubuntu 22.04.3
- VirtualBox:7.0.26r168464
- Vagrant:2.4.1
0. 環境の準備
0-1. VagrantFileの作成
作業用ディレクトリを作成する
mkdir rootkit-malware
cd rootkit-malware
VagrantFileを作成する ※学習環境として以下を定義
- OS:Ubuntu 22.04 LTS
- CPU:2コア
- メモリ:2GB
クリックで開く
# -*- mode: ruby -*-
# vi: set ft=ruby :
#
# LPIC 303 332.2 — ルートキット・マルウェア検出 学習環境
# カバートピック: chkrootkit, rkhunter, /etc/rkhunter.conf, maldet, conf.maldet, cron自動化
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/jammy64" # Ubuntu 22.04 LTS
config.vm.hostname = "rootkit-lab"
config.vm.network "private_network", ip: "192.168.56.11"
config.vm.provider "virtualbox" do |vb|
vb.name = "lpic303-332-2-rootkit-malware"
vb.memory = 2048
vb.cpus = 2
end
# -------------------------------------------------------
# プロビジョニング
# -------------------------------------------------------
config.vm.provision "shell", inline: <<-SHELL
set -eux
export DEBIAN_FRONTEND=noninteractive
echo "=== apt update ==="
apt-get update -y
# -------------------------------------------------------
# chkrootkit のインストール
# -------------------------------------------------------
echo "=== chkrootkit install ==="
apt-get install -y chkrootkit
# -------------------------------------------------------
# rkhunter のインストールと初期設定
# -------------------------------------------------------
echo "=== rkhunter install ==="
apt-get install -y rkhunter
# データベースの初期化(インターネット接続が必要)
rkhunter --update || echo "WARNING: rkhunter --update failed (network issue?)"
# プロパティデータベースの初期化
rkhunter --propupd || echo "WARNING: rkhunter --propupd failed"
# -------------------------------------------------------
# Linux Malware Detect (maldet) のインストール
# -------------------------------------------------------
echo "=== maldet install ==="
MALDET_VER="1.6.4"
MALDET_URL="https://www.rfxn.com/downloads/maldetect-current.tar.gz"
MALDET_TMP="/tmp/maldet"
mkdir -p "${MALDET_TMP}"
cd "${MALDET_TMP}"
if curl -fsSL --connect-timeout 30 --retry 3 -o maldetect-current.tar.gz "${MALDET_URL}"; then
tar xzf maldetect-current.tar.gz
cd maldetect-*/
bash install.sh
echo "INFO: maldet installed successfully"
else
echo "WARNING: maldet download failed. Trying GitHub fallback..."
# GitHub 経由のフォールバック
if curl -fsSL --connect-timeout 30 -o maldetect.tar.gz \
"https://github.com/rfxn/linux-malware-detect/archive/refs/heads/master.tar.gz"; then
tar xzf maldetect.tar.gz
cd linux-malware-detect-master/
bash install.sh
echo "INFO: maldet installed via GitHub"
else
echo "WARNING: maldet installation skipped (no network). Install manually: bash install.sh"
fi
fi
cd /tmp
rm -rf "${MALDET_TMP}"
# maldet シグネチャのアップデート(失敗してもスキップ)
maldet -u || echo "WARNING: maldet signature update failed"
# -------------------------------------------------------
# cron による自動スキャン設定
# -------------------------------------------------------
echo "=== cron scan setup ==="
# rkhunter 週次スキャン(日曜 2:00)
cat > /etc/cron.d/rkhunter-scan << 'EOF'
# rkhunter 週次スキャン(日曜 2:00)
0 2 * * 0 root /usr/bin/rkhunter --cronjob --update --quiet 2>&1 | /usr/bin/logger -t rkhunter
EOF
# chkrootkit 週次スキャン(日曜 3:00)
cat > /etc/cron.d/chkrootkit-scan << 'EOF'
# chkrootkit 週次スキャン(日曜 3:00)
0 3 * * 0 root /usr/sbin/chkrootkit 2>&1 | /usr/bin/logger -t chkrootkit
EOF
# -------------------------------------------------------
# 共通ユーティリティ
# -------------------------------------------------------
echo "=== utilities ==="
apt-get install -y \
curl wget git vim tree \
net-tools lsof less cron
systemctl enable cron
systemctl start cron
echo "=== provisioning done ==="
echo "chkrootkit: $(chkrootkit -V 2>&1 | head -1)"
echo "rkhunter: $(rkhunter --version 2>&1 | head -1)"
maldet -v 2>&1 | head -1 || echo "maldet: check /usr/local/maldetect/"
SHELL
end
0-2. VM の起動
vagrant up
初回は Ubuntu イメージのダウンロードとプロビジョニングが実行されます(5〜10分程度)。
0-3. VM へのログイン
vagrant ssh
0-4. root に昇格
sudo -i
1. chkrootkit
- 役割: ルートキットの痕跡をシステム上のバイナリや設定を検査して検出するツール
- 特徴: エージェント不要で定期的に
cronで実行するのが一般的 - 制限: シグネチャベースのみで、未知のルートキットは検出不可
- パッケージ:
chkrootkit - コマンド:
/usr/sbin/chkrootkit
1-1. インストール確認
chkrootkit -V
chkrootkit version 0.55
1-2. スキャン実行
- 全スキャンの実施
chkrootkit
Checking `amd'... not found
Checking `basename'... not infected
Checking `biff'... not found
Searching for Backdoor.Linux.Mokes.a ... nothing found
Searching for Malicious TinyDNS ... nothing found
Searching for Linux.Xor.DDoS ... INFECTED: Possible Malicious Linux.Xor.DDoS installed
/tmp/vagrant-shell
Checking `OSX_RSPLUG'... not tested
-
出力内容からわかること:
- not infected / nothing found: 典型的なrootkitによる改ざんがされていない
- not found : そのコマンドやサービスがインストールされていない
- INFECTED : 既知のrootkitによる改ざんがされている可能性がある(検証環境ではVagrantにより作成されたスクリプトが検知されている)
- not tested : chkrootkitがその項目をチェックできなかった
-
その他の使い方
# 特定のモジュールのみ実行
chkrootkit basename
ROOTDIR is `/'
Checking `basename'... not infected
# INFECTED状態のみを出力(quietモード)
chkrootkit -q
The following suspicious files and directories were found:
/usr/lib/modules/5.15.0-173-generic/vdso/.build-id
/usr/lib/ruby/gems/3.0.0/gems/minitest-5.14.2/.autotest
/usr/lib/ruby/gems/3.0.0/gems/power_assert-1.2.0/.travis.yml
/usr/lib/ruby/gems/3.0.0/gems/rbs-1.0.4/.rubocop.yml
/usr/lib/ruby/vendor_ruby/rubygems/optparse/.document
/usr/lib/ruby/vendor_ruby/rubygems/ssl_certs/.document
/usr/lib/ruby/vendor_ruby/rubygems/tsort/.document
INFECTED: Possible Malicious Linux.Xor.DDoS installed
/tmp/vagrant-shell
Output from ifpromisc:
enp0s3: PACKET SNIFFER(/usr/lib/systemd/systemd-networkd[1792])
enp0s8: PACKET SNIFFER(/usr/lib/systemd/systemd-networkd[1792])
# 特定ディレクトリを指定(外部メディアもスキャンできる)
chkrootkit -r /mnt/external
# cronでの定期実行例(chkrootkitのログをsyslogに出力)
cat /etc/cron.d/chkrootkit-scan
# chkrootkit 週次スキャン(日曜 3:00)
0 3 * * 0 root /usr/sbin/chkrootkit 2>&1 | /usr/bin/logger -t chkrootkit
2. rkhunter
- 役割: ルートキット・バックドア・ローカルエクスプロイトのスキャナー
- 特徴: ファイルハッシュデータベースを持ち、システムファイルの改ざんも検出できる
- 設定ファイル:
/etc/rkhunter.conf - データベース:
/var/lib/rkhunter/db/ - 定期実行:
cronまたは/etc/cron.d/rkhunter
2-1. インストール確認
rkhunter --version
Rootkit Hunter 1.4.6
2-2. データベースの更新
# データベースの確認
ls -l /var/lib/rkhunter/db/
total 92
-rw-r--r-- 1 root root 1055 Aug 22 2021 backdoorports.dat
drwxr-xr-x 2 root root 4096 May 2 09:11 i18n
-rw-r--r-- 1 root root 97 Aug 22 2021 mirrors.dat
-rw-r--r-- 1 root root 3605 Aug 22 2021 programs_bad.dat
-rw------- 1 root root 18072 May 2 09:11 rkhunter.dat
-rw------- 1 root root 18072 May 2 09:11 rkhunter.dat.old
-rw------- 1 root root 24600 May 2 09:11 rkhunter_prop_list.dat
drwxr-xr-x 2 root root 4096 May 2 09:11 signatures
-rw-r--r-- 1 root root 1904 Aug 22 2021 suspscan.dat
# 以下の項目をデフォルト設定から変更する
vi /etc/rkhunter.conf
UPDATE_MIRRORS=1 # ミラーサイトリストの更新を行う
MIRRORS_MODE=0 # リモートミラーサイトを利用する
PKGMGR=DPKG # Debian系パッケージの指定
WEB_CMD="" # rkhunter本体(/usr/bin/rkhunter)で設定されている取得方法(curl/wget等)を利用する
# 設定を確認して問題がないか検証(何も出力されなければOK)
rkhunter --config-check
# シグネチャデータベースの更新
rkhunter --update
[ Rootkit Hunter version 1.4.6 ]
Checking rkhunter data files...
Checking file mirrors.dat [ Updated ]
Checking file programs_bad.dat [ No update ]
Checking file backdoorports.dat [ No update ]
Checking file suspscan.dat [ No update ]
Checking file i18n/cn [ Skipped ]
Checking file i18n/de [ Skipped ]
Checking file i18n/en [ No update ]
Checking file i18n/tr [ Skipped ]
Checking file i18n/tr.utf8 [ Skipped ]
Checking file i18n/zh [ Skipped ]
Checking file i18n/zh.utf8 [ Skipped ]
Checking file i18n/ja [ Skipped ]
# 更新後のデータベース確認
ls -l /var/lib/rkhunter/db/
drwxr-xr-x 4 root root 4096 May 2 09:11 ./
drwxr-xr-x 4 root root 4096 May 2 09:11 ../
-rw-r--r-- 1 root root 1055 Aug 22 2021 backdoorports.dat
drwxr-xr-x 2 root root 4096 May 2 09:11 i18n/
-rw-r--r-- 1 root root 97 May 3 07:48 mirrors.dat # 更新されている
-rw-r--r-- 1 root root 3605 Aug 22 2021 programs_bad.dat
-rw------- 1 root root 18072 May 2 09:11 rkhunter.dat
-rw------- 1 root root 18072 May 2 09:11 rkhunter.dat.old
-rw------- 1 root root 24600 May 2 09:11 rkhunter_prop_list.dat
drwxr-xr-x 2 root root 4096 May 2 09:11 signatures/
-rw-r--r-- 1 root root 1904 Aug 22 2021 suspscan.dat
# システムファイルのプロパティデータベース更新(インストール直後・パッケージ更新後に実施)
rkhunter --propupd
File updated: searched for 180 files, found 142
注:
--propupdは信頼できる状態で実行する必要があります。マルウェアに感染した状態で実行すると、感染状態が「正常」として記録されます。
2-3. スキャン実行
# 検証用のrootkit名がついた空ファイルを作成
mkdir -p /dev/.lib
touch /dev/.lib/libproc.so
# 基本スキャン(確認プロンプトをスキップ)
rkhunter --check --sk
[ Rootkit Hunter version 1.4.6 ]
Checking system commands...
Performing 'strings' command checks
Checking 'strings' command [ OK ]
Performing 'shared libraries' checks
Checking for preloading variables [ None found ]
Checking for preloaded libraries [ None found ]
Checking LD_LIBRARY_PATH variable [ Not found ]
Performing file properties checks
Checking for prerequisites [ OK ]
/usr/sbin/adduser [ OK ]
/usr/sbin/chroot [ OK ]
/usr/sbin/cron [ OK ]
<中略>
Performing check of known rootkit files and directories
TBD (Telnet BackDoor) [ Not found ]
TeLeKiT Rootkit [ Not found ]
T0rn Rootkit [ Warning ]
<中略>
System checks summary
=====================
File properties checks...
Files checked: 142
Suspect files: 0
Rootkit checks...
Rootkits checked : 498
Possible rootkits: 1
Rootkit names : T0rn Rootkit
Applications checks...
All checks skipped
The system checks took: 46 seconds
All results have been written to the log file: /var/log/rkhunter.log
One or more warnings have been found while checking the system.
Please check the log file (/var/log/rkhunter.log)
# cron 向けに標準出力ではなくログに出力させる(--cronjob = --check --sk --nocolors)
rkhunter --cronjob
# ログファイルの確認
grep Warning /var/log/rkhunter.log
[08:18:30] Warning: T0rn Rootkit [ Warning ]
[08:18:47] Checking if SSH root access is allowed [ Warning ]
[08:18:47] Warning: The SSH configuration option 'PermitRootLogin' has not been set.
[08:18:48] Checking for hidden files and directories [ Warning ]
[08:18:48] Warning: Hidden directory found: /dev/.lib
# cronでの定期実行例(/var/log/rkhunter.logに結果を定期出力)
cat /etc/cron.d/rkhunter-scan
# rkhunter 週次スキャン(日曜 2:00)
0 2 * * 0 root /usr/bin/rkhunter --cronjob --update --quiet 2>&1
3. Linux Malware Detect (maldet / LMD)
- 役割: Linux 環境のマルウェア・ウイルスを検出する専用ツール
- 特徴: ClamAV シグネチャとの統合、メール通知、自動クォランティン機能
- インストール先:
/usr/local/maldetect/ - 設定ファイル:
/usr/local/maldetect/conf.maldet - コマンド:
maldetまたは/usr/local/sbin/maldet
3-1. インストール確認
# バージョン確認
maldet -v
Linux Malware Detect v1.6.6
(C) 2002-2023, R-fx Networks <proj@rfxn.com>
(C) 2023, Ryan MacDonald <ryan@rfxn.com>
This program may be freely redistributed under the terms of the GNU GPL v2
signature set: 2026041090472
usage maldet [-h|--help] [-a|--scan-all PATH] [-r|--scan-recent PATH DAYS]
[-f|--file-list PATH] [-i|--include-regex] [-x|--exclude-regex]
[-b|--background] [-m|--monitor] [-k|--kill-monitor] [-c|--checkout]
[-q|--quarantine] [-s|--restore] [-n|--clean] [-l|--log] [-e|--report]
[-u|--update-sigs] [-d|--update-ver]
3-2. conf.maldet の主要設定
cat /usr/local/maldetect/conf.maldet | grep -v "^#" | grep -v "^$"
| 設定項目 | 説明 | デフォルト |
|---|---|---|
email_alert |
アラートメール送信 | 0(無効) |
email_addr |
送信先メールアドレス | you@domain.com |
quarantine_hits |
検出時の自動クォランティン(隔離) | 0(無効) |
quarantine_clean |
クォランティン時にファイルを削除 | 0 |
scan_max_depth |
スキャンするディレクトリの最大深度 | 15 |
scan_clamscan |
ClamAV エンジン使用 | 1(有効) |
3-3. シグネチャの更新
# シグネチャの更新
maldet -u
Linux Malware Detect v1.6.6
(C) 2002-2023, R-fx Networks <proj@rfxn.com>
(C) 2023, Ryan MacDonald <ryan@rfxn.com>
This program may be freely redistributed under the terms of the GNU GPL v2
maldet(2316): {sigup} performing signature update check...
maldet(2316): {sigup} local signature set is version 2026041090472
maldet(2316): {sigup} latest signature set already installed
# 最新バージョンへの更新
maldet -d
Linux Malware Detect v1.6.6
(C) 2002-2023, R-fx Networks <proj@rfxn.com>
(C) 2023, Ryan MacDonald <ryan@rfxn.com>
This program may be freely redistributed under the terms of the GNU GPL v2
maldet(2399): {update} checking for available updates...
maldet(2399): {update} hashing install files and checking against server...
maldet(2399): {update} latest version already installed.
3-4. スキャン実行
# 特定ディレクトリをスキャン
maldet -a /home
Linux Malware Detect v1.6.6
(C) 2002-2023, R-fx Networks <proj@rfxn.com>
(C) 2023, Ryan MacDonald <ryan@rfxn.com>
This program may be freely redistributed under the terms of the GNU GPL v2
maldet(2679): {scan} signatures loaded: 51459 (45385 MD5 | 2368 HEX | 3706 YARA | 0 USER)
maldet(2679): {scan} building file list for /home, this might take awhile...
maldet(2679): {scan} setting nice scheduler priorities for all operations: cpunice 19 , ionice 6
maldet(2679): {scan} file list completed in 0s, found 7 files... # スキャン対象のファイルが7つ存在
maldet(2679): {scan} scan of /home (7 files) in progress...
maldet(2679): {scan} 7/7 files scanned: 0 hits 0 cleaned # マルウェアや駆除対象なし
maldet(2679): {scan} scan completed on /home: files 7, malware hits 0, cleaned hits 0, time 0s
maldet(2679): {scan} scan report saved, to view run: maldet --report 260503-1538.2679
# 最新のスキャンレポートを表示
maldet -e list
Linux Malware Detect v1.6.6
(C) 2002-2023, R-fx Networks <proj@rfxn.com>
(C) 2023, Ryan MacDonald <ryan@rfxn.com>
This program may be freely redistributed under the terms of the GNU GPL v2
# /homeのスキャン結果が表示されている
May 3 2026 15:38:01 | SCANID: 260503-1538.2679 | RUNTIME: 0s | FILES: 7 | HITS: 0 | CLEANED: 0
# ログを表示
maldet -l
Linux Malware Detect v1.6.6
(C) 2002-2023, R-fx Networks <proj@rfxn.com>
(C) 2023, Ryan MacDonald <ryan@rfxn.com>
This program may be freely redistributed under the terms of the GNU GPL v2
Viewing last 50 lines from /usr/local/maldetect/logs/event_log:
May 02 2026 09:12:01 rootkit-lab maldet(32314): {sigup} unpacked and installed maldet-sigpack.tgz
May 02 2026 09:12:01 rootkit-lab maldet(32314): {sigup} verified md5sum of maldet-clean.tgz
May 02 2026 09:12:01 rootkit-lab maldet(32314): {sigup} unpacked and installed maldet-clean.tgz
May 02 2026 09:12:01 rootkit-lab maldet(32314): {sigup} signature set update completed
May 02 2026 09:12:01 rootkit-lab maldet(32314): {sigup} 51459 signatures (45385 MD5 | 2368 HEX | 3706 YARA | 0 USER)
May 02 2026 09:12:01 rootkit-lab maldet(32507): {sigup} performing signature update check...
May 02 2026 09:12:01 rootkit-lab maldet(32507): {sigup} local signature set is version 2026041090472
May 02 2026 09:12:02 rootkit-lab maldet(32507): {sigup} downloaded https://cdn.rfxn.com/downloads/maldet.sigs.ver
May 02 2026 09:12:02 rootkit-lab maldet(32507): {sigup} latest signature set already installed
May 03 2026 06:33:39 rootkit-lab maldet(51543): {update} checking for available updates...
May 03 2026 06:33:40 rootkit-lab maldet(51543): {update} downloaded https://cdn.rfxn.com/downloads/maldet.current.ver
May 03 2026 06:33:40 rootkit-lab maldet(51543): {update} hashing install files and checking against server...
May 03 2026 06:33:40 rootkit-lab maldet(51543): {update} downloaded https://cdn.rfxn.com/downloads/maldet.current.hash
May 03 2026 06:33:40 rootkit-lab maldet(51543): {update} latest version already installed.
4. まとめ・比較表
| ツール | 検出対象 | シグネチャ更新 | 設定ファイル | 定期実行 |
|---|---|---|---|---|
chkrootkit |
ルートキット | コードに内包 | なし | cron |
rkhunter |
ルートキット・バックドア | --update |
/etc/rkhunter.conf |
--cronjob |
maldet |
マルウェア全般 | maldet -u |
/usr/local/maldetect/conf.maldet |
cron / デーモン |
後片付け
# VM のシャットダウン
vagrant halt
# VM の完全削除
vagrant destroy -f
付録: よく使うコマンドまとめ
# ===== chkrootkit =====
chkrootkit # 全チェック実行
chkrootkit -q # クワイエットモード
chkrootkit -V # バージョン確認
chkrootkit -l # 利用可能なテスト一覧
# ===== rkhunter =====
rkhunter --version # バージョン確認
rkhunter --update # シグネチャ DB 更新
rkhunter --propupd # ファイルプロパティ DB 更新
rkhunter --check --sk # スキャン実行(確認プロンプトスキップ)
rkhunter --check --sk -q # クワイエットモード
rkhunter --cronjob # cron 用スキャン
rkhunter --config-check # 設定ファイルの検証
cat /var/log/rkhunter.log # ログ確認
# ===== maldet =====
maldet -v # バージョン確認
maldet -u # シグネチャ更新
maldet -d # エンジン更新
maldet -a /path # 指定パスをスキャン
maldet -l # ログの表示
cat /usr/local/maldetect/conf.maldet # 設定ファイル確認