Falco知识点

Falco 规则

- rule: <规则名称>
  desc: <规则描述>
  condition: <条件表达式>
  output: <告警输出模板>
  priority: <告警级别>
  tags: [标签]

Falco 的 condition 支持以下类型的语法:

类型示例说明
布尔运算and, or, not, ()逻辑组合
比较运算=, !=, <, <=, >, >=数值/字符串比较
集合匹配in, not in集合匹配(字符串、数字、集合)
字符串匹配contains, startswith, endswith, glob, pmatch模糊匹配
字段存在性exists(field)判断字段是否存在
集合定义myset = (a, b, c)自定义宏或集合
宏调用proc_is_shell复用宏条件(相当于子表达式)

Falco 的条件表达式通过事件字段来判断,例如:

字段含义
evt.type事件类型(syscall 名称,如 open, execve
evt.dir事件方向(< 进入 syscall, > 退出 syscall)
evt.arg.<name>syscall 参数(如 evt.arg.flags
evt.time时间戳
proc.name进程名
proc.cmdline命令行
user.name用户名
fd.name文件名(路径)
fd.type文件类型(如 file, socket, pipe)
container是否在容器中(布尔值)
container.id容器 ID
fd.sip, fd.dip源/目的 IP
fd.sport, fd.dport源/目的端口

系统内置了很多,比如:

宏名作用
container是否在容器中
user_known_write_activities合法写入操作
proc_is_shell是否 shell 进程
consider_syslog排除 syslog 写入

Falco 支持宏定义,用来重用复杂条件:

- macro: sensitive_files
  condition: fd.name in (/etc/shadow, /etc/passwd, /etc/ssl/*)

- rule: Sensitive File Access
  condition: evt.type in (open, openat) and sensitive_files

例如: 

evt.type = open and fd.name = /etc/passwd, 可用括号 () 控制优先级

contains    包含子串    fd.name contains /etc/
startswith    以某字符串开头    proc.name startswith ssh
endswith    以某字符串结尾    fd.name endswith .conf
glob    Shell 模式匹配    fd.name glob /etc/*.conf
pmatch    模糊匹配(带通配符)    proc.cmdline pmatch "curl *http*"

示例

- rule: Read Sensitive File
  desc: Detect reading of /etc/shadow or /etc/passwd
  condition: >
    evt.type in (open, openat) and fd.name in (/etc/shadow, /etc/passwd)
  output: >
    Sensitive file opened for reading (user=%user.name file=%fd.name proc=%proc.name)
  priority: CRITICAL
  tags: [filesystem, security]
- rule: Access Sensitive System Files
  desc: Detect any process trying to open sensitive files
  condition: >
    evt.type in (open, openat)
    and fd.name in (/etc/passwd, /etc/shadow, /etc/sudoers)
    and not proc.name in (cat, less)
  output: >
    Sensitive file accessed (file=%fd.name user=%user.name proc=%proc.name)
  priority: CRITICAL
  tags: [filesystem, security]

open, openat, creat — 文件“打开”阶段(建立文件描述符)

read, write, pread, pwrite — 文件“操作”阶段(使用文件描述符)

相关帮助命令

falco --help

falco --list-events | grep open

falco --list | grep proc
falco --list | grep user
falco --list | grep container

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值