tcell_agent 2.2.1 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +2 -2
  3. data/bin/tcell_agent +6 -11
  4. data/lib/tcell_agent/agent.rb +18 -13
  5. data/lib/tcell_agent/config_initializer.rb +2 -5
  6. data/lib/tcell_agent/configuration.rb +6 -6
  7. data/lib/tcell_agent/hooks/login_fraud.rb +1 -1
  8. data/lib/tcell_agent/instrumentation/cmdi.rb +32 -0
  9. data/lib/tcell_agent/instrumentation/lfi.rb +55 -9
  10. data/lib/tcell_agent/instrumentation/monkey_patches/ruby_2/file.rb +21 -0
  11. data/lib/tcell_agent/instrumentation/monkey_patches/ruby_2/io.rb +75 -0
  12. data/lib/tcell_agent/instrumentation/monkey_patches/ruby_2/kernel.rb +80 -0
  13. data/lib/tcell_agent/instrumentation/monkey_patches/ruby_3/file.rb +21 -0
  14. data/lib/tcell_agent/instrumentation/monkey_patches/ruby_3/io.rb +75 -0
  15. data/lib/tcell_agent/instrumentation/monkey_patches/ruby_3/kernel.rb +80 -0
  16. data/lib/tcell_agent/instrumentation.rb +14 -6
  17. data/lib/tcell_agent/logger.rb +2 -2
  18. data/lib/tcell_agent/policies/dataloss_policy.rb +15 -8
  19. data/lib/tcell_agent/policies/headers_policy.rb +2 -2
  20. data/lib/tcell_agent/policies/patches_policy.rb +8 -4
  21. data/lib/tcell_agent/policies/policies_manager.rb +1 -0
  22. data/lib/tcell_agent/policies/policy_polling.rb +4 -3
  23. data/lib/tcell_agent/rails/auth/doorkeeper.rb +1 -0
  24. data/lib/tcell_agent/rails/better_ip.rb +7 -19
  25. data/lib/tcell_agent/rails/dlp/process_request.rb +5 -0
  26. data/lib/tcell_agent/rails/dlp.rb +48 -48
  27. data/lib/tcell_agent/rails/dlp_handler.rb +9 -10
  28. data/lib/tcell_agent/rails/js_agent_insert.rb +2 -3
  29. data/lib/tcell_agent/rails/middleware/context_middleware.rb +2 -1
  30. data/lib/tcell_agent/rails/middleware/global_middleware.rb +1 -5
  31. data/lib/tcell_agent/rails/middleware/headers_middleware.rb +1 -0
  32. data/lib/tcell_agent/rails/routes/grape.rb +2 -1
  33. data/lib/tcell_agent/rails/settings_reporter.rb +3 -6
  34. data/lib/tcell_agent/rails/tcell_body_proxy.rb +4 -6
  35. data/lib/tcell_agent/routes/table.rb +3 -0
  36. data/lib/tcell_agent/rust/agent_config.rb +20 -2
  37. data/lib/tcell_agent/rust/{libtcellagent-5.0.2.so → libtcellagent-alpine.so} +0 -0
  38. data/lib/tcell_agent/rust/{tcellagent-5.0.2.dll → libtcellagent-x64.dll} +0 -0
  39. data/lib/tcell_agent/rust/{libtcellagent-5.0.2.dylib → libtcellagent.dylib} +0 -0
  40. data/lib/tcell_agent/rust/{libtcellagent-alpine-5.0.2.so → libtcellagent.so} +0 -0
  41. data/lib/tcell_agent/rust/native_agent.rb +51 -59
  42. data/lib/tcell_agent/rust/native_library.rb +7 -10
  43. data/lib/tcell_agent/sensor_events/server_agent.rb +3 -100
  44. data/lib/tcell_agent/sensor_events/util/sanitizer_utilities.rb +1 -0
  45. data/lib/tcell_agent/servers/puma.rb +25 -8
  46. data/lib/tcell_agent/servers/rack_puma_handler.rb +13 -3
  47. data/lib/tcell_agent/servers/webrick.rb +13 -3
  48. data/lib/tcell_agent/settings_reporter.rb +0 -14
  49. data/lib/tcell_agent/sinatra.rb +1 -0
  50. data/lib/tcell_agent/tcell_context.rb +15 -6
  51. data/lib/tcell_agent/utils/headers.rb +0 -1
  52. data/lib/tcell_agent/utils/strings.rb +2 -2
  53. data/lib/tcell_agent/version.rb +1 -1
  54. data/spec/cruby_spec_helper.rb +26 -0
  55. data/spec/lib/tcell_agent/instrument_servers_spec.rb +1 -1
  56. data/spec/lib/tcell_agent/instrumentation/cmdi/io_cmdi_spec.rb +2 -2
  57. data/spec/lib/tcell_agent/instrumentation/lfi/file_lfi_spec.rb +211 -272
  58. data/spec/lib/tcell_agent/instrumentation/lfi/io_lfi_spec.rb +207 -223
  59. data/spec/lib/tcell_agent/instrumentation/lfi/kernel_lfi_spec.rb +89 -70
  60. data/spec/lib/tcell_agent/instrumentation/lfi_spec.rb +73 -0
  61. data/spec/lib/tcell_agent/patches_spec.rb +2 -1
  62. data/spec/lib/tcell_agent/policies/clickjacking_policy_spec.rb +1 -2
  63. data/spec/lib/tcell_agent/policies/content_security_policy_spec.rb +5 -6
  64. data/spec/lib/tcell_agent/policies/patches_policy_spec.rb +21 -2
  65. data/spec/lib/tcell_agent/policies/policies_manager_spec.rb +1 -1
  66. data/spec/lib/tcell_agent/policies/secure_headers_policy_spec.rb +13 -8
  67. data/spec/lib/tcell_agent/rails/better_ip_spec.rb +9 -11
  68. data/spec/lib/tcell_agent/rails/csrf_exception_spec.rb +6 -6
  69. data/spec/lib/tcell_agent/rails/dlp_spec.rb +1 -0
  70. data/spec/lib/tcell_agent/rails/js_agent_insert_spec.rb +10 -2
  71. data/spec/lib/tcell_agent/rails/middleware/tcell_body_proxy_spec.rb +2 -1
  72. data/spec/lib/tcell_agent/rails/routes/route_id_spec.rb +4 -4
  73. data/spec/lib/tcell_agent/settings_reporter_spec.rb +2 -16
  74. data/spec/lib/tcell_agent/tcell_context_spec.rb +6 -5
  75. data/spec/spec_helper.rb +3 -1
  76. data/spec/support/builders.rb +2 -1
  77. data/spec/support/server_mocks/puma_mock.rb +4 -0
  78. data/spec/support/shared_spec.rb +29 -0
  79. data/tcell_agent.gemspec +14 -14
  80. metadata +23 -19
  81. data/Rakefile +0 -18
  82. data/lib/tcell_agent/instrumentation/monkey_patches/file.rb +0 -25
  83. data/lib/tcell_agent/instrumentation/monkey_patches/io.rb +0 -131
  84. data/lib/tcell_agent/instrumentation/monkey_patches/kernel.rb +0 -102
