tcell_agent 1.1.12 → 2.2.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.
Files changed (169) hide show
  1. checksums.yaml +5 -5
  2. data/bin/tcell_agent +45 -137
  3. data/lib/tcell_agent.rb +12 -14
  4. data/lib/tcell_agent/agent.rb +108 -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/config_initializer.rb +66 -0
  8. data/lib/tcell_agent/configuration.rb +69 -345
  9. data/lib/tcell_agent/hooks/login_fraud.rb +30 -33
  10. data/lib/tcell_agent/instrument_servers.rb +23 -0
  11. data/lib/tcell_agent/instrumentation.rb +12 -10
  12. data/lib/tcell_agent/instrumentation/cmdi.rb +29 -25
  13. data/lib/tcell_agent/instrumentation/lfi.rb +84 -0
  14. data/lib/tcell_agent/instrumentation/monkey_patches/file.rb +25 -0
  15. data/lib/tcell_agent/instrumentation/monkey_patches/io.rb +131 -0
  16. data/lib/tcell_agent/instrumentation/monkey_patches/kernel.rb +102 -0
  17. data/lib/tcell_agent/logger.rb +49 -114
  18. data/lib/tcell_agent/patches.rb +6 -7
  19. data/lib/tcell_agent/policies/appfirewall_policy.rb +26 -0
  20. data/lib/tcell_agent/policies/command_injection_policy.rb +28 -0
  21. data/lib/tcell_agent/policies/dataloss_policy.rb +44 -44
  22. data/lib/tcell_agent/policies/headers_policy.rb +25 -0
  23. data/lib/tcell_agent/policies/http_redirect_policy.rb +13 -79
  24. data/lib/tcell_agent/policies/js_agent_policy.rb +27 -0
  25. data/lib/tcell_agent/policies/local_file_access.rb +28 -0
  26. data/lib/tcell_agent/policies/login_policy.rb +43 -0
  27. data/lib/tcell_agent/policies/patches_policy.rb +27 -0
  28. data/lib/tcell_agent/policies/policies_manager.rb +68 -0
  29. data/lib/tcell_agent/policies/policy_polling.rb +58 -0
  30. data/lib/tcell_agent/policies/policy_types.rb +14 -0
  31. data/lib/tcell_agent/policies/system_enablements.rb +27 -0
  32. data/lib/tcell_agent/rails/auth/authlogic.rb +46 -75
  33. data/lib/tcell_agent/rails/auth/authlogic_helper.rb +20 -0
  34. data/lib/tcell_agent/rails/auth/devise.rb +100 -105
  35. data/lib/tcell_agent/rails/auth/devise_helper.rb +29 -0
  36. data/lib/tcell_agent/rails/auth/doorkeeper.rb +62 -76
  37. data/lib/tcell_agent/{userinfo.rb → rails/auth/userinfo.rb} +0 -0
  38. data/lib/tcell_agent/rails/csrf_exception.rb +2 -10
  39. data/lib/tcell_agent/rails/dlp.rb +35 -23
  40. data/lib/tcell_agent/rails/dlp_handler.rb +1 -2
  41. data/lib/tcell_agent/rails/js_agent_insert.rb +12 -13
  42. data/lib/tcell_agent/rails/middleware/body_filter_middleware.rb +4 -25
  43. data/lib/tcell_agent/rails/middleware/context_middleware.rb +2 -12
  44. data/lib/tcell_agent/rails/middleware/global_middleware.rb +1 -2
  45. data/lib/tcell_agent/rails/middleware/headers_middleware.rb +14 -34
  46. data/lib/tcell_agent/{rails.rb → rails/railties/tcell_agent_railties.rb} +11 -16
  47. data/lib/tcell_agent/rails/railties/tcell_agent_unicorn_railties.rb +8 -0
  48. data/lib/tcell_agent/rails/routes.rb +10 -12
  49. data/lib/tcell_agent/rails/routes/grape.rb +4 -14
  50. data/lib/tcell_agent/rails/routes/route_id.rb +3 -1
  51. data/lib/tcell_agent/rails/settings_reporter.rb +23 -36
  52. data/lib/tcell_agent/rails/tcell_body_proxy.rb +5 -4
  53. data/lib/tcell_agent/rust/agent_config.rb +60 -0
  54. data/lib/tcell_agent/rust/{libtcellagent-alpine-1.3.2.so → libtcellagent-5.0.2.dylib} +0 -0
  55. data/lib/tcell_agent/rust/{libtcellagent-1.3.2.so → libtcellagent-5.0.2.so} +0 -0
  56. data/lib/tcell_agent/rust/libtcellagent-alpine-5.0.2.so +0 -0
  57. data/lib/tcell_agent/rust/models.rb +6 -52
  58. data/lib/tcell_agent/rust/native_agent.rb +549 -0
  59. data/lib/tcell_agent/rust/native_agent_response.rb +42 -0
  60. data/lib/tcell_agent/rust/native_library.rb +69 -0
  61. data/lib/tcell_agent/rust/tcellagent-5.0.2.dll +0 -0
  62. data/lib/tcell_agent/sensor_events/agent_setting_event.rb +12 -0
  63. data/lib/tcell_agent/sensor_events/{app_config.rb → app_config_setting_event.rb} +0 -6
  64. data/lib/tcell_agent/sensor_events/dlp.rb +2 -6
  65. data/lib/tcell_agent/sensor_events/sensor.rb +0 -62
  66. data/lib/tcell_agent/sensor_events/server_agent.rb +13 -18
  67. data/lib/tcell_agent/sensor_events/util/sanitizer_utilities.rb +0 -108
  68. data/lib/tcell_agent/sensor_events/util/utils.rb +0 -2
  69. data/lib/tcell_agent/servers/passenger.rb +1 -28
  70. data/lib/tcell_agent/servers/puma.rb +3 -21
  71. data/lib/tcell_agent/servers/rails_server.rb +1 -2
  72. data/lib/tcell_agent/servers/thin.rb +2 -2
  73. data/lib/tcell_agent/servers/unicorn.rb +19 -80
  74. data/lib/tcell_agent/servers/webrick.rb +1 -2
  75. data/lib/tcell_agent/settings_reporter.rb +11 -90
  76. data/lib/tcell_agent/sinatra.rb +14 -16
  77. data/lib/tcell_agent/tcell_context.rb +40 -14
  78. data/lib/tcell_agent/utils/headers.rb +14 -0
  79. data/lib/tcell_agent/version.rb +1 -1
  80. data/spec/lib/tcell_agent/configuration_spec.rb +55 -346
  81. data/spec/lib/tcell_agent/hooks/login_fraud_spec.rb +46 -173
  82. data/spec/lib/tcell_agent/instrumentation/cmdi/io_cmdi_spec.rb +504 -0
  83. data/spec/lib/tcell_agent/instrumentation/cmdi/kernel_cmdi_spec.rb +435 -0
  84. data/spec/lib/tcell_agent/instrumentation/cmdi_spec.rb +201 -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 +562 -0
  87. data/spec/lib/tcell_agent/instrumentation/lfi/kernel_lfi_spec.rb +264 -0
  88. data/spec/lib/tcell_agent/instrumentation/lfi_spec.rb +150 -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/rust/agent_config_spec.rb +27 -0
  108. data/spec/lib/tcell_agent/sensor_events/util/sanitizer_utilities_spec.rb +0 -35
  109. data/spec/lib/tcell_agent/settings_reporter_spec.rb +56 -155
  110. data/spec/spec_helper.rb +1 -1
  111. data/spec/support/builders.rb +103 -0
  112. data/spec/support/force_logger_mocking.rb +38 -0
  113. data/spec/support/resources/lfi_sample_file.txt +2 -0
  114. data/spec/support/static_agent_overrides.rb +0 -15
  115. metadata +72 -83
  116. data/lib/tcell_agent/agent/event_processor.rb +0 -326
  117. data/lib/tcell_agent/agent/fork_pipe_manager.rb +0 -113
  118. data/lib/tcell_agent/agent/policy_manager.rb +0 -219
  119. data/lib/tcell_agent/agent/policy_types.rb +0 -30
  120. data/lib/tcell_agent/api.rb +0 -91
  121. data/lib/tcell_agent/appsensor/injections_reporter.rb +0 -24
  122. data/lib/tcell_agent/authlogic.rb +0 -26
  123. data/lib/tcell_agent/config/child_process_events.rb +0 -8
  124. data/lib/tcell_agent/config/unknown_options.rb +0 -123
  125. data/lib/tcell_agent/devise.rb +0 -35
  126. data/lib/tcell_agent/instrumentation/cmdi/backtick.rb +0 -10
  127. data/lib/tcell_agent/instrumentation/cmdi/exec.rb +0 -14
  128. data/lib/tcell_agent/instrumentation/cmdi/popen.rb +0 -28
  129. data/lib/tcell_agent/instrumentation/cmdi/spawn.rb +0 -11
  130. data/lib/tcell_agent/instrumentation/cmdi/system.rb +0 -11
  131. data/lib/tcell_agent/policies/http_tx_policy.rb +0 -60
  132. data/lib/tcell_agent/policies/login_fraud_policy.rb +0 -45
  133. data/lib/tcell_agent/policies/rust_policies.rb +0 -110
  134. data/lib/tcell_agent/rails/on_start.rb +0 -41
  135. data/lib/tcell_agent/rust/libtcellagent-1.3.2.dylib +0 -0
  136. data/lib/tcell_agent/rust/tcellagent-1.3.2.dll +0 -0
  137. data/lib/tcell_agent/rust/whisperer.rb +0 -308
  138. data/lib/tcell_agent/sensor_events/appsensor_event.rb +0 -52
  139. data/lib/tcell_agent/sensor_events/appsensor_meta_event.rb +0 -45
  140. data/lib/tcell_agent/sensor_events/command_injection.rb +0 -75
  141. data/lib/tcell_agent/sensor_events/honeytokens.rb +0 -16
  142. data/lib/tcell_agent/sensor_events/login_fraud.rb +0 -60
  143. data/lib/tcell_agent/sensor_events/metrics.rb +0 -123
  144. data/lib/tcell_agent/sensor_events/patches.rb +0 -21
  145. data/lib/tcell_agent/start_background_thread.rb +0 -55
  146. data/lib/tcell_agent/system_info.rb +0 -11
  147. data/lib/tcell_agent/utils/io.rb +0 -38
  148. data/lib/tcell_agent/utils/passwords.rb +0 -28
  149. data/lib/tcell_agent/utils/queue_with_timeout.rb +0 -142
  150. data/spec/lib/tcell_agent/agent/fork_pipe_manager_spec.rb +0 -100
  151. data/spec/lib/tcell_agent/agent/policy_manager_spec.rb +0 -535
  152. data/spec/lib/tcell_agent/agent/static_agent_spec.rb +0 -133
  153. data/spec/lib/tcell_agent/api/api_spec.rb +0 -39
  154. data/spec/lib/tcell_agent/appsensor/injections_reporter_spec.rb +0 -187
  155. data/spec/lib/tcell_agent/cmdi_spec.rb +0 -736
  156. data/spec/lib/tcell_agent/config/unknown_options_spec.rb +0 -213
  157. data/spec/lib/tcell_agent/instrumentation_spec.rb +0 -225
  158. data/spec/lib/tcell_agent/policies/appsensor_policy_spec.rb +0 -517
  159. data/spec/lib/tcell_agent/policies/http_tx_policy_spec.rb +0 -22
  160. data/spec/lib/tcell_agent/rails/middleware/appsensor_middleware_spec.rb +0 -293
  161. data/spec/lib/tcell_agent/rails/middleware/dlp_middleware_spec.rb +0 -198
  162. data/spec/lib/tcell_agent/rails/middleware/global_middleware_spec.rb +0 -180
  163. data/spec/lib/tcell_agent/rails/middleware/redirect_middleware_spec.rb +0 -116
  164. data/spec/lib/tcell_agent/rust/models_spec.rb +0 -120
  165. data/spec/lib/tcell_agent/rust/whisperer_spec.rb +0 -704
  166. data/spec/lib/tcell_agent/sensor_events/appsensor_meta_event_spec.rb +0 -45
  167. data/spec/lib/tcell_agent/sensor_events/sessions_metric_spec.rb +0 -272
  168. data/spec/lib/tcell_agent/utils/bounded_queue_spec.rb +0 -52
  169. data/spec/lib/tcell_agent/utils/passwords_spec.rb +0 -143
