tcell_agent 1.1.12 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. checksums.yaml +5 -5
  2. data/bin/tcell_agent +26 -14
  3. data/lib/tcell_agent.rb +16 -10
  4. data/lib/tcell_agent/agent.rb +78 -97
  5. data/lib/tcell_agent/agent/route_manager.rb +0 -16
  6. data/lib/tcell_agent/agent/static_agent.rb +9 -30
  7. data/lib/tcell_agent/authlogic.rb +3 -6
  8. data/lib/tcell_agent/config/unknown_options.rb +4 -8
  9. data/lib/tcell_agent/configuration.rb +38 -119
  10. data/lib/tcell_agent/devise.rb +25 -27
  11. data/lib/tcell_agent/hooks/login_fraud.rb +30 -33
  12. data/lib/tcell_agent/instrument_servers.rb +25 -0
  13. data/lib/tcell_agent/instrumentation.rb +12 -10
  14. data/lib/tcell_agent/instrumentation/cmdi.rb +19 -15
  15. data/lib/tcell_agent/instrumentation/lfi.rb +73 -0
  16. data/lib/tcell_agent/instrumentation/monkey_patches/file.rb +25 -0
  17. data/lib/tcell_agent/instrumentation/monkey_patches/io.rb +123 -0
  18. data/lib/tcell_agent/instrumentation/monkey_patches/kernel.rb +159 -0
  19. data/lib/tcell_agent/logger.rb +50 -114
  20. data/lib/tcell_agent/patches.rb +6 -7
  21. data/lib/tcell_agent/policies/appfirewall_policy.rb +26 -0
  22. data/lib/tcell_agent/policies/command_injection_policy.rb +28 -0
  23. data/lib/tcell_agent/policies/dataloss_policy.rb +44 -44
  24. data/lib/tcell_agent/policies/headers_policy.rb +25 -0
  25. data/lib/tcell_agent/policies/http_redirect_policy.rb +13 -79
  26. data/lib/tcell_agent/policies/js_agent_policy.rb +27 -0
  27. data/lib/tcell_agent/policies/local_file_access.rb +28 -0
  28. data/lib/tcell_agent/policies/login_policy.rb +43 -0
  29. data/lib/tcell_agent/policies/patches_policy.rb +27 -0
  30. data/lib/tcell_agent/policies/policies_manager.rb +68 -0
  31. data/lib/tcell_agent/policies/policy_polling.rb +58 -0
  32. data/lib/tcell_agent/policies/policy_types.rb +14 -0
  33. data/lib/tcell_agent/policies/system_enablements.rb +27 -0
  34. data/lib/tcell_agent/rails/auth/authlogic.rb +43 -68
  35. data/lib/tcell_agent/rails/auth/devise.rb +20 -23
  36. data/lib/tcell_agent/rails/auth/doorkeeper.rb +63 -74
  37. data/lib/tcell_agent/rails/csrf_exception.rb +2 -2
  38. data/lib/tcell_agent/rails/dlp.rb +25 -15
  39. data/lib/tcell_agent/rails/dlp_handler.rb +1 -2
  40. data/lib/tcell_agent/rails/js_agent_insert.rb +12 -13
  41. data/lib/tcell_agent/rails/middleware/body_filter_middleware.rb +4 -25
  42. data/lib/tcell_agent/rails/middleware/context_middleware.rb +2 -12
  43. data/lib/tcell_agent/rails/middleware/global_middleware.rb +0 -1
  44. data/lib/tcell_agent/rails/middleware/headers_middleware.rb +14 -34
  45. data/lib/tcell_agent/rails/on_start.rb +32 -31
  46. data/lib/tcell_agent/rails/routes.rb +7 -6
  47. data/lib/tcell_agent/rails/routes/grape.rb +1 -3
  48. data/lib/tcell_agent/rails/routes/route_id.rb +3 -1
  49. data/lib/tcell_agent/rails/settings_reporter.rb +23 -36
  50. data/lib/tcell_agent/rails/start_agent_after_initializers.rb +12 -0
  51. data/lib/tcell_agent/rails/tcell_body_proxy.rb +6 -4
  52. data/lib/tcell_agent/rust/agent_config.rb +49 -0
  53. data/lib/tcell_agent/rust/{libtcellagent-alpine-1.3.2.so → libtcellagent-4.14.0.dylib} +0 -0
  54. data/lib/tcell_agent/rust/libtcellagent-4.14.0.so +0 -0
  55. data/lib/tcell_agent/rust/{libtcellagent-1.3.2.so → libtcellagent-alpine-4.14.0.so} +0 -0
  56. data/lib/tcell_agent/rust/models.rb +0 -55
  57. data/lib/tcell_agent/rust/native_agent.rb +531 -0
  58. data/lib/tcell_agent/rust/native_agent_response.rb +42 -0
  59. data/lib/tcell_agent/rust/native_library.rb +68 -0
  60. data/lib/tcell_agent/rust/tcellagent-4.14.0.dll +0 -0
  61. data/lib/tcell_agent/sensor_events/agent_setting_event.rb +12 -0
  62. data/lib/tcell_agent/sensor_events/{app_config.rb → app_config_setting_event.rb} +0 -6
  63. data/lib/tcell_agent/sensor_events/dlp.rb +2 -6
  64. data/lib/tcell_agent/sensor_events/sensor.rb +0 -62
  65. data/lib/tcell_agent/sensor_events/server_agent.rb +13 -18
  66. data/lib/tcell_agent/sensor_events/util/sanitizer_utilities.rb +0 -108
  67. data/lib/tcell_agent/sensor_events/util/utils.rb +0 -2
  68. data/lib/tcell_agent/servers/passenger.rb +1 -28
  69. data/lib/tcell_agent/servers/puma.rb +3 -21
  70. data/lib/tcell_agent/servers/rails_server.rb +1 -1
  71. data/lib/tcell_agent/servers/thin.rb +2 -2
  72. data/lib/tcell_agent/servers/unicorn.rb +19 -80
  73. data/lib/tcell_agent/servers/webrick.rb +1 -1
  74. data/lib/tcell_agent/settings_reporter.rb +24 -24
  75. data/lib/tcell_agent/sinatra.rb +14 -16
  76. data/lib/tcell_agent/tcell_context.rb +40 -14
  77. data/lib/tcell_agent/utils/headers.rb +14 -0
  78. data/lib/tcell_agent/version.rb +1 -1
  79. data/spec/lib/tcell_agent/cmdi_spec.rb +0 -585
  80. data/spec/lib/tcell_agent/config/unknown_options_spec.rb +0 -18
  81. data/spec/lib/tcell_agent/configuration_spec.rb +4 -140
  82. data/spec/lib/tcell_agent/hooks/login_fraud_spec.rb +46 -173
  83. data/spec/lib/tcell_agent/instrumentation/cmdi/io_cmdi_spec.rb +504 -0
  84. data/spec/lib/tcell_agent/instrumentation/cmdi/kernel_cmdi_spec.rb +435 -0
  85. data/spec/lib/tcell_agent/instrumentation/lfi/file_lfi_spec.rb +326 -0
  86. data/spec/lib/tcell_agent/instrumentation/lfi/io_lfi_spec.rb +556 -0
  87. data/spec/lib/tcell_agent/instrumentation/lfi/kernel_lfi_spec.rb +249 -0
  88. data/spec/lib/tcell_agent/instrumentation/lfi_spec.rb +105 -0
  89. data/spec/lib/tcell_agent/patches_spec.rb +25 -43
  90. data/spec/lib/tcell_agent/policies/appfirewall_policy_spec.rb +183 -0
  91. data/spec/lib/tcell_agent/policies/clickjacking_policy_spec.rb +57 -0
  92. data/spec/lib/tcell_agent/policies/command_injection_policy_spec.rb +84 -773
  93. data/spec/lib/tcell_agent/policies/content_security_policy_spec.rb +161 -0
  94. data/spec/lib/tcell_agent/policies/dataloss_policy_spec.rb +9 -9
  95. data/spec/lib/tcell_agent/policies/http_redirect_policy_spec.rb +243 -198
  96. data/spec/lib/tcell_agent/policies/js_agent_policy_spec.rb +75 -0
  97. data/spec/lib/tcell_agent/policies/login_policy_spec.rb +165 -33
  98. data/spec/lib/tcell_agent/policies/patches_policy_spec.rb +84 -277
  99. data/spec/lib/tcell_agent/policies/policies_manager_spec.rb +104 -0
  100. data/spec/lib/tcell_agent/policies/policy_polling_spec.rb +6 -0
  101. data/spec/lib/tcell_agent/policies/secure_headers_policy_spec.rb +56 -0
  102. data/spec/lib/tcell_agent/rails/csrf_exception_spec.rb +9 -18
  103. data/spec/lib/tcell_agent/rails/js_agent_insert_spec.rb +13 -30
  104. data/spec/lib/tcell_agent/rails/logger_spec.rb +27 -7
  105. data/spec/lib/tcell_agent/rails/middleware/tcell_body_proxy_spec.rb +17 -12
  106. data/spec/lib/tcell_agent/rails/routes/routes_spec.rb +14 -14
  107. data/spec/lib/tcell_agent/sensor_events/util/sanitizer_utilities_spec.rb +0 -35
  108. data/spec/lib/tcell_agent/settings_reporter_spec.rb +127 -153
  109. data/spec/spec_helper.rb +1 -1
  110. data/spec/support/builders.rb +104 -0
  111. data/spec/support/force_logger_mocking.rb +38 -0
  112. data/spec/support/resources/lfi_sample_file.txt +2 -0
  113. data/spec/support/static_agent_overrides.rb +0 -15
  114. metadata +63 -74
  115. data/lib/tcell_agent/agent/event_processor.rb +0 -326
  116. data/lib/tcell_agent/agent/fork_pipe_manager.rb +0 -113
  117. data/lib/tcell_agent/agent/policy_manager.rb +0 -219
  118. data/lib/tcell_agent/agent/policy_types.rb +0 -30
  119. data/lib/tcell_agent/api.rb +0 -91
  120. data/lib/tcell_agent/appsensor/injections_reporter.rb +0 -24
  121. data/lib/tcell_agent/config/child_process_events.rb +0 -8
  122. data/lib/tcell_agent/instrumentation/cmdi/backtick.rb +0 -10
  123. data/lib/tcell_agent/instrumentation/cmdi/exec.rb +0 -14
  124. data/lib/tcell_agent/instrumentation/cmdi/popen.rb +0 -28
  125. data/lib/tcell_agent/instrumentation/cmdi/spawn.rb +0 -11
  126. data/lib/tcell_agent/instrumentation/cmdi/system.rb +0 -11
  127. data/lib/tcell_agent/policies/http_tx_policy.rb +0 -60
  128. data/lib/tcell_agent/policies/login_fraud_policy.rb +0 -45
  129. data/lib/tcell_agent/policies/rust_policies.rb +0 -110
  130. data/lib/tcell_agent/rails.rb +0 -40
  131. data/lib/tcell_agent/rust/libtcellagent-1.3.2.dylib +0 -0
  132. data/lib/tcell_agent/rust/tcellagent-1.3.2.dll +0 -0
  133. data/lib/tcell_agent/rust/whisperer.rb +0 -308
  134. data/lib/tcell_agent/sensor_events/appsensor_event.rb +0 -52
  135. data/lib/tcell_agent/sensor_events/appsensor_meta_event.rb +0 -45
  136. data/lib/tcell_agent/sensor_events/command_injection.rb +0 -75
  137. data/lib/tcell_agent/sensor_events/honeytokens.rb +0 -16
  138. data/lib/tcell_agent/sensor_events/login_fraud.rb +0 -60
  139. data/lib/tcell_agent/sensor_events/metrics.rb +0 -123
  140. data/lib/tcell_agent/sensor_events/patches.rb +0 -21
  141. data/lib/tcell_agent/start_background_thread.rb +0 -55
  142. data/lib/tcell_agent/system_info.rb +0 -11
  143. data/lib/tcell_agent/utils/io.rb +0 -38
  144. data/lib/tcell_agent/utils/passwords.rb +0 -28
  145. data/lib/tcell_agent/utils/queue_with_timeout.rb +0 -142
  146. data/spec/lib/tcell_agent/agent/fork_pipe_manager_spec.rb +0 -100
  147. data/spec/lib/tcell_agent/agent/policy_manager_spec.rb +0 -535
  148. data/spec/lib/tcell_agent/agent/static_agent_spec.rb +0 -133
  149. data/spec/lib/tcell_agent/api/api_spec.rb +0 -39
  150. data/spec/lib/tcell_agent/appsensor/injections_reporter_spec.rb +0 -187
  151. data/spec/lib/tcell_agent/instrumentation_spec.rb +0 -225
  152. data/spec/lib/tcell_agent/policies/appsensor_policy_spec.rb +0 -517
  153. data/spec/lib/tcell_agent/policies/http_tx_policy_spec.rb +0 -22
  154. data/spec/lib/tcell_agent/rails/middleware/appsensor_middleware_spec.rb +0 -293
  155. data/spec/lib/tcell_agent/rails/middleware/dlp_middleware_spec.rb +0 -198
  156. data/spec/lib/tcell_agent/rails/middleware/global_middleware_spec.rb +0 -180
  157. data/spec/lib/tcell_agent/rails/middleware/redirect_middleware_spec.rb +0 -116
  158. data/spec/lib/tcell_agent/rust/models_spec.rb +0 -120
  159. data/spec/lib/tcell_agent/rust/whisperer_spec.rb +0 -704
  160. data/spec/lib/tcell_agent/sensor_events/appsensor_meta_event_spec.rb +0 -45
  161. data/spec/lib/tcell_agent/sensor_events/sessions_metric_spec.rb +0 -272
  162. data/spec/lib/tcell_agent/utils/bounded_queue_spec.rb +0 -52
  163. data/spec/lib/tcell_agent/utils/passwords_spec.rb +0 -143
