tcell_agent 2.0.0 → 2.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b0b98e0366f6de14a287a83e13f08a0b5fdc9f13d12d8c6d1f0a2fa7f1caad9c
4
- data.tar.gz: 88cfc253d06f635d54ab72d83e4d3a28829526c3df47e2e1e7cad19fd47c9293
3
+ metadata.gz: 9d37df3ff2819b9794d9bde01418437c3efed75358fa58f4f65d80ea4f63e7b8
4
+ data.tar.gz: 97efa888f4adf090f13fa5bc0597a91ea981ad299062d3dbd267ed4216b18ba8
5
5
  SHA512:
6
- metadata.gz: 04c30f374634daf21590a07f94e3ea27cf09cd6931570b43a215f8d424983a86519c393faad76f7c809580dc9a02a905de00e6e28c4017d789b7baa6b86c5a3f
7
- data.tar.gz: 39119777a798add18175e51c5935fb08d8ea85f2cde16d237e87f9175f477d9d3333cf91e4cecf089b39b355db31052a5047a444a420ea778e505631952be623
6
+ metadata.gz: 0f77740a99dd8678ca62a5ccf7e0e69304e680a8fa65258105c101ec360413920afcfea4d6e03237e1c6893198fa6232133ab05111bb2b0341586635db43a9bd
7
+ data.tar.gz: c980a3e122b6453e3660358a2ba6a2bbe86179a9f54ca09e34135c8e9f86eb6498ebd8346dbf28b117f2f0b160bc23338b80502dc6c07c28d0b3b03472756a39
@@ -50,7 +50,7 @@ module TCellAgent
50
50
  args_copy = Array.new(args)
51
51
  first_arg = args_copy.shift
52
52
 
53
- cmd = first_arg[1..-1] if first_arg && first_arg[0] == '|'
53
+ cmd = first_arg[1..-1] if first_arg && (first_arg.is_a? String) && first_arg[0] == '|'
54
54
  end
55
55
  end
56
56
 
@@ -32,12 +32,12 @@ module TCellAgent
32
32
  args_copy = Array.new(args)
33
33
  path = args_copy.shift
34
34
  mode = args_copy.shift || 'r'
35
- end
36
35
 
37
- if path && path.to_s[0] != '|'
38
- [File.expand_path(path).to_s, convert_mode(mode)]
39
- else
40
- ['', '']
36
+ if path && path.to_s[0] != '|'
37
+ [File.expand_path(path).to_s, convert_mode(mode)]
38
+ else
39
+ ['', '']
40
+ end
41
41
  end
42
42
  end
43
43
 
@@ -52,10 +52,10 @@ module TCellAgent
52
52
  else
53
53
  path = ARGF.filename
54
54
  end
55
- end
56
55
 
57
- path = File.expand_path(path) unless path.nil?
58
- [path.to_s, mode]
56
+ path = File.expand_path(path) unless path.nil?
57
+ [path.to_s, mode]
58
+ end
59
59
  end
60
60
 
61
61
  def self.convert_mode(mode)
@@ -4,12 +4,15 @@ class IO
4
4
  def binread(*args, &block)
5
5
  path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(*args)
6
6
 
7
- if path && TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode)
7
+ if !path.strip.empty? && TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode)
8
8
  raise IOError, "tCell.io Agent: Attempted access to file #{path} with mode #{mode} denied"
9
9
  end
10
- cmd = TCellAgent::Cmdi.parse_command_from_open(*args)
11
- if cmd && TCellAgent::Cmdi.block_command?(cmd)
12
- raise "tCell.io Agent: Command not allowed by policy: #{cmd}"
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
13
16
  end
14
17
 
15
18
  tcell_original_binread(*args, &block)
@@ -69,14 +72,17 @@ class IO
69
72
  path, _mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(*args)
70
73
  mode = 'Read'
71
74
 
72
- if path && TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode)
75
+ if !path.strip.empty? && TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode)
73
76
  raise IOError, "tCell.io Agent: Attempted access to file #{path} with mode #{mode} denied"
74
77
  end
