From f9f053064078e914aca4d555c6fb9459fba3dbce Mon Sep 17 00:00:00 2001 From: BenoitDePaoli Date: Tue, 7 Oct 2025 14:24:50 +0200 Subject: [PATCH] fix(console): prevent RHOSTS temp file deletion after services -R --- lib/msf/ui/console/command_dispatcher/common.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/msf/ui/console/command_dispatcher/common.rb b/lib/msf/ui/console/command_dispatcher/common.rb index e764b89b00e62..edbc1b4dc3c6d 100644 --- a/lib/msf/ui/console/command_dispatcher/common.rb +++ b/lib/msf/ui/console/command_dispatcher/common.rb @@ -89,6 +89,10 @@ def set_rhosts_from_addrs(rhosts) # create the output file and assign it to the RHOSTS variable rhosts_file.write(rhosts.join("\n")+"\n") rhosts_file.close + # Keep a reference so Ruby's GC doesn't finalize and unlink the temp file + # before a module has a chance to read it. + @persisted_rhosts_files ||= [] + @persisted_rhosts_files << rhosts_file else # For short lists, just set it directly mydatastore['RHOSTS'] = rhosts.join(" ")