Skip to content

Commit c47ea05

Browse files
committed
make msf_cmd syntax more maintainable
1 parent 30b1b4f commit c47ea05

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Diff for: msfdb

+6-4
Original file line numberDiff line numberDiff line change
@@ -650,9 +650,11 @@ end
650650
def 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
661663
def 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)
666668
end
667669

668670
def 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)
673675
end
674676

0 commit comments

Comments
 (0)