通过文件修改实现持久化

编辑

此规则利用文件完整性监控 (FIM) 集成来检测对 Linux 系统中常用持久化文件的修改。该规则检测对常用 cron 作业、systemd 服务、每日消息 (MOTD)、SSH 配置、shell 配置、运行时控制、init 守护进程、passwd/sudoers/shadow 文件、Systemd udevd 和 XDG/KDE 自动启动项文件的修改。要利用此规则,需要将查询中指定的路径添加到 Elastic Security 应用中的 FIM 策略中。

规则类型: eql

规则索引:

  • logs-fim.event-*
  • auditbeat-*

严重性: 低

风险评分: 21

每隔: 5 分钟

搜索索引自: now-9m (日期数学格式,另见 额外回溯时间)

每次执行的最大告警数: 100

参考资料:

标签:

  • 领域:端点
  • 操作系统:Linux
  • 用例:威胁检测
  • 策略:持久化
  • 策略:权限提升
  • 数据源:文件完整性监控

版本: 4

规则作者:

  • Elastic

规则许可证: Elastic License v2

设置

编辑

设置

此规则需要来自 Elastic 文件完整性监控 (FIM) 集成的传入数据。

Elastic FIM 集成设置

要配置 Elastic FIM 集成,请按照以下步骤操作

  1. 在您的 Linux 系统上安装并配置 Elastic Agent。您可以参考 Elastic Agent 文档 获取详细说明。
  2. 安装 Elastic Agent 后,导航到 Kibana 中的 Elastic Security 应用。
  3. 在 Kibana 首页,单击左侧边栏中的“集成”。
  4. 在搜索栏中搜索“文件完整性监控”,然后选择集成。
  5. 为集成提供名称和可选说明。
  6. 为您的 Linux 系统选择合适的 Agent 策略,或创建一个新的策略。
  7. 通过指定要监控文件修改的路径来配置 FIM 策略。您可以使用规则的 query 字段中提到的相同路径。请注意,FIM 不接受路径中的通配符,因此您需要指定要监控的确切路径。
  8. 保存配置,Elastic Agent 将开始监控指定路径的文件修改。

有关配置 Elastic FIM 集成的更多详细信息,您可以参考 Elastic FIM 文档

规则查询

编辑
file where host.os.type == "linux" and event.dataset == "fim.event" and event.action == "updated" and
file.path : (
  // cron, anacron & at
  "/etc/cron.d/*", "/etc/cron.daily/*", "/etc/cron.hourly/*", "/etc/cron.monthly/*",
  "/etc/cron.weekly/*", "/etc/crontab", "/var/spool/cron/crontabs/*", "/etc/cron.allow",
  "/etc/cron.deny",  "/var/spool/anacron/*", "/var/spool/cron/atjobs/*",

  // systemd services & timers
  "/etc/systemd/system/*", "/usr/local/lib/systemd/system/*", "/lib/systemd/system/*",
  "/usr/lib/systemd/system/*", "/home/*/.config/systemd/user/*", "/home/*/.local/share/systemd/user/*",
  "/root/.config/systemd/user/*", "/root/.local/share/systemd/user/*",

  // LD_PRELOAD
  "/etc/ld.so.preload", "/etc/ld.so.conf.d/*", "/etc/ld.so.conf",

  // message-of-the-day (MOTD)
  "/etc/update-motd.d/*",

  // SSH
  "/home/*/.ssh/*", "/root/.ssh/*", "/etc/ssh/*",

  // system-wide shell configurations
  "/etc/profile", "/etc/profile.d/*", "/etc/bash.bashrc", "/etc/zsh/*", "/etc/csh.cshrc",
  "/etc/csh.login", "/etc/fish/config.fish", "/etc/ksh.kshrc",

  // root and user shell configurations
  "/home/*/.profile", "/home/*/.bashrc", "/home/*/.bash_login", "/home/*/.bash_logout",
  "/root/.profile", "/root/.bashrc", "/root/.bash_login", "/root/.bash_logout",
  "/home/*/.zprofile", "/home/*/.zshrc", "/root/.zprofile", "/root/.zshrc",
  "/home/*/.cshrc", "/home/*/.login", "/home/*/.logout", "/root/.cshrc", "/root/.login", "/root/.logout",
  "/home/*/.config/fish/config.fish", "/root/.config/fish/config.fish",
  "/home/*/.kshrc", "/root/.kshrc",

  // runtime control
  "/etc/rc.common", "/etc/rc.local",

  // System V init/Upstart
  "/etc/init.d/*", "/etc/init/*",

  // passwd/sudoers/shadow
  "/etc/passwd", "/etc/shadow", "/etc/sudoers", "/etc/sudoers.d/*",

  // Systemd udevd
  "/lib/udev/*", "/etc/udev/rules.d/*", "/usr/lib/udev/rules.d/*", "/run/udev/rules.d/*", "/usr/local/lib/udev/rules.d/*",

  // XDG/KDE autostart entries
  "/home/*/.config/autostart/*", "/root/.config/autostart/*", "/etc/xdg/autostart/*", "/usr/share/autostart/*",
  "/home/*/.kde/Autostart/*", "/root/.kde/Autostart/*",
  "/home/*/.kde4/Autostart/*", "/root/.kde4/Autostart/*",
  "/home/*/.kde/share/autostart/*", "/root/.kde/share/autostart/*",
  "/home/*/.kde4/share/autostart/*", "/root/.kde4/share/autostart/*",
  "/home/*/.local/share/autostart/*", "/root/.local/share/autostart/*",
  "/home/*/.config/autostart-scripts/*", "/root/.config/autostart-scripts/*"
) and not (
  file.path : (
    "/var/spool/cron/crontabs/tmp.*", "/run/udev/rules.d/*rules.*", "/home/*/.ssh/known_hosts.*", "/root/.ssh/known_hosts.*"
  ) or
  file.extension in ("dpkg-new", "dpkg-remove", "SEQ")
)

框架: MITRE ATT&CKTM