Move prepare_params method to v1.0 RpcCommand

The method was created to support RPC v1.0 (v10) processing and should
not be necessary for future RPC versions.
GSoC/Meterpreter_Web_Console
Matthew Kienow 2018-09-28 10:51:10 -04:00
parent ab443831a9
commit 60bd00ee5b
No known key found for this signature in database
GPG Key ID: 40787F8B1EAC6E41
2 changed files with 28 additions and 31 deletions

View File

@ -40,7 +40,6 @@ module Msf::RPC::JSON
end
::Timeout.timeout(@execute_timeout) do
params = prepare_params(params)
if params.nil?
return @methods[method].call()
elsif params.is_a?(Array)
@ -50,35 +49,5 @@ module Msf::RPC::JSON
end
end
end
private
# Prepare params for use by RPC methods by converting all hashes
# to use strings for their names (keys).
# @param params [Array, Hash] parameters for the RPC call
# @returns [Array, Hash] modified parameters
def prepare_params(params)
clean_params = params
if params.is_a?(Array)
clean_params = params.map do |p|
if p.is_a?(Hash)
stringify_names(p)
else
p
end
end
elsif params.is_a?(Hash)
clean_params = stringify_names(params)
end
clean_params
end
# Stringify the names (keys) in hash.
# @param hash [Hash] input hash
# @returns [Hash] a new hash with strings for the keys.
def stringify_names(hash)
JSON.parse(JSON.dump(hash), symbolize_names: false)
end
end
end

View File

@ -106,6 +106,34 @@ module Msf::RPC::JSON
handler
end
# Prepare params for use by RPC methods by converting all hashes
# to use strings for their names (keys).
# @param params [Array, Hash] parameters for the RPC call
# @returns [Array, Hash] modified parameters
def prepare_params(params)
clean_params = params
if params.is_a?(Array)
clean_params = params.map do |p|
if p.is_a?(Hash)
stringify_names(p)
else
p
end
end
# elsif params.is_a?(Hash)
# clean_params = stringify_names(params)
end
clean_params
end
# Stringify the names (keys) in hash.
# @param hash [Hash] input hash
# @returns [Hash] a new hash with strings for the keys.
def stringify_names(hash)
JSON.parse(JSON.dump(hash), symbolize_names: false)
end
# Perform custom post processing of the execute result data.
# @param result [Object] the method's return value
# @param method [String] the RPC method name