falco 【2】规则(2)

简介: falco 【2】规则(2)

4.8 fd.sip.name

域的实际查找是在单独的线程上完成的,以避免停止主系统调用事件循环。此外,域的 IP 集会定期刷新,策略如下:

  • 域名的基本刷新时间为 10 秒。
  • 如果在刷新周期后 IP 地址未更改,则该域名的刷新超时时间会加倍,直到 320 秒(约 5 分钟)
- list: https_miner_domains
  items: [
    "ca.minexmr.com",
    "cn.stratum.slushpool.com",
    "de.minexmr.com",
    "fr.minexmr.com",
    "mine.moneropool.com",
    "mine.xmrpool.net",
    "pool.minexmr.com",
    "sg.minexmr.com",
    "stratum-eth.antpool.com",
    "stratum-ltc.antpool.com",
    "stratum-zec.antpool.com",
    "stratum.antpool.com",
    "xmr.crypto-pool.fr"
  ]
# Add rule based on crypto mining IOCs
- macro: minerpool_https
  condition: (fd.sport="443" and fd.sip.name in (https_miner_domains))
- rule: Connect to Yahoo
  desc: Detect Connects to yahoo.com IPs
  condition: evt.type=connect and fd.sip.name=yahoo.com
  output: Some connect to yahoo (command=%proc.cmdline connection=%fd.name IP=%fd.sip.name)
  priority: INFO

相反,此rule将永远不会显示有意义的输出…IP=%fd.sip.name,因为比较使用否定匹配:

- rule: Connect to Anything but Yahoo
  desc: Detect Connects to anything other than yahoo.com IPs
  condition: evt.type=connect and fd.sip.name!=yahoo.com
  output: Some connect to something other than yahoo (command=%proc.cmdline connection=%fd.name IP=%fd.sip.name)
  priority: INFO

4.9 rule exceptions

- rule: Write below binary dir
  desc: an attempt to write to any file below a set of binary directories
  condition: >
    bin_dir and evt.dir = < and open_write
    and not package_mgmt_procs
    and not exe_running_docker_save
    and not python_running_get_pip
    and not python_running_ms_oms
    and not user_known_write_below_binary_dir_activities
...

以前,这些例外被表示为原始rule条件的串联。例如,查看宏 package_mgmt_procs:

- macro: package_mgmt_procs
  condition: proc.name in (package_mgmt_binaries)

结果附加and not proc.name in (package_mgmt_binaries)到rule的条件。

一个更极端的情况是 Write_below_etc 宏被 Write below etc rule使用。它有几十个例外:

...
    and not sed_temporary_file
    and not exe_running_docker_save
    and not ansible_running_python
    and not python_running_denyhosts
    and not fluentd_writing_conf_files
    and not user_known_write_etc_conditions
    and not run_by_centrify
    and not run_by_adclient
    and not qualys_writing_conf_files
    and not git_writing_nssdb
...

这些例外通常都遵循相同的结构——命名一个程序和 /etc 下允许该程序写入文件的目录前缀

从 0.28.0 开始,falco 支持exceptionsrule的可选属性。例外键是标识符列表加上过滤检查字段的元组列表。这是一个例子:

- rule: Write below binary dir
  desc: an attempt to write to any file below a set of binary directories
  condition: >
    bin_dir and evt.dir = < and open_write
    and not package_mgmt_procs
    and not exe_running_docker_save
    and not python_running_get_pip
    and not python_running_ms_oms
    and not user_known_write_below_binary_dir_activities
  exceptions:
   - name: proc_writer
     fields: [proc.name, fd.directory]
     comps: [=, =]
     values:
       - [my-custom-yum, /usr/bin]
       - [my-custom-apt, /usr/local/bin]
   - name: cmdline_writer
     fields: [proc.cmdline, fd.directory]
     comps: [startswith, =]
   - name: container_writer
     fields: [container.image.repository, fd.directory]
   - name: proc_filenames
     fields: [proc.name, fd.name]
     comps: [=, in]
     values:
       - [my-custom-dpkg, [/usr/bin, /bin]]
   - name: filenames
     fields: fd.filename
     comps: in

