Browse Source

Adds --ask option to prompt before exiting msfconsole

Iquaba 5 years ago
parent
commit
6cea921478
3 changed files with 20 additions and 1 deletions
  1. 8
    1
      lib/msf/ui/console/command_dispatcher/core.rb
  2. 8
    0
      lib/msf/ui/console/driver.rb
  3. 4
    0
      msfconsole

+ 8
- 1
lib/msf/ui/console/command_dispatcher/core.rb View File

@@ -670,8 +670,15 @@ class Core
670 670
     if(framework.sessions.length > 0 and not forced)
671 671
       print_status("You have active sessions open, to exit anyway type \"exit -y\"")
672 672
       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
673 681
     end
674
-
675 682
     driver.stop
676 683
   end
677 684
 

+ 8
- 0
lib/msf/ui/console/driver.rb View File

@@ -158,6 +158,9 @@ class Driver < Msf::Ui::Driver
158 158
     # Whether or not command passthru should be allowed
159 159
     self.command_passthru = (opts['AllowCommandPassthru'] == false) ? false : true
160 160
 
161
+    # Whether or not to confirm before exiting
162
+    self.confirm_exit = (opts['ConfirmExit'] == true) ? true : false
163
+
161 164
     # Disables "dangerous" functionality of the console
162 165
     @defanged = opts['Defanged'] == true
163 166
 
@@ -592,6 +595,10 @@ class Driver < Msf::Ui::Driver
592 595
   # The framework instance associated with this driver.
593 596
   #
594 597
   attr_reader   :framework
598
+  #  
599
+  # Whether or not to confirm before exiting
600
+  #  
601
+  attr_reader   :confirm_exit
595 602
   #
596 603
   # Whether or not commands can be passed through.
597 604
   #
@@ -628,6 +635,7 @@ class Driver < Msf::Ui::Driver
628 635
 protected
629 636
 
630 637
   attr_writer   :framework # :nodoc:
638
+  attr_writer   :confirm_exit # :nodoc:
631 639
   attr_writer   :command_passthru # :nodoc:
632 640
 
633 641
   #

+ 4
- 0
msfconsole View File

@@ -101,6 +101,10 @@ class OptsConsole
101 101
         options['DisableBanner'] = true
102 102
       end
103 103
 
104
+      opts.on("-a", "--ask", "Ask before exiting Metasploit or accept 'exit -y'") do |v|
105
+        options['ConfirmExit'] = true
106
+      end
107
+      
104 108
       opts.on("-x", "-x <command>", "Execute the specified string as console commands (use ; for multiples)") do |s|
105 109
         options['XCommands'] ||= []
106 110
         options['XCommands'] += s.split(/\s*;\s*/)

Loading…
Cancel
Save