Ubuntu 22.04 rkhunter 与 chkrootkit Rootkit 检测详解

Ubuntu 22.04 系统 rkhunter 与 chkrootkit Rootkit 检测工具的安装(在线 apt 与离线 deb)与各命令参数实测详解,含配置、属性基线、扫描结果解读与误报处理

Linux 安全与审计rkhunterchkrootkit安全加固Ubuntu 22.04安全审计2026/10/06

Ubuntu 22.04 rkhunter 与 chkrootkit Rootkit 检测详解

目标:在 Ubuntu 22.04 上完成 rkhunter 与 chkrootkit 的安装、配置、属性基线建立、完整扫描与误报处理,全部命令与输出已在 Ubuntu 22.04 真实环境实测通过。

一、环境信息

本文所有命令与输出均在以下环境实测:

项目实测值
操作系统Ubuntu 22.04.5 LTS(Jammy Jellyfish)
内核版本(uname -r 实测)6.8.0-138-generic
架构x86_64
rkhunter 版本1.4.6(deb 包 rkhunter 1.4.6-10,来自 jammy/universe 仓库)
chkrootkit 版本0.55(deb 包 chkrootkit 0.55-4,来自 jammy/universe 仓库)
rkhunter 配置文件/etc/rkhunter.conf
rkhunter 自动化配置/etc/default/rkhunter(Ubuntu 特有,控制每日 cron 行为)
rkhunter 日志/var/log/rkhunter.log(Ubuntu 包默认路径)
rkhunter 数据库目录/var/lib/rkhunter/db/(含 backdoorports.dat、programs_bad.dat、suspscan.dat、rkhunter.dat、rkhunter_prop_list.dat、mirrors.dat、signatures/、i18n/)
rkhunter 属性基线文件/var/lib/rkhunter/db/rkhunter_prop_list.dat
chkrootkit 可执行文件/usr/sbin/chkrootkit(deb 包自带辅助二进制)
chkrootkit 日志集成/var/log/chkrootkit/ 目录(log.today、log.today.raw、log.expected),由 /etc/cron.daily/chkrootkit 维护
chkrootkit 配置/etc/chkrootkit/chkrootkit.conf(仅控制 cron 任务,非扫描行为)
包管理器apt / dpkg

补充说明:

  • 安装 rkhunter 时 apt 会同时安装 43 个依赖包(实测列表见 3.1 节),其中 postfix(本地邮件发送)、unhide/unhide.rb(进程隐藏检测)、lsof、net-tools、binutils、file 等对安全检测工具链有实际作用。
  • 属性基线在安装时由包配置脚本自动建立一次(File created: searched for 179 files, found 121),补测阶段重建为 File updated: searched for 179 files, found 124,最终基线收录 124 个文件。
  • Ubuntu 的 rkhunter 包默认配置 WEB_CMD="/bin/false"(禁用在线更新),导致 rkhunter --update 与 --config-check 报 Invalid WEB_CMD configuration option: Relative pathname: "/bin/false",这是 Ubuntu 包与 CentOS 包的最大差异,本文 6.1.6 节与 FAQ 10.1 节详述处理办法。

二、工具概述

2.1 Rootkit 是什么

Rootkit(根工具包)是攻击者在获得系统权限后安装的一组恶意软件,用于:

  • 隐藏自身进程、文件、网络连接与内核模块,使管理员难以发现入侵;
  • 替换或挂钩系统关键命令(ls、ps、netstat、sshd 等),返回伪造的正常结果;
  • 维持持久化后门,供攻击者随时重新进入系统。

根据攻击层次可分为用户态 rootkit(替换二进制、预加载恶意动态库)与内核态 rootkit(LKM 恶意内核模块)两类。

2.2 rkhunter 工作原理

rkhunter(Rootkit Hunter)1.4.6 是一套基于 Shell 脚本的检测框架,主要依赖三类机制:

  1. 文件属性基线比对:执行 rkhunter --propupd 将系统命令/关键文件的哈希值(默认 SHA256)、权限、属主、属组、大小、修改时间、inode、硬链接数等快照存入 /var/lib/rkhunter/db/rkhunter_prop_list.dat。此后每次 --check 重新采集并逐项比对,任何变化(如 /usr/bin/df 被替换)都会产生 [ Warning ] 并给出「当前值 vs 基线存储值」的明细。这是 rkhunter 最核心的检测手段。
  2. 已知 rootkit 签名库检测:/var/lib/rkhunter/db/rkhunter.dat(实测 130 行)维护了历史上出现过的 rootkit 特征文件名/目录/字符串;programs_bad.dat 收录已知恶意程序名;suspscan.dat 收录可疑扫描特征。--check 时逐个比对,实测本次检查了 491 个 rootkit 签名。
  3. 系统命令 / 内核模块 / 后门检测:包括 strings 命令替换检查、动态库预加载变量(LD_PRELOAD/LD_LIBRARY_PATH)检查、隐藏目录/隐藏进程检查、网络后门端口检查(backdoorports.dat)、网卡混杂模式检查、SSH 配置检查、passwd/group 文件变化检查等。

rkhunter 一次完整 --check 实测耗时 2 分 27 秒,退出码非 0 表示发现警告,扫描结果同时写入 /var/log/rkhunter.log。

2.3 chkrootkit 工作原理

chkrootkit 0.55 是一组 C 程序与 Shell 脚本的集合,核心原理是字符串签名扫描:

  • 对系统命令(ps、ls、login、sshd 等 60 余个)执行 strings 提取可打印字符串,与已知 rootkit 的二进制特征字符串比对,输出 not infected / infected;
  • 通过 chkproc(比对 /proc 进程目录与 ps 输出)、chkdirs(隐藏目录)、chkwtmp/chklastlog/chkutmp(日志删除痕迹)、ifpromisc(网卡混杂模式/PF_PACKET socket)等辅助程序做行为检测;
  • 对 aliens(可疑隐藏文件)、sniffer(抓包进程)、lkm(内核模块篡改)等做启发式检查。

chkrootkit 无扫描配置文件、无签名库更新机制,每次运行现场扫描,依赖系统自带命令(ps、grep、sed、awk、netstat、strings 等)工作。deb 包安装时自带全部辅助二进制,无需编译。

2.4 两者互补关系

维度rkhunterchkrootkit
检测机制属性基线比对 + 签名库 + 行为检查字符串签名扫描 + 行为检查
需要预先建基线是(--propupd)否,即扫即检
签名更新--update 在线更新(Ubuntu 默认被 WEB_CMD 禁用,需修复)需升级新版本
扫描耗时(实测)约 2.5 分钟约 1 分钟以内
误报处理ALLOWHIDDENDIR/ALLOWHIDDENFILE 白名单无扫描配置,需人工研判
自动化/etc/cron.daily/rkhunter + /etc/default/rkhunter/etc/cron.daily/chkrootkit(默认已启用)

结论:两者检测视角不同、误报互补,生产环境建议同时部署,rkhunter 负责每日基线比对,chkrootkit 负责快速签名扫描,任何一方告警都需人工复核。

三、在线安装方案

3.1 rkhunter 安装(apt)

rkhunter 位于 universe 仓库,直接安装:

DEBIAN_FRONTEND=noninteractive apt-get install -y rkhunter

实测回显(关键部分):

Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
  binutils binutils-common binutils-x86-64-linux-gnu bsd-mailx cpio file
  fonts-lato iproute2 javascript-common libatm1 libbinutils libbpf0
  libcap2-bin libctf-nobfd0 libctf0 libedit2 libelf1 libjs-jquery
  liblockfile-bin liblockfile1 libmagic-mgc libmagic1 libpam-cap libruby3.0
  libyaml-0-2 lsof net-tools postfix rake ruby ruby-net-telnet ruby-rubygems
  ruby-webrick ruby-xmlrpc ruby3.0 rubygems-integration ssl-cert unhide
  unhide.rb unzip wget zip
Suggested packages:
  binutils-doc libarchive1 iproute2-doc apache2 | lighttpd | httpd procmail
  postfix-mysql postfix-pgsql postfix-ldap postfix-pcre postfix-lmdb
  postfix-sqlite sasl2-bin | dovecot-common resolvconf postfix-cdb
  postfix-mta-sts-resolver postfix-doc powermgmt-base ri ruby-dev bundler
