msf-json-rpc.ru 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. require 'pathname'
  6. @framework_path = File.expand_path(File.dirname(__FILE__))
  7. root = Pathname.new(@framework_path).expand_path
  8. @framework_lib_path = root.join('lib')
  9. $LOAD_PATH << @framework_lib_path.to_path unless $LOAD_PATH.include?(@framework_lib_path)
  10. require 'msfenv'
  11. if ENV['MSF_LOCAL_LIB']
  12. $LOAD_PATH << ENV['MSF_LOCAL_LIB'] unless $LOAD_PATH.include?(ENV['MSF_LOCAL_LIB'])
  13. end
  14. run Msf::WebServices::JsonRpcApp
  15. #
  16. # Ensure that framework is loaded before any external requests can be routed to the running
  17. # application. This stops the possibility of the rack application being alive, but all
  18. # requests failing.
  19. #
  20. warmup do |app|
  21. client = Rack::MockRequest.new(app)
  22. response = client.get('/api/v1/health')
  23. warmup_error_message = "Metasploit JSON RPC did not successfully start up. Unexpected response returned: '#{response.body}'"
  24. begin
  25. parsed_response = JSON.parse(response.body)
  26. rescue JSON::ParserError => e
  27. raise warmup_error_message, e
  28. end
  29. expected_response = { 'data' => { 'status' => 'UP' } }
  30. is_valid_response = parsed_response == expected_response
  31. unless is_valid_response
  32. raise warmup_error_message
  33. end
  34. end