tcell_agent 1.1.12 → 2.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.
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
@@ -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,79 +1,54 @@
1
- if TCellAgent.configuration.should_instrument_authlogic?
1
+ if TCellAgent.configuration.should_instrument_authlogic? && defined?(Authlogic)
2
2
 
3
- require 'tcell_agent/logger'
4
3
  require 'tcell_agent/configuration'
5
4
  require 'tcell_agent/instrumentation'
6
5
 
7
6
  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
7
+ require 'tcell_agent/agent'
8
+
9
+ Authlogic::Session::Base.class_eval do
10
+ alias_method :tcell_save, :save
11
+ def save(&block)
12
+ return tcell_save(&block) unless TCellAgent.configuration.should_intercept_requests?
13
+
14
+ user_logged_in_before = !user.nil?
15
+ success = tcell_save(&block)
16
+ user_logged_in_after = !user.nil?
17
+
18
+ TCellAgent::Instrumentation.safe_block('Authlogic login info') do
19
+ user_id = nil
20
+ password = nil
21
+ user_valid = nil
22
+ TCellAgent::Instrumentation.safe_block('getting userid for login form') do
23
+ user_id = send(self.class.login_field.to_sym)
24
+ end
72
25
 
73
- else
74
- tcell_save(&block)
26
+ request = Authlogic::Session::Base.controller.request
27
+ tcell_data = request.env[TCellAgent::Instrumentation::TCELL_ID]
28
+
29
+ return success unless tcell_data
30
+
31
+ login_policy = TCellAgent.policy(TCellAgent::PolicyTypes::LOGINFRAUD)
32
+ if user_logged_in_before && user_logged_in_after
33
+ # password changed or logged in as another user
34
+ elsif !user_logged_in_before && !user_logged_in_after
35
+ login_policy.report_login_failure(
36
+ user_id,
37
+ password,
38
+ request.env,
39
+ user_valid,
40
+ tcell_data
41
+ )
42
+ elsif !user_logged_in_before && user_logged_in_after
43
+ login_policy.report_login_success(
44
+ user_id,
45
+ request.env,
46
+ tcell_data
47
+ )
75
48
  end
76
49
  end
50
+
51
+ success
77
52
  end
78
53
  end
79
54
  end