@@ -0,0 +1,25 @@
1
+ require 'tcell_agent/policies/policy'
2
+
3
+ module TCellAgent
4
+ module Policies
5
+ class HeadersPolicy < Policy
6
+ def self.api_identifier
7
+ 'headers'
8
+ end
9
+
10
+ attr_accessor :enabled
11
+
12
+ def initialize(native_agent, enablements)
13
+ @native_agent = native_agent
14
+ @enabled = enablements['headers'] || false
15
+ end
16
+
17
+ def get_headers(tcell_context)
18
+ return [] unless @enabled
19
+
20
+ response = @native_agent.get_headers(tcell_context)
21
+ response['headers'] || []
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,95 +1,29 @@
1
- # See the file "LICENSE" for the full license governing this code.
2
- require 'uri'
3
-
4
1
  require 'tcell_agent/policies/policy'
5
- require 'tcell_agent/logger'
6
2
 
7
3
  module TCellAgent
8
4
  module Policies
9
5
  class HttpRedirectPolicy < Policy
10
- attr_accessor :policy_id, :enabled, :whitelist, :block, :data_scheme_allowed
11
-
12
- def initialize
13
- @policy_id = nil
14
- @enabled = false
15
- @whitelist = []
16
- @block = false
17
- @data_scheme_allowed = false
6
+ def self.api_identifier
7
+ 'http-redirect'
18
8
  end
