Files
metasploit-gs/lib/msf/core/post/osx/system.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

124 lines
3.0 KiB
Ruby
Raw Normal View History

# -*- coding: binary -*-
2011-06-02 22:20:36 +00:00
2013-08-29 13:37:50 -05:00
module Msf::Post::OSX::System
2013-09-05 13:41:25 -05:00
include ::Msf::Post::Common
include ::Msf::Post::File
2011-06-02 22:20:36 +00:00
2018-11-15 08:48:10 +08:00
def get_system_version
cmd_exec("/usr/bin/sw_vers -productVersion")
end
#
# Return a hash with system Information
#
def get_sysinfo
system_info = {}
cmd_output = cmd_exec("/usr/bin/sw_vers").split("\n")
cmd_output.each do |l|
field,val = l.chomp.split(":")
system_info[field] = val.strip
2011-06-02 23:17:52 +00:00
end
system_info["Kernel"] = cmd_exec("uname -a")
system_info["Hostname"] = system_info["Kernel"].split(" ")[1]
2018-10-17 12:43:05 -04:00
report_host({
:host => rhost,
:os_name => 'osx',
2018-11-03 17:05:47 -04:00
:os_flavor => system_info["Kernel"],
2018-10-17 12:43:05 -04:00
:name => system_info["Hostname"]
})
return system_info
end
2011-06-02 22:20:36 +00:00
#
# Returns an array of hashes each representing a user on the system
# Keys are name, gid, uid, dir and shell
#
def get_users
cmd_output = cmd_exec("/usr/bin/dscacheutil -q user")
users = []
users_arry = cmd_output.tr("\r", "").split("\n\n")
users_arry.each do |u|
entry = Hash.new
u.each_line do |l|
field,val = l.chomp.split(": ")
next if field == "password"
unless val.nil?
entry[field] = val.strip
end
2011-06-02 22:20:36 +00:00
end
users << entry
2011-06-02 22:20:36 +00:00
end
return users
end
2011-06-02 22:20:36 +00:00
#
# Returns an array of hashes each representing a system accounts on the system
# Keys are name, gid, uid, dir and shell
#
def get_system_accounts
cmd_output = cmd_exec("/usr/bin/dscacheutil -q user")
users = []
users_arry = cmd_output.tr("\r", "").split("\n\n")
users_arry.each do |u|
entry = {}
u.each_line do |l|
field,val = l.chomp.split(": ")
next if field == "password"
unless val.nil?
entry[field] = val.strip
end
2011-06-02 22:20:36 +00:00
end
next if entry["name"][0] != '_'
users << entry
2011-06-02 22:20:36 +00:00
end
return users
end
2011-06-02 22:20:36 +00:00
#
# Returns an array of hashes each representing non system accounts on the system
# Keys are name, gid, uid, dir and shell
#
def get_nonsystem_accounts
cmd_output = cmd_exec("/usr/bin/dscacheutil -q user")
users = []
users_arry = cmd_output.tr("\r", "").split("\n\n")
users_arry.each do |u|
entry = {}
u.each_line do |l|
field,val = l.chomp.split(": ")
next if field == "password"
unless val.nil?
entry[field] = val.strip
end
2011-06-02 22:20:36 +00:00
end
next if entry["name"][0] == '_'
users << entry
2011-06-02 22:20:36 +00:00
end
return users
end
2011-06-02 22:20:36 +00:00
#
# Returns an array of hashes each representing user group on the system
# Keys are name, guid and users
#
def get_groups
cmd_output = cmd_exec("/usr/bin/dscacheutil -q group")
groups = []
groups_arry = cmd_output.split("\n\n")
groups_arry.each do |u|
entry = Hash.new
u.each_line do |l|
field,val = l.chomp.split(": ")
next if field == "password"
unless val.nil?
entry[field] = val.strip
end
2013-09-05 13:41:25 -05:00
end
groups << entry
end
return groups
end
2013-08-29 13:37:50 -05:00
end