Class: Msf::MCP::Metasploit::JsonRpcClient
- Inherits:
-
Object
- Object
- Msf::MCP::Metasploit::JsonRpcClient
- Defined in:
- lib/msf/core/mcp/metasploit/jsonrpc_client.rb
Overview
JSON-RPC 2.0 client for Metasploit Framework Implements bearer token authentication for the Metasploit JSON-RPC API Endpoint: /api/v1/json-rpc (default port 8081) See: lib/msf/core/rpc/json/ in Metasploit Framework repository
Constant Summary collapse
- DEFAULT_ENDPOINT =
'/api/v1/json-rpc'
Instance Method Summary collapse
-
#authenticate(_user, _password) ⇒ String
No-op for JSON-RPC: authentication uses a pre-configured bearer token.
-
#call_api(method, args = []) ⇒ Hash
Call Metasploit API method using JSON-RPC 2.0 format.
-
#db_creds(options = {}) ⇒ Hash
Get credentials from database.
-
#db_hosts(options = {}) ⇒ Hash
Get hosts from database.
-
#db_loot(options = {}) ⇒ Hash
Get loot from database.
-
#db_notes(options = {}) ⇒ Hash
Get notes from database.
-
#db_services(options = {}) ⇒ Hash
Get services from database.
-
#db_vulns(options = {}) ⇒ Hash
Get vulnerabilities from database.
-
#initialize(host:, port:, endpoint: DEFAULT_ENDPOINT, token:, ssl: true) ⇒ JsonRpcClient
constructor
Initialize JSON-RPC client.
-
#module_info(type, name) ⇒ Hash
Get module information.
-
#search_modules(query) ⇒ Array<Hash>
Search for Metasploit modules.
-
#shutdown ⇒ Object
Shutdown client.
Constructor Details
#initialize(host:, port:, endpoint: DEFAULT_ENDPOINT, token:, ssl: true) ⇒ JsonRpcClient
Initialize JSON-RPC client
21 22 23 24 25 26 27 28 29 |
# File 'lib/msf/core/mcp/metasploit/jsonrpc_client.rb', line 21 def initialize(host:, port:, endpoint: DEFAULT_ENDPOINT, token:, ssl: true) @host = host @port = port @endpoint = endpoint @token = token @request_id = 0 @http = nil @ssl = ssl end |
Instance Method Details
#authenticate(_user, _password) ⇒ String
No-op for JSON-RPC: authentication uses a pre-configured bearer token. This method exists so that JsonRpcClient satisfies the same interface as MessagePackClient, allowing the Client facade to delegate uniformly.
38 39 40 |
# File 'lib/msf/core/mcp/metasploit/jsonrpc_client.rb', line 38 def authenticate(_user, _password) @token end |
#call_api(method, args = []) ⇒ Hash
Call Metasploit API method using JSON-RPC 2.0 format
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/msf/core/mcp/metasploit/jsonrpc_client.rb', line 50 def call_api(method, args = []) raise ArgumentError, "args must be an Array, got #{args.class}" unless args.is_a?(Array) @request_id += 1 # Build JSON-RPC 2.0 request as a hash request_body = { jsonrpc: '2.0', method: method, params: args, id: @request_id } # Send HTTP request response = send_request(request_body) # Check for JSON-RPC error if response['error'] error_msg = response['error']['message'] || 'Unknown error' raise APIError, error_msg end response['result'] end |
#db_creds(options = {}) ⇒ Hash
Get credentials from database
121 122 123 |
# File 'lib/msf/core/mcp/metasploit/jsonrpc_client.rb', line 121 def db_creds( = {}) call_api('db.creds', []) end |
#db_hosts(options = {}) ⇒ Hash
Get hosts from database
93 94 95 |
# File 'lib/msf/core/mcp/metasploit/jsonrpc_client.rb', line 93 def db_hosts( = {}) call_api('db.hosts', []) end |
#db_loot(options = {}) ⇒ Hash
Get loot from database
128 129 130 |
# File 'lib/msf/core/mcp/metasploit/jsonrpc_client.rb', line 128 def db_loot( = {}) call_api('db.loots', []) end |
#db_notes(options = {}) ⇒ Hash
Get notes from database
114 115 116 |
# File 'lib/msf/core/mcp/metasploit/jsonrpc_client.rb', line 114 def db_notes( = {}) call_api('db.notes', []) end |
#db_services(options = {}) ⇒ Hash
Get services from database
100 101 102 |
# File 'lib/msf/core/mcp/metasploit/jsonrpc_client.rb', line 100 def db_services( = {}) call_api('db.services', []) end |
#db_vulns(options = {}) ⇒ Hash
Get vulnerabilities from database
107 108 109 |
# File 'lib/msf/core/mcp/metasploit/jsonrpc_client.rb', line 107 def db_vulns( = {}) call_api('db.vulns', []) end |
#module_info(type, name) ⇒ Hash
Get module information
86 87 88 |
# File 'lib/msf/core/mcp/metasploit/jsonrpc_client.rb', line 86 def module_info(type, name) call_api('module.info', [type, name]) end |
#search_modules(query) ⇒ Array<Hash>
Search for Metasploit modules
78 79 80 |
# File 'lib/msf/core/mcp/metasploit/jsonrpc_client.rb', line 78 def search_modules(query) call_api('module.search', [query]) end |
#shutdown ⇒ Object
Shutdown client
133 134 135 136 |
# File 'lib/msf/core/mcp/metasploit/jsonrpc_client.rb', line 133 def shutdown @http&.finish if @http&.started? @http = nil end |