Skip to content

Commit

Permalink
Update rules to improve performance.
Browse files Browse the repository at this point in the history
Make changes to rules to improve performance:

- Rely on an upcoming change to
  sysdig (draios/sysdig#610) that allows
  specifying an open/openat for reading/writing, without having to
  search through all the flags individually.

- Switch to consistently using evt.type instead of syscall.type.

- Move positive tests like etc_dir, bin_dir, etc., which are most likely
  to not succeed, to the beginning of rules, so they have a greater
  chance to cause the rest of the rule to be skipped, which saves time.
  • Loading branch information
mstemm committed Jun 17, 2016
1 parent 8572f58 commit a3f673b
Showing 1 changed file with 17 additions and 26 deletions.
43 changes: 17 additions & 26 deletions rules/falco_rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,17 @@
# condition: (syscall.type=read and evt.dir=> and fd.type in (file, directory))

- macro: open_write
condition: >
(evt.type=open or evt.type=openat) and
fd.typechar='f' and
(evt.arg.flags contains O_WRONLY or
evt.arg.flags contains O_RDWR or
evt.arg.flags contains O_CREAT or
evt.arg.flags contains O_TRUNC)
condition: evt.type in (open, openat) and evt.is_open_write=true and fd.typechar='f'

- macro: open_read
condition: >
(evt.type=open or evt.type=openat) and
fd.typechar='f' and
(evt.arg.flags contains O_RDONLY or
evt.arg.flags contains O_RDWR)
condition: evt.type in (open, openat) and evt.is_open_read=true and fd.typechar='f'

- macro: rename
condition: syscall.type = rename
condition: evt.type = rename
- macro: mkdir
condition: syscall.type = mkdir
condition: evt.type = mkdir
- macro: remove
condition: syscall.type in (remove, rmdir, unlink, unlink_at)
condition: evt.type in (rmdir, unlink, unlinkat)

- macro: modify
condition: rename or remove
Expand Down Expand Up @@ -150,11 +141,11 @@

# Network
- macro: inbound
condition: ((syscall.type=listen and evt.dir=>) or (syscall.type=accept and evt.dir=<))
condition: ((evt.type=listen and evt.dir=>) or (evt.type=accept and evt.dir=<))

# Currently sendto is an ignored syscall, otherwise this could also check for (syscall.type=sendto and evt.dir=>)
# Currently sendto is an ignored syscall, otherwise this could also check for (evt.type=sendto and evt.dir=>)
- macro: outbound
condition: syscall.type=connect and evt.dir=< and (fd.typechar=4 or fd.typechar=6)
condition: evt.type=connect and evt.dir=< and (fd.typechar=4 or fd.typechar=6)

- macro: ssh_port
condition: fd.lport=22
Expand All @@ -165,7 +156,7 @@

# System
- macro: modules
condition: syscall.type in (delete_module, init_module)
condition: evt.type in (delete_module, init_module)
- macro: container
condition: container.id != host
- macro: interactive
Expand All @@ -189,26 +180,26 @@

- rule: write_binary_dir
desc: an attempt to write to any file below a set of binary directories
condition: evt.dir = < and open_write and not package_mgmt_binaries and bin_dir
condition: evt.dir = < and open_write and bin_dir and not package_mgmt_binaries
output: "File below a known binary directory opened for writing (user=%user.name command=%proc.cmdline file=%fd.name)"
priority: WARNING

- rule: write_etc
desc: an attempt to write to any file below /etc, not in a pipe installer session
condition: evt.dir = < and open_write and not shadowutils_binaries and not sysdigcloud_binaries_parent and not package_mgmt_binaries and etc_dir and not proc.sname=fbash
condition: evt.dir = < and open_write and etc_dir and not shadowutils_binaries and not sysdigcloud_binaries_parent and not package_mgmt_binaries and not proc.sname=fbash
output: "File below /etc opened for writing (user=%user.name command=%proc.cmdline file=%fd.name)"
priority: WARNING

# Within a fbash session, the severity is lowered to INFO
- rule: write_etc_installer
desc: an attempt to write to any file below /etc, in a pipe installer session
condition: evt.dir = < and open_write and not shadowutils_binaries and not sysdigcloud_binaries_parent and not package_mgmt_binaries and etc_dir and proc.sname=fbash
condition: evt.dir = < and open_write and etc_dir and not shadowutils_binaries and not sysdigcloud_binaries_parent and not package_mgmt_binaries and proc.sname=fbash
output: "File below /etc opened for writing (user=%user.name command=%proc.cmdline file=%fd.name) within pipe installer session"
priority: INFO

- rule: read_sensitive_file_untrusted
desc: an attempt to read any sensitive file (e.g. files containing user/password/authentication information). Exceptions are made for known trusted programs.
condition: open_read and not user_mgmt_binaries and not userexec_binaries and not proc.name in (iptables, ps, lsb_release, check-new-relea, dumpe2fs, accounts-daemon, bash, sshd) and not cron and sensitive_files
condition: open_read and sensitive_files and not user_mgmt_binaries and not userexec_binaries and not proc.name in (iptables, ps, lsb_release, check-new-relea, dumpe2fs, accounts-daemon, bash, sshd) and not cron
output: "Sensitive file opened for reading by non-trusted program (user=%user.name command=%proc.cmdline file=%fd.name)"
priority: WARNING

Expand All @@ -221,7 +212,7 @@
# Only let rpm-related programs write to the rpm database
- rule: write_rpm_database
desc: an attempt to write to the rpm database by any non-rpm related program
condition: open_write and not proc.name in (rpm,rpmkey,yum) and fd.directory=/var/lib/rpm
condition: open_write and fd.directory=/var/lib/rpm and not proc.name in (rpm,rpmkey,yum)
output: "Rpm database opened for writing by a non-rpm program (command=%proc.cmdline file=%fd.name)"
priority: WARNING

Expand Down Expand Up @@ -261,7 +252,7 @@

- rule: change_thread_namespace
desc: an attempt to change a program/thread\'s namespace (commonly done as a part of creating a container) by calling setns.
condition: syscall.type = setns and not proc.name in (docker, sysdig, dragent)
condition: evt.type = setns and not proc.name in (docker, sysdig, dragent, nsenter)
output: "Namespace change (setns) by unexpected program (user=%user.name command=%proc.cmdline container=%container.id)"
priority: WARNING

Expand Down Expand Up @@ -320,7 +311,7 @@
# (we may need to add additional checks against false positives, see: https://bugs.launchpad.net/ubuntu/+source/rkhunter/+bug/86153)
- rule: create_files_below_dev
desc: creating any files below /dev other than known programs that manage devices. Some rootkits hide files in /dev.
condition: (evt.type = creat or evt.arg.flags contains O_CREAT) and proc.name != blkid and fd.directory = /dev and not fd.name in (/dev/null,/dev/stdin,/dev/stdout,/dev/stderr)
condition: (evt.type = creat or evt.arg.flags contains O_CREAT) and proc.name != blkid and fd.directory = /dev and fd.name != /dev/null
output: "File created below /dev by untrusted program (user=%user.name command=%proc.cmdline file=%fd.name)"
priority: WARNING

Expand Down

0 comments on commit a3f673b

Please sign in to comment.