650
650
def run_msfconsole_command ( cmd )
651
651
# Attempts to run a the metasploit command first with the default env settings, and once again with the path set
652
652
# to the current directory. This ensures that it works in an environment such as bundler
653
- if @db_driver . run_cmd ( cmd ) != 0
653
+ # @msf_command holds the initial common part of commands (msfconsole -qx) and takes the optional specific commands as arguments (#{cmd})
654
+ msf_command = "msfconsole -qx '#{ cmd } '"
655
+ if @db_driver . run_cmd ( msf_command ) != 0
654
656
# attempt to execute msfconsole in the current working directory
655
- if @db_driver . run_cmd ( cmd , env : { 'PATH' => ".:#{ ENV [ "PATH" ] } " } ) != 0
657
+ if @db_driver . run_cmd ( msf_command , env : { 'PATH' => ".:#{ ENV [ "PATH" ] } " } ) != 0
656
658
puts 'Failed to run msfconsole'
657
659
end
658
660
end
@@ -661,14 +663,14 @@ end
661
663
def persist_data_service
662
664
puts 'Persisting http web data service credentials in msfconsole'
663
665
# execute msfconsole commands to add and persist the data service connection
664
- cmd = "msfconsole -qx ' #{ get_db_connect_command } ; db_save; exit' "
666
+ cmd = "#{ get_db_connect_command } ; db_save; exit"
665
667
run_msfconsole_command ( cmd )
666
668
end
667
669
668
670
def clear_default_data_service
669
671
puts 'Clearing http web data service credentials in msfconsole'
670
672
# execute msfconsole commands to clear the default data service connection
671
- cmd = "msfconsole -qx ' db_disconnect --clear; exit' "
673
+ cmd = "db_disconnect --clear; exit"
672
674
run_msfconsole_command ( cmd )
673
675
end
674
676
0 commit comments