排查systemd定时器后门需重点检查:systemctl list-timers --all中异常触发状态的timer;systemctl list-unit-files --type=timer | grep enabled筛选非官方启用项;通过systemctl cat确认OnCalendar和绑定service的ExecStart是否可疑;核查FragmentPath是否指向/run/systemd/system/(运行时注入);比对磁盘文件与实际加载单元是否一致;检查UID、PPID及WantedBy配置是否符合规范。

排查 systemd 定时器(timer)下的持久化后门,关键在于识别“看似合法、实则异常”的自动执行逻辑。systemd timer 是攻击者偏爱的隐蔽自启载体——它不依赖 crontab,不写入用户 shell 配置,且默认无日志输出,容易被忽略。
检查已启用但未被审查的 timer 单元
攻击者常创建名称模糊(如 update-check.timer、sys-maint.timer)或仿冒系统单元(如 dbus-broker.timer)的定时器。执行:
- systemctl list-timers --all:查看所有已加载、启用、触发过的 timer,重点关注 LOAD 状态为 loaded 但 ACTIVE 状态异常(如 last triggered 是几小时前,但 next elapses 是“n/a”或远超常规间隔)的条目
-
systemctl list-unit-files --type=timer | grep enabled:筛选出所有启用的 timer,排除官方包自带的(如
logrotate.timer、fstrim.timer),对非标准名称逐个 inspect
深入 inspect 每个可疑 timer 的实际行为
仅看 timer 文件本身不够,必须确认其绑定的 service 单元是否真实可信:
- 用 systemctl cat <unit-name>.timer 查看 timer 定义,注意
OnCalendar=或OnUnitActiveSec=是否设置为高频(如每分钟)、非常规时间(如*-*-* 02:17:00)或模糊表达式(如hourly但无对应系统级策略) - 找出它触发的 service:timer 中通常含
Unit=xxx.service;再运行 systemctl cat <xxx.service>,重点检查:
–ExecStart=是否调用可疑路径(如/tmp/.X11-unix/xxx、/dev/shm/.cache/run.sh)
– 是否使用bash -c、python3 -c或wget/curl -o /dev/shm/...类动态下载执行命令
–DynamicUser=yes或RestrictAddressFamilies=等安全限制是否存在(缺失即可疑)
比对磁盘文件与运行时单元状态的一致性
攻击者可能直接修改内存中的 unit(通过 systemctl daemon-reload 加载恶意内容),而不落地到磁盘:
- 运行 systemctl show --property=FragmentPath <unit-name>.timer,若返回空或
/run/systemd/system/...(而非/usr/lib/systemd/system/...或/etc/systemd/system/...),说明该 timer 是运行时注入的,极大概率是后门 - 检查
/run/systemd/system/目录下是否有新增的 .timer 或 .service 文件:ls -la /run/systemd/system/*.timer /run/systemd/system/*.service 2>/dev/null;该目录内容重启即失,但存在即表明近期有非法 reload 行为 - 对比
systemctl list-timers输出的 UNIT 名称,和find /etc/systemd/system /usr/lib/systemd/system -name "*.timer" -type f的结果——若前者多出若干,说明有未落盘的恶意 timer
关联检查启动链与权限上下文
一个真正的后门 timer 往往伴随权限异常或父子关系断裂:
- 查该 timer 对应 service 进程的 UID:systemctl show --property=UID <xxx.service>;正常系统服务 UID 应为 0 或明确指定的受限用户(如
nobody),若为-1或空,需警惕 - 用 systemctl status <xxx.service> 查看最近一次启动的
Process行,记下 PID,再执行 ps -o pid,ppid,comm -p <PID>,确认父进程是否为systemd(PPID=1);若 PPID 是其他进程(如bash或python),说明该 service 是被伪造启动的假 timer - 检查该 service 是否设置了
WantedBy=timers.target或WantedBy=multi-user.target—— 合法 timer 一般只在[Install]段声明WantedBy=timers.target;若同时出现在多个 target,属异常配置


