该rule定义了四种例外情况:


proc_writer:使用 proc.name 和 fd.directory 的组合

cmdline_writer:使用 proc.cmeline 和 fd.directory 的组合

container_writer:使用 container.image.repository 和 fd.directory 的组合

proc_filenames:使用进程和文件名列表的组合。

文件名:使用文件名列表

该fields属性包含一个或多个将从事件中提取值的字段。该comps属性包含将 1-1 与 fields 属性中的项目对齐的比较运算符。该values属性包含值的元组。元组中的每个项目都应与相应的字段和比较运算符 1-1 对齐。每个值元组都与字段/组合组合在一起,以修改条件以将排除项添加到rule的条件中。


例如,对于上面的异常“proc_writer”,字段/comps/values 相当于将以下内容添加到rule的条件中:

... and not ((proc.name=my-custom-yum and fd.directory=/usr/bin) or (proc.name=my-custom-apt and fd.directory=/usr/local/bin))

请注意,当比较运算符为“in”时,对应的值元组项应该是一个列表。上面的“proc_filenames”使用该语法,相当于:

... and not (proc.name=my-custom-dpkg and fd.name in (/usr/bin, /bin))

4.9.1 Appending Exception Values

异常值通常在rule中使用 append: true 定义。这是一个例子:

- list: apt_files
  items: [/bin/ls, /bin/rm]
- rule: Write below binary dir
  exceptions:
  - name: proc_writer
    values:
    - [apk, /usr/lib/alpine]
    - [npm, /usr/node/bin]
  - name: container_writer
    values:
    - [docker.io/alpine, /usr/libexec/alpine]
  - name: proc_filenames
    values:
    - [apt, [apt_files]]
    - [rpm, [/bin/cp, /bin/pwd]]
  - name: filenames
    values: [python, go]
  append: true

在这种情况下,这些值将附加到基本rule的任何值,然后将字段/comps/values 添加到rule的条件中。

综上所述,该rule的有效rule条件为:

