From 60bd00ee5bf55712b6e37d330c2f99e41e737254 Mon Sep 17 00:00:00 2001 From: Matthew Kienow Date: Fri, 28 Sep 2018 10:51:10 -0400 Subject: [PATCH] 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. --- lib/msf/core/rpc/json/rpc_command.rb | 31 ----------------------- lib/msf/core/rpc/json/v1_0/rpc_command.rb | 28 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/lib/msf/core/rpc/json/rpc_command.rb b/lib/msf/core/rpc/json/rpc_command.rb index a995940a72..e23c3948be 100644 --- a/lib/msf/core/rpc/json/rpc_command.rb +++ b/lib/msf/core/rpc/json/rpc_command.rb @@ -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 \ No newline at end of file diff --git a/lib/msf/core/rpc/json/v1_0/rpc_command.rb b/lib/msf/core/rpc/json/v1_0/rpc_command.rb index 12f058ec15..293e37ad08 100644 --- a/lib/msf/core/rpc/json/v1_0/rpc_command.rb +++ b/lib/msf/core/rpc/json/v1_0/rpc_command.rb @@ -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