tcell_agent 2.3.0 → 2.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) 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 +4 -4
  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 +18 -0
  37. data/lib/tcell_agent/rust/{libtcellagent-alpine-6.2.1.so → libtcellagent-alpine.so} +0 -0
  38. data/lib/tcell_agent/rust/{tcellagent-6.2.1.dll → libtcellagent-x64.dll} +0 -0
  39. data/lib/tcell_agent/rust/{libtcellagent-6.2.1.dylib → libtcellagent.dylib} +0 -0
  40. data/lib/tcell_agent/rust/{libtcellagent-6.2.1.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 +14 -4
  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 +42 -7
  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 → puma_mock_1.rb} +5 -1
  78. data/spec/support/server_mocks/puma_mock_2.rb +26 -0
  79. data/spec/support/server_mocks/puma_mock_3.rb +22 -0
  80. data/spec/support/shared_spec.rb +29 -0
  81. data/tcell_agent.gemspec +14 -14
  82. metadata +29 -21
  83. data/Rakefile +0 -18
  84. data/lib/tcell_agent/instrumentation/monkey_patches/file.rb +0 -25
  85. data/lib/tcell_agent/instrumentation/monkey_patches/io.rb +0 -131
  86. data/lib/tcell_agent/instrumentation/monkey_patches/kernel.rb +0 -102
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 15b359f97c96e28cf58ee258ebd6cc0112b31656165271012b8c804a406a2904
4
- data.tar.gz: cd73c079ce0bd4f063a7c32571ae9e57155bdcd86fa4fd81a9738c97acec3d49
3
+ metadata.gz: 521fa2c98be5ea73aa4a9f4a8c00b9c1e51e2dd801de3c886324e28c95205142
4
+ data.tar.gz: a257258e3e3a4f71ee52d2242a3e37ec56c103da6aaae7ed471b87ef3b5ae054
5
5
  SHA512:
6
- metadata.gz: 7dca586b7699c1bc013b1b5a07034087b8f45322cc30439b3d29e7ab16dfe8b8e85ae07d39738135020628e590bfb1b3a9b154bb6c954c99123102a4df19240a
7
- data.tar.gz: 937109bc1a6b08d05cd3442e31ed6d4d2d4763ce7954d76cb65c26159c501c0e73fb68a2451c45b1b04e02fd15f3d0ab0564c29c59bf90fa4dc38db1472ea125
6
+ metadata.gz: '0349621e1d4393d435561bb72dcb8928746caffb6f57828f4ea429d93546ef550be81ce7d15fad344775b9c4af18b17cff6339c800c51bcc573c025bcb2e4f49'
7
+ data.tar.gz: 4c7b9c61a59d6b7023fd2e54b8262a8ea1efed04600a36ccd5d92be85eb2240a1832178197dfa40ccef35ecddc886ee34d25ec674ba926c909461c7164b5b11d
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (C) 2015 tCell.io, Inc. - All Rights Reserved
1
+ Copyright (C) 2020 Rapid7, Inc. - All Rights Reserved
2
2
  Proprietary and confidential
3
3
 
4
- http://choosealicense.com/licenses/no-license/
4
+ https://docs.rapid7.com/tcell/ruby-agent-install/
data/bin/tcell_agent CHANGED
@@ -9,7 +9,7 @@ options = {}
9
9
  def yesno(default = true)
10
10
  begin
11
11
  system('stty raw -echo')
12
- str = STDIN.getc
12
+ str = $stdin.getc
13
13
  ensure
14
14
  system('stty -raw echo')
15
15
  end
@@ -33,8 +33,6 @@ global = OptionParser.new do |opts|
33
33
  Kernel.exit(1)
34
34
  end
35
35
 
36
- opts.on('test', 'Run diagnostics and test event sending') do |_v|
37
- end
38
36
  opts.separator ''
39
37
  opts.separator subtext
40
38
  end
