Module: Kernel

Defined in:
lib/tcell_agent/instrumentation/monkey_patches/kernel.rb

Class Method Summary collapse

Class Method Details

.`(cmd) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/tcell_agent/instrumentation/monkey_patches/kernel.rb', line 21

def `(cmd)
  if TCellAgent::Cmdi.block_command?(cmd)
    raise "tCell.io Agent: Command not allowed by policy: #{cmd}"
  end

  tcell_original_backtick(cmd)
end

.exec(*args) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/tcell_agent/instrumentation/monkey_patches/kernel.rb', line 30

def exec(*args)
  cmd = TCellAgent::Cmdi.parse_command(*args)
  if TCellAgent::Cmdi.block_command?(cmd)
    raise "tCell.io Agent: Command not allowed by policy: #{cmd}"
  end

  tcell_original_exec(*args)
end

.gets(*args, &block) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/tcell_agent/instrumentation/monkey_patches/kernel.rb', line 40

def gets(*args, &block)
  path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode_argf

  if TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode)
    raise IOError, "tCell.io Agent: Attempted access to file #{path} with mode #{mode} denied"
  end

  tcell_original_gets(*args, &block)
end

.open(*args, &block) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/tcell_agent/instrumentation/monkey_patches/kernel.rb', line 50

def open(*args, &block)
  path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode(*args)

  if !path.strip.empty? && TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode)
    raise IOError, "tCell.io Agent: Attempted access to file #{path} with mode #{mode} denied"
  end

  if path.empty?
    cmd = TCellAgent::Cmdi.parse_command_from_open(*args)
    if cmd && TCellAgent::Cmdi.block_command?(cmd)
      raise "tCell.io Agent: Command not allowed by policy: #{cmd}"
    end
  end

  tcell_original_open(*args, &block)
end

.readline(*args, &block) ⇒ Object



67
68
69
70
71
72
73
74
75
# File 'lib/tcell_agent/instrumentation/monkey_patches/kernel.rb', line 67

def readline(*args, &block)
  path, mode = TCellAgent::Instrumentation::Lfi.extract_path_mode_argf

  if TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode)
    raise IOError, "tCell.io Agent: Attempted access to file #{path} with mode #{mode} denied"
  end

  tcell_original_readline(*args, &block)
end

.spawn(*args) ⇒ Object



77
78
79
80
81
82
83
84
# File 'lib/tcell_agent/instrumentation/monkey_patches/kernel.rb', line 77

def spawn(*args)
  cmd = TCellAgent::Cmdi.parse_command(*args)
  if TCellAgent::Cmdi.block_command?(cmd)
    raise "tCell.io Agent: Command not allowed by policy: #{cmd}"
  end

  tcell_original_spawn(*args)
end

.system(*args) ⇒ Object



86
87
88
89
90
91
92
93
# File 'lib/tcell_agent/instrumentation/monkey_patches/kernel.rb', line 86

def system(*args)
  cmd = TCellAgent::Cmdi.parse_command(*args)
  if TCellAgent::Cmdi.block_command?(cmd)
    raise "tCell.io Agent: Command not allowed by policy: #{cmd}"
  end

  tcell_original_system(*args)
end

.tcell_original_execObject



13
# File 'lib/tcell_agent/instrumentation/monkey_patches/kernel.rb', line 13

alias_method :tcell_original_exec, :exec

.tcell_original_getsObject



15
# File 'lib/tcell_agent/instrumentation/monkey_patches/kernel.rb', line 15

alias_method :tcell_original_gets, :gets

.tcell_original_openObject



14
# File 'lib/tcell_agent/instrumentation/monkey_patches/kernel.rb', line 14

alias_method :tcell_original_open, :open

.tcell_original_readlineObject



16
# File 'lib/tcell_agent/instrumentation/monkey_patches/kernel.rb', line 16

alias_method :tcell_original_readline, :readline

.tcell_original_spawnObject



17
# File 'lib/tcell_agent/instrumentation/monkey_patches/kernel.rb', line 17

alias_method :tcell_original_spawn, :spawn

.tcell_original_systemObject



18
# File 'lib/tcell_agent/instrumentation/monkey_patches/kernel.rb', line 18

alias_method :tcell_original_system, :system