@@ -26,10 +26,9 @@ module TCellAgent
26
26
  :app_id,
27
27
  :api_key,
28
28
  :hmac_key,
29
+ :tcell_api_url,
29
30
  :tcell_input_url,
30
31
  :logging_options,
31
- :logger,
32
- :appfirewall_payloads_logger, # appfirewall_payloads_logger can be specified from initializers
33
32
  :fetch_policies_from_tcell, :instrument_for_events,
34
33
  :preload_policy_filename,
35
34
  :host_identifier,
@@ -37,13 +36,13 @@ module TCellAgent
37
36
  :event_batch_size_limit, :event_time_limit_seconds,
38
37
  :base_dir,
39
38
  :cache_filename,
39
+ :cache_folder,
40
40
  :js_agent_api_base_url,
41
41
  :js_agent_url,
42
42
  :config_filename,
43
43
  :agent_log_dir,
44
44
  :max_data_ex_db_records_per_request,
45
45
  :agent_home_dir,
46
- :agent_home_owner,
47
46
  :reverse_proxy,
48
47
  :reverse_proxy_ip_address_header,
49
48
  :log_file_name,
@@ -51,9 +50,8 @@ module TCellAgent
51
50
  :max_csp_header_bytes,
52
51
  :demomode,
53
52
  :allow_payloads,
