Commit Graph

2722 Commits

Author SHA1 Message Date
Mark Stemm
a2011c37a0 Performance/FP rule updates.
Make changes to rules to improve performance and reduce FPs:

- Rely on https://github.com/draios/sysdig/pull/610 that allows
  specifying an open/openat for reading/writing without having to search
  through all the flags individually.

- For a two-item list (open, openat), and thinking ahead to
  https://github.com/draios/sysdig/pull/624, check the event type
  individually instead of as a set membership test, which is a bit
  faster.

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

- Move positive tests like etc_dir, bin_dir, sensitive_files,
  proc.sname, 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.

- Using exim as a mail program--exim also can suid to root.

- add a new macro for ssl management binaries and allow them to write
  below /etc and read sensitive files.

- add a new macro for dhcp client binaries and allow them to write below
  /etc.

- Add exe (docker-related program) as a program that can set a namespace
  using setns.

- Don't count /dev/tty as an important file under /dev.
2016-07-12 08:22:29 -07:00
Mark Stemm
8225dc0762 Merge pull request #98 from draios/add-lists
Add list support to rules file.
2016-07-11 16:05:29 -07:00
Mark Stemm
022614a98d Merge pull request #100 from draios/use-startswith
Utilize sysdig's startswith operator.
2016-07-11 15:04:43 -07:00
Mark Stemm
3cf0dd8ab0 Utilize sysdig's startswith operator.
https://github.com/draios/sysdig/pull/623 adds support for a startswith
operator to allow for string prefix matching. Modify the parser to
recognize that operator, and use that operator for rules that really
want to check the beginning of a pathname, directory, etc. to make them
faster and avoid FPs.
2016-07-11 13:30:58 -07:00
Mark Stemm
502941b804 Add list support to rules file.
Once sysdig adds support for handling "in (...)" filter expressions as
set membership tests, it will be advantageous to combine lists of items
together into a single list so they can all be checked in a single set
membership test.

This commit adds support for a new yaml item type "list" containing a
field "name" and field "items" containing a list of items. These are
represented as a yaml list, which allows yaml to handle some of the
initial parsing with the list items maintained natively in lua.

Allow lists to contain list references by expanding any references to
the items in the list, before storing the list items in
state.lists.

When parsing macro or rule conditions, replace all references to a list
name with the list items as a comma separated string.

Modify the falco rules to switch to lists whenever possible. The
new convention is to use the suffix _binaries for lists of program names
and _procs for macros that define a filter expression using the list.
2016-07-11 13:14:39 -07:00
Mark Stemm
d16bb8fd2c Merge pull request #97 from draios/nodejs-bad-rest-api
Example showing running bash via a bad rest api.
2016-07-07 15:58:05 -07:00
Mark Stemm
4a941df787 Example showing running bash via a bad rest api.
Simple docker-compose environment that starts a simple express server
with a poorly-designed /api/exec/<cmd> endpoint that executes arbitrary
commands, and uses falco to detect running bash.
2016-07-07 15:35:11 -07:00
Mark Stemm
7b26eb0eb1 Merge pull request #96 from draios/add-jq
Add jq library.
2016-06-28 14:10:00 -07:00
Mark Stemm
8426117ffd Add jq library.
JQ was added to sysdig in
20c20fc3a1,
so add it to the falco build.
2016-06-28 13:42:21 -07:00
Mark Stemm
8572f58c45 Merge pull request #93 from draios/add-examples
Docker-compose environment for mitm example.
2016-06-10 17:13:22 -07:00
Mark Stemm
139ee56af7 Docker-compose environment for mitm example.
Adding docker-compose based example of man-in-the-middle attack against
installation scripts and how it can be detected using sysdig falco.

The docker-compose environment starts a good web server, compromised
nginx installation, evil web server, and a copy of sysdig falco. The
README walks through the process of compromising a client by using curl
http://localhost/get-software.sh | bash and detecting the compromise
using ./fbash.

