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



134
135
136
137
138
139
140
141
# File 'lib/tcell_agent/instrumentation/monkey_patches/kernel.rb', line 134

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



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

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
# 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 && TCellAgent::Instrumentation::Lfi.block_file_access?(path, mode)
    raise IOError, "tCell.io Agent: Attempted access to file #{path} with mode #{mode} denied"
  end

  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

  tcell_original_1_open(*args, &block)
end

.readline(*args, &block) ⇒ Object



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

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



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

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



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

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



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

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



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

alias_method :tcell_original_1_spawn, :spawn

.tcell_original_1_systemObject



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

alias_method :tcell_original_1_system, :system

.tcell_original_execObject



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

alias_method :tcell_original_exec, :exec

.tcell_original_readlineObject



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

alias_method :tcell_original_readline, :readline

Instance Method Details

#`(cmd) ⇒ Object



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

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



88
89
90
91
92
93
94
95
96
# File 'lib/tcell_agent/instrumentation/monkey_patches/kernel.rb', line 88

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



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

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

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

  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

  tcell_original_2_open(*args, &block)
end

#readline(*args, &block) ⇒ Object



99
100
101
102
103
104
105
106
107
# File 'lib/tcell_agent/instrumentation/monkey_patches/kernel.rb', line 99

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



110
111
112
113
114
115
116
117
# File 'lib/tcell_agent/instrumentation/monkey_patches/kernel.rb', line 110

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



120
121
122
123
124
125
126
127
# File 'lib/tcell_agent/instrumentation/monkey_patches/kernel.rb', line 120

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



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

alias_method :tcell_original_2_gets, :gets

#tcell_original_2_openObject



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

alias_method :tcell_original_2_open, :open

#tcell_original_2_spawnObject



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

alias_method :tcell_original_2_spawn, :spawn

#tcell_original_2_systemObject



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

alias_method :tcell_original_2_system, :system

#tcell_original_execObject



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

alias_method :tcell_original_exec, :exec

#tcell_original_readlineObject



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

alias_method :tcell_original_readline, :readline