Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/spec/support/acceptance/datastore_formatting.rb
74512 views
1
# frozen_string_literal: true
2
3
module Acceptance
4
# Shared helper for rendering datastore options as a command-line string
5
# suitable for msfconsole. Used by both Target and Payload.
6
module DatastoreFormatting
7
# @param [Hash] module_datastore The merged datastore hash
8
# @return [String] The formatted datastore options string
9
def format_datastore_options(module_datastore)
10
module_options = module_datastore.map do |key, value|
11
value_str = value.to_s
12
if value_str.match?(/[\s'"\\]/)
13
escaped = value_str.gsub('"', '\\"')
14
"#{key}=\"#{escaped}\""
15
else
16
"#{key}=#{value_str}"
17
end
18
end
19
20
module_options.join(' ')
21
end
22
end
23
end
24
25