OSX Post mixin lib

git-svn-id: file:///home/svn/framework3/trunk@12827 4d416f70-5f16-0410-b530-b9f4589650da
unstable
Carlos Perez 2011-06-02 22:20:36 +00:00
parent 110f4df649
commit 46cb4954b5
1 changed files with 105 additions and 0 deletions

View File

@ -0,0 +1,105 @@
require 'msf/core/post/common'
require 'msf/core/post/file'
module Msf
class Post
module System
include ::Msf::Post::Common
include ::Msf::Post::File
# 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
end
system_info["Kernel"] = `uname -a`.chomp
system_info["Hostname"] = system_info["Kernel"].split(" ")[1]
return system_info
end
# 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.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"
entry[field] = val.chomp
end
users << entry
end
return users
end
# 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.split("\n\n")
users_arry.each do |u|
entry = {}
u.each_line do |l|
field,val = l.chomp.split(": ")
next if field == "password"
entry[field] = val.chomp
end
next if entry["name"] !~ /^_/
users << entry
end
return users
end
# 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.split("\n\n")
users_arry.each do |u|
entry = {}
u.each_line do |l|
field,val = l.chomp.split(": ")
next if field == "password"
entry[field] = val.chomp
end
next if entry["name"] =~ /^_/
users << entry
end
return users
end
# 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"
entry[field] = val.chomp
end
groups << entry
end
return groups
end
end # System
end # Post
end # Msf