tcell_agent 2.1.1 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +2 -2
- data/bin/tcell_agent +41 -150
- data/lib/tcell_agent.rb +8 -16
- data/lib/tcell_agent/agent.rb +87 -52
- data/lib/tcell_agent/config_initializer.rb +62 -0
- data/lib/tcell_agent/configuration.rb +72 -267
- data/lib/tcell_agent/hooks/login_fraud.rb +1 -1
- data/lib/tcell_agent/instrument_servers.rb +14 -18
- data/lib/tcell_agent/instrumentation.rb +14 -6
- data/lib/tcell_agent/instrumentation/cmdi.rb +47 -15
- data/lib/tcell_agent/instrumentation/lfi.rb +68 -11
- data/lib/tcell_agent/instrumentation/monkey_patches/ruby_2/file.rb +21 -0
- data/lib/tcell_agent/instrumentation/monkey_patches/ruby_2/io.rb +75 -0
- data/lib/tcell_agent/instrumentation/monkey_patches/ruby_2/kernel.rb +80 -0
- data/lib/tcell_agent/instrumentation/monkey_patches/ruby_3/file.rb +21 -0
- data/lib/tcell_agent/instrumentation/monkey_patches/ruby_3/io.rb +75 -0
- data/lib/tcell_agent/instrumentation/monkey_patches/ruby_3/kernel.rb +80 -0
- data/lib/tcell_agent/logger.rb +3 -4
- data/lib/tcell_agent/policies/dataloss_policy.rb +15 -8
- data/lib/tcell_agent/policies/headers_policy.rb +2 -2
- data/lib/tcell_agent/policies/patches_policy.rb +8 -4
- data/lib/tcell_agent/policies/policies_manager.rb +1 -0
- data/lib/tcell_agent/policies/policy_polling.rb +4 -3
- data/lib/tcell_agent/rails/auth/authlogic.rb +49 -44
- data/lib/tcell_agent/rails/auth/authlogic_helper.rb +20 -0
- data/lib/tcell_agent/rails/auth/devise.rb +103 -102
- data/lib/tcell_agent/rails/auth/devise_helper.rb +29 -0
- data/lib/tcell_agent/rails/auth/doorkeeper.rb +54 -57
- data/lib/tcell_agent/{userinfo.rb → rails/auth/userinfo.rb} +0 -0
- data/lib/tcell_agent/rails/better_ip.rb +7 -19
- data/lib/tcell_agent/rails/csrf_exception.rb +0 -8
- data/lib/tcell_agent/rails/dlp.rb +48 -52
- data/lib/tcell_agent/rails/dlp/process_request.rb +5 -0
- data/lib/tcell_agent/rails/dlp_handler.rb +9 -10
- data/lib/tcell_agent/rails/js_agent_insert.rb +2 -3
- data/lib/tcell_agent/rails/middleware/context_middleware.rb +2 -1
- data/lib/tcell_agent/rails/middleware/global_middleware.rb +3 -4
- data/lib/tcell_agent/rails/middleware/headers_middleware.rb +1 -0
- data/lib/tcell_agent/rails/{on_start.rb → railties/tcell_agent_railties.rb} +9 -16
- data/lib/tcell_agent/rails/railties/tcell_agent_unicorn_railties.rb +8 -0
- data/lib/tcell_agent/rails/routes.rb +3 -6
- data/lib/tcell_agent/rails/routes/grape.rb +5 -12
- data/lib/tcell_agent/rails/settings_reporter.rb +0 -8
- data/lib/tcell_agent/rails/tcell_body_proxy.rb +4 -7
- data/lib/tcell_agent/routes/table.rb +3 -0
- data/lib/tcell_agent/rust/agent_config.rb +52 -32
- data/lib/tcell_agent/rust/{libtcellagent-4.18.0.so → libtcellagent-alpine.so} +0 -0
- data/lib/tcell_agent/rust/libtcellagent-x64.dll +0 -0
- data/lib/tcell_agent/rust/{libtcellagent-4.18.0.dylib → libtcellagent.dylib} +0 -0
- data/lib/tcell_agent/rust/{libtcellagent-alpine-4.18.0.so → libtcellagent.so} +0 -0
- data/lib/tcell_agent/rust/models.rb +9 -0
- data/lib/tcell_agent/rust/native_agent.rb +58 -50
- data/lib/tcell_agent/rust/native_library.rb +8 -10
- data/lib/tcell_agent/sensor_events/server_agent.rb +3 -100
- data/lib/tcell_agent/sensor_events/util/sanitizer_utilities.rb +1 -0
- data/lib/tcell_agent/servers/puma.rb +30 -13
- data/lib/tcell_agent/servers/rack_puma_handler.rb +33 -0
- data/lib/tcell_agent/servers/rails_server.rb +4 -4
- data/lib/tcell_agent/servers/unicorn.rb +1 -1
- data/lib/tcell_agent/servers/webrick.rb +12 -3
- data/lib/tcell_agent/settings_reporter.rb +0 -93
- data/lib/tcell_agent/sinatra.rb +1 -0
- data/lib/tcell_agent/tcell_context.rb +16 -7
- data/lib/tcell_agent/utils/headers.rb +0 -1
- data/lib/tcell_agent/utils/strings.rb +2 -2
- data/lib/tcell_agent/version.rb +1 -1
- data/spec/cruby_spec_helper.rb +26 -0
- data/spec/lib/tcell_agent/configuration_spec.rb +62 -212
- data/spec/lib/tcell_agent/instrument_servers_spec.rb +95 -0
- data/spec/lib/tcell_agent/instrumentation/cmdi/io_cmdi_spec.rb +2 -2
- data/spec/lib/tcell_agent/instrumentation/cmdi_spec.rb +46 -4
- data/spec/lib/tcell_agent/instrumentation/lfi/file_lfi_spec.rb +211 -272
- data/spec/lib/tcell_agent/instrumentation/lfi/io_lfi_spec.rb +207 -223
- data/spec/lib/tcell_agent/instrumentation/lfi/kernel_lfi_spec.rb +89 -70
- data/spec/lib/tcell_agent/instrumentation/lfi_spec.rb +120 -2
- data/spec/lib/tcell_agent/patches_spec.rb +2 -1
- data/spec/lib/tcell_agent/policies/clickjacking_policy_spec.rb +1 -2
- data/spec/lib/tcell_agent/policies/content_security_policy_spec.rb +5 -6
- data/spec/lib/tcell_agent/policies/patches_policy_spec.rb +21 -2
- data/spec/lib/tcell_agent/policies/policies_manager_spec.rb +1 -1
- data/spec/lib/tcell_agent/policies/secure_headers_policy_spec.rb +14 -8
- data/spec/lib/tcell_agent/rails/better_ip_spec.rb +9 -11
- data/spec/lib/tcell_agent/rails/csrf_exception_spec.rb +6 -6
- data/spec/lib/tcell_agent/rails/dlp_spec.rb +1 -0
- data/spec/lib/tcell_agent/rails/js_agent_insert_spec.rb +10 -2
- data/spec/lib/tcell_agent/rails/middleware/tcell_body_proxy_spec.rb +2 -1
- data/spec/lib/tcell_agent/rails/routes/route_id_spec.rb +4 -4
- data/spec/lib/tcell_agent/rust/agent_config_spec.rb +27 -0
- data/spec/lib/tcell_agent/settings_reporter_spec.rb +2 -89
- data/spec/lib/tcell_agent/tcell_context_spec.rb +6 -5
- data/spec/spec_helper.rb +9 -1
- data/spec/support/builders.rb +8 -7
- data/spec/support/server_mocks/passenger_mock.rb +7 -0
- data/spec/support/server_mocks/puma_mock.rb +21 -0
- data/spec/support/server_mocks/rails_mock.rb +7 -0
- data/spec/support/server_mocks/thin_mock.rb +7 -0
- data/spec/support/server_mocks/unicorn_mock.rb +11 -0
- data/spec/support/shared_spec.rb +29 -0
- data/tcell_agent.gemspec +14 -14
- metadata +44 -27
- data/Rakefile +0 -18
- data/lib/tcell_agent/authlogic.rb +0 -23
- data/lib/tcell_agent/config/unknown_options.rb +0 -119
- data/lib/tcell_agent/devise.rb +0 -33
- data/lib/tcell_agent/instrumentation/monkey_patches/file.rb +0 -25
- data/lib/tcell_agent/instrumentation/monkey_patches/io.rb +0 -131
- data/lib/tcell_agent/instrumentation/monkey_patches/kernel.rb +0 -163
- data/lib/tcell_agent/rails/start_agent_after_initializers.rb +0 -12
- data/lib/tcell_agent/rust/tcellagent-4.18.0.dll +0 -0
- data/spec/lib/tcell_agent/config/unknown_options_spec.rb +0 -195
@@ -1,119 +0,0 @@
|
|
1
|
-
require 'set'
|
2
|
-
|
3
|
-
module TCellAgent
|
4
|
-
module Config
|
5
|
-
module Validate
|
6
|
-
def self.get_unknown_options(config_json)
|
7
|
-
messages = []
|
8
|
-
|
9
|
-
known_tcell_env_vars = Set.new(
|
10
|
-
[
|
11
|
-
'TCELL_AGENT_SERVER', # this is only meant for specs
|
12
|
-
'TCELL_AGENT_APP_ID',
|
13
|
-
'TCELL_AGENT_API_KEY',
|
14
|
-
'TCELL_HMAC_KEY',
|
15
|
-
'TCELL_PASSWORD_HMAC_KEY',
|
16
|
-
'TCELL_AGENT_HOST_IDENTIFIER',
|
17
|
-
'TCELL_API_URL',
|
18
|
-
'TCELL_INPUT_URL',
|
19
|
-
'TCELL_DEMOMODE',
|
20
|
-
'TCELL_AGENT_HOME',
|
21
|
-
'TCELL_AGENT_LOG_DIR',
|
22
|
-
'TCELL_AGENT_CONFIG',
|
23
|
-
'TCELL_AGENT_ALLOW_PAYLOADS',
|
24
|
-
'TCELL_AGENT_LOG_LEVEL',
|
25
|
-
'TCELL_AGENT_LOG_FILENAME',
|
26
|
-
'TCELL_AGENT_LOG_ENABLED'
|
27
|
-
]
|
28
|
-
)
|
29
|
-
|
30
|
-
ENV.keys.each do |environment_key|
|
31
|
-
if environment_key =~ /^TCELL_/ && !known_tcell_env_vars.include?(environment_key)
|
32
|
-
messages << "Unrecognized environment parameter (TCELL_*) found: #{environment_key}"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
begin
|
37
|
-
key_differences = []
|
38
|
-
|
39
|
-
if config_json
|
40
|
-
first_level_keys = %w[version applications]
|
41
|
-
|
42
|
-
key_differences = config_json.keys - first_level_keys
|
43
|
-
|
44
|
-
applications = config_json.fetch('applications', nil)
|
45
|
-
if applications
|
46
|
-
|
47
|
-
if applications.size > 1
|
48
|
-
messages << 'Multiple applications detected in config file'
|
49
|
-
|
50
|
-
elsif applications.size == 1
|
51
|
-
application = applications[0]
|
52
|
-
|
53
|
-
second_level_keys = %w[
|
54
|
-
name
|
55
|
-
app_id
|
56
|
-
api_key
|
57
|
-
fetch_policies_from_tcell
|
58
|
-
preload_policy_filename
|
59
|
-
log_dir
|
60
|
-
tcell_api_url
|
61
|
-
tcell_input_url
|
62
|
-
host_identifier
|
63
|
-
hipaaSafeMode
|
64
|
-
hmac_key
|
65
|
-
password_hmac_key
|
66
|
-
js_agent_api_base_url
|
67
|
-
js_agent_url
|
68
|
-
max_csp_header_bytes
|
69
|
-
event_batch_size_limit
|
70
|
-
allow_payloads
|
71
|
-
reverse_proxy
|
72
|
-
reverse_proxy_ip_address_header
|
73
|
-
demomode
|
74
|
-
logging_options
|
75
|
-
data_exposure
|
76
|
-
disable_all
|
77
|
-
enabled
|
78
|
-
enable_event_manager
|
79
|
-
enable_policy_polling
|
80
|
-
enable_instrumentation
|
81
|
-
enable_intercept_requests
|
82
|
-
instrument_for_events
|
83
|
-
enabled_instrumentations
|
84
|
-
stdout_logger
|
85
|
-
]
|
86
|
-
|
87
|
-
key_differences += (application.keys - second_level_keys)
|
88
|
-
|
89
|
-
if application.fetch('logging_options', nil)
|
90
|
-
logging_options = application['logging_options']
|
91
|
-
key_differences += (logging_options.keys - %w[enabled level filename])
|
92
|
-
end
|
93
|
-
|
94
|
-
if application.fetch('data_exposure', nil)
|
95
|
-
data_exposure = application['data_exposure']
|
96
|
-
key_differences += (data_exposure.keys - ['max_data_ex_db_records_per_request'])
|
97
|
-
end
|
98
|
-
|
99
|
-
if application.fetch('enabled_instrumentations', nil)
|
100
|
-
enabled_instrumentations = application['enabled_instrumentations']
|
101
|
-
key_differences += (enabled_instrumentations.keys - %w[doorkeeper devise authlogic])
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
key_differences.each do |key|
|
107
|
-
messages << "Unrecognized config setting key: #{key}"
|
108
|
-
end
|
109
|
-
|
110
|
-
end
|
111
|
-
rescue StandardError => exception
|
112
|
-
messages << "Something went wrong verifying config file: #{exception}"
|
113
|
-
end
|
114
|
-
|
115
|
-
messages
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
data/lib/tcell_agent/devise.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
if TCellAgent.configuration.should_instrument_devise? && defined?(Devise)
|
2
|
-
require 'devise'
|
3
|
-
require 'devise/rails'
|
4
|
-
require 'devise/strategies/database_authenticatable'
|
5
|
-
require 'tcell_agent/userinfo'
|
6
|
-
|
7
|
-
module TCellAgent
|
8
|
-
if defined?(Devise)
|
9
|
-
TCellAgent::UserInformation.class_eval do
|
10
|
-
class << self
|
11
|
-
alias_method :original_get_user_from_request, :get_user_from_request
|
12
|
-
def get_user_from_request(request)
|
13
|
-
orig_user_id = original_get_user_from_request(request)
|
14
|
-
begin
|
15
|
-
if request.session && request.session.key?('warden.user.user.key')
|
16
|
-
userkey = request.session['warden.user.user.key']
|
17
|
-
user_id = if userkey.length == 2
|
18
|
-
userkey[0][0]
|
19
|
-
else
|
20
|
-
userkey[1][0]
|
21
|
-
end
|
22
|
-
return user_id.to_s if user_id.is_a? Integer
|
23
|
-
end
|
24
|
-
rescue StandardError
|
25
|
-
return orig_user_id
|
26
|
-
end
|
27
|
-
orig_user_id
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
class File
|
2
|
-
class << self
|
3
|
-
alias_method :tcell_original_new, :new
|
4
|
-
def new(*args, &block)
|
5
|
-
path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(*args)
|
6
|
-
|
7
|
-
if TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode)
|
8
|
-
raise IOError, "tCell.io Agent: Attempted access to file #{path} with mode #{mode} denied"
|
9
|
-
end
|
10
|
-
|
11
|
-
tcell_original_new(*args, &block)
|
12
|
-
end
|
13
|
-
|
14
|
-
alias_method :tcell_original_open, :open
|
15
|
-
def open(*args, &block)
|
16
|
-
path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(*args)
|
17
|
-
|
18
|
-
if TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode)
|
19
|
-
raise IOError, "tCell.io Agent: Attempted access to file #{path} with mode #{mode} denied"
|
20
|
-
end
|
21
|
-
|
22
|
-
tcell_original_open(*args, &block)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,131 +0,0 @@
|
|
1
|
-
class IO
|
2
|
-
class << self
|
3
|
-
alias_method :tcell_original_binread, :binread
|
4
|
-
def binread(*args, &block)
|
5
|
-
path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(*args)
|
6
|
-
|
7
|
-
if !path.strip.empty? && TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode)
|
8
|
-
raise IOError, "tCell.io Agent: Attempted access to file #{path} with mode #{mode} denied"
|
9
|
-
end
|
10
|
-
|
11
|
-
if path.empty?
|
12
|
-
cmd = TCellAgent::Cmdi.parse_command_from_open(*args)
|
13
|
-
if cmd && TCellAgent::Cmdi.block_command?(cmd)
|
14
|
-
raise "tCell.io Agent: Command not allowed by policy: #{cmd}"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
tcell_original_binread(*args, &block)
|
19
|
-
end
|
20
|
-
|
21
|
-
alias_method :tcell_original_binwrite, :binwrite
|
22
|
-
def binwrite(*args, &block)
|
23
|
-
path, _mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(*args)
|
24
|
-
mode = 'Write'
|
25
|
-
|
26
|
-
if TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode)
|
27
|
-
raise IOError, "tCell.io Agent: Attempted access to file #{path} with mode #{mode} denied"
|
28
|
-
end
|
29
|
-
|
30
|
-
tcell_original_binwrite(*args, &block)
|
31
|
-
end
|
32
|
-
|
33
|
-
alias_method :tcell_original_foreach, :foreach
|
34
|
-
def foreach(*args, &block)
|
35
|
-
path, _mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(*args)
|
36
|
-
mode = 'Read'
|
37
|
-
|
38
|
-
if TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode)
|
39
|
-
raise IOError, "tCell.io Agent: Attempted access to file #{path} with mode #{mode} denied"
|
40
|
-
end
|
41
|
-
|
42
|
-
tcell_original_foreach(*args, &block)
|
43
|
-
end
|
44
|
-
|
45
|
-
alias_method :tcell_original_popen, :popen
|
46
|
-
def popen(*args, &block)
|
47
|
-
unless args.empty?
|
48
|
-
cmd = ''
|
49
|
-
|
50
|
-
TCellAgent::Instrumentation.safe_block('CMDI Parsing popen *args') do
|
51
|
-
args_copy = Array.new(args)
|
52
|
-
args_copy.shift if args_copy.first.is_a?(Hash)
|
53
|
-
args_copy.pop if args_copy.last.is_a?(Hash)
|
54
|
-
|
55
|
-
cmd = if args_copy.first.is_a?(String)
|
56
|
-
args_copy.shift
|
57
|
-
else
|
58
|
-
TCellAgent::Cmdi.parse_command(*args_copy.shift)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
if TCellAgent::Cmdi.block_command?(cmd)
|
63
|
-
raise "tCell.io Agent: Command not allowed by policy: #{cmd}"
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
tcell_original_popen(*args, &block)
|
68
|
-
end
|
69
|
-
|
70
|
-
alias_method :tcell_original_read, :read
|
71
|
-
def read(*args, &block)
|
72
|
-
path, _mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(*args)
|
73
|
-
mode = 'Read'
|
74
|
-
|
75
|
-
if !path.strip.empty? && TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode)
|
76
|
-
raise IOError, "tCell.io Agent: Attempted access to file #{path} with mode #{mode} denied"
|
77
|
-
end
|
78
|
-
|
79
|
-
if path.empty?
|
80
|
-
cmd = TCellAgent::Cmdi.parse_command_from_open(*args)
|
81
|
-
if cmd && TCellAgent::Cmdi.block_command?(cmd)
|
82
|
-
raise "tCell.io Agent: Command not allowed by policy: #{cmd}"
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
tcell_original_read(*args, &block)
|
87
|
-
end
|
88
|
-
|
89
|
-
alias_method :tcell_original_readlines, :readlines
|
90
|
-
def readlines(*args, &block)
|
91
|
-
path, _mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(*args)
|
92
|
-
mode = 'Read'
|
93
|
-
|
94
|
-
if !path.strip.empty? && TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode)
|
95
|
-
raise IOError, "tCell.io Agent: Attempted access to file #{path} with mode #{mode} denied"
|
96
|
-
end
|
97
|
-
|
98
|
-
if path.empty?
|
99
|
-
cmd = TCellAgent::Cmdi.parse_command_from_open(*args)
|
100
|
-
if cmd && TCellAgent::Cmdi.block_command?(cmd)
|
101
|
-
raise "tCell.io Agent: Command not allowed by policy: #{cmd}"
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
tcell_original_readlines(*args, &block)
|
106
|
-
end
|
107
|
-
|
108
|
-
alias_method :tcell_original_sysopen, :sysopen
|
109
|
-
def sysopen(*args, &block)
|
110
|
-
path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(*args)
|
111
|
-
|
112
|
-
if TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode)
|
113
|
-
raise IOError, "tCell.io Agent: Attempted access to file #{path} with mode #{mode} denied"
|
114
|
-
end
|
115
|
-
|
116
|
-
tcell_original_sysopen(*args, &block)
|
117
|
-
end
|
118
|
-
|
119
|
-
alias_method :tcell_original_write, :write
|
120
|
-
def write(*args, &block)
|
121
|
-
path, _mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(*args)
|
122
|
-
mode = 'Write'
|
123
|
-
|
124
|
-
if TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode)
|
125
|
-
raise IOError, "tCell.io Agent: Attempted access to file #{path} with mode #{mode} denied"
|
126
|
-
end
|
127
|
-
|
128
|
-
tcell_original_write(*args, &block)
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
@@ -1,163 +0,0 @@
|
|
1
|
-
module Kernel
|
2
|
-
class << self
|
3
|
-
alias_method :tcell_original_1_open, :open
|
4
|
-
def open(*args, &block)
|
5
|
-
path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(*args)
|
6
|
-
|
7
|
-
if !path.strip.empty? && TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode)
|
8
|
-
raise IOError, "tCell.io Agent: Attempted access to file #{path} with mode #{mode} denied"
|
9
|
-
end
|
10
|
-
|
11
|
-
if path.empty?
|
12
|
-
cmd = TCellAgent::Cmdi.parse_command_from_open(*args)
|
13
|
-
if cmd && TCellAgent::Cmdi.block_command?(cmd)
|
14
|
-
raise "tCell.io Agent: Command not allowed by policy: #{cmd}"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
tcell_original_1_open(*args, &block)
|
19
|
-
end
|
20
|
-
|
21
|
-
alias_method :tcell_original_1_gets, :gets
|
22
|
-
def gets(*args, &block)
|
23
|
-
path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode_argf
|
24
|
-
|
25
|
-
if TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode)
|
26
|
-
raise IOError, "tCell.io Agent: Attempted access to file #{path} with mode #{mode} denied"
|
27
|
-
end
|
28
|
-
|
29
|
-
tcell_original_1_gets(*args, &block)
|
30
|
-
end
|
31
|
-
|
32
|
-
alias_method :tcell_original_readline, :readline
|
33
|
-
def readline(*args, &block)
|
34
|
-
path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode_argf
|
35
|
-
|
36
|
-
if TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode)
|
37
|
-
raise IOError, "tCell.io Agent: Attempted access to file #{path} with mode #{mode} denied"
|
38
|
-
end
|
39
|
-
|
40
|
-
tcell_original_readline(*args, &block)
|
41
|
-
end
|
42
|
-
|
43
|
-
alias_method :tcell_original_1_spawn, :spawn
|
44
|
-
def spawn(*args)
|
45
|
-
cmd = TCellAgent::Cmdi.parse_command(*args)
|
46
|
-
if TCellAgent::Cmdi.block_command?(cmd)
|
47
|
-
raise "tCell.io Agent: Command not allowed by policy: #{cmd}"
|
48
|
-
end
|
49
|
-
|
50
|
-
tcell_original_1_spawn(*args)
|
51
|
-
end
|
52
|
-
|
53
|
-
alias_method :tcell_original_1_system, :system
|
54
|
-
def system(*args)
|
55
|
-
cmd = TCellAgent::Cmdi.parse_command(*args)
|
56
|
-
if TCellAgent::Cmdi.block_command?(cmd)
|
57
|
-
raise "tCell.io Agent: Command not allowed by policy: #{cmd}"
|
58
|
-
end
|
59
|
-
|
60
|
-
tcell_original_1_system(*args)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
alias_method :tcell_original_backtick, :`
|
65
|
-
def `(cmd)
|
66
|
-
if TCellAgent::Cmdi.block_command?(cmd)
|
67
|
-
raise "tCell.io Agent: Command not allowed by policy: #{cmd}"
|
68
|
-
end
|
69
|
-
|
70
|
-
tcell_original_backtick(cmd)
|
71
|
-
end
|
72
|
-
|
73
|
-
alias_method :tcell_original_2_open, :open
|
74
|
-
def open(*args, &block)
|
75
|
-
path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(*args)
|
76
|
-
|
77
|
-
if !path.strip.empty? && TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode)
|
78
|
-
raise IOError, "tCell.io Agent: Attempted access to file #{path} with mode #{mode} denied"
|
79
|
-
end
|
80
|
-
|
81
|
-
if path.empty?
|
82
|
-
cmd = TCellAgent::Cmdi.parse_command_from_open(*args)
|
83
|
-
if cmd && TCellAgent::Cmdi.block_command?(cmd)
|
84
|
-
raise "tCell.io Agent: Command not allowed by policy: #{cmd}"
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
tcell_original_2_open(*args, &block)
|
89
|
-
end
|
90
|
-
|
91
|
-
alias_method :tcell_original_2_gets, :gets
|
92
|
-
def gets(*args, &block)
|
93
|
-
path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode_argf
|
94
|
-
|
95
|
-
if TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode)
|
96
|
-
raise IOError, "tCell.io Agent: Attempted access to file #{path} with mode #{mode} denied"
|
97
|
-
end
|
98
|
-
|
99
|
-
tcell_original_2_gets(*args, &block)
|
100
|
-
end
|
101
|
-
|
102
|
-
alias_method :tcell_original_readline, :readline
|
103
|
-
def readline(*args, &block)
|
104
|
-
path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode_argf
|
105
|
-
|
106
|
-
if TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode)
|
107
|
-
raise IOError, "tCell.io Agent: Attempted access to file #{path} with mode #{mode} denied"
|
108
|
-
end
|
109
|
-
|
110
|
-
tcell_original_readline(*args, &block)
|
111
|
-
end
|
112
|
-
|
113
|
-
alias_method :tcell_original_2_spawn, :spawn
|
114
|
-
def spawn(*args)
|
115
|
-
cmd = TCellAgent::Cmdi.parse_command(*args)
|
116
|
-
if TCellAgent::Cmdi.block_command?(cmd)
|
117
|
-
raise "tCell.io Agent: Command not allowed by policy: #{cmd}"
|
118
|
-
end
|
119
|
-
|
120
|
-
tcell_original_2_spawn(*args)
|
121
|
-
end
|
122
|
-
|
123
|
-
alias_method :tcell_original_2_system, :system
|
124
|
-
def system(*args)
|
125
|
-
cmd = TCellAgent::Cmdi.parse_command(*args)
|
126
|
-
if TCellAgent::Cmdi.block_command?(cmd)
|
127
|
-
raise "tCell.io Agent: Command not allowed by policy: #{cmd}"
|
128
|
-
end
|
129
|
-
|
130
|
-
tcell_original_2_system(*args)
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
if TCellAgent.configuration.should_instrument_cmdi_exec?
|
135
|
-
module Kernel
|
136
|
-
class << self
|
137
|
-
alias_method :tcell_original_exec, :exec
|
138
|
-
def exec(*args)
|
139
|
-
cmd = TCellAgent::Cmdi.parse_command(*args)
|
140
|
-
if TCellAgent::Cmdi.block_command?(cmd)
|
141
|
-
raise "tCell.io Agent: Command not allowed by policy: #{cmd}"
|
142
|
-
end
|
143
|
-
|
144
|
-
tcell_original_exec(*args)
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
alias_method :tcell_original_exec, :exec
|
149
|
-
|
150
|
-
private
|
151
|
-
|
152
|
-
def exec(*args)
|
153
|
-
cmd = TCellAgent::Cmdi.parse_command(*args)
|
154
|
-
if TCellAgent::Cmdi.block_command?(cmd)
|
155
|
-
raise "tCell.io Agent: Command not allowed by policy: #{cmd}"
|
156
|
-
end
|
157
|
-
|
158
|
-
tcell_original_exec(*args)
|
159
|
-
end
|
160
|
-
end
|
161
|
-
else
|
162
|
-
TCellAgent.logger.debug('Disabling cmdi Kernel::exec instrumentation', 'TCellAgent::Cmdi')
|
163
|
-
end
|