The following NEW packages will be installed:
  binutils binutils-common binutils-x86-64-linux-gnu bsd-mailx cpio file
  fonts-lato iproute2 javascript-common libatm1 libbinutils libbpf0
  libcap2-bin libctf-nobfd0 libctf0 libedit2 libelf1 libjs-jquery
  liblockfile-bin liblockfile1 libmagic-mgc libmagic1 libpam-cap libruby3.0
  libyaml-0-2 lsof net-tools postfix rake rkhunter ruby ruby-net-telnet
  ruby-rubygems ruby-webrick ruby-xmlrpc ruby3.0 rubygems-integration ssl-cert
  unhide unhide.rb unzip wget zip
0 upgraded, 43 newly installed, 0 to remove and 9 not upgraded.
Need to get 16.7 MB of archives.
After this operation, 73.6 MB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu jammy/main amd64 fonts-lato all 2.0-2.1 [2696 kB]
Get:2 http://archive.ubuntu.com/ubuntu jammy/main amd64 ssl-cert all 1.1.2 [17.4 kB]
...
Get:16 http://archive.ubuntu.com/ubuntu jammy/universe amd64 rkhunter all 1.4.6-10 [220 kB]
...
Get:42 http://archive.ubuntu.com/ubuntu jammy/universe amd64 unhide amd64 20130526-4ubuntu1 [47.7 kB]
Get:43 http://archive.ubuntu.com/ubuntu jammy/universe amd64 unhide.rb all 22-6 [8942 B]
debconf: delaying package configuration, since apt-utils is not installed
Fetched 16.7 MB in 4s (3961 kB/s)

关键安装过程回显(rkhunter 配置脚本自动建立基线):

Setting up rkhunter (1.4.6-10) ...

Creating config file /etc/default/rkhunter with new version
[ Rootkit Hunter version 1.4.6 ]
File created: searched for 179 files, found 121
...
Processing triggers for rkhunter (1.4.6-10) ...
[ Rootkit Hunter version 1.4.6 ]
File updated: searched for 179 files, found 121

同时 postfix 被安装并配置为本地 MTA(实测回显节选):

Setting up postfix (3.6.4-1ubuntu1.4) ...
Adding group `postfix' (GID 109) ...
Adding system user `postfix' (UID 106) ...
setting myhostname: b3d88cde7ef0.localdomain
...
Created symlink /etc/systemd/system/multi-user.target.wants/postfix.service → /lib/systemd/system/postfix.service.

验证安装:

rkhunter --version

实测回显:

Rootkit Hunter 1.4.6

This software was developed by the Rootkit Hunter project team.
Please review your rkhunter configuration files before using.
Please review the documentation before posting bug reports or questions.
To report bugs, provide patches or comments, please go to:
http://rkhunter.sourceforge.net

To ask questions about rkhunter, please use the rkhunter-users mailing list.
Note this is a moderated list: please subscribe before posting.

Rootkit Hunter comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it under the
terms of the GNU General Public License. See the LICENSE file for details.

3.2 chkrootkit 安装(apt)

chkrootkit 同样位于 universe 仓库:

DEBIAN_FRONTEND=noninteractive apt-get install -y chkrootkit

实测回显:

Reading package lists...
Building dependency tree...
Reading state information...
The following NEW packages will be installed:
  chkrootkit
0 upgraded, 1 newly installed, 0 to remove and 9 not upgraded.
Need to get 352 kB of archives.
After this operation, 1079 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu jammy/universe amd64 chkrootkit amd64 0.55-4 [352 kB]
debconf: delaying package configuration, since apt-utils is not installed
Fetched 352 kB in 2s (143 kB/s)
Selecting previously unselected package chkrootkit.
(Reading database ... 36755 files and directories currently installed.)
Preparing to unpack .../chkrootkit_0.55-4_amd64.deb ...
Unpacking chkrootkit (0.55-4) ...
Setting up chkrootkit (0.55-4) ...

验证:

chkrootkit -V

实测回显:

chkrootkit version 0.55

deb 包会将 chkrootkit 脚本与全部辅助二进制(strings-static、ifpromisc、chkproc、chkdirs、chkwtmp、chklastlog、chkutmp、check_wtmpx)安装到 /usr/sbin/,可直接从任意目录运行,不存在源码编译版的相对路径问题。

四、离线安装方案(内网环境)

以下方案针对无法访问外网的内网生产环境,未在本次实测环境执行,标注预期行为,请以实际环境为准。

4.1 在线机器下载 deb 包

在能联网的同版本 Ubuntu 22.04 机器上下载(只下载不安装):

cd /tmp && apt-get download rkhunter chkrootkit

如需连带依赖包一起离线(rkhunter 依赖较多,建议用 apt 的模拟安装列出依赖后逐个下载,或使用 apt-rdepends):

apt-cache depends rkhunter

4.2 内网机器离线安装

将下载的 deb 拷贝到内网目标机后:

dpkg -i ./rkhunter_1.4.6-10_all.deb ./chkrootkit_0.55-4_amd64.deb
apt-get install -f

⚠️ 预期行为:dpkg -i 只安装指定包,若缺少依赖会报 dependency problems,随后 apt-get install -f 尝试从本地缓存/已配置内网源补齐依赖;rkhunter 的依赖(postfix、unhide、binutils 等 43 个)在内网环境中需一并准备。最稳妥的方式是使用 apt-get download $(apt-rdepends rkhunter | grep -v '^ ') 之类方式批量下载全部依赖后整体离线安装。

五、配置详解

5.1 /etc/rkhunter.conf 关键配置项(Ubuntu 实测)

配置文件关键行实测值:

行号配置项实测值含义
107UPDATE_MIRRORS0不自动轮换镜像更新(Ubuntu 默认关闭)
355ENABLE_TESTSALL启用全部测试
356DISABLE_TESTSsuspscan hidden_ports hidden_procs deleted_files packet_cap_apps apps禁用 6 组测试
1190WEB_CMD"/bin/false"下载命令被设为 /bin/false(Ubuntu 包刻意禁用在线更新,但写法是相对路径,导致 --update/--config-check 报错)
323ALLOW_SSH_PROT_V12SSH 协议 v1 检查的放行级别

Ubuntu 包未在配置中显式写 LOG_FILE(使用默认 /var/log/rkhunter.log)与 REPORT_EMAIL(默认通过 /etc/default/rkhunter 的 REPORT_EMAIL 控制)。

5.2 WEB_CMD 问题详解

实测执行:

rkhunter --config-check

回显:

Invalid WEB_CMD configuration option: Relative pathname: "/bin/false"

原因:rkhunter 要求 WEB_CMD 必须是绝对路径的命令(可带参数),而 Ubuntu 包写的是 WEB_CMD="/bin/false"。这里的意图是禁用 rkhunter 在线下载功能(/bin/false 永远返回非 0),但 --config-check 会校验该值合法性。修复方案(任选其一):

方案一:改回绝对路径(保留禁用在线更新的意图):

sed -i 's|^WEB_CMD="/bin/false"|WEB_CMD="/bin/false --noop"|' /etc/rkhunter.conf

注意:/bin/false 本身不接受 --noop 参数,此方案不可行;正确做法见方案三。

方案二:改为 wget,恢复在线更新能力:

sed -i 's|^WEB_CMD="/bin/false"|WEB_CMD=wget|' /etc/rkhunter.conf

方案三:注释该行(rkhunter 内部默认使用 wget):

sed -i 's|^WEB_CMD="/bin/false"|#WEB_CMD=|' /etc/rkhunter.conf

修改后验证:

rkhunter --config-check && echo OK

⚠️ 说明:本文 6.1.6 节实测的 rkhunter --update 报错即为方案未修改前的状态(Invalid WEB_CMD configuration option: Relative pathname: "/bin/false",退出码 1),如实记录。

5.3 /etc/default/rkhunter(Ubuntu 特有自动扫描配置)

Ubuntu 通过 /etc/default/rkhunter 控制每日自动任务,实测完整内容:

