Class: Msf::RPC::JSON::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/msf/core/rpc/json/client.rb

Overview

JSON-RPC Client All client method call requests must be dispatched from within an EventMachine (reactor) run loop.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, api_token: nil, namespace: nil, symbolize_names: true, private_key_file: nil, cert_chain_file: nil, verify_peer: nil) ⇒ Client

Instantiate a Client. be prepended to the method name with a period separator. Default: nil processing JSON objects; otherwise, strings are used. Default: true from a peer, to be verified by user code. Default: nil

Parameters:

  • uri (String)

    the JSON-RPC service URI

  • api_token (String) (defaults to: nil)

    the API token. Default: nil

  • namespace (String) (defaults to: nil)

    the namespace for the JSON-RPC method. The namespace will

  • symbolize_names (Boolean) (defaults to: true)

    If true, symbols are used for the names (keys) when

  • private_key_file (String) (defaults to: nil)

    the SSL private key file used for the HTTPS request. Default: nil

  • cert_chain_file (String) (defaults to: nil)

    the SSL cert chain file used for the HTTPS request. Default: nil

  • verify_peer (Boolean) (defaults to: nil)

    indicates whether a server should request a certificate



26
27
28
29
30
31
32
33
34
35
# File 'lib/msf/core/rpc/json/client.rb', line 26

def initialize(uri, api_token: nil, namespace: nil, symbolize_names: true,
               private_key_file: nil, cert_chain_file: nil, verify_peer: nil)
  @uri = URI.parse(uri)
  @api_token = api_token
  @namespace = namespace
  @symbolize_names = symbolize_names
  @private_key_file = private_key_file
  @cert_chain_file = cert_chain_file
  @verify_peer = verify_peer
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args, **keyword_args, &block) ⇒ Msf::RPC::JSON::Request (private)

Invoked by Ruby when obj is sent a message it cannot handle, then processes the call as an RPC method invocation.

Parameters:

  • symbol (Symbol)

    the symbol for the method called

  • args (Array)

    any positional arguments passed to the method

  • keyword_args (Hash)

    any keyword arguments passed to the method

Returns:



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/msf/core/rpc/json/client.rb', line 45

def method_missing(symbol, *args, **keyword_args, &block)
  # assemble method parameters
  if !args.empty? && !keyword_args.empty?
    params = args << keyword_args
  elsif !args.empty?
    params = args
  elsif !keyword_args.empty?
    params = keyword_args
  else
    params = nil
  end

  process_call_async(symbol, params)
end

Instance Attribute Details

#api_tokenObject (readonly)

Returns the value of attribute api_token.



11
12
13
# File 'lib/msf/core/rpc/json/client.rb', line 11

def api_token
  @api_token
end

#namespaceObject

Returns the value of attribute namespace.



13
14
15
# File 'lib/msf/core/rpc/json/client.rb', line 13

def namespace
  @namespace
end

#symbolize_namesObject (readonly)

Returns the value of attribute symbolize_names.



12
13
14
# File 'lib/msf/core/rpc/json/client.rb', line 12

def symbolize_names
  @symbolize_names
end

#uriObject (readonly)

Returns the value of attribute uri.



10
11
12
# File 'lib/msf/core/rpc/json/client.rb', line 10

def uri
  @uri
end