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



相关文章
|
1月前
|
Kubernetes 负载均衡 网络协议
在K8S中,Pod的探针有哪些及用途?
在K8S中,Pod的探针有哪些及用途?
|
1月前
|
Prometheus Cloud Native
prometheus告警规则分发服务
prometheus告警规则分发服务
34 1
|
2月前
编写的Snort规则不报警怎么办?
以上步骤应该能帮助你找出规则不报警的原因,并进行相应的解决。
25 1
|
4月前
|
存储 Prometheus 监控
Alertmanager配置概述及告警规则
Alertmanager配置概述及告警规则
|
10月前
|
Prometheus Kubernetes Cloud Native
Prometheus Operator创建告警规则文件
Prometheus Operator创建告警规则文件
69 0
|
Prometheus 监控 Cloud Native
在Linux系统部署prometheus监控(2) --配置规则
在Linux系统部署prometheus监控(2) --配置规则
|
Prometheus 监控 Cloud Native
Prometheus: ansible+consul自动发现,监控服务器
Prometheus: ansible+consul自动发现,监控服务器
554 0
|
JSON Kubernetes 安全
falco 【2】规则(1)
falco 【2】规则(1)
falco 【2】规则(1)
|
Prometheus 监控 Kubernetes
在ASM中为应用服务启用SLO(4):导入生成的规则到Prometheus中执行SLO
服务等级目标SLO可以用于衡量服务的水平。用户可以基于Prometheus指标手动定义SLO,但过程相对繁琐。ASM服务网格提供了生成SLO以及配套的告警规则的能力,能够通过自定义资源YAML配置的方式简化这一流程。本文将介绍如何将生成的规则导入到Prometheus中以及如何执行SLO。
307 0
在ASM中为应用服务启用SLO(4):导入生成的规则到Prometheus中执行SLO
|
JSON Prometheus 监控
在ASM中为应用服务启用SLO(5):使用Grafana查看SLO
Grafana是开源的数据可视化平台,它可以生成各种可视化仪表,大大帮助我们简化监控的复杂度,下面介绍如何使用Grafana查看SLO相关指标。
231 0
在ASM中为应用服务启用SLO(5):使用Grafana查看SLO