Fix bug #6815: A race condition that results in an invalid handle.

Under certain conditions, the module may run into an "The handle
is invalid" while obtaining registry keys and values from the
victim machine.  The fix is to retry a couple of times, and hope
we don't hit the race condition again.
unstable
sinn3r 2012-05-14 17:44:35 -05:00
parent 3033838909
commit 6bbf018423
1 changed files with 14 additions and 2 deletions

View File

@ -58,6 +58,8 @@ class Metasploit3 < Msf::Post
end
def run
tries = 0
begin
print_status("Obtaining the boot key...")
@ -93,8 +95,18 @@ class Metasploit3 < Msf::Post
rescue ::Interrupt
raise $!
rescue ::Rex::Post::Meterpreter::RequestError => e
print_error("Meterpreter Exception: #{e.class} #{e}")
print_error("This script requires the use of a SYSTEM user context (hint: migrate into service process)")
# Sometimes we get this invalid handle race condition.
# So let's retry a couple of times before giving up.
# See bug #6815
if tries < 5 and e.to_s =~ /The handle is invalid/
print_status("Handle is invalid, retrying...")
tries += 1
retry
else
print_error("Meterpreter Exception: #{e.class} #{e}")
print_error("This script requires the use of a SYSTEM user context (hint: migrate into service process)")
end
#rescue ::Exception => e
# print_error("Error: #{e.class} #{e} #{e.backtrace}")
end