The fbash program included in this example fixes https://github.com/draios/falco/issues/46.
2016-06-10 16:39:59 -07:00
Mark Stemm
8d181e9051 Merge pull request #92 from draios/dev
Merging for 0.2.0
2016-06-09 10:40:20 -07:00
Mark Stemm
674e63eef0 Merge pull request #91 from draios/update-releasenotes-0_2_0
Add release notes for 0.2.0.
2016-06-09 09:57:25 -07:00
Mark Stemm
b8cd89757a Add release notes for 0.2.0.
Noting changes since 0.1.0.
2016-06-09 09:55:43 -07:00
Mark Stemm
85fd7c0227 Merge pull request #89 from draios/update-json-output
Add more useful json output.
2016-06-07 14:37:56 -07:00
Mark Stemm
995e61210e Add regression tests for json output.
Modify falco_test.py to look for a boolean multiplex attribute
'json_output'. If true, examine the lines of the output and for any line
that begins with '{', parse it as json and ensure it has the 4
attributes we expect.

Modify run_regression_tests to have a utility function
prepare_multiplex_fileset that does the work of looping over files in a
directory, along with detect, level, and json output arguments. The
appropriate multiplex attributes are added for each file.

Use that utility function to test json output for the positive and
informational  directories along with non-json output. The negative
directory is only tested once.
2016-06-07 14:04:53 -07:00
Mark Stemm
52a7c77596 Add more useful json output.
Instead of using sysdig's json output, which only contains the fields
from the format string without any formatting text, use the string
output to build a json object containing the format string, rule name,
severity, and the event time (converted to a json-friendly ISO8601).

This fixes https://github.com/draios/falco/issues/82.
2016-06-07 14:04:53 -07:00
Mark Stemm
9ab7f52fb0 Merge pull request #90 from draios/migrate-readme-to-wiki
Migrate README contents to wiki.
2016-06-07 11:57:10 -07:00
Mark Stemm
23322700b4 Migrate README contents to wiki.
Split up the content from the README into individual pages in the
wiki--that's in a separate change.
2016-06-07 10:18:16 -07:00
Mark Stemm
8ecdb80a73 Merge pull request #87 from draios/update-fbash-rules
Update fbash rules to use proc.sname.
2016-06-06 10:53:59 -07:00
Mark Stemm
fc6d775e5b Add additional rules/tests for pipe installers.
Add additional rules related to using pipe installers within a fbash
session:

 - Modify write_etc to only trigger if *not* in a fbash session. There's
   a new rule write_etc_installer which has the same conditions when in
   a fbash session, logging at INFO severity.

 - A new rule write_rpm_database warns if any non package management
   program tries to write below /var/lib/rpm.

 - Add a new warning if any program below a fbash session tries to open
   an outbound network connection on ports other than http(s) and dns.

 - Add INFO level messages when programs in a fbash session try to run
   package management binaries (rpm,yum,etc) or service
   management (systemctl,chkconfig,etc) binaries.

In order to test these new INFO level rules, make up a third class of
trace files traces-info.zip containing trace files that should result in
info-level messages.

To differentiate warning and info level detection, add an attribute to
the multiplex file "detect_level", which is "Warning" for the files in
traces-positive and "Info" for the files in traces-info. Modify
falco_test.py to look specifically for a non-zero count for the given
detect_level.

Doing this exposed a bug in the way the level-specific counts were being
recorded--they were keeping counts by level name, not number. Fix that.
2016-06-06 10:29:41 -07:00
Mark Stemm
31c87c295a Update fbash rules to use proc.sname.
Update fbash rules to use proc.sname instead of proc.aname and to rely
on sessions instead of process ancestors.

I also wanted to add details on the address/port being listened to but
that's blocked on https://github.com/draios/falco/issues/86.

Along with this change, there are new positive trace files
installer-bash-starts-network-server.scap and
installer-bash-starts-session.scap that test these updated rules.
2016-05-31 17:44:41 -07:00
Mark Stemm
e9cdd46838 Merge pull request #83 from draios/add-correctness-tests
Add correctness tests
2016-05-25 18:13:07 -07:00
Mark Stemm
0f4b378775 Add .gitignore for test directory.
Exclude trace directories.
2016-05-25 17:51:50 -07:00
Mark Stemm
b3ae480fac Another round of rule cleanups.
Do another round of rule cleanups now that we have a larger set of
positive and negative trace files to work with. Outside of this commit,
there are now trace files for all the positive rules, a docker-compose
startup and teardown, and some trace files from the sysdig cloud staging
environment.

