Module: Msf::Post::OSX::System

Includes:
Common, File
Defined in:
lib/msf/core/post/osx/system.rb

Instance Method Summary collapse

Methods included from File

#_append_file_powershell, #_append_file_unix_shell, #_can_echo?, #_read_file_meterpreter, #_read_file_powershell, #_read_file_powershell_fragment, #_shell_command_with_success_code, #_shell_process_with_success_code, #_unix_max_line_length, #_win_ansi_append_file, #_win_ansi_write_file, #_win_bin_append_file, #_win_bin_write_file, #_write_file_meterpreter, #_write_file_powershell, #_write_file_powershell_fragment, #_write_file_unix_shell, #append_file, #attributes, #cd, #chmod, #copy_file, #dir, #directory?, #executable?, #exist?, #expand_path, #exploit_data, #exploit_source, #file?, #file_local_write, #file_remote_digestmd5, #file_remote_digestsha1, #file_remote_digestsha2, #immutable?, #initialize, #mkdir, #pwd, #read_file, #readable?, #rename_file, #rm_f, #rm_rf, #setuid?, #stat, #upload_and_chmodx, #upload_file, #writable?, #write_file

Methods included from Common

#clear_screen, #cmd_exec, #cmd_exec_get_pid, #cmd_exec_with_result, #command_exists?, #create_process, #get_env, #get_envs, #initialize, #peer, #report_virtualization, #rhost, #rport

Instance Method Details

#get_groupsObject

Returns an array of hashes each representing user group on the system Keys are name, guid and users



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/msf/core/post/osx/system.rb', line 106

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
    end
    groups << entry
  end
  return groups
end

#get_nonsystem_accountsObject

Returns an array of hashes each representing non system accounts on the system Keys are name, gid, uid, dir and shell



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/msf/core/post/osx/system.rb', line 83

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
    end
    next if entry["name"][0] == '_'
    users << entry
  end
  return users
end

#get_sysinfoObject

Return a hash with system Information



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/msf/core/post/osx/system.rb', line 14

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"] = cmd_exec("uname -a")
  system_info["Hostname"] = system_info["Kernel"].split(" ")[1]

  report_host({
    :host => rhost,
    :os_name => 'osx',
    :os_flavor => system_info["Kernel"],
    :name => system_info["Hostname"]
  })

  return system_info
end

#get_system_accountsObject

Returns an array of hashes each representing a system accounts on the system Keys are name, gid, uid, dir and shell



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/msf/core/post/osx/system.rb', line 60

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
    end
    next if entry["name"][0] != '_'
    users << entry
  end
  return users
end

#get_system_versionObject



7
8
9
# File 'lib/msf/core/post/osx/system.rb', line 7

def get_system_version
  cmd_exec("/usr/bin/sw_vers -productVersion")
end

#get_usersObject

Returns an array of hashes each representing a user on the system Keys are name, gid, uid, dir and shell



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/msf/core/post/osx/system.rb', line 38

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
    end
    users << entry
  end
  return users
end