From 4acf695de99948feb5b937896d10779fd41bb7b5 Mon Sep 17 00:00:00 2001 From: Matthew Kienow Date: Thu, 20 Sep 2018 18:05:36 -0400 Subject: [PATCH] Remove debug output and unused code --- lib/msf/core/rpc/json/dispatcher.rb | 22 ------------------- lib/msf/core/rpc/json/dispatcher_helper.rb | 6 ----- lib/msf/core/rpc/json/rpc_command.rb | 13 ----------- lib/msf/core/rpc/json/rpc_command_factory.rb | 2 -- lib/msf/core/rpc/json/v1_0/rpc_command.rb | 17 -------------- lib/msf/core/rpc/json/v2_0/rpc_test.rb | 9 +------- .../web_services/servlet/json_rpc_servlet.rb | 3 --- 7 files changed, 1 insertion(+), 71 deletions(-) diff --git a/lib/msf/core/rpc/json/dispatcher.rb b/lib/msf/core/rpc/json/dispatcher.rb index eaebadf587..a1b5a83b53 100644 --- a/lib/msf/core/rpc/json/dispatcher.rb +++ b/lib/msf/core/rpc/json/dispatcher.rb @@ -15,16 +15,12 @@ module Msf::RPC::JSON def set_command(command) @command = command - $stderr.puts("Msf::RPC::JSON::Dispatcher.set_command(): command=#{command}, @command=#{@command}") # TODO: remove end def process(source) begin - $stderr.puts("Msf::RPC::JSON::Dispatcher.process(): source=#{source}") # TODO: remove request = parse_json_request(source) - $stderr.puts("Msf::RPC::JSON::Dispatcher.process(): request=#{request}") # TODO: remove if request.is_a?(Array) - $stderr.puts("Msf::RPC::JSON::Dispatcher.process(): batch request") # TODO: remove # If the batch rpc call itself fails to be recognized as an valid # JSON or as an Array with at least one value, the response from # the Server MUST be a single Response object. @@ -58,8 +54,6 @@ module Msf::RPC::JSON def process_request(request) begin - $stderr.puts("Msf::RPC::JSON::Dispatcher.process_request(): request=#{request}") # TODO: remove - if !validate_rpc_request(request) response = self.class.create_error_response(InvalidRequest.new) return response @@ -67,7 +61,6 @@ module Msf::RPC::JSON # dispatch method execution to command result = @command.execute(request[:method], request[:params]) - $stderr.puts("Msf::RPC::JSON::Dispatcher.process_request(): dispatch result=#{result}, result.class=#{result.class}") # TODO: remove # A Notification is a Request object without an "id" member. A Request # object that is a Notification signifies the Client's lack of interest @@ -85,8 +78,6 @@ module Msf::RPC::JSON raise InvalidParams.new rescue Msf::RPC::Exception => e ApplicationServerError.new(e.message, data: { code: e.code }) - # rescue => e - # raise ApplicationServerError.new(e) end end @@ -113,29 +104,18 @@ module Msf::RPC::JSON id: [Integer, String, NilClass] } - $stderr.puts("Msf::RPC::JSON::Dispatcher.validate_rpc_request(): request.is_a?(Hash)=#{request.is_a?(Hash)}, request=#{request}") # validate request is an object return false unless request.is_a?(Hash) # validate request contains required members required_members.each { |member| return false unless request.key?(member) } - # required_members.each do |member| - # $stderr.puts("Msf::RPC::JSON::Dispatcher.validate_rpc_request(): member=#{member}, request.key?(member)=#{request.key?(member)}") - # return false unless request.key?(member) - # end - $stderr.puts("Msf::RPC::JSON::Dispatcher.validate_rpc_request(): request[:jsonrpc] != JSON_RPC_VERSION=#{request[:jsonrpc] != JSON_RPC_VERSION}") return false if request[:jsonrpc] != JSON_RPC_VERSION # validate request members are correct types request.each do |member, value| return false if member_types.key?(member) && !member_types[member].one? { |type| value.is_a?(type) } - # if member_types.key?(member) && !member_types[member].one? { |type| value.is_a?(type) } - # return false - # else - # return false - # end end true @@ -172,7 +152,6 @@ module Msf::RPC::JSON } self.add_response_id_member(response, request) - $stderr.puts("Msf::RPC::JSON::Dispatcher.success_response(): response=#{response}") response end @@ -189,7 +168,6 @@ module Msf::RPC::JSON } self.add_response_id_member(response, request) - $stderr.puts("Msf::RPC::JSON::Dispatcher.error_response(): response=#{response}") response end diff --git a/lib/msf/core/rpc/json/dispatcher_helper.rb b/lib/msf/core/rpc/json/dispatcher_helper.rb index 64544f449b..a4e08f563a 100644 --- a/lib/msf/core/rpc/json/dispatcher_helper.rb +++ b/lib/msf/core/rpc/json/dispatcher_helper.rb @@ -3,10 +3,8 @@ require 'msf/core/rpc' module Msf::RPC::JSON module DispatcherHelper def get_dispatcher(dispatchers, version, framework) - $stderr.puts("Msf::RPC::JSON::DispatcherHelper.get_dispatcher(): dispatchers=#{dispatchers}, version=#{version}, framework=#{framework}") version_sym = version.to_sym unless dispatchers.key?(version_sym) - $stderr.puts("Msf::RPC::JSON::DispatcherHelper.get_dispatcher(): creating dispatcher for RPC version #{version}...") dispatchers[version_sym] = create_dispatcher(version_sym, framework) end @@ -14,11 +12,7 @@ module Msf::RPC::JSON end def create_dispatcher(version, framework) - $stderr.puts("Msf::RPC::JSON::DispatcherHelper.create_dispatcher(): version=#{version}, framework=#{framework}") - $stderr.puts("Msf::RPC::JSON::DispatcherHelper.create_dispatcher(): creating RpcCommand...") command = RpcCommandFactory.create(version, framework) - $stderr.puts("Msf::RPC::JSON::DispatcherHelper.create_dispatcher(): command=#{command}") - $stderr.puts("Msf::RPC::JSON::DispatcherHelper.create_dispatcher(): creating Dispatcher...") dispatcher = Dispatcher.new(framework) dispatcher.set_command(command) diff --git a/lib/msf/core/rpc/json/rpc_command.rb b/lib/msf/core/rpc/json/rpc_command.rb index 10df34c4c7..d053fac5db 100644 --- a/lib/msf/core/rpc/json/rpc_command.rb +++ b/lib/msf/core/rpc/json/rpc_command.rb @@ -7,18 +7,12 @@ module Msf::RPC::JSON @framework = framework @execute_timeout = execute_timeout @methods = {} - - $stderr.puts("Msf::RPC::JSON::RpcCommand.initialize(): @framework=#{@framework}, @framework.object_id=#{@framework.object_id}") - $stderr.puts("Msf::RPC::JSON::RpcCommand.initialize(): @execute_timeout=#{@execute_timeout}") - $stderr.puts("Msf::RPC::JSON::RpcCommand.initialize(): @methods=#{@methods}") end # Add a method to the RPC Command def register_method(method, name: nil) - $stderr.puts("Msf::RPC::JSON::RpcCommand.register_method(): method.class=#{method.class}, method.inspect=#{method.inspect}, name=#{name}") if name.nil? if method.is_a?(Method) - $stderr.puts("Msf::RPC::JSON::RpcCommand.register_method(): method.name=#{method.name}") name = method.name.to_s else name = method.to_s @@ -29,16 +23,10 @@ module Msf::RPC::JSON # Call method on the receiver object previously registered. def execute(method, params) - $stderr.puts("Msf::RPC::JSON::RpcCommand.execute(): method=#{method}, params=#{params}") - $stderr.puts("Msf::RPC::JSON::RpcCommand.execute(): @methods.key?(method)=#{@methods.key?(method)}") - $stderr.puts("Msf::RPC::JSON::RpcCommand.execute(): @methods[method]=#{@methods[method]}") if @methods.key?(method) - unless @methods.key?(method) - $stderr.puts("Msf::RPC::JSON::RpcCommand.execute(): raising MethodNotFound...") raise MethodNotFound.new(method) end - $stderr.puts("Msf::RPC::JSON::RpcCommand.execute(): calling method_name=#{method}...") ::Timeout.timeout(@execute_timeout) do params = prepare_params(params) if params.nil? @@ -68,7 +56,6 @@ module Msf::RPC::JSON clean_params = stringify_names(params) end - $stderr.puts("Msf::RPC::JSON::RpcCommand.prepare_params(): params=#{params}, clean_params=#{clean_params}") clean_params end diff --git a/lib/msf/core/rpc/json/rpc_command_factory.rb b/lib/msf/core/rpc/json/rpc_command_factory.rb index 6ac2c0b4e2..22a2c6328f 100644 --- a/lib/msf/core/rpc/json/rpc_command_factory.rb +++ b/lib/msf/core/rpc/json/rpc_command_factory.rb @@ -5,7 +5,6 @@ require 'msf/core/rpc/json/v2_0/rpc_test' module Msf::RPC::JSON class RpcCommandFactory def self.create(version, framework) - $stderr.puts("Msf::RPC::JSON::RpcCommandFactory.create: version=#{version}, framework=#{framework}") # TODO: remove case version when :v1, :v1_0, :v10 return Msf::RPC::JSON::V1_0::RpcCommand.new(framework) @@ -20,7 +19,6 @@ module Msf::RPC::JSON # TODO: does belong in some sort of loader class for an RPC version? # instantiate receiver rpc_test = Msf::RPC::JSON::V2_0::RpcTest.new() - $stderr.puts("Msf::RPC::JSON::RpcCommandFactory.create_rpc_command_v2_0: rpc_test=#{rpc_test}") command = Msf::RPC::JSON::RpcCommand.new(framework) 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 dd37929665..5313973920 100644 --- a/lib/msf/core/rpc/json/v1_0/rpc_command.rb +++ b/lib/msf/core/rpc/json/v1_0/rpc_command.rb @@ -19,9 +19,6 @@ module Msf::RPC::JSON @legacy_rpc_service = ::Msf::RPC::Service.new(@framework, { execute_timeout: @execute_timeout }) - - $stderr.puts("Msf::RPC::JSON::V1_0::RpcCommand.initialize(): @framework=#{@framework}, @framework.object_id=#{@framework.object_id}") - $stderr.puts("Msf::RPC::JSON::V1_0::RpcCommand.initialize(): @legacy_rpc_service=#{@legacy_rpc_service}, @legacy_rpc_service.handlers=#{@legacy_rpc_service.handlers}") end def register_method(method, name: nil) @@ -42,25 +39,14 @@ module Msf::RPC::JSON # Call method on the receiver object previously registered. def execute_internal(method, params) - $stderr.puts("Msf::RPC::JSON::V1_0::RpcCommand.execute(): method=#{method}, params=#{params}") - # parse method string group, base_method = parse_method_group(method) - $stderr.puts("Msf::RPC::JSON::V1_0::RpcCommand.execute(): group=#{group}, base_method=#{base_method}") # TODO: remove method_name = "rpc_#{base_method}" method_name_noauth = "rpc_#{base_method}_noauth" - $stderr.puts("Msf::RPC::JSON::V1_0::RpcCommand.execute(): method_name=#{base_method}, method_name_noauth=#{method_name_noauth}, @legacy_rpc_service.handlers[group]=#{@legacy_rpc_service.handlers[group]}") - $stderr.puts("Msf::RPC::JSON::V1_0::RpcCommand.execute(): @legacy_rpc_service.handlers[group].nil?=#{@legacy_rpc_service.handlers[group].nil?}") - $stderr.puts("Msf::RPC::JSON::V1_0::RpcCommand.execute(): @legacy_rpc_service.handlers[group].respond_to?(method_name)=#{@legacy_rpc_service.handlers[group].respond_to?(method_name)}") - $stderr.puts("Msf::RPC::JSON::V1_0::RpcCommand.execute(): @legacy_rpc_service.handlers[group].respond_to?(method_name_noauth)=#{@legacy_rpc_service.handlers[group].respond_to?(method_name_noauth)}") - - handler = (find_handler(@legacy_rpc_service.handlers, group, method_name) || find_handler(@legacy_rpc_service.handlers, group, method_name_noauth)) - $stderr.puts("Msf::RPC::JSON::V1_0::RpcCommand.execute(): handler=#{handler}") if handler.nil? - $stderr.puts("Msf::RPC::JSON::V1_0::RpcCommand.execute(): raising MethodNotFound...") raise MethodNotFound.new(method) end @@ -68,8 +54,6 @@ module Msf::RPC::JSON method_name = method_name_noauth end - - $stderr.puts("Msf::RPC::JSON::V1_0::RpcCommand.execute(): calling method_name=#{method_name}...") ::Timeout.timeout(@execute_timeout) do params = prepare_params(params) if params.nil? @@ -107,7 +91,6 @@ module Msf::RPC::JSON if method == MODULE_EXECUTE_KEY && params.size >= 2 && params[0] == PAYLOAD_MODULE_TYPE_KEY && result.key?(PAYLOAD_KEY) result[PAYLOAD_KEY] = Base64.strict_encode64(result[PAYLOAD_KEY]) - $stderr.puts("Msf::RPC::JSON::V1_0::RpcCommand.post_process_result(): converted result key '#{PAYLOAD_KEY}': new value=#{result[PAYLOAD_KEY]}") end result diff --git a/lib/msf/core/rpc/json/v2_0/rpc_test.rb b/lib/msf/core/rpc/json/v2_0/rpc_test.rb index 615262b793..a81544b4bd 100644 --- a/lib/msf/core/rpc/json/v2_0/rpc_test.rb +++ b/lib/msf/core/rpc/json/v2_0/rpc_test.rb @@ -4,25 +4,18 @@ module Msf::RPC::JSON::V2_0 def initialize r = Random.new @rand_num = r.rand(0..100) - $stderr.puts("Msf::RPC::JSON::V2_0::RpcTest.initialize(): @rand_num=#{@rand_num}") end def self.add(x, y) - result = x + y - $stderr.puts("Msf::RPC::JSON::V2_0::RpcTest.add(): x=#{x}, y=#{y}, result=#{result}") - - result + x + y end def get_instance_rand_num - $stderr.puts("Msf::RPC::JSON::V2_0::RpcTest instance.get_instance_rand_num(): @rand_num=#{@rand_num}") - @rand_num end def add_instance_rand_num(x) @rand_num = @rand_num + x - $stderr.puts("Msf::RPC::JSON::V2_0::RpcTest instance.add_instance_rand_num(): x=#{x}, @rand_num=#{@rand_num}") @rand_num end diff --git a/lib/msf/core/web_services/servlet/json_rpc_servlet.rb b/lib/msf/core/web_services/servlet/json_rpc_servlet.rb index dcbce72157..1299ef037a 100644 --- a/lib/msf/core/web_services/servlet/json_rpc_servlet.rb +++ b/lib/msf/core/web_services/servlet/json_rpc_servlet.rb @@ -19,10 +19,7 @@ module JsonRpcServlet warden.authenticate! begin body = request.body.read - $stderr.puts("JsonRpcServlet: body=#{body}") tmp_params = sanitize_params(params) - $stderr.puts("JsonRpcServlet: tmp_params=#{tmp_params}") - data = get_dispatcher(settings.dispatchers, tmp_params[:version], settings.framework).process(body) set_raw_response(data) rescue => e