@@ -53,15 +51,11 @@ subcommands = {
53
51
 
54
52
  global.order!
55
53
  command = ARGV.shift
56
- deprecated_commands = %w[setup loglevel preload demomode enable disable]
57
54
  if command.nil?
58
55
  puts global
59
56
  Kernel.exit(1)
60
57
  elsif subcommands[command]
61
58
  subcommands[command].order!
62
- elsif !deprecated_commands.include?(command)
63
- puts global
64
- Kernel.exit(1)
65
59
  end
66
60
 
67
61
  if command == 'setup'
@@ -87,9 +81,9 @@ if command == 'setup'
87
81
  end
88
82
  end
89
83
  print 'Enter your API Key (ie gAABAAAA...): '
90
- api_key = STDIN.gets.chomp
84
+ api_key = $stdin.gets.chomp
91
85
  print 'Enter your App ID (ie MyApp-Fdk4j): '
92
- app_id = STDIN.gets.chomp
86
+ app_id = $stdin.gets.chomp
93
87
  config_hash = {
94
88
  'version' => 1,
95
89
  'applications' => [
@@ -176,10 +170,11 @@ elsif command == 'demomode'
176
170
  puts 'done.'
177
171
 
178
172
  elsif command == 'test'
179
- Dir[Dir.pwd + '/config/initializers/*.rb'].sort.each do |f|
173
+ Dir["#{Dir.pwd}/config/initializers/*.rb"].sort.each do |f|
180
174
  begin
181
175
  require f
182
- rescue NameError # rubocop: disable Lint/HandleExceptions
176
+ rescue NameError
177
+ # do nothing
183
178
  rescue StandardError => e
184
179
  puts "[ERROR] Loading initializers failed. #{e}"
185
180
  end
@@ -56,19 +56,25 @@ module TCellAgent
56
56
  require 'tcell_agent/instrumentation/cmdi'
57
57
  require 'tcell_agent/instrumentation/lfi'
58
58
 
59
+ variant = if RUBY_VERSION.start_with?('3')
60
+ 'ruby_3'
61
+ else
62
+ 'ruby_2'
63
+ end
64
+
59
65
  if TCellAgent.configuration.should_instrument?('io')
60
66
  module_logger.info('Instrumenting Ruby Class: IO')
61
- require 'tcell_agent/instrumentation/monkey_patches/io'
67
+ require "tcell_agent/instrumentation/monkey_patches/#{variant}/io"
62
68
  end
63
69
 
64
70
  if TCellAgent.configuration.should_instrument?('file')
65
71
  module_logger.info('Instrumenting Ruby Class: File')
66
- require 'tcell_agent/instrumentation/monkey_patches/file'
72
+ require "tcell_agent/instrumentation/monkey_patches/#{variant}/file"
67
73
  end
68
74
 
69
75
  if TCellAgent.configuration.should_instrument?('kernel') # rubocop:disable Style/GuardClause
70
76
  module_logger.info('Instrumenting Ruby Module: Kernel')
71
- require 'tcell_agent/instrumentation/monkey_patches/kernel'
77
+ require "tcell_agent/instrumentation/monkey_patches/#{variant}/kernel"
72
78
  end
73
79
  end
74
80
 
@@ -100,18 +106,18 @@ module TCellAgent
100
106
  @native_agent.send_sanitized_events(
101
107
  [event]
102
108
  )
103
- rescue StandardError => standard_error
104
- module_logger.error("Error sending event: (#{standard_error.class}) #{standard_error.message}")
105
- module_logger.exception(standard_error)
109
+ rescue StandardError => e
110
+ module_logger.error("Error sending event: (#{e.class}) #{e.message}")
111
+ module_logger.exception(e)
106
112
  end
107
113
 
108
114
  def report_metrics(request_time, tcell_context)
109
115
  @native_agent.report_metrics(
110
116
  request_time, tcell_context
111
117
  )
112
- rescue StandardError => standard_error
113
- module_logger.error("Error reporting metric: (#{standard_error.class}) #{standard_error.message}")
114
- module_logger.exception(standard_error)
118
+ rescue StandardError => e
119
+ module_logger.error("Error reporting metric: (#{e.class}) #{e.message}")
120
+ module_logger.exception(e)
115
121
  end
116
122
 
117
123
  def start(server_name)
@@ -135,12 +141,11 @@ module TCellAgent
135
141
 
136
142
  module_logger.info("Started thread agent: #{server_name}")
137
143
  TCellAgent.report_settings
138
- TCellAgent::Instrumentation::Rails.send_framework_info
139
144
  TCellAgent::Instrumentation::Rails.send_settings
140
- rescue StandardError => standard_error
145
+ rescue StandardError => e
141
146
  TCellAgent.configuration.enabled = false
142
- module_logger.error("Error starting agent: (#{standard_error.class}) #{standard_error.message}")
143
- module_logger.exception(standard_error)
147
+ module_logger.error("Error starting agent: (#{e.class}) #{e.message}")
148
+ module_logger.exception(e)
144
149
  end
145
150
  end
146
151
  end
@@ -9,7 +9,8 @@ module TCellAgent
9
9
  :reverse_proxy_ip_address_header, :host_identifier,
10
10
  :hmac_key, :password_hmac_key,
11
11
  :js_agent_url, :js_agent_api_base_url,
12
- :max_csp_header_bytes, :allow_payloads
12
+ :max_csp_header_bytes, :allow_payloads,
13
+ :proxy_url, :proxy_username, :proxy_password
13
14
 
14
15
  attr_reader :logging_options
15
16
 
@@ -58,9 +59,5 @@ module TCellAgent
58
59
  def enable_intercept_requests=(bool)
59
60
  @disabled_instrumentation << 'intercept_requests' unless TCellAgent.configuration.to_bool(bool)
60
61
  end
61
-
62
- def get_config_file_path
63
- super
64
- end
65
62
  end
66
63
  end
@@ -85,7 +85,8 @@ module TCellAgent
85
85
  app_data = config['applications'][0]
86
86
  @disable_all = to_bool(app_data.fetch('disable_all', @disable_all))
87
87
  end
88
- rescue StandardError # rubocop:disable Lint/HandleExceptions
88
+ rescue StandardError
89
+ # do nothing
89
90
  end
90
91
  end
91
92
 
@@ -108,9 +109,8 @@ module TCellAgent
108
109
  @password_hmac_key = apps['password_hmac_key']
109
110
 
110
111
  # proxy config
111
- proxy_config = apps['proxy_config'] || {}
112
- @reverse_proxy = proxy_config['reverse_proxy']
113
- @reverse_proxy_ip_address_header = proxy_config['reverse_proxy_ip_address_header']
112
+ @reverse_proxy = apps['reverse_proxy']
113
+ @reverse_proxy_ip_address_header = apps['reverse_proxy_ip_address_header']
114
114
 
115
115
  # endpoint config
116
116
  endpoint = native_agent_config_response['endpoint_config'] || {}
@@ -3,7 +3,7 @@ require 'tcell_agent/agent'
3
3
  module TCellAgent
4
4
  module Hooks
5
5
  module LoginFraud
6
- # Note: mock out in tests
6
+ # NOTE: mock out in tests
7
7
  def self.get_logger
8
8
  unless defined?(@login_fraud_logger)
9
9
  @login_fraud_logger = TCellAgent::ModuleLogger.new(TCellAgent.logger, name)
@@ -56,5 +56,37 @@ module TCellAgent
56
56
 
57
57
  cmd
58
58
  end
59
+
60
+ def self.raise_if_block(cmd)
61
+ return unless TCellAgent::Cmdi.block_command?(cmd)
62
+
63
+ raise "tCell.io Agent: Command not allowed by policy: #{cmd}"
64
+ end
65
+
66
+ def self.default_cmdi_handler(args)
67
+ cmd = TCellAgent::Cmdi.parse_command(*args)
68
+
69
+ raise_if_block(cmd)
70
+ end
71
+
72
+ def self.popen_cmdi_handler(args)
73
+ return if args.empty?
74
+
75
+ cmd = ''
76
+
77
+ TCellAgent::Instrumentation.safe_block('CMDI Parsing popen *args') do
78
+ args_copy = Array.new(args)
79
+ args_copy.shift if args_copy.first.is_a?(Hash)
80
+ args_copy.pop if args_copy.last.is_a?(Hash)
81
+
82
+ cmd = if args_copy.first.is_a?(String)
83
+ args_copy.shift
84
+ else
85
+ TCellAgent::Cmdi.parse_command(*args_copy.shift)
86
+ end
87
+ end
88
+
89
+ raise_if_block(cmd)
90
+ end
59
91
  end
60
92
  end
@@ -5,6 +5,8 @@ require 'tcell_agent/configuration'
5
5
  module TCellAgent
6
6
  module Instrumentation
7
7
  module Lfi
8
+ extend TCellAgent::ModuleLoggerAccess
9
+
8
10
  def self.block_file_access?(path, mode)
9
11
  TCellAgent::Instrumentation.safe_block('Checking Local Files Policy') do
10
12
  if TCellAgent::Utils::Strings.present?(path)
@@ -54,17 +56,27 @@ module TCellAgent
54
56
  mode = 'Read'
55
57
 
56
58
  TCellAgent::Instrumentation.safe_block('LFI Parsing ARGF') do
57
- if ARGF.eof? && !ARGV.empty?
58
- argv_copy = Array.new(ARGV)
59
- path = argv_copy.shift
60
- else
61
- path = ARGF.filename
62
- end
59
+ begin
60
+ return ['', ''] if ARGF.file == $stdin
63
61
 
64
- if path && path.to_s[0] != '|'
65
- [File.expand_path(path.to_s), mode]
66
- else
62
+ if ARGF.eof? && !ARGV.empty?
63
+ argv_copy = Array.new(ARGV)
64
+ path = argv_copy.shift
65
+ else
66
+ path = ARGF.filename
67
+ end
68
+
69
+ if path && path.to_s[0] != '|'
70
+ [File.expand_path(path.to_s), mode]
71
+ else
72
+ ['', '']
73
+ end
74
+ rescue Errno::ENOENT
75
+ module_logger.debug('LFI Parsing ARGF: attempted to read a non-existent file')
67
76
  ['', '']
77
+ rescue Errno::EISDIR
78
+ module_logger.debug('LFI Parsing ARGF: attempted to read a directory')
79
+ [ARGF.filename, mode]
68
80
  end
69
81
  end
70
82
  end
@@ -79,6 +91,40 @@ module TCellAgent
79
91
  end
80
92
  'Read'
81
93
  end
94
+
95
+ def self.raise_if_block(path, mode)
96
+ return unless block_file_access?(path, mode)
97
+
98
+ raise IOError, "tCell.io Agent: Attempted access to file #{path} with mode #{mode} denied"
99
+ end
100
+
101
+ def self.default_open_handler(args, override_mode = '')
102
+ path, mode = extract_path_mode(*args)
103
+
104
+ mode = override_mode unless override_mode.empty?
105
+
106
+ raise_if_block(path, mode)
107
+ end
108
+
109
+ def self.argf_open_handler
110
+ path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode_argf
111
+
112
+ raise_if_block(path, mode)
113
+ end
114
+
115
+ def self.cmdi_open_handler(args, override_mode = '')
116
+ path, mode = extract_path_mode(*args)
117
+
118
+ mode = override_mode unless override_mode.empty?
119
+
120
+ raise_if_block(path, mode)
121
+
122
+ return unless path.empty?
123
+
124
+ cmd = TCellAgent::Cmdi.parse_command_from_open(*args)
125
+
126
+ TCellAgent::Cmdi.raise_if_block(cmd) if cmd
127
+ end
82
128
  end
83
129
  end
84
130
  end
@@ -0,0 +1,21 @@
1
+ class File
2
+ class << self
3
+ if TCellAgent.configuration.should_instrument?('File::new')
4
+ alias_method :tcell_original_new, :new
5
+ def new(*args, &block)
6
+ TCellAgent::Instrumentation::Lfi.default_open_handler(args)
7
+
8
+ tcell_original_new(*args, &block)
9
+ end
10
+ end
11
+
12
+ if TCellAgent.configuration.should_instrument?('File::open')
13
+ alias_method :tcell_original_open, :open
14
+ def open(*args, &block)
15
+ TCellAgent::Instrumentation::Lfi.default_open_handler(args)
16
+
17
+ tcell_original_open(*args, &block)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,75 @@
1
+ class IO
2
+ class << self
3
+ if TCellAgent.configuration.should_instrument?('IO::binread')
4
+ alias_method :tcell_original_binread, :binread
5
+ def binread(*args, &block)
6
+ TCellAgent::Instrumentation::Lfi.cmdi_open_handler(args)
7
+
8
+ tcell_original_binread(*args, &block)
9
+ end
10
+ end
11
+
12
+ if TCellAgent.configuration.should_instrument?('IO::binwrite')
13
+ alias_method :tcell_original_binwrite, :binwrite
14
+ def binwrite(*args, &block)
15
+ TCellAgent::Instrumentation::Lfi.default_open_handler(args, 'Write')
16
+
17
+ tcell_original_binwrite(*args, &block)
18
+ end
19
+ end
20
+
21
+ if TCellAgent.configuration.should_instrument?('IO::foreach')
22
+ alias_method :tcell_original_foreach, :foreach
23
+ def foreach(*args, &block)
24
+ TCellAgent::Instrumentation::Lfi.default_open_handler(args, 'Read')
25
+
26
+ tcell_original_foreach(*args, &block)
27
+ end
28
+ end
29
+
30
+ if TCellAgent.configuration.should_instrument?('IO::popen')
31
+ alias_method :tcell_original_popen, :popen
32
+ def popen(*args, &block)
33
+ TCellAgent::Cmdi.popen_cmdi_handler(args)
34
+
35
+ tcell_original_popen(*args, &block)
36
+ end
37
+ end
38
+
39
+ if TCellAgent.configuration.should_instrument?('IO::read')
40
+ alias_method :tcell_original_read, :read
41
+ def read(*args, &block)
42
+ TCellAgent::Instrumentation::Lfi.cmdi_open_handler(args, 'Read')
43
+
44
+ tcell_original_read(*args, &block)
45
+ end
46
+ end
47
+
48
+ if TCellAgent.configuration.should_instrument?('IO::readlines')
49
+ alias_method :tcell_original_readlines, :readlines
50
+ def readlines(*args, &block)
51
+ TCellAgent::Instrumentation::Lfi.cmdi_open_handler(args, 'Read')
52
+
53
+ tcell_original_readlines(*args, &block)
54
+ end
55
+ end
56
+
57
+ if TCellAgent.configuration.should_instrument?('IO::sysopen')
58
+ alias_method :tcell_original_sysopen, :sysopen
59
+ def sysopen(*args, &block)
60
+ TCellAgent::Instrumentation::Lfi.default_open_handler(args)
61
+
62
+ tcell_original_sysopen(*args, &block)
63
+ end
64
+ end
65
+
66
+ if TCellAgent.configuration.should_instrument?('IO::write')
67
+ alias_method :tcell_original_write, :write
68
+ def write(*args, &block)
69
+ TCellAgent::Instrumentation::Lfi.default_open_handler(args, 'Write')
70
+
71
+ tcell_original_write(*args, &block)
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,80 @@
1
+ module Kernel
2
+ private
3
+
4
+ if TCellAgent.configuration.should_instrument?('Kernel#`')
5
+ alias_method :tcell_original_backtick, :`
6
+ def `(cmd)
7
+ TCellAgent::Cmdi.raise_if_block(cmd)
8
+
9
+ tcell_original_backtick(cmd)
10
+ end
11
+
12
+ module_function :`
13
+ end
14
+
15
+ if TCellAgent.configuration.should_instrument?('Kernel#exec')
16
+ alias_method :tcell_original_exec, :exec
17
+ def exec(*args)
18
+ TCellAgent::Cmdi.default_cmdi_handler(args)
19
+
20
+ tcell_original_exec(*args)
21
+ end
22
+
23
+ module_function :exec
24
+ end
25
+
26
+ if TCellAgent.configuration.should_instrument?('Kernel#gets')
27
+ alias_method :tcell_original_gets, :gets
28
+ def gets(*args, &block)
29
+ TCellAgent::Instrumentation::Lfi.argf_open_handler
30
+
31
+ tcell_original_gets(*args, &block)
32
+ end
33
+
34
+ module_function :gets
35
+ end
36
+
37
+ if TCellAgent.configuration.should_instrument?('Kernel#open')
38
+ alias_method :tcell_original_open, :open
39
+ def open(*args, &block)
40
+ TCellAgent::Instrumentation::Lfi.cmdi_open_handler(args)
41
+
42
+ tcell_original_open(*args, &block)
43
+ end
44
+
45
+ module_function :open
46
+ end
47
+
48
+ if TCellAgent.configuration.should_instrument?('Kernel#readline')
49
+ alias_method :tcell_original_readline, :readline
50
+ def readline(*args, &block)
51
+ TCellAgent::Instrumentation::Lfi.argf_open_handler
52
+
53
+ tcell_original_readline(*args, &block)
54
+ end
55
+
56
+ module_function :readline
57
+ end
58
+
59
+ if TCellAgent.configuration.should_instrument?('Kernel#spawn')
60
+ alias_method :tcell_original_spawn, :spawn
61
+ def spawn(*args)
62
+ TCellAgent::Cmdi.default_cmdi_handler(args)
63
+
64
+ tcell_original_spawn(*args)
65
+ end
66
+
67
+ module_function :spawn
68
+ end
69
+
70
+ if TCellAgent.configuration.should_instrument?('Kernel#system')
71
+ alias_method :tcell_original_system, :system
72
+ def system(*args)
73
+ TCellAgent::Cmdi.default_cmdi_handler(args)
74
+
75
+ tcell_original_system(*args)
76
+ end
77
+
78
+ module_function :system
79
+ end
80
+ end
@@ -0,0 +1,21 @@
1
+ class File
2
+ class << self
3
+ if TCellAgent.configuration.should_instrument?('File::new')
4
+ alias_method :tcell_original_new, :new
5
+ def new(*args, **kwargs, &block)
6
+ TCellAgent::Instrumentation::Lfi.default_open_handler(args)
7
+
8
+ tcell_original_new(*args, **kwargs, &block)
9
+ end
10
+ end
11
+
12
+ if TCellAgent.configuration.should_instrument?('File::open')
13
+ alias_method :tcell_original_open, :open
14
+ def open(*args, **kwargs, &block)
15
+ TCellAgent::Instrumentation::Lfi.default_open_handler(args)
16
+
17
+ tcell_original_open(*args, **kwargs, &block)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,75 @@
1
+ class IO
2
+ class << self
3
+ if TCellAgent.configuration.should_instrument?('IO::binread')
4
+ alias_method :tcell_original_binread, :binread
5
+ def binread(*args, **kwargs, &block)
6
+ TCellAgent::Instrumentation::Lfi.cmdi_open_handler(args)
7
+
8
+ tcell_original_binread(*args, **kwargs, &block)
9
+ end
10
+ end
11
+
12
+ if TCellAgent.configuration.should_instrument?('IO::binwrite')
13
+ alias_method :tcell_original_binwrite, :binwrite
14
+ def binwrite(*args, **kwargs, &block)
15
+ TCellAgent::Instrumentation::Lfi.default_open_handler(args, 'Write')
16
+
17
+ tcell_original_binwrite(*args, **kwargs, &block)
18
+ end
19
+ end
20
+
21
+ if TCellAgent.configuration.should_instrument?('IO::foreach')
22
+ alias_method :tcell_original_foreach, :foreach
23
+ def foreach(*args, **kwargs, &block)
24
+ TCellAgent::Instrumentation::Lfi.default_open_handler(args, 'Read')
25
+
26
+ tcell_original_foreach(*args, **kwargs, &block)
27
+ end
28
+ end
29
+
30
+ if TCellAgent.configuration.should_instrument?('IO::popen')
31
+ alias_method :tcell_original_popen, :popen
32
+ def popen(*args, **kwargs, &block)
33
+ TCellAgent::Cmdi.popen_cmdi_handler(args)
34
+
35
+ tcell_original_popen(*args, **kwargs, &block)
36
+ end
37
+ end
38
+
39
+ if TCellAgent.configuration.should_instrument?('IO::read')
40
+ alias_method :tcell_original_read, :read
41
+ def read(*args, **kwargs, &block)
42
+ TCellAgent::Instrumentation::Lfi.cmdi_open_handler(args, 'Read')
43
+
44
+ tcell_original_read(*args, **kwargs, &block)
45
+ end
46
+ end
47
+
48
+ if TCellAgent.configuration.should_instrument?('IO::readlines')
49
+ alias_method :tcell_original_readlines, :readlines
50
+ def readlines(*args, **kwargs, &block)
51
+ TCellAgent::Instrumentation::Lfi.cmdi_open_handler(args, 'Read')
52
+
53
+ tcell_original_readlines(*args, **kwargs, &block)
54
+ end
55
+ end
56
+
57
+ if TCellAgent.configuration.should_instrument?('IO::sysopen')
58
+ alias_method :tcell_original_sysopen, :sysopen
59
+ def sysopen(*args, **kwargs, &block)
60
+ TCellAgent::Instrumentation::Lfi.default_open_handler(args)
61
+
62
+ tcell_original_sysopen(*args, **kwargs, &block)
63
+ end
64
+ end
65
+
66
+ if TCellAgent.configuration.should_instrument?('IO::write')
67
+ alias_method :tcell_original_write, :write
68
+ def write(*args, **kwargs, &block)
69
+ TCellAgent::Instrumentation::Lfi.default_open_handler(args, 'Write')
70
+
71
+ tcell_original_write(*args, **kwargs, &block)
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,80 @@
1
+ module Kernel
2
+ private
3
+
4
+ if TCellAgent.configuration.should_instrument?('Kernel#`')
5
+ alias_method :tcell_original_backtick, :`
6
+ def `(cmd)
7
+ TCellAgent::Cmdi.raise_if_block(cmd)
8
+
9
+ tcell_original_backtick(cmd)
10
+ end
11
+
12
+ module_function :`
13
+ end
14
+
15
+ if TCellAgent.configuration.should_instrument?('Kernel#exec')
16
+ alias_method :tcell_original_exec, :exec
17
+ def exec(*args)
18
+ TCellAgent::Cmdi.default_cmdi_handler(args)
19
+
20
+ tcell_original_exec(*args)
21
+ end
22
+
23
+ module_function :exec
24
+ end
25
+
26
+ if TCellAgent.configuration.should_instrument?('Kernel#gets')
27
+ alias_method :tcell_original_gets, :gets
28
+ def gets(*args, **kwargs, &block)
29
+ TCellAgent::Instrumentation::Lfi.argf_open_handler
30
+
31
+ tcell_original_gets(*args, **kwargs, &block)
32
+ end
33
+
34
+ module_function :gets
35
+ end
36
+
37
+ if TCellAgent.configuration.should_instrument?('Kernel#open')
38
+ alias_method :tcell_original_open, :open
39
+ def open(*args, **kwargs, &block)
40
+ TCellAgent::Instrumentation::Lfi.cmdi_open_handler(args)
41
+
42
+ tcell_original_open(*args, **kwargs, &block)
43
+ end
44
+
45
+ module_function :open
46
+ end
47
+
48
+ if TCellAgent.configuration.should_instrument?('Kernel#readline')
49
+ alias_method :tcell_original_readline, :readline
50
+ def readline(*args, **kwargs, &block)
51
+ TCellAgent::Instrumentation::Lfi.argf_open_handler
52
+
53
+ tcell_original_readline(*args, **kwargs, &block)
54
+ end
55
+
56
+ module_function :readline
57
+ end
58
+
59
+ if TCellAgent.configuration.should_instrument?('Kernel#spawn')
60
+ alias_method :tcell_original_spawn, :spawn
61
+ def spawn(*args, **kwargs)
62
+ TCellAgent::Cmdi.default_cmdi_handler(args)
63
+
64
+ tcell_original_spawn(*args, **kwargs)
65
+ end
66
+
67
+ module_function :spawn
68
+ end
69
+
70
+ if TCellAgent.configuration.should_instrument?('Kernel#system')
71
+ alias_method :tcell_original_system, :system
72
+ def system(*args, **kwargs)
73
+ TCellAgent::Cmdi.default_cmdi_handler(args)
74
+
75
+ tcell_original_system(*args, **kwargs)
76
+ end
77
+
78
+ module_function :system
79
+ end
80
+ end