tcell_agent 0.4.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +9 -22
- data/bin/tcell_agent +127 -132
- data/lib/tcell_agent/agent/event_processor.rb +23 -22
- data/lib/tcell_agent/agent/fork_pipe_manager.rb +7 -7
- data/lib/tcell_agent/agent/policy_manager.rb +20 -15
- data/lib/tcell_agent/agent/policy_types.rb +5 -11
- data/lib/tcell_agent/agent/static_agent.rb +5 -1
- data/lib/tcell_agent/agent.rb +6 -4
- data/lib/tcell_agent/api.rb +7 -9
- data/lib/tcell_agent/appsensor/meta_data.rb +11 -4
- data/lib/tcell_agent/authlogic.rb +3 -3
- data/lib/tcell_agent/cmdi.rb +6 -4
- data/lib/tcell_agent/config/unknown_options.rb +3 -1
- data/lib/tcell_agent/configuration.rb +47 -49
- data/lib/tcell_agent/devise.rb +2 -2
- data/lib/tcell_agent/hooks/login_fraud.rb +58 -29
- data/lib/tcell_agent/instrumentation.rb +11 -10
- data/lib/tcell_agent/logger.rb +2 -2
- data/lib/tcell_agent/patches/meta_data.rb +9 -13
- data/lib/tcell_agent/patches.rb +7 -10
- data/lib/tcell_agent/policies/clickjacking_policy.rb +4 -5
- data/lib/tcell_agent/policies/content_security_policy.rb +6 -12
- data/lib/tcell_agent/policies/dataloss_policy.rb +2 -2
- data/lib/tcell_agent/policies/http_redirect_policy.rb +2 -2
- data/lib/tcell_agent/policies/policy.rb +0 -2
- data/lib/tcell_agent/policies/rust_policies.rb +90 -0
- data/lib/tcell_agent/policies/secure_headers_policy.rb +2 -2
- data/lib/tcell_agent/rails/auth/authlogic.rb +42 -24
- data/lib/tcell_agent/rails/auth/devise.rb +44 -23
- data/lib/tcell_agent/rails/auth/doorkeeper.rb +33 -15
- data/lib/tcell_agent/rails/better_ip.rb +1 -1
- data/lib/tcell_agent/rails/csrf_exception.rb +2 -2
- data/lib/tcell_agent/rails/dlp/process_request.rb +1 -1
- data/lib/tcell_agent/rails/dlp.rb +6 -6
- data/lib/tcell_agent/rails/dlp_handler.rb +1 -1
- data/lib/tcell_agent/rails/js_agent_insert.rb +1 -1
- data/lib/tcell_agent/rails/middleware/body_filter_middleware.rb +1 -1
- data/lib/tcell_agent/rails/middleware/context_middleware.rb +3 -2
- data/lib/tcell_agent/rails/middleware/headers_middleware.rb +10 -9
- data/lib/tcell_agent/rails/routes/grape.rb +6 -6
- data/lib/tcell_agent/rails/routes.rb +8 -11
- data/lib/tcell_agent/rust/libtcellagent-0.11.1.dylib +0 -0
- data/lib/tcell_agent/rust/{libtcellagent-0.6.1.so → libtcellagent-0.11.1.so} +0 -0
- data/lib/tcell_agent/rust/models.rb +16 -0
- data/lib/tcell_agent/rust/tcellagent-0.11.1.dll +0 -0
- data/lib/tcell_agent/rust/whisperer.rb +119 -48
- data/lib/tcell_agent/sensor_events/appsensor_meta_event.rb +17 -20
- data/lib/tcell_agent/sensor_events/command_injection.rb +50 -5
- data/lib/tcell_agent/sensor_events/login_fraud.rb +34 -18
- data/lib/tcell_agent/sensor_events/patches.rb +21 -0
- data/lib/tcell_agent/sensor_events/server_agent.rb +3 -3
- data/lib/tcell_agent/sensor_events/util/utils.rb +4 -3
- data/lib/tcell_agent/servers/puma.rb +2 -2
- data/lib/tcell_agent/servers/unicorn.rb +1 -1
- data/lib/tcell_agent/utils/passwords.rb +28 -0
- data/lib/tcell_agent/version.rb +1 -1
- data/lib/tcell_agent.rb +1 -5
- data/spec/apps/rails-3.2/config/tcell_agent.config +15 -0
- data/spec/apps/rails-3.2/log/development.log +0 -0
- data/spec/apps/rails-3.2/log/test.log +12 -0
- data/spec/apps/rails-4.1/log/test.log +0 -0
- data/spec/lib/tcell_agent/agent/fork_pipe_manager_spec.rb +46 -45
- data/spec/lib/tcell_agent/agent/policy_manager_spec.rb +276 -164
- data/spec/lib/tcell_agent/agent/static_agent_spec.rb +44 -47
- data/spec/lib/tcell_agent/api/api_spec.rb +16 -16
- data/spec/lib/tcell_agent/appsensor/injections_reporter_spec.rb +131 -116
- data/spec/lib/tcell_agent/appsensor/meta_data_spec.rb +55 -51
- data/spec/lib/tcell_agent/cmdi_spec.rb +413 -436
- data/spec/lib/tcell_agent/config/unknown_options_spec.rb +145 -128
- data/spec/lib/tcell_agent/configuration_spec.rb +165 -169
- data/spec/lib/tcell_agent/hooks/login_fraud_spec.rb +144 -153
- data/spec/lib/tcell_agent/instrumentation_spec.rb +84 -85
- data/spec/lib/tcell_agent/patches_spec.rb +70 -111
- data/spec/lib/tcell_agent/policies/appsensor_policy_spec.rb +313 -244
- data/spec/lib/tcell_agent/policies/clickjacking_policy_spec.rb +28 -28
- data/spec/lib/tcell_agent/policies/command_injection_policy_spec.rb +643 -513
- data/spec/lib/tcell_agent/policies/content_security_policy_spec.rb +55 -102
- data/spec/lib/tcell_agent/policies/dataloss_policy_spec.rb +111 -134
- data/spec/lib/tcell_agent/policies/http_redirect_policy_spec.rb +141 -146
- data/spec/lib/tcell_agent/policies/http_tx_policy_spec.rb +8 -8
- data/spec/lib/tcell_agent/policies/login_policy_spec.rb +15 -17
- data/spec/lib/tcell_agent/policies/patches_policy_spec.rb +231 -559
- data/spec/lib/tcell_agent/policies/secure_headers_policy_spec.rb +27 -27
- data/spec/lib/tcell_agent/rails/better_ip_spec.rb +30 -34
- data/spec/lib/tcell_agent/rails/logger_spec.rb +50 -49
- data/spec/lib/tcell_agent/rails/middleware/appsensor_middleware_spec.rb +182 -199
- data/spec/lib/tcell_agent/rails/middleware/dlp_middleware_spec.rb +110 -84
- data/spec/lib/tcell_agent/rails/middleware/global_middleware_spec.rb +107 -85
- data/spec/lib/tcell_agent/rails/middleware/redirect_middleware_spec.rb +68 -40
- data/spec/lib/tcell_agent/rails/middleware/tcell_body_proxy_spec.rb +81 -67
- data/spec/lib/tcell_agent/rails/responses_spec.rb +33 -37
- data/spec/lib/tcell_agent/rails/routes/grape_spec.rb +116 -121
- data/spec/lib/tcell_agent/rails/routes/route_id_spec.rb +25 -28
- data/spec/lib/tcell_agent/rails/routes/routes_spec.rb +87 -85
- data/spec/lib/tcell_agent/rails_spec.rb +1 -6
- data/spec/lib/tcell_agent/rust/models_spec.rb +112 -0
- data/spec/lib/tcell_agent/rust/whisperer_spec.rb +502 -179
- data/spec/lib/tcell_agent/sensor_events/appsensor_meta_event_spec.rb +44 -33
- data/spec/lib/tcell_agent/sensor_events/dlp_spec.rb +4 -4
- data/spec/lib/tcell_agent/sensor_events/sessions_metric_spec.rb +183 -169
- data/spec/lib/tcell_agent/sensor_events/util/sanitizer_utilities_spec.rb +25 -25
- data/spec/lib/tcell_agent/utils/bounded_queue_spec.rb +17 -20
- data/spec/lib/tcell_agent/utils/params_spec.rb +28 -28
- data/spec/lib/tcell_agent/utils/passwords_spec.rb +143 -0
- data/spec/lib/tcell_agent/utils/strings_spec.rb +35 -35
- data/spec/lib/tcell_agent_spec.rb +8 -8
- data/spec/spec_helper.rb +4 -4
- data/spec/support/middleware_helper.rb +10 -10
- data/spec/support/static_agent_overrides.rb +16 -12
- data/tcell_agent.gemspec +17 -33
- metadata +43 -198
- data/LICENSE_libinjection +0 -32
- data/Readme.txt +0 -7
- data/ext/libinjection/extconf.rb +0 -3
- data/ext/libinjection/libinjection.h +0 -65
- data/ext/libinjection/libinjection_html5.c +0 -847
- data/ext/libinjection/libinjection_html5.h +0 -54
- data/ext/libinjection/libinjection_sqli.c +0 -2317
- data/ext/libinjection/libinjection_sqli.h +0 -295
- data/ext/libinjection/libinjection_sqli_data.h +0 -9004
- data/ext/libinjection/libinjection_wrap.c +0 -3525
- data/ext/libinjection/libinjection_xss.c +0 -531
- data/ext/libinjection/libinjection_xss.h +0 -21
- data/lib/tcell_agent/appsensor/injections_matcher.rb +0 -155
- data/lib/tcell_agent/appsensor/rules/appsensor_rule_manager.rb +0 -49
- data/lib/tcell_agent/appsensor/rules/appsensor_rule_set.rb +0 -67
- data/lib/tcell_agent/appsensor/rules/baserules.json +0 -467
- data/lib/tcell_agent/patches/block_rule.rb +0 -93
- data/lib/tcell_agent/patches/sensors_matcher.rb +0 -31
- data/lib/tcell_agent/policies/appsensor/cmdi_sensor.rb +0 -23
- data/lib/tcell_agent/policies/appsensor/fpt_sensor.rb +0 -23
- data/lib/tcell_agent/policies/appsensor/injection_sensor.rb +0 -117
- data/lib/tcell_agent/policies/appsensor/nullbyte_sensor.rb +0 -26
- data/lib/tcell_agent/policies/appsensor/retr_sensor.rb +0 -22
- data/lib/tcell_agent/policies/appsensor/sqli_sensor.rb +0 -34
- data/lib/tcell_agent/policies/appsensor/xss_sensor.rb +0 -34
- data/lib/tcell_agent/policies/appsensor_policy.rb +0 -49
- data/lib/tcell_agent/policies/command_injection_policy.rb +0 -196
- data/lib/tcell_agent/policies/honeytokens_policy.rb +0 -69
- data/lib/tcell_agent/policies/patches_policy.rb +0 -84
- data/lib/tcell_agent/rust/libtcellagent-0.6.1.dylib +0 -0
- data/lib/tcell_agent/rust/tcellagent-0.6.1.dll +0 -0
- data/spec/apps/rails-3.2/Gemfile +0 -25
- data/spec/apps/rails-3.2/Gemfile.lock +0 -126
- data/spec/apps/rails-3.2/Rakefile +0 -7
- data/spec/apps/rails-3.2/app/assets/images/rails.png +0 -0
- data/spec/apps/rails-3.2/app/assets/javascripts/application.js +0 -15
- data/spec/apps/rails-3.2/app/assets/stylesheets/application.css +0 -13
- data/spec/apps/rails-3.2/app/controllers/application_controller.rb +0 -3
- data/spec/apps/rails-3.2/app/controllers/t_cell_app_controller.rb +0 -5
- data/spec/apps/rails-3.2/app/helpers/application_helper.rb +0 -2
- data/spec/apps/rails-3.2/app/views/layouts/application.html.erb +0 -14
- data/spec/apps/rails-3.2/app/views/t_cell_app/index.html.erb +0 -1
- data/spec/apps/rails-3.2/config/application.rb +0 -63
- data/spec/apps/rails-3.2/config/boot.rb +0 -6
- data/spec/apps/rails-3.2/config/environment.rb +0 -5
- data/spec/apps/rails-3.2/config/environments/test.rb +0 -37
- data/spec/apps/rails-3.2/config/routes.rb +0 -11
- data/spec/apps/rails-3.2/config.ru +0 -4
- data/spec/apps/rails-4.1/Gemfile +0 -7
- data/spec/apps/rails-4.1/Gemfile.lock +0 -114
- data/spec/apps/rails-4.1/Rakefile +0 -6
- data/spec/apps/rails-4.1/app/assets/javascripts/application.js +0 -16
- data/spec/apps/rails-4.1/app/assets/stylesheets/application.css +0 -15
- data/spec/apps/rails-4.1/app/controllers/application_controller.rb +0 -5
- data/spec/apps/rails-4.1/app/controllers/t_cell_app_controller.rb +0 -5
- data/spec/apps/rails-4.1/app/helpers/application_helper.rb +0 -2
- data/spec/apps/rails-4.1/app/views/layouts/application.html.erb +0 -14
- data/spec/apps/rails-4.1/app/views/t_cell_app/index.html.erb +0 -1
- data/spec/apps/rails-4.1/config/application.rb +0 -24
- data/spec/apps/rails-4.1/config/boot.rb +0 -4
- data/spec/apps/rails-4.1/config/environment.rb +0 -5
- data/spec/apps/rails-4.1/config/environments/test.rb +0 -41
- data/spec/apps/rails-4.1/config/initializers/assets.rb +0 -8
- data/spec/apps/rails-4.1/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/apps/rails-4.1/config/initializers/cookies_serializer.rb +0 -3
- data/spec/apps/rails-4.1/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/apps/rails-4.1/config/initializers/inflections.rb +0 -16
- data/spec/apps/rails-4.1/config/initializers/mime_types.rb +0 -4
- data/spec/apps/rails-4.1/config/initializers/session_store.rb +0 -3
- data/spec/apps/rails-4.1/config/initializers/wrap_parameters.rb +0 -14
- data/spec/apps/rails-4.1/config/locales/en.yml +0 -23
- data/spec/apps/rails-4.1/config/routes.rb +0 -12
- data/spec/apps/rails-4.1/config/secrets.yml +0 -22
- data/spec/apps/rails-4.1/config.ru +0 -4
- data/spec/controllers/application_controller.rb +0 -12
- data/spec/lib/tcell_agent/appsensor/injections_matcher_spec.rb +0 -522
- data/spec/lib/tcell_agent/appsensor/rules/appsensor_rule_manager_spec.rb +0 -23
- data/spec/lib/tcell_agent/appsensor/rules/appsensor_rule_set_spec.rb +0 -159
- data/spec/lib/tcell_agent/patches/block_rule_spec.rb +0 -458
- data/spec/lib/tcell_agent/patches/sensors_matcher_spec.rb +0 -35
- data/spec/lib/tcell_agent/policies/appsensor/cmdi_sensor_spec.rb +0 -139
- data/spec/lib/tcell_agent/policies/appsensor/fpt_sensor_spec.rb +0 -139
- data/spec/lib/tcell_agent/policies/appsensor/nullbyte_sensor_spec.rb +0 -167
- data/spec/lib/tcell_agent/policies/appsensor/retr_sensor_spec.rb +0 -139
- data/spec/lib/tcell_agent/policies/appsensor/sqli_sensor_spec.rb +0 -246
- data/spec/lib/tcell_agent/policies/appsensor/xss_sensor_spec.rb +0 -882
- data/spec/lib/tcell_agent/policies/honeytokens_policy_spec.rb +0 -22
@@ -2,735 +2,865 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module TCellAgent
|
4
4
|
module Policies
|
5
|
+
describe RustPolicies do
|
6
|
+
before(:each) do
|
7
|
+
allow(TCellAgent).to receive(:is_it_safe_to_send_cmdi_events?).and_return(true)
|
8
|
+
@rust_policies = RustPolicies.new
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#update_policies' do
|
12
|
+
context 'with a nil policy' do
|
13
|
+
it 'should return nil' do
|
14
|
+
expect(TCellAgent).to_not receive(:logger)
|
15
|
+
|
16
|
+
@rust_policies.update_policies(nil)
|
5
17
|
|
6
|
-
|
7
|
-
describe "#from_json" do
|
8
|
-
context "with a nil policy" do
|
9
|
-
it "should return nil" do
|
10
|
-
expect(CommandInjectionPolicy.from_json(nil)).to be_nil
|
18
|
+
expect(@rust_policies.cmdi_enabled).to eq(false)
|
11
19
|
end
|
12
20
|
end
|
13
21
|
|
14
|
-
context
|
15
|
-
it
|
16
|
-
expect
|
17
|
-
|
18
|
-
|
22
|
+
context 'with an empty policy' do
|
23
|
+
it 'should raise a policy missing error' do
|
24
|
+
expect(TCellAgent).to_not receive(:logger)
|
25
|
+
@rust_policies.update_policies({})
|
26
|
+
|
27
|
+
expect(@rust_policies.cmdi_enabled).to eq(false)
|
19
28
|
end
|
20
29
|
end
|
21
30
|
|
22
|
-
context
|
23
|
-
it
|
24
|
-
|
25
|
-
|
26
|
-
expect(
|
27
|
-
expect(
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
31
|
+
context 'with an empty version' do
|
32
|
+
it 'should have empty version' do
|
33
|
+
logger = double('logger')
|
34
|
+
|
35
|
+
expect(TCellAgent).to receive(:logger).and_return(logger)
|
36
|
+
expect(logger).to receive(:error).with(
|
37
|
+
'Error updating policies: Failed to decode cmdi policy: missing field `version`'
|
38
|
+
)
|
39
|
+
@rust_policies.update_policies(
|
40
|
+
{
|
41
|
+
'cmdi' => { 'policy_id' => 'policy_id' }
|
42
|
+
}
|
43
|
+
)
|
44
|
+
|
45
|
+
expect(@rust_policies.cmdi_enabled).to eq(false)
|
32
46
|
end
|
33
47
|
end
|
34
48
|
|
35
|
-
context
|
36
|
-
it
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
expect(
|
49
|
+
context 'with no data' do
|
50
|
+
it 'should have disabled ip blocking' do
|
51
|
+
expect(TCellAgent).to_not receive(:logger)
|
52
|
+
|
53
|
+
@rust_policies.update_policies(
|
54
|
+
{
|
55
|
+
'cmdi' => {
|
56
|
+
'policy_id' => 'policy_id',
|
57
|
+
'version' => 1
|
58
|
+
}
|
59
|
+
}
|
60
|
+
)
|
61
|
+
expect(@rust_policies.cmdi_enabled).to eq(false)
|
48
62
|
end
|
49
63
|
end
|
50
64
|
|
51
|
-
context
|
52
|
-
it
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
expect(
|
64
|
-
expect(cmdi.collect_full_commandline).to eq(false)
|
65
|
+
context 'with empty data' do
|
66
|
+
it 'should have default values' do
|
67
|
+
expect(TCellAgent).to_not receive(:logger)
|
68
|
+
@rust_policies.update_policies(
|
69
|
+
{
|
70
|
+
'cmdi' => {
|
71
|
+
'policy_id' => 'policy_id',
|
72
|
+
'version' => 1,
|
73
|
+
'data' => {}
|
74
|
+
}
|
75
|
+
}
|
76
|
+
)
|
77
|
+
expect(@rust_policies.cmdi_enabled).to eq(false)
|
65
78
|
end
|
66
79
|
end
|
67
80
|
|
68
|
-
context
|
69
|
-
it
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
81
|
+
context 'with empty command rules' do
|
82
|
+
it 'should have default values' do
|
83
|
+
expect(TCellAgent).to_not receive(:logger)
|
84
|
+
@rust_policies.update_policies(
|
85
|
+
{
|
86
|
+
'cmdi' => {
|
87
|
+
'policy_id' => 'policy_id',
|
88
|
+
'version' => 1,
|
89
|
+
'data' => {
|
90
|
+
'command_rules' => []
|
91
|
+
}
|
92
|
+
}
|
75
93
|
}
|
76
|
-
|
77
|
-
expect(
|
78
|
-
expect(cmdi.version).to eq(1)
|
79
|
-
expect(cmdi.enabled).to eq(false)
|
80
|
-
expect(cmdi.overall_action).to be_nil
|
81
|
-
expect(cmdi.compound_statement_rule).to be_nil
|
82
|
-
expect(cmdi.command_rules).to eq({})
|
83
|
-
expect(cmdi.collect_full_commandline).to eq(false)
|
94
|
+
)
|
95
|
+
expect(@rust_policies.cmdi_enabled).to eq(false)
|
84
96
|
end
|
85
97
|
end
|
86
98
|
|
87
|
-
context
|
88
|
-
it
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
99
|
+
context 'with empty compount statement rules' do
|
100
|
+
it 'should have default values' do
|
101
|
+
expect(TCellAgent).to_not receive(:logger)
|
102
|
+
@rust_policies.update_policies(
|
103
|
+
{
|
104
|
+
'cmdi' => {
|
105
|
+
'policy_id' => 'policy_id',
|
106
|
+
'version' => 1,
|
107
|
+
'data' => {
|
108
|
+
'compound_statement_rules' => []
|
109
|
+
}
|
110
|
+
}
|
94
111
|
}
|
95
|
-
|
96
|
-
expect(
|
97
|
-
expect(cmdi.version).to eq(1)
|
98
|
-
expect(cmdi.enabled).to eq(false)
|
99
|
-
expect(cmdi.overall_action).to be_nil
|
100
|
-
expect(cmdi.compound_statement_rule).to be_nil
|
101
|
-
expect(cmdi.command_rules).to eq({})
|
102
|
-
expect(cmdi.collect_full_commandline).to eq(false)
|
112
|
+
)
|
113
|
+
expect(@rust_policies.cmdi_enabled).to eq(false)
|
103
114
|
end
|
104
115
|
end
|
105
116
|
|
106
|
-
context
|
107
|
-
it
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
117
|
+
context 'with populated command rules' do
|
118
|
+
it 'should have default values' do
|
119
|
+
expect(TCellAgent).to_not receive(:logger)
|
120
|
+
@rust_policies.update_policies(
|
121
|
+
{
|
122
|
+
'cmdi' => {
|
123
|
+
'policy_id' => 'policy_id',
|
124
|
+
'version' => 1,
|
125
|
+
'data' => {
|
126
|
+
'command_rules' => [
|
127
|
+
{ 'rule_id' => '1', 'action' => 'block' },
|
128
|
+
{ 'rule_id' => '2', 'command' => 'nc', 'action' => 'ignore' }
|
129
|
+
]
|
130
|
+
}
|
131
|
+
}
|
116
132
|
}
|
117
|
-
|
118
|
-
|
119
|
-
expect(
|
120
|
-
expect(cmdi.version).to eq(1)
|
121
|
-
expect(cmdi.enabled).to eq(true)
|
122
|
-
expect(cmdi.overall_action).to_not be_nil
|
123
|
-
expect(cmdi.overall_action.rule_id).to eq("1")
|
124
|
-
expect(cmdi.overall_action.action).to eq(CommandRule::BLOCK)
|
125
|
-
expect(cmdi.overall_action.command).to be_nil
|
126
|
-
expect(cmdi.command_rules.size).to eq(1)
|
127
|
-
expect(cmdi.command_rules["nc"]).to_not be_nil
|
128
|
-
expect(cmdi.command_rules["nc"].rule_id).to eq("2")
|
129
|
-
expect(cmdi.command_rules["nc"].action).to eq(CommandRule::IGNORE)
|
130
|
-
expect(cmdi.command_rules["nc"].command).to eq("nc")
|
131
|
-
expect(cmdi.compound_statement_rule).to be_nil
|
132
|
-
expect(cmdi.collect_full_commandline).to eq(false)
|
133
|
+
)
|
134
|
+
|
135
|
+
expect(@rust_policies.cmdi_enabled).to eq(true)
|
133
136
|
end
|
134
137
|
end
|
135
138
|
|
136
|
-
context
|
137
|
-
it
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
139
|
+
context 'with populated compound statement rules' do
|
140
|
+
it 'should have default values' do
|
141
|
+
expect(TCellAgent).to_not receive(:logger)
|
142
|
+
@rust_policies.update_policies(
|
143
|
+
{
|
144
|
+
'cmdi' => {
|
145
|
+
'policy_id' => 'policy_id',
|
146
|
+
'version' => 1,
|
147
|
+
'data' => {
|
148
|
+
'compound_statement_rules' => [
|
149
|
+
{ 'rule_id' => '3', 'action' => 'block' }
|
150
|
+
]
|
151
|
+
}
|
152
|
+
}
|
145
153
|
}
|
146
|
-
|
147
|
-
|
148
|
-
expect(
|
149
|
-
expect(cmdi.version).to eq(1)
|
150
|
-
expect(cmdi.enabled).to eq(true)
|
151
|
-
expect(cmdi.overall_action).to be_nil
|
152
|
-
expect(cmdi.command_rules).to eq({})
|
153
|
-
expect(cmdi.compound_statement_rule).to_not be_nil
|
154
|
-
expect(cmdi.compound_statement_rule.rule_id).to eq("3")
|
155
|
-
expect(cmdi.compound_statement_rule.action).to eq(CommandRule::BLOCK)
|
156
|
-
expect(cmdi.compound_statement_rule.command).to be_nil
|
157
|
-
expect(cmdi.collect_full_commandline).to eq(false)
|
154
|
+
)
|
155
|
+
|
156
|
+
expect(@rust_policies.cmdi_enabled).to eq(true)
|
158
157
|
end
|
159
158
|
end
|
160
159
|
|
161
|
-
context
|
162
|
-
context
|
163
|
-
it
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
160
|
+
context 'with populated collect_full_commandline' do
|
161
|
+
context 'as nil' do
|
162
|
+
it 'should have collect_full_commandline disabled' do
|
163
|
+
expect(TCellAgent).to_not receive(:logger)
|
164
|
+
@rust_policies.update_policies(
|
165
|
+
{
|
166
|
+
'cmdi' => {
|
167
|
+
'policy_id' => 'policy_id',
|
168
|
+
'version' => 1,
|
169
|
+
'data' => {
|
170
|
+
'collect_full_commandline' => nil,
|
171
|
+
'compound_statement_rules' => [
|
172
|
+
{ 'rule_id' => '3', 'action' => 'block' }
|
173
|
+
]
|
174
|
+
}
|
175
|
+
}
|
172
176
|
}
|
173
|
-
|
174
|
-
|
175
|
-
expect(
|
176
|
-
expect(cmdi.version).to eq(1)
|
177
|
-
expect(cmdi.enabled).to eq(true)
|
178
|
-
expect(cmdi.overall_action).to be_nil
|
179
|
-
expect(cmdi.command_rules).to eq({})
|
180
|
-
expect(cmdi.compound_statement_rule).to_not be_nil
|
181
|
-
expect(cmdi.compound_statement_rule.rule_id).to eq("3")
|
182
|
-
expect(cmdi.compound_statement_rule.action).to eq(CommandRule::BLOCK)
|
183
|
-
expect(cmdi.compound_statement_rule.command).to be_nil
|
184
|
-
expect(cmdi.collect_full_commandline).to eq(false)
|
177
|
+
)
|
178
|
+
|
179
|
+
expect(@rust_policies.cmdi_enabled).to eq(true)
|
185
180
|
end
|
186
181
|
end
|
187
182
|
|
188
|
-
context
|
189
|
-
it
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
183
|
+
context 'as false' do
|
184
|
+
it 'should have collect_full_commandline disabled' do
|
185
|
+
@rust_policies.update_policies(
|
186
|
+
{
|
187
|
+
'cmdi' => {
|
188
|
+
'policy_id' => 'policy_id',
|
189
|
+
'version' => 1,
|
190
|
+
'data' => {
|
191
|
+
'collect_full_commandline' => false,
|
192
|
+
'compound_statement_rules' => [
|
193
|
+
{ 'rule_id' => '3', 'action' => 'block' }
|
194
|
+
]
|
195
|
+
}
|
196
|
+
}
|
198
197
|
}
|
199
|
-
|
200
|
-
|
201
|
-
expect(
|
202
|
-
expect(cmdi.version).to eq(1)
|
203
|
-
expect(cmdi.enabled).to eq(true)
|
204
|
-
expect(cmdi.overall_action).to be_nil
|
205
|
-
expect(cmdi.command_rules).to eq({})
|
206
|
-
expect(cmdi.compound_statement_rule).to_not be_nil
|
207
|
-
expect(cmdi.compound_statement_rule.rule_id).to eq("3")
|
208
|
-
expect(cmdi.compound_statement_rule.action).to eq(CommandRule::BLOCK)
|
209
|
-
expect(cmdi.compound_statement_rule.command).to be_nil
|
210
|
-
expect(cmdi.collect_full_commandline).to eq(false)
|
198
|
+
)
|
199
|
+
|
200
|
+
expect(@rust_policies.cmdi_enabled).to eq(true)
|
211
201
|
end
|
212
202
|
end
|
213
203
|
|
214
|
-
context
|
215
|
-
it
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
204
|
+
context 'as true' do
|
205
|
+
it 'should have collect_full_commandline enabled' do
|
206
|
+
@rust_policies.update_policies(
|
207
|
+
{
|
208
|
+
'cmdi' => {
|
209
|
+
'policy_id' => 'policy_id',
|
210
|
+
'version' => 1,
|
211
|
+
'data' => {
|
212
|
+
'collect_full_commandline' => true,
|
213
|
+
'compound_statement_rules' => [
|
214
|
+
{ 'rule_id' => '3', 'action' => 'block' }
|
215
|
+
]
|
216
|
+
}
|
217
|
+
}
|
224
218
|
}
|
225
|
-
|
226
|
-
|
227
|
-
expect(
|
228
|
-
expect(cmdi.version).to eq(1)
|
229
|
-
expect(cmdi.enabled).to eq(true)
|
230
|
-
expect(cmdi.overall_action).to be_nil
|
231
|
-
expect(cmdi.command_rules).to eq({})
|
232
|
-
expect(cmdi.compound_statement_rule).to_not be_nil
|
233
|
-
expect(cmdi.compound_statement_rule.rule_id).to eq("3")
|
234
|
-
expect(cmdi.compound_statement_rule.action).to eq(CommandRule::BLOCK)
|
235
|
-
expect(cmdi.compound_statement_rule.command).to be_nil
|
236
|
-
expect(cmdi.collect_full_commandline).to eq(true)
|
219
|
+
)
|
220
|
+
|
221
|
+
expect(@rust_policies.cmdi_enabled).to eq(true)
|
237
222
|
end
|
238
223
|
end
|
239
224
|
end
|
240
|
-
|
241
225
|
end
|
242
226
|
|
243
|
-
describe
|
244
|
-
context
|
245
|
-
context
|
246
|
-
it
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
227
|
+
describe '#block_command?' do
|
228
|
+
context 'with command rules' do
|
229
|
+
context 'that are blank' do
|
230
|
+
it 'should not block' do
|
231
|
+
@rust_policies.update_policies(
|
232
|
+
{
|
233
|
+
'cmdi' => {
|
234
|
+
'policy_id' => 'policy_id',
|
235
|
+
'version' => 1,
|
236
|
+
'data' => {
|
237
|
+
'collect_full_commandline' => true,
|
238
|
+
'command_rules' => []
|
239
|
+
}
|
240
|
+
}
|
253
241
|
}
|
254
|
-
|
242
|
+
)
|
255
243
|
|
256
244
|
expect(TCellAgent).to_not receive(:send_event)
|
257
245
|
|
258
246
|
expect(
|
259
|
-
|
247
|
+
@rust_policies.block_command?('cat /etc/passwd | grep root', nil)
|
260
248
|
).to eq(false)
|
261
249
|
end
|
262
250
|
end
|
263
251
|
|
264
|
-
context
|
265
|
-
it
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
252
|
+
context 'that ignore all' do
|
253
|
+
it 'should not block' do
|
254
|
+
@rust_policies.update_policies(
|
255
|
+
{
|
256
|
+
'cmdi' => {
|
257
|
+
'policy_id' => 'policy_id',
|
258
|
+
'version' => 1,
|
259
|
+
'data' => {
|
260
|
+
'collect_full_commandline' => true,
|
261
|
+
'command_rules' => [{ 'rule_id' => '1', 'action' => 'ignore' }]
|
262
|
+
}
|
263
|
+
}
|
272
264
|
}
|
273
|
-
|
265
|
+
)
|
274
266
|
|
275
267
|
expect(TCellAgent).to_not receive(:send_event)
|
276
268
|
|
277
269
|
expect(
|
278
|
-
|
270
|
+
@rust_policies.block_command?('cat /etc/passwd | grep root', nil)
|
279
271
|
).to eq(false)
|
280
272
|
end
|
281
273
|
|
282
|
-
context
|
283
|
-
it
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
274
|
+
context 'and ignore cat' do
|
275
|
+
it 'should not send an event' do
|
276
|
+
@rust_policies.update_policies(
|
277
|
+
{
|
278
|
+
'cmdi' => {
|
279
|
+
'policy_id' => 'policy_id',
|
280
|
+
'version' => 1,
|
281
|
+
'data' => {
|
282
|
+
'collect_full_commandline' => true,
|
283
|
+
'command_rules' => [
|
284
|
+
{ 'rule_id' => '1', 'action' => 'ignore' },
|
285
|
+
{ 'rule_id' => '2', 'action' => 'ignore', 'command' => 'cat' }
|
286
|
+
]
|
287
|
+
}
|
288
|
+
}
|
293
289
|
}
|
294
|
-
|
290
|
+
)
|
295
291
|
|
296
292
|
expect(TCellAgent).to_not receive(:send_event)
|
297
293
|
|
298
294
|
expect(
|
299
|
-
|
295
|
+
@rust_policies.block_command?('cat /etc/passwd | grep root', nil)
|
300
296
|
).to eq(false)
|
301
297
|
end
|
302
298
|
end
|
303
299
|
|
304
|
-
context
|
305
|
-
it
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
300
|
+
context 'and report cat' do
|
301
|
+
it 'should send an event' do
|
302
|
+
@rust_policies.update_policies(
|
303
|
+
{
|
304
|
+
'cmdi' => {
|
305
|
+
'policy_id' => 'policy_id',
|
306
|
+
'version' => 1,
|
307
|
+
'data' => {
|
308
|
+
'collect_full_commandline' => true,
|
309
|
+
'command_rules' => [
|
310
|
+
{ 'rule_id' => '1', 'action' => 'ignore' },
|
311
|
+
{ 'rule_id' => '2', 'action' => 'report', 'command' => 'cat' }
|
312
|
+
]
|
313
|
+
}
|
314
|
+
}
|
315
315
|
}
|
316
|
-
|
317
|
-
|
318
|
-
expect(TCellAgent).to receive(:send_event).with(
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
316
|
+
)
|
317
|
+
|
318
|
+
expect(TCellAgent).to receive(:send_event).with(
|
319
|
+
{
|
320
|
+
'event_type' => 'cmdi',
|
321
|
+
'commands' => [
|
322
|
+
{ 'command' => 'cat', 'arg_count' => 1 },
|
323
|
+
{ 'command' => 'grep', 'arg_count' => 1 }
|
324
|
+
],
|
325
|
+
'blocked' => false,
|
326
|
+
'matches' => [{ 'rule_id' => '2', 'command' => 'cat' }],
|
327
|
+
'full_commandline' => 'cat /etc/passwd | grep root'
|
328
|
+
}
|
329
|
+
)
|
325
330
|
|
326
331
|
expect(
|
327
|
-
|
332
|
+
@rust_policies.block_command?('cat /etc/passwd | grep root', nil)
|
328
333
|
).to eq(false)
|
329
334
|
end
|
330
335
|
end
|
331
336
|
|
332
|
-
context
|
333
|
-
it
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
337
|
+
context 'and block cat' do
|
338
|
+
it 'should send an event and block' do
|
339
|
+
@rust_policies.update_policies(
|
340
|
+
{
|
341
|
+
'cmdi' => {
|
342
|
+
'policy_id' => 'policy_id',
|
343
|
+
'version' => 1,
|
344
|
+
'data' => {
|
345
|
+
'collect_full_commandline' => true,
|
346
|
+
'command_rules' => [
|
347
|
+
{ 'rule_id' => '1', 'action' => 'ignore' },
|
348
|
+
{ 'rule_id' => '2', 'action' => 'block', 'command' => 'cat' }
|
349
|
+
]
|
350
|
+
}
|
351
|
+
}
|
343
352
|
}
|
344
|
-
|
345
|
-
|
346
|
-
expect(TCellAgent).to receive(:send_event).with(
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
+
)
|
354
|
+
|
355
|
+
expect(TCellAgent).to receive(:send_event).with(
|
356
|
+
{
|
357
|
+
'event_type' => 'cmdi',
|
358
|
+
'commands' => [
|
359
|
+
{ 'command' => 'cat', 'arg_count' => 1 },
|
360
|
+
{ 'command' => 'grep', 'arg_count' => 1 }
|
361
|
+
],
|
362
|
+
'blocked' => true,
|
363
|
+
'matches' => [{ 'rule_id' => '2', 'command' => 'cat' }],
|
364
|
+
'full_commandline' => 'cat /etc/passwd | grep root'
|
365
|
+
}
|
366
|
+
)
|
353
367
|
|
354
368
|
expect(
|
355
|
-
|
369
|
+
@rust_policies.block_command?('cat /etc/passwd | grep root', nil)
|
356
370
|
).to eq(true)
|
357
371
|
end
|
358
372
|
end
|
359
373
|
end
|
360
374
|
|
361
|
-
context
|
362
|
-
it
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
375
|
+
context 'that report all' do
|
376
|
+
it 'should send an event' do
|
377
|
+
@rust_policies.update_policies(
|
378
|
+
{
|
379
|
+
'cmdi' => {
|
380
|
+
'policy_id' => 'policy_id',
|
381
|
+
'version' => 1,
|
382
|
+
'data' => {
|
383
|
+
'command_rules' => [{ 'rule_id' => '1', 'action' => 'report' }]
|
384
|
+
}
|
385
|
+
}
|
368
386
|
}
|
369
|
-
|
370
|
-
|
371
|
-
expect(TCellAgent).to receive(:send_event).with(
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
387
|
+
)
|
388
|
+
|
389
|
+
expect(TCellAgent).to receive(:send_event).with(
|
390
|
+
{
|
391
|
+
'event_type' => 'cmdi',
|
392
|
+
'commands' => [
|
393
|
+
{ 'command' => 'cat', 'arg_count' => 1 },
|
394
|
+
{ 'command' => 'grep', 'arg_count' => 1 }
|
395
|
+
],
|
396
|
+
'blocked' => false,
|
397
|
+
'matches' => [
|
398
|
+
{ 'rule_id' => '1', 'command' => 'cat' },
|
399
|
+
{ 'rule_id' => '1', 'command' => 'grep' }
|
400
|
+
]
|
401
|
+
}
|
402
|
+
)
|
377
403
|
|
378
404
|
expect(
|
379
|
-
|
405
|
+
@rust_policies.block_command?('cat /etc/passwd | grep root', nil)
|
380
406
|
).to eq(false)
|
381
407
|
end
|
382
408
|
|
383
|
-
context
|
384
|
-
it
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
409
|
+
context 'and ignore cat' do
|
410
|
+
it 'should send an event for grep not cat' do
|
411
|
+
@rust_policies.update_policies(
|
412
|
+
{
|
413
|
+
'cmdi' => {
|
414
|
+
'policy_id' => 'policy_id',
|
415
|
+
'version' => 1,
|
416
|
+
'data' => {
|
417
|
+
'command_rules' => [
|
418
|
+
{ 'rule_id' => '1', 'action' => 'report' },
|
419
|
+
{ 'rule_id' => '2', 'action' => 'ignore', 'command' => 'cat' }
|
420
|
+
]
|
421
|
+
}
|
422
|
+
}
|
393
423
|
}
|
394
|
-
|
395
|
-
|
396
|
-
expect(TCellAgent).to receive(:send_event).with(
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
424
|
+
)
|
425
|
+
|
426
|
+
expect(TCellAgent).to receive(:send_event).with(
|
427
|
+
{
|
428
|
+
'event_type' => 'cmdi',
|
429
|
+
'commands' => [
|
430
|
+
{ 'command' => 'cat', 'arg_count' => 1 },
|
431
|
+
{ 'command' => 'grep', 'arg_count' => 1 }
|
432
|
+
],
|
433
|
+
'blocked' => false,
|
434
|
+
'matches' => [{ 'rule_id' => '1', 'command' => 'grep' }]
|
435
|
+
}
|
436
|
+
)
|
402
437
|
|
403
438
|
expect(
|
404
|
-
|
439
|
+
@rust_policies.block_command?('cat /etc/passwd | grep root', nil)
|
405
440
|
).to eq(false)
|
406
441
|
end
|
407
442
|
end
|
408
443
|
|
409
|
-
context
|
410
|
-
it
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
444
|
+
context 'and report cat' do
|
445
|
+
it 'should send an event for grep and cat' do
|
446
|
+
@rust_policies.update_policies(
|
447
|
+
{
|
448
|
+
'cmdi' => {
|
449
|
+
'policy_id' => 'policy_id',
|
450
|
+
'version' => 1,
|
451
|
+
'data' => {
|
452
|
+
'command_rules' => [
|
453
|
+
{ 'rule_id' => '1', 'action' => 'report' },
|
454
|
+
{ 'rule_id' => '2', 'action' => 'report', 'command' => 'cat' }
|
455
|
+
]
|
456
|
+
}
|
457
|
+
}
|
458
|
+
}
|
459
|
+
)
|
460
|
+
|
461
|
+
expect(TCellAgent).to receive(:send_event).with(
|
462
|
+
{
|
463
|
+
'event_type' => 'cmdi',
|
464
|
+
'commands' => [
|
465
|
+
{ 'command' => 'cat', 'arg_count' => 1 },
|
466
|
+
{ 'command' => 'grep', 'arg_count' => 1 }
|
467
|
+
],
|
468
|
+
'blocked' => false,
|
469
|
+
'matches' => [
|
470
|
+
{ 'rule_id' => '2', 'command' => 'cat' },
|
471
|
+
{ 'rule_id' => '1', 'command' => 'grep' }
|
418
472
|
]
|
419
473
|
}
|
420
|
-
|
421
|
-
|
422
|
-
expect(TCellAgent).to receive(:send_event).with({
|
423
|
-
"event_type" => "cmdi",
|
424
|
-
"commands" => [{"command" => "cat", "arg_count" => 1}, {"command" => "grep", "arg_count" => 1}],
|
425
|
-
"blocked" => false,
|
426
|
-
"matches" => [{"rule_id" => "2", "command" => "cat"}, {"rule_id" => "1", "command" => "grep"}]
|
427
|
-
})
|
474
|
+
)
|
428
475
|
|
429
476
|
expect(
|
430
|
-
|
477
|
+
@rust_policies.block_command?('cat /etc/passwd | grep root', nil)
|
431
478
|
).to eq(false)
|
432
479
|
end
|
433
480
|
end
|
434
481
|
|
435
|
-
context
|
436
|
-
it
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
482
|
+
context 'and block cat' do
|
483
|
+
it 'should send an event for grep and cat and block' do
|
484
|
+
@rust_policies.update_policies(
|
485
|
+
{
|
486
|
+
'cmdi' => {
|
487
|
+
'policy_id' => 'policy_id',
|
488
|
+
'version' => 1,
|
489
|
+
'data' => {
|
490
|
+
'command_rules' => [
|
491
|
+
{ 'rule_id' => '1', 'action' => 'report' },
|
492
|
+
{ 'rule_id' => '2', 'action' => 'block', 'command' => 'cat' }
|
493
|
+
]
|
494
|
+
}
|
495
|
+
}
|
496
|
+
}
|
497
|
+
)
|
498
|
+
|
499
|
+
expect(TCellAgent).to receive(:send_event).with(
|
500
|
+
{
|
501
|
+
'event_type' => 'cmdi',
|
502
|
+
'commands' => [
|
503
|
+
{ 'command' => 'cat', 'arg_count' => 1 },
|
504
|
+
{ 'command' => 'grep', 'arg_count' => 1 }
|
505
|
+
],
|
506
|
+
'blocked' => true,
|
507
|
+
'matches' => [
|
508
|
+
{ 'rule_id' => '2', 'command' => 'cat' },
|
509
|
+
{ 'rule_id' => '1', 'command' => 'grep' }
|
444
510
|
]
|
445
511
|
}
|
446
|
-
|
447
|
-
|
448
|
-
expect(TCellAgent).to receive(:send_event).with({
|
449
|
-
"event_type" => "cmdi",
|
450
|
-
"commands" => [{"command" => "cat", "arg_count" => 1}, {"command" => "grep", "arg_count" => 1}],
|
451
|
-
"blocked" => true,
|
452
|
-
"matches" => [{"rule_id" => "2", "command" => "cat"}, {"rule_id" => "1", "command" => "grep"}]
|
453
|
-
})
|
512
|
+
)
|
454
513
|
|
455
514
|
expect(
|
456
|
-
|
515
|
+
@rust_policies.block_command?('cat /etc/passwd | grep root', nil)
|
457
516
|
).to eq(true)
|
458
517
|
end
|
459
518
|
end
|
460
519
|
end
|
461
520
|
|
462
|
-
context
|
463
|
-
it
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
521
|
+
context 'that block all' do
|
522
|
+
it 'should send an event and block' do
|
523
|
+
@rust_policies.update_policies(
|
524
|
+
{
|
525
|
+
'cmdi' => {
|
526
|
+
'policy_id' => 'policy_id',
|
527
|
+
'version' => 1,
|
528
|
+
'data' => {
|
529
|
+
'command_rules' => [{ 'rule_id' => '1', 'action' => 'block' }]
|
530
|
+
}
|
531
|
+
}
|
469
532
|
}
|
470
|
-
|
471
|
-
|
472
|
-
expect(TCellAgent).to receive(:send_event).with(
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
533
|
+
)
|
534
|
+
|
535
|
+
expect(TCellAgent).to receive(:send_event).with(
|
536
|
+
{
|
537
|
+
'event_type' => 'cmdi',
|
538
|
+
'commands' => [
|
539
|
+
{ 'command' => 'cat', 'arg_count' => 1 },
|
540
|
+
{ 'command' => 'grep', 'arg_count' => 1 }
|
541
|
+
],
|
542
|
+
'blocked' => true,
|
543
|
+
'matches' => [
|
544
|
+
{ 'rule_id' => '1', 'command' => 'cat' },
|
545
|
+
{ 'rule_id' => '1', 'command' => 'grep' }
|
546
|
+
]
|
547
|
+
}
|
548
|
+
)
|
478
549
|
|
479
550
|
expect(
|
480
|
-
|
551
|
+
@rust_policies.block_command?('cat /etc/passwd | grep root', nil)
|
481
552
|
).to eq(true)
|
482
553
|
end
|
483
554
|
|
484
|
-
context
|
485
|
-
it
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
555
|
+
context 'and ignore cat' do
|
556
|
+
it 'should send an event for grep not cat and block' do
|
557
|
+
@rust_policies.update_policies(
|
558
|
+
{
|
559
|
+
'cmdi' => {
|
560
|
+
'policy_id' => 'policy_id',
|
561
|
+
'version' => 1,
|
562
|
+
'data' => {
|
563
|
+
'command_rules' => [
|
564
|
+
{ 'rule_id' => '1', 'action' => 'block' },
|
565
|
+
{ 'rule_id' => '2', 'action' => 'ignore', 'command' => 'cat' }
|
566
|
+
]
|
567
|
+
}
|
568
|
+
}
|
494
569
|
}
|
495
|
-
|
496
|
-
|
497
|
-
expect(TCellAgent).to receive(:send_event).with(
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
570
|
+
)
|
571
|
+
|
572
|
+
expect(TCellAgent).to receive(:send_event).with(
|
573
|
+
{
|
574
|
+
'event_type' => 'cmdi',
|
575
|
+
'commands' => [
|
576
|
+
{ 'command' => 'cat', 'arg_count' => 1 },
|
577
|
+
{ 'command' => 'grep', 'arg_count' => 1 }
|
578
|
+
],
|
579
|
+
'blocked' => true,
|
580
|
+
'matches' => [{ 'rule_id' => '1', 'command' => 'grep' }]
|
581
|
+
}
|
582
|
+
)
|
503
583
|
|
504
584
|
expect(
|
505
|
-
|
585
|
+
@rust_policies.block_command?('cat /etc/passwd | grep root', nil)
|
506
586
|
).to eq(true)
|
507
587
|
end
|
508
588
|
end
|
509
589
|
|
510
|
-
context
|
511
|
-
it
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
590
|
+
context 'and report cat' do
|
591
|
+
it 'should send an event for grep and cat and block' do
|
592
|
+
@rust_policies.update_policies(
|
593
|
+
{
|
594
|
+
'cmdi' => {
|
595
|
+
'policy_id' => 'policy_id',
|
596
|
+
'version' => 1,
|
597
|
+
'data' => {
|
598
|
+
'command_rules' => [
|
599
|
+
{ 'rule_id' => '1', 'action' => 'block' },
|
600
|
+
{ 'rule_id' => '2', 'action' => 'report', 'command' => 'cat' }
|
601
|
+
]
|
602
|
+
}
|
603
|
+
}
|
604
|
+
}
|
605
|
+
)
|
606
|
+
|
607
|
+
expect(TCellAgent).to receive(:send_event).with(
|
608
|
+
{
|
609
|
+
'event_type' => 'cmdi',
|
610
|
+
'commands' => [
|
611
|
+
{ 'command' => 'cat', 'arg_count' => 1 },
|
612
|
+
{ 'command' => 'grep', 'arg_count' => 1 }
|
613
|
+
],
|
614
|
+
'blocked' => true,
|
615
|
+
'matches' => [
|
616
|
+
{ 'rule_id' => '2', 'command' => 'cat' },
|
617
|
+
{ 'rule_id' => '1', 'command' => 'grep' }
|
519
618
|
]
|
520
619
|
}
|
521
|
-
|
522
|
-
|
523
|
-
expect(TCellAgent).to receive(:send_event).with({
|
524
|
-
"event_type" => "cmdi",
|
525
|
-
"commands" => [{"command" => "cat", "arg_count" => 1}, {"command" => "grep", "arg_count" => 1}],
|
526
|
-
"blocked" => true,
|
527
|
-
"matches" => [{"rule_id" => "2", "command" => "cat"}, {"rule_id" => "1", "command" => "grep"}]
|
528
|
-
})
|
620
|
+
)
|
529
621
|
|
530
622
|
expect(
|
531
|
-
|
623
|
+
@rust_policies.block_command?('cat /etc/passwd | grep root', nil)
|
532
624
|
).to eq(true)
|
533
625
|
end
|
534
626
|
end
|
535
627
|
|
536
|
-
context
|
537
|
-
it
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
628
|
+
context 'and block cat' do
|
629
|
+
it 'should send an event for grep and cat and block' do
|
630
|
+
@rust_policies.update_policies(
|
631
|
+
{
|
632
|
+
'cmdi' => {
|
633
|
+
'policy_id' => 'policy_id',
|
634
|
+
'version' => 1,
|
635
|
+
'data' => {
|
636
|
+
'command_rules' => [
|
637
|
+
{ 'rule_id' => '1', 'action' => 'block' },
|
638
|
+
{ 'rule_id' => '2', 'action' => 'block', 'command' => 'cat' }
|
639
|
+
]
|
640
|
+
}
|
641
|
+
}
|
642
|
+
}
|
643
|
+
)
|
644
|
+
|
645
|
+
expect(TCellAgent).to receive(:send_event).with(
|
646
|
+
{
|
647
|
+
'event_type' => 'cmdi',
|
648
|
+
'commands' => [
|
649
|
+
{ 'command' => 'cat', 'arg_count' => 1 },
|
650
|
+
{ 'command' => 'grep', 'arg_count' => 1 }
|
651
|
+
],
|
652
|
+
'blocked' => true,
|
653
|
+
'matches' => [
|
654
|
+
{ 'rule_id' => '2', 'command' => 'cat' },
|
655
|
+
{ 'rule_id' => '1', 'command' => 'grep' }
|
545
656
|
]
|
546
657
|
}
|
547
|
-
|
548
|
-
|
549
|
-
expect(TCellAgent).to receive(:send_event).with({
|
550
|
-
"event_type" => "cmdi",
|
551
|
-
"commands" => [{"command" => "cat", "arg_count" => 1}, {"command" => "grep", "arg_count" => 1}],
|
552
|
-
"blocked" => true,
|
553
|
-
"matches" => [{"rule_id" => "2", "command" => "cat"}, {"rule_id" => "1", "command" => "grep"}]
|
554
|
-
})
|
658
|
+
)
|
555
659
|
|
556
660
|
expect(
|
557
|
-
|
661
|
+
@rust_policies.block_command?('cat /etc/passwd | grep root', nil)
|
558
662
|
).to eq(true)
|
559
663
|
end
|
560
664
|
end
|
561
665
|
end
|
562
666
|
end
|
563
667
|
|
564
|
-
context
|
668
|
+
context 'with compound statement rules' do
|
565
669
|
before(:each) do
|
566
670
|
@tcell_context = TCellAgent::Instrumentation::TCellData.new
|
567
|
-
@tcell_context.request_method =
|
568
|
-
@tcell_context.ip_address =
|
569
|
-
@tcell_context.route_id =
|
570
|
-
@tcell_context.hmac_session_id =
|
571
|
-
@tcell_context.user_id =
|
671
|
+
@tcell_context.request_method = 'GET'
|
672
|
+
@tcell_context.ip_address = '1.1.1.1'
|
673
|
+
@tcell_context.route_id = '12345'
|
674
|
+
@tcell_context.hmac_session_id = 'sldfjk2343'
|
675
|
+
@tcell_context.user_id = 'user_id'
|
572
676
|
end
|
573
677
|
|
574
|
-
context
|
678
|
+
context 'set to ignore' do
|
575
679
|
before(:each) do
|
576
|
-
@
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
680
|
+
@rust_policies.update_policies(
|
681
|
+
{
|
682
|
+
'cmdi' => {
|
683
|
+
'policy_id' => 'policy_id',
|
684
|
+
'version' => 1,
|
685
|
+
'data' => {
|
686
|
+
'compound_statement_rules' => [
|
687
|
+
{ 'rule_id' => '1', 'action' => 'ignore' }
|
688
|
+
]
|
689
|
+
}
|
690
|
+
}
|
583
691
|
}
|
584
|
-
|
692
|
+
)
|
585
693
|
end
|
586
694
|
|
587
|
-
context
|
588
|
-
it
|
695
|
+
context 'one parsed command' do
|
696
|
+
it 'should not send events or block' do
|
589
697
|
expect(TCellAgent).to_not receive(:send_event)
|
590
698
|
|
591
699
|
expect(
|
592
|
-
@
|
700
|
+
@rust_policies.block_command?('cat /etc/passwd', @tcell_context)
|
593
701
|
).to eq(false)
|
594
702
|
end
|
595
703
|
end
|
596
704
|
|
597
|
-
context
|
598
|
-
it
|
705
|
+
context 'two parsed commands' do
|
706
|
+
it 'should not send events or block' do
|
599
707
|
expect(TCellAgent).to_not receive(:send_event)
|
600
708
|
|
601
709
|
expect(
|
602
|
-
@
|
710
|
+
@rust_policies.block_command?('cat /etc/passwd | grep root', @tcell_context)
|
603
711
|
).to eq(false)
|
604
712
|
end
|
605
713
|
end
|
606
714
|
end
|
607
715
|
|
608
|
-
context
|
716
|
+
context 'set to report' do
|
609
717
|
before(:each) do
|
610
|
-
@
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
718
|
+
@rust_policies.update_policies(
|
719
|
+
{
|
720
|
+
'cmdi' => {
|
721
|
+
'policy_id' => 'policy_id',
|
722
|
+
'version' => 1,
|
723
|
+
'data' => {
|
724
|
+
'compound_statement_rules' => [
|
725
|
+
{ 'rule_id' => '1', 'action' => 'report' }
|
726
|
+
]
|
727
|
+
}
|
728
|
+
}
|
617
729
|
}
|
618
|
-
|
730
|
+
)
|
619
731
|
end
|
620
732
|
|
621
|
-
context
|
622
|
-
it
|
733
|
+
context 'one parsed command' do
|
734
|
+
it 'should not send events or block' do
|
623
735
|
expect(TCellAgent).to_not receive(:send_event)
|
624
736
|
|
625
737
|
expect(
|
626
|
-
@
|
738
|
+
@rust_policies.block_command?('cat /etc/passwd', @tcell_context)
|
627
739
|
).to eq(false)
|
628
740
|
end
|
629
741
|
end
|
630
742
|
|
631
|
-
context
|
632
|
-
it
|
633
|
-
expect(TCellAgent).to receive(:send_event).with(
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
743
|
+
context 'two parsed commands' do
|
744
|
+
it 'should send an event but not block' do
|
745
|
+
expect(TCellAgent).to receive(:send_event).with(
|
746
|
+
{
|
747
|
+
'event_type' => 'cmdi',
|
748
|
+
'commands' => [
|
749
|
+
{ 'command' => 'cat', 'arg_count' => 1 },
|
750
|
+
{ 'command' => 'grep', 'arg_count' => 1 }
|
751
|
+
],
|
752
|
+
'blocked' => false,
|
753
|
+
'matches' => [{ 'rule_id' => '1' }],
|
754
|
+
'm' => 'GET',
|
755
|
+
'remote_addr' => '1.1.1.1',
|
756
|
+
'rid' => '12345',
|
757
|
+
'sid' => 'sldfjk2343',
|
758
|
+
'uid' => 'user_id'
|
759
|
+
}
|
760
|
+
)
|
647
761
|
|
648
762
|
expect(
|
649
|
-
@
|
763
|
+
@rust_policies.block_command?('cat /etc/passwd | grep root', @tcell_context)
|
650
764
|
).to eq(false)
|
651
765
|
end
|
652
766
|
end
|
653
767
|
end
|
654
768
|
|
655
|
-
context
|
769
|
+
context 'set to block' do
|
656
770
|
before(:each) do
|
657
|
-
@
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
771
|
+
@rust_policies.update_policies(
|
772
|
+
{
|
773
|
+
'cmdi' => {
|
774
|
+
'policy_id' => 'policy_id',
|
775
|
+
'version' => 1,
|
776
|
+
'data' => {
|
777
|
+
'compound_statement_rules' => [
|
778
|
+
{ 'rule_id' => '1', 'action' => 'block' }
|
779
|
+
]
|
780
|
+
}
|
781
|
+
}
|
664
782
|
}
|
665
|
-
|
783
|
+
)
|
666
784
|
end
|
667
785
|
|
668
|
-
context
|
669
|
-
it
|
786
|
+
context 'one parsed command' do
|
787
|
+
it 'should not send events or block' do
|
670
788
|
expect(TCellAgent).to_not receive(:send_event)
|
671
789
|
|
672
790
|
expect(
|
673
|
-
@
|
791
|
+
@rust_policies.block_command?('cat /etc/passwd', @tcell_context)
|
674
792
|
).to eq(false)
|
675
793
|
end
|
676
794
|
end
|
677
795
|
|
678
|
-
context
|
679
|
-
it
|
680
|
-
expect(TCellAgent).to receive(:send_event).with(
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
796
|
+
context 'two parsed commands' do
|
797
|
+
it 'should send an event and block' do
|
798
|
+
expect(TCellAgent).to receive(:send_event).with(
|
799
|
+
{
|
800
|
+
'event_type' => 'cmdi',
|
801
|
+
'commands' => [
|
802
|
+
{ 'command' => 'cat', 'arg_count' => 1 },
|
803
|
+
{ 'command' => 'grep', 'arg_count' => 1 }
|
804
|
+
],
|
805
|
+
'blocked' => true,
|
806
|
+
'matches' => [{ 'rule_id' => '1' }],
|
807
|
+
'm' => 'GET',
|
808
|
+
'remote_addr' => '1.1.1.1',
|
809
|
+
'rid' => '12345',
|
810
|
+
'sid' => 'sldfjk2343',
|
811
|
+
'uid' => 'user_id'
|
812
|
+
}
|
813
|
+
)
|
691
814
|
|
692
815
|
expect(
|
693
|
-
@
|
816
|
+
@rust_policies.block_command?('cat /etc/passwd | grep root', @tcell_context)
|
694
817
|
).to eq(true)
|
695
818
|
end
|
696
819
|
end
|
697
820
|
end
|
698
821
|
|
699
|
-
context
|
700
|
-
it
|
822
|
+
context 'that conflict' do
|
823
|
+
it 'only take the first one and ignore the rest' do
|
701
824
|
## multiple compound statements present only first one is taken
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
825
|
+
@rust_policies.update_policies(
|
826
|
+
{
|
827
|
+
'cmdi' => {
|
828
|
+
'policy_id' => 'policy_id',
|
829
|
+
'version' => 1,
|
830
|
+
'data' => {
|
831
|
+
'compound_statement_rules' => [
|
832
|
+
{ 'rule_id' => '1', 'action' => 'block' },
|
833
|
+
{ 'rule_id' => '2', 'action' => 'ignore' }
|
834
|
+
]
|
835
|
+
}
|
836
|
+
}
|
837
|
+
}
|
838
|
+
)
|
839
|
+
|
840
|
+
expect(TCellAgent).to receive(:send_event).with(
|
841
|
+
{
|
842
|
+
'event_type' => 'cmdi',
|
843
|
+
'commands' => [
|
844
|
+
{ 'command' => 'cat', 'arg_count' => 1 },
|
845
|
+
{ 'command' => 'grep', 'arg_count' => 1 }
|
846
|
+
],
|
847
|
+
'blocked' => true,
|
848
|
+
'matches' => [{ 'rule_id' => '1' }],
|
849
|
+
'm' => 'GET',
|
850
|
+
'remote_addr' => '1.1.1.1',
|
851
|
+
'rid' => '12345',
|
852
|
+
'sid' => 'sldfjk2343',
|
853
|
+
'uid' => 'user_id'
|
710
854
|
}
|
711
|
-
|
712
|
-
|
713
|
-
expect(TCellAgent).to receive(:send_event).with({
|
714
|
-
"event_type" => "cmdi",
|
715
|
-
"commands" => [{"command" => "cat", "arg_count" => 1}, {"command" => "grep", "arg_count" => 1}],
|
716
|
-
"blocked" => true,
|
717
|
-
"matches" => [{"rule_id" => "1"}],
|
718
|
-
"method" => "GET",
|
719
|
-
"remote_address" => "1.1.1.1",
|
720
|
-
"route_id" => "12345",
|
721
|
-
"session_id" => "sldfjk2343",
|
722
|
-
"user_id" => "user_id"
|
723
|
-
})
|
855
|
+
)
|
724
856
|
|
725
857
|
expect(
|
726
|
-
|
858
|
+
@rust_policies.block_command?('cat /etc/passwd | grep root', @tcell_context)
|
727
859
|
).to eq(true)
|
728
860
|
end
|
729
|
-
|
730
861
|
end
|
731
862
|
end
|
732
863
|
end
|
733
|
-
|
734
864
|
end
|
735
865
|
end
|
736
866
|
end
|