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
|
@@ -14,9 +14,6 @@ require "tcell_agent/policies/clickjacking_policy"
|
|
|
14
14
|
require "tcell_agent/policies/http_tx_policy"
|
|
15
15
|
require "tcell_agent/policies/http_redirect_policy"
|
|
16
16
|
require "tcell_agent/policies/secure_headers_policy"
|
|
17
|
-
require "tcell_agent/policies/honeytokens_policy"
|
|
18
|
-
require "tcell_agent/policies/appsensor_policy"
|
|
19
|
-
require "tcell_agent/policies/patches_policy"
|
|
20
17
|
|
|
21
18
|
require "tcell_agent/sensor_events/server_agent"
|
|
22
19
|
|
|
@@ -101,7 +98,7 @@ module TCellAgent
|
|
|
101
98
|
failure_sleep_time *= 2
|
|
102
99
|
end
|
|
103
100
|
|
|
104
|
-
return
|
|
101
|
+
return [failure_sleep_time, last_poll_time]
|
|
105
102
|
|
|
106
103
|
elsif policy_jsons.key?("last_timestamp")
|
|
107
104
|
if policy_jsons["last_timestamp"] != 0
|
|
@@ -119,7 +116,7 @@ module TCellAgent
|
|
|
119
116
|
|
|
120
117
|
rescue TCellAgent::ConfigurationException
|
|
121
118
|
Thread.exit
|
|
122
|
-
rescue
|
|
119
|
+
rescue StandardError => e
|
|
123
120
|
TCellAgent.logger.error("exception while handling connection: #{e.message}")
|
|
124
121
|
TCellAgent.logger.debug(e.backtrace)
|
|
125
122
|
TCellAgent.logger.debug("Sleeping 30 seconds because the tCell.io request failed...")
|
|
@@ -141,17 +138,25 @@ module TCellAgent
|
|
|
141
138
|
new_policy = policy_class.from_json(policy_jsons[policy_type])
|
|
142
139
|
if new_policy
|
|
143
140
|
@lock.synchronize do
|
|
144
|
-
old_policy = @policies[policy_type]
|
|
145
141
|
@policies[policy_type] = new_policy
|
|
146
|
-
if cache_the_policy
|
|
147
|
-
cache(policy_type, policy_jsons[policy_type])
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
old_policy.free_native_memory if old_policy
|
|
151
142
|
end
|
|
152
143
|
end
|
|
153
144
|
end
|
|
154
145
|
end
|
|
146
|
+
|
|
147
|
+
@policies[TCellAgent::PolicyTypes::Rust].update_policies(policy_jsons)
|
|
148
|
+
|
|
149
|
+
if cache_the_policy
|
|
150
|
+
(TCellAgent::PolicyTypes::ClassMap.keys +
|
|
151
|
+
[TCellAgent::PolicyTypes::AppSensor,
|
|
152
|
+
TCellAgent::PolicyTypes::Patches,
|
|
153
|
+
TCellAgent::PolicyTypes::CommandInjection,
|
|
154
|
+
TCellAgent::PolicyTypes::Regex]).each do |policy_type|
|
|
155
|
+
@lock.synchronize do
|
|
156
|
+
cache(policy_type, policy_jsons[policy_type]) if policy_jsons[policy_type]
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
end
|
|
155
160
|
end
|
|
156
161
|
|
|
157
162
|
def cache(policy_name, policy)
|
|
@@ -164,7 +169,7 @@ module TCellAgent
|
|
|
164
169
|
TCellAgent.configuration.agent_home_owner
|
|
165
170
|
)
|
|
166
171
|
|
|
167
|
-
f1 = open(cache_filename, File::RDWR|File::CREAT)
|
|
172
|
+
f1 = File.open(cache_filename, File::RDWR|File::CREAT)
|
|
168
173
|
|
|
169
174
|
Timeout::timeout(0.100) { f1.flock(File::LOCK_EX) }
|
|
170
175
|
|
|
@@ -184,7 +189,7 @@ module TCellAgent
|
|
|
184
189
|
end
|
|
185
190
|
policy_cache[policy_name] = policy
|
|
186
191
|
@complete_policy_cache = policy_cache
|
|
187
|
-
rescue
|
|
192
|
+
rescue StandardError => e
|
|
188
193
|
TCellAgent.logger.warn(e.message)
|
|
189
194
|
if @complete_policy_cache
|
|
190
195
|
policy_cache = @complete_policy_cache
|
|
@@ -200,7 +205,7 @@ module TCellAgent
|
|
|
200
205
|
cache_filename,
|
|
201
206
|
TCellAgent.configuration.agent_home_owner
|
|
202
207
|
)
|
|
203
|
-
rescue
|
|
208
|
+
rescue StandardError => e
|
|
204
209
|
TCellAgent.logger.warn(e.message)
|
|
205
210
|
|
|
206
211
|
ensure
|
|
@@ -227,7 +232,7 @@ module TCellAgent
|
|
|
227
232
|
@complete_policy_cache = policy_jsons
|
|
228
233
|
return policy_jsons
|
|
229
234
|
|
|
230
|
-
rescue
|
|
235
|
+
rescue StandardError => e
|
|
231
236
|
TCellAgent.logger.warn(e.message)
|
|
232
237
|
end
|
|
233
238
|
|
|
@@ -8,12 +8,9 @@ require "tcell_agent/policies/clickjacking_policy"
|
|
|
8
8
|
require "tcell_agent/policies/http_tx_policy"
|
|
9
9
|
require "tcell_agent/policies/http_redirect_policy"
|
|
10
10
|
require "tcell_agent/policies/secure_headers_policy"
|
|
11
|
-
require "tcell_agent/policies/honeytokens_policy"
|
|
12
|
-
require "tcell_agent/policies/appsensor_policy"
|
|
13
11
|
require "tcell_agent/policies/login_fraud_policy"
|
|
14
12
|
require "tcell_agent/policies/dataloss_policy"
|
|
15
|
-
require "tcell_agent/policies/
|
|
16
|
-
require "tcell_agent/policies/command_injection_policy"
|
|
13
|
+
require "tcell_agent/policies/rust_policies"
|
|
17
14
|
|
|
18
15
|
module TCellAgent
|
|
19
16
|
class PolicyTypes
|
|
@@ -22,12 +19,13 @@ module TCellAgent
|
|
|
22
19
|
SecureHeaders = "secure-headers"
|
|
23
20
|
HttpTx = "http-tx"
|
|
24
21
|
HttpRedirect = "http-redirect"
|
|
25
|
-
AppSensor = "appsensor"
|
|
26
|
-
HoneyTokens = "exp-honeytokens"
|
|
27
22
|
LoginFraud = "login"
|
|
28
23
|
DataLoss = "dlp"
|
|
24
|
+
AppSensor = "appsensor"
|
|
29
25
|
Patches = "patches"
|
|
30
26
|
CommandInjection = "cmdi"
|
|
27
|
+
Regex = "regex"
|
|
28
|
+
Rust = "rust"
|
|
31
29
|
|
|
32
30
|
ClassMap = {
|
|
33
31
|
CSP=>TCellAgent::Policies::ContentSecurityPolicy,
|
|
@@ -35,12 +33,8 @@ module TCellAgent
|
|
|
35
33
|
SecureHeaders=>TCellAgent::Policies::SecureHeadersPolicy,
|
|
36
34
|
HttpTx=>TCellAgent::Policies::HttpTxPolicy,
|
|
37
35
|
HttpRedirect=>TCellAgent::Policies::HttpRedirectPolicy,
|
|
38
|
-
AppSensor=>TCellAgent::Policies::AppSensorPolicy,
|
|
39
|
-
HoneyTokens=>TCellAgent::Policies::HoneytokensPolicy,
|
|
40
36
|
LoginFraud=>TCellAgent::Policies::LoginFraudPolicy,
|
|
41
|
-
DataLoss=>TCellAgent::Policies::DataLossPolicy
|
|
42
|
-
Patches=>TCellAgent::Policies::PatchesPolicy,
|
|
43
|
-
CommandInjection=>TCellAgent::Policies::CommandInjectionPolicy
|
|
37
|
+
DataLoss=>TCellAgent::Policies::DataLossPolicy
|
|
44
38
|
}
|
|
45
39
|
|
|
46
40
|
end
|
|
@@ -24,7 +24,7 @@ module TCellAgent
|
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
# setter
|
|
27
|
-
def self.thread_agent=some_agent
|
|
27
|
+
def self.thread_agent=(some_agent)
|
|
28
28
|
@@instance_lock.synchronize do
|
|
29
29
|
@@my_thread_agent = some_agent
|
|
30
30
|
end
|
|
@@ -60,4 +60,8 @@ module TCellAgent
|
|
|
60
60
|
def self.ensure_event_processor_running
|
|
61
61
|
self.thread_agent.ensure_event_processor_running
|
|
62
62
|
end
|
|
63
|
+
|
|
64
|
+
def self.is_it_safe_to_send_cmdi_events?
|
|
65
|
+
self.thread_agent.is_it_safe_to_send_cmdi_events?
|
|
66
|
+
end
|
|
63
67
|
end
|
data/lib/tcell_agent/agent.rb
CHANGED
|
@@ -66,21 +66,23 @@ module TCellAgent
|
|
|
66
66
|
@@policy_tapi = TCellApi.new
|
|
67
67
|
|
|
68
68
|
# Agent request thread
|
|
69
|
-
@policies = {
|
|
69
|
+
@policies = {
|
|
70
|
+
TCellAgent::PolicyTypes::Rust => TCellAgent::Policies::RustPolicies.new
|
|
71
|
+
}
|
|
70
72
|
@lock = Monitor.new
|
|
71
73
|
|
|
72
74
|
self.initialize_processor_variables
|
|
73
75
|
|
|
74
76
|
if TCellAgent.configuration.preload_policy_filename != nil
|
|
75
|
-
TCellAgent.logger.info("Preloading a policy file")
|
|
77
|
+
TCellAgent.logger.info("Preloading a policy file")
|
|
76
78
|
begin
|
|
77
|
-
policy_file = open(TCellAgent.configuration.preload_policy_filename).read
|
|
79
|
+
policy_file = File.open(TCellAgent.configuration.preload_policy_filename).read
|
|
78
80
|
policy_jsons = JSON.parse(policy_file)
|
|
79
81
|
if policy_jsons.key?("result")
|
|
80
82
|
policy_jsons = policy_jsons["result"]
|
|
81
83
|
end
|
|
82
84
|
processPolicyJson(policy_jsons, false)
|
|
83
|
-
rescue
|
|
85
|
+
rescue StandardError => e
|
|
84
86
|
TCellAgent.logger.error(e.message)
|
|
85
87
|
end
|
|
86
88
|
end
|
data/lib/tcell_agent/api.rb
CHANGED
|
@@ -31,25 +31,23 @@ module TCellAgent
|
|
|
31
31
|
req['Authorization'] = 'Bearer ' + TCellAgent.configuration.api_key
|
|
32
32
|
begin
|
|
33
33
|
req['TCellAgent'] = "RubyAgent " + TCellAgent::VERSION
|
|
34
|
-
rescue
|
|
34
|
+
rescue StandardError => e
|
|
35
35
|
TCellAgent.logger.debug("tCell.io Could not add agent string: " + e.message)
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
-
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl
|
|
38
|
+
res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => (uri.scheme == 'https')) { |http| http.request(req) }
|
|
39
39
|
|
|
40
40
|
if res.is_a?(Net::HTTPSuccess)
|
|
41
|
-
TCellAgent.logger.debug("tCell.io API Response: #{res.body}")
|
|
41
|
+
TCellAgent.logger.debug("tCell.io API Response: #{res.body}".force_encoding("UTF-8"))
|
|
42
42
|
response_json = JSON.parse(res.body)
|
|
43
43
|
if (response_json && response_json.has_key?("result"))
|
|
44
44
|
return response_json["result"]
|
|
45
45
|
end
|
|
46
|
-
|
|
47
|
-
return nil
|
|
48
|
-
|
|
49
46
|
else
|
|
50
47
|
TCellAgent.logger.error("Received error response while contacting api: #{res.inspect}")
|
|
51
|
-
return nil
|
|
52
48
|
end
|
|
49
|
+
|
|
50
|
+
return nil
|
|
53
51
|
end
|
|
54
52
|
|
|
55
53
|
def send_event_set(events)
|
|
@@ -81,11 +79,11 @@ module TCellAgent
|
|
|
81
79
|
|
|
82
80
|
begin
|
|
83
81
|
req['TCellAgent'] = "RubyAgent " + TCellAgent::VERSION
|
|
84
|
-
rescue
|
|
82
|
+
rescue StandardError => e
|
|
85
83
|
TCellAgent.logger.debug("tCell.io Could not add agent string: " + e.message)
|
|
86
84
|
end
|
|
87
85
|
|
|
88
|
-
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl
|
|
86
|
+
res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => (uri.scheme == 'https')) { |http| http.request(req) }
|
|
89
87
|
|
|
90
88
|
TCellAgent.logger.debug("tCell.io SendEvents API Response: #{res.code}")
|
|
91
89
|
|
|
@@ -8,11 +8,17 @@ module TCellAgent
|
|
|
8
8
|
class MetaData < TCellAgent::SensorEvents::TCellSensorEvent
|
|
9
9
|
|
|
10
10
|
attr_accessor :get_dict, :post_dict, :body_dict, :cookie_dict, :path_parameters,
|
|
11
|
-
:remote_address, :method, :route_id, :session_id, :user_id, :transaction_id
|
|
11
|
+
:remote_address, :method, :route_id, :session_id, :user_id, :transaction_id, :location
|
|
12
12
|
|
|
13
13
|
attr_reader :headers_dict
|
|
14
14
|
|
|
15
|
-
def initialize(method,
|
|
15
|
+
def initialize(method,
|
|
16
|
+
remote_address,
|
|
17
|
+
route_id,
|
|
18
|
+
session_id,
|
|
19
|
+
user_id,
|
|
20
|
+
transaction_id,
|
|
21
|
+
location)
|
|
16
22
|
@send = false
|
|
17
23
|
|
|
18
24
|
@method = method
|
|
@@ -21,6 +27,7 @@ module TCellAgent
|
|
|
21
27
|
@session_id = session_id
|
|
22
28
|
@user_id = user_id
|
|
23
29
|
@transaction_id = transaction_id
|
|
30
|
+
@location = location
|
|
24
31
|
|
|
25
32
|
@body_dict = {}
|
|
26
33
|
@get_dict = {}
|
|
@@ -96,7 +103,7 @@ module TCellAgent
|
|
|
96
103
|
(header_downcased != "http_cookie" && header_downcased.start_with?('http_')) ||
|
|
97
104
|
["content_type", "content_length"].include?(header_downcased)
|
|
98
105
|
}.inject({}) { |memo, (k,v)|
|
|
99
|
-
memo[k.downcase.sub(/^http_/, '').
|
|
106
|
+
memo[k.downcase.sub(/^http_/, '').tr('_', '-')] = v
|
|
100
107
|
memo
|
|
101
108
|
}
|
|
102
109
|
end
|
|
@@ -110,7 +117,7 @@ module TCellAgent
|
|
|
110
117
|
begin
|
|
111
118
|
# don't enqueue parameter values of unknown type to avoid any serialization issues
|
|
112
119
|
@body_dict = TCellAgent::Utils::Params.flatten(JSON.parse(request_body))
|
|
113
|
-
rescue
|
|
120
|
+
rescue JSON::ParserError
|
|
114
121
|
TCellAgent.logger.debug("JSON body parameter parsing failed")
|
|
115
122
|
@body_dict = {}
|
|
116
123
|
end
|
|
@@ -12,10 +12,10 @@ module TCellAgent
|
|
|
12
12
|
def getUserFromRequest(request)
|
|
13
13
|
orig_user_id = original_getUserFromRequest(request)
|
|
14
14
|
begin
|
|
15
|
-
if request.session
|
|
15
|
+
if request.session && request.session.has_key?("user_credentials_id")
|
|
16
16
|
return request.session["user_credentials_id"].to_s
|
|
17
17
|
end
|
|
18
|
-
rescue
|
|
18
|
+
rescue StandardError => e
|
|
19
19
|
return orig_user_id
|
|
20
20
|
end
|
|
21
21
|
return orig_user_id
|
|
@@ -23,4 +23,4 @@ module TCellAgent
|
|
|
23
23
|
end
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
|
-
end
|
|
26
|
+
end
|
data/lib/tcell_agent/cmdi.rb
CHANGED
|
@@ -7,11 +7,13 @@ module TCellAgent
|
|
|
7
7
|
def self.block_command?(cmd)
|
|
8
8
|
TCellAgent::Instrumentation.safe_block("Checking Command Injection Policy") do
|
|
9
9
|
if TCellAgent::Utils::Strings.present?(cmd)
|
|
10
|
-
|
|
11
|
-
if
|
|
12
|
-
request_env = TCellAgent::Instrumentation::Rails::Middleware::ContextMiddleware::THREADS.fetch(
|
|
10
|
+
rust_policies = TCellAgent.policy(TCellAgent::PolicyTypes::Rust)
|
|
11
|
+
if rust_policies && rust_policies.cmdi_enabled
|
|
12
|
+
request_env = TCellAgent::Instrumentation::Rails::Middleware::ContextMiddleware::THREADS.fetch(
|
|
13
|
+
Thread.current.object_id, {}
|
|
14
|
+
)
|
|
13
15
|
tcell_context = request_env[TCellAgent::Instrumentation::TCELL_ID]
|
|
14
|
-
return
|
|
16
|
+
return rust_policies.block_command?(cmd, tcell_context)
|
|
15
17
|
end
|
|
16
18
|
end
|
|
17
19
|
end
|
|
@@ -12,6 +12,7 @@ module TCellAgent
|
|
|
12
12
|
"TCELL_AGENT_APP_ID",
|
|
13
13
|
"TCELL_AGENT_API_KEY",
|
|
14
14
|
"TCELL_HMAC_KEY",
|
|
15
|
+
"TCELL_PASSWORD_HMAC_KEY",
|
|
15
16
|
"TCELL_AGENT_HOST_IDENTIFIER",
|
|
16
17
|
"TCELL_API_URL",
|
|
17
18
|
"TCELL_INPUT_URL",
|
|
@@ -59,6 +60,7 @@ module TCellAgent
|
|
|
59
60
|
"host_identifier",
|
|
60
61
|
"hipaaSafeMode",
|
|
61
62
|
"hmac_key",
|
|
63
|
+
"password_hmac_key",
|
|
62
64
|
"js_agent_api_base_url",
|
|
63
65
|
"js_agent_url",
|
|
64
66
|
"max_csp_header_bytes",
|
|
@@ -106,7 +108,7 @@ module TCellAgent
|
|
|
106
108
|
end
|
|
107
109
|
|
|
108
110
|
end
|
|
109
|
-
rescue
|
|
111
|
+
rescue StandardError => exception
|
|
110
112
|
messages << "Something went wrong verifying config file: #{exception}"
|
|
111
113
|
end
|
|
112
114
|
|
|
@@ -35,7 +35,6 @@ module TCellAgent
|
|
|
35
35
|
:cache_filename,
|
|
36
36
|
:js_agent_api_base_url,
|
|
37
37
|
:js_agent_url,
|
|
38
|
-
:startup_js_agent_url,
|
|
39
38
|
:config_filename,
|
|
40
39
|
:agent_log_dir,
|
|
41
40
|
:max_data_ex_db_records_per_request,
|
|
@@ -47,7 +46,8 @@ module TCellAgent
|
|
|
47
46
|
:log_tag,
|
|
48
47
|
:max_csp_header_bytes,
|
|
49
48
|
:demomode,
|
|
50
|
-
:allow_payloads
|
|
49
|
+
:allow_payloads,
|
|
50
|
+
:password_hmac_key
|
|
51
51
|
|
|
52
52
|
attr_accessor :disable_all,
|
|
53
53
|
:enabled,
|
|
@@ -131,14 +131,11 @@ module TCellAgent
|
|
|
131
131
|
@enable_intercept_requests = true
|
|
132
132
|
|
|
133
133
|
@enabled_instrumentations = {
|
|
134
|
-
doorkeeper
|
|
135
|
-
devise
|
|
136
|
-
authlogic
|
|
134
|
+
:doorkeeper => true,
|
|
135
|
+
:devise => true,
|
|
136
|
+
:authlogic => true
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
@agent_home_dir = File.join(Dir.getwd, "tcell")
|
|
140
|
-
@config_filename = File.join(Dir.getwd, filename)
|
|
141
|
-
|
|
142
139
|
@log_file_name = "tcell_agent.log"
|
|
143
140
|
|
|
144
141
|
@event_batch_size_limit = 50
|
|
@@ -150,9 +147,18 @@ module TCellAgent
|
|
|
150
147
|
@allow_payloads = true
|
|
151
148
|
|
|
152
149
|
@max_csp_header_bytes = nil
|
|
150
|
+
@password_hmac_key = nil
|
|
151
|
+
|
|
152
|
+
@agent_home_dir = ENV["TCELL_AGENT_HOME"] || File.join(Dir.getwd, "tcell")
|
|
153
|
+
@config_filename = ENV["TCELL_AGENT_CONFIG"] || File.join(Dir.getwd, filename)
|
|
153
154
|
|
|
154
|
-
read_config_using_env
|
|
155
155
|
read_config_from_file(@config_filename)
|
|
156
|
+
read_config_using_env
|
|
157
|
+
|
|
158
|
+
if @demomode
|
|
159
|
+
@event_batch_size_limit = 2
|
|
160
|
+
@event_time_limit_seconds = 5
|
|
161
|
+
end
|
|
156
162
|
|
|
157
163
|
if ENV["TCELL_AGENT_ALLOW_UNENCRYPTED_APPSENSOR_PAYLOADS"]
|
|
158
164
|
puts "tCell.io Agent: [DEPRECATED] TCELL_AGENT_ALLOW_UNENCRYPTED_APPSENSOR_PAYLOADS is deprecated and will be removed in a future release. Please switch to TCELL_AGENT_ALLOW_PAYLOADS."
|
|
@@ -175,13 +181,12 @@ module TCellAgent
|
|
|
175
181
|
@tcell_api_url ||= "https://api.tcell.io/api/v1"
|
|
176
182
|
@tcell_input_url ||= "https://input.tcell.io/api/v1"
|
|
177
183
|
@js_agent_api_base_url ||= nil
|
|
178
|
-
@js_agent_url ||= "https://
|
|
179
|
-
@startup_js_agent_url = @js_agent_url
|
|
184
|
+
@js_agent_url ||= "https://jsagent.tcell.io/tcellagent.min.js"
|
|
180
185
|
|
|
181
186
|
if (@host_identifier == nil)
|
|
182
187
|
begin
|
|
183
188
|
@host_identifier = (Socket.gethostname() || "localhost")
|
|
184
|
-
rescue
|
|
189
|
+
rescue StandardError
|
|
185
190
|
@host_identifier = "host_identifier_not_found"
|
|
186
191
|
end
|
|
187
192
|
end
|
|
@@ -200,23 +205,17 @@ module TCellAgent
|
|
|
200
205
|
end
|
|
201
206
|
|
|
202
207
|
def read_config_using_env
|
|
203
|
-
@app_id = ENV["TCELL_AGENT_APP_ID"]
|
|
204
|
-
@api_key = ENV["TCELL_AGENT_API_KEY"]
|
|
205
|
-
@hmac_key = ENV["TCELL_HMAC_KEY"]
|
|
208
|
+
@app_id = ENV["TCELL_AGENT_APP_ID"] || @app_id
|
|
209
|
+
@api_key = ENV["TCELL_AGENT_API_KEY"] || @api_key
|
|
210
|
+
@hmac_key = ENV["TCELL_HMAC_KEY"] || @hmac_key
|
|
211
|
+
@password_hmac_key = ENV["TCELL_PASSWORD_HMAC_KEY"] || @password_hmac_key
|
|
206
212
|
@host_identifier = ENV["TCELL_AGENT_HOST_IDENTIFIER"] || @host_identifier
|
|
207
|
-
@tcell_api_url = ENV["TCELL_API_URL"]
|
|
208
|
-
@tcell_input_url = ENV["TCELL_INPUT_URL"]
|
|
213
|
+
@tcell_api_url = ENV["TCELL_API_URL"] || @tcell_api_url
|
|
214
|
+
@tcell_input_url = ENV["TCELL_INPUT_URL"] || @tcell_input_url
|
|
209
215
|
@demomode = ENV["TCELL_DEMOMODE"] || @demomode
|
|
210
216
|
|
|
211
|
-
@
|
|
212
|
-
@
|
|
213
|
-
@agent_log_dir = ENV["TCELL_AGENT_LOG_DIR"]
|
|
214
|
-
@config_filename = ENV["TCELL_AGENT_CONFIG"] || @config_filename
|
|
215
|
-
|
|
216
|
-
if @demomode
|
|
217
|
-
@event_batch_size_limit = 2
|
|
218
|
-
@event_time_limit_seconds = 5
|
|
219
|
-
end
|
|
217
|
+
@agent_home_owner = ENV["TCELL_AGENT_HOME_OWNER"] || @agent_home_owner
|
|
218
|
+
@agent_log_dir = ENV["TCELL_AGENT_LOG_DIR"] || @agent_log_dir
|
|
220
219
|
end
|
|
221
220
|
|
|
222
221
|
def read_config_from_file(filename)
|
|
@@ -235,9 +234,8 @@ module TCellAgent
|
|
|
235
234
|
# Required
|
|
236
235
|
app_data = config["applications"][0] #Default
|
|
237
236
|
@version = 1
|
|
238
|
-
@app_id
|
|
239
|
-
@
|
|
240
|
-
@api_key ||= app_data["api_key"]
|
|
237
|
+
@app_id = app_data["app_id"]
|
|
238
|
+
@api_key = app_data["api_key"]
|
|
241
239
|
|
|
242
240
|
# Optional
|
|
243
241
|
@preload_policy_filename = app_data.fetch("preload_policy_filename", nil)
|
|
@@ -253,12 +251,9 @@ module TCellAgent
|
|
|
253
251
|
@fetch_policies_from_tcell = app_data.fetch("fetch_policies_from_tcell", @fetch_policies_from_tcell)
|
|
254
252
|
@instrument_for_events = app_data.fetch("instrument_for_events", @instrument_for_events)
|
|
255
253
|
|
|
256
|
-
@agent_home_owner = app_data.fetch("agent_home_owner"
|
|
254
|
+
@agent_home_owner = app_data.fetch("agent_home_owner", @agent_home_owner)
|
|
257
255
|
|
|
258
256
|
@logging_options = app_data.fetch("logging_options", {})
|
|
259
|
-
# DEPRECATED: this was incorrectly placed here. Keep it here until we can
|
|
260
|
-
# be sure that no customers are relying on this
|
|
261
|
-
@agent_log_dir = @logging_options.fetch("log_dir", @agent_log_dir)
|
|
262
257
|
@agent_log_dir = app_data.fetch("log_dir", @agent_log_dir)
|
|
263
258
|
@log_file_name = @logging_options.fetch("filename", @log_file_name)
|
|
264
259
|
|
|
@@ -267,12 +262,18 @@ module TCellAgent
|
|
|
267
262
|
|
|
268
263
|
@max_csp_header_bytes = app_data.fetch("max_csp_header_bytes", @max_csp_header_bytes)
|
|
269
264
|
|
|
270
|
-
@allow_payloads =
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
@allow_payloads =
|
|
275
|
-
|
|
265
|
+
@allow_payloads = app_data.fetch(
|
|
266
|
+
'allow_unencrypted_appsensor_payloads',
|
|
267
|
+
@allow_payloads
|
|
268
|
+
)
|
|
269
|
+
@allow_payloads = app_data.fetch(
|
|
270
|
+
'allow_unencrypted_appfirewall_payloads',
|
|
271
|
+
@allow_payloads
|
|
272
|
+
)
|
|
273
|
+
@allow_payloads = app_data.fetch(
|
|
274
|
+
'allow_payloads',
|
|
275
|
+
@allow_payloads
|
|
276
|
+
)
|
|
276
277
|
|
|
277
278
|
data_exposure = app_data.fetch('data_exposure', {})
|
|
278
279
|
@max_data_ex_db_records_per_request = data_exposure.fetch('max_data_ex_db_records_per_request', @max_data_ex_db_records_per_request)
|
|
@@ -282,8 +283,11 @@ module TCellAgent
|
|
|
282
283
|
@reverse_proxy = app_data.fetch('reverse_proxy', @reverse_proxy)
|
|
283
284
|
@reverse_proxy_ip_address_header = app_data.fetch('reverse_proxy_ip_address_header', @reverse_proxy_ip_address_header)
|
|
284
285
|
|
|
285
|
-
@host_identifier =
|
|
286
|
-
@hmac_key
|
|
286
|
+
@host_identifier = app_data.fetch("host_identifier", @host_identifier)
|
|
287
|
+
@hmac_key = app_data.fetch("hmac_key", @hmac_key)
|
|
288
|
+
|
|
289
|
+
@password_hmac_key = app_data.fetch("password_hmac_key", @password_hmac_key)
|
|
290
|
+
|
|
287
291
|
@uuid = SecureRandom.uuid
|
|
288
292
|
if (@uuid == nil)
|
|
289
293
|
@uuid = "secure-random-failed"
|
|
@@ -296,20 +300,14 @@ module TCellAgent
|
|
|
296
300
|
@js_agent_url = app_data["js_agent_url"]
|
|
297
301
|
end
|
|
298
302
|
|
|
299
|
-
|
|
300
|
-
@demomode = app_data.fetch('demomode', false)
|
|
301
|
-
end
|
|
302
|
-
if @demomode
|
|
303
|
-
@event_batch_size_limit = 2
|
|
304
|
-
@event_time_limit_seconds = 5
|
|
305
|
-
end
|
|
303
|
+
@demomode = app_data.fetch('demomode', @demomode)
|
|
306
304
|
else
|
|
307
305
|
puts " ********* ********* ********* *********"
|
|
308
306
|
puts "* tCell.io *"
|
|
309
307
|
puts "* Unsupported config file version *"
|
|
310
308
|
puts " ********* ********* ********* *********"
|
|
311
309
|
end
|
|
312
|
-
rescue
|
|
310
|
+
rescue StandardError => e
|
|
313
311
|
puts " ********* ********* ********* *********"
|
|
314
312
|
puts "* tCell.io *"
|
|
315
313
|
puts "* Could not load config file *"
|
data/lib/tcell_agent/devise.rb
CHANGED
|
@@ -15,7 +15,7 @@ module TCellAgent
|
|
|
15
15
|
def getUserFromRequest(request)
|
|
16
16
|
orig_user_id = original_getUserFromRequest(request)
|
|
17
17
|
begin
|
|
18
|
-
if request.session
|
|
18
|
+
if request.session && request.session.has_key?("warden.user.user.key")
|
|
19
19
|
userkey = request.session["warden.user.user.key"]
|
|
20
20
|
if (userkey.length == 2)
|
|
21
21
|
user_id = userkey[0][0]
|
|
@@ -26,7 +26,7 @@ module TCellAgent
|
|
|
26
26
|
return user_id.to_s
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
|
-
rescue
|
|
29
|
+
rescue StandardError => e
|
|
30
30
|
return orig_user_id
|
|
31
31
|
end
|
|
32
32
|
return orig_user_id
|