Skip to content

Commit b7df521

Browse files
authored
Merge pull request #20126 from bcoles/lib-msf-core-post-linux-kernel-yama
Msf::Post::Linux::Kernel: Add yama_ptrace_scope method
2 parents 54cdcc6 + 417f9a0 commit b7df521

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

lib/msf/core/post/linux/kernel.rb

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,26 @@ def selinux_enforcing?
334334
raise 'Could not determine SELinux status'
335335
end
336336

337+
#
338+
# Returns Yama LSM ptrace scope level
339+
#
340+
# @return [Integer] Yama ptrace scope level (0 if disabled or not installed)
341+
# @raise [RuntimeError] If execution fails.
342+
#
343+
def yama_ptrace_scope
344+
ptrace_scope = read_file('/proc/sys/kernel/yama/ptrace_scope').to_s.strip
345+
346+
return 0 unless ptrace_scope
347+
348+
level = ptrace_scope.scan(/\A(\d+)\z/).flatten.first.to_i
349+
350+
return 0 unless level
351+
352+
level
353+
rescue StandardError
354+
raise 'Could not determine Yama scope'
355+
end
356+
337357
#
338358
# Returns true if Yama is installed
339359
#
@@ -356,9 +376,7 @@ def yama_installed?
356376
# @raise [RuntimeError] If execution fails.
357377
#
358378
def yama_enabled?
359-
return false unless yama_installed?
360-
361-
!read_file('/proc/sys/kernel/yama/ptrace_scope').to_s.strip.eql? '0'
379+
yama_ptrace_scope > 0
362380
rescue StandardError
363381
raise 'Could not determine Yama status'
364382
end

0 commit comments

Comments
 (0)