tcell_agent 0.4.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,389 +2,458 @@ require 'spec_helper'
|
|
|
2
2
|
|
|
3
3
|
module TCellAgent
|
|
4
4
|
module Policies
|
|
5
|
-
|
|
6
|
-
describe AppSensorPolicy do
|
|
7
|
-
|
|
5
|
+
describe RustPolicies do
|
|
8
6
|
everything_enabled_policy_json = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"payloads" => {
|
|
17
|
-
"send_payloads" => true,
|
|
18
|
-
"send_blacklist" => {
|
|
19
|
-
"ssn" => ["*"],
|
|
20
|
-
"password" => ["*"]
|
|
7
|
+
'appsensor' => {
|
|
8
|
+
'policy_id' => '01a1',
|
|
9
|
+
'version' => 2,
|
|
10
|
+
'data' => {
|
|
11
|
+
'options' => {
|
|
12
|
+
'uri_options' => {
|
|
13
|
+
'collect_full_uri' => true
|
|
21
14
|
},
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
15
|
+
'payloads' => {
|
|
16
|
+
'send_payloads' => true,
|
|
17
|
+
'send_blacklist' => {
|
|
18
|
+
'ssn' => ['*'],
|
|
19
|
+
'password' => ['*']
|
|
20
|
+
},
|
|
21
|
+
'send_whitelist' => {},
|
|
22
|
+
'log_payloads' => true,
|
|
23
|
+
'log_blacklist' => {},
|
|
24
|
+
'log_whitelist' => {
|
|
25
|
+
'username' => ['*']
|
|
26
|
+
}
|
|
27
27
|
}
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
"sensors" => {
|
|
31
|
-
"req_size" => {
|
|
32
|
-
"limit" => 1024,
|
|
33
|
-
"exclude_routes" => ["2300"]
|
|
34
28
|
},
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
29
|
+
'sensors' => {
|
|
30
|
+
'req_size' => {
|
|
31
|
+
'limit' => 1024,
|
|
32
|
+
'exclude_routes' => ['2300']
|
|
33
|
+
},
|
|
34
|
+
'resp_size' => {
|
|
35
|
+
'limit' => 2048,
|
|
36
|
+
'exclude_routes' => ['2323']
|
|
37
|
+
},
|
|
38
|
+
'resp_codes' => {
|
|
39
|
+
'series_400_enabled' => true,
|
|
40
|
+
'series_500_enabled' => true
|
|
41
|
+
},
|
|
42
|
+
'xss' => {
|
|
43
|
+
'libinjection' => true,
|
|
44
|
+
'patterns' => %w[1 2 8],
|
|
45
|
+
'exclusions' => {
|
|
46
|
+
'bob' => ['*']
|
|
48
47
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
48
|
+
},
|
|
49
|
+
'sqli' => {
|
|
50
|
+
'libinjection' => true,
|
|
51
|
+
'exclude_headers' => true,
|
|
52
|
+
'patterns' => ['1']
|
|
53
|
+
},
|
|
54
|
+
'fpt' => {
|
|
55
|
+
'patterns' => %w[1 2],
|
|
56
|
+
'exclude_forms' => true,
|
|
57
|
+
'exclude_cookies' => true,
|
|
58
|
+
'exclusions' => {
|
|
59
|
+
'somethingcommon' => ['form']
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
'cmdi' => {
|
|
63
|
+
'patterns' => %w[1 2]
|
|
64
|
+
},
|
|
65
|
+
'nullbyte' => {
|
|
66
|
+
'patterns' => %w[1 2]
|
|
67
|
+
},
|
|
68
|
+
'retr' => {
|
|
69
|
+
'patterns' => %w[1 2]
|
|
70
|
+
},
|
|
71
|
+
'ua' => {
|
|
72
|
+
'empty_enabled' => true
|
|
73
|
+
},
|
|
74
|
+
'errors' => {
|
|
75
|
+
'csrf_exception_enabled' => true,
|
|
76
|
+
'sql_exception_enabled' => true
|
|
77
|
+
},
|
|
78
|
+
'database' => {
|
|
79
|
+
'large_result' => {
|
|
80
|
+
'limit' => 10
|
|
61
81
|
}
|
|
62
|
-
},
|
|
63
|
-
"cmdi" => {
|
|
64
|
-
"patterns" => ["1","2"]
|
|
65
|
-
},
|
|
66
|
-
"nullbyte" => {
|
|
67
|
-
"patterns" => ["1","2"]
|
|
68
|
-
},
|
|
69
|
-
"retr" => {
|
|
70
|
-
"patterns" => ["1","2"]
|
|
71
|
-
},
|
|
72
|
-
"ua" => {
|
|
73
|
-
"empty_enabled" => true,
|
|
74
|
-
},
|
|
75
|
-
"errors" => {
|
|
76
|
-
"csrf_exception_enabled" => true,
|
|
77
|
-
"sql_exception_enabled" => true
|
|
78
|
-
},
|
|
79
|
-
"database" => {
|
|
80
|
-
"large_result" => {
|
|
81
|
-
"limit" => 10
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
|
+
},
|
|
86
|
+
'regex' => {
|
|
87
|
+
'data' => {
|
|
88
|
+
'patterns' => [
|
|
89
|
+
{
|
|
90
|
+
'id' => 'tc-xss-1',
|
|
91
|
+
'pattern' => '(?:<(script))',
|
|
92
|
+
'sensor' => 'xss',
|
|
93
|
+
'title' => 'Basic Injection'
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
'safe_pattern' => '^[a-zA-Z0-9_\\s\\r\\n\\t]*$',
|
|
97
|
+
'pattern' => '(?:[\\s()]case\\s*\\()|(?:\\)\\s*like\\s*\\()|(?:having\\s*[^\\s]+\\s*[^\\w\\s])|(?:if\\s?\\([\\d\\w]\\s*[=<>~])',
|
|
98
|
+
'sensor' => 'sqli',
|
|
99
|
+
'id' => 'tc-sqli-1',
|
|
100
|
+
'title' => 'Conditional Attempts'
|
|
101
|
+
}
|
|
102
|
+
],
|
|
103
|
+
'version' => 1_518_546_622_571
|
|
104
|
+
},
|
|
105
|
+
'policy_id' => 'f3a313b0-10eb-11e8-8080-808080808080',
|
|
106
|
+
'version' => 1
|
|
85
107
|
}
|
|
86
108
|
}
|
|
87
109
|
|
|
88
|
-
describe
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
expect(
|
|
110
|
+
describe '#update_policies' do
|
|
111
|
+
before(:each) do
|
|
112
|
+
@rust_policies = RustPolicies.new
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
context 'with v2 policy' do
|
|
116
|
+
context 'that is missing a policy id' do
|
|
117
|
+
it 'should have appfirewall disabled' do
|
|
118
|
+
logger = double('logger')
|
|
119
|
+
|
|
120
|
+
expect(TCellAgent).to receive(:logger).and_return(logger)
|
|
121
|
+
expect(logger).to receive(:error).with(
|
|
122
|
+
'Error updating policies: Failed to decode appsensor policy: missing field `policy_id`'
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
@rust_policies.update_policies({
|
|
126
|
+
'appsensor' => {
|
|
127
|
+
'version' => 2,
|
|
128
|
+
'data' => {}
|
|
129
|
+
}
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
expect(@rust_policies.appfirewall_enabled).to eq(false)
|
|
99
133
|
end
|
|
100
134
|
end
|
|
101
135
|
|
|
102
|
-
context
|
|
103
|
-
it
|
|
104
|
-
|
|
105
|
-
"policy_id" => "01a1",
|
|
106
|
-
"data" => { }
|
|
107
|
-
})
|
|
136
|
+
context 'that is missing a version id' do
|
|
137
|
+
it 'should have appfirewall disabled' do
|
|
138
|
+
logger = double('logger')
|
|
108
139
|
|
|
109
|
-
expect(
|
|
110
|
-
expect(
|
|
140
|
+
expect(TCellAgent).to receive(:logger).and_return(logger)
|
|
141
|
+
expect(logger).to receive(:error).with(
|
|
142
|
+
'Error updating policies: Failed to decode appsensor policy: missing field `version`'
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
@rust_policies.update_policies({
|
|
146
|
+
'appsensor' => {
|
|
147
|
+
'policy_id' => '01a1',
|
|
148
|
+
'data' => {}
|
|
149
|
+
}
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
expect(@rust_policies.appfirewall_enabled).to eq(false)
|
|
111
153
|
end
|
|
112
154
|
end
|
|
113
155
|
|
|
114
|
-
context
|
|
115
|
-
it
|
|
156
|
+
context 'that has no sensors' do
|
|
157
|
+
it 'should have all sensors disabled' do
|
|
158
|
+
expect(TCellAgent).to_not receive(:logger)
|
|
159
|
+
|
|
116
160
|
policy_json_empty = {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
161
|
+
'appsensor' => {
|
|
162
|
+
'policy_id' => '01a1',
|
|
163
|
+
'version' => 2,
|
|
164
|
+
'data' => {
|
|
165
|
+
}
|
|
120
166
|
}
|
|
121
167
|
}
|
|
122
168
|
|
|
123
|
-
|
|
169
|
+
@rust_policies.update_policies(policy_json_empty)
|
|
124
170
|
|
|
125
|
-
expect(
|
|
126
|
-
expect(empty_policy.appfirewall_ptr).to_not be_nil
|
|
171
|
+
expect(@rust_policies.appfirewall_enabled).to eq(false)
|
|
127
172
|
end
|
|
128
173
|
end
|
|
129
174
|
|
|
130
|
-
context
|
|
131
|
-
it
|
|
175
|
+
context 'that has empty sensors' do
|
|
176
|
+
it 'should have all sensors disabled' do
|
|
177
|
+
expect(TCellAgent).to_not receive(:logger)
|
|
178
|
+
|
|
132
179
|
policy_json_empty = {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
180
|
+
'appsensor' => {
|
|
181
|
+
'policy_id' => '01a1',
|
|
182
|
+
'version' => 2,
|
|
183
|
+
'data' => {
|
|
184
|
+
'sensors' => {}
|
|
185
|
+
}
|
|
137
186
|
}
|
|
138
187
|
}
|
|
139
188
|
|
|
140
|
-
|
|
189
|
+
@rust_policies.update_policies(policy_json_empty)
|
|
141
190
|
|
|
142
|
-
expect(
|
|
143
|
-
expect(empty_policy.appfirewall_ptr).to_not be_nil
|
|
191
|
+
expect(@rust_policies.appfirewall_enabled).to eq(true)
|
|
144
192
|
end
|
|
145
193
|
end
|
|
146
194
|
|
|
147
|
-
context
|
|
148
|
-
it
|
|
195
|
+
context 'that only has xss enabled' do
|
|
196
|
+
it 'should be enabled' do
|
|
197
|
+
expect(TCellAgent).to_not receive(:logger)
|
|
198
|
+
|
|
149
199
|
policy_json = {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
200
|
+
'appsensor' => {
|
|
201
|
+
'policy_id' => '01a1',
|
|
202
|
+
'version' => 2,
|
|
203
|
+
'data' => {
|
|
204
|
+
'sensors' => {
|
|
205
|
+
'xss' => {
|
|
206
|
+
'libinjection' => true,
|
|
207
|
+
'patterns' => %w[1 2 8],
|
|
208
|
+
'exclusions' => {
|
|
209
|
+
'bob' => ['*']
|
|
210
|
+
}
|
|
159
211
|
}
|
|
160
212
|
}
|
|
161
213
|
}
|
|
162
214
|
}
|
|
163
215
|
}
|
|
164
216
|
|
|
165
|
-
|
|
217
|
+
@rust_policies.update_policies(policy_json)
|
|
166
218
|
|
|
167
|
-
expect(
|
|
168
|
-
expect(policy.appfirewall_ptr).to_not be_nil
|
|
219
|
+
expect(@rust_policies.appfirewall_enabled).to eq(true)
|
|
169
220
|
end
|
|
170
221
|
end
|
|
171
222
|
|
|
172
|
-
context
|
|
173
|
-
it
|
|
174
|
-
|
|
223
|
+
context 'that has everything enabled' do
|
|
224
|
+
it 'should be enabled' do
|
|
225
|
+
expect(TCellAgent).to_not receive(:logger)
|
|
226
|
+
|
|
227
|
+
@rust_policies.update_policies(everything_enabled_policy_json)
|
|
175
228
|
|
|
176
|
-
expect(
|
|
177
|
-
expect(policy.appfirewall_ptr).to_not be_nil
|
|
229
|
+
expect(@rust_policies.appfirewall_enabled).to eq(true)
|
|
178
230
|
end
|
|
179
231
|
end
|
|
180
232
|
end
|
|
181
233
|
end
|
|
182
234
|
|
|
183
|
-
describe
|
|
184
|
-
context
|
|
235
|
+
describe '#check_appfirewall_injections' do
|
|
236
|
+
context 'with everything enabled policy' do
|
|
185
237
|
before(:each) do
|
|
186
|
-
@
|
|
238
|
+
@rust_policies = RustPolicies.new
|
|
239
|
+
@rust_policies.update_policies(everything_enabled_policy_json)
|
|
187
240
|
@appsensor_meta = TCellAgent::SensorEvents::AppSensorMetaEvent.new(
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
241
|
+
'GET',
|
|
242
|
+
'192.168.1.1',
|
|
243
|
+
'12345',
|
|
244
|
+
'session_id',
|
|
245
|
+
'user_id',
|
|
246
|
+
'transaction_id',
|
|
247
|
+
'http://test.com/?some_param=present'
|
|
248
|
+
)
|
|
249
|
+
@appsensor_meta.user_agent = 'Mozilla'
|
|
195
250
|
@appsensor_meta.response_code = 200
|
|
196
251
|
end
|
|
197
252
|
|
|
198
|
-
context
|
|
199
|
-
context
|
|
200
|
-
it
|
|
253
|
+
context 'csrf exception' do
|
|
254
|
+
context 'nil csrf exception' do
|
|
255
|
+
it 'should not send an event' do
|
|
201
256
|
expect(TCellAgent).to_not receive(:send_event)
|
|
202
257
|
|
|
203
258
|
@appsensor_meta.csrf_exception_name = nil
|
|
204
|
-
@
|
|
259
|
+
@rust_policies.check_appfirewall_injections(
|
|
205
260
|
@appsensor_meta
|
|
206
261
|
)
|
|
207
262
|
end
|
|
208
263
|
end
|
|
209
264
|
|
|
210
|
-
context
|
|
211
|
-
it
|
|
265
|
+
context 'empty csrf exception' do
|
|
266
|
+
it 'should not send an event' do
|
|
212
267
|
expect(TCellAgent).to_not receive(:send_event)
|
|
213
268
|
|
|
214
|
-
@appsensor_meta.csrf_exception_name =
|
|
215
|
-
@
|
|
269
|
+
@appsensor_meta.csrf_exception_name = ''
|
|
270
|
+
@rust_policies.check_appfirewall_injections(
|
|
216
271
|
@appsensor_meta
|
|
217
272
|
)
|
|
218
273
|
end
|
|
219
274
|
end
|
|
220
275
|
|
|
221
|
-
context
|
|
222
|
-
it
|
|
276
|
+
context 'one csrf exception' do
|
|
277
|
+
it 'should send a csrf exception event' do
|
|
223
278
|
expect(TCellAgent).to receive(:send_event).with({
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
279
|
+
'event_type' => 'as',
|
|
280
|
+
'dp' => 'excsrf',
|
|
281
|
+
'param' => 'ActionController::InvalidAuthenticityToken',
|
|
282
|
+
'm' => 'GET',
|
|
283
|
+
'rid' => '12345',
|
|
284
|
+
'full_uri' => 'http://test.com/?some_param=present',
|
|
285
|
+
'uri' => 'http://test.com/?some_param=',
|
|
286
|
+
'uid' => 'user_id',
|
|
287
|
+
'sid' => 'session_id',
|
|
288
|
+
'remote_addr' => '192.168.1.1'
|
|
289
|
+
})
|
|
290
|
+
|
|
291
|
+
@appsensor_meta.csrf_exception_name = 'ActionController::InvalidAuthenticityToken'
|
|
292
|
+
@rust_policies.check_appfirewall_injections(
|
|
236
293
|
@appsensor_meta
|
|
237
294
|
)
|
|
238
295
|
end
|
|
239
296
|
end
|
|
240
297
|
end
|
|
241
298
|
|
|
242
|
-
context
|
|
243
|
-
context
|
|
244
|
-
it
|
|
299
|
+
context 'sql exception' do
|
|
300
|
+
context 'empty sql exceptions' do
|
|
301
|
+
it 'should not send an event' do
|
|
245
302
|
expect(TCellAgent).to_not receive(:send_event)
|
|
246
303
|
|
|
247
304
|
@appsensor_meta.sql_exceptions = []
|
|
248
|
-
@
|
|
305
|
+
@rust_policies.check_appfirewall_injections(
|
|
249
306
|
@appsensor_meta
|
|
250
307
|
)
|
|
251
308
|
end
|
|
252
309
|
end
|
|
253
310
|
|
|
254
|
-
context
|
|
255
|
-
it
|
|
311
|
+
context 'one sql exception' do
|
|
312
|
+
it 'should send one event' do
|
|
256
313
|
expect(TCellAgent).to receive(:send_event).with({
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
314
|
+
'event_type' => 'as',
|
|
315
|
+
'dp' => 'exsql',
|
|
316
|
+
'param' => 'ActiveRecord::StatementInvalid',
|
|
317
|
+
'm' => 'GET',
|
|
318
|
+
'rid' => '12345',
|
|
319
|
+
'full_uri' => 'http://test.com/?some_param=present',
|
|
320
|
+
'uri' => 'http://test.com/?some_param=',
|
|
321
|
+
'uid' => 'user_id',
|
|
322
|
+
'sid' => 'session_id',
|
|
323
|
+
'remote_addr' => '192.168.1.1',
|
|
324
|
+
'payload' => 'exception message goes here'
|
|
325
|
+
})
|
|
267
326
|
|
|
268
327
|
@appsensor_meta.sql_exceptions = [{
|
|
269
|
-
|
|
270
|
-
|
|
328
|
+
'exception_name' => 'ActiveRecord::StatementInvalid',
|
|
329
|
+
'exception_payload' => 'exception message goes here'
|
|
271
330
|
}]
|
|
272
|
-
@
|
|
331
|
+
@rust_policies.check_appfirewall_injections(
|
|
273
332
|
@appsensor_meta
|
|
274
333
|
)
|
|
275
334
|
end
|
|
276
335
|
end
|
|
277
336
|
|
|
278
|
-
context
|
|
279
|
-
it
|
|
337
|
+
context 'multiple sql exception' do
|
|
338
|
+
it 'should send multiple event' do
|
|
280
339
|
expect(TCellAgent).to receive(:send_event).with({
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
340
|
+
'event_type' => 'as',
|
|
341
|
+
'dp' => 'exsql',
|
|
342
|
+
'param' => 'ActiveRecord::StatementInvalid',
|
|
343
|
+
'm' => 'GET',
|
|
344
|
+
'rid' => '12345',
|
|
345
|
+
'full_uri' => 'http://test.com/?some_param=present',
|
|
346
|
+
'uri' => 'http://test.com/?some_param=',
|
|
347
|
+
'uid' => 'user_id',
|
|
348
|
+
'sid' => 'session_id',
|
|
349
|
+
'remote_addr' => '192.168.1.1',
|
|
350
|
+
'payload' => 'exception message goes here'
|
|
351
|
+
})
|
|
291
352
|
expect(TCellAgent).to receive(:send_event).with({
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
353
|
+
'event_type' => 'as',
|
|
354
|
+
'dp' => 'exsql',
|
|
355
|
+
'param' => 'ActiveRecord::StatementInvalid',
|
|
356
|
+
'm' => 'GET',
|
|
357
|
+
'rid' => '12345',
|
|
358
|
+
'full_uri' => 'http://test.com/?some_param=present',
|
|
359
|
+
'uri' => 'http://test.com/?some_param=',
|
|
360
|
+
'uid' => 'user_id',
|
|
361
|
+
'sid' => 'session_id',
|
|
362
|
+
'remote_addr' => '192.168.1.1',
|
|
363
|
+
'payload' => 'second exception message goes here'
|
|
364
|
+
})
|
|
302
365
|
|
|
303
366
|
@appsensor_meta.sql_exceptions = [
|
|
304
367
|
{
|
|
305
|
-
|
|
306
|
-
|
|
368
|
+
'exception_name' => 'ActiveRecord::StatementInvalid',
|
|
369
|
+
'exception_payload' => 'exception message goes here'
|
|
307
370
|
},
|
|
308
371
|
{
|
|
309
|
-
|
|
310
|
-
|
|
372
|
+
'exception_name' => 'ActiveRecord::StatementInvalid',
|
|
373
|
+
'exception_payload' => 'second exception message goes here'
|
|
311
374
|
}
|
|
312
375
|
]
|
|
313
|
-
@
|
|
376
|
+
@rust_policies.check_appfirewall_injections(
|
|
314
377
|
@appsensor_meta
|
|
315
378
|
)
|
|
316
379
|
end
|
|
317
380
|
end
|
|
318
381
|
end
|
|
319
382
|
|
|
320
|
-
context
|
|
321
|
-
context
|
|
322
|
-
it
|
|
383
|
+
context 'db max result' do
|
|
384
|
+
context 'nil db max result' do
|
|
385
|
+
it 'should not send an event' do
|
|
323
386
|
expect(TCellAgent).to_not receive(:send_event)
|
|
324
387
|
|
|
325
388
|
@appsensor_meta.database_result_sizes = nil
|
|
326
|
-
@
|
|
389
|
+
@rust_policies.check_appfirewall_injections(
|
|
327
390
|
@appsensor_meta
|
|
328
391
|
)
|
|
329
392
|
end
|
|
330
393
|
end
|
|
331
394
|
|
|
332
|
-
context
|
|
333
|
-
it
|
|
395
|
+
context 'empty db max result' do
|
|
396
|
+
it 'should not send an event' do
|
|
334
397
|
expect(TCellAgent).to_not receive(:send_event)
|
|
335
398
|
|
|
336
399
|
@appsensor_meta.database_result_sizes = []
|
|
337
|
-
@
|
|
400
|
+
@rust_policies.check_appfirewall_injections(
|
|
338
401
|
@appsensor_meta
|
|
339
402
|
)
|
|
340
403
|
end
|
|
341
404
|
end
|
|
342
405
|
|
|
343
|
-
context
|
|
344
|
-
it
|
|
406
|
+
context 'one db max result' do
|
|
407
|
+
it 'should send one event' do
|
|
345
408
|
expect(TCellAgent).to receive(:send_event).with({
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
409
|
+
'event_type' => 'as',
|
|
410
|
+
'dp' => 'dbmaxrows',
|
|
411
|
+
'm' => 'GET',
|
|
412
|
+
'meta' => { 'rows' => 1001 },
|
|
413
|
+
'rid' => '12345',
|
|
414
|
+
'full_uri' => 'http://test.com/?some_param=present',
|
|
415
|
+
'uri' => 'http://test.com/?some_param=',
|
|
416
|
+
'uid' => 'user_id',
|
|
417
|
+
'sid' => 'session_id',
|
|
418
|
+
'remote_addr' => '192.168.1.1'
|
|
419
|
+
})
|
|
355
420
|
|
|
356
421
|
@appsensor_meta.database_result_sizes = [1001]
|
|
357
|
-
@
|
|
422
|
+
@rust_policies.check_appfirewall_injections(
|
|
358
423
|
@appsensor_meta
|
|
359
424
|
)
|
|
360
425
|
end
|
|
361
426
|
end
|
|
362
427
|
|
|
363
|
-
context
|
|
364
|
-
it
|
|
428
|
+
context 'multiple db max results' do
|
|
429
|
+
it 'should send multiple event' do
|
|
365
430
|
expect(TCellAgent).to receive(:send_event).with({
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
431
|
+
'event_type' => 'as',
|
|
432
|
+
'dp' => 'dbmaxrows',
|
|
433
|
+
'm' => 'GET',
|
|
434
|
+
'meta' => { 'rows' => 1001 },
|
|
435
|
+
'rid' => '12345',
|
|
436
|
+
'full_uri' => 'http://test.com/?some_param=present',
|
|
437
|
+
'uri' => 'http://test.com/?some_param=',
|
|
438
|
+
'uid' => 'user_id',
|
|
439
|
+
'sid' => 'session_id',
|
|
440
|
+
'remote_addr' => '192.168.1.1'
|
|
441
|
+
})
|
|
375
442
|
expect(TCellAgent).to receive(:send_event).with({
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
443
|
+
'event_type' => 'as',
|
|
444
|
+
'dp' => 'dbmaxrows',
|
|
445
|
+
'm' => 'GET',
|
|
446
|
+
'meta' => { 'rows' => 1002 },
|
|
447
|
+
'rid' => '12345',
|
|
448
|
+
'full_uri' => 'http://test.com/?some_param=present',
|
|
449
|
+
'uri' => 'http://test.com/?some_param=',
|
|
450
|
+
'uid' => 'user_id',
|
|
451
|
+
'sid' => 'session_id',
|
|
452
|
+
'remote_addr' => '192.168.1.1'
|
|
453
|
+
})
|
|
385
454
|
|
|
386
455
|
@appsensor_meta.database_result_sizes = [1001, 1002]
|
|
387
|
-
@
|
|
456
|
+
@rust_policies.check_appfirewall_injections(
|
|
388
457
|
@appsensor_meta
|
|
389
458
|
)
|
|
390
459
|
end
|