Skip to content

Commit 93174a8

Browse files
committed
Land rapid7#3628 - Add --ask option in msfconsole
2 parents 2967d85 + b33d2b8 commit 93174a8

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

lib/msf/ui/console/command_dispatcher/core.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,14 @@ def cmd_exit(*args)
670670
if(framework.sessions.length > 0 and not forced)
671671
print_status("You have active sessions open, to exit anyway type \"exit -y\"")
672672
return
673+
elsif(driver.confirm_exit and not forced)
674+
print("Are you sure you want to exit Metasploit? [y/N]: ")
675+
response = gets.downcase.chomp
676+
if(response == "y" || response == "yes")
677+
driver.stop
678+
else
679+
return
680+
end
673681
end
674682

675683
driver.stop

lib/msf/ui/console/driver.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ def initialize(prompt = DefaultPrompt, prompt_char = DefaultPromptChar, opts = {
158158
# Whether or not command passthru should be allowed
159159
self.command_passthru = (opts['AllowCommandPassthru'] == false) ? false : true
160160

161+
# Whether or not to confirm before exiting
162+
self.confirm_exit = (opts['ConfirmExit'] == true) ? true : false
163+
161164
# Disables "dangerous" functionality of the console
162165
@defanged = opts['Defanged'] == true
163166

@@ -592,6 +595,10 @@ def on_variable_unset(glob, var)
592595
# The framework instance associated with this driver.
593596
#
594597
attr_reader :framework
598+
#
599+
# Whether or not to confirm before exiting
600+
#
601+
attr_reader :confirm_exit
595602
#
596603
# Whether or not commands can be passed through.
597604
#
@@ -628,6 +635,7 @@ def stop
628635
protected
629636

630637
attr_writer :framework # :nodoc:
638+
attr_writer :confirm_exit # :nodoc:
631639
attr_writer :command_passthru # :nodoc:
632640

633641
#

msfconsole

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ class OptsConsole
101101
options['DisableBanner'] = true
102102
end
103103

104+
opts.on("-a", "--ask", "Ask before exiting Metasploit or accept 'exit -y'") do |v|
105+
options['ConfirmExit'] = true
106+
end
107+
104108
opts.on("-x", "-x <command>", "Execute the specified string as console commands (use ; for multiples)") do |s|
105109
options['XCommands'] ||= []
106110
options['XCommands'] += s.split(/\s*;\s*/)

0 commit comments

Comments
 (0)