data/Rakefile DELETED
@@ -1,18 +0,0 @@
1
- require 'rspec/core/rake_task'
2
-
3
- RSpec::Core::RakeTask.new(:spec)
4
-
5
- desc 'Run tests'
6
- task :default => [:spec]
7
- task :test => :spec
8
-
9
- task 'init-integration-tests' do
10
- system('docker-compose run railsintegration224 bundle install')
11
- system('docker-compose run railsintegration224 bundle exec rake db:create db:setup')
12
- system('docker-compose stop')
13
- end
14
-
15
- task 'integration-test' do
16
- system('docker-compose up railsintegration224')
17
- system('docker-compose stop')
18
- 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,102 +0,0 @@
1
- module Kernel
2
- private
3
-
4
- alias_method :tcell_original_backtick, :`
5
- alias_method :tcell_original_exec, :exec
6
- alias_method :tcell_original_open, :open
7
- alias_method :tcell_original_gets, :gets
8
- alias_method :tcell_original_readline, :readline
9
- alias_method :tcell_original_spawn, :spawn
10
- alias_method :tcell_original_system, :system
11
-
12
- class << self
13
- alias_method :tcell_original_exec, :exec
14
- alias_method :tcell_original_open, :open
15
- alias_method :tcell_original_gets, :gets
16
- alias_method :tcell_original_readline, :readline
17
- alias_method :tcell_original_spawn, :spawn
18
- alias_method :tcell_original_system, :system
19
- end
20
-
21
- def `(cmd)
22
- if TCellAgent::Cmdi.block_command?(cmd)
23
- raise "tCell.io Agent: Command not allowed by policy: #{cmd}"
24
- end
25
-
26
- tcell_original_backtick(cmd)
27
- end
28
-
29
- if TCellAgent.configuration.should_instrument?('kernel_exec')
30
- def exec(*args)
31
- cmd = TCellAgent::Cmdi.parse_command(*args)
32
- if TCellAgent::Cmdi.block_command?(cmd)
33
- raise "tCell.io Agent: Command not allowed by policy: #{cmd}"
34
- end
35
-
36
- tcell_original_exec(*args)
37
- end
38
- end
39
-
40
- def gets(*args, &block)
41
- path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode_argf
42
-
43
- if TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode)
44
- raise IOError, "tCell.io Agent: Attempted access to file #{path} with mode #{mode} denied"
45
- end
46
-
47
- tcell_original_gets(*args, &block)
48
- end
49
-
50
- def open(*args, &block)
51
- path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(*args)
52
-
53
- if !path.strip.empty? && TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode)
54
- raise IOError, "tCell.io Agent: Attempted access to file #{path} with mode #{mode} denied"
55
- end
56
-
57
- if path.empty?
58
- cmd = TCellAgent::Cmdi.parse_command_from_open(*args)
59
- if cmd && TCellAgent::Cmdi.block_command?(cmd)
60
- raise "tCell.io Agent: Command not allowed by policy: #{cmd}"
61
- end
62
- end
63
-
64
- tcell_original_open(*args, &block)
65
- end
66
-
67
- def readline(*args, &block)
68
- path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode_argf
69
-
70
- if TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode)
71
- raise IOError, "tCell.io Agent: Attempted access to file #{path} with mode #{mode} denied"
72
- end
73
-
74
- tcell_original_readline(*args, &block)
75
- end
76
-
77
- def spawn(*args)
78
- cmd = TCellAgent::Cmdi.parse_command(*args)
79
- if TCellAgent::Cmdi.block_command?(cmd)
80
- raise "tCell.io Agent: Command not allowed by policy: #{cmd}"
81
- end
82
-
83
- tcell_original_spawn(*args)
84
- end
85
-
86
- def system(*args)
87
- cmd = TCellAgent::Cmdi.parse_command(*args)
88
- if TCellAgent::Cmdi.block_command?(cmd)
89
- raise "tCell.io Agent: Command not allowed by policy: #{cmd}"
90
- end
91
-
92
- tcell_original_system(*args)
93
- end
94
-
95
- module_function :`
96
- module_function :exec
97
- module_function :gets
98
- module_function :open
99
- module_function :readline
100
- module_function :spawn
101
- module_function :system
102
- end