File tree Expand file tree Collapse file tree
lib/msf/core/web_services Expand file tree Collapse file tree Original file line number Diff line number Diff line change 7373 pdf-reader
7474 pg
7575 puma
76- rack (~> 2.2 )
76+ rack (~> 3.1 )
7777 railties
7878 rasn1 (= 0.14.0 )
7979 rb-readline
@@ -106,13 +106,13 @@ PATH
106106 ruby_smb (~> 3.3.19 )
107107 rubyntlm
108108 rubyzip
109- sinatra (~> 3.2 )
109+ sinatra (~> 4.1 )
110110 sqlite3 (= 1.7.3 )
111111 sshkey
112112 stringio (= 3.1.1 )
113113 swagger-blocks
114114 syslog
115- thin (~> 1.x )
115+ thin (~> 2.0 )
116116 tzinfo
117117 tzinfo-data
118118 unix-crypt
@@ -445,24 +445,25 @@ GEM
445445 pry-byebug (3.11.0 )
446446 byebug (~> 12.0 )
447447 pry (>= 0.13 , < 0.16 )
448- psych (5.2.6 )
448+ psych (5.3.1 )
449449 date
450450 stringio
451451 public_suffix (6.0.2 )
452452 puma (6.6.0 )
453453 nio4r (~> 2.0 )
454454 racc (1.8.1 )
455- rack (2.2.19 )
456- rack-protection (3 .2.0 )
455+ rack (3.1.21 )
456+ rack-protection (4 .2.1 )
457457 base64 (>= 0.1.0 )
458- rack (~> 2.2 , >= 2.2.4 )
459- rack-session (1.0.2 )
460- rack (< 3 )
458+ logger (>= 1.6.0 )
459+ rack (>= 3.0.0 , < 4 )
460+ rack-session (2.1.2 )
461+ base64 (>= 0.1.0 )
462+ rack (>= 3.0.0 )
461463 rack-test (2.2.0 )
462464 rack (>= 1.3 )
463- rackup (1.0.1 )
464- rack (< 3 )
465- webrick
465+ rackup (2.3.1 )
466+ rack (>= 3 )
466467 rails-dom-testing (2.3.0 )
467468 activesupport (>= 5.0.0 )
468469 minitest
@@ -621,10 +622,12 @@ GEM
621622 simplecov-html (~> 0.11 )
622623 simplecov-html (0.13.1 )
623624 simpleidn (0.2.3 )
624- sinatra (3.2.0 )
625+ sinatra (4.2.1 )
626+ logger (>= 1.6.0 )
625627 mustermann (~> 3.0 )
626- rack (~> 2.2 , >= 2.2.4 )
627- rack-protection (= 3.2.0 )
628+ rack (>= 3.0.0 , < 4 )
629+ rack-protection (= 4.2.1 )
630+ rack-session (>= 2.0.0 , < 3 )
628631 tilt (~> 2.0 )
629632 sqlite3 (1.7.3 )
630633 mini_portile2 (~> 2.8.0 )
@@ -635,10 +638,11 @@ GEM
635638 syslog (0.3.0 )
636639 logger
637640 test-prof (1.4.4 )
638- thin (1.8.2 )
641+ thin (2.0.1 )
639642 daemons (~> 1.0 , >= 1.0.9 )
640643 eventmachine (~> 1.0 , >= 1.0.4 )
641- rack (>= 1 , < 3 )
644+ logger
645+ rack (>= 1 , < 4 )
642646 thor (1.4.0 )
643647 tilt (2.6.0 )
644648 timecop (0.9.10 )
Original file line number Diff line number Diff line change 11require 'rack'
2+ require 'thin'
3+ require 'rackup/handler/thin'
24require 'metasploit/framework/parsed_options/remote_db'
35
46# TODO: This functionality isn't fully used currently, it should be integrated and called from the top level msfdb.rb file
@@ -25,7 +27,7 @@ def start(opts)
2527
2628 def start_http_server ( opts )
2729
28- Rack ::Handler ::Thin . run ( Msf ::WebServices ::MetasploitApiApp , **opts ) do |server |
30+ Rackup ::Handler ::Thin . run ( Msf ::WebServices ::MetasploitApiApp , **opts ) do |server |
2931
3032 if opts [ :ssl ] && opts [ :ssl ] = true
3133 print_good ( 'SSL Enabled' )
Original file line number Diff line number Diff line change @@ -26,6 +26,10 @@ class JsonRpcApp < Sinatra::Base
2626 # Disables Sinatra HTML Error Responses
2727 set :show_exceptions , false
2828
29+ # Sinatra 4 / rack-protection 4.x enables host authorization by default;
30+ # the JSON-RPC service binds to user-specified addresses so all hosts are permitted.
31+ set :host_authorization , { permitted_hosts : [ ] }
32+
2933 set :sessions , { key : 'msf-ws.session' , expire_after : 300 }
3034 set :session_secret , ENV . fetch ( 'MSF_WS_SESSION_SECRET' , SecureRandom . hex ( 32 ) )
3135 set :api_token , ENV . fetch ( 'MSF_WS_JSON_RPC_API_TOKEN' , nil )
Original file line number Diff line number Diff line change @@ -35,6 +35,9 @@ class Msf::WebServices::MetasploitApiApp < Sinatra::Base
3535 configure do
3636 set :sessions , { key : 'msf-ws.session' , expire_after : 300 }
3737 set :session_secret , ENV . fetch ( 'MSF_WS_SESSION_SECRET' ) { SecureRandom . hex ( 32 ) }
38+ # Sinatra 4 / rack-protection 4.x enables host authorization by default;
39+ # the web service binds to user-specified addresses so all hosts are permitted.
40+ set :host_authorization , { permitted_hosts : [ ] }
3841 end
3942
4043 before do
Original file line number Diff line number Diff line change @@ -107,12 +107,12 @@ Gem::Specification.new do |spec|
107107 # Required for Metasploit Web Services
108108 spec . add_runtime_dependency 'puma'
109109 spec . add_runtime_dependency 'ruby-mysql'
110- # webserver - pinned due to: https://github.com/github/secure_headers/issues/514
111- spec . add_runtime_dependency 'thin ' , '~> 1.x '
112- # rack pinned due to authlogic warnings when setting cookie keys with a / char present: https://github.com/binarylogic/authlogic/issues/779
113- spec . add_runtime_dependency 'rack ' , '~> 2.2 '
114- # 4.x needs tested and verified for JSON RPC service
115- spec . add_runtime_dependency 'sinatra ' , '~> 3.2 '
110+
111+ spec . add_runtime_dependency 'rack ' , '~> 3.1 '
112+ # 4.x supports Rack 3 for JSON RPC service
113+ spec . add_runtime_dependency 'sinatra ' , '~> 4.1 '
114+ # Web server for msfdb web services; 2.x supports Rack 3
115+ spec . add_runtime_dependency 'thin ' , '~> 2.0 '
116116 spec . add_runtime_dependency 'warden'
117117 spec . add_runtime_dependency 'swagger-blocks'
118118 # Required for JSON-RPC client
Original file line number Diff line number Diff line change 2323 before ( :example ) do
2424 framework . modules . add_module_path ( File . join ( FILE_FIXTURES_PATH , 'json_rpc' ) )
2525 app . settings . framework = framework
26+ # Rack 3 / rack-test requires explicit content type for raw JSON bodies
27+ header 'Content-Type' , 'application/json'
2628 end
2729
2830 after ( :example ) do
Original file line number Diff line number Diff line change 1+ require 'spec_helper'
2+ require 'rack/test'
3+
4+ RSpec . describe Msf ::WebServices ::MetasploitApiApp do
5+ include Rack ::Test ::Methods
6+ include_context 'Msf::DBManager'
7+
8+ let ( :app ) { described_class . new }
9+
10+ before ( :example ) do
11+ header 'Content-Type' , 'application/json'
12+ end
13+
14+ describe 'host authorization' do
15+ it 'does not reject requests with a 403 Host not permitted error' do
16+ get '/api/v1/hosts'
17+ expect ( last_response . status ) . not_to eq ( 403 )
18+ expect ( last_response . body ) . not_to include ( 'Host not permitted' )
19+ end
20+ end
21+
22+ describe 'authentication' do
23+ it 'does not return 200 for unauthenticated requests to protected endpoints' do
24+ get '/api/v1/hosts'
25+ expect ( last_response . status ) . not_to eq ( 200 )
26+ end
27+
28+ it 'returns a JSON response body' do
29+ get '/api/v1/hosts'
30+ expect { JSON . parse ( last_response . body ) } . not_to raise_error
31+ end
32+ end
33+
34+ describe 'response headers' do
35+ it 'uses lowercase header keys' do
36+ get '/api/v1/hosts'
37+ raw_keys = last_response . headers . keys
38+ raw_keys . each do |key |
39+ expect ( key ) . to eq ( key . downcase ) , "Expected header '#{ key } ' to be lowercase"
40+ end
41+ end
42+ end
43+ end
You can’t perform that action at this time.
0 commit comments