Also add a script that runs sysdig with a filter that removes all the
syscalls not handled by falco as well as a few other high-volume,
low-information syscalls. This script was used to create the staging
environment trace files.

Notable rule changes:

 - The direction for write_binary_dir/write_etc needs to be exit instead
   of enter, as the bin_dir clause works on the file descriptor returned
   by the open/openat call.

 - Add login as a trusted binary that can read sensitive files (occurs
   for direct console logins).

 - sshd can read sensitive files well after startup, so exclude it from
   the set of binaries that can trigger
   read_sensitive_file_trusted_after_startup.

 - limit run_shell_untrusted to non-containers.

 - Disable the ssh_error_syslog rule for now. With the current
   restriction on system calls (no read/write/sendto/recvfrom/etc), you
   won't see the ssh error messages. Nevertheless, add a string to look
   for to indicate ssh errors and add systemd's true location for the
   syslog device.

 - Sshd attemps to setuid even when it's not running as root, so exclude
   it from the set of binaries to monitor for now.

 - Let programs that are direct decendants of systemd spawn user
   management tasks for now.

 - Temporarily disable the EACCESS rule. This rule is exposing a bug in
   sysdig in debug mode, https://github.com/draios/sysdig/issues/598. The
   rule is also pretty noisy so I'll keep it disabled until the sysdig bug
   is fixed.

 - The etc_dir and bin_dir macros both have the problem that they match
   pathnames with /etc/, /bin/, etc in the middle of the path, as sysdig
   doesn't have a "begins with" comparison. Add notes for that.

 - Change spawn_process to spawned_process to indicate that it's for the
   exit side of the execve. Also use it in a few places that were
   looking for the same conditions without any macro.

 - Get rid of adduser_binaries and fold any programs not already present
   into shadowutils_binaries.

 - Add new groups sysdigcloud_binaries and sysdigcloud_binaries_parent
   and add them as exceptions for write_etc/write_binary_dir.

 - Add yum as a package management binary and add it as an exception to
   write_etc/write_binary_dir.

 - Change how db_program_spawned_process works. Since all of the useful
   information is on the exit side of the event, you can't really add a
   condition based on the process being new. Isntead, have the rule
   check for a non-database-related program being spawned by a
   database-related program.

 - Allow dragent to run shells.

 - Add sendmail, sendmail-msp as a program that attempts to setuid.

 - Some of the *_binaries macros that were based on dpkg -L accidentally
   contained directories in addition to end files. Trim those.

 - Add systemd-logind as a login_binary.

 - Add unix_chkpwd as a shadowutils_binary.

 - Add parentheses around any macros that group items using or. I found
   this necessary when the macro is used in the middle of a list of and
   conditions.

 - Break out system_binaries into a new subset user_mgmt_binaries
   containing login_, passwd_, and shadowutils_ binaries. That way you
   don't have to pull in all of system_binaries when looking for
   sensisitive files or user management activity.

 - Rename fs-bash to fbash, thinking ahead to its more likely name.
2016-05-25 17:40:01 -07:00
Mark Stemm
4751546c03 Add correctness tests using Avocado
Start using the Avocado framework for automated regression
testing. Create a test FalcoTest in falco_test.py which can run on a
collection of trace files. The script test/run_regression_tests.sh is
responsible for pulling zip files containing the positive (falco should
detect) and negative (falco should not detect) trace files, creating a
Avocado multiplex file that defines all the tests (one for each trace
file), running avocado on all the trace files, and showing full logs for
any test that didn't pass.

The old regression script, which simply ran falco, has been removed.

Modify falco's stats output to show the total number of events detected
for use in the tests.

In travis.yml, pull a known stable version of avocado and build it,
including installing any dependencies, as a part of the build process.
2016-05-24 13:56:48 -07:00
Mark Stemm
a41bb0dac0 Print stats when shutting down.
At shutdown, print stats on the number of rules triggered by severity
and rule name. This is done by a lua function print_stats and the
associated table rule_output_counts.

