Module: Kernel

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exec(*args) ⇒ Object



138
139
140
141
142
143
144
145
# File 'lib/tcell_agent/instrumentation/monkey_patches/kernel.rb', line 138

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



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

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_1_gets(*args, &block)
end

.open(*args, &block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/tcell_agent/instrumentation/monkey_patches/kernel.rb', line 4

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_1_open(*args, &block)
end

.readline(*args, &block) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/tcell_agent/instrumentation/monkey_patches/kernel.rb', line 33

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



44
45
46
47
48
49
50
51
# File 'lib/tcell_agent/instrumentation/monkey_patches/kernel.rb', line 44

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_1_spawn(*args)
end

.system(*args) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/tcell_agent/instrumentation/monkey_patches/kernel.rb', line 54

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_1_system(*args)
end

.tcell_original_1_getsObject



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

alias_method :tcell_original_1_gets, :gets

.tcell_original_1_openObject



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

alias_method :tcell_original_1_open, :open

.tcell_original_1_spawnObject



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

alias_method :tcell_original_1_spawn, :spawn

.tcell_original_1_systemObject



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

alias_method :tcell_original_1_system, :system

.tcell_original_execObject



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

alias_method :tcell_original_exec, :exec

.tcell_original_readlineObject



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

alias_method :tcell_original_readline, :readline

Instance Method Details

#`(cmd) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/tcell_agent/instrumentation/monkey_patches/kernel.rb', line 65

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

  tcell_original_backtick(cmd)
end

#gets(*args, &block) ⇒ Object



92
93
94
95
96
97
98
99
100
# File 'lib/tcell_agent/instrumentation/monkey_patches/kernel.rb', line 92

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_2_gets(*args, &block)
end

#open(*args, &block) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/tcell_agent/instrumentation/monkey_patches/kernel.rb', line 74

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_2_open(*args, &block)
end

#readline(*args, &block) ⇒ Object



103
104
105
106
107
108
109
110
111
# File 'lib/tcell_agent/instrumentation/monkey_patches/kernel.rb', line 103

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



114
115
116
117
118
119
120
121
# File 'lib/tcell_agent/instrumentation/monkey_patches/kernel.rb', line 114

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_2_spawn(*args)
end

#system(*args) ⇒ Object



124
125
126
127
128
129
130
131
# File 'lib/tcell_agent/instrumentation/monkey_patches/kernel.rb', line 124

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_2_system(*args)
end

#tcell_original_2_getsObject



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

alias_method :tcell_original_2_gets, :gets

#tcell_original_2_openObject



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

alias_method :tcell_original_2_open, :open

#tcell_original_2_spawnObject



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

alias_method :tcell_original_2_spawn, :spawn

#tcell_original_2_systemObject



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

alias_method :tcell_original_2_system, :system

#tcell_original_execObject



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

alias_method :tcell_original_exec, :exec

#tcell_original_readlineObject



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

alias_method :tcell_original_readline, :readline