Unfubar the threading for #service_list

Also makes the test for service_start a little more resilient in case
W32Time is already started
unstable
James Lee 2012-11-06 18:29:42 -06:00
parent 34bc92584b
commit 7a6ccb92ab
2 changed files with 19 additions and 16 deletions

View File

@ -91,22 +91,22 @@ module Services
serviceskey = "HKLM\\SYSTEM\\CurrentControlSet\\Services"
a =[]
services = []
registry_enumkeys(serviceskey).each do |s|
1.upto 10 do
a.push(::Thread.new(s) { |sk|
begin
srvtype = registry_getvaldata("#{serviceskey}\\#{sk}","Type").to_s
if srvtype =~ /32|16/
services << sk
end
rescue
end
})
end
until a.empty?
keys = registry_enumkeys(serviceskey)
keys.each do |s|
if a.length >= 10
a.first.join
a.delete_if {|x| not x.alive?}
end
t = framework.threads.spawn(self.refname+"-ServiceRegistryList",false,s) { |sk|
begin
srvtype = registry_getvaldata("#{serviceskey}\\#{sk}","Type").to_s
if srvtype == "32" or srvtype == "16"
services << sk
end
rescue
end
}
a.push(t)
end
return services

View File

@ -6,11 +6,9 @@ require 'msf/core'
require 'rex'
require 'msf/core/post/windows/services'
load 'lib/msf/core/post/windows/services.rb'
class Metasploit3 < Msf::Post
include Msf::Post::Windows::WindowsServices
include Msf::Post::Windows::Services
include Msf::ModuleTest::PostTest
@ -42,6 +40,11 @@ class Metasploit3 < Msf::Post
it "should start #{datastore["SSERVICE"]}" do
ret = true
results = service_start(datastore['SSERVICE'])
if results != 0
# Failed the first time, try to stop it first, then try again
service_stop(datastore['SSERVICE'])
results = service_start(datastore['SSERVICE'])
end
ret &&= (results == 0)
ret