... and not ((proc.name=my-custom-yum and fd.directory=/usr/bin) or                             # proc_writer
             (proc.name=my-custom-apt and fd.directory=/usr/local/bin) or
       (proc.name=apk and fd.directory=/usr/lib/alpine) or
       (proc.name=npm and fd.directory=/usr/node/bin) or
       (container.image.repository=docker.io/alpine and fd.name=/usr/libexec/alpine) or   # container_writer
       (proc.name=apt and fd.name in (apt_files)) or                                      # proc_filenames
       (proc.name=rpm and fd.name in (/bin/cp, /bin/pwd)) or
       (fd.filename in (python, go))                                                      # filenames

定义异常时,请尝试考虑actor、action和target,并尽可能将所有三个项目用于异常。例如,除了简单地使用proc.name or container.image.repository用于基于文件的异常,还包括通过fd.name、fd.directory等操作的文件。类似地,如果rule是特定于容器的,则不仅包括 image container.image.repository,还包括进程名称proc.name

4.9.2 Exceptions Syntax Shortcuts

rule可以定义字段和组合,但不能定义值。这允许稍后使用“append:true”的rule将值添加到异常中(更多内容见下文)。上 面的异常“cmdline_writer”具有以下格式:

   - name: cmdline_writer
     fields: [proc.cmdline, fd.directory]
     comps: [startswith, =]

定义异常的另一种方法是让字段包含单个字段,而 comps 包含单个比较运算符(必须是“in”、“pmatch”、“intersects”之一)。在这种格式中,values 是一个值列表,而不是元组列表。上面的异常“文件名”具有以下格式:

   - name: filenames
     fields: fd.filename
     comps: in

在这种情况下,异常相当于:

... and not (fd.filename in (...))

如果未提供 comps,则填写默认值。当 fields 为列表时,comps 将设置为 = 的等长列表。上面的异常“container_writer”具有该格式,相当于:

   - name: container_writer
     fields: [container.image.repository, fd.directory]
     comps: [=, =]

当 fields 是单个字段时,comps 设置为单个字段“in”。

5. 转义特殊字符

在某些情况下,rule可能需要包含特殊字符,如(、空格等。例如,您可能需要查找 a proc.name of (systemd),包括周围的括号。

您可以使用"这些特殊字符来捕获。这是一个例子:

- rule: Any Open Activity by Systemd
  desc: Detects all open events by systemd.
  condition: evt.type=open and proc.name="(systemd)" or proc.name=systemd
  output: "File opened by systemd (user=%user.name command=%proc.cmdline file=%fd.name)"
  priority: WARNING

在列表中包含项目时,请确保不会通过用单引号将带引号的字符串从 YAML 文件中解释双引号。这是一个例子:

- list: systemd_procs
  items: [systemd, '"(systemd)"']
- rule: Any Open Activity by Systemd
  desc: Detects all open events by systemd.
  condition: evt.type=open and proc.name in (systemd_procs)
  output: "File opened by systemd (user=%user.name command=%proc.cmdline file=%fd.name)"
  priority: WARNING

6. rule 文件

6.1 默认 rule 文件

默认的 falco rule文件安装在/etc/falco/falco_rules.yaml. 它包含一组预定义的rule,旨在在各种情况下提供良好的覆盖。目的是不修改此rule文件,并用每个新的软件版本替换。

6.2 本地 rule 文件

本地 falco rule文件安装在/etc/falco/falco_rules.local.yaml. 除了一些评论之外,它是空的。目的是将主rule文件的添加/覆盖/修改添加到此本地文件中。它不会被每个新的软件版本所取代。

7. rule 禁用默认

7.1 通过现有的宏

大多数默认rule都提供了某种consider_*宏,这些宏已经是rule条件的一部分。这些consider_*宏通常设置为(never_true)或(always_true)基本上启用或禁用相关rule。现在,如果您想启用默认禁用的rule(例如Unexpected outbound connection destination),您只需在自定义 Falco 配置中覆盖rule的consider_*宏(consider_all_outbound_conns在这种情况下)。

您的自定义 Falco 配置示例(注意(always_true)条件):

- macro: consider_all_outbound_conns
  condition: (always_true)

请再次注意,指定配置文件的顺序很重要!最后定义的同名宏有效。

7.2 通过 Falco 参数

Falco 提供以下参数来限制应该启用/使用哪些默认rule,哪些不应该:

-D <substring>                Disable any rules with names having the substring <substring>. Can be specified multiple times.
-T <tag>                      Disable any rules with a tag=<tag>. Can be specified multiple times.
                               Can not be specified with -t.
-t <tag>                      Only run those rules with a tag=<tag>. Can be specified multiple times.
                               Can not be specified with -T/-D.

extraArgs如果您通过官方 Helm charts 部署 Falco,这些参数也可以指定为 Helm 图表值 ( ).

7.3 通过自定义rule定义

enabled: false最后但并非最不重要的一点是,您可以使用rule 属性禁用默认启用的rule。这对于在默认条件下不提供consider_*宏的rule特别有用。


确保在默认配置文件之后加载自定义配置文件。您可以使用多个-r参数配置正确的顺序,直接在 falco 配置文件中falco.yaml通过rules_file. 如果您使用的是官方 Helm charts,则使用该falco.rules File值配置顺序。


例如,在定义自定义rule时禁用User mgmt binaries默认rule:

/etc/falco/falco_rules.yaml /etc/falco/rules.d/custom-rules.yaml

- rule: User mgmt binaries
  enabled: false

同时,可以使用enabled: true rule 属性重新启用禁用的rule。例如,默认情况下禁用的Change thread namespacerule/etc/falco/falco_rules.yaml可以通过以下方式手动启用:

- rule: Change thread namespace
  enabled: true

8. rule 陷阱

带有rule/宏附加和逻辑运算符的陷阱

请记住,在附加rule和宏时,第二个rule/宏的文本只是简单地添加到第一个rule/宏的条件中。如果原始rule/宏具有潜在的模棱两可的逻辑运算符,这可能会导致意外结果。这是一个例子:

- rule: my_rule
  desc: ...
  condition: evt.type=open and proc.name=apache
  output: ...
- rule: my_rule
  append: true
  condition: or proc.name=nginx

应该proc.name=nginx解释为相对于and proc.name=apache,即允许 apache/nginx 打开文件,或者相对于evt.type=open,即允许 apache 打开文件或允许 nginx 做任何事情?


在这种情况下,请务必尽可能用括号限定原始条件的逻辑运算符范围,或者在不可能时避免附加条件。


参考:


falco rules



相关文章
|
JavaScript
Node.js npm设置淘宝npm镜像
Node.js npm设置淘宝npm镜像
2909 0
|
9天前
|
域名解析 人工智能 Linux
|
19天前
|
Linux Go 开发工具
手机上跑 DeepSeek 智能体:开源安卓客户端 DSH Go 安装与使用指南
DSH Go 是一款开源安卓客户端,将 DeepSeek Harness 智能体引擎装进手机:免 Root、免 Termux,一键安装即用;支持本机运行(内置 Ubuntu+Node.js)或远程接管电脑会话;具备插话打断、过程折叠、屏幕操控、端到端加密分享等特色功能,真正实现智能体“口袋化”。
17546 63
|
17天前
|
人工智能
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
进不去 Antigravity 或 Gemini,提示所在地区不可用?三步查清 Google 账号关联地区、官方更正表单理由选法与改区注意事项。
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
|
3天前
|
人工智能 安全 网络安全
|
7天前
|
云安全 数据采集 人工智能
|
8天前
|
Linux API iOS开发
【DSH】DeepSeek Harness新手保姆教程(下载+安装+配置+使用,2026最新实测)
DeepSeek Harness(dsh)是 DeepSeek AI 开源的智能体框架,秉持“一切皆插件”理念,支持读文件、改代码、执行命令、处理表格等自动化任务;免费开源,兼容 Win/macOS,需配 API 密钥使用。(239字)
1382 5
|
14天前
|
人工智能 开发工具 开发者
2026最新codex下载安装保姆级使用教程(下载+安装+登录+使用,含所有历史版本)
Codex 是 OpenAI 推出的开源 AI 编程智能体,跑在本地终端和桌面客户端里,能读懂整个代码仓库,一句自然语言就能让它改代码、执行命令、跑测试、修 Bug,支持 Windows、macOS、Linux 三大平台。本文把 Codex下载、安装、登录、汉化、基础使用一次讲全,并整理了国内用户最常踩的坑,跟着做 10 分钟就能跑起来。
2440 8
|
19天前
|
弹性计算 人工智能 API
Codex超详细入门指南(下载·安装·登录·上手,全版本覆盖,2026最新版)
建议收藏本教程,2026 全年各版本更新随时回来查阅。如果你在搭建过程中遇到任何问题,欢迎结合 阿里云工单系统 提交技术支持请求,或在 阿里云开发者社区 搜索 Codex 相关话题交流。 祝你编码愉快,效率翻倍!
3945 22
|
20天前
|
Linux API iOS开发
【DSH】DeepSeek Harness新手保姆教程(下载+安装+配置+使用,2026最新实测)
DeepSeek Harness(dsh)是DeepSeek AI开源的智能体框架,秉持“一切皆插件”理念,支持读文件、改代码、跑命令、处理表格、联网搜索等操作。免费开源,兼容Windows/macOS/Linux,提供桌面端与网页端,可灵活安装插件扩展能力。

热门文章

最新文章