19
9
 
20
- def suspicious_redirect?(host, current_host)
21
- if !host || host == '' || host == current_host
22
- # local redirect
23
- return false
24
- end
25
-
26
- whitelist.each do |whitelist_regex|
27
- if (host =~ whitelist_regex) || ("www.#{host}" =~ whitelist_regex)
28
- return false
29
- end
30
- end
31
-
32
- true
33
- end
34
-
35
- def enforce(target_uri, request_uri, current_path, method, route_id, status_code, remote_addr, hmac_session_id = nil)
36
- return nil unless @enabled
37
-
38
- current_host = URI.parse(request_uri).host
39
- if target_uri.downcase.start_with?('data:')
40
- return nil if @data_scheme_allowed
10
+ attr_accessor :enabled
41
11
 
42
- target_host = target_uri.split(',')[0]
43
-
44
- else
45
- target_host = URI.parse(target_uri).host
46
- return nil unless suspicious_redirect?(target_host, current_host)
47
- end
48
-
49
- begin
50
- event = TCellAgent::SensorEvents::TCellRedirectSensorEvent.new(
51
- target_host,
52
- current_host,
53
- current_path,
54
- method,
55
- route_id,
56
- status_code,
57
- remote_addr,
58
- hmac_session_id,
59
- nil
60
- )
61
-
62
- TCellAgent.send_event(event)
63
- rescue StandardError => ie
64
- TCellAgent.logger.error("uncaught exception while creating redirect event: #{ie.message}")
65
- end
66
-
67
- return '/' if @block
68
-
69
- nil
12
+ def initialize(native_agent, enablements)
13
+ @native_agent = native_agent
14
+ @enabled = enablements['http_redirect'] || false
70
15
  end