# Defaults for rkhunter automatic tasks
# sourced by /etc/cron.*/rkhunter and /etc/apt/apt.conf.d/90rkhunter
#
# This is a POSIX shell fragment
#

# Set this to yes to enable rkhunter daily runs
# (default: false)
CRON_DAILY_RUN=""

# Set this to yes to enable rkhunter weekly database updates
# (default: false)
CRON_DB_UPDATE=""

# Set this to yes to enable reports of weekly database updates
# (default: false)
DB_UPDATE_EMAIL="false"

# Set this to the email address where reports and run output should be sent
# (default: root)
REPORT_EMAIL="root"

# Set this to yes to enable automatic database updates
# (default: false)
APT_AUTOGEN="false"

# Nicenesses range from -20 (most favorable scheduling) to 19 (least favorable)
# (default: 0)
NICE="0"

# Should daily check be run when running on battery
# powermgmt-base is required to detect if running on battery or on AC power
# (default: false)
RUN_CHECK_ON_BATTERY="false"

关键项说明:

配置项默认值作用
CRON_DAILY_RUN空(false)设为 yes 启用每日自动扫描
CRON_DB_UPDATE空(false)设为 yes 启用每周自动更新签名库
DB_UPDATE_EMAILfalse每周更新结果是否发邮件
REPORT_EMAILroot扫描报告收件人
APT_AUTOGENfalseapt 更新系统包后是否自动重跑 --propupd
NICE0扫描进程优先级(nice 值)
RUN_CHECK_ON_BATTERYfalse笔记本电池供电时是否仍执行

启用每日扫描并指定收件人:

sed -i 's/^CRON_DAILY_RUN=""/CRON_DAILY_RUN="yes"/' /etc/default/rkhunter
sed -i 's/^REPORT_EMAIL="root"/REPORT_EMAIL="security@example.com"/' /etc/default/rkhunter

5.4 chkrootkit 配置机制

chkrootkit 0.55 没有扫描配置文件,所有检测行为由脚本内嵌逻辑决定。Ubuntu 额外提供的 /etc/chkrootkit/chkrootkit.conf 只控制每日 cron 任务(是否运行、输出过滤、diff 模式等),实测关键内容:

### This file is used to configure the daily cron job for chkrootkit(1)
## It is sourced by /etc/cron.daily/chkrootkit so needs to be a valid
## shell script.
##
## The majority of the options allow the output of chkrootkit to be
## filtered (changed) and/or ignored to hide false positives.

## Whether the daily cron job should run chkrootkit at all
# true/false, default: true
RUN_DAILY="true"

## Arguments to pass to chkrootkit (default: "").
# See chkrootkit(1) for details, but particularly useful are
#  "-q" (especially useful if you set DIFF_MODE=false above )
#  "-e" and "-s" (which are yet another way to hide output)
# The default is to pass no arguments so you see all output: this is
# particularly useful with DIFF_MODE=true as it gives context when the
# output changes, but DIFF_MODE hides the text that does not change
RUN_DAILY_OPTS=""

## Whether to show changes since last run (true/false, default: true)
# true means you will see how the entire differs (using diff(1)) to
# the 'expected' output in /var/log/chkrootkit/log.expected
# if that file does not exist you will see the whole output.
#
# If set to false you see the whole output every day - if you do set
# DIFF_MODE to "false" you probably also want RUN_DAILY_OPTS="-q"
#
DIFF_MODE="true"

### The results of chkrootkit are passed through $FILTER and $IGNORE_FILE

## FILTER is a way of changing output to make it stable or hide it
## completely (especially useful when DIFF_MODE=true
#
# FILTER can be any shell command which will be piped unfiltered output
# on stdin and anything written to stdout will become the new,
# filtered, output.
#
# The default uses sed to do two things
# 1) stops message (from ifpromisc, run by the 'sniffer' test) about
#     'usual' network managers changing if their pid, interface name,
#     or order changes
# 2) stops list of processes not using utmp (from chkutmp) changing if
#     their pid changes
# To disable both of these defaults you can set this to "" or "cat"
FILTER="sed -re 's![[:alnum:]]+: PACKET SNIFFER\(((/lib/systemd/systemd-networkd|(/usr)?/sbin/(dhclient|dhcpc?d[0-9]*|wpa_supplicant|NetworkManager))\[[0-9]+\](, )?)+\)!<interface>: PACKET SNIFFER\([systemd-networkd|dhclient|dhcpd|dhcpcd|wpa_supplicant|NetworkManager]{PID}\)!' -e 's/(! [[:alnum:]+-]+)\s+[0-9]+/\1 {PID}/'"

## If $IGNORE_FILE exists then lines of output matching patterns that
## appear in $IGNORE_FILE are removed from the output. Each line in
## $IGNORE_FILE interpreted as an extended regexp, see egrep(1). If
## $IGNORE_FILE is empty (the default) or does not exist then no
## filtering is done.
#
# This is done after $FILTER - you can use either or both. IGNORE_FILE
# is slightly simpler but slightly less powerfull than FILTER as you
# can only hide, not change output.
#
# The default is /etc/chkrootkit/chkrootkit.ignore (which is empty by
# default, meaning nothing is ignored)
IGNORE_FILE="/etc/chkrootkit/chkrootkit.ignore"

### The remaining options are commented out as the defaults are likely
### to be fine for most users, but you can edit these as well:

## The chkrootkit(1) scanner that is run
# what is actually run is: eval "$IONICE" "$CHKROOTKIT" "$RUN_DAILY_OPTS"
#CHKROOTKIT=/usr/sbin/chkrootkit

## Where output is saved
#LOG_DIR=/var/log/chkrootkit

## 'Clean' output (after FILTER and IGNORE_FILE)
#OUTPUT="$LOG_DIR/log.today"

## 'Raw' output is saved here
#RAW_OUTPUT="$OUTPUT.raw"

## 'Expected' output (only used if DIFF_MODE=true)
#EXPECTED_OUTPUT="$LOG_DIR/log.expected"

## The default is to run using ionice if possible.
## If you do not want to use ionice at all, set IONICE="" instead
#if [ -x /usr/bin/ionice ] && /usr/bin/ionice -c3 true 2>/dev/null; then
#               IONICE="/usr/bin/ionice -c3"
#else
#               IONICE=""
#fi

要点:RUN_DAILY 默认 "true",即 Ubuntu 安装 chkrootkit 后每日 cron 已默认执行;DIFF_MODE=true 时每日输出与 /var/log/chkrootkit/log.expected 做 diff,仅在结果变化时向管理员暴露差异(通过 cron 的 MAILTO 发出)。

5.5 推荐的生产配置片段

在 /etc/rkhunter.conf 末尾追加或修改:

# 修复 Ubuntu 默认 WEB_CMD 导致的更新报错
WEB_CMD=wget
UPDATE_MIRRORS=1

# 日志与邮件
LOG_FILE=/var/log/rkhunter.log
REPORT_EMAIL=security@example.com
MAIL_CMD=mail -s "[rkhunter] Warnings found for ${HOST_NAME}"
COPY_LOG_ON_ERROR=y
DELETE_OLD_LOGS=y

# 白名单(按需追加业务目录)
ALLOWHIDDENDIR=/data/.app
ALLOWHIDDENFILE=/data/.app/config

# 日志轮转
MAX_LOG_AGE=7

说明:上述为推荐配置示例,除已实测确认的项外,请结合 rkhunter 官方文档核对各选项在当前版本的行为。

六、命令详解

6.1 rkhunter 命令

6.1.1 rkhunter --version

用途:显示版本号。

rkhunter --version

实测回显见 3.1 节,首行 Rootkit Hunter 1.4.6。

6.1.2 rkhunter --help

用途:显示完整用法与参数表。

rkhunter --help

实测回显(关键参数,与 CentOS 包一致,完整输出见 sec-notes):

Usage: rkhunter {--check | --unlock | --update | --versioncheck |
                 --propupd [{filename | directory | package name},...] |
                 --list [{tests | {lang | languages} | rootkits | perl | propfiles}] |
                 --config-check | --version | --help} [options]

