From 6561f149a8221ff23d3ed35fe68ae8d2e0dcefcc Mon Sep 17 00:00:00 2001 From: joev Date: Wed, 27 Nov 2013 06:16:25 -0600 Subject: [PATCH] DRY up URL_REGEX constant. --- modules/post/osx/manage/mount_share.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/post/osx/manage/mount_share.rb b/modules/post/osx/manage/mount_share.rb index 09391d0cfb..be6d5b1701 100644 --- a/modules/post/osx/manage/mount_share.rb +++ b/modules/post/osx/manage/mount_share.rb @@ -8,10 +8,15 @@ require 'rex' class Metasploit3 < Msf::Post + # list of accepted file share protocols. other "special" URLs (like vnc://) will be ignored. FILE_SHARE_PROTOCOLS = %w(smb nfs cifs ftp afp) + # Used to parse a name property from a plist NAME_REGEXES = [/^Name \= \"(.*)\"\;$/, /^Name \= (.*)\;$/] + # Used to parse a URL property from a plist + URL_REGEX = /^URL = \"(.*)\"\;$/ + include Msf::Post::File def initialize(info={}) @@ -150,7 +155,7 @@ class Metasploit3 < Msf::Post def get_favorite_shares(sidebar_plist_path) # Grep for URL data = cmd_exec("defaults read #{sidebar_plist_path} favoriteservers") - list = data.lines.map(&:strip).map { |line| line =~ /^URL = \"(.*)\"\;$/ && $1 }.compact + list = data.lines.map(&:strip).map { |line| line =~ URL_REGEX && $1 }.compact # Grep for EntryType and Name data = cmd_exec("defaults read #{sidebar_plist_path} favorites") @@ -173,7 +178,7 @@ class Metasploit3 < Msf::Post def get_recent_shares(recent_plist_path) # Grep for Name data = cmd_exec("defaults read #{recent_plist_path} Hosts") - data.lines.map(&:strip).map { |line| line =~ /^URL = \"(.*)\"\;$/ && $1 }.compact.uniq.sort + data.lines.map(&:strip).map { |line| line =~ URL_REGEX && $1 }.compact.uniq.sort end # @return [Array] sorted list of mounted volume names