75
78
 
76
- cmd = TCellAgent::Cmdi.parse_command_from_open(*args)
77
- if cmd && TCellAgent::Cmdi.block_command?(cmd)
78
- raise "tCell.io Agent: Command not allowed by policy: #{cmd}"
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
79
84
  end
85
+
80
86
  tcell_original_read(*args, &block)
81
87
  end
82
88
 
@@ -85,13 +91,15 @@ class IO
85
91
  path, _mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(*args)
86
92
  mode = 'Read'
87
93
 
88
- if path && TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode)
94
+ if !path.strip.empty? && TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode)
89
95
  raise IOError, "tCell.io Agent: Attempted access to file #{path} with mode #{mode} denied"
90
96
  end
91
97
 
92
- cmd = TCellAgent::Cmdi.parse_command_from_open(*args)
93
- if cmd && TCellAgent::Cmdi.block_command?(cmd)
94
- raise "tCell.io Agent: Command not allowed by policy: #{cmd}"
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
95
103
  end
96
104
 
97
105
  tcell_original_readlines(*args, &block)
@@ -4,13 +4,15 @@ module Kernel
4
4
  def open(*args, &block)
5
5
  path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(*args)
6
6
 
7
- if path && TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode)
7
+ if !path.strip.empty? && TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode)
8
8
  raise IOError, "tCell.io Agent: Attempted access to file #{path} with mode #{mode} denied"
9
9
  end
10
10
 
11
- cmd = TCellAgent::Cmdi.parse_command_from_open(*args)
12
- if cmd && TCellAgent::Cmdi.block_command?(cmd)
13
- raise "tCell.io Agent: Command not allowed by policy: #{cmd}"
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
14
16
  end
15
17
 
16
18
  tcell_original_1_open(*args, &block)
@@ -72,13 +74,15 @@ module Kernel
72
74
  def open(*args, &block)
73
75
  path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(*args)
74
76
 
75
- if path && TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode)
77
+ if !path.strip.empty? && TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode)
76
78
  raise IOError, "tCell.io Agent: Attempted access to file #{path} with mode #{mode} denied"
77
79
  end
78
80
 
79
- cmd = TCellAgent::Cmdi.parse_command_from_open(*args)
80
- if cmd && TCellAgent::Cmdi.block_command?(cmd)
81
- raise "tCell.io Agent: Command not allowed by policy: #{cmd}"
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
82
86
  end
83
87
 
84
88
  tcell_original_2_open(*args, &block)
@@ -15,7 +15,7 @@ module TCellAgent
15
15
  end
16
16
 
17
17
  def block_command?(command, tcell_context)
18
- return false unless @enabled
18
+ return false unless @enabled && tcell_context
19
19
 
20
20
  response = @native_agent.apply_cmdi(
21
21
  command, tcell_context
@@ -228,9 +228,15 @@ module TCellAgent
228
228
  )
229
229
  tcell_data = request_env[TCellAgent::Instrumentation::TCELL_ID]
230
230
  if tcell_data && result.is_a?(ActiveRecord::StatementInvalid)
231
- tcell_data.sql_exceptions.push(
232
- { 'exception_name' => result.class.name, 'exception_payload' => message }
233
- )
231
+ if message.is_a? Hash
232
+ tcell_data.sql_exceptions.push(
233
+ { 'exception_name' => result.class.name, 'exception_payload' => message[:message] }
234
+ )
235
+ else
236
+ tcell_data.sql_exceptions.push(
237
+ { 'exception_name' => result.class.name, 'exception_payload' => message }
238
+ )
239
+ end
234
240
  end
235
241
  end
236
242
  end
@@ -253,7 +259,7 @@ module TCellAgent
253
259
  end
254
260
 
255
261
  ActiveRecord::Querying.module_eval do
256
- if ::Rails::VERSION::MAJOR == 5
262
+ if ::Rails::VERSION::MAJOR >= 5
257
263
  alias_method :tcell_find_by_sql, :find_by_sql
258
264
  def find_by_sql(*args)
