tcell_agent 1.1.12 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,249 @@
|
|
1
|
+
# rubocop:disable Security/Open
|
2
|
+
# rubocop:disable Lint/UselessAssignment
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'securerandom'
|
5
|
+
|
6
|
+
describe 'Kernel' do
|
7
|
+
before do
|
8
|
+
native_agent = double('native_agent')
|
9
|
+
@local_files_policy = TCellAgent::Policies::LocalFileInclusion.new(
|
10
|
+
native_agent, {}
|
11
|
+
)
|
12
|
+
@filename = get_test_resource_path('lfi_sample_file.txt')
|
13
|
+
@file_contents = "This is line one.\nThis is line two.\n"
|
14
|
+
end
|
15
|
+
|
16
|
+
before(:all) do
|
17
|
+
@new_file_name = '/tmp/' + SecureRandom.uuid
|
18
|
+
end
|
19
|
+
describe '#open and ::open' do
|
20
|
+
context 'empty path' do
|
21
|
+
it 'should raise an error' do
|
22
|
+
expect do
|
23
|
+
Kernel.open
|
24
|
+
end.to raise_error(ArgumentError)
|
25
|
+
expect do
|
26
|
+
Kernel.open(nil)
|
27
|
+
end.to raise_error(TypeError)
|
28
|
+
expect do
|
29
|
+
Kernel.open('')
|
30
|
+
end.to raise_error(Errno::ENOENT)
|
31
|
+
expect do
|
32
|
+
open
|
33
|
+
end.to raise_error(ArgumentError)
|
34
|
+
expect do
|
35
|
+
open(nil)
|
36
|
+
end.to raise_error(TypeError)
|
37
|
+
expect do
|
38
|
+
open('')
|
39
|
+
end.to raise_error(Errno::ENOENT)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
context 'with a filename not blocked for read/write' do
|
43
|
+
before do |test|
|
44
|
+
unless test.metadata[:skip_before]
|
45
|
+
expect(TCellAgent).to receive(:policy).with(
|
46
|
+
TCellAgent::PolicyTypes::LFI
|
47
|
+
).and_return(@local_files_policy, @local_files_policy)
|
48
|
+
expect(@local_files_policy).to receive(:block_file_access?).and_return(false, false)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should still be able to execute OS commands', :skip_before do
|
53
|
+
result = Kernel.open('|echo test').read
|
54
|
+
expect(result).to eq "test\n"
|
55
|
+
|
56
|
+
result = open('|echo test').read
|
57
|
+
expect(result).to eq "test\n"
|
58
|
+
end
|
59
|
+
context 'with a nonexistent filename with mode w' do
|
60
|
+
it 'should create the file' do
|
61
|
+
Kernel.open(@new_file_name, 'w')
|
62
|
+
expect(File.exist?(@new_file_name)).to be_truthy
|
63
|
+
File.delete(@new_file_name)
|
64
|
+
|
65
|
+
open(@new_file_name, 'w')
|
66
|
+
expect(File.exist?(@new_file_name)).to be_truthy
|
67
|
+
File.delete(@new_file_name)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
context 'with a filename and mode w and file permissions 644' do
|
71
|
+
it 'should create the file with the correct permissions' do
|
72
|
+
Kernel.open(@new_file_name, 'w', 0o644)
|
73
|
+
expect(File.stat(@new_file_name).mode.to_s(8)[3..5]).to eq('644')
|
74
|
+
File.delete(@new_file_name)
|
75
|
+
|
76
|
+
open(@new_file_name, 'w', 0o644)
|
77
|
+
expect(File.stat(@new_file_name).mode.to_s(8)[3..5]).to eq('644')
|
78
|
+
File.delete(@new_file_name)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
context 'with a filename and mode w and file permissions 777' do
|
82
|
+
it 'should create the file with the correct permissions 755' do
|
83
|
+
Kernel.open(@new_file_name, 'w', 0o777)
|
84
|
+
expect(File.stat(@new_file_name).mode.to_s(8)[3..5]).to eq('755')
|
85
|
+
File.delete(@new_file_name)
|
86
|
+
|
87
|
+
open(@new_file_name, 'w', 0o777)
|
88
|
+
expect(File.stat(@new_file_name).mode.to_s(8)[3..5]).to eq('755')
|
89
|
+
File.delete(@new_file_name)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
context 'with a filename blocked for read/write' do
|
94
|
+
before do |test|
|
95
|
+
unless test.metadata[:skip_before]
|
96
|
+
expect(TCellAgent).to receive(:policy).with(
|
97
|
+
TCellAgent::PolicyTypes::LFI
|
98
|
+
).and_return(@local_files_policy, @local_files_policy)
|
99
|
+
expect(@local_files_policy).to receive(:block_file_access?).and_return(true, true)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'should still be able to execute OS commands', :skip_before do
|
104
|
+
result = Kernel.open('|echo test').read
|
105
|
+
expect(result).to eq "test\n"
|
106
|
+
|
107
|
+
result = open('|echo test').read
|
108
|
+
expect(result).to eq "test\n"
|
109
|
+
end
|
110
|
+
context 'with a nonexistent filename with mode w' do
|
111
|
+
it 'should raise an error' do
|
112
|
+
expect do
|
113
|
+
Kernel.open(@new_file_name, 'w')
|
114
|
+
end.to raise_error(IOError)
|
115
|
+
|
116
|
+
expect do
|
117
|
+
open(@new_file_name, 'w')
|
118
|
+
end.to raise_error(IOError)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
context 'with a filename and mode w' do
|
122
|
+
it 'should raise an error' do
|
123
|
+
expect do
|
124
|
+
Kernel.open(@new_file_name, 'w')
|
125
|
+
end.to raise_error(IOError)
|
126
|
+
|
127
|
+
expect do
|
128
|
+
open(@new_file_name, 'w')
|
129
|
+
end.to raise_error(IOError)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
context 'with a filename and mode a' do
|
133
|
+
it 'should raise an error' do
|
134
|
+
expect do
|
135
|
+
Kernel.open(@new_file_name, 'a')
|
136
|
+
end.to raise_error(IOError)
|
137
|
+
|
138
|
+
expect do
|
139
|
+
open(@new_file_name, 'a')
|
140
|
+
end.to raise_error(IOError)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe '::gets and #gets' do
|
147
|
+
context 'with a filename not blocked for read/write' do
|
148
|
+
it 'should still be able to read the file' do
|
149
|
+
expect(TCellAgent).to receive(:policy).with(
|
150
|
+
TCellAgent::PolicyTypes::LFI
|
151
|
+
).and_return(@local_files_policy, @local_files_policy, @local_files_policy, @local_files_policy)
|
152
|
+
expect(@local_files_policy).to receive(:block_file_access?).and_return(false, false, false, false)
|
153
|
+
|
154
|
+
copy = Array.new(ARGV)
|
155
|
+
ARGV.clear
|
156
|
+
ARGV << @filename
|
157
|
+
result = gets
|
158
|
+
result << gets
|
159
|
+
ARGV.replace(copy)
|
160
|
+
expect(result).to eq @file_contents
|
161
|
+
|
162
|
+
copy = Array.new(ARGV)
|
163
|
+
ARGV.clear
|
164
|
+
ARGV << @filename
|
165
|
+
result = Kernel.gets
|
166
|
+
result << Kernel.gets
|
167
|
+
ARGV.replace(copy)
|
168
|
+
expect(result).to eq @file_contents
|
169
|
+
end
|
170
|
+
end
|
171
|
+
context 'with a filename blocked for read/write' do
|
172
|
+
it 'should not be able to read the file' do
|
173
|
+
expect(TCellAgent).to receive(:policy).with(
|
174
|
+
TCellAgent::PolicyTypes::LFI
|
175
|
+
).and_return(@local_files_policy, @local_files_policy)
|
176
|
+
expect(@local_files_policy).to receive(:block_file_access?).and_return(true, true)
|
177
|
+
|
178
|
+
copy = Array.new(ARGV)
|
179
|
+
ARGV.clear
|
180
|
+
ARGV << @filename
|
181
|
+
expect do
|
182
|
+
result = gets
|
183
|
+
end.to raise_error(IOError)
|
184
|
+
ARGV.replace(copy)
|
185
|
+
|
186
|
+
copy = Array.new(ARGV)
|
187
|
+
ARGV.clear
|
188
|
+
ARGV << @filename
|
189
|
+
expect do
|
190
|
+
result = Kernel.gets
|
191
|
+
end.to raise_error(IOError)
|
192
|
+
ARGV.replace(copy)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
describe '::readline and #readline' do
|
198
|
+
context 'with a filename not blocked for read/write' do
|
199
|
+
it 'should be able to read the file' do
|
200
|
+
expect(TCellAgent).to receive(:policy).with(
|
201
|
+
TCellAgent::PolicyTypes::LFI
|
202
|
+
).and_return(@local_files_policy, @local_files_policy, @local_files_policy, @local_files_policy)
|
203
|
+
expect(@local_files_policy).to receive(:block_file_access?).and_return(false, false, false, false)
|
204
|
+
|
205
|
+
copy = Array.new(ARGV)
|
206
|
+
ARGV.clear
|
207
|
+
ARGV << @filename
|
208
|
+
result = readline
|
209
|
+
result << readline
|
210
|
+
ARGV.replace(copy)
|
211
|
+
expect(result).to eq @file_contents
|
212
|
+
|
213
|
+
result = ''
|
214
|
+
copy = Array.new(ARGV)
|
215
|
+
ARGV.clear
|
216
|
+
ARGV << @filename
|
217
|
+
result = Kernel.readline
|
218
|
+
result << Kernel.readline
|
219
|
+
ARGV.replace(copy)
|
220
|
+
expect(result).to eq @file_contents
|
221
|
+
end
|
222
|
+
end
|
223
|
+
context 'with a filename blocked for read' do
|
224
|
+
it 'should not be able to read the file' do
|
225
|
+
expect(TCellAgent).to receive(:policy).with(
|
226
|
+
TCellAgent::PolicyTypes::LFI
|
227
|
+
).and_return(@local_files_policy, @local_files_policy)
|
228
|
+
expect(@local_files_policy).to receive(:block_file_access?).and_return(true, true)
|
229
|
+
|
230
|
+
expect do
|
231
|
+
copy = Array.new(ARGV)
|
232
|
+
ARGV.clear
|
233
|
+
ARGV << @filename
|
234
|
+
Kernel.readline
|
235
|
+
ARGV.replace(copy)
|
236
|
+
end.to raise_error(IOError)
|
237
|
+
expect do
|
238
|
+
copy = Array.new(ARGV)
|
239
|
+
ARGV.clear
|
240
|
+
ARGV << @filename
|
241
|
+
Kernel.readline
|
242
|
+
ARGV.replace(copy)
|
243
|
+
end.to raise_error(IOError)
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
247
|
+
end
|
248
|
+
# rubocop:enable Security/Open
|
249
|
+
# rubocop:enable Lint/UselessAssignment
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module TCellAgent
|
4
|
+
module Instrumentation
|
5
|
+
module Lfi
|
6
|
+
describe 'extract path and mode' do
|
7
|
+
context 'with path' do
|
8
|
+
it 'should extract the path correctly' do
|
9
|
+
args = '/path-to-file'
|
10
|
+
path, _mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(args)
|
11
|
+
expect(path).to eq(File.expand_path('/path-to-file'))
|
12
|
+
end
|
13
|
+
it 'should default to read mode' do
|
14
|
+
args = '/path-to-file'
|
15
|
+
_path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(args)
|
16
|
+
expect(mode).to eq('Read')
|
17
|
+
end
|
18
|
+
it 'should not expand paths starting with |' do
|
19
|
+
args = '|cat /etc/passwd'
|
20
|
+
path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(args)
|
21
|
+
expect(path).to eq('')
|
22
|
+
expect(mode).to eq('')
|
23
|
+
end
|
24
|
+
it 'should not expand paths starting with |-' do
|
25
|
+
args = '|-'
|
26
|
+
path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(args)
|
27
|
+
expect(path).to eq('')
|
28
|
+
expect(mode).to eq('')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
context 'with path and mode' do
|
32
|
+
context 'with a valid mode' do
|
33
|
+
it 'should return Read for mode r' do
|
34
|
+
args = '/path-to-file', 'r'
|
35
|
+
_path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(*args)
|
36
|
+
expect(mode).to eq('Read')
|
37
|
+
end
|
38
|
+
it 'should return Write for mode w' do
|
39
|
+
args = '/path-to-file', 'w'
|
40
|
+
_path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(*args)
|
41
|
+
expect(mode).to eq('Write')
|
42
|
+
end
|
43
|
+
it 'should return Write for mode a' do
|
44
|
+
args = '/path-to-file', 'a'
|
45
|
+
_path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(*args)
|
46
|
+
expect(mode).to eq('Write')
|
47
|
+
end
|
48
|
+
it 'should return ReadWrite for mode r+' do
|
49
|
+
args = '/path-to-file', 'r+'
|
50
|
+
_path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(*args)
|
51
|
+
expect(mode).to eq('ReadWrite')
|
52
|
+
end
|
53
|
+
it 'should return ReadWrite for mode w+' do
|
54
|
+
args = '/path-to-file', 'w+'
|
55
|
+
_path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(*args)
|
56
|
+
expect(mode).to eq('ReadWrite')
|
57
|
+
end
|
58
|
+
it 'should return ReadWrite for mode a+' do
|
59
|
+
args = '/path-to-file', 'a+'
|
60
|
+
_path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(*args)
|
61
|
+
expect(mode).to eq('ReadWrite')
|
62
|
+
end
|
63
|
+
it 'should return Read for mode ::File::RDONLY (0)' do
|
64
|
+
args = '/path-to-file', ::File::RDONLY
|
65
|
+
_path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(*args)
|
66
|
+
expect(mode).to eq('Read')
|
67
|
+
end
|
68
|
+
it 'should return Write for mode ::File::WRONLY (1)' do
|
69
|
+
args = '/path-to-file', ::File::WRONLY
|
70
|
+
_path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(*args)
|
71
|
+
expect(mode).to eq('Write')
|
72
|
+
end
|
73
|
+
it 'should return ReadWrite for mode ::File::RDWR (2)' do
|
74
|
+
args = '/path-to-file', ::File::RDWR
|
75
|
+
_path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(*args)
|
76
|
+
expect(mode).to eq('ReadWrite')
|
77
|
+
end
|
78
|
+
it 'should return Write for mode ::File::CREAT | ::File::EXCL | ::File::WRONLY (2561)' do
|
79
|
+
args = '/path-to-file', ::File::CREAT | ::File::EXCL | ::File::WRONLY
|
80
|
+
_path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(*args)
|
81
|
+
expect(mode).to eq('Write')
|
82
|
+
end
|
83
|
+
end
|
84
|
+
context 'with an invalid mode' do
|
85
|
+
it 'should return Read when mode is a random string' do
|
86
|
+
args = '/path-to-file', 'mode'
|
87
|
+
_path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(*args)
|
88
|
+
expect(mode).to eq('Read')
|
89
|
+
end
|
90
|
+
it 'should return Read when mode is a hash' do
|
91
|
+
args = '/path-to-file', {}
|
92
|
+
_path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(*args)
|
93
|
+
expect(mode).to eq('Read')
|
94
|
+
end
|
95
|
+
it 'should return Read when mode is an array' do
|
96
|
+
args = '/path-to-file', []
|
97
|
+
_path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(*args)
|
98
|
+
expect(mode).to eq('Read')
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -4,19 +4,11 @@ module TCellAgent
|
|
4
4
|
module Instrumentation
|
5
5
|
describe '.block?' do
|
6
6
|
before(:each) do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
'api_key' => 'api_key',
|
12
|
-
'allow_payloads' => true,
|
13
|
-
'js_agent_api_base_url' => 'http://api.tcell.com/',
|
14
|
-
'js_agent_url' => 'https://jsagent.tcell.io/tcellagent.min.js',
|
15
|
-
'max_csp_header_bytes' => nil
|
16
|
-
}
|
7
|
+
native_agent = double('native_agent')
|
8
|
+
@patches_policy = TCellAgent::Policies::PatchesPolicy.new(
|
9
|
+
native_agent,
|
10
|
+
{}
|
17
11
|
)
|
18
|
-
expect(TCellAgent).to receive(:configuration).and_return(configuration).at_least(:once)
|
19
|
-
@rust_policies = TCellAgent::Policies::RustPolicies.new
|
20
12
|
end
|
21
13
|
|
22
14
|
context 'with an unexpected error' do
|
@@ -24,24 +16,14 @@ module TCellAgent
|
|
24
16
|
logger = double('logger')
|
25
17
|
request = double('request')
|
26
18
|
expect(TCellAgent).to receive(:policy).with(
|
27
|
-
TCellAgent::PolicyTypes::
|
19
|
+
TCellAgent::PolicyTypes::PATCHES
|
28
20
|
).and_raise(StandardError.new('UNEXPECTED'))
|
29
|
-
expect(TCellAgent::MetaData).to_not receive(:
|
30
|
-
expect(TCellAgent).to receive(:
|
31
|
-
expect(logger).to receive(:
|
32
|
-
'
|
21
|
+
expect(TCellAgent::MetaData).to_not receive(:for_patches)
|
22
|
+
expect(TCellAgent::Instrumentation).to receive(:get_safe_block_logger).and_return(logger)
|
23
|
+
expect(logger).to receive(:error).with(
|
24
|
+
'Error Checking patches blocking (StandardError): UNEXPECTED'
|
33
25
|
)
|
34
|
-
expect(logger).to receive(:
|
35
|
-
|
36
|
-
expect(Patches.block?(request)).to eq(false)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
context 'with an empty patches policy' do
|
41
|
-
it 'should return false' do
|
42
|
-
request = double('request')
|
43
|
-
expect(TCellAgent).to receive(:policy).and_return(nil)
|
44
|
-
expect(TCellAgent::MetaData).to_not receive(:from_request)
|
26
|
+
expect(logger).to receive(:exception) # exception stack trace
|
45
27
|
|
46
28
|
expect(Patches.block?(request)).to eq(false)
|
47
29
|
end
|
@@ -50,10 +32,10 @@ module TCellAgent
|
|
50
32
|
context 'with a disabled patches policy' do
|
51
33
|
it 'should return false' do
|
52
34
|
request = double('request')
|
53
|
-
expect(@
|
35
|
+
expect(@patches_policy.enabled).to eq(false)
|
54
36
|
|
55
|
-
expect(TCellAgent).to receive(:policy).and_return(@
|
56
|
-
expect(TCellAgent::MetaData).to_not receive(:
|
37
|
+
expect(TCellAgent).to receive(:policy).and_return(@patches_policy)
|
38
|
+
expect(TCellAgent::MetaData).to_not receive(:for_patches)
|
57
39
|
|
58
40
|
expect(Patches.block?(request)).to eq(false)
|
59
41
|
end
|
@@ -65,15 +47,15 @@ module TCellAgent
|
|
65
47
|
meta_data = double('meta_data')
|
66
48
|
tcell_context = TCellAgent::Instrumentation::TCellData.new
|
67
49
|
|
68
|
-
expect(TCellAgent).to receive(:policy).and_return(@
|
69
|
-
expect(@
|
70
|
-
expect(@
|
50
|
+
expect(TCellAgent).to receive(:policy).and_return(@patches_policy)
|
51
|
+
expect(@patches_policy).to receive(:enabled).and_return(true)
|
52
|
+
expect(@patches_policy).to receive(:block_request?).and_return(false)
|
71
53
|
expect(request).to receive(:env).and_return(
|
72
54
|
{
|
73
55
|
TCellAgent::Instrumentation::TCELL_ID => tcell_context
|
74
56
|
}
|
75
57
|
)
|
76
|
-
expect(TCellAgent::MetaData).to receive(:
|
58
|
+
expect(TCellAgent::MetaData).to receive(:for_patches).and_return(
|
77
59
|
meta_data
|
78
60
|
)
|
79
61
|
|
@@ -89,10 +71,10 @@ module TCellAgent
|
|
89
71
|
tcell_context = TCellAgent::Instrumentation::TCellData.new
|
90
72
|
expect(tcell_context.patches_blocking_triggered).to eq(false)
|
91
73
|
|
92
|
-
expect(TCellAgent).to receive(:policy).and_return(@
|
93
|
-
expect(@
|
94
|
-
expect(@
|
95
|
-
expect(TCellAgent::MetaData).to receive(:
|
74
|
+
expect(TCellAgent).to receive(:policy).and_return(@patches_policy)
|
75
|
+
expect(@patches_policy).to receive(:enabled).and_return(true)
|
76
|
+
expect(@patches_policy).to receive(:block_request?).and_return(true)
|
77
|
+
expect(TCellAgent::MetaData).to receive(:for_patches).and_return(
|
96
78
|
meta_data
|
97
79
|
)
|
98
80
|
expect(request).to receive(:env).and_return({ TCellAgent::Instrumentation::TCELL_ID => tcell_context })
|
@@ -119,10 +101,10 @@ module TCellAgent
|
|
119
101
|
|
120
102
|
expect(tcell_context.patches_blocking_triggered).to eq(false)
|
121
103
|
|
122
|
-
expect(TCellAgent).to receive(:policy).and_return(@
|
123
|
-
expect(@
|
124
|
-
expect(@
|
125
|
-
expect(TCellAgent::MetaData).to receive(:
|
104
|
+
expect(TCellAgent).to receive(:policy).and_return(@patches_policy)
|
105
|
+
expect(@patches_policy).to receive(:enabled).and_return(true)
|
106
|
+
expect(@patches_policy).to receive(:block_request?).and_return(true)
|
107
|
+
expect(TCellAgent::MetaData).to receive(:for_patches).and_return(
|
126
108
|
meta_data
|
127
109
|
)
|
128
110
|
expect(request).to receive(:env).and_return({ TCellAgent::Instrumentation::TCELL_ID => tcell_context })
|