54
- :password_hmac_key
55
-
56
- attr_reader :tcell_api_url
53
+ :password_hmac_key,
54
+ :stdout_logger
57
55
 
58
56
  attr_accessor :disable_all,
59
57
  :enabled,
@@ -61,8 +59,7 @@ module TCellAgent
61
59
  :enable_event_consumer, # false = Do not consume events, drop them
62
60
  :enable_policy_polling, # false = Do not poll for policies
63
61
  :enable_instrumentation, # false = Do not add instrumentation
64
- :enable_intercept_requests, # false = Do not insert middleware
65
- :enable_child_process_events # true = Start an event processor on all processes, even children
62
+ :enable_intercept_requests # false = Do not insert middleware
66
63
 
67
64
  attr_accessor :enabled_instrumentations
68
65
 
@@ -70,23 +67,10 @@ module TCellAgent
70
67
 
71
68
  attr_accessor :disable_cmdi_exec_instrumentation # true = disable cmdi Kernel::exec instrumentation
72
69
 
73
- def tcell_api_url=(value)
74
- @tcell_api_url = value
75
- @tcell_api_url = compose_api_url!
76
- end
77
-
78
70
  def should_start_event_manager?
79
71
  @enabled && @enable_event_manager
80
72
  end
81
73
 
82
- def should_start_event_manager_in_child_processes?
83
- @enabled && @enable_event_manager && @enable_child_process_events
84
- end
85
-
86
- def should_consume_event?
87
- @enabled && @enable_event_manager && @enable_event_consumer
88
- end
89
-
90
74
  def should_start_policy_poll?