259
265
  results = tcell_find_by_sql(*args)
@@ -77,7 +77,7 @@ module TCellAgent
77
77
  end
78
78
 
79
79
  def self.create_tcell_route(route)
80
- return TCellRoute5.new(route) if route && ::Rails::VERSION::MAJOR == 5
80
+ return TCellRoute5.new(route) if route && ::Rails::VERSION::MAJOR >= 5
81
81
  return TCellRoute4.new(route) if route && ::Rails::VERSION::MAJOR < 5
82
82
 
83
83
  TCellRoute.new
@@ -173,7 +173,7 @@ module TCellAgent
173
173
  end
174
174
  end
175
175
 
176
- if ::Rails::VERSION::MAJOR == 5
176
+ if ::Rails::VERSION::MAJOR >= 5
177
177
  ActionDispatch::Journey::Routes.class_eval do
178
178
  alias_method :tcell_add_route, :add_route
179
179
  def add_route(name, mapping)
@@ -188,7 +188,7 @@ module TCellAgent
188
188
  end
189
189
  end
190
190
 
191
- if ::Rails::VERSION::MAJOR == 5 || (::Rails::VERSION::MAJOR == 4 && ::Rails::VERSION::MINOR >= 2)
191
+ if ::Rails::VERSION::MAJOR >= 5 || (::Rails::VERSION::MAJOR == 4 && ::Rails::VERSION::MINOR >= 2)
192
192
  ActionDispatch::Journey::Router.class_eval do
193
193
  alias_method :tcell_serve, :serve
194
194
  def serve(req)
@@ -6,7 +6,7 @@ module TCellAgent
6
6
  require 'ffi'
7
7
  extend FFI::Library
8
8
 
9
- VERSION = '4.14.0'.freeze
9
+ VERSION = '4.17.1'.freeze
10
10
  prefix = 'lib'
11
11
  extension = '.so'
12
12
  variant = ''
@@ -1,5 +1,5 @@
1
1
  # See the file "LICENSE" for the full license governing this code.
2
2
 
3
3
  module TCellAgent
4
- VERSION = '2.0.0'.freeze
4
+ VERSION = '2.1.0'.freeze
5
5
  end
@@ -147,5 +147,13 @@ module TCellAgent
147
147
  end
148
148
  end
149
149
  end
150
+ describe '.parse_command_from_open' do
151
+ context 'with string command' do
152
+ it 'should parse the command properly' do
153
+ cmd = TCellAgent::Cmdi.parse_command_from_open('|echo')
154
+ expect(cmd).to eq('echo')
155
+ end
156
+ end
157
+ end
150
158
  end
151
159
  end
@@ -42,6 +42,7 @@ describe 'IO' do
42
42
  TCellAgent::PolicyTypes::LFI
43
43
  ).and_return(@local_files_policy)
44
44
  expect(@local_files_policy).to receive(:block_file_access?).and_return(false)
45
+ expect(TCellAgent::Cmdi).not_to receive(:parse_command_from_open)
45
46
  end
46
47
  end
47
48
 
@@ -75,6 +76,7 @@ describe 'IO' do
75
76
  TCellAgent::PolicyTypes::LFI
76
77
  ).and_return(@local_files_policy)
77
78
  expect(@local_files_policy).to receive(:block_file_access?).and_return(true)
79
+ expect(TCellAgent::Cmdi).not_to receive(:parse_command_from_open)
78
80
  end
79
81
  end
80
82
 
@@ -254,6 +256,7 @@ describe 'IO' do
254
256
  ).and_return(@local_files_policy)
255
257
 
256
258
  expect(@local_files_policy).to receive(:block_file_access?).and_return(false)
259
+ expect(TCellAgent::Cmdi).not_to receive(:parse_command_from_open)
257
260
  end
258
261
  end
259
262
 
@@ -288,6 +291,7 @@ describe 'IO' do
288
291
  ).and_return(@local_files_policy)
289
292
 
290
293
  expect(@local_files_policy).to receive(:block_file_access?).and_return(true)
