Class: Msf::RPC::Client
- Inherits:
-
Object
- Object
- Msf::RPC::Client
- Defined in:
- lib/msf/core/rpc/v10/client.rb
Instance Attribute Summary collapse
-
#info ⇒ Hash
Login information.
-
#token ⇒ String
A login token.
Instance Method Summary collapse
-
#call(meth, *args) ⇒ Hash
Calls an API.
-
#close ⇒ void
Closes the client.
-
#initialize(info = {}) ⇒ void
constructor
Initializes the RPC client to connect to: 127.0.0.1:3790 (TLS1) The connection information is overridden through the optional info hash.
-
#login(user, pass) ⇒ TrueClass
Logs in by calling the ‘auth.login’ API.
-
#re_login ⇒ TrueClass
Attempts to login again with the last known user name and password.
Constructor Details
#initialize(info = {}) ⇒ void
Initializes the RPC client to connect to: 127.0.0.1:3790 (TLS1) The connection information is overridden through the optional info hash.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/msf/core/rpc/v10/client.rb', line 29 def initialize(info={}) @user = nil @pass = nil self.info = { :host => '127.0.0.1', :port => 3790, :uri => '/api/', :ssl => true, :ssl_version => 'TLS1.2', :context => {} }.merge(info) self.token = self.info[:token] end |
Instance Attribute Details
#info ⇒ Hash
Returns Login information.
20 21 22 |
# File 'lib/msf/core/rpc/v10/client.rb', line 20 def info @info end |
#token ⇒ String
Returns A login token.
16 17 18 |
# File 'lib/msf/core/rpc/v10/client.rb', line 16 def token @token end |
Instance Method Details
#call(meth, *args) ⇒ Hash
Calls an API.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/msf/core/rpc/v10/client.rb', line 89 def call(meth, *args) if meth == 'auth.logout' do_logout_cleanup end if meth != 'auth.login' && meth != 'health.check' unless self.token raise RuntimeError, "client not authenticated" end args.unshift(self.token) end args.unshift(meth) begin send_rpc_request(args) rescue Msf::RPC::ServerException => e if e. =~ /Invalid Authentication Token/i && meth != 'auth.login' && @user && @pass re_login args[1] = self.token retry else raise e end ensure @cli.close if @cli end end |
#close ⇒ void
This method returns an undefined value.
Closes the client.
123 124 125 126 127 128 |
# File 'lib/msf/core/rpc/v10/client.rb', line 123 def close if @cli && @cli.conn? @cli.close end @cli = nil end |
#login(user, pass) ⇒ TrueClass
Logs in by calling the ‘auth.login’ API. The authentication token will expire after 5 minutes, but will automatically be rewnewed when you make a new RPC request.
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/msf/core/rpc/v10/client.rb', line 53 def login(user,pass) @user = user @pass = pass res = self.call("auth.login", user, pass) unless (res && res['result'] == "success") raise RuntimeError, "authentication failed" end self.token = res['token'] true end |
#re_login ⇒ TrueClass
Attempts to login again with the last known user name and password.
68 69 70 |
# File 'lib/msf/core/rpc/v10/client.rb', line 68 def re_login login(@user, @pass) end |