Current options are:
         --append-log                  Append to the logfile, do not overwrite
         --bindir <directory>...       Use the specified command directories
     -c, --check                       Check the local system
     -C, --config-check                Check the configuration file(s), then exit
  --cs2, --color-set2                  Use the second color set for output
         --configfile <file>           Use the specified configuration file
         --cronjob                     Run as a cron job
                                       (implies -c, --sk and --nocolors options)
         --dbdir <directory>           Use the specified database directory
         --debug                       Debug mode
         --disable <test>[,<test>...]  Disable specific tests
         --enable  <test>[,<test>...]  Enable specific tests
         --hash {MD5 | SHA1 | SHA224 | SHA256 | SHA384 | SHA512 |
                 NONE | <command>}     Use the specified file hash function
                                       (Default is SHA256)
     -h, --help                        Display this help menu, then exit
 --lang, --language <language>         Specify the language to use
         --list [tests | languages |   List the available test names, languages,
                 rootkits | perl |     rootkit names, perl module status
                 propfiles]            or file properties database, then exit
     -l, --logfile [file]              Write to a logfile
                                       (Default is /var/log/rkhunter.log)
         --nocolors                    Use black and white output
         --nolog                       Do not write to a logfile
--nomow, --no-mail-on-warning          Do not send a message if warnings occur
   --ns, --nosummary                   Do not show the summary of check results
 --novl, --no-verbose-logging          No verbose logging
         --pkgmgr {RPM | DPKG | BSD |  Use the specified package manager to obtain
                   BSDng | SOLARIS |   or verify file property values.
                   NONE}               (Default is NONE)
         --propupd [file | directory | Update the entire file properties database,
                    package]...        or just for the specified entries
     -q, --quiet                       Quiet mode (no output at all)
  --rwo, --report-warnings-only        Show only warning messages
   --sk, --skip-keypress               Don't wait for a keypress after each test
         --summary                     Show the summary of system check results
         --syslog [facility.priority]  Log the check start and finish times to syslog
         --tmpdir <directory>          Use the specified temporary directory
         --unlock                      Unlock (remove) the lock file
         --update                      Check for updates to database files
   --vl, --verbose-logging             Use verbose logging (on by default)
     -V, --version                     Display the version number, then exit
         --versioncheck                Check for latest version of program

参数速查表:

参数说明
-c / --check执行系统全面检查
--sk / --skip-keypress每个检查段之间不等待按键
--nocolors黑白输出
--rwo / --report-warnings-only只输出警告信息
--cronjob定时任务模式(等价于 -c --sk --nocolors)
--propupd [文件/目录/包]更新属性基线数据库
--update在线更新 rootkit 签名数据库(Ubuntu 默认被 WEB_CMD 挡住,需先修复配置)
--versioncheck检查 rkhunter 程序自身版本
--list tests/languages/...列出测试名/语言/rootkit 名等
--enable/--disable <tests>启用/禁用指定测试
--lang <language>指定输出语言
--hash MD5/SHA1/...指定文件哈希算法(默认 SHA256)
--pkgmgr RPM/DPKG/NONE指定包管理器验证文件属性(Ubuntu 包默认 NONE)
-C / --config-check检查配置文件语法
--configfile <file>使用指定配置文件
--logfile <file>指定日志文件
--syslog [facility.priority]检查起止时间写入 syslog
--unlock删除锁文件
-q / --quiet安静模式
-V / --version版本

6.1.3 rkhunter --check

用途:执行完整系统检查,是日常扫描的主命令。

rkhunter --check

实测开头输出(真实回显,含 ANSI 颜色码):

[ 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 ]
    /usr/sbin/fsck                                           [ OK ]
    /usr/sbin/groupadd                                       [ OK ]
    /usr/sbin/groupdel                                       [ OK ]
    /usr/sbin/groupmod                                       [ OK ]
    /usr/sbin/grpck                                          [ OK ]
    /usr/sbin/ifconfig                                       [ OK ]
    /usr/sbin/init                                           [ OK ]
    /usr/sbin/ip                                             [ OK ]
    /usr/sbin/nologin                                        [ OK ]
    /usr/sbin/pwck                                           [ OK ]
    /usr/sbin/route                                          [ OK ]
    /usr/sbin/rsyslogd                                       [ Warning ]
    /usr/sbin/runlevel                                       [ OK ]
    /usr/sbin/sshd                                           [ Warning ]
    /usr/sbin/sulogin                                        [ OK ]
    /usr/sbin/sysctl                                         [ OK ]
    /usr/sbin/useradd                                        [ OK ]
    /usr/sbin/userdel                                        [ OK ]
    /usr/sbin/usermod                                        [ OK ]
    /usr/sbin/vipw                                           [ OK ]
    /usr/sbin/unhide                                         [ OK ]
    /usr/sbin/unhide-linux                                   [ OK ]
    /usr/sbin/unhide-posix                                   [ OK ]

实测结尾输出(完整运行 2 分 27 秒):

    Checking for group file changes                          [ Warning ]
    Checking root account shell history files                [ None found ]

  Performing system configuration file checks
    Checking for an SSH configuration file                   [ Found ]
    Checking if SSH root access is allowed                   [ Warning ]
    Checking if SSH protocol v1 is allowed                   [ Not set ]
    Checking for other suspicious configuration settings     [ None found ]
    Checking for a running system logging daemon             [ Found ]
    Checking for a system logging configuration file         [ Found ]
    Checking if syslog remote logging is allowed             [ Not allowed ]

  Performing filesystem checks
    Checking /dev for suspicious file types                  [ None found ]
    Checking for hidden files and directories                [ None found ]

[Press <ENTER> to continue]


System checks summary
=====================

File properties checks...
    Files checked: 124
    Suspect files: 4

Rootkit checks...
    Rootkits checked : 491
    Possible rootkits: 0

Applications checks...
    All checks skipped

The system checks took: 2 minutes and 27 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)

Summary 各字段解读:

字段含义本次实测值
Files checked本次比对的属性基线文件数124
Suspect files属性发生变化/可疑的文件数4
Rootkits checked已检查的 rootkit 签名数491
Possible rootkits疑似 rootkit 数(0 为干净)0
Applications checked应用检查(被 DISABLE_TESTS=apps 禁用,显示 All checks skipped)All checks skipped
The system checks took总耗时2 分 27 秒

本次检查的警告明细(/var/log/rkhunter.log 中 grep -n "Warning" 实测):

[14:31:59]   /usr/sbin/rsyslogd                              [ Warning ]
[14:31:59] Warning: The file '/usr/sbin/rsyslogd' exists on the system, but it is not present in the 'rkhunter.dat' file.
[14:32:00]   /usr/sbin/sshd                                  [ Warning ]
[14:32:00] Warning: The file '/usr/sbin/sshd' exists on the system, but it is not present in the 'rkhunter.dat' file.
[14:32:19]   /usr/bin/ssh                                    [ Warning ]
[14:32:19] Warning: The file '/usr/bin/ssh' exists on the system, but it is not present in the 'rkhunter.dat' file.
[14:32:25]   /usr/bin/lwp-request                            [ Warning ]
[14:32:25] Warning: The command '/usr/bin/lwp-request' has been replaced by a script: /usr/bin/lwp-request: Perl script text executable
[14:33:57]     Checking kernel module names                  [ Warning ]
[14:33:57] Warning: The kernel modules directory '/lib/modules' is missing or empty.
[14:34:01]   Checking for passwd file changes                [ Warning ]
[14:34:01] Warning: User 'snort' has been added to the passwd file.
[14:34:01] Warning: User 'syslog' has been added to the passwd file.
[14:34:01] Warning: User 'sshd' has been added to the passwd file.
[14:34:01]   Checking for group file changes                 [ Warning ]

解读:

  • rsyslogd/sshd/ssh 警告:文件存在于系统但未收录进 rkhunter.dat(属性基线建立后系统组件更新所致),执行 rkhunter --propupd 收录后消失;
  • lwp-request 警告:/usr/bin/lwp-request 在 Ubuntu 上本来就是 Perl 脚本(libwww-perl 包),rkhunter 判定「命令被替换为脚本」属典型误报;
  • /lib/modules 缺失:最小化安装环境未安装内核模块目录所致,非安全事件;
  • snort/syslog/sshd 用户新增:基线建立后安装软件(如 snort IDS)时创建的系统用户,确认来源后重跑 --propupd 即可。