294
+ expect(TCellAgent::Cmdi).not_to receive(:parse_command_from_open)
291
295
  end
292
296
  end
293
297
 
@@ -338,6 +342,7 @@ describe 'IO' do
338
342
  ).and_return(@local_files_policy)
339
343
 
340
344
  expect(@local_files_policy).to receive(:block_file_access?).and_return(false)
345
+ expect(TCellAgent::Cmdi).not_to receive(:parse_command_from_open)
341
346
  end
342
347
  end
343
348
 
@@ -366,6 +371,7 @@ describe 'IO' do
366
371
  ).and_return(@local_files_policy)
367
372
 
368
373
  expect(@local_files_policy).to receive(:block_file_access?).and_return(true)
374
+ expect(TCellAgent::Cmdi).not_to receive(:parse_command_from_open)
369
375
  end
370
376
  end
371
377
 
@@ -2,6 +2,7 @@
2
2
  # rubocop:disable Lint/UselessAssignment
3
3
  require 'spec_helper'
4
4
  require 'securerandom'
5
+ require 'pathname'
5
6
 
6
7
  describe 'Kernel' do
7
8
  before do
@@ -15,6 +16,7 @@ describe 'Kernel' do
15
16
 
16
17
  before(:all) do
17
18
  @new_file_name = '/tmp/' + SecureRandom.uuid
19
+ @new_pathname = Pathname.new(@new_file_name)
18
20
  end
19
21
  describe '#open and ::open' do
20
22
  context 'empty path' do
@@ -39,13 +41,14 @@ describe 'Kernel' do
39
41
  end.to raise_error(Errno::ENOENT)
40
42
  end
41
43
  end
42
- context 'with a filename not blocked for read/write' do
44
+ context 'with a non-existent file, with filename not blocked for read/write' do
43
45
  before do |test|
44
46
  unless test.metadata[:skip_before]
45
47
  expect(TCellAgent).to receive(:policy).with(
46
48
  TCellAgent::PolicyTypes::LFI
47
49
  ).and_return(@local_files_policy, @local_files_policy)
48
50
  expect(@local_files_policy).to receive(:block_file_access?).and_return(false, false)
51
+ expect(TCellAgent::Cmdi).not_to receive(:parse_command_from_open)
49
52
  end
50
53
  end
51
54
 
@@ -56,7 +59,18 @@ describe 'Kernel' do
56
59
  result = open('|echo test').read
57
60
  expect(result).to eq "test\n"
58
61
  end
59
- context 'with a nonexistent filename with mode w' do
62
+ context 'with a pathname filename with mode w' do
63
+ it 'should create the file' do
64
+ Kernel.open(@new_pathname, 'w')
65
+ expect(File.exist?(@new_pathname)).to be_truthy
66
+ File.delete(@new_pathname)
67
+
68
+ open(@new_pathname, 'w')
69
+ expect(File.exist?(@new_pathname)).to be_truthy
70
+ File.delete(@new_pathname)
71
+ end
72
+ end
73
+ context 'with a filename with mode w' do
60
74
  it 'should create the file' do
61
75
  Kernel.open(@new_file_name, 'w')
62
76
  expect(File.exist?(@new_file_name)).to be_truthy
@@ -90,13 +104,14 @@ describe 'Kernel' do
90
104
  end
91
105
  end
92
106
  end
93
- context 'with a filename blocked for read/write' do
107
+ context 'with a non-existent file, with filename blocked for read/write' do
94
108
  before do |test|
95
109
  unless test.metadata[:skip_before]
96
110
  expect(TCellAgent).to receive(:policy).with(
97
111
  TCellAgent::PolicyTypes::LFI
98
112
  ).and_return(@local_files_policy, @local_files_policy)
99
113
  expect(@local_files_policy).to receive(:block_file_access?).and_return(true, true)
114
+ expect(TCellAgent::Cmdi).not_to receive(:parse_command_from_open)
100
115
  end
101
116
  end
102
117
 
@@ -107,7 +122,7 @@ describe 'Kernel' do
107
122
  result = open('|echo test').read
108
123
  expect(result).to eq "test\n"