71
16
 
72
- def self.from_json(policy_json)
73
- return nil unless policy_json
74
-
75
- http_redirect_policy = HttpRedirectPolicy.new
76
- http_redirect_policy.policy_id = policy_json['policy_id']
77
- raise 'Policy ID missing' unless http_redirect_policy.policy_id
78
-
79
- policy_data_json = policy_json['data']
80
- return http_redirect_policy unless policy_data_json
17
+ def check_redirect(redirect_url, from_domain, status_code, tcell_context)
18
+ return redirect_url unless @enabled
81
19
 
82
- http_redirect_policy.enabled = policy_data_json.fetch('enabled', false)
83
- http_redirect_policy.block = policy_data_json.fetch('block', false)
84
- http_redirect_policy.data_scheme_allowed = policy_data_json.fetch('data_scheme_allowed', false)
20
+ redirect_response = @native_agent.check_http_redirect(
21
+ redirect_url, from_domain, status_code, tcell_context
22
+ )
85
23
 
86
- http_redirect_policy.whitelist = []
87
- policy_data_json.fetch('whitelist', []).each do |regex_pattern|
88
- escaped = Regexp.escape(regex_pattern).gsub('\*', '.*?')
89
- http_redirect_policy.whitelist.push(Regexp.new("^#{escaped}$", Regexp::IGNORECASE))
90
- end
24
+ return '/' if redirect_response['block']
91
25
 