6.1.4 rkhunter --check --sk

用途:与 --check 相同,但每段检查后不等待按键,适合脚本与非交互终端。

rkhunter --check --sk

实测行为:输出与 --check 完全一致(见 6.1.3),非交互环境下不会卡在 [Press <ENTER> to continue]。若系统曾异常中断导致锁文件残留,先执行:

rkhunter --unlock

6.1.5 rkhunter --propupd

用途:更新/重建文件属性基线数据库(rkhunter_prop_list.dat)。系统更新、安装新软件、修改了被监控文件后必须重跑,否则后续 --check 会误报。

rkhunter --propupd

实测回显:

[ Rootkit Hunter version 1.4.6 ]
File updated: searched for 179 files, found 124

首次建立基线时输出 File created(安装时自动执行,found 121),手动更新时输出 File updated。

6.1.6 rkhunter --update

用途:在线更新 rootkit 签名数据库。Ubuntu 默认配置下实测会失败:

rkhunter --update

实测回显:

Invalid WEB_CMD configuration option: Relative pathname: "/bin/false"

退出码 1。原因与修复见 5.2 节。修复后(WEB_CMD=wget)预期回显(与 CentOS 实测形态一致,此处为预期输出):

[ Rootkit Hunter version 1.4.6 ]

Checking rkhunter data files...
  Checking file mirrors.dat                                  [ Updated ]
  Checking file programs_bad.dat                             [ Updated ]
  ...

6.1.7 rkhunter --versioncheck

用途:检查 rkhunter 程序自身是否有新版本(依赖 mirrors.dat,同样受 WEB_CMD 影响)。

rkhunter --versioncheck

6.1.8 rkhunter --list tests / --list lang

用途:列出可用的测试名称与语言。

rkhunter --list tests

实测回显:

Current test names:
    additional_rkts all apps attributes avail_modules deleted_files
    filesystem group_accounts group_changes hashes hidden_ports hidden_procs
    immutable ipc_shared_mem known_rkts loaded_modules local_host login_backdoors
    malware network none os_specific packet_cap_apps passwd_changes
    ports possible_rkt_files possible_rkt_strings promisc properties rootkits
    running_procs scripts shared_libs shared_libs_path sniffer_logs startup_files
    startup_malware strings susp_dirs suspscan system_commands system_configs
    system_configs_ssh system_configs_syslog tripwire trojans

Grouped test names:
    additional_rkts => possible_rkt_files possible_rkt_strings
    group_accounts  => group_changes passwd_changes
    local_host      => filesystem group_changes passwd_changes startup_malware system_configs_ssh system_configs_syslog
    malware         => deleted_files hidden_procs ipc_shared_mem login_backdoors running_procs sniffer_logs susp_dirs suspscan tripwire
    network         => hidden_ports packet_cap_apps ports promisc
    os_specific     => avail_modules loaded_modules
    properties      => attributes hashes immutable scripts
    rootkits        => avail_modules deleted_files hidden_procs ipc_shared_mem known_rkts loaded_modules login_backdoors possible_rkt_files possible_rkt_strings running_procs sniffer_logs susp_dirs suspscan tripwire trojans
    shared_libs     => shared_libs_path
    startup_files   => startup_malware
    system_commands => attributes hashes immutable scripts shared_libs_path strings
    system_configs  => system_configs_ssh system_configs_syslog
rkhunter --list lang

实测回显(Ubuntu 包内置语言比 CentOS 包多):

Current languages:
    cn de en ja tr tr.utf8 zh zh.utf8

6.1.9 rkhunter --report-warnings-only(--rwo)

用途:只输出警告信息,无警告则无输出。每日定时任务即使用该模式,实现「有问题才报警」。

rkhunter --check --sk --nocolors --report-warnings-only

实测回显(exit=1,仅列出 4 条警告):

Warning: The file properties have changed:
         File: /usr/bin/df
         Current file modification time: 1791297400 (06-Oct-2026 14:36:40)
         Stored file modification time : 1787670771 (25-Aug-2026 15:12:51)
Warning: The command '/usr/bin/lwp-request' has been replaced by a script: /usr/bin/lwp-request: Perl script text executable
Warning: The kernel modules directory '/lib/modules' is missing or empty.
Warning: The SSH configuration option 'PermitRootLogin' has not been set.
         The default value may be 'yes', to allow root access.

(注:df 警告来自演练阶段 touch /usr/bin/df 后的残留,详见第七章实战演练。)

6.1.10 rkhunter --enable / --disable <tests>

用途:临时启用/禁用指定测试(逗号分隔,可为 6.1.8 中的分组名),优先级高于配置文件。

rkhunter --check --sk --disable known_rkts --nocolors --report-warnings-only

实测回显(exit=1,禁用 known_rkts 后 rootkit 签名检查被跳过,仅输出其余警告):

Warning: The file properties have changed:
         File: /usr/bin/df
         Current file modification time: 1791297400 (06-Oct-2026 14:36:40)
         Stored file modification time : 1787670771 (25-Aug-2026 15:12:51)
Warning: The command '/usr/bin/lwp-request' has been replaced by a script: /usr/bin/lwp-request: Perl script text executable
Warning: The kernel modules directory '/lib/modules' is missing or empty.
Warning: The SSH configuration option 'PermitRootLogin' has not been set.
         The default value may be 'yes', to allow root access.

启用示例:

rkhunter --check --sk --enable hidden_ports,deleted_files

6.1.11 rkhunter --lang <language>

用途:切换输出语言。Ubuntu 包支持 8 种语言:

rkhunter --lang zh --version

实测回显(首行):

Rootkit Hunter 1.4.6

6.1.12 rkhunter --nocolors

用途:禁用 ANSI 颜色,输出纯文本,便于日志与邮件。示例见 6.1.9,实测输出不含颜色码。

6.1.13 rkhunter --cronjob

用途:定时任务专用模式,等价于 -c --sk --nocolors。Ubuntu 的 /etc/cron.daily/rkhunter 脚本在 CRON_DAILY_RUN=yes 时按 --cronjob --report-warnings-only --appendlog 运行(详见第八章)。

6.2 chkrootkit 命令

6.2.1 chkrootkit -V

用途:显示版本号。

chkrootkit -V

实测回显:

chkrootkit version 0.55

6.2.2 chkrootkit -l

用途:列出所有可检查的项目。

chkrootkit -l

实测回显:

/usr/sbin/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

各检查项含义:

检查项检测内容
amd / basename / biff / chfn / chsh / cron / crontab / date / du / dirname / echo / egrep / env / find / grep / hdparm / su / ifconfig / init / killall / login / ls / lsof / mail / netstat / named / nologin / passwd / pidof / ps / pstree / tar / tcpd / tcpdump / top / vdir / w / write 等对系统命令执行字符串特征比对,输出 not found / not infected / infected
inetd / syslogd / inetdconf / identd / rlogind / rshd / slogin / sendmail / sshd / telnetd / timed / traceroute 等同上(对应服务未安装时输出 not found)
aliens检查可疑隐藏文件/目录
asp / bindshell检查 ASP 后门与绑定 shell 后门
lkm检查 LKM 内核模块 rootkit(调用 chkproc/chkdirs)
rexedcs检查 rexedcs 后门
sniffer检查网卡混杂模式与抓包 socket(调用 ifpromisc)
w55808 / wted / scalper / slapper / z2检查对应历史 rootkit/worm
chkutmp / chkwtmp / chklastlog检查 wtmp/utmp/lastlog 日志删除痕迹
OSX_RSPLUGmacOS 专用检查项(Linux 上输出 not tested)

6.2.3 chkrootkit -q(quiet)

用途:静默模式,只输出可疑项(suspicious files、infected 等),正常结果全部隐藏。

chkrootkit -q

实测回显(exit=0,21 条可疑项,全部为误报):

