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
29

被折叠的 条评论
为什么被折叠?



