Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gen events falco engine #1715

Merged
merged 18 commits into from
Oct 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmake/modules/falcosecurity-libs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ file(MAKE_DIRECTORY ${FALCOSECURITY_LIBS_CMAKE_WORKING_DIR})
# default below In case you want to test against another falcosecurity/libs version just pass the variable - ie., `cmake
# -DFALCOSECURITY_LIBS_VERSION=dev ..`
if(NOT FALCOSECURITY_LIBS_VERSION)
set(FALCOSECURITY_LIBS_VERSION "3aa7a83bf7b9e6229a3824e3fd1f4452d1e95cb4")
set(FALCOSECURITY_LIBS_CHECKSUM "SHA256=1edb535b3778fcfb46bbeeda891f176a1bd591bebd7b89c27f04837e55a52beb")
set(FALCOSECURITY_LIBS_VERSION "a03ccfda795f2ba711b80f69cb06869f2b63121b")
set(FALCOSECURITY_LIBS_CHECKSUM "SHA256=97ce5c30b985b77e1abb04ef7037c69be176cbe2122acf67a7f6ec6b39dbdc27")
endif()

# cd /path/to/build && cmake /path/to/source
Expand Down
2 changes: 1 addition & 1 deletion rules/falco_rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@
# for efficiency.
- macro: inbound_outbound
condition: >
((((evt.type in (accept,listen,connect) and evt.dir=<)) or
((((evt.type in (accept,listen,connect) and evt.dir=<)) and
mstemm marked this conversation as resolved.
Show resolved Hide resolved
(fd.typechar = 4 or fd.typechar = 6)) and
(fd.ip != "0.0.0.0" and fd.net != "127.0.0.0/8") and
(evt.rawres >= 0 or evt.res = EINPROGRESS))
Expand Down
19 changes: 6 additions & 13 deletions test/falco_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,10 @@ trace_files: !mux
- leading_not
- not_equals_at_end
- not_at_end
- not_before_trailing_evttype
- not_equals_before_trailing_evttype
- not_equals_and_not
- not_equals_before_in
- not_before_in
- not_in_before_in
- leading_in_not_equals_before_evttype
- leading_in_not_equals_at_evttype
- not_with_evttypes
- not_with_evttypes_addl
- not_equals_before_evttype
- not_equals_before_in_evttype
- not_before_evttype
- not_before_evttype_using_in
rules_events:
- no_warnings: [execve]
- no_evttype: [all]
Expand Down Expand Up @@ -1142,6 +1132,8 @@ trace_files: !mux
detect_level: INFO
rules_file:
- rules/syscalls.yaml
rules_warning:
- detect_madvise
detect_counts:
- detect_madvise: 2
- detect_open: 2
Expand All @@ -1160,7 +1152,8 @@ trace_files: !mux

skip_unknown_noevt:
detect: False
stdout_contains: Skipping rule "Contains Unknown Event And Skipping". contains unknown filter proc.nobody
rules_warning:
- Contains Unknown Event And Skipping
rules_file:
- rules/skip_unknown_evt.yaml
trace_file: trace_files/cat_write.scap
Expand All @@ -1175,7 +1168,7 @@ trace_files: !mux
exit_status: 1
stderr_contains: |+
Could not load rules file.*skip_unknown_error.yaml: 1 errors:
rule "Contains Unknown Event And Not Skipping". contains unknown filter proc.nobody
Rule Contains Unknown Event And Not Skipping: error filter_check called with nonexistent field proc.nobody
---
- rule: Contains Unknown Event And Not Skipping
desc: Contains an unknown event
Expand All @@ -1192,7 +1185,7 @@ trace_files: !mux
exit_status: 1
stderr_contains: |+
Could not load rules file .*skip_unknown_unspec.yaml: 1 errors:
rule "Contains Unknown Event And Unspecified". contains unknown filter proc.nobody
Rule Contains Unknown Event And Unspecified: error filter_check called with nonexistent field proc.nobody
---
- rule: Contains Unknown Event And Unspecified
desc: Contains an unknown event
Expand Down
11 changes: 8 additions & 3 deletions test/falco_traces.yaml.in
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,17 @@ traces: !mux
detect_counts:
- "Read sensitive file untrusted": 1

# This should *not* generate any falco alerts as of the changes in
# https://github.com/falcosecurity/libs/pull/94--the execve event in
# this trace file is PPME_SYSCALL_EXECVE_18, which was deprecated by
# PPME_SYSCALL_EXECVE_19 in 2018.
#
# This activity in this trace file overlaps with the activity in
# falco-event-generator.scap so the rule is still being tested.
run-shell-untrusted:
trace_file: traces-positive/run-shell-untrusted.scap
detect: True
detect: False
detect_level: DEBUG
detect_counts:
- "Run shell untrusted": 1

system-binaries-network-activity:
trace_file: traces-positive/system-binaries-network-activity.scap
Expand Down
4 changes: 2 additions & 2 deletions test/rules/rule_append.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
#
- rule: my_rule
desc: A process named cat does an open
condition: evt.type=open and fd.name=not-a-real-file
condition: (evt.type=open and fd.name=not-a-real-file)
output: "An open of /dev/null was seen (command=%proc.cmdline)"
priority: WARNING

- rule: my_rule
append: true
condition: or fd.name=/dev/null
condition: or (evt.type=open and fd.name=/dev/null)
72 changes: 41 additions & 31 deletions tests/engine/test_rulesets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,25 @@ static uint16_t default_ruleset = 0;
static uint16_t non_default_ruleset = 3;
static uint16_t other_non_default_ruleset = 2;
static std::set<std::string> tags = {"some_tag", "some_other_tag"};
static std::set<uint32_t> event_tags = {1};

static std::shared_ptr<gen_event_filter> create_filter()
{
// The actual contents of the filters don't matter here.
sinsp_filter_compiler compiler(NULL, "evt.type=open");
sinsp_filter *f = compiler.compile();

std::shared_ptr<gen_event_filter> ret(f);

return ret;
}

TEST_CASE("Should enable/disable for exact match w/ default ruleset", "[rulesets]")
{
falco_ruleset r;
gen_event_filter *filter = new gen_event_filter();
std::shared_ptr<gen_event_filter> filter = create_filter();
string rule_name = "one_rule";

r.add(rule_name, tags, event_tags, filter);
r.add(rule_name, tags, filter);

r.enable("one_rule", exact_match, enabled);
REQUIRE(r.num_rules_for_ruleset(default_ruleset) == 1);
Expand All @@ -45,10 +55,10 @@ TEST_CASE("Should enable/disable for exact match w/ default ruleset", "[rulesets
TEST_CASE("Should enable/disable for exact match w/ specific ruleset", "[rulesets]")
{
falco_ruleset r;
gen_event_filter *filter = new gen_event_filter();
std::shared_ptr<gen_event_filter> filter = create_filter();
string rule_name = "one_rule";

r.add(rule_name, tags, event_tags, filter);
r.add(rule_name, tags, filter);

r.enable("one_rule", exact_match, enabled, non_default_ruleset);
REQUIRE(r.num_rules_for_ruleset(non_default_ruleset) == 1);
Expand All @@ -64,10 +74,10 @@ TEST_CASE("Should enable/disable for exact match w/ specific ruleset", "[ruleset
TEST_CASE("Should not enable for exact match different rule name", "[rulesets]")
{
falco_ruleset r;
gen_event_filter *filter = new gen_event_filter();
std::shared_ptr<gen_event_filter> filter = create_filter();
string rule_name = "one_rule";

r.add(rule_name, tags, event_tags, filter);
r.add(rule_name, tags, filter);

r.enable("some_other_rule", exact_match, enabled);
REQUIRE(r.num_rules_for_ruleset(default_ruleset) == 0);
Expand All @@ -76,10 +86,10 @@ TEST_CASE("Should not enable for exact match different rule name", "[rulesets]")
TEST_CASE("Should enable/disable for exact match w/ substring and default ruleset", "[rulesets]")
{
falco_ruleset r;
gen_event_filter *filter = new gen_event_filter();
std::shared_ptr<gen_event_filter> filter = create_filter();
string rule_name = "one_rule";

r.add(rule_name, tags, event_tags, filter);
r.add(rule_name, tags, filter);

r.enable("one_rule", substring_match, enabled);
REQUIRE(r.num_rules_for_ruleset(default_ruleset) == 1);
Expand All @@ -91,10 +101,10 @@ TEST_CASE("Should enable/disable for exact match w/ substring and default rulese
TEST_CASE("Should not enable for substring w/ exact_match", "[rulesets]")
{
falco_ruleset r;
gen_event_filter *filter = new gen_event_filter();
std::shared_ptr<gen_event_filter> filter = create_filter();
string rule_name = "one_rule";

r.add(rule_name, tags, event_tags, filter);
r.add(rule_name, tags, filter);

r.enable("one_", exact_match, enabled);
REQUIRE(r.num_rules_for_ruleset(default_ruleset) == 0);
Expand All @@ -103,10 +113,10 @@ TEST_CASE("Should not enable for substring w/ exact_match", "[rulesets]")
TEST_CASE("Should enable/disable for prefix match w/ default ruleset", "[rulesets]")
{
falco_ruleset r;
gen_event_filter *filter = new gen_event_filter();
std::shared_ptr<gen_event_filter> filter = create_filter();
string rule_name = "one_rule";

r.add(rule_name, tags, event_tags, filter);
r.add(rule_name, tags, filter);

r.enable("one_", substring_match, enabled);
REQUIRE(r.num_rules_for_ruleset(default_ruleset) == 1);
Expand All @@ -118,10 +128,10 @@ TEST_CASE("Should enable/disable for prefix match w/ default ruleset", "[ruleset
TEST_CASE("Should enable/disable for suffix match w/ default ruleset", "[rulesets]")
{
falco_ruleset r;
gen_event_filter *filter = new gen_event_filter();
std::shared_ptr<gen_event_filter> filter = create_filter();
string rule_name = "one_rule";

r.add(rule_name, tags, event_tags, filter);
r.add(rule_name, tags, filter);

r.enable("_rule", substring_match, enabled);
REQUIRE(r.num_rules_for_ruleset(default_ruleset) == 1);
Expand All @@ -133,10 +143,10 @@ TEST_CASE("Should enable/disable for suffix match w/ default ruleset", "[ruleset
TEST_CASE("Should enable/disable for substring match w/ default ruleset", "[rulesets]")
{
falco_ruleset r;
gen_event_filter *filter = new gen_event_filter();
std::shared_ptr<gen_event_filter> filter = create_filter();
string rule_name = "one_rule";

r.add(rule_name, tags, event_tags, filter);
r.add(rule_name, tags, filter);

r.enable("ne_ru", substring_match, enabled);
REQUIRE(r.num_rules_for_ruleset(default_ruleset) == 1);
Expand All @@ -148,10 +158,10 @@ TEST_CASE("Should enable/disable for substring match w/ default ruleset", "[rule
TEST_CASE("Should enable/disable for substring match w/ specific ruleset", "[rulesets]")
{
falco_ruleset r;
gen_event_filter *filter = new gen_event_filter();
std::shared_ptr<gen_event_filter> filter = create_filter();
string rule_name = "one_rule";

r.add(rule_name, tags, event_tags, filter);
r.add(rule_name, tags, filter);

r.enable("ne_ru", substring_match, enabled, non_default_ruleset);
REQUIRE(r.num_rules_for_ruleset(non_default_ruleset) == 1);
Expand All @@ -167,11 +177,11 @@ TEST_CASE("Should enable/disable for substring match w/ specific ruleset", "[rul
TEST_CASE("Should enable/disable for tags w/ default ruleset", "[rulesets]")
{
falco_ruleset r;
gen_event_filter *filter = new gen_event_filter();
std::shared_ptr<gen_event_filter> filter = create_filter();
string rule_name = "one_rule";
std::set<std::string> want_tags = {"some_tag"};

r.add(rule_name, tags, event_tags, filter);
r.add(rule_name, tags, filter);

r.enable_tags(want_tags, enabled);
REQUIRE(r.num_rules_for_ruleset(default_ruleset) == 1);
Expand All @@ -183,11 +193,11 @@ TEST_CASE("Should enable/disable for tags w/ default ruleset", "[rulesets]")
TEST_CASE("Should enable/disable for tags w/ specific ruleset", "[rulesets]")
{
falco_ruleset r;
gen_event_filter *filter = new gen_event_filter();
std::shared_ptr<gen_event_filter> filter = create_filter();
string rule_name = "one_rule";
std::set<std::string> want_tags = {"some_tag"};

r.add(rule_name, tags, event_tags, filter);
r.add(rule_name, tags, filter);

r.enable_tags(want_tags, enabled, non_default_ruleset);
REQUIRE(r.num_rules_for_ruleset(non_default_ruleset) == 1);
Expand All @@ -203,11 +213,11 @@ TEST_CASE("Should enable/disable for tags w/ specific ruleset", "[rulesets]")
TEST_CASE("Should not enable for different tags", "[rulesets]")
{
falco_ruleset r;
gen_event_filter *filter = new gen_event_filter();
std::shared_ptr<gen_event_filter> filter = create_filter();
string rule_name = "one_rule";
std::set<std::string> want_tags = {"some_different_tag"};

r.add(rule_name, tags, event_tags, filter);
r.add(rule_name, tags, filter);

r.enable_tags(want_tags, enabled);
REQUIRE(r.num_rules_for_ruleset(non_default_ruleset) == 0);
Expand All @@ -216,11 +226,11 @@ TEST_CASE("Should not enable for different tags", "[rulesets]")
TEST_CASE("Should enable/disable for overlapping tags", "[rulesets]")
{
falco_ruleset r;
gen_event_filter *filter = new gen_event_filter();
std::shared_ptr<gen_event_filter> filter = create_filter();
string rule_name = "one_rule";
std::set<std::string> want_tags = {"some_tag", "some_different_tag"};

r.add(rule_name, tags, event_tags, filter);
r.add(rule_name, tags, filter);

r.enable_tags(want_tags, enabled);
REQUIRE(r.num_rules_for_ruleset(default_ruleset) == 1);
Expand All @@ -232,15 +242,15 @@ TEST_CASE("Should enable/disable for overlapping tags", "[rulesets]")
TEST_CASE("Should enable/disable for incremental adding tags", "[rulesets]")
{
falco_ruleset r;
gen_event_filter *rule1_filter = new gen_event_filter();
std::shared_ptr<gen_event_filter> rule1_filter = create_filter();
string rule1_name = "one_rule";
std::set<std::string> rule1_tags = {"rule1_tag"};
r.add(rule1_name, rule1_tags, event_tags, rule1_filter);
r.add(rule1_name, rule1_tags, rule1_filter);

gen_event_filter *rule2_filter = new gen_event_filter();
std::shared_ptr<gen_event_filter> rule2_filter = create_filter();
string rule2_name = "two_rule";
std::set<std::string> rule2_tags = {"rule2_tag"};
r.add(rule2_name, rule2_tags, event_tags, rule2_filter);
r.add(rule2_name, rule2_tags, rule2_filter);

std::set<std::string> want_tags;

Expand Down
5 changes: 0 additions & 5 deletions userspace/engine/falco_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ falco_common::~falco_common()
}
}

void falco_common::set_inspector(sinsp *inspector)
{
m_inspector = inspector;
}

void falco_common::init(const char *lua_main_filename, const char *alternate_lua_dir)
{
ifstream is;
Expand Down
6 changes: 1 addition & 5 deletions userspace/engine/falco_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ class falco_common

void init(const char *lua_main_filename, const char *alternate_lua_dir);

void set_inspector(sinsp *inspector);

// Priority levels, as a vector of strings
static std::vector<std::string> priority_names;

Expand All @@ -94,8 +92,6 @@ class falco_common

std::mutex m_ls_semaphore;

sinsp *m_inspector;

private:
void add_lua_path(std::string &path);
};
};
Loading