The following suspicious files and directories were found:
/usr/lib/python3/dist-packages/fail2ban/tests/files/config/apache-auth/noentry/.htaccess
/usr/lib/python3/dist-packages/fail2ban/tests/files/config/apache-auth/digest_time/.htpasswd
/usr/lib/python3/dist-packages/fail2ban/tests/files/config/apache-auth/digest_time/.htaccess
/usr/lib/python3/dist-packages/fail2ban/tests/files/config/apache-auth/digest_anon/.htpasswd
/usr/lib/python3/dist-packages/fail2ban/tests/files/config/apache-auth/digest_anon/.htaccess
/usr/lib/python3/dist-packages/fail2ban/tests/files/config/apache-auth/basic/authz_owner/.htpasswd
/usr/lib/python3/dist-packages/fail2ban/tests/files/config/apache-auth/basic/authz_owner/.htaccess
/usr/lib/python3/dist-packages/fail2ban/tests/files/config/apache-auth/basic/file/.htpasswd
/usr/lib/python3/dist-packages/fail2ban/tests/files/config/apache-auth/basic/file/.htaccess
/usr/lib/python3/dist-packages/fail2ban/tests/files/config/apache-auth/digest_wrongrelm/.htpasswd
/usr/lib/python3/dist-packages/fail2ban/tests/files/config/apache-auth/digest_wrongrelm/.htaccess
/usr/lib/python3/dist-packages/fail2ban/tests/files/config/apache-auth/digest/.htpasswd
/usr/lib/python3/dist-packages/fail2ban/tests/files/config/apache-auth/digest/.htaccess
/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/gems/3.0.0/gems/minitest-5.14.2/.autotest
/usr/lib/ruby/vendor_ruby/rubygems/ssl_certs/.document
/usr/lib/ruby/vendor_ruby/rubygems/optparse/.document
/usr/lib/ruby/vendor_ruby/rubygems/tsort/.document

解读(均为误报,详见 7.6 节):

  • 前 13 条为 fail2ban 软件包自带测试样例(apache-auth 场景的 .htaccess/.htpasswd 测试文件);
  • 其余 8 条为 ruby gem 包自带的点文件(.travis.yml、.rubocop.yml、.autotest、.document 等);
  • chkrootkit 的 aliens 检查按「隐藏文件 + 启发式路径」匹配产生误报。

6.2.4 chkrootkit -x(专家模式)

用途:专家模式,除结果外还打印每个检查项执行的原始命令及其完整输出,用于人工深度研判。

chkrootkit -x

实测回显(开头部分):

ROOTDIR is `/'
not found
###
### Output of: /usr/bin/strings -a /usr/bin/basename
###
/lib64/ld-linux-x86-64.so.2
__cxa_finalize
__libc_start_main
__cxa_atexit
dcgettext
stderr
__fprintf_chk
__printf_chk
stdout
fputs_unlocked
strcmp
setlocale
strncmp
error
abort
strlen
strndup
free
__overflow
nl_langinfo
__fpending
fileno
__freading
fflush
__errno_location
fclose
lseek
fseeko
fputc_unlocked
__stack_chk_fail
__memcpy_chk
__ctype_get_mb_cur_max
memcmp
__ctype_b_loc
mbrtowc
iswprint
mbsinit
realloc
memset
malloc

说明:-x 输出量大,适合对单个可疑项复核;日常扫描建议用 -q 或默认模式。

6.2.5 默认完整扫描

用途:完整运行全部检查项。

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 infected
Checking `inetdconf'...                                     not found
Checking `identd'...                                        not found
Checking `init'...                                          not infected
Checking `killall'...                                       not found
Checking `ldsopreload'...                                   not infected
Checking `login'...                                         not infected
Checking `ls'...                                            not infected
Checking `lsof'...                                          not infected

实测结尾回显:

Checking `asp'...                                           not infected
Checking `bindshell'...                                     not infected
Checking `lkm'...                                           chkproc: nothing detected
chkdirs: nothing detected
Checking `rexedcs'...                                       not found
Checking `sniffer'...                                       Output from ifpromisc:
lo: not promisc and no packet sniffer sockets
eth0: not promisc and no packet sniffer sockets
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 tested

结果解读:

  • not found:该命令未安装(如 fingerd、gpm 等),非感染;
  • not infected:命令存在且未发现 rootkit 字符串特征;
  • not tested:当前环境不适用(OSX 检查项);
  • chkproc: nothing detected、chkdirs: nothing detected:无隐藏进程/隐藏目录;
  • lo/eth0: not promisc and no packet sniffer sockets:网卡非混杂模式、无抓包 socket,正常。

6.2.6 其他参数

参数说明
-r <dir>指定根目录(ROOTDIR),对指定目录树进行扫描(如 chkrootkit -r /mnt/sysimage 检查离线系统)
-n跳过 NFS 挂载的目录
-e <tests>排除指定检查项(逗号分隔)
-s不打印警告信息
-x专家模式
-q静默模式
-V版本
-l列出检查项

6.2.7 输出状态汇总

chkrootkit 每个检查项的输出状态及其含义:

状态含义是否需要关注
not found被检查命令不存在否
not infected无感染特征否
infected发现感染特征⚠️ 立即人工复核
not tested不适用/无法测试否
nothing found未发现对应 rootkit 特征否
no suspect files / nothing detected / nothing deleted无可疑文件/进程/日志删除否
The following suspicious files and directories were foundaliens 检查发现可疑隐藏文件⚠️ 需确认归属(Ubuntu 上多为软件包样例,见 7.6)
PACKET SNIFFER(...)存在抓包 socket需判断进程来源

七、实战演练

本章完整演示「建立基线 → 首次扫描 → 篡改文件 → 复扫捕获 → chkrootkit 扫描 → 误报处理」全流程。

7.1 第一步:建立属性基线

echo y | rkhunter --propupd

实测回显:

[ Rootkit Hunter version 1.4.6 ]
File updated: searched for 179 files, found 124

基线写入 /var/lib/rkhunter/db/rkhunter_prop_list.dat(实测 1074 行,保存每个受监控文件的哈希、权限、属主、mtime 等属性)。

7.2 第二步:完整扫描(干净状态)

rkhunter --check --sk > /tmp/rkhunter-check.log 2>&1

扫描约 2.5 分钟后,结尾 Summary 实测回显:

System checks summary
=====================

File properties checks...
    Files checked: 124
    Suspect files: 4

Rootkit checks...
    Rootkits checked : 491
    Possible rootkits: 0

Applications checks...
    All checks skipped

The system checks took: 2 minutes and 27 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)

(警告内容与解读见 6.1.3 节:rsyslogd/sshd/ssh 未收录、lwp-request 脚本误报、/lib/modules 缺失、snort/syslog/sshd 用户新增,均非安全事件。)

7.3 第三步:模拟篡改文件

以攻击者「替换系统命令」的典型场景为例,修改 /usr/bin/df 的属性(touch 会更新 mtime/ctime,真实攻击中会替换二进制内容,效果类似):

touch /usr/bin/df
ls -l /usr/bin/df

实测回显:

-rwxr-xr-x 1 root root 85072 Oct  6 14:36 /usr/bin/df

7.4 第四步:复扫并捕获属性变化警告

rkhunter --check --sk

实测回显中 df 一行:

    /usr/bin/df                                               [ Warning ]

日志 /var/log/rkhunter.log 中对应详情(实测,注意与 CentOS 的差异:Ubuntu 包默认 --pkgmgr NONE,直接给出属性明细):

[14:37:11]   /usr/bin/df                                     [ Warning ]
[14:37:11] Warning: The file properties have changed:
[14:37:11]          File: /usr/bin/df
[14:37:11]          Current file modification time: 1791297400 (06-Oct-2026 14:36:40)
[14:37:11]          Stored file modification time : 1787670771 (25-Aug-2026 15:12:51)

验证基线数据库确实记录到变化(可选):

rkhunter --check --sk --nocolors --report-warnings-only

实测回显(exit=1):

Warning: The file properties have changed:
         File: /usr/bin/df
         Current file modification time: 1791297400 (06-Oct-2026 14:36:40)
         Stored file modification time : 1787670771 (25-Aug-2026 15:12:51)