109
124
  end
110
- context 'with a nonexistent filename with mode w' do
125
+ context 'with a filename with mode w' do
111
126
  it 'should raise an error' do
112
127
  expect do
113
128
  Kernel.open(@new_file_name, 'w')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tcell_agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafael
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-04 00:00:00.000000000 Z
11
+ date: 2020-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -162,14 +162,14 @@ files:
162
162
  - lib/tcell_agent/rails/tcell_body_proxy.rb
163
163
  - lib/tcell_agent/routes/table.rb
164
164
  - lib/tcell_agent/rust/agent_config.rb
165
- - lib/tcell_agent/rust/libtcellagent-4.14.0.dylib
166
- - lib/tcell_agent/rust/libtcellagent-4.14.0.so
167
- - lib/tcell_agent/rust/libtcellagent-alpine-4.14.0.so
165
+ - lib/tcell_agent/rust/libtcellagent-4.17.1.dylib
166
+ - lib/tcell_agent/rust/libtcellagent-4.17.1.so
167
+ - lib/tcell_agent/rust/libtcellagent-alpine-4.17.1.so
168
168
  - lib/tcell_agent/rust/models.rb
169
169
  - lib/tcell_agent/rust/native_agent.rb
170
170
  - lib/tcell_agent/rust/native_agent_response.rb
171
171
  - lib/tcell_agent/rust/native_library.rb
172
- - lib/tcell_agent/rust/tcellagent-4.14.0.dll
172
+ - lib/tcell_agent/rust/tcellagent-4.17.1.dll
173
173
  - lib/tcell_agent/sensor_events/agent_setting_event.rb
174
174
  - lib/tcell_agent/sensor_events/app_config_setting_event.rb
175
175
  - lib/tcell_agent/sensor_events/discovery.rb
@@ -192,12 +192,12 @@ files:
192
192
  - lib/tcell_agent/utils/params.rb
193
193
  - lib/tcell_agent/utils/strings.rb
194
194
  - lib/tcell_agent/version.rb
195
- - spec/lib/tcell_agent/cmdi_spec.rb
196
195
  - spec/lib/tcell_agent/config/unknown_options_spec.rb
197
196
  - spec/lib/tcell_agent/configuration_spec.rb
198
197
  - spec/lib/tcell_agent/hooks/login_fraud_spec.rb
199
198
  - spec/lib/tcell_agent/instrumentation/cmdi/io_cmdi_spec.rb
200
199
  - spec/lib/tcell_agent/instrumentation/cmdi/kernel_cmdi_spec.rb
200
+ - spec/lib/tcell_agent/instrumentation/cmdi_spec.rb
201
201
  - spec/lib/tcell_agent/instrumentation/lfi/file_lfi_spec.rb
202
202
  - spec/lib/tcell_agent/instrumentation/lfi/io_lfi_spec.rb
203
203
  - spec/lib/tcell_agent/instrumentation/lfi/kernel_lfi_spec.rb
@@ -266,12 +266,12 @@ signing_key:
266
266
  specification_version: 4
267
267
  summary: tCell.io Agent for Rails
268
268
  test_files:
269
- - spec/lib/tcell_agent/cmdi_spec.rb
270
269
  - spec/lib/tcell_agent/config/unknown_options_spec.rb
271
270
  - spec/lib/tcell_agent/configuration_spec.rb
272
271
  - spec/lib/tcell_agent/hooks/login_fraud_spec.rb
273
272
  - spec/lib/tcell_agent/instrumentation/cmdi/io_cmdi_spec.rb
274
273
  - spec/lib/tcell_agent/instrumentation/cmdi/kernel_cmdi_spec.rb
274
+ - spec/lib/tcell_agent/instrumentation/cmdi_spec.rb
275
275
  - spec/lib/tcell_agent/instrumentation/lfi/file_lfi_spec.rb
276
276
  - spec/lib/tcell_agent/instrumentation/lfi/io_lfi_spec.rb
277
277
  - spec/lib/tcell_agent/instrumentation/lfi/kernel_lfi_spec.rb