92
- http_redirect_policy
26
+ redirect_url
93
27
  end
94
28
  end
95
29
  end
@@ -0,0 +1,27 @@
1
+ require 'tcell_agent/policies/policy'
2
+
3
+ module TCellAgent
4
+ module Policies
5
+ class JsAgentPolicy < Policy
6
+ def self.api_identifier
7
+ 'jsagentinjection'
8
+ end
9
+
10
+ attr_accessor :enabled
11
+
12
+ def initialize(native_agent, enablements)
13
+ @native_agent = native_agent
14
+ @enabled = enablements['jsagentinjection'] || false
15
+ end
16
+
17
+ def get_js_agent_script_tag(tcell_context)
18
+ return nil unless @enabled
19
+
20
+ response = @native_agent.get_js_agent_script_tag(
21
+ tcell_context
22
+ )
23
+ response['script_tag']
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,28 @@
1
+ require 'tcell_agent/policies/policy'
2
+
3
+ module TCellAgent
4
+ module Policies
5
+ class LocalFileInclusion < Policy
6
+ def self.api_identifier
7
+ 'lfi'
8
+ end
9
+
10
+ attr_accessor :enabled
11
+
12
+ def initialize(native_agent, enablements)
13
+ @native_agent = native_agent
14
+ @enabled = enablements['local_file_access'] || false
15
+ end
16
+
17
+ def block_file_access?(path, mode, tcell_context)
18
+ return false unless @native_agent
19
+
20
+ response = @native_agent.file_access_apply(
21
+ path, mode, tcell_context
22
+ )
23
+
24
+ !response['blocked'].nil? && response['blocked']
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,43 @@
1
+ require 'tcell_agent/policies/policy'
2
+
3
+ module TCellAgent
4
+ module Policies
5
+ class LoginPolicy < Policy
6
+ def self.api_identifier
7
+ 'login'
8
+ end
9
+
10
+ attr_reader :login_success_enabled, :login_failed_enabled
11
+
12
+ def initialize(native_agent, enablements)
13
+ @native_agent = native_agent
14
+ @login_success_enabled = enablements['login_success_enabled'] || false
15
+ @login_failed_enabled = enablements['login_failed_enabled'] || false
16
+ end
17
+
18
+ def report_login_success(user_id, headers, tcell_context)
19
+ return {} unless @login_success_enabled
20
+
21
+ success = true
22
+ password = nil
23
+ user_valid = true
24
+ @native_agent.login_fraud_apply(
25
+ success, user_id, password, headers, user_valid, tcell_context
26
+ )
27
+ end
28
+
29
+ def report_login_failure(user_id,
30
+ password,
31
+ headers,
32
+ user_valid,
33
+ tcell_context)
34
+ return {} unless @login_failed_enabled
35
+
36
+ success = false
37
+ @native_agent.login_fraud_apply(
38
+ success, user_id, password, headers, user_valid, tcell_context
39
+ )
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,27 @@
1
+ require 'tcell_agent/policies/policy'
2
+
3
+ module TCellAgent
4
+ module Policies
5
+ class PatchesPolicy < Policy
6
+ def self.api_identifier
7
+ 'patches'
8
+ end
9
+
10
+ attr_accessor :enabled
11
+
12
+ def initialize(native_agent, enablements)
13
+ @native_agent = native_agent
14
+ @enabled = enablements['patches'] || false
15
+ end
16
+
17
+ def block_request?(appsensor_meta)
18
+ return false unless @enabled
19
+
20
+ response = @native_agent.apply_patches(
21
+ appsensor_meta
22
+ )
23
+ !response['apply_response'].nil? && response['apply_response']['status'] == 'Blocked'
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,68 @@
1
+ # See the file "LICENSE" for the full license governing this code.
2
+
3
+ require 'tcell_agent/policies/policy_types'
4
+
5
+ require 'tcell_agent/policies/appfirewall_policy'
6
+ require 'tcell_agent/policies/command_injection_policy'
7
+ require 'tcell_agent/policies/dataloss_policy'
8
+ require 'tcell_agent/policies/headers_policy'
9
+ require 'tcell_agent/policies/http_redirect_policy'
10
+ require 'tcell_agent/policies/js_agent_policy'
11
+ require 'tcell_agent/policies/login_policy'
12
+ require 'tcell_agent/policies/patches_policy'
13
+ require 'tcell_agent/policies/local_file_access'
14
+ require 'tcell_agent/policies/system_enablements'
15
+
16
+ RUST_POLICY_CLASSES = [
17
+ TCellAgent::Policies::AppfirewallPolicy,
18
+ TCellAgent::Policies::CommandInjectionPolicy,
19
+ TCellAgent::Policies::HeadersPolicy,
20
+ TCellAgent::Policies::HttpRedirectPolicy,
21
+ TCellAgent::Policies::JsAgentPolicy,
22
+ TCellAgent::Policies::LoginPolicy,
23
+ TCellAgent::Policies::PatchesPolicy,
24
+ TCellAgent::Policies::LocalFileInclusion,
25
+ TCellAgent::Policies::SystemEnablements
26
+ ].freeze
27
+
28
+ module TCellAgent
29
+ class PoliciesManager
30
+ attr_accessor :policies
31
+
32
+ def initialize(native_agent)
33
+ @native_agent = native_agent
34
+ @policies = {}
35
+
36
+ enablements = {}
37
+ RUST_POLICY_CLASSES.each do |policy_class|
38
+ @policies[policy_class.api_identifier] = policy_class.new(
39
+ @native_agent, enablements
40
+ )
41
+ end
42
+
43
+ set_dataloss_policy({ 'dlp' => {} })
44
+ end
45
+
46
+ def set_dataloss_policy(policies_json)
47
+ TCellAgent::Instrumentation.safe_block('Setting DLP policy') do
48
+ dlp_api_identifier = TCellAgent::Policies::DataLossPolicy.api_identifier
49
+ return unless policies_json.key?(dlp_api_identifier)
50
+ @policies[dlp_api_identifier] = TCellAgent::Policies::DataLossPolicy.new(
51
+ policies_json[dlp_api_identifier]
52
+ )
53
+ end
54
+ end
55
+
56
+ def process_policy_json(enablements, policies_json)
57
+ return if enablements.nil? || enablements == {}
58
+
59
+ RUST_POLICY_CLASSES.each do |policy_class|
60
+ @policies[policy_class.api_identifier] = policy_class.new(
61
+ @native_agent, enablements
62
+ )
63
+ end
64
+
65
+ set_dataloss_policy(policies_json)
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,58 @@
1
+ module TCellAgent
2
+ class PolicyPolling
3
+ include TCellAgent::ModuleLoggerAccess
4
+
5
+ def initialize(policies_manager, native_agent)
6
+ @policies_manager = policies_manager
7
+ @policy_polling_worker_mutex = Mutex.new
8
+ @policy_polling_thread = nil
9
+
10
+ start_policy_polling(native_agent)
11
+ end
12
+
13
+ def start_policy_polling(native_agent)
14
+ configuration = TCellAgent.configuration
15
+ return unless configuration.should_start_policy_poll?
16
+ return unless configuration.tcell_api_url &&
17
+ configuration.app_id &&
18
+ configuration.api_key
19
+ return if policy_polling_running?
20
+
21
+ @policy_polling_worker_mutex.synchronize do
22
+ return if policy_polling_running?
23
+ start_policy_polling_loop(native_agent)
24
+ end
25
+ end
26
+
27
+ def policy_polling_running?
28
+ @policy_polling_thread && @policy_polling_thread.alive?
29
+ end
30
+
31
+ def stop_policy_polling
32
+ module_logger.debug('Stopping policy polling thread')
33
+ @policy_polling_thread.exit if policy_polling_running?
34
+ end
35
+
36
+ def start_policy_polling_loop(native_agent)
37
+ module_logger.debug('Starting policy polling thread')
38
+ @policy_polling_thread = Thread.new do
39
+ loop do
40
+ begin
41
+ result = native_agent.poll_new_policies
42
+ policies_and_enablements = result['new_policies_and_enablements'] || {}
43
+ @policies_manager.process_policy_json(
44
+ policies_and_enablements['enablements'],
45
+ policies_and_enablements['policies']
46
+ )
47
+ rescue StandardError => standard_error
48
+ module_logger.error("Error in polling policies: #{standard_error.message}")
49
+ module_logger.exception(standard_error)
50
+ end
51
+
52
+ # TODO(ralba): this might need to be changed to see how it affects performance
53
+ sleep 0.1
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,14 @@
1
+ module TCellAgent
2
+ class PolicyTypes
3
+ HTTPREDIRECT = 'http-redirect'.freeze
4
+ LOGINFRAUD = 'login'.freeze
5
+ DATALOSS = 'dlp'.freeze
6
+ APPSENSOR = 'appsensor'.freeze
7
+ PATCHES = 'patches'.freeze
8
+ COMMANDINJECTION = 'cmdi'.freeze
9
+ JSAGENTINJECTION = 'jsagentinjection'.freeze
10
+ HEADERS = 'headers'.freeze
11
+ LFI = 'lfi'.freeze
12
+ SYSTEM_ENABLEMENTS = 'systemEnablement'.freeze
13
+ end
14
+ end
@@ -0,0 +1,27 @@
1
+ require 'tcell_agent/policies/policy'
2
+
3
+ module TCellAgent
4
+ module Policies
5
+ class SystemEnablements < Policy
6
+ def self.api_identifier
7
+ 'systemEnablement'
8
+ end
9
+
10
+ attr_accessor :send_routes_enabled,
11
+ :send_lfi_path_discovery
12
+
13
+ def initialize(native_agent, enablements)
14
+ @native_agent = native_agent
15
+ @send_routes_enabled = true
16
+ update_enablements(enablements)
17
+ end
18
+
19
+ def update_enablements(enablements)
20
+ enablements ||= {}
21
+
22
+ @send_routes_enabled = enablements['system_send_routes'] || true
23
+ @send_lfi_path_discovery = enablements['send_lfi_path_discovery'] || true
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,81 +1,52 @@
1
- if TCellAgent.configuration.should_instrument_authlogic?
2
-
3
- require 'tcell_agent/logger'
4
- require 'tcell_agent/configuration'
5
- require 'tcell_agent/instrumentation'
6
-
7
- module TCellAgent
8
- if defined?(Authlogic)
9
-
10
- TCellAgent.logger.debug('Instrumenting Authlogic')
11
-
12
- require 'tcell_agent/agent'
13
- require 'tcell_agent/sensor_events/login_fraud'
14
-
15
- Authlogic::Session::Base.class_eval do
16
- alias_method :tcell_save, :save
17
- def save(&block)
18
- if TCellAgent.configuration.enabled &&
19
- TCellAgent.configuration.should_intercept_requests?
20
-
21
- user_logged_in_before = !user.nil?
22
- success = tcell_save(&block)
23
- user_logged_in_after = !user.nil?
24
-
25
- TCellAgent::Instrumentation.safe_block('Authlogic login info') do
26
- login_fraud_policy = TCellAgent.policy(TCellAgent::PolicyTypes::LOGINFRAUD)
27
- if login_fraud_policy && login_fraud_policy.enabled
28
- user_id = nil
29
- TCellAgent::Instrumentation.safe_block('getting userid for login form') do
30
- user_id = send(self.class.login_field.to_sym)
31
- end
32
-
33
- password = nil
34
-
35
- if user_logged_in_before && user_logged_in_after
36
- # password changed or logged in as another user
37
-
38
- elsif !user_logged_in_before && !user_logged_in_after
39
- if login_fraud_policy.login_failed_enabled
40
- request = Authlogic::Session::Base.controller.request
41
- tcell_data = request.env[TCellAgent::Instrumentation::TCELL_ID]
42
- if tcell_data
43
- event = TCellAgent::SensorEvents::LoginFailure.new(
44
- request.env,
45
- tcell_data,
46
- user_id,
47
- password
48
- )
49
- TCellAgent.send_event(event)
50
- end
51
- end
52
-
53
- elsif !user_logged_in_before && user_logged_in_after
54
- if login_fraud_policy.login_success_enabled
55
- request = Authlogic::Session::Base.controller.request
56
- tcell_data = request.env[TCellAgent::Instrumentation::TCELL_ID]
57
- if tcell_data
58
- event = TCellAgent::SensorEvents::LoginSuccess.new(
59
- request.env,
60
- tcell_data,
61
- user_id,
62
- password
63
- )
64
- TCellAgent.send_event(event)
65
- end
66
- end
67
- end
68
- end
69
- end
70
-
71
- success
1
+ require 'tcell_agent/configuration'
2
+ require 'tcell_agent/instrumentation'
3
+
4
+ module TCellAgent
5
+ require 'tcell_agent/agent'
6
+
7
+ Authlogic::Session::Base.class_eval do
8
+ alias_method :tcell_save, :save
9
+ def save(&block)
10
+ return tcell_save(&block) unless TCellAgent.configuration.should_intercept_requests?
11
+
12
+ user_logged_in_before = !user.nil?
13
+ success = tcell_save(&block)
14
+ user_logged_in_after = !user.nil?
15
+
16
+ TCellAgent::Instrumentation.safe_block('Authlogic login info') do
17
+ user_id = nil
18
+ password = nil
19
+ user_valid = nil
20
+ TCellAgent::Instrumentation.safe_block('getting userid for login form') do
21
+ user_id = send(self.class.login_field.to_sym)
22
+ end
72
23
 
73
- else
74
- tcell_save(&block)
75
- end
24
+ request = Authlogic::Session::Base.controller.request
25
+ tcell_data = request.env[TCellAgent::Instrumentation::TCELL_ID]
26
+
27
+ return success unless tcell_data
28
+
29
+ login_policy = TCellAgent.policy(TCellAgent::PolicyTypes::LOGINFRAUD)
30
+ if user_logged_in_before && user_logged_in_after
31
+ # password changed or logged in as another user
32
+ elsif !user_logged_in_before && !user_logged_in_after
33
+ login_policy.report_login_failure(
34
+ user_id,
35
+ password,
36
+ request.env,
37
+ user_valid,
38
+ tcell_data
39
+ )
40
+ elsif !user_logged_in_before && user_logged_in_after
41
+ login_policy.report_login_success(
42
+ user_id,
43
+ request.env,
44
+ tcell_data
45
+ )
76
46
  end
77
47
  end
48
+
49
+ success
78
50
  end
79
51
  end
80
-
81
52
  end