|
1 |
| -# |
2 |
| -# by kernelsmith (kernelsmith+\x40+kernelsmith+\.com) |
3 |
| -# |
4 |
| - |
5 |
| -require 'msf/core' |
6 |
| -require 'rex' |
7 |
| -require 'msf/core/post/windows/services' |
8 |
| - |
9 |
| -class Metasploit3 < Msf::Post |
10 |
| - |
11 |
| - include Msf::Post::Windows::Services |
12 |
| - |
13 |
| - include Msf::ModuleTest::PostTest |
14 |
| - |
15 |
| - def initialize(info={}) |
16 |
| - super( update_info( info, |
17 |
| - 'Name' => 'services_post_testing', |
18 |
| - 'Description' => %q{ This module will test windows services methods within a shell}, |
19 |
| - 'License' => MSF_LICENSE, |
20 |
| - 'Author' => [ 'kernelsmith', 'egypt' ], |
21 |
| - 'Version' => '$Revision: 11663 $', |
22 |
| - 'Platform' => [ 'windows' ], |
23 |
| - 'SessionTypes' => [ 'meterpreter', 'shell' ] |
24 |
| - )) |
25 |
| - register_options( |
26 |
| - [ |
27 |
| - OptString.new("QSERVICE" , [true, "Service (keyname) to query", "winmgmt"]), |
28 |
| - OptString.new("NSERVICE" , [true, "New Service (keyname) to create/del", "testes"]), |
29 |
| - OptString.new("SSERVICE" , [true, "Service (keyname) to start/stop", "W32Time"]), |
30 |
| - OptString.new("DNAME" , [true, "Display name used for create test", "Cool display name"]), |
31 |
| - OptString.new("BINPATH" , [true, "Binary path for create test", "C:\\WINDOWS\\system32\\svchost.exe -k netsvcs"]), |
32 |
| - OptEnum.new("MODE", [true, "Mode to use for startup/create tests", "auto", |
33 |
| - ["auto", "manual", "disable"] |
34 |
| - ]), |
35 |
| - ], self.class) |
36 |
| - |
37 |
| - end |
38 |
| - |
39 |
| - def test_start |
40 |
| - it "should start #{datastore["SSERVICE"]}" do |
41 |
| - ret = true |
42 |
| - results = service_start(datastore['SSERVICE']) |
43 |
| - if results != 0 |
44 |
| - # Failed the first time, try to stop it first, then try again |
45 |
| - service_stop(datastore['SSERVICE']) |
46 |
| - results = service_start(datastore['SSERVICE']) |
47 |
| - end |
48 |
| - ret &&= (results == 0) |
49 |
| - |
50 |
| - ret |
51 |
| - end |
52 |
| - it "should stop #{datastore["SSERVICE"]}" do |
53 |
| - ret = true |
54 |
| - results = service_stop(datastore['SSERVICE']) |
55 |
| - ret &&= (results == 0) |
56 |
| - |
57 |
| - ret |
58 |
| - end |
59 |
| - end |
60 |
| - |
61 |
| - def test_list |
62 |
| - it "should list services" do |
63 |
| - ret = true |
64 |
| - results = service_list |
65 |
| - |
66 |
| - ret &&= results.kind_of? Array |
67 |
| - ret &&= results.length > 0 |
68 |
| - ret &&= results.include? datastore["QSERVICE"] |
69 |
| - |
70 |
| - ret |
71 |
| - end |
72 |
| - end |
73 |
| - |
74 |
| - def test_info |
75 |
| - it "should return info on a given service" do |
76 |
| - ret = true |
77 |
| - results = service_info(datastore['QSERVICE']) |
78 |
| - |
79 |
| - ret &&= results.kind_of? Hash |
80 |
| - if ret |
81 |
| - ret &&= results.has_key? "Name" |
82 |
| - ret &&= (results["Name"] == "Windows Management Instrumentation") |
83 |
| - ret &&= results.has_key? "Startup" |
84 |
| - ret &&= results.has_key? "Command" |
85 |
| - ret &&= results.has_key? "Credentials" |
86 |
| - end |
87 |
| - |
88 |
| - ret |
89 |
| - end |
90 |
| - end |
91 |
| - |
92 |
| - def test_create |
93 |
| - it "should create a service" do |
94 |
| - mode = case datastore["MODE"] |
95 |
| - when "disable"; 4 |
96 |
| - when "manual"; 3 |
97 |
| - when "auto"; 2 |
98 |
| - else; 2 |
99 |
| - end |
100 |
| - ret = service_create(datastore['NSERVICE'],datastore['DNAME'],datastore['BINPATH'],mode) |
101 |
| - |
102 |
| - ret |
103 |
| - end |
104 |
| - |
105 |
| - it "should return info on the newly-created service" do |
106 |
| - ret = true |
107 |
| - results = service_info(datastore['NSERVICE']) |
108 |
| - |
109 |
| - ret &&= results.kind_of? Hash |
110 |
| - ret &&= results.has_key? "Name" |
111 |
| - ret &&= (results["Name"] == datastore["DNAME"]) |
112 |
| - ret &&= results.has_key? "Startup" |
113 |
| - ret &&= (results["Startup"].downcase == datastore["MODE"]) |
114 |
| - ret &&= results.has_key? "Command" |
115 |
| - ret &&= results.has_key? "Credentials" |
116 |
| - |
117 |
| - ret |
118 |
| - end |
119 |
| - |
120 |
| - it "should delete the new service" do |
121 |
| - ret = service_delete(datastore['NSERVICE']) |
122 |
| - |
123 |
| - ret |
124 |
| - end |
125 |
| - end |
126 |
| - |
127 |
| - |
128 |
| -=begin |
129 |
| - def run |
130 |
| - blab = datastore['VERBOSE'] |
131 |
| - print_status("Running against session #{datastore["SESSION"]}") |
132 |
| - print_status("Session type is #{session.type}") |
133 |
| - print_status("Verbosity is set to #{blab.to_s}") |
134 |
| - print_status("Don't be surprised to see some errors as the script is faster") |
135 |
| - print_line("than the windows SCM, just make sure the errors are sane. You can") |
136 |
| - print_line("set VERBOSE to true to see more details") |
137 |
| -
|
138 |
| - print_status() |
139 |
| - print_status("TESTING service_query_ex on servicename: #{datastore["QSERVICE"]}") |
140 |
| - results = service_query_ex(datastore['QSERVICE']) |
141 |
| - print_status("RESULTS: #{results.class} #{results.pretty_inspect}") |
142 |
| -
|
143 |
| - print_status() |
144 |
| - print_status("TESTING service_query_config on servicename: #{datastore["QSERVICE"]}") |
145 |
| - results = service_query_config(datastore['QSERVICE']) |
146 |
| - print_status("RESULTS: #{results.class} #{results.pretty_inspect}") |
147 |
| -
|
148 |
| - print_status() |
149 |
| - print_status("TESTING service_change_startup on servicename: #{datastore['QSERVICE']} " + |
150 |
| - "to #{datastore['MODE']}") |
151 |
| - results = service_change_startup(datastore['QSERVICE'],datastore['MODE']) |
152 |
| - print_status("RESULTS: #{results.class} #{results.pretty_inspect}") |
153 |
| - print_status("Current status of this service " + |
154 |
| - "#{service_query_ex(datastore['QSERVICE']).pretty_inspect}") if blab |
155 |
| -
|
156 |
| - print_status() |
157 |
| - print_status("TESTING service_start on servicename: #{datastore['SSERVICE']}") |
158 |
| - results = service_start(datastore['SSERVICE']) |
159 |
| - print_status("RESULTS: #{results.class} #{results.pretty_inspect}") |
160 |
| - print_status("Current status of this service " + |
161 |
| - "#{service_query_ex(datastore['SSERVICE']).pretty_inspect}") if blab |
162 |
| - print_status("Sleeping to give the service a chance to start") |
163 |
| - select(nil, nil, nil, 2) # give the service time to start, reduces false negatives |
164 |
| -
|
165 |
| - print_status() |
166 |
| - print_status("TESTING service_stop on servicename: #{datastore['SSERVICE']}") |
167 |
| - results = service_stop(datastore['SSERVICE']) |
168 |
| - print_status("RESULTS: #{results.class} #{results.pretty_inspect}") |
169 |
| - print_status("Current status of this service " + |
170 |
| - "#{service_query_ex(datastore['SSERVICE']).pretty_inspect}") if blab |
171 |
| -
|
172 |
| - print_status() |
173 |
| - print_status("TESTING service_delete on servicename: #{datastore['NSERVICE']}") |
174 |
| - results = service_delete(datastore['NSERVICE']) |
175 |
| - print_status("RESULTS: #{results.class} #{results.pretty_inspect}") |
176 |
| - print_status("Current status of this service " + |
177 |
| - "#{service_query_ex(datastore['QSERVICE']).pretty_inspect}") if blab |
178 |
| - print_status() |
179 |
| - print_status("Testing complete.") |
180 |
| - end |
181 |
| -=end |
182 |
| - |
183 |
| -end |
| 1 | +# |
| 2 | +# by kernelsmith (kernelsmith+\x40+kernelsmith+\.com) |
| 3 | +# |
| 4 | + |
| 5 | +require 'msf/core' |
| 6 | +require 'rex' |
| 7 | +require 'msf/core/post/windows/services' |
| 8 | + |
| 9 | +class Metasploit3 < Msf::Post |
| 10 | + |
| 11 | + include Msf::Post::Windows::Services |
| 12 | + |
| 13 | + include Msf::ModuleTest::PostTest |
| 14 | + |
| 15 | + def initialize(info={}) |
| 16 | + super( update_info( info, |
| 17 | + 'Name' => 'Test Post::Windows::Services', |
| 18 | + 'Description' => %q{ This module will test windows services methods within a shell}, |
| 19 | + 'License' => MSF_LICENSE, |
| 20 | + 'Author' => [ 'kernelsmith', 'egypt' ], |
| 21 | + 'Version' => '$Revision: 11663 $', |
| 22 | + 'Platform' => [ 'windows' ], |
| 23 | + 'SessionTypes' => [ 'meterpreter', 'shell' ] |
| 24 | + )) |
| 25 | + register_options( |
| 26 | + [ |
| 27 | + OptString.new("QSERVICE" , [true, "Service (keyname) to query", "winmgmt"]), |
| 28 | + OptString.new("NSERVICE" , [true, "New Service (keyname) to create/del", "testes"]), |
| 29 | + OptString.new("SSERVICE" , [true, "Service (keyname) to start/stop", "W32Time"]), |
| 30 | + OptString.new("DNAME" , [true, "Display name used for create test", "Cool display name"]), |
| 31 | + OptString.new("BINPATH" , [true, "Binary path for create test", "C:\\WINDOWS\\system32\\svchost.exe -k netsvcs"]), |
| 32 | + OptEnum.new("MODE", [true, "Mode to use for startup/create tests", "auto", |
| 33 | + ["auto", "manual", "disable"] |
| 34 | + ]), |
| 35 | + ], self.class) |
| 36 | + |
| 37 | + end |
| 38 | + |
| 39 | + def test_start |
| 40 | + it "should start #{datastore["SSERVICE"]}" do |
| 41 | + ret = true |
| 42 | + results = service_start(datastore['SSERVICE']) |
| 43 | + if results != 0 |
| 44 | + # Failed the first time, try to stop it first, then try again |
| 45 | + service_stop(datastore['SSERVICE']) |
| 46 | + results = service_start(datastore['SSERVICE']) |
| 47 | + end |
| 48 | + ret &&= (results == 0) |
| 49 | + |
| 50 | + ret |
| 51 | + end |
| 52 | + it "should stop #{datastore["SSERVICE"]}" do |
| 53 | + ret = true |
| 54 | + results = service_stop(datastore['SSERVICE']) |
| 55 | + ret &&= (results == 0) |
| 56 | + |
| 57 | + ret |
| 58 | + end |
| 59 | + end |
| 60 | + |
| 61 | + def test_list |
| 62 | + it "should list services" do |
| 63 | + ret = true |
| 64 | + results = service_list |
| 65 | + |
| 66 | + ret &&= results.kind_of? Array |
| 67 | + ret &&= results.length > 0 |
| 68 | + ret &&= results.include? datastore["QSERVICE"] |
| 69 | + |
| 70 | + ret |
| 71 | + end |
| 72 | + end |
| 73 | + |
| 74 | + def test_info |
| 75 | + it "should return info on a given service" do |
| 76 | + ret = true |
| 77 | + results = service_info(datastore['QSERVICE']) |
| 78 | + |
| 79 | + ret &&= results.kind_of? Hash |
| 80 | + if ret |
| 81 | + ret &&= results.has_key? "Name" |
| 82 | + ret &&= (results["Name"] == "Windows Management Instrumentation") |
| 83 | + ret &&= results.has_key? "Startup" |
| 84 | + ret &&= results.has_key? "Command" |
| 85 | + ret &&= results.has_key? "Credentials" |
| 86 | + end |
| 87 | + |
| 88 | + ret |
| 89 | + end |
| 90 | + end |
| 91 | + |
| 92 | + def test_create |
| 93 | + it "should create a service" do |
| 94 | + mode = case datastore["MODE"] |
| 95 | + when "disable"; 4 |
| 96 | + when "manual"; 3 |
| 97 | + when "auto"; 2 |
| 98 | + else; 2 |
| 99 | + end |
| 100 | + ret = service_create(datastore['NSERVICE'],datastore['DNAME'],datastore['BINPATH'],mode) |
| 101 | + |
| 102 | + ret |
| 103 | + end |
| 104 | + |
| 105 | + it "should return info on the newly-created service" do |
| 106 | + ret = true |
| 107 | + results = service_info(datastore['NSERVICE']) |
| 108 | + |
| 109 | + ret &&= results.kind_of? Hash |
| 110 | + ret &&= results.has_key? "Name" |
| 111 | + ret &&= (results["Name"] == datastore["DNAME"]) |
| 112 | + ret &&= results.has_key? "Startup" |
| 113 | + ret &&= (results["Startup"].downcase == datastore["MODE"]) |
| 114 | + ret &&= results.has_key? "Command" |
| 115 | + ret &&= results.has_key? "Credentials" |
| 116 | + |
| 117 | + ret |
| 118 | + end |
| 119 | + |
| 120 | + it "should delete the new service" do |
| 121 | + ret = service_delete(datastore['NSERVICE']) |
| 122 | + |
| 123 | + ret |
| 124 | + end |
| 125 | + end |
| 126 | + |
| 127 | + |
| 128 | +=begin |
| 129 | + def run |
| 130 | + blab = datastore['VERBOSE'] |
| 131 | + print_status("Running against session #{datastore["SESSION"]}") |
| 132 | + print_status("Session type is #{session.type}") |
| 133 | + print_status("Verbosity is set to #{blab.to_s}") |
| 134 | + print_status("Don't be surprised to see some errors as the script is faster") |
| 135 | + print_line("than the windows SCM, just make sure the errors are sane. You can") |
| 136 | + print_line("set VERBOSE to true to see more details") |
| 137 | +
|
| 138 | + print_status() |
| 139 | + print_status("TESTING service_query_ex on servicename: #{datastore["QSERVICE"]}") |
| 140 | + results = service_query_ex(datastore['QSERVICE']) |
| 141 | + print_status("RESULTS: #{results.class} #{results.pretty_inspect}") |
| 142 | +
|
| 143 | + print_status() |
| 144 | + print_status("TESTING service_query_config on servicename: #{datastore["QSERVICE"]}") |
| 145 | + results = service_query_config(datastore['QSERVICE']) |
| 146 | + print_status("RESULTS: #{results.class} #{results.pretty_inspect}") |
| 147 | +
|
| 148 | + print_status() |
| 149 | + print_status("TESTING service_change_startup on servicename: #{datastore['QSERVICE']} " + |
| 150 | + "to #{datastore['MODE']}") |
| 151 | + results = service_change_startup(datastore['QSERVICE'],datastore['MODE']) |
| 152 | + print_status("RESULTS: #{results.class} #{results.pretty_inspect}") |
| 153 | + print_status("Current status of this service " + |
| 154 | + "#{service_query_ex(datastore['QSERVICE']).pretty_inspect}") if blab |
| 155 | +
|
| 156 | + print_status() |
| 157 | + print_status("TESTING service_start on servicename: #{datastore['SSERVICE']}") |
| 158 | + results = service_start(datastore['SSERVICE']) |
| 159 | + print_status("RESULTS: #{results.class} #{results.pretty_inspect}") |
| 160 | + print_status("Current status of this service " + |
| 161 | + "#{service_query_ex(datastore['SSERVICE']).pretty_inspect}") if blab |
| 162 | + print_status("Sleeping to give the service a chance to start") |
| 163 | + select(nil, nil, nil, 2) # give the service time to start, reduces false negatives |
| 164 | +
|
| 165 | + print_status() |
| 166 | + print_status("TESTING service_stop on servicename: #{datastore['SSERVICE']}") |
| 167 | + results = service_stop(datastore['SSERVICE']) |
| 168 | + print_status("RESULTS: #{results.class} #{results.pretty_inspect}") |
| 169 | + print_status("Current status of this service " + |
| 170 | + "#{service_query_ex(datastore['SSERVICE']).pretty_inspect}") if blab |
| 171 | +
|
| 172 | + print_status() |
| 173 | + print_status("TESTING service_delete on servicename: #{datastore['NSERVICE']}") |
| 174 | + results = service_delete(datastore['NSERVICE']) |
| 175 | + print_status("RESULTS: #{results.class} #{results.pretty_inspect}") |
| 176 | + print_status("Current status of this service " + |
| 177 | + "#{service_query_ex(datastore['QSERVICE']).pretty_inspect}") if blab |
| 178 | + print_status() |
| 179 | + print_status("Testing complete.") |
| 180 | + end |
| 181 | +=end |
| 182 | + |
| 183 | +end |
0 commit comments