91
75
  @enabled && @enable_policy_polling && @fetch_policies_from_tcell # fetch_policies_from_tcel = legacy
92
76
  end
@@ -134,11 +118,7 @@ module TCellAgent
134
118
  @agent_log_dir = nil
135
119
  @log_tag = nil
136
120
 
137
- @logger = nil
138
- @appfirewall_payloads_logger = nil
139
-
140
121
  @version = 0
141
- @exp_config_settings = true
142
122
  @demomode = false
143
123
 
144
124
  @fetch_policies_from_tcell = true
@@ -147,11 +127,9 @@ module TCellAgent
147
127
  @disable_all = false
148
128
  @enabled = true
149
129
  @enable_event_manager = true
150
- @enable_event_consumer = true
151
130
  @enable_policy_polling = true
152
131
  @enable_instrumentation = true
153
132
  @enable_intercept_requests = true
154
- @enable_child_process_events = false
155
133
 
156
134
  @enabled_instrumentations = {
157
135
  :doorkeeper => true,
@@ -168,13 +146,17 @@ module TCellAgent
168
146
 
169
147
  @max_data_ex_db_records_per_request = 1000
170
148
  @reverse_proxy = true
171
- @reverse_proxy_ip_address_header = nil
149
+ @reverse_proxy_ip_address_header = 'X-Forwarded-For'
172
150
  @allow_payloads = true
173
151
 
174
152
  @max_csp_header_bytes = nil
175
153
  @password_hmac_key = nil
154
+ @logging_options = {}
176
155
 
177
156
  @agent_home_dir = ENV['TCELL_AGENT_HOME'] || File.join(Dir.getwd, 'tcell')
157
+ @cache_folder = File.join(@agent_home_dir, 'cache/')
158
+ @agent_log_dir = File.join(@agent_home_dir, 'logs')
159
+
178
160
  @config_filename = ENV['TCELL_AGENT_CONFIG'] || File.join(Dir.getwd, filename)
179
161
 
180
162
  read_config_from_file(@config_filename)
@@ -185,27 +167,9 @@ module TCellAgent
185
167
  @event_time_limit_seconds = 2
186
168
  end
187
169
 
188
- if ENV['TCELL_AGENT_ALLOW_UNENCRYPTED_APPSENSOR_PAYLOADS']
189
- 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.'
190
- end
191
-
192
- if ENV['TCELL_AGENT_ALLOW_UNENCRYPTED_APPFIREWALL_PAYLOADS']
193
- puts 'tCell.io Agent: [DEPRECATED] TCELL_AGENT_ALLOW_UNENCRYPTED_APPFIREWALL_PAYLOADS is deprecated and will be removed in a future release. Please switch to TCELL_AGENT_ALLOW_PAYLOADS.'
194
- end
195
-
196
- unless ENV['TCELL_AGENT_ALLOW_UNENCRYPTED_APPSENSOR_PAYLOADS'].nil?
197
- @allow_payloads = [true, 'true', 'yes', '1'].include?(ENV['TCELL_AGENT_ALLOW_UNENCRYPTED_APPSENSOR_PAYLOADS'])
198
- end
199
- unless ENV['TCELL_AGENT_ALLOW_UNENCRYPTED_APPFIREWALL_PAYLOADS'].nil?
200
- @allow_payloads = [true, 'true', 'yes', '1'].include?(ENV['TCELL_AGENT_ALLOW_UNENCRYPTED_APPFIREWALL_PAYLOADS'])
201
- end
202
- unless ENV['TCELL_AGENT_ALLOW_PAYLOADS'].nil?
203
- @allow_payloads = [true, 'true', 'yes', '1'].include?(ENV['TCELL_AGENT_ALLOW_PAYLOADS'])
204
- end
205
-
206
- @tcell_api_url = compose_api_url!
207
- @tcell_input_url ||= 'https://input.tcell.io/api/v1'
208
- @js_agent_url ||= 'https://jsagent.tcell.io/tcellagent.min.js'
170
+ @tcell_api_url ||= 'https://us.agent.tcell.insight.rapid7.com/api/v1'
171
+ @tcell_input_url ||= 'https://us.input.tcell.insight.rapid7.com/api/v1'
172
+ @js_agent_url ||= 'https://us.jsagent.tcell.insight.rapid7.com/tcellagent.min.js'
209
173
 
210
174
  if @host_identifier.nil?
211
175
  begin
@@ -218,50 +182,6 @@ module TCellAgent
218
182
  @uuid = SecureRandom.uuid
219
183
  end
220
184
 
221
- def compose_api_url!
222
- @tcell_api_url ||= 'https://api.tcell.io'
223
- parsed_uri = URI.parse(@tcell_api_url)
224
-
225
- api_url = [
226
- parsed_uri.scheme,
227
- '://',
228
- parsed_uri.host
229
- ]
230
-
231
- api_url.push(":#{parsed_uri.port}") unless [80, 443].include?(parsed_uri.port)
232
-
233
- @js_agent_api_base_url ||= "#{api_url.join('')}/api/v1"
234
-
235
- [
236
- api_url.join(''),
237
- '/agents/api/v1/apps/',
238
- '{app_id}',
239
- '/policies/latest',
240
- '?',
241
- 'type=jsagentinjection:v1',
242
- '&type=http-redirect:v1',
243
- '&type=clickjacking:v1',
244
- '&type=secure-headers:v1',
245
- '&type=cmdi:v1',
246
- '&type=csp-headers:v1',
247
- '&type=dlp:v1',
248
- '&type=login:v1',
249
- '&type=regex:v1',
250
- '&type=appsensor:v2',
251
- '&type=patches:v1'
252
- ].join('')
253
- end
254
-
255
- def cache_filename_with_app_id
256
- @cache_filename ||= File.join(@agent_home_dir, 'cache', 'tcell_agent.cache')
257
-
258
- if @app_id
259
- "#{@cache_filename}.#{@app_id}"
260
- else
261
- @cache_filename
262
- end
263
- end
264
-
265
185
  def read_config_using_env
266
186
  @app_id = ENV['TCELL_AGENT_APP_ID'] || @app_id
267
187
  @api_key = ENV['TCELL_AGENT_API_KEY'] || @api_key
@@ -272,12 +192,16 @@ module TCellAgent
272
192
  @tcell_input_url = ENV['TCELL_INPUT_URL'] || @tcell_input_url
273
193
  @demomode = ENV['TCELL_DEMOMODE'] || @demomode
274
194
 
275
- @agent_home_owner = ENV['TCELL_AGENT_HOME_OWNER'] || @agent_home_owner
276
195
  @agent_log_dir = ENV['TCELL_AGENT_LOG_DIR'] || @agent_log_dir
196
+ @log_file_name = ENV['TCELL_AGENT_LOG_FILENAME'] || @log_file_name
197
+
198
+ @logging_options['enabled'] = to_bool(ENV['TCELL_AGENT_LOG_ENABLED']) unless to_bool(ENV['TCELL_AGENT_LOG_ENABLED']).nil?
199
+ @logging_options['level'] = ENV['TCELL_AGENT_LOG_LEVEL'] || @logging_options['level'] unless @logging_options.nil?
277
200
 
278
- @disable_cmdi_exec_instrumentation = ENV['TCELL_CMDI_EXEC_DISABLED'] || @disable_cmdi_exec_instrumentation
201
+ @enabled = to_bool(ENV['TCELL_AGENT_ENABLED']) unless to_bool(ENV['TCELL_AGENT_ENABLED']).nil?
279
202
 
280
- @enabled = ENV['TCELL_AGENT_ENABLED'].to_s.casecmp('true').zero? if %w[true false].include? ENV['TCELL_AGENT_ENABLED'].to_s.downcase
203
+ @allow_payloads = to_bool(ENV['TCELL_AGENT_ALLOW_PAYLOADS']) unless to_bool(ENV['TCELL_AGENT_ALLOW_PAYLOADS']).nil?
204
+ @disable_cmdi_exec_instrumentation = to_bool(ENV['TCELL_CMDI_EXEC_DISABLED']) || @disable_cmdi_exec_instrumentation
281
205
  end
282
206
 
283
207
  def read_config_from_file(filename)
@@ -306,33 +230,21 @@ module TCellAgent
306
230
  @enabled = app_data.fetch('enabled', @enabled)
307
231
 
308
232
  @enable_event_manager = app_data.fetch('enable_event_manager', @enable_event_manager)
309
- @enable_event_consumer = app_data.fetch('enable_event_consumer', @enable_event_consumer)
310
233
  @enable_policy_polling = app_data.fetch('enable_policy_polling', @enable_policy_polling)
311
234
  @enable_instrumentation = app_data.fetch('enable_instrumentation', @enable_instrumentation)
312
235
  @enable_intercept_requests = app_data.fetch('enable_intercept_requests', @enable_intercept_requests)
313
236
  @fetch_policies_from_tcell = app_data.fetch('fetch_policies_from_tcell', @fetch_policies_from_tcell)
314
237
  @instrument_for_events = app_data.fetch('instrument_for_events', @instrument_for_events)
315
- @enable_child_process_events = app_data.fetch('enable_child_process_events', @enable_child_process_events)
316
-
317
- @agent_home_owner = app_data.fetch('agent_home_owner', @agent_home_owner)
318
238
 
319
239
  @logging_options = app_data.fetch('logging_options', {})
320
240
  @agent_log_dir = app_data.fetch('log_dir', @agent_log_dir)
321
- @log_file_name = @logging_options.fetch('filename', @log_file_name)
241
+ @log_file_name = @logging_options['filename'] || @log_file_name
322
242
 
323
243
  @tcell_api_url = app_data.fetch('tcell_api_url', @tcell_api_url)
324
244
  @tcell_input_url = app_data.fetch('tcell_input_url', @tcell_input_url)
325
245
 
326
246
  @max_csp_header_bytes = app_data.fetch('max_csp_header_bytes', @max_csp_header_bytes)
327
247
 
328
- @allow_payloads = app_data.fetch(
329
- 'allow_unencrypted_appsensor_payloads',
330
- @allow_payloads
331
- )
332
- @allow_payloads = app_data.fetch(
333
- 'allow_unencrypted_appfirewall_payloads',
334
- @allow_payloads
335
- )
336
248
  @allow_payloads = app_data.fetch(
337
249
  'allow_payloads',
338
250
  @allow_payloads
@@ -377,15 +289,19 @@ module TCellAgent
377
289
  end
378
290
  end
379
291
 
380
- # old value could be set via initializers, this makes sure those initializers still work
381
- # properly
382
- def allow_unencrypted_appfirewall_payloads=(val)
383
- @allow_payloads = val
292
+ def to_bool(var)
293
+ return unless var
294
+ var.to_s.casecmp('true').zero? if %w[true false].include? var.to_s.downcase
384
295
  end
385
296
 
386
- # keep this around in case the value was read as well
387
- def allow_unencrypted_appfirewall_payloads
388
- @allow_payloads
297
+ def enforce_symbol_keys(hashmap)
298
+ hashmap.each_with_object({}) do |(k, v), memo|
299
+ memo[k.to_sym] = v
300
+ end
301
+ end
302
+
303
+ def logging_enabled?
304
+ @enabled && enforce_symbol_keys(@logging_options || {})[:enabled]
389
305
  end
390
306
 
391
307
  def log_filename
@@ -393,9 +309,12 @@ module TCellAgent
393
309
  File.join(@agent_log_dir, @log_file_name)
394
310
  end
395
311
 
396
- def appfirewall_payloads_log_filename
397
- @agent_log_dir ||= File.join(@agent_home_dir, 'logs')
398
- File.join(@agent_log_dir, 'tcell_agent_payloads.log')
312
+ def clean_logging_options
313
+ {
314
+ :enabled => true,
315
+ :level => 'INFO',
316
+ :filename => log_file_name
317
+ }.merge(enforce_symbol_keys(@logging_options || {}))
399
318
  end
400
319
  end
401
320
 
@@ -1,33 +1,31 @@
1
- # See the file "LICENSE" for the full license governing this code.
1
+ if TCellAgent.configuration.should_instrument_devise? && defined?(Devise)
2
+ require 'devise'
3
+ require 'devise/rails'
4
+ require 'devise/strategies/database_authenticatable'
5
+ require 'tcell_agent/userinfo'
2
6
 
3
- require 'devise'
4
- require 'devise/rails'
5
- require 'devise/strategies/database_authenticatable'
6
- require 'tcell_agent/userinfo'
7
- require 'tcell_agent/logger'
8
- require 'tcell_agent/sensor_events/honeytokens'
9
-
10
- module TCellAgent
11
- if defined?(Devise)
12
- TCellAgent::UserInformation.class_eval do
13
- class << self
14
- alias_method :original_get_user_from_request, :get_user_from_request
15
- def get_user_from_request(request)
16
- orig_user_id = original_get_user_from_request(request)
17
- begin
18
- if request.session && request.session.key?('warden.user.user.key')
19
- userkey = request.session['warden.user.user.key']
20
- user_id = if userkey.length == 2
21
- userkey[0][0]
22
- else
23
- userkey[1][0]
24
- end
25
- return user_id.to_s if user_id.is_a? Integer
7
+ module TCellAgent
8
+ if defined?(Devise)
9
+ TCellAgent::UserInformation.class_eval do
10
+ class << self
11
+ alias_method :original_get_user_from_request, :get_user_from_request
12
+ def get_user_from_request(request)
13
+ orig_user_id = original_get_user_from_request(request)
14
+ begin
15
+ if request.session && request.session.key?('warden.user.user.key')
16
+ userkey = request.session['warden.user.user.key']
17
+ user_id = if userkey.length == 2
18
+ userkey[0][0]
19
+ else
20
+ userkey[1][0]
21
+ end
22
+ return user_id.to_s if user_id.is_a? Integer
23
+ end
24
+ rescue StandardError
25
+ return orig_user_id
26
26
  end
27
- rescue StandardError
28
- return orig_user_id
27
+ orig_user_id
29
28
  end
30
- orig_user_id
31
29
  end
32
30
  end
33
31
  end
@@ -1,47 +1,44 @@
1
1
  require 'tcell_agent/agent'
2
- require 'tcell_agent/sensor_events/login_fraud'
3
2
 
4
3
  module TCellAgent
5
4
  module Hooks
6
5
  module LoginFraud
6
+ # Note: mock out in tests
7
+ def self.get_logger
8
+ unless defined?(@login_fraud_logger)
9
+ @login_fraud_logger = TCellAgent::ModuleLogger.new(TCellAgent.logger, name)
10
+ end
11
+
12
+ @login_fraud_logger
13
+ end
14
+
7
15
  def self.report_login_event(status,
8
16
  env_or_header_keys,
9
17
  tcell_data,
10
18
  user_id,
11
19
  password,
12
20
  user_valid)
13
- if TCellAgent.configuration.enabled &&
14
- TCellAgent.configuration.should_intercept_requests?
15
- login_fraud_policy = TCellAgent.policy(TCellAgent::PolicyTypes::LOGINFRAUD)
16
-
17
- if login_fraud_policy && login_fraud_policy.enabled
18
- if tcell_data
19
- if ![TCellAgent::Hooks::V1::Login::LOGIN_FAILURE,
20
- TCellAgent::Hooks::V1::Login::LOGIN_SUCCESS].include?(status)
21
- TCellAgent.logger.error("Unkown login status: #{status}")
21
+ return unless TCellAgent.configuration.should_intercept_requests? && tcell_data
22
22
 
23
- elsif (status == TCellAgent::Hooks::V1::Login::LOGIN_FAILURE) &&
24
- login_fraud_policy.login_failed_enabled
25
- TCellAgent.send_event(
26
- TCellAgent::SensorEvents::LoginFailure.new(env_or_header_keys,
27
- tcell_data,
28
- user_id,
29
- password,
30
- user_valid)
31
- )
23
+ login_policy = TCellAgent.policy(TCellAgent::PolicyTypes::LOGINFRAUD)
32
24
 
33
- elsif (status == TCellAgent::Hooks::V1::Login::LOGIN_SUCCESS) &&
34
- login_fraud_policy.login_success_enabled
35
- TCellAgent.send_event(
36
- TCellAgent::SensorEvents::LoginSuccess.new(env_or_header_keys,
37
- tcell_data,
38
- user_id,
39
- password,
40
- user_valid)
41
- )
42
- end
43
- end
44
- end
25
+ if ![TCellAgent::Hooks::V1::Login::LOGIN_FAILURE,
26
+ TCellAgent::Hooks::V1::Login::LOGIN_SUCCESS].include?(status)
27
+ get_logger.error("Unkown login status: #{status}")
28
+ elsif status == TCellAgent::Hooks::V1::Login::LOGIN_FAILURE
29
+ login_policy.report_login_failure(
30
+ user_id,
31
+ password,
32
+ env_or_header_keys,
33
+ user_valid,
34
+ tcell_data
35
+ )
36
+ elsif status == TCellAgent::Hooks::V1::Login::LOGIN_SUCCESS
37
+ login_policy.report_login_success(
38
+ user_id,
39
+ env_or_header_keys,
40
+ tcell_data
41
+ )
45
42
  end
46
43
  end
47
44
  end
@@ -91,9 +88,9 @@ if defined?(TCellAgent::Hooks::V1::Login)
91
88
  tcell_data = TCellAgent::Instrumentation::TCellData.new
92
89
  tcell_data.user_agent = user_agent
93
90
  tcell_data.referrer = referrer
94
- tcell_data.ip_address = remote_address
91
+ tcell_data.remote_address = remote_address
95
92
  tcell_data.path = document_uri
96
- tcell_data.hmac_session_id = TCellAgent::SensorEvents::Util.hmac(session_id)
93
+ tcell_data.session_id = session_id
97
94
 
98
95
  TCellAgent::Hooks::LoginFraud.report_login_event(status,
99
96
  header_keys,
@@ -0,0 +1,25 @@
1
+ tcell_server = ENV['TCELL_AGENT_SERVER']
2
+
3
+ if TCellAgent.configuration.should_instrument?
4
+ unless tcell_server && tcell_server == 'mock'
5
+ if (tcell_server && tcell_server == 'webrick') || defined?(Rails::Server)
6
+ require('tcell_agent/servers/rails_server')
7
+
8
+ elsif (tcell_server && tcell_server == 'thin') || defined?(Thin)
9
+ require('tcell_agent/servers/thin')
10
+
11
+ elsif (tcell_server && tcell_server == 'puma') || defined?(Puma)
12
+ require('tcell_agent/servers/puma')
13
+
14
+ elsif (tcell_server && tcell_server == 'unicorn') || defined?(Unicorn)
15
+ require('tcell_agent/servers/unicorn')
16
+
17
+ elsif (tcell_server && tcell_server == 'passenger') || defined?(PhusionPassenger)
18
+ require('tcell_agent/servers/passenger')
19
+ end
20
+ end
21
+
22
+ elsif (tcell_server && tcell_server == 'unicorn') || defined?(Unicorn)
23
+ # unicorn is always instrumented to support rolling restarts
24
+ require('tcell_agent/servers/unicorn')
25
+ end