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" serviceskey = "HKLM\\SYSTEM\\CurrentControlSet\\Services"
a =[] a =[]
services = [] services = []
registry_enumkeys(serviceskey).each do |s| keys = registry_enumkeys(serviceskey)
1.upto 10 do keys.each do |s|
a.push(::Thread.new(s) { |sk| if a.length >= 10
begin
srvtype = registry_getvaldata("#{serviceskey}\\#{sk}","Type").to_s
if srvtype =~ /32|16/
services << sk
end
rescue
end
})
end
until a.empty?
a.first.join a.first.join
a.delete_if {|x| not x.alive?} a.delete_if {|x| not x.alive?}
end 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 end
return services return services

View File

@ -6,11 +6,9 @@ require 'msf/core'
require 'rex' require 'rex'
require 'msf/core/post/windows/services' require 'msf/core/post/windows/services'
load 'lib/msf/core/post/windows/services.rb'
class Metasploit3 < Msf::Post class Metasploit3 < Msf::Post
include Msf::Post::Windows::WindowsServices include Msf::Post::Windows::Services
include Msf::ModuleTest::PostTest include Msf::ModuleTest::PostTest
@ -42,6 +40,11 @@ class Metasploit3 < Msf::Post
it "should start #{datastore["SSERVICE"]}" do it "should start #{datastore["SSERVICE"]}" do
ret = true ret = true
results = service_start(datastore['SSERVICE']) 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 &&= (results == 0)
ret ret