Module: Msf::Post::Linux::Priv

Includes:
Common
Defined in:
lib/msf/core/post/linux/priv.rb

Instance Method Summary collapse

Methods included from Common

#cmd_exec, #cmd_exec_get_pid, #get_env, #get_envs, #has_pid?, #peer, #report_vm, #rhost, #rport

Instance Method Details

#is_root?Boolean

Returns true if running as root, false if not.


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/msf/core/post/linux/priv.rb', line 13

def is_root?
  root_priv = false
  user_id = cmd_exec("id -u")
  clean_user_id = user_id.to_s.gsub(/[^\d]/,"")
  unless clean_user_id.empty?
    if clean_user_id =~ /^0$/
      root_priv = true
    elsif clean_user_id =~ /^\d*$/
      root_priv = false
    end
  else
    raise "Could not determine UID: #{user_id.inspect}"
  end
  return root_priv
end