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.
- checksums.yaml +5 -5
- data/bin/tcell_agent +26 -14
- data/lib/tcell_agent.rb +16 -10
- data/lib/tcell_agent/agent.rb +78 -97
- data/lib/tcell_agent/agent/route_manager.rb +0 -16
- data/lib/tcell_agent/agent/static_agent.rb +9 -30
- data/lib/tcell_agent/authlogic.rb +3 -6
- data/lib/tcell_agent/config/unknown_options.rb +4 -8
- data/lib/tcell_agent/configuration.rb +38 -119
- data/lib/tcell_agent/devise.rb +25 -27
- data/lib/tcell_agent/hooks/login_fraud.rb +30 -33
- data/lib/tcell_agent/instrument_servers.rb +25 -0
- data/lib/tcell_agent/instrumentation.rb +12 -10
- data/lib/tcell_agent/instrumentation/cmdi.rb +19 -15
- data/lib/tcell_agent/instrumentation/lfi.rb +73 -0
- data/lib/tcell_agent/instrumentation/monkey_patches/file.rb +25 -0
- data/lib/tcell_agent/instrumentation/monkey_patches/io.rb +123 -0
- data/lib/tcell_agent/instrumentation/monkey_patches/kernel.rb +159 -0
- data/lib/tcell_agent/logger.rb +50 -114
- data/lib/tcell_agent/patches.rb +6 -7
- data/lib/tcell_agent/policies/appfirewall_policy.rb +26 -0
- data/lib/tcell_agent/policies/command_injection_policy.rb +28 -0
- data/lib/tcell_agent/policies/dataloss_policy.rb +44 -44
- data/lib/tcell_agent/policies/headers_policy.rb +25 -0
- data/lib/tcell_agent/policies/http_redirect_policy.rb +13 -79
- data/lib/tcell_agent/policies/js_agent_policy.rb +27 -0
- data/lib/tcell_agent/policies/local_file_access.rb +28 -0
- data/lib/tcell_agent/policies/login_policy.rb +43 -0
- data/lib/tcell_agent/policies/patches_policy.rb +27 -0
- data/lib/tcell_agent/policies/policies_manager.rb +68 -0
- data/lib/tcell_agent/policies/policy_polling.rb +58 -0
- data/lib/tcell_agent/policies/policy_types.rb +14 -0
- data/lib/tcell_agent/policies/system_enablements.rb +27 -0
- data/lib/tcell_agent/rails/auth/authlogic.rb +43 -68
- data/lib/tcell_agent/rails/auth/devise.rb +20 -23
- data/lib/tcell_agent/rails/auth/doorkeeper.rb +63 -74
- data/lib/tcell_agent/rails/csrf_exception.rb +2 -2
- data/lib/tcell_agent/rails/dlp.rb +25 -15
- data/lib/tcell_agent/rails/dlp_handler.rb +1 -2
- data/lib/tcell_agent/rails/js_agent_insert.rb +12 -13
- data/lib/tcell_agent/rails/middleware/body_filter_middleware.rb +4 -25
- data/lib/tcell_agent/rails/middleware/context_middleware.rb +2 -12
- data/lib/tcell_agent/rails/middleware/global_middleware.rb +0 -1
- data/lib/tcell_agent/rails/middleware/headers_middleware.rb +14 -34
- data/lib/tcell_agent/rails/on_start.rb +32 -31
- data/lib/tcell_agent/rails/routes.rb +7 -6
- data/lib/tcell_agent/rails/routes/grape.rb +1 -3
- data/lib/tcell_agent/rails/routes/route_id.rb +3 -1
- data/lib/tcell_agent/rails/settings_reporter.rb +23 -36
- data/lib/tcell_agent/rails/start_agent_after_initializers.rb +12 -0
- data/lib/tcell_agent/rails/tcell_body_proxy.rb +6 -4
- data/lib/tcell_agent/rust/agent_config.rb +49 -0
- data/lib/tcell_agent/rust/{libtcellagent-alpine-1.3.2.so → libtcellagent-4.14.0.dylib} +0 -0
- data/lib/tcell_agent/rust/libtcellagent-4.14.0.so +0 -0
- data/lib/tcell_agent/rust/{libtcellagent-1.3.2.so → libtcellagent-alpine-4.14.0.so} +0 -0
- data/lib/tcell_agent/rust/models.rb +0 -55
- data/lib/tcell_agent/rust/native_agent.rb +531 -0
- data/lib/tcell_agent/rust/native_agent_response.rb +42 -0
- data/lib/tcell_agent/rust/native_library.rb +68 -0
- data/lib/tcell_agent/rust/tcellagent-4.14.0.dll +0 -0
- data/lib/tcell_agent/sensor_events/agent_setting_event.rb +12 -0
- data/lib/tcell_agent/sensor_events/{app_config.rb → app_config_setting_event.rb} +0 -6
- data/lib/tcell_agent/sensor_events/dlp.rb +2 -6
- data/lib/tcell_agent/sensor_events/sensor.rb +0 -62
- data/lib/tcell_agent/sensor_events/server_agent.rb +13 -18
- data/lib/tcell_agent/sensor_events/util/sanitizer_utilities.rb +0 -108
- data/lib/tcell_agent/sensor_events/util/utils.rb +0 -2
- data/lib/tcell_agent/servers/passenger.rb +1 -28
- data/lib/tcell_agent/servers/puma.rb +3 -21
- data/lib/tcell_agent/servers/rails_server.rb +1 -1
- data/lib/tcell_agent/servers/thin.rb +2 -2
- data/lib/tcell_agent/servers/unicorn.rb +19 -80
- data/lib/tcell_agent/servers/webrick.rb +1 -1
- data/lib/tcell_agent/settings_reporter.rb +24 -24
- data/lib/tcell_agent/sinatra.rb +14 -16
- data/lib/tcell_agent/tcell_context.rb +40 -14
- data/lib/tcell_agent/utils/headers.rb +14 -0
- data/lib/tcell_agent/version.rb +1 -1
- data/spec/lib/tcell_agent/cmdi_spec.rb +0 -585
- data/spec/lib/tcell_agent/config/unknown_options_spec.rb +0 -18
- data/spec/lib/tcell_agent/configuration_spec.rb +4 -140
- data/spec/lib/tcell_agent/hooks/login_fraud_spec.rb +46 -173
- data/spec/lib/tcell_agent/instrumentation/cmdi/io_cmdi_spec.rb +504 -0
- data/spec/lib/tcell_agent/instrumentation/cmdi/kernel_cmdi_spec.rb +435 -0
- data/spec/lib/tcell_agent/instrumentation/lfi/file_lfi_spec.rb +326 -0
- data/spec/lib/tcell_agent/instrumentation/lfi/io_lfi_spec.rb +556 -0
- data/spec/lib/tcell_agent/instrumentation/lfi/kernel_lfi_spec.rb +249 -0
- data/spec/lib/tcell_agent/instrumentation/lfi_spec.rb +105 -0
- data/spec/lib/tcell_agent/patches_spec.rb +25 -43
- data/spec/lib/tcell_agent/policies/appfirewall_policy_spec.rb +183 -0
- data/spec/lib/tcell_agent/policies/clickjacking_policy_spec.rb +57 -0
- data/spec/lib/tcell_agent/policies/command_injection_policy_spec.rb +84 -773
- data/spec/lib/tcell_agent/policies/content_security_policy_spec.rb +161 -0
- data/spec/lib/tcell_agent/policies/dataloss_policy_spec.rb +9 -9
- data/spec/lib/tcell_agent/policies/http_redirect_policy_spec.rb +243 -198
- data/spec/lib/tcell_agent/policies/js_agent_policy_spec.rb +75 -0
- data/spec/lib/tcell_agent/policies/login_policy_spec.rb +165 -33
- data/spec/lib/tcell_agent/policies/patches_policy_spec.rb +84 -277
- data/spec/lib/tcell_agent/policies/policies_manager_spec.rb +104 -0
- data/spec/lib/tcell_agent/policies/policy_polling_spec.rb +6 -0
- data/spec/lib/tcell_agent/policies/secure_headers_policy_spec.rb +56 -0
- data/spec/lib/tcell_agent/rails/csrf_exception_spec.rb +9 -18
- data/spec/lib/tcell_agent/rails/js_agent_insert_spec.rb +13 -30
- data/spec/lib/tcell_agent/rails/logger_spec.rb +27 -7
- data/spec/lib/tcell_agent/rails/middleware/tcell_body_proxy_spec.rb +17 -12
- data/spec/lib/tcell_agent/rails/routes/routes_spec.rb +14 -14
- data/spec/lib/tcell_agent/sensor_events/util/sanitizer_utilities_spec.rb +0 -35
- data/spec/lib/tcell_agent/settings_reporter_spec.rb +127 -153
- data/spec/spec_helper.rb +1 -1
- data/spec/support/builders.rb +104 -0
- data/spec/support/force_logger_mocking.rb +38 -0
- data/spec/support/resources/lfi_sample_file.txt +2 -0
- data/spec/support/static_agent_overrides.rb +0 -15
- metadata +63 -74
- data/lib/tcell_agent/agent/event_processor.rb +0 -326
- data/lib/tcell_agent/agent/fork_pipe_manager.rb +0 -113
- data/lib/tcell_agent/agent/policy_manager.rb +0 -219
- data/lib/tcell_agent/agent/policy_types.rb +0 -30
- data/lib/tcell_agent/api.rb +0 -91
- data/lib/tcell_agent/appsensor/injections_reporter.rb +0 -24
- data/lib/tcell_agent/config/child_process_events.rb +0 -8
- data/lib/tcell_agent/instrumentation/cmdi/backtick.rb +0 -10
- data/lib/tcell_agent/instrumentation/cmdi/exec.rb +0 -14
- data/lib/tcell_agent/instrumentation/cmdi/popen.rb +0 -28
- data/lib/tcell_agent/instrumentation/cmdi/spawn.rb +0 -11
- data/lib/tcell_agent/instrumentation/cmdi/system.rb +0 -11
- data/lib/tcell_agent/policies/http_tx_policy.rb +0 -60
- data/lib/tcell_agent/policies/login_fraud_policy.rb +0 -45
- data/lib/tcell_agent/policies/rust_policies.rb +0 -110
- data/lib/tcell_agent/rails.rb +0 -40
- data/lib/tcell_agent/rust/libtcellagent-1.3.2.dylib +0 -0
- data/lib/tcell_agent/rust/tcellagent-1.3.2.dll +0 -0
- data/lib/tcell_agent/rust/whisperer.rb +0 -308
- data/lib/tcell_agent/sensor_events/appsensor_event.rb +0 -52
- data/lib/tcell_agent/sensor_events/appsensor_meta_event.rb +0 -45
- data/lib/tcell_agent/sensor_events/command_injection.rb +0 -75
- data/lib/tcell_agent/sensor_events/honeytokens.rb +0 -16
- data/lib/tcell_agent/sensor_events/login_fraud.rb +0 -60
- data/lib/tcell_agent/sensor_events/metrics.rb +0 -123
- data/lib/tcell_agent/sensor_events/patches.rb +0 -21
- data/lib/tcell_agent/start_background_thread.rb +0 -55
- data/lib/tcell_agent/system_info.rb +0 -11
- data/lib/tcell_agent/utils/io.rb +0 -38
- data/lib/tcell_agent/utils/passwords.rb +0 -28
- data/lib/tcell_agent/utils/queue_with_timeout.rb +0 -142
- data/spec/lib/tcell_agent/agent/fork_pipe_manager_spec.rb +0 -100
- data/spec/lib/tcell_agent/agent/policy_manager_spec.rb +0 -535
- data/spec/lib/tcell_agent/agent/static_agent_spec.rb +0 -133
- data/spec/lib/tcell_agent/api/api_spec.rb +0 -39
- data/spec/lib/tcell_agent/appsensor/injections_reporter_spec.rb +0 -187
- data/spec/lib/tcell_agent/instrumentation_spec.rb +0 -225
- data/spec/lib/tcell_agent/policies/appsensor_policy_spec.rb +0 -517
- data/spec/lib/tcell_agent/policies/http_tx_policy_spec.rb +0 -22
- data/spec/lib/tcell_agent/rails/middleware/appsensor_middleware_spec.rb +0 -293
- data/spec/lib/tcell_agent/rails/middleware/dlp_middleware_spec.rb +0 -198
- data/spec/lib/tcell_agent/rails/middleware/global_middleware_spec.rb +0 -180
- data/spec/lib/tcell_agent/rails/middleware/redirect_middleware_spec.rb +0 -116
- data/spec/lib/tcell_agent/rust/models_spec.rb +0 -120
- data/spec/lib/tcell_agent/rust/whisperer_spec.rb +0 -704
- data/spec/lib/tcell_agent/sensor_events/appsensor_meta_event_spec.rb +0 -45
- data/spec/lib/tcell_agent/sensor_events/sessions_metric_spec.rb +0 -272
- data/spec/lib/tcell_agent/utils/bounded_queue_spec.rb +0 -52
- data/spec/lib/tcell_agent/utils/passwords_spec.rb +0 -143
@@ -0,0 +1,42 @@
|
|
1
|
+
module TCellAgent
|
2
|
+
module Rust
|
3
|
+
class NativeAgentResponse
|
4
|
+
attr_reader :errors, :response
|
5
|
+
|
6
|
+
def initialize(native_method_name, response, response_len)
|
7
|
+
@response = {}
|
8
|
+
@errors = []
|
9
|
+
|
10
|
+
if response_len < 0
|
11
|
+
@errors.push(
|
12
|
+
"Error response from `#{native_method_name}` in native library method: #{response_len}"
|
13
|
+
)
|
14
|
+
return
|
15
|
+
end
|
16
|
+
|
17
|
+
begin
|
18
|
+
@response = JSON.parse(response.get_string(0, response_len))
|
19
|
+
if @response['error']
|
20
|
+
@errors.push(
|
21
|
+
"#{native_method_name} returned an error: #{@response['error']}"
|
22
|
+
)
|
23
|
+
@response = {}
|
24
|
+
end
|
25
|
+
if @response['errors']
|
26
|
+
@response['errors'].each do |error|
|
27
|
+
@errors.push(
|
28
|
+
"#{native_method_name} returned an error: #{error}"
|
29
|
+
)
|
30
|
+
@response = {}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
rescue JSON::ParserError
|
34
|
+
@errors.push(
|
35
|
+
"Could not parse json response from `#{native_method_name}` in native library."
|
36
|
+
)
|
37
|
+
@response = {}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'tcell_agent/rust/models'
|
2
|
+
|
3
|
+
module TCellAgent
|
4
|
+
module Rust
|
5
|
+
module NativeLibrary
|
6
|
+
require 'ffi'
|
7
|
+
extend FFI::Library
|
8
|
+
|
9
|
+
VERSION = '4.14.0'.freeze
|
10
|
+
prefix = 'lib'
|
11
|
+
extension = '.so'
|
12
|
+
variant = ''
|
13
|
+
if /cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM
|
14
|
+
extension = '.dll'
|
15
|
+
prefix = ''
|
16
|
+
elsif /darwin/ =~ RUBY_PLATFORM
|
17
|
+
extension = '.dylib'
|
18
|
+
elsif /musl/ =~ RUBY_PLATFORM
|
19
|
+
variant = 'alpine-'
|
20
|
+
end
|
21
|
+
|
22
|
+
begin
|
23
|
+
ffi_lib File.join(File.dirname(__FILE__),
|
24
|
+
"#{prefix}tcellagent-#{variant}#{VERSION}#{extension}")
|
25
|
+
|
26
|
+
# All the rust library calls have the following response api:
|
27
|
+
#
|
28
|
+
# result [int]: 0+ length of buffer_out answer
|
29
|
+
# -1 general error
|
30
|
+
# -2 buffer_out is not big enough for response
|
31
|
+
# -3 buffer_out is null
|
32
|
+
|
33
|
+
attach_function :create_agent, %i[pointer size_t pointer size_t], :int
|
34
|
+
attach_function :free_agent, [:pointer], :int
|
35
|
+
attach_function :request_policies, %i[pointer pointer size_t], :int
|
36
|
+
attach_function :poll_new_policies, %i[pointer pointer size_t], :int
|
37
|
+
attach_function :appfirewall_apply, %i[pointer pointer size_t pointer size_t], :int
|
38
|
+
attach_function :patches_apply, %i[pointer pointer size_t pointer size_t], :int
|
39
|
+
attach_function :cmdi_apply, %i[pointer pointer size_t pointer size_t], :int
|
40
|
+
attach_function :get_headers, %i[pointer pointer size_t pointer size_t], :int
|
41
|
+
attach_function :get_js_agent_script_tag, %i[pointer pointer size_t pointer size_t], :int
|
42
|
+
attach_function :check_http_redirect, %i[pointer pointer size_t pointer size_t], :int
|
43
|
+
attach_function :report_metrics, %i[pointer pointer size_t pointer size_t], :int
|
44
|
+
attach_function :login_fraud_apply, %i[pointer pointer size_t pointer size_t], :int
|
45
|
+
attach_function :file_access_apply, %i[pointer pointer size_t pointer size_t], :int
|
46
|
+
|
47
|
+
attach_function :send_sanitized_events, %i[pointer pointer size_t pointer size_t], :int
|
48
|
+
attach_function :log_message, %i[pointer pointer size_t pointer size_t], :int
|
49
|
+
|
50
|
+
attach_function :update_policies, %i[pointer pointer size_t pointer size_t], :int
|
51
|
+
attach_function :test_event_sender, %i[pointer size_t pointer size_t], :int
|
52
|
+
attach_function :test_policies, %i[pointer size_t pointer size_t], :int
|
53
|
+
|
54
|
+
def self.common_lib_available?
|
55
|
+
true
|
56
|
+
end
|
57
|
+
rescue LoadError => load_error
|
58
|
+
logger = TCellAgent::ModuleLogger.new(TCellAgent::RubyLogger.new, name)
|
59
|
+
logger.error("Failed loading agent library. #{load_error.message}")
|
60
|
+
logger.exception(load_error)
|
61
|
+
|
62
|
+
def self.common_lib_available? # rubocop:disable Lint/DuplicateMethods
|
63
|
+
false
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
Binary file
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'tcell_agent/sensor_events/app_config_setting_event'
|
2
|
+
require 'tcell_agent/sensor_events/sensor'
|
3
|
+
|
4
|
+
module TCellAgent
|
5
|
+
module SensorEvents
|
6
|
+
class AgentSettingEvent < AppConfigSettingEvent
|
7
|
+
def initialize(name, value)
|
8
|
+
super('tcell', 'config', nil, name, value)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'tcell_agent/sensor_events/util/sanitizer_utilities'
|
4
4
|
require 'tcell_agent/sensor_events/sensor'
|
5
|
-
|
5
|
+
|
6
6
|
module TCellAgent
|
7
7
|
module SensorEvents
|
8
8
|
class DlpEvent < TCellSensorEvent
|
@@ -20,7 +20,7 @@ module TCellAgent
|
|
20
20
|
super('dlp')
|
21
21
|
self['rid'] = route_id if route_id
|
22
22
|
self['found_in'] = found_in
|
23
|
-
|
23
|
+
self['uri'] = Util.strip_uri_values(raw_uri) if raw_uri
|
24
24
|
self['sid'] = hmac_session_id if hmac_session_id
|
25
25
|
self['uid'] = user_id if user_id
|
26
26
|
self['rule'] = id if id
|
@@ -48,10 +48,6 @@ module TCellAgent
|
|
48
48
|
self['variable'] = variable
|
49
49
|
self
|
50
50
|
end
|
51
|
-
|
52
|
-
def post_process
|
53
|
-
self['uri'] = Util.strip_uri_values(@raw_uri) if @raw_uri
|
54
|
-
end
|
55
51
|
end
|
56
52
|
end
|
57
53
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# See the file "LICENSE" for the full license governing this code.
|
2
2
|
|
3
3
|
require 'tcell_agent/sensor_events/util/sanitizer_utilities'
|
4
|
-
require 'tcell_agent/logger'
|
5
4
|
require 'uri'
|
6
5
|
|
7
6
|
module TCellAgent
|
@@ -21,70 +20,9 @@ module TCellAgent
|
|
21
20
|
self['offset'] = from_timestamp - @timestamp
|
22
21
|
end
|
23
22
|
|
24
|
-
def post_process
|
25
|
-
# This is called in the background thread, so any
|
26
|
-
# santization, analysis, etc doesn't get in the way
|
27
|
-
end
|
28
|
-
|
29
23
|
def bucket_key
|
30
24
|
nil
|
31
25
|
end
|
32
26
|
end
|
33
|
-
|
34
|
-
class TCellHttpTxSensorEvent < TCellSensorEvent
|
35
|
-
def initialize(request, response)
|
36
|
-
super('http_tx')
|
37
|
-
@raw_request = request
|
38
|
-
@raw_response = response
|
39
|
-
end
|
40
|
-
|
41
|
-
def post_process
|
42
|
-
self['request'] = Util.request_sanitized_json(@raw_request) if defined? @raw_request
|
43
|
-
|
44
|
-
self['response'] = Util.response_sanitized_json(@raw_response) if defined? @raw_response
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
class TCellRedirectSensorEvent < TCellSensorEvent
|
49
|
-
def initialize(redirect_domain,
|
50
|
-
original_domain,
|
51
|
-
original_url,
|
52
|
-
method,
|
53
|
-
route_id,
|
54
|
-
status_code,
|
55
|
-
remote_addr,
|
56
|
-
hmac_session_id = nil,
|
57
|
-
user_id = nil)
|
58
|
-
super('redirect')
|
59
|
-
self['method'] = method
|
60
|
-
self['from_domain'] = original_domain
|
61
|
-
self['status_code'] = status_code
|
62
|
-
self['remote_addr'] = remote_addr
|
63
|
-
self['to'] = redirect_domain
|
64
|
-
self['uid'] = user_id.to_s if user_id
|
65
|
-
self['from'] = Util.strip_uri_values(original_url)
|
66
|
-
self['rid'] = route_id if route_id
|
67
|
-
self['sid'] = hmac_session_id if hmac_session_id
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
class TCellFingerprintSensorEvent < TCellSensorEvent
|
72
|
-
def initialize(request, hmac_session_id, user_id = nil)
|
73
|
-
super('fingerprint')
|
74
|
-
@raw_request = request
|
75
|
-
@hmac_session_id = hmac_session_id
|
76
|
-
@user_id = user_id
|
77
|
-
end
|
78
|
-
|
79
|
-
def post_process
|
80
|
-
unless @raw_request.headers.key?('HTTP_USER_AGENT')
|
81
|
-
raise 'User Agent not Found!'
|
82
|
-
end
|
83
|
-
self['ua'] = @raw_request.headers['HTTP_USER_AGENT']
|
84
|
-
self['ip'] = @raw_request.remote_ip
|
85
|
-
self['sid'] = @hmac_session_id
|
86
|
-
self['uid'] = @user_id if @user_id
|
87
|
-
end
|
88
|
-
end
|
89
27
|
end
|
90
28
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
# See the file "LICENSE" for the full license governing this code.
|
2
2
|
|
3
|
-
require 'tcell_agent/logger'
|
4
3
|
require 'tcell_agent/sensor_events/util/sanitizer_utilities'
|
5
4
|
require 'tcell_agent/sensor_events/sensor'
|
6
5
|
require 'tcell_agent/sensor_events/util/utils'
|
@@ -8,15 +7,9 @@ require 'etc'
|
|
8
7
|
|
9
8
|
module TCellAgent
|
10
9
|
module SensorEvents
|
11
|
-
class FlushDummyEvent < TCellSensorEvent
|
12
|
-
def initialize
|
13
|
-
super('dummy')
|
14
|
-
@send = false
|
15
|
-
@flush = true
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
10
|
class ServerAgentDetailsSensorEvent < TCellSensorEvent
|
11
|
+
include TCellAgent::ModuleLoggerAccess
|
12
|
+
|
20
13
|
def initialize
|
21
14
|
super('server_agent_details')
|
22
15
|
@flush = true
|
@@ -33,17 +26,17 @@ module TCellAgent
|
|
33
26
|
info = Etc.getpwnam(login)
|
34
27
|
self['group'] = info.gid.to_s
|
35
28
|
rescue StandardError => te
|
36
|
-
|
37
|
-
|
29
|
+
module_logger.debug("Could not get group id: #{te.message}")
|
30
|
+
module_logger.exception(te)
|
38
31
|
end
|
39
32
|
end
|
40
33
|
rescue StandardError => to
|
41
|
-
|
42
|
-
|
34
|
+
module_logger.debug("Could not get user & group: #{to.message}")
|
35
|
+
module_logger.exception(te)
|
43
36
|
end
|
44
37
|
|
45
|
-
|
46
|
-
|
38
|
+
module_logger.debug("User #{self['user']}")
|
39
|
+
module_logger.debug("Group #{self['group']}")
|
47
40
|
end
|
48
41
|
end
|
49
42
|
|
@@ -68,6 +61,8 @@ module TCellAgent
|
|
68
61
|
end
|
69
62
|
|
70
63
|
class ServerAgentPackagesSensorEvent < TCellSensorEvent
|
64
|
+
include TCellAgent::ModuleLoggerAccess
|
65
|
+
|
71
66
|
def initialize
|
72
67
|
super('server_agent_packages')
|
73
68
|
@flush = true
|
@@ -78,11 +73,11 @@ module TCellAgent
|
|
78
73
|
if x.name
|
79
74
|
package = { 'n' => x.name, 'v' => x.version.version }
|
80
75
|
packages.push(package)
|
81
|
-
|
76
|
+
module_logger.debug("Adding packages #{x.name}")
|
82
77
|
end
|
83
78
|
rescue StandardError => te
|
84
|
-
|
85
|
-
|
79
|
+
module_logger.error("Exception adding package: #{te.message}")
|
80
|
+
module_logger.exception(te)
|
86
81
|
end
|
87
82
|
end
|
88
83
|
self['packages'] = packages
|
@@ -1,6 +1,5 @@
|
|
1
1
|
# See the file "LICENSE" for the full license governing this code.
|
2
2
|
|
3
|
-
require 'logger'
|
4
3
|
require 'cgi'
|
5
4
|
require 'uri'
|
6
5
|
require 'openssl'
|
@@ -16,98 +15,6 @@ module TCellAgent
|
|
16
15
|
h[0...h.length / 2]
|
17
16
|
end
|
18
17
|
|
19
|
-
def self.request_sanitized_json(request)
|
20
|
-
sanitized_headers = {}
|
21
|
-
headers = request.headers.select { |k, _v| k.start_with? 'HTTP_' }
|
22
|
-
.collect { |pair| [pair[0].sub(/^HTTP_/, ''), pair[1]] }
|
23
|
-
.sort
|
24
|
-
headers.each do |header_name, header_value|
|
25
|
-
lower_header_name = header_name.downcase
|
26
|
-
sanitized_headers[header_name] = if lower_header_name == 'cookie'
|
27
|
-
[santize_request_cookie_string(header_value)]
|
28
|
-
elsif %w[content_type content_length user_agent csp].include?(lower_header_name)
|
29
|
-
[header_value]
|
30
|
-
else
|
31
|
-
[]
|
32
|
-
end
|
33
|
-
end
|
34
|
-
new_request = { 'method' => request.request_method,
|
35
|
-
'uri' => sanitize_uri(request.fullpath),
|
36
|
-
'headers' => sanitized_headers }
|
37
|
-
request_body = request.body.read
|
38
|
-
if request_body
|
39
|
-
new_request['post_data'] = sanitize_query_string(request_body)
|
40
|
-
end
|
41
|
-
new_request
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.response_sanitized_json(response)
|
45
|
-
status, headers, _body = *response
|
46
|
-
sanitized_headers = {}
|
47
|
-
content_type = 'unknown'
|
48
|
-
headers.each do |header_name, header_value|
|
49
|
-
lower_header_name = header_name.downcase
|
50
|
-
if lower_header_name == 'set-cookie'
|
51
|
-
sanitized_headers[header_name] = [santize_response_cookie_string(header_value)]
|
52
|
-
else
|
53
|
-
content_type = header_value if lower_header_name == 'content-type'
|
54
|
-
sanitized_headers[header_name] = if ['content-type', 'content-length'].include?(lower_header_name)
|
55
|
-
[header_value]
|
56
|
-
else
|
57
|
-
[]
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
{ 'status' => status,
|
63
|
-
'headers' => sanitized_headers }
|
64
|
-
end
|
65
|
-
|
66
|
-
def self.santize_request_cookie_string(request_cookie_string)
|
67
|
-
sanitized_cookies = {}
|
68
|
-
cookies = CGI::Cookie.parse(request_cookie_string)
|
69
|
-
cookies.each do |cookie_name, cookie_value|
|
70
|
-
next if cookie_value.length != 1
|
71
|
-
sanitized_cookies[cookie_name] = Util.hmac(cookie_value[0])
|
72
|
-
end
|
73
|
-
sanitized_cookies.map { |k, v| "#{k}=#{v}" }.join(';')
|
74
|
-
end
|
75
|
-
|
76
|
-
def self.santize_response_cookie_string(response_cookie_string_value)
|
77
|
-
cookie_parts = response_cookie_string_value.split('; ')
|
78
|
-
cookie_string = cookie_parts[0]
|
79
|
-
cookies = CGI::Cookie.parse(cookie_string)
|
80
|
-
return '[COOKIEMALFORMED]' if cookies.length != 1
|
81
|
-
cookie_name = cookies.keys.first
|
82
|
-
cookie_values = cookies.values.first
|
83
|
-
return '[COOKIEHADTOOMANYVALUES]' if cookie_values.length != 1
|
84
|
-
h = Util.hmac(cookie_values[0])
|
85
|
-
new_cookie_string = "#{cookie_name}=#{h}"
|
86
|
-
cookie_parts[0] = new_cookie_string
|
87
|
-
cookie_parts.map { |k, v| "#{k}=#{v}" }.join('; ')
|
88
|
-
end
|
89
|
-
|
90
|
-
def self.sanitize_query_string(query)
|
91
|
-
params = CGI.parse(query)
|
92
|
-
params.each do |param_name, param_values|
|
93
|
-
next if param_values.nil? || param_values.empty?
|
94
|
-
if param_name.match(/password/i) ||
|
95
|
-
param_name.match(/passwd/i) ||
|
96
|
-
param_name.match(/token/i) ||
|
97
|
-
param_name.match(/sessionid/i)
|
98
|
-
params[param_name] = ['?']
|
99
|
-
next
|
100
|
-
end
|
101
|
-
new_param_values = []
|
102
|
-
param_values.each do |param_value|
|
103
|
-
h = Util.hmac(param_value)
|
104
|
-
new_param_values.push << h
|
105
|
-
end
|
106
|
-
params[param_name] = new_param_values
|
107
|
-
end
|
108
|
-
params.map { |k, v| "#{k}=#{v.join(',')}" }.join('&')
|
109
|
-
end
|
110
|
-
|
111
18
|
def self.strip_values_query_string(query)
|
112
19
|
params = CGI.parse(query)
|
113
20
|
params.each do |param_name, param_values|
|
@@ -117,13 +24,6 @@ module TCellAgent
|
|
117
24
|
params.map { |k, v| "#{k}=#{v.join(',')}" }.join('&')
|
118
25
|
end
|
119
26
|
|
120
|
-
def self.sanitize_uri(uri_string)
|
121
|
-
uri = URI(uri_string)
|
122
|
-
query = uri.query
|
123
|
-
uri.query = sanitize_query_string(query) if query
|
124
|
-
uri.to_s
|
125
|
-
end
|
126
|
-
|
127
27
|
def self.strip_uri_values(uri_string)
|
128
28
|
uri = URI(uri_string)
|
129
29
|
query = uri.query
|
@@ -137,14 +37,6 @@ module TCellAgent
|
|
137
37
|
|
138
38
|
'tcell_hmac_key'
|
139
39
|
end
|
140
|
-
|
141
|
-
def self.clean_header_keys(request_env_or_header_keys)
|
142
|
-
if request_env_or_header_keys.is_a?(Hash)
|
143
|
-
request_env_or_header_keys.select { |k, _v| k.start_with? 'HTTP_' }.collect { |k, _v| k.sub(/^HTTP_/, '') }
|
144
|
-
else
|
145
|
-
request_env_or_header_keys.map { |k| k.sub(/^HTTP_/, '') }
|
146
|
-
end
|
147
|
-
end
|
148
40
|
end
|
149
41
|
end
|
150
42
|
end
|