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,52 +0,0 @@
1
- require 'tcell_agent/sensor_events/sensor'
2
-
3
- module TCellAgent
4
- module SensorEvents
5
- class TCellAppSensorEvent < TCellSensorEvent
6
- def initialize(location,
7
- detection_point,
8
- method,
9
- remote_address,
10
- param,
11
- route_id,
12
- meta,
13
- hmac_session_id,
14
- user_id,
15
- payload,
16
- pattern,
17
- full_uri)
18
- super('as')
19
- self['dp'] = detection_point
20
-
21
- self['param'] = param.to_s if param
22
- self['m'] = method.to_s if method
23
- self['pattern'] = pattern if pattern
24
- self['meta'] = meta if meta
25
- self['rid'] = route_id.to_s if route_id
26
- self['full_uri'] = full_uri if full_uri
27
- self['uri'] = location if location
28
- self['uid'] = user_id.to_s if user_id
29
- self['sid'] = hmac_session_id if hmac_session_id
30
- self['remote_addr'] = remote_address.to_s if remote_address
31
- self['payload'] = payload if payload
32
- end
33
-
34
- def self.build_from_native_lib_event(event)
35
- TCellAppSensorEvent.new(
36
- event['uri'],
37
- event['detection_point'],
38
- event['method'],
39
- event['remote_address'],
40
- event['parameter'],
41
- event['route_id'],
42
- event['meta'],
43
- event['session_id'],
44
- event['user_id'],
45
- event['payload'],
46
- event['pattern'],
47
- event['full_uri']
48
- )
49
- end
50
- end
51
- end
52
- end
@@ -1,45 +0,0 @@
1
- require 'tcell_agent/agent'
2
- require 'tcell_agent/agent/policy_types'
3
- require 'tcell_agent/tcell_context'
4
- require 'tcell_agent/sensor_events/sensor'
5
-
6
- module TCellAgent
7
- module SensorEvents
8
- class AppSensorMetaEvent < TCellAgent::SensorEvents::TCellSensorEvent
9
- class << self
10
- def build(request, response_content_length, response_code, response_headers)
11
- meta_data = TCellAgent::MetaData.from_request(request)
12
-
13
- tcell_context = request.env[TCellAgent::Instrumentation::TCELL_ID]
14
- meta_data.csrf_exception_name = tcell_context.csrf_exception_name
15
- meta_data.user_agent = tcell_context.user_agent
16
- meta_data.path_parameters = tcell_context.path_parameters
17
- meta_data.sql_exceptions = tcell_context.sql_exceptions
18
- meta_data.database_result_sizes = tcell_context.database_result_sizes
19
-
20
- meta_data.response_content_bytes_len = response_content_length
21
-
22
- meta_data.response_code = response_code
23
- meta_data.response_headers = response_headers
24
-
25
- AppSensorMetaEvent.new(meta_data)
26
- end
27
- end
28
-
29
- attr_accessor :meta_data
30
-
31
- def initialize(meta_data)
32
- @send = false
33
-
34
- @meta_data = meta_data
35
- end
36
-
37
- def post_process
38
- rust_policies = TCellAgent.policy(TCellAgent::PolicyTypes::RUST)
39
- return unless rust_policies
40
-
41
- rust_policies.check_appfirewall_injections(@meta_data)
42
- end
43
- end
44
- end
45
- end
@@ -1,75 +0,0 @@
1
- require 'tcell_agent/sensor_events/sensor'
2
-
3
- module TCellAgent
4
- module SensorEvents
5
- class CommandInjectionMatchEvent < Hash
6
- def initialize(rule_id, command)
7
- self['rule_id'] = rule_id
8
- self['command'] = command if command
9
- end
10
- end
11
-
12
- class CommandInjectionEvent < TCellSensorEvent
13
- def self.build_from_native_lib_response_and_tcell_context(apply_response,
14
- tcell_context)
15
- matches = apply_response.fetch('matches', [])
16
-
17
- return nil if !matches || matches.empty?
18
-
19
- method, remote_address, route_id, session_id, user_id, uri = nil
20
- if tcell_context
21
- method = tcell_context.request_method
22
- remote_address = tcell_context.ip_address
23
- route_id = tcell_context.route_id
24
- session_id = tcell_context.hmac_session_id
25
- user_id = tcell_context.user_id
26
- uri = tcell_context.uri
27
- end
28
-
29
- matches_without_emtpy_values = matches.map do |match|
30
- CommandInjectionMatchEvent.new(
31
- match['rule_id'], match['command']
32
- )
33
- end
34
-
35
- CommandInjectionEvent.new(
36
- apply_response['commands'],
37
- apply_response.fetch('blocked', false),
38
- matches_without_emtpy_values,
39
- method,
40
- remote_address,
41
- route_id,
42
- session_id,
43
- user_id,
44
- uri,
45
- apply_response['full_commandline']
46
- )
47
- end
48
-
49
- def initialize(commands,
50
- blocked,
51
- matches,
52
- method = nil,
53
- remote_address = nil,
54
- route_id = nil,
55
- session_id = nil,
56
- user_id = nil,
57
- uri = nil,
58
- full_commandline = nil)
59
- super('cmdi')
60
-
61
- self['commands'] = commands
62
- self['blocked'] = blocked
63
- self['matches'] = matches
64
- self['m'] = method if method
65
-
66
- self['remote_addr'] = remote_address if remote_address
67
- self['rid'] = route_id if route_id
68
- self['sid'] = session_id if session_id
69
- self['uid'] = user_id if user_id
70
- self['full_commandline'] = full_commandline if full_commandline
71
- self['uri'] = TCellAgent::SensorEvents::Util.strip_uri_values(uri) if uri
72
- end
73
- end
74
- end
75
- end
@@ -1,16 +0,0 @@
1
- # See the file "LICENSE" for the full license governing this code.
2
-
3
- require 'tcell_agent/sensor_events/util/sanitizer_utilities'
4
- require 'tcell_agent/sensor_events/sensor'
5
-
6
- module TCellAgent
7
- module SensorEvents
8
- class HoneytokensSensorEvent < TCellSensorEvent
9
- def initialize(request, token_id)
10
- super('honeytoken')
11
- self['id'] = token_id
12
- self['ip'] = request.remote_ip
13
- end
14
- end
15
- end
16
- end
@@ -1,60 +0,0 @@
1
- # See the file "LICENSE" for the full license governing this code.
2
-
3
- require 'tcell_agent/sensor_events/util/sanitizer_utilities'
4
- require 'tcell_agent/sensor_events/sensor'
5
-
6
- module TCellAgent
7
- module SensorEvents
8
- class LoginEvent < TCellSensorEvent
9
- def initialize(header_keys,
10
- tcell_data,
11
- user_id,
12
- password,
13
- user_valid)
14
- super('login')
15
-
16
- self['header_keys'] = header_keys
17
-
18
- self['user_agent'] = tcell_data.user_agent.to_s if tcell_data.user_agent
19
- self['referrer'] = TCellAgent::SensorEvents::Util.strip_uri_values(tcell_data.referrer) if tcell_data.referrer
20
- self['remote_addr'] = tcell_data.ip_address.to_s if tcell_data.ip_address
21
- self['user_id'] = user_id.to_s if user_id
22
- self['document_uri'] = TCellAgent::SensorEvents::Util.strip_uri_values(tcell_data.path) if tcell_data.path
23
- self['session'] = tcell_data.hmac_session_id if tcell_data.hmac_session_id
24
-
25
- digest = TCellAgent::Utils::Passwords.fingerprint_password(password,
26
- user_id)
27
- self['password_id'] = digest if digest
28
- self['user_valid'] = user_valid if user_valid
29
- end
30
- end
31
-
32
- class LoginFailure < LoginEvent
33
- def initialize(request_env_or_header_keys,
34
- tcell_data,
35
- user_id,
36
- password,
37
- user_valid = nil)
38
- header_keys = Util.clean_header_keys(request_env_or_header_keys)
39
-
40
- super(header_keys, tcell_data, user_id, password, user_valid)
41
-
42
- self['event_name'] = 'login-failure'
43
- end
44
- end
45
-
46
- class LoginSuccess < LoginEvent
47
- def initialize(request_env_or_header_keys,
48
- tcell_data,
49
- user_id,
50
- password,
51
- user_valid = nil)
52
- header_keys = Util.clean_header_keys(request_env_or_header_keys)
53
-
54
- super(header_keys, tcell_data, user_id, password, user_valid)
55
-
56
- self['event_name'] = 'login-success'
57
- end
58
- end
59
- end
60
- end
@@ -1,123 +0,0 @@
1
- # See the file "LICENSE" for the full license governing this code.
2
-
3
- module TCellAgent
4
- module SensorEvents
5
- class Counter
6
- attr_reader :counter
7
- def initialize
8
- @counter = 0
9
- end
10
-
11
- def add_object
12
- @counter += 1
13
- end
14
-
15
- def reset
16
- @counter = 0
17
- end
18
- end
19
-
20
- class RequestRouteTimer < TCellSensorEvent
21
- attr_accessor :route_id
22
- attr_accessor :response_time
23
- def initialize(route_id, response_time)
24
- super('RequestRouteTimer')
25
- self.route_id = route_id
26
- self.response_time = response_time
27
- @send = false
28
- end
29
- end
30
-
31
- class MetricsEvent < TCellSensorEvent
32
- def initialize
33
- super('metrics')
34
- end
35
-
36
- def set_route_count_table(route_count_table)
37
- self['rct'] = route_count_table
38
- end
39
- end
40
-
41
- class SessionsMetric < TCellSensorEvent
42
- class UserSessionTrackMetric < Hash
43
- def initialize(object_counter, user_id)
44
- @object_counter = object_counter
45
- @user_agents = {}
46
- self['uid'] = user_id
47
- self['track'] = []
48
- end
49
-
50
- def add_user_agent_ip(truncated_agent, ip_address)
51
- if @user_agents.key?(truncated_agent)
52
- tracked_agents = @user_agents[truncated_agent]
53
- ips = tracked_agents[1]
54
- unless ips.include?(ip_address)
55
- @object_counter.add_object
56
- ips.push(ip_address)
57
- end
58
- else
59
- @object_counter.add_object
60
- @user_agents[truncated_agent] = [truncated_agent, [ip_address]]
61
- self['track'].push(@user_agents[truncated_agent])
62
- end
63
- end
64
- end
65
-
66
- class UserSessionMetric < Array
67
- def initialize(object_counter)
68
- @user_ids = {}
69
- @object_counter = object_counter
70
- end
71
-
72
- def add_user_id_user_agent_ip(user_id, truncated_agent, ip_address)
73
- if @user_ids.key?(user_id)
74
- user_id_info = @user_ids[user_id]
75
- user_id_info.add_user_agent_ip(truncated_agent, ip_address)
76
- else
77
- @object_counter.add_object
78
-
79
- @user_ids[user_id] = user_id_info = UserSessionTrackMetric.new(@object_counter, user_id)
80
- user_id_info.add_user_agent_ip(truncated_agent, ip_address)
81
-
82
- push(user_id_info)
83
- end
84
- end
85
- end
86
-
87
- def initialize
88
- super('metrics')
89
- @send = false
90
- @flush = false
91
-
92
- self['sessions'] = {}
93
- @has_sessions = false
94
- @object_counter = Counter.new
95
- end
96
-
97
- def sessions?
98
- @has_sessions
99
- end
100
-
101
- def add_session_info(hmac_session_id, user_id, ip_address, user_agent)
102
- if @object_counter.counter >= 250
103
- TCellAgent.logger.warn('Sessions Metric is full. Information dropped')
104
-
105
- else
106
- self['sessions'][hmac_session_id] =
107
- self['sessions'].fetch(hmac_session_id, UserSessionMetric.new(@object_counter))
108
-
109
- @has_sessions = true
110
-
111
- truncated_agent = truncated_user_agent(user_agent)
112
- self['sessions'][hmac_session_id].add_user_id_user_agent_ip(user_id, truncated_agent, ip_address)
113
-
114
- @flush = true if @object_counter.counter >= 200
115
- end
116
- end
117
-
118
- def truncated_user_agent(user_agent)
119
- user_agent[0...256]
120
- end
121
- end
122
- end
123
- end
@@ -1,21 +0,0 @@
1
- require 'tcell_agent/sensor_events/sensor'
2
-
3
- module TCellAgent
4
- module SensorEvents
5
- class PatchesEvent < TCellSensorEvent
6
- def initialize(rust_response, appsensor_meta)
7
- super('patches')
8
-
9
- self['patches_pid'] = rust_response['patches_policy_id']
10
- self['rule_id'] = rust_response['rule_id']
11
- self['action'] = 'blocked'
12
- self['sz'] = appsensor_meta.request_content_bytes_len if appsensor_meta.request_content_bytes_len
13
- self['m'] = appsensor_meta.method if appsensor_meta.method
14
- self['remote_addr'] = appsensor_meta.remote_address if appsensor_meta.remote_address
15
- self['uri'] = TCellAgent::SensorEvents::Util.strip_uri_values(appsensor_meta.location) if appsensor_meta.location
16
- self['regex_pid'] = rust_response['regex_pid'] if rust_response['regex_pid']
17
- self['payload'] = rust_response['payload'] if rust_response['payload']
18
- end
19
- end
20
- end
21
- end
@@ -1,55 +0,0 @@
1
- # See the file "LICENSE" for the full license governing this code.
2
- require 'tcell_agent/configuration'
3
-
4
- unless TCellAgent.configuration.disable_all
5
- require 'tcell_agent/logger'
6
- require 'tcell_agent/agent'
7
- require 'thread'
8
-
9
- module TCellAgent
10
- # require 'tcell_agent/sinatra' if defined?(Sinatra)
11
- require 'tcell_agent/rails' if defined?(Rails)
12
- require 'tcell_agent/instrumentation/cmdi'
13
-
14
- def self.run_instrumentation(server_name, send_startup_events = true)
15
- require 'tcell_agent/hooks/login_fraud'
16
- require 'tcell_agent/rails/on_start' if defined?(Rails)
17
- require 'tcell_agent/settings_reporter'
18
-
19
- TCellAgent::Instrumentation.safe_block('Starting thread agent') do
20
- TCellAgent.logger.debug("Instrumenting: #{server_name}")
21
- TCellAgent.thread_agent.start
22
- end
23
-
24
- report_settings(send_startup_events)
25
- end
26
- end
27
-
28
- tcell_server = ENV['TCELL_AGENT_SERVER']
29
-
30
- if TCellAgent.configuration.should_instrument?
31
- unless tcell_server && tcell_server == 'mock'
32
-
33
- if (tcell_server && tcell_server == 'webrick') || defined?(Rails::Server)
34
- require('tcell_agent/servers/rails_server')
35
-
36
- elsif (tcell_server && tcell_server == 'thin') || defined?(Thin)
37
- require('tcell_agent/servers/thin')
38
-
39
- elsif (tcell_server && tcell_server == 'puma') || defined?(Puma)
40
- require('tcell_agent/servers/puma')
41
-
42
- elsif (tcell_server && tcell_server == 'unicorn') || defined?(Unicorn)
43
- require('tcell_agent/servers/unicorn')
44
-
45
- elsif (tcell_server && tcell_server == 'passenger') || defined?(PhusionPassenger)
46
- require('tcell_agent/servers/passenger')
47
-
48
- end
49
- end
50
-
51
- elsif (tcell_server && tcell_server == 'unicorn') || defined?(Unicorn)
52
- # unicorn is always instrumented to support rolling restarts
53
- require('tcell_agent/servers/unicorn')
54
- end
55
- end