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
|
@@ -1,522 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
module TCellAgent
|
|
4
|
-
module AppSensor
|
|
5
|
-
|
|
6
|
-
describe "InjectionsMatcher" do
|
|
7
|
-
|
|
8
|
-
describe ".from_json" do
|
|
9
|
-
context "with nil json" do
|
|
10
|
-
it "should create a disabled injections matcher" do
|
|
11
|
-
injection_matcher = InjectionsMatcher.from_json(1, nil)
|
|
12
|
-
|
|
13
|
-
expect(injection_matcher.enabled).to eq(false)
|
|
14
|
-
expect(injection_matcher.sensors).to eq([])
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
context "with empty json" do
|
|
19
|
-
it "should create a disabled injections matcher" do
|
|
20
|
-
injection_matcher = InjectionsMatcher.from_json(1, {})
|
|
21
|
-
|
|
22
|
-
expect(injection_matcher.enabled).to eq(false)
|
|
23
|
-
expect(injection_matcher.sensors).to eq([])
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
context "with v1 sensors config" do
|
|
28
|
-
context "with nil options" do
|
|
29
|
-
it "should create a disabled injection matcher" do
|
|
30
|
-
injection_matcher = InjectionsMatcher.from_json(1, {"options" => nil})
|
|
31
|
-
|
|
32
|
-
expect(injection_matcher.enabled).to eq(false)
|
|
33
|
-
expect(injection_matcher.sensors).to eq([])
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
context "with empty options" do
|
|
38
|
-
it "should create a disabled injection matcher" do
|
|
39
|
-
injection_matcher = InjectionsMatcher.from_json(1, {"options" => []})
|
|
40
|
-
|
|
41
|
-
expect(injection_matcher.enabled).to eq(false)
|
|
42
|
-
expect(injection_matcher.sensors).to eq([])
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
context "with xss sensor disabled" do
|
|
47
|
-
it "should create no sensors" do
|
|
48
|
-
sensors_json = {
|
|
49
|
-
"options" => {
|
|
50
|
-
"xss" => false
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
injection_matcher = InjectionsMatcher.from_json(1, sensors_json)
|
|
55
|
-
|
|
56
|
-
expect(injection_matcher.enabled).to eq(false)
|
|
57
|
-
expect(injection_matcher.sensors).to eq([])
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
context "with xss sensor enabled" do
|
|
62
|
-
it "should create an xss sensors" do
|
|
63
|
-
sensors_json = {
|
|
64
|
-
"options" => {
|
|
65
|
-
"xss" => true
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
injection_matcher = InjectionsMatcher.from_json(1, sensors_json)
|
|
70
|
-
|
|
71
|
-
expect(injection_matcher.enabled).to eq(true)
|
|
72
|
-
expect(injection_matcher.sensors.size).to eq(1)
|
|
73
|
-
expect(injection_matcher.sensors[ 0 ].enabled).to eq(true)
|
|
74
|
-
expect(injection_matcher.sensors[ 0 ].libinjection).to eq(false)
|
|
75
|
-
expect(injection_matcher.sensors[ 0 ].detection_point).to eq("xss")
|
|
76
|
-
expect(injection_matcher.sensors[ 0 ].exclude_headers).to eq(false)
|
|
77
|
-
expect(injection_matcher.sensors[ 0 ].exclude_forms).to eq(false)
|
|
78
|
-
expect(injection_matcher.sensors[ 0 ].exclude_cookies).to eq(false)
|
|
79
|
-
expect(injection_matcher.sensors[ 0 ].exclusions).to eq({})
|
|
80
|
-
expect(injection_matcher.sensors[ 0 ].active_pattern_ids).to eq(Set.new)
|
|
81
|
-
expect(injection_matcher.sensors[ 0 ].v1_compatability_enabled).to eq(true)
|
|
82
|
-
expect(injection_matcher.sensors[ 0 ].excluded_route_ids).to eq(Set.new)
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
context "with two sensors" do
|
|
87
|
-
context "one is disabled and one is enabled" do
|
|
88
|
-
it "should create one sensor" do
|
|
89
|
-
sensors_json = {
|
|
90
|
-
"options" => {
|
|
91
|
-
"sqli" => false,
|
|
92
|
-
"xss" => true
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
injection_matcher = InjectionsMatcher.from_json(1, sensors_json)
|
|
97
|
-
|
|
98
|
-
expect(injection_matcher.enabled).to eq(true)
|
|
99
|
-
expect(injection_matcher.sensors.size).to eq(1)
|
|
100
|
-
expect(injection_matcher.sensors[ 0 ].enabled).to eq(true)
|
|
101
|
-
expect(injection_matcher.sensors[ 0 ].libinjection).to eq(false)
|
|
102
|
-
expect(injection_matcher.sensors[ 0 ].detection_point).to eq("xss")
|
|
103
|
-
expect(injection_matcher.sensors[ 0 ].exclude_headers).to eq(false)
|
|
104
|
-
expect(injection_matcher.sensors[ 0 ].exclude_forms).to eq(false)
|
|
105
|
-
expect(injection_matcher.sensors[ 0 ].exclude_cookies).to eq(false)
|
|
106
|
-
expect(injection_matcher.sensors[ 0 ].exclusions).to eq({})
|
|
107
|
-
expect(injection_matcher.sensors[ 0 ].active_pattern_ids).to eq(Set.new)
|
|
108
|
-
expect(injection_matcher.sensors[ 0 ].v1_compatability_enabled).to eq(true)
|
|
109
|
-
expect(injection_matcher.sensors[ 0 ].excluded_route_ids).to eq(Set.new)
|
|
110
|
-
end
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
context "both enabled" do
|
|
114
|
-
it "should create two sensors" do
|
|
115
|
-
sensors_json = {
|
|
116
|
-
"options" => {
|
|
117
|
-
"sqli" => true,
|
|
118
|
-
"xss" => true
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
injection_matcher = InjectionsMatcher.from_json(1, sensors_json)
|
|
123
|
-
|
|
124
|
-
sorted_sensors = injection_matcher.sensors.sort { |a,b| a.detection_point <=> b.detection_point }
|
|
125
|
-
|
|
126
|
-
expect(injection_matcher.enabled).to eq(true)
|
|
127
|
-
expect(injection_matcher.sensors.size).to eq(2)
|
|
128
|
-
expect(sorted_sensors[ 0 ].enabled).to eq(true)
|
|
129
|
-
expect(sorted_sensors[ 0 ].libinjection).to eq(false)
|
|
130
|
-
expect(sorted_sensors[ 0 ].detection_point).to eq("sqli")
|
|
131
|
-
expect(sorted_sensors[ 0 ].exclude_headers).to eq(false)
|
|
132
|
-
expect(sorted_sensors[ 0 ].exclude_forms).to eq(false)
|
|
133
|
-
expect(sorted_sensors[ 0 ].exclude_cookies).to eq(false)
|
|
134
|
-
expect(sorted_sensors[ 0 ].exclusions).to eq({})
|
|
135
|
-
expect(sorted_sensors[ 0 ].active_pattern_ids).to eq(Set.new)
|
|
136
|
-
expect(sorted_sensors[ 0 ].v1_compatability_enabled).to eq(true)
|
|
137
|
-
expect(sorted_sensors[ 0 ].excluded_route_ids).to eq(Set.new)
|
|
138
|
-
expect(sorted_sensors[ 1 ].enabled).to eq(true)
|
|
139
|
-
expect(sorted_sensors[ 1 ].libinjection).to eq(false)
|
|
140
|
-
expect(sorted_sensors[ 1 ].detection_point).to eq("xss")
|
|
141
|
-
expect(sorted_sensors[ 1 ].exclude_headers).to eq(false)
|
|
142
|
-
expect(sorted_sensors[ 1 ].exclude_forms).to eq(false)
|
|
143
|
-
expect(sorted_sensors[ 1 ].exclude_cookies).to eq(false)
|
|
144
|
-
expect(sorted_sensors[ 1 ].exclusions).to eq({})
|
|
145
|
-
expect(sorted_sensors[ 1 ].active_pattern_ids).to eq(Set.new)
|
|
146
|
-
expect(sorted_sensors[ 1 ].v1_compatability_enabled).to eq(true)
|
|
147
|
-
expect(sorted_sensors[ 1 ].excluded_route_ids).to eq(Set.new)
|
|
148
|
-
end
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
context "both disabled" do
|
|
152
|
-
it "should create no sensors and be disabled" do
|
|
153
|
-
sensors_json = {
|
|
154
|
-
"options" => {
|
|
155
|
-
"sqli" => false,
|
|
156
|
-
"xss" => false
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
injection_matcher = InjectionsMatcher.from_json(1, sensors_json)
|
|
161
|
-
|
|
162
|
-
expect(injection_matcher.enabled).to eq(false)
|
|
163
|
-
expect(injection_matcher.sensors.size).to eq(0)
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
end
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
context "with resp_codes sensor enabled" do
|
|
170
|
-
it "should create no sensors" do
|
|
171
|
-
sensors_json = {
|
|
172
|
-
"options" => {
|
|
173
|
-
"resp_codes" => true
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
injection_matcher = InjectionsMatcher.from_json(1, sensors_json)
|
|
178
|
-
|
|
179
|
-
expect(injection_matcher.enabled).to eq(false)
|
|
180
|
-
expect(injection_matcher.sensors).to eq([])
|
|
181
|
-
end
|
|
182
|
-
end
|
|
183
|
-
end
|
|
184
|
-
|
|
185
|
-
context "with v2 sensors config" do
|
|
186
|
-
context "with a sensor config that's not an injection sensor" do
|
|
187
|
-
it "should ignore the sensor config" do
|
|
188
|
-
sensors_json = {
|
|
189
|
-
"req_size" => {
|
|
190
|
-
"limit" => 1024,
|
|
191
|
-
"exclude_routes" => ["2300"]
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
injection_matcher = InjectionsMatcher.from_json(2, sensors_json)
|
|
196
|
-
|
|
197
|
-
expect(injection_matcher.enabled).to eq(false)
|
|
198
|
-
expect(injection_matcher.sensors.size).to eq(0)
|
|
199
|
-
end
|
|
200
|
-
end
|
|
201
|
-
|
|
202
|
-
context "with a disabled sensor config" do
|
|
203
|
-
it "should create no sensors and be disabled" do
|
|
204
|
-
sensors_json = {
|
|
205
|
-
"xss" => {
|
|
206
|
-
"enabled" => false,
|
|
207
|
-
"libinjection" => true,
|
|
208
|
-
"patterns" => ["1","2","8"],
|
|
209
|
-
"exclusions" => {
|
|
210
|
-
"bob" => ["*"]
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
injection_matcher = InjectionsMatcher.from_json(2, sensors_json)
|
|
216
|
-
|
|
217
|
-
expect(injection_matcher.enabled).to eq(false)
|
|
218
|
-
expect(injection_matcher.sensors.size).to eq(0)
|
|
219
|
-
end
|
|
220
|
-
end
|
|
221
|
-
|
|
222
|
-
context "with one sensor config" do
|
|
223
|
-
it "should create one sensor" do
|
|
224
|
-
sensors_json = {
|
|
225
|
-
"xss" => {
|
|
226
|
-
"libinjection" => true,
|
|
227
|
-
"patterns" => ["1","2","8"],
|
|
228
|
-
"exclusions" => {
|
|
229
|
-
"bob" => ["*"]
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
injection_matcher = InjectionsMatcher.from_json(2, sensors_json)
|
|
235
|
-
|
|
236
|
-
expect(injection_matcher.enabled).to eq(true)
|
|
237
|
-
expect(injection_matcher.sensors.size).to eq(1)
|
|
238
|
-
expect(injection_matcher.sensors[0].enabled).to eq(true)
|
|
239
|
-
expect(injection_matcher.sensors[0].detection_point).to eq("xss")
|
|
240
|
-
expect(injection_matcher.sensors[0].exclude_headers).to eq(false)
|
|
241
|
-
expect(injection_matcher.sensors[0].exclude_forms).to eq(false)
|
|
242
|
-
expect(injection_matcher.sensors[0].exclude_cookies).to eq(false)
|
|
243
|
-
expect(injection_matcher.sensors[0].exclusions).to eq({"bob" => Set.new(["*"])})
|
|
244
|
-
expect(injection_matcher.sensors[0].active_pattern_ids).to eq(Set.new(["1", "2", "8"]))
|
|
245
|
-
expect(injection_matcher.sensors[0].v1_compatability_enabled).to eq(false)
|
|
246
|
-
expect(injection_matcher.sensors[0].excluded_route_ids).to eq(Set.new)
|
|
247
|
-
end
|
|
248
|
-
end
|
|
249
|
-
|
|
250
|
-
context "with two sensor configs" do
|
|
251
|
-
context "one enabled and one disabled" do
|
|
252
|
-
it "should create one sensor" do
|
|
253
|
-
sensors_json = {
|
|
254
|
-
"sqli" => {
|
|
255
|
-
"enabled" => false,
|
|
256
|
-
"libinjection" => true,
|
|
257
|
-
"patterns" => ["1","2","8"],
|
|
258
|
-
"exclusions" => {
|
|
259
|
-
"bob" => ["*"]
|
|
260
|
-
}
|
|
261
|
-
},
|
|
262
|
-
"xss" => {
|
|
263
|
-
"libinjection" => true,
|
|
264
|
-
"patterns" => ["1","2","8"],
|
|
265
|
-
"exclusions" => {
|
|
266
|
-
"bob" => ["*"]
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
injection_matcher = InjectionsMatcher.from_json(2, sensors_json)
|
|
272
|
-
|
|
273
|
-
expect(injection_matcher.enabled).to eq(true)
|
|
274
|
-
expect(injection_matcher.sensors.size).to eq(1)
|
|
275
|
-
expect(injection_matcher.sensors[0].enabled).to eq(true)
|
|
276
|
-
expect(injection_matcher.sensors[0].detection_point).to eq("xss")
|
|
277
|
-
expect(injection_matcher.sensors[0].exclude_headers).to eq(false)
|
|
278
|
-
expect(injection_matcher.sensors[0].exclude_forms).to eq(false)
|
|
279
|
-
expect(injection_matcher.sensors[0].exclude_cookies).to eq(false)
|
|
280
|
-
expect(injection_matcher.sensors[0].exclusions).to eq({"bob" => Set.new(["*"])})
|
|
281
|
-
expect(injection_matcher.sensors[0].active_pattern_ids).to eq(Set.new(["1", "2", "8"]))
|
|
282
|
-
expect(injection_matcher.sensors[0].v1_compatability_enabled).to eq(false)
|
|
283
|
-
expect(injection_matcher.sensors[0].excluded_route_ids).to eq(Set.new)
|
|
284
|
-
end
|
|
285
|
-
end
|
|
286
|
-
|
|
287
|
-
context "both disabled" do
|
|
288
|
-
it "should create no sensors and be disabled" do
|
|
289
|
-
sensors_json = {
|
|
290
|
-
"sqli" => {
|
|
291
|
-
"enabled" => false,
|
|
292
|
-
"libinjection" => true,
|
|
293
|
-
"patterns" => ["1","2","8"],
|
|
294
|
-
"exclusions" => {
|
|
295
|
-
"bob" => ["*"]
|
|
296
|
-
}
|
|
297
|
-
},
|
|
298
|
-
"xss" => {
|
|
299
|
-
"enabled" => false,
|
|
300
|
-
"libinjection" => true,
|
|
301
|
-
"patterns" => ["1","2","8"],
|
|
302
|
-
"exclusions" => {
|
|
303
|
-
"bob" => ["*"]
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
injection_matcher = InjectionsMatcher.from_json(2, sensors_json)
|
|
309
|
-
|
|
310
|
-
expect(injection_matcher.enabled).to eq(false)
|
|
311
|
-
expect(injection_matcher.sensors.size).to eq(0)
|
|
312
|
-
end
|
|
313
|
-
end
|
|
314
|
-
|
|
315
|
-
context "both enabled" do
|
|
316
|
-
it "should create two sensors" do
|
|
317
|
-
sensors_json = {
|
|
318
|
-
"sqli" => {
|
|
319
|
-
"libinjection" => true,
|
|
320
|
-
"patterns" => ["1","2","8"],
|
|
321
|
-
"exclusions" => {
|
|
322
|
-
"bob" => ["*"]
|
|
323
|
-
}
|
|
324
|
-
},
|
|
325
|
-
"xss" => {
|
|
326
|
-
"libinjection" => true,
|
|
327
|
-
"patterns" => ["3","4","5"],
|
|
328
|
-
"exclusions" => {
|
|
329
|
-
"bob" => ["*"]
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
injection_matcher = InjectionsMatcher.from_json(2, sensors_json)
|
|
335
|
-
|
|
336
|
-
sorted_sensors = injection_matcher.sensors.sort { |a,b| a.detection_point <=> b.detection_point }
|
|
337
|
-
|
|
338
|
-
expect(injection_matcher.enabled).to eq(true)
|
|
339
|
-
expect(injection_matcher.sensors.size).to eq(2)
|
|
340
|
-
expect(sorted_sensors[0].enabled).to eq(true)
|
|
341
|
-
expect(sorted_sensors[0].detection_point).to eq("sqli")
|
|
342
|
-
expect(sorted_sensors[0].exclude_headers).to eq(false)
|
|
343
|
-
expect(sorted_sensors[0].exclude_forms).to eq(false)
|
|
344
|
-
expect(sorted_sensors[0].exclude_cookies).to eq(false)
|
|
345
|
-
expect(sorted_sensors[0].exclusions).to eq({"bob" => Set.new(["*"])})
|
|
346
|
-
expect(sorted_sensors[0].active_pattern_ids).to eq(Set.new(["1", "2", "8"]))
|
|
347
|
-
expect(sorted_sensors[0].v1_compatability_enabled).to eq(false)
|
|
348
|
-
expect(sorted_sensors[0].excluded_route_ids).to eq(Set.new)
|
|
349
|
-
expect(sorted_sensors[1].enabled).to eq(true)
|
|
350
|
-
expect(sorted_sensors[1].detection_point).to eq("xss")
|
|
351
|
-
expect(sorted_sensors[1].exclude_headers).to eq(false)
|
|
352
|
-
expect(sorted_sensors[1].exclude_forms).to eq(false)
|
|
353
|
-
expect(sorted_sensors[1].exclude_cookies).to eq(false)
|
|
354
|
-
expect(sorted_sensors[1].exclusions).to eq({"bob" => Set.new(["*"])})
|
|
355
|
-
expect(sorted_sensors[1].active_pattern_ids).to eq(Set.new(["3", "4", "5"]))
|
|
356
|
-
expect(sorted_sensors[1].v1_compatability_enabled).to eq(false)
|
|
357
|
-
expect(sorted_sensors[1].excluded_route_ids).to eq(Set.new)
|
|
358
|
-
end
|
|
359
|
-
end
|
|
360
|
-
end
|
|
361
|
-
|
|
362
|
-
end
|
|
363
|
-
end
|
|
364
|
-
|
|
365
|
-
describe "#check_param_for_injections" do
|
|
366
|
-
before(:each) do
|
|
367
|
-
@meta_data = TCellAgent::AppSensor::MetaData.new(
|
|
368
|
-
"get",
|
|
369
|
-
"remote_address",
|
|
370
|
-
"route_id",
|
|
371
|
-
"session_id",
|
|
372
|
-
"user_id",
|
|
373
|
-
"transaction_id")
|
|
374
|
-
end
|
|
375
|
-
|
|
376
|
-
context "with no sensors" do
|
|
377
|
-
it "should not find any injections" do
|
|
378
|
-
injection_matcher = InjectionsMatcher.new([])
|
|
379
|
-
|
|
380
|
-
result = injection_matcher.check_param_for_injections(
|
|
381
|
-
InjectionsMatcher::URI_PARAM, @meta_data, "dirty", "<script></script>"
|
|
382
|
-
)
|
|
383
|
-
|
|
384
|
-
expect(result).to eq(nil)
|
|
385
|
-
end
|
|
386
|
-
end
|
|
387
|
-
|
|
388
|
-
context "with one sensors that finds an injection" do
|
|
389
|
-
it "should return the injection attempt" do
|
|
390
|
-
fake_sensor = double("fake_sensor")
|
|
391
|
-
|
|
392
|
-
injection_matcher = InjectionsMatcher.new([fake_sensor])
|
|
393
|
-
|
|
394
|
-
expect(fake_sensor).to receive(:applicable_for_param_type?).with(
|
|
395
|
-
InjectionsMatcher::URI_PARAM
|
|
396
|
-
).and_return(true)
|
|
397
|
-
expect(fake_sensor).to receive(:get_injection_attempt).with(
|
|
398
|
-
InjectionsMatcher::URI_PARAM, @meta_data, "dirty", "<script></script>"
|
|
399
|
-
).and_return({"injection" => true})
|
|
400
|
-
|
|
401
|
-
result = injection_matcher.check_param_for_injections(
|
|
402
|
-
InjectionsMatcher::URI_PARAM, @meta_data, "dirty", "<script></script>"
|
|
403
|
-
)
|
|
404
|
-
|
|
405
|
-
expect(result).to eq({"injection" => true})
|
|
406
|
-
end
|
|
407
|
-
end
|
|
408
|
-
end
|
|
409
|
-
|
|
410
|
-
describe "#each_injection" do
|
|
411
|
-
context "with appsensor meta data" do
|
|
412
|
-
context "with one param of each type" do
|
|
413
|
-
it "should call check_param_for_injections once for each param" do
|
|
414
|
-
meta_data = TCellAgent::SensorEvents::AppSensorMetaEvent.new(
|
|
415
|
-
"get",
|
|
416
|
-
"remote_address",
|
|
417
|
-
"route_id",
|
|
418
|
-
"session_id",
|
|
419
|
-
"user_id",
|
|
420
|
-
"transaction_id")
|
|
421
|
-
meta_data.get_dict = {"get_param" => "get_value"}
|
|
422
|
-
# post dict for appsensor meta data gets flatten before being enqueued
|
|
423
|
-
meta_data.post_dict = TCellAgent::Utils::Params.flatten({"post_param" => "post_value"})
|
|
424
|
-
meta_data.body_dict = TCellAgent::Utils::Params.flatten({"body_param" => "body_value"})
|
|
425
|
-
meta_data.cookie_dict = {"cookie_param" => "cookie_value"}
|
|
426
|
-
meta_data.path_parameters = {"path_param" => "path_value"}
|
|
427
|
-
|
|
428
|
-
uri_injection = double("uri_injection")
|
|
429
|
-
get_injection = double("get_injection")
|
|
430
|
-
post_injection = double("post_injection")
|
|
431
|
-
json_injection = double("json_injection")
|
|
432
|
-
cookie_injection = double("cookie_injection")
|
|
433
|
-
|
|
434
|
-
injections_matcher = InjectionsMatcher.new([double("fake_sensor")])
|
|
435
|
-
|
|
436
|
-
expect(injections_matcher).to receive(:check_param_for_injections).with(
|
|
437
|
-
InjectionsMatcher::URI_PARAM, meta_data, "path_param", "path_value"
|
|
438
|
-
).and_return(uri_injection)
|
|
439
|
-
expect(injections_matcher).to receive(:check_param_for_injections).with(
|
|
440
|
-
InjectionsMatcher::GET_PARAM, meta_data, "get_param", "get_value"
|
|
441
|
-
).and_return(get_injection)
|
|
442
|
-
expect(injections_matcher).to receive(:check_param_for_injections).with(
|
|
443
|
-
InjectionsMatcher::POST_PARAM, meta_data, "post_param", "post_value"
|
|
444
|
-
).and_return(post_injection)
|
|
445
|
-
expect(injections_matcher).to receive(:check_param_for_injections).with(
|
|
446
|
-
InjectionsMatcher::JSON_PARAM, meta_data, "body_param", "body_value"
|
|
447
|
-
).and_return(json_injection)
|
|
448
|
-
expect(injections_matcher).to receive(:check_param_for_injections).with(
|
|
449
|
-
InjectionsMatcher::COOKIE_PARAM, meta_data, "cookie_param", "cookie_value"
|
|
450
|
-
).and_return(cookie_injection)
|
|
451
|
-
|
|
452
|
-
injection_attempts = []
|
|
453
|
-
injections_matcher.each_injection(meta_data) do |injection_attempt|
|
|
454
|
-
injection_attempts.push(injection_attempt)
|
|
455
|
-
end
|
|
456
|
-
|
|
457
|
-
expect(injection_attempts.size).to eq(5)
|
|
458
|
-
expect(injection_attempts).to eq(
|
|
459
|
-
[uri_injection, get_injection, post_injection, json_injection, cookie_injection]
|
|
460
|
-
)
|
|
461
|
-
end
|
|
462
|
-
end
|
|
463
|
-
end
|
|
464
|
-
|
|
465
|
-
context "with patches meta data" do
|
|
466
|
-
context "with one param of each type" do
|
|
467
|
-
it "should call check_param_for_injections once for each param" do
|
|
468
|
-
meta_data = TCellAgent::Patches::MetaData.new(
|
|
469
|
-
"get",
|
|
470
|
-
"remote_address",
|
|
471
|
-
"route_id",
|
|
472
|
-
"session_id",
|
|
473
|
-
"user_id",
|
|
474
|
-
"transaction_id")
|
|
475
|
-
meta_data.get_dict = {"get_param" => "get_value"}
|
|
476
|
-
meta_data.post_dict = {"post_param" => "post_value"}
|
|
477
|
-
meta_data.body_dict = TCellAgent::Utils::Params.flatten({"body_param" => "body_value"})
|
|
478
|
-
meta_data.cookie_dict = {"cookie_param" => "cookie_value"}
|
|
479
|
-
meta_data.path_parameters = {"path_param" => "path_value"}
|
|
480
|
-
|
|
481
|
-
uri_injection = double("uri_injection")
|
|
482
|
-
get_injection = double("get_injection")
|
|
483
|
-
post_injection = double("post_injection")
|
|
484
|
-
json_injection = double("json_injection")
|
|
485
|
-
cookie_injection = double("cookie_injection")
|
|
486
|
-
|
|
487
|
-
injections_matcher = InjectionsMatcher.new([double("fake_sensor")])
|
|
488
|
-
|
|
489
|
-
expect(injections_matcher).to receive(:check_param_for_injections).with(
|
|
490
|
-
InjectionsMatcher::URI_PARAM, meta_data, "path_param", "path_value"
|
|
491
|
-
).and_return(uri_injection)
|
|
492
|
-
expect(injections_matcher).to receive(:check_param_for_injections).with(
|
|
493
|
-
InjectionsMatcher::GET_PARAM, meta_data, "get_param", "get_value"
|
|
494
|
-
).and_return(get_injection)
|
|
495
|
-
expect(injections_matcher).to receive(:check_param_for_injections).with(
|
|
496
|
-
InjectionsMatcher::POST_PARAM, meta_data, "post_param", "post_value"
|
|
497
|
-
).and_return(post_injection)
|
|
498
|
-
expect(injections_matcher).to receive(:check_param_for_injections).with(
|
|
499
|
-
InjectionsMatcher::JSON_PARAM, meta_data, "body_param", "body_value"
|
|
500
|
-
).and_return(json_injection)
|
|
501
|
-
expect(injections_matcher).to receive(:check_param_for_injections).with(
|
|
502
|
-
InjectionsMatcher::COOKIE_PARAM, meta_data, "cookie_param", "cookie_value"
|
|
503
|
-
).and_return(cookie_injection)
|
|
504
|
-
|
|
505
|
-
injection_attempts = []
|
|
506
|
-
injections_matcher.each_injection(meta_data) do |injection_attempt|
|
|
507
|
-
injection_attempts.push(injection_attempt)
|
|
508
|
-
end
|
|
509
|
-
|
|
510
|
-
expect(injection_attempts.size).to eq(5)
|
|
511
|
-
expect(injection_attempts).to eq(
|
|
512
|
-
[uri_injection, get_injection, post_injection, json_injection, cookie_injection]
|
|
513
|
-
)
|
|
514
|
-
end
|
|
515
|
-
end
|
|
516
|
-
|
|
517
|
-
end
|
|
518
|
-
end
|
|
519
|
-
end
|
|
520
|
-
|
|
521
|
-
end
|
|
522
|
-
end
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
module TCellAgent
|
|
4
|
-
|
|
5
|
-
describe AppSensorRuleManager do
|
|
6
|
-
after(:each) do
|
|
7
|
-
# since rule manager is a singleton, load default rules so rest of the specs work properly
|
|
8
|
-
AppSensorRuleManager.instance.load_default_rules_file
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
describe "#load_rules_file" do
|
|
12
|
-
context "with nonexistent file" do
|
|
13
|
-
it "should do nothing" do
|
|
14
|
-
rule_manager = AppSensorRuleManager.instance
|
|
15
|
-
rule_manager.load_rules_file("non-existent-file.json")
|
|
16
|
-
|
|
17
|
-
expect(rule_manager.rule_info.empty?).to eq(true)
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
end
|