When passing rules to outputs, update the counts in rule_output_counts.
2016-05-24 13:56:48 -07:00
Mark Stemm
1a2719437f Add graceful shutdown on SIGINT/SIGTERM.
Add signal handlers for SIGINT/SIGTERM that set a shutdown
flag. Initialize the live inspector with a timeout so the main loop can
watch the flag set by the signal handlers.
2016-05-24 13:56:48 -07:00
Mark Stemm
18f4a20338 Merge pull request #84 from draios/cmake-cleanups
Quote path variables that may contain spaces.
2016-05-24 09:44:23 -07:00
Mark Stemm
583afbf941 Merge pull request #85 from draios/remove-unnecessary-delete
Don't null-check inspector.
2016-05-24 09:24:15 -07:00
Mark Stemm
66cedc89f2 Don't null-check inspector.
delete(NULL) is ok so don't bother protecting it.
2016-05-23 17:24:38 -07:00
Mark Stemm
2237532ff0 Quote path variables that may contain spaces.
Make sure that references to variables that may be paths (which in turn
may contain spaces) are quoted, so cmake won't break on the spaces.

This fixes https://github.com/draios/falco/issues/79.
2016-05-23 17:20:15 -07:00
Henri DF
22dce61974 Readme.md: overview tweaks 2016-05-18 09:32:04 -07:00
Mark Stemm
acbb2f5862 Merge pull request #76 from draios/add-travis
Add minimal travis support.
2016-05-17 22:43:03 -07:00
Mark Stemm
450c347ef3 Add a basic test to run falco.
Add a basic test that loads the kernel module from the source directory
and runs falco. No testing of behavior yet.
2016-05-17 17:43:09 -07:00
Mark Stemm
467fe33e37 Add travis badges.
Showing both dev/master branches for now.
2016-05-17 16:19:18 -07:00
Mark Stemm
c9d2550ecd Add minimal travis support.
Add minimal travis.yml file that builds and packages falco. No actual
tests yet.
2016-05-17 16:16:34 -07:00
Henri DF
b5055e34af Merge pull request #75 from draios/readme-release-info
Readme tweaks
2016-05-17 14:17:20 -07:00
Henri DF
5fe663e62a readme: lowercase falco 2016-05-17 20:46:51 +00:00
Henri DF
38caea4388 README: add "latest release" section 2016-05-17 20:46:50 +00:00
Henri DF
260b96167c README: Minor format changes, remove tagline 2016-05-17 13:33:57 -07:00
Mark Stemm
0ed09d72db Use 0.1.0 as initial version.
This is a bit more consistent with sysdig.
2016-05-17 12:52:03 -07:00
Henri DF
d33ab98822 Merge pull request #74 from draios/remove-old-rule-examples
Remove outdated rule examples
2016-05-17 11:40:12 -07:00
Henri DF
6b749b3a5c Remove outdated rule examples 2016-05-17 18:36:26 +00:00
Mark Stemm
aec85ad6f3 Merge pull request #73 from draios/initial-changelog
Initial CHANGELOG.
2016-05-17 11:27:04 -07:00
Mark Stemm
88c903e6ba Initial CHANGELOG.
This will contain the changes for each release.
2016-05-17 11:26:22 -07:00
Mark Stemm
084267ae32 Merge pull request #71 from draios/rule-perf-improvements
Additional rule cleanups to improve performance.
2016-05-17 11:17:04 -07:00
Mark Stemm
ff9907b552 Merge pull request #66 from draios/add-community-readme
Add community links to README.
2016-05-17 09:36:01 -07:00
Henri DF
d373644bc1 Readme.md: update ignored syscalls
https://github.com/draios/sysdig/pull/592
2016-05-16 17:58:06 -07:00
Mark Stemm
6b58e94068 Add community links to README.
Falco for mailing list and slack. Use the general sysdig
twitter. Sysdig.com is the host for the blog but there's a link to posts
tagged with falco.
2016-05-16 17:46:21 -07:00