Class: Metasploit::Aggregator::ServerProxy

Inherits:
Service
  • Object
show all
Defined in:
lib/metasploit/aggregator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Service

#version

Constructor Details

#initialize(host, port) ⇒ ServerProxy

Returns a new instance of ServerProxy.



96
97
98
99
100
101
102
103
104
105
# File 'lib/metasploit/aggregator.rb', line 96

def initialize(host, port)
  @host = host
  @port = port
  @client = Metasploit::Aggregator::Pb::Stub.new("#{@host}:#{@port}", :this_channel_is_insecure)
  # TODO: add arg{ :channel_override => Core::Channel } to control connection
  @uuid = SecureRandom.uuid
  @no_params = Metasploit::Aggregator::Message::No_params.new
  # server_version = pb_to_array(@client.version(@no_params).value)[0]
  # raise CompatibilityError("server version mis-match found #{server_version}") unless server_version == version
end

Instance Attribute Details

#uuidObject (readonly)

Returns the value of attribute uuid.



88
89
90
# File 'lib/metasploit/aggregator.rb', line 88

def uuid
  @uuid
end

Instance Method Details

#add_cable(type, host, port, certificate = nil) ⇒ Object



139
140
141
142
143
144
145
146
147
# File 'lib/metasploit/aggregator.rb', line 139

def add_cable(type, host, port, certificate = nil)
  args = nil
  if certificate.nil?
    args = Metasploit::Aggregator::Message::Cable_def.new( type: type, host: host, port: port.to_i )
  else
    args = Metasploit::Aggregator::Message::Cable_def.new( type: type, host: host, port: port.to_i, pem: certificate )
  end
  @client.add_cable(args).answer
end

#available?Boolean

Returns:

  • (Boolean)


107
108
109
110
111
112
113
# File 'lib/metasploit/aggregator.rb', line 107

def available?
  begin
    @client.available(@no_params).answer
  rescue GRPC::Unavailable
    false # unavailable if client throws exception.
  end
end

#available_addressesObject



166
167
168
# File 'lib/metasploit/aggregator.rb', line 166

def available_addresses
  pb_to_array(@client.available_addresses(@no_params).value)
end

#cablesObject



119
120
121
# File 'lib/metasploit/aggregator.rb', line 119

def cables
  pb_to_array(@client.cables(@no_params).value)
end

#defaultObject



162
163
164
# File 'lib/metasploit/aggregator.rb', line 162

def default
  pb_to_array(@client.default(@no_params).value)[0]
end

#obtain_session(payload, uuid) ⇒ Object



124
125
126
127
# File 'lib/metasploit/aggregator.rb', line 124

def obtain_session(payload, uuid)
  args = Metasploit::Aggregator::Message::String_array.new( value: [payload, uuid] )
  @client.obtain_session(args).answer
end

#register_default(uuid, payload_list) ⇒ Object



154
155
156
157
158
159
160
# File 'lib/metasploit/aggregator.rb', line 154

def register_default(uuid, payload_list)
  uuid = "" if uuid.nil?
  payloads = []
  payloads = payload + payload_list unless payload_list.nil?
  args = Metasploit::Aggregator::Message::Register.new( uuid: uuid, payloads: payloads )
  @client.register_default(args).answer
end

#register_response_channel(requester) ⇒ Object



180
181
182
183
184
185
186
# File 'lib/metasploit/aggregator.rb', line 180

def register_response_channel(requester)
  unless requester.kind_of? Metasploit::Aggregator::Http::Requester
    raise ArgumentError("response channel class invalid")
  end
  @response_io = requester
  process
end

#release_session(payload) ⇒ Object



129
130
131
132
# File 'lib/metasploit/aggregator.rb', line 129

def release_session(payload)
  args = Metasploit::Aggregator::Message::String_array.new( value: [payload] )
  @client.release_session(args).answer
end

#remove_cable(host, port) ⇒ Object



149
150
151
152
# File 'lib/metasploit/aggregator.rb', line 149

def remove_cable(host, port)
  args = Metasploit::Aggregator::Message::String_array.new( value: [host, port] )
  @client.remove_cable(args).answer
end

#session_details(payload) ⇒ Object



134
135
136
137
# File 'lib/metasploit/aggregator.rb', line 134

def session_details(payload)
  args = Metasploit::Aggregator::Message::String_array.new( value: [payload] )
  pb_to_map(@client.session_details(args).map)
end

#sessionsObject



115
116
117
# File 'lib/metasploit/aggregator.rb', line 115

def sessions
  pb_to_map(@client.sessions(@no_params).map)
end

#stop(force = false) ⇒ Object



170
171
172
173
174
175
176
177
178
# File 'lib/metasploit/aggregator.rb', line 170

def stop(force = false)
  # end the response queue
  ServerProxy.unregister_for_cleanup(self) unless force
  @response_queue.push(self) unless @response_queue.nil?

  @listening_thread.join if @listening_thread
  @listening_thread = nil
  @client = nil
end