From db6377134e6fbf5a500a29506d4cd365997a9df4 Mon Sep 17 00:00:00 2001 From: Brent Cook Date: Tue, 28 Nov 2017 12:04:19 -0600 Subject: [PATCH] restore original module RHOST on abort --- lib/msf/ui/console/command_dispatcher/exploit.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/msf/ui/console/command_dispatcher/exploit.rb b/lib/msf/ui/console/command_dispatcher/exploit.rb index 749a12ec56..8264119f1e 100644 --- a/lib/msf/ui/console/command_dispatcher/exploit.rb +++ b/lib/msf/ui/console/command_dispatcher/exploit.rb @@ -48,12 +48,15 @@ class Exploit end def exploit_single(opts, rhost = nil) + orig_rhost = mod.datastore['RHOST'] begin - mod.datastore['RHOST'] = rhost if rhost + mod.datastore['RHOST'] = rhost if orig_rhost session = mod.exploit_simple(opts) rescue ::Interrupt + mod.datastore['RHOST'] = orig_rhost raise $! rescue ::Exception => e + mod.datastore['RHOST'] = orig_rhost print_error("Exploit exception (#{mod.refname}): #{e.class} #{e}") if e.class.to_s != 'Msf::OptionValidateError' print_error("Call stack:") @@ -97,6 +100,7 @@ class Exploit end end end + mod.datastore['RHOST'] = orig_rhost end def cmd_exploit_tabs(str, words)