Warning: The command '/usr/bin/lwp-request' has been replaced by a script: /usr/bin/lwp-request: Perl script text executable
Warning: The kernel modules directory '/lib/modules' is missing or empty.
Warning: The SSH configuration option 'PermitRootLogin' has not been set.
         The default value may be 'yes', to allow root access.

处理:确认 df 未被真正篡改后(本例仅为演示 touch),重跑基线消除告警:

rkhunter --propupd

7.5 第五步:chkrootkit 完整扫描

chkrootkit | tee /var/log/chkrootkit.log

实测结果(exit=0,完整输出见 6.2.5 节开头与结尾),扫描确认无任何 infected/隐藏进程/混杂网卡:

ROOTDIR is `/'
Checking `amd'...                                           not found
...
Checking `lkm'...                                           chkproc: nothing detected
chkdirs: nothing detected
...
Checking `sniffer'...                                       Output from ifpromisc:
lo: not promisc and no packet sniffer sockets
eth0: not promisc and no packet sniffer sockets
...
Checking `OSX_RSPLUG'...                                    not tested

7.6 误报分析与处理

Ubuntu 上 chkrootkit 的主要误报集中在 aliens 检查(21 条可疑文件):

误报项误报原因处理建议
/usr/lib/python3/dist-packages/fail2ban/tests/.../.htaccess 与 .htpasswd(13 条)fail2ban 软件包自带的 apache 认证测试样例文件,被 aliens 按隐藏文件启发式匹配用 dpkg -S 确认归属后忽略;或在 /etc/chkrootkit/chkrootkit.ignore 中加入忽略模式
/usr/lib/ruby/gems/.../.travis.yml、.rubocop.yml、.autotest 及 /usr/lib/ruby/vendor_ruby/rubygems/.../.document(8 条)ruby gem 包自带点文件(CI 配置、文档标记等)同上,确认归属后忽略
rkhunter 报 /usr/bin/lwp-request 被替换为 Perl 脚本lwp-request 在 Ubuntu 上本来就是 Perl 脚本(libwww-perl 包)确认包归属后忽略或加入 SCRIPTWHITELIST
rkhunter 报 /lib/modules 缺失最小化安装环境未安装内核模块目录确认非攻击行为后忽略

处理命令示例:

dpkg -S /usr/lib/python3/dist-packages/fail2ban/tests/files/config/apache-auth/digest/.htaccess
dpkg -S /usr/lib/ruby/vendor_ruby/rubygems/ssl_certs/.document

结论:chkrootkit 0.55 本次扫描未发现真实 rootkit(各 nothing found、not infected 状态为主),rkhunter 的 4 条警告亦可全部归因于环境特性与软件包正常行为。

八、定时任务与自动化管理

8.1 rkhunter 每日自动扫描(/etc/default/rkhunter 控制)

Ubuntu 包自带 /etc/cron.daily/rkhunter 脚本,但默认不运行(/etc/default/rkhunter 中 CRON_DAILY_RUN 为空)。启用方法:

sed -i 's/^CRON_DAILY_RUN=""/CRON_DAILY_RUN="yes"/' /etc/default/rkhunter

启用后每日脚本真实内容(节选关键逻辑):

#!/bin/sh

RKHUNTER=/usr/bin/rkhunter

test -x $RKHUNTER || exit 0

# source our config
. /etc/default/rkhunter

if [ -z "$NICE" ]; then
    NICE=0
fi

if [ -z "$RUN_CHECK_ON_BATTERY" ]; then
    RUN_CHECK_ON_BATTERY="false"
fi

# Do not run daily check if running on battery except if explicitely allowed
case "$RUN_CHECK_ON_BATTERY" in
    [NnFf]*)
        if [ -x /usr/bin/on_ac_power ]; then
            on_ac_power >/dev/null 2>&1
            [ $? -eq 1 ] && exit 0
        fi
esac

case "$CRON_DAILY_RUN" in
    [YyTt]*)
        OUTFILE=`mktemp` || exit 1
        /usr/bin/nice -n $NICE $RKHUNTER --cronjob --report-warnings-only --appendlog > $OUTFILE
        if [ -s "$OUTFILE" -a -n "$REPORT_EMAIL" ]; then
          (
            echo "Subject: [rkhunter] $(hostname) - Daily report"
            echo "To: $REPORT_EMAIL"
            echo ""
            cat $OUTFILE
          ) | /usr/sbin/sendmail $REPORT_EMAIL
        fi
        rm -f $OUTFILE
        ;;
      *)
       exit 0
       ;;
esac

工作流程:每日由 anacron 触发 → 检查是否在电池供电 → 执行 nice -n $NICE rkhunter --cronjob --report-warnings-only --appendlog → 输出非空(有警告)且 REPORT_EMAIL 已配置时,通过 sendmail 发送标题为 [rkhunter] <主机名> - Daily report 的邮件。

若需每周自动更新签名库(需先修复 WEB_CMD,见 5.2 节),同时设置:

sed -i 's/^CRON_DB_UPDATE=""/CRON_DB_UPDATE="yes"/' /etc/default/rkhunter
sed -i 's/^DB_UPDATE_EMAIL="false"/DB_UPDATE_EMAIL="true"/' /etc/default/rkhunter

8.2 chkrootkit 每日自动扫描(Ubuntu 默认启用)

Ubuntu 包自带 /etc/cron.daily/chkrootkit,且 /etc/chkrootkit/chkrootkit.conf 中 RUN_DAILY="true" 默认启用。脚本关键逻辑(实测):

  • 从 /etc/chkrootkit/chkrootkit.conf 读取配置;
  • 以 ionice -c3(空闲优先级)运行 /usr/sbin/chkrootkit,输出 tee 到 /var/log/chkrootkit/log.today.raw(原始输出);
  • 经 FILTER(sed 归一化 PACKET SNIFFER 输出与 PID)过滤后,按 /etc/chkrootkit/chkrootkit.ignore 的 egrep 模式剔除匹配行,写入 /var/log/chkrootkit/log.today;
  • DIFF_MODE=true(默认)时与 /var/log/chkrootkit/log.expected 做 diff,仅在结果变化时输出差异(通过 cron 的 MAILTO 发出告警邮件);
  • 首次运行提示创建 log.expected:
No file $LOG_DIR/log.expected
This file should contain expected output from chkrootkit
...
To create this file containing all output from today's run, do (as root)
# cp -a $OUTPUT $EXPECTED_OUTPUT

如不想每日收到完整输出,建议改为 diff 模式并配合 -q:

sed -i 's/^DIFF_MODE="true"/DIFF_MODE="true"/' /etc/chkrootkit/chkrootkit.conf
sed -i 's/^RUN_DAILY_OPTS=""/RUN_DAILY_OPTS="-q"/' /etc/chkrootkit/chkrootkit.conf

8.3 cron/anacron 与 systemd

Ubuntu 的每日任务由 cron + anacron 承载(/etc/cron.daily 由 anacron 在开机/唤醒后补齐执行),服务使用 systemd 管理(每行一个单元命令):

systemctl status cron
systemctl enable cron
systemctl start cron
systemctl restart cron
systemctl status anacron.timer

自定义定时任务示例(每行一个单元命令):

systemd-run --on-calendar="daily" --unit=rkhunter-manual /usr/bin/rkhunter --check --sk --nocolors --report-warnings-only
systemctl status rkhunter-manual.timer
systemctl list-timers rkhunter-manual.timer

8.4 推荐生产自动化策略

  1. 修复 WEB_CMD 后每周运行一次 rkhunter --update 更新签名库;
  2. 每次 apt upgrade 系统更新后运行 rkhunter --propupd 重建基线(见第九章注意事项);
  3. 每日 rkhunter 与 chkrootkit 双扫描(chkrootkit 已默认启用);
  4. 告警邮件必须配置真实可达的收件人(REPORT_EMAIL 与 cron MAILTO),并建立「告警 → 研判 → 处置」SOP。

九、注意事项

以下为本专栏实测过程中总结的关键注意事项:

  • ⚠️ Ubuntu 的 WEB_CMD 陷阱:Ubuntu 包默认 WEB_CMD="/bin/false" 导致 --update、--versioncheck、--config-check 全部报 Invalid WEB_CMD configuration option。生产环境务必按 5.2 节修复(改为 wget 或注释),否则签名库永远无法在线更新。
  • ⚠️ 基线更新时机:--propupd 必须在系统全新安装、应用部署完毕后执行一次作为黄金基线;此后每次 apt 升级、安装软件、修改受监控文件后都必须重跑,否则 --check 会产生大量属性变化误报。
  • ⚠️ 属性变化警告不等于被入侵:文件属性变化(如本文 /usr/bin/df 案例)可能来自系统更新、日志轮转、包管理器脚本、管理员操作等正常行为。收到警告先查 /var/log/rkhunter.log 中变化的具体属性(mtime/hash/权限),再结合 dpkg -V 包名 验证,切忌直接 --propupd 掩盖问题。
  • ⚠️ 禁止盲目 --propupd:在未确认警告原因前执行 --propupd 会永久覆盖基线,若系统确实被入侵则等于销毁取证证据。正确顺序:查日志 → 定位变化文件 → 确认来源 → 才可更新基线。
  • ⚠️ chkrootkit 对只读文件系统的限制:chkrootkit 的 chkwtmp/chklastlog/chkutmp 需要读取并比对 wtmp/utmp/lastlog,且 lkm 检查依赖 /proc 与 ps 的一致性;对只读根文件系统或 /proc 视图受限的环境,部分检查会输出 not tested 或产生 lkm 误报,属预期行为,需结合人工研判。
  • ⚠️ chkrootkit 的 aliens 误报量大:Ubuntu 系统软件包(fail2ban、ruby gem 等)自带大量点文件,chkrootkit -q 实测报出 21 条可疑文件全部为误报。使用 /etc/chkrootkit/chkrootkit.ignore 维护忽略清单可显著降低噪音。
  • ⚠️ rkhunter --check 在非交互终端:不带 --sk 时每段检查后打印 [Press <ENTER> to continue];通过脚本/定时任务运行时务必使用 --sk 或 --cronjob,避免任务挂起。
  • ⚠️ 日志权限:/var/log/rkhunter.log 与属性基线 rkhunter_prop_list.dat 权限为 0600(实测 -rw-------),不要手工改宽松,防止攻击者反查基线。
  • ⚠️ 两种工具都要更新:chkrootkit 无在线更新机制,需定期(如每季度)通过 apt 升级或源码重编获取新版本;仅更新 rkhunter 签名库无法覆盖 chkrootkit 的检测范围。

十、常见问题(FAQ)

10.1 rkhunter --update 报 Invalid WEB_CMD configuration option 怎么办?

这是 Ubuntu 包默认配置问题,实测报错:

Invalid WEB_CMD configuration option: Relative pathname: "/bin/false"

修复(三选一):

sed -i 's|^WEB_CMD="/bin/false"|WEB_CMD=wget|' /etc/rkhunter.conf
# 或
sed -i 's|^WEB_CMD="/bin/false"|#WEB_CMD=|' /etc/rkhunter.conf

修改后验证:

rkhunter --config-check
rkhunter --update

10.2 rkhunter --check 报「文件存在但不在 rkhunter.dat 中」如何处理?

该警告(实测见于 /usr/sbin/rsyslogd、/usr/sbin/sshd、/usr/bin/ssh)表示文件是属性基线建立后更新/新增的,rkhunter 无法校验其属性。处理:

dpkg -S /usr/sbin/sshd          # 确认文件来源包
rkhunter --propupd              # 确认来源正常后收录基线

10.3 如何判断属性变化警告是误报还是真被篡改?

按顺序执行:

grep -A4 "Warning" /var/log/rkhunter.log | tail -40   # 1. 看变化的具体属性
dpkg -V 包名                                            # 2. dpkg 校验(5 表示 MD5 变化等)
ls -l /path/to/file                                     # 3. 手工查看文件

若警告仅为 mtime 变化(如 touch 所致)而内容未变,可判定为无害;若出现哈希变化(5 标记),高度怀疑被替换,立即取证并处置。

10.4 如何设置 rkhunter 邮件告警?

Ubuntu 通过 /etc/default/rkhunter 配置(需已启用 CRON_DAILY_RUN):

sed -i 's/^CRON_DAILY_RUN=""/CRON_DAILY_RUN="yes"/' /etc/default/rkhunter
sed -i 's/^REPORT_EMAIL="root"/REPORT_EMAIL="security@example.com"/' /etc/default/rkhunter

apt 安装 rkhunter 时已自动安装 postfix 作为本地 MTA,脚本通过 sendmail 发送。手工测试:

echo "rkhunter test" | /usr/sbin/sendmail security@example.com

10.5 chkrootkit 报 suspicious files(.htaccess/.htpasswd/.travis.yml 等)怎么办?

这些多为软件包自带的测试样例与点文件(Ubuntu 实测 21 条全部来自 fail2ban 与 ruby gem),chkrootkit 的 aliens 检查按「隐藏文件+启发式路径」匹配,属典型误报。处理:

  1. 逐个确认文件归属:dpkg -S /path/to/file;
  2. 确认属于正常软件包后忽略;
  3. 将稳定误报写入 /etc/chkrootkit/chkrootkit.ignore(每行一个 egrep 正则),例如:
/usr/lib/python3/dist-packages/fail2ban/tests/
/usr/lib/ruby/

10.6 chkrootkit 报 PACKET SNIFFER 或 PF_PACKET 是不是被装了抓包后门?

不一定。dhclient、NetworkManager、systemd-networkd、suricata、wireshark 等软件打开原始套接字均属正常。Ubuntu 的 /etc/cron.daily/chkrootkit 内置 FILTER 已专门归一化上述网络管理进程的输出。复核:

ss -lunp | grep -i raw     # 查看原始套接字进程
ps aux | grep -E "suricata|tcpdump|wireshark"

确认进程来源正常即可忽略。

10.7 扫描一次要多久?

实测:rkhunter --check 完整扫描 Ubuntu 22.04 约 2 分 27 秒(受文件数与 suspscan 等测试影响);chkrootkit 完整扫描 1 分钟以内,-q 模式更快。定时任务建议避开业务高峰,如每日 06:30。

10.8 为什么 rkhunter --check 显示 Applications checks 全部 skipped?

因为 /etc/rkhunter.conf 中 DISABLE_TESTS 包含了 apps 测试组(Ubuntu 默认 DISABLE_TESTS=suspscan hidden_ports hidden_procs deleted_files packet_cap_apps apps)。如需检查应用篡改,把 apps 从 DISABLE_TESTS 移除后重跑:

sed -i 's/DISABLE_TESTS=.*/DISABLE_TESTS=suspscan hidden_ports hidden_procs deleted_files packet_cap_apps/' /etc/rkhunter.conf
rkhunter --config-check

10.9 apt 升级系统后 rkhunter 天天报属性变化怎么办?

这是预期行为——系统包升级会更新大量受监控文件。正确做法:升级完成后确认无异常,立即重跑基线:

apt upgrade -y
rkhunter --propupd

若升级频繁,可在 /etc/default/rkhunter 中启用 APT_AUTOGEN:

sed -i 's/^APT_AUTOGEN="false"/APT_AUTOGEN="true"/' /etc/default/rkhunter

该选项让 rkhunter 在 apt 升级后自动重跑 --propupd(由 /etc/apt/apt.conf.d/90rkhunter 触发)。

十一、卸载方式

11.1 卸载 rkhunter

apt-get purge -y rkhunter

实测说明:purge 会删除程序、/etc/default/rkhunter 与配置(apt 安装时创建的 /etc/rkhunter.conf 属 conffile,purge 一并删除);apt-get remove 则保留配置。手工清理残留:

rm -rf /var/lib/rkhunter
rm -f /var/log/rkhunter.log

(卸载动作本次未实测,命令基于 dpkg 常规行为,执行前请自行确认。)

11.2 卸载 chkrootkit

apt-get purge -y chkrootkit

清理 cron 集成残留:

rm -rf /etc/chkrootkit
rm -rf /var/log/chkrootkit

十二、参考链接