CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/msf-json-rpc.ru
Views: 1903
1
# msf-json-rpc.ru
2
# Start using thin:
3
# thin --rackup msf-json-rpc.ru --address localhost --port 8081 --environment development --tag msf-json-rpc start
4
#
5
6
require 'pathname'
7
@framework_path = File.expand_path(File.dirname(__FILE__))
8
root = Pathname.new(@framework_path).expand_path
9
@framework_lib_path = root.join('lib')
10
$LOAD_PATH << @framework_lib_path.to_path unless $LOAD_PATH.include?(@framework_lib_path)
11
12
require 'msfenv'
13
14
if ENV['MSF_LOCAL_LIB']
15
$LOAD_PATH << ENV['MSF_LOCAL_LIB'] unless $LOAD_PATH.include?(ENV['MSF_LOCAL_LIB'])
16
end
17
18
run Msf::WebServices::JsonRpcApp
19
20
#
21
# Ensure that framework is loaded before any external requests can be routed to the running
22
# application. This stops the possibility of the rack application being alive, but all
23
# requests failing.
24
#
25
warmup do |app|
26
client = Rack::MockRequest.new(app)
27
response = client.get('/api/v1/health')
28
29
warmup_error_message = "Metasploit JSON RPC did not successfully start up. Unexpected response returned: '#{response.body}'"
30
begin
31
parsed_response = JSON.parse(response.body)
32
rescue JSON::ParserError => e
33
raise warmup_error_message, e
34
end
35
36
expected_response = { 'data' => { 'status' => 'UP' } }
37
is_valid_response = parsed_response == expected_response
38
39
unless is_valid_response
40
raise warmup_error_message
41
end
42
end
43
44