Class: Msf::Plugin::MSGRPC

Inherits:
Msf::Plugin show all
Defined in:
plugins/msgrpc.rb

Overview

This class implements the msfd plugin interface.

Constant Summary collapse

DefaultHost =

The default local hostname that the server listens on.

'127.0.0.1'.freeze
DefaultPort =

The default local port that the server listens on.

55552

Instance Attribute Summary collapse

Attributes inherited from Msf::Plugin

#opts

Attributes included from Framework::Offspring

#framework

Instance Method Summary collapse

Methods inherited from Msf::Plugin

#add_console_dispatcher, create, #flush, #input, #output, #print, #print_error, #print_good, #print_line, #print_status, #print_warning, #remove_console_dispatcher

Constructor Details

#initialize(framework, opts) ⇒ MSGRPC

ServerPort

The local port to listen on for connections. The default is 55552



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'plugins/msgrpc.rb', line 35

def initialize(framework, opts)
  super

  host = opts['ServerHost'] || DefaultHost
  port = opts['ServerPort'] || DefaultPort
  ssl = (opts['SSL'] && opts['SSL'].to_s =~ /^[ty]/i) ? true : false
  cert = opts['SSLCert']

  user = opts['User'] || 'msf'
  pass = opts['Pass'] || ::Rex::Text.rand_text_alphanumeric(8)
  uri = opts['URI'] || '/api'
  timeout = opts['TokenTimeout'] || 300

  print_status("MSGRPC Service:  #{host}:#{port} #{ssl ? ' (SSL)' : ''}")
  print_status("MSGRPC Username: #{user}")
  print_status("MSGRPC Password: #{pass}")

  self.server	= ::Msf::RPC::Service.new(framework, {
    host: host,
    port: port,
    ssl: ssl,
    cert: cert,
    uri: uri,
    tokens: {},
    token_timeout: timeout
  })

  server.add_user(user, pass)

  # If the run in foreground flag is not specified, then go ahead and fire
  # it off in a worker thread.
  unless opts['RunInForeground'] == true
    # Store a handle to the thread so we can kill it during
    # cleanup when we get unloaded.
    self.thread = Thread.new { run }
    framework.threads.register(thread, 'MetasploitRPCServer', true)
  end
end

Instance Attribute Details

#serverObject

The MSGRPC instance.



115
116
117
# File 'plugins/msgrpc.rb', line 115

def server
  @server
end

#threadObject

Returns the value of attribute thread.



116
117
118
# File 'plugins/msgrpc.rb', line 116

def thread
  @thread
end

#tokensObject

Returns the value of attribute tokens.



116
117
118
# File 'plugins/msgrpc.rb', line 116

def tokens
  @tokens
end

#usersObject

Returns the value of attribute users.



116
117
118
# File 'plugins/msgrpc.rb', line 116

def users
  @users
end

Instance Method Details

#cleanupObject

Closes the listener service.



105
106
107
108
109
110
# File 'plugins/msgrpc.rb', line 105

def cleanup
  server.stop if server
  thread.kill if thread
  self.server = nil
  super
end

#descObject

Returns the plugin description.



84
85
86
# File 'plugins/msgrpc.rb', line 84

def desc
  'Provides a MessagePack interface over HTTP'
end

#nameObject

Returns ‘msgrpc’



77
78
79
# File 'plugins/msgrpc.rb', line 77

def name
  'msgrpc'
end

#runObject

The meat of the plugin, sets up handlers for requests



91
92
93
94
95
96
97
98
99
100
# File 'plugins/msgrpc.rb', line 91

def run
  # Start the actual service
  server.start

  # Register
  framework.threads.register(Thread.current, 'MetasploitRPCServer', true)

  # Wait for the service to complete
  server.wait
end