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