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



135
136
137
138
139
140
141
142
143
# File 'lib/metasploit/aggregator.rb', line 135

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
# File 'lib/metasploit/aggregator.rb', line 107

def available?
  @client.available(@no_params).answer
end

#available_addressesObject



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

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

#cablesObject



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

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

#defaultObject



158
159
160
# File 'lib/metasploit/aggregator.rb', line 158

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

#obtain_session(payload, uuid) ⇒ Object



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

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



150
151
152
153
154
155
156
# File 'lib/metasploit/aggregator.rb', line 150

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



176
177
178
179
180
181
182
# File 'lib/metasploit/aggregator.rb', line 176

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



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

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

#remove_cable(host, port) ⇒ Object



145
146
147
148
# File 'lib/metasploit/aggregator.rb', line 145

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



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

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

#sessionsObject



111
112
113
# File 'lib/metasploit/aggregator.rb', line 111

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

#stop(force = false) ⇒ Object



166
167
168
169
170
171
172
173
174
# File 'lib/metasploit/aggregator.rb', line 166

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