650650def run_msfconsole_command ( cmd )
651651 # Attempts to run a the metasploit command first with the default env settings, and once again with the path set
652652 # 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
654656 # 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
656658 puts 'Failed to run msfconsole'
657659 end
658660 end
@@ -661,14 +663,14 @@ end
661663def persist_data_service
662664 puts 'Persisting http web data service credentials in msfconsole'
663665 # 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"
665667 run_msfconsole_command ( cmd )
666668end
667669
668670def clear_default_data_service
669671 puts 'Clearing http web data service credentials in msfconsole'
670672 # execute msfconsole commands to clear the default data service connection
671- cmd = "./msfconsole -qx ' db_disconnect --clear; exit' "
673+ cmd = "db_disconnect --clear; exit"
672674 run_msfconsole_command ( cmd )
673675end
674676
0 commit comments