Skip to content

Commit 029d3b7

Browse files
committed
Connect and get working with net/http.
POST looks to be working too.
1 parent 04f5f41 commit 029d3b7

File tree

1 file changed

+21
-25
lines changed
  • lib/metasploit/framework/data_service/remote/http

1 file changed

+21
-25
lines changed

lib/metasploit/framework/data_service/remote/http/core.rb

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
require 'metasploit/framework/data_service/remote/http/remote_service_endpoint'
22
require 'metasploit/framework/data_service'
33
require 'metasploit/framework/data_service/remote/http/data_service_auto_loader'
4+
require 'net/http'
5+
require 'net/https'
46

57
#
68
# Parent data service for managing metasploit data in/on a separate process/machine over HTTP(s)
@@ -47,15 +49,15 @@ def post_data(path, data_hash)
4749

4850
puts "#{Time.now} - Posting #{data_hash} to #{path}"
4951
client = @client_pool.pop()
50-
request_opts = build_request_opts(POST_REQUEST, data_hash, path)
51-
request = client.request_raw(request_opts)
52-
response = client._send_recv(request)
52+
request = Net::HTTP::Post.new(path)
53+
request = build_request(request, data_hash)
54+
response = client.request(request)
5355

54-
if response.code == 200
56+
if response.code == "200"
5557
#puts "POST request: #{path} with body: #{json_body} sent successfully"
5658
return SuccessResponse.new(response)
5759
else
58-
puts "POST request: #{path} with body: #{json_body} failed with code: #{response.code} message: #{response.body}"
60+
puts "POST request: #{path} with body: #{request.body} failed with code: #{response.code} message: #{response.body}"
5961
return FailedResponse.new(response)
6062
end
6163
rescue Exception => e
@@ -81,11 +83,11 @@ def get_data(path, data_hash = nil)
8183

8284
puts "#{Time.now} - Getting #{path} with #{data_hash ? data_hash : "nil"}"
8385
client = @client_pool.pop()
84-
request_opts = build_request_opts(GET_REQUEST, data_hash, path)
85-
request = client.request_raw(request_opts)
86-
response = client._send_recv(request)
86+
request = Net::HTTP::Get.new(path)
87+
request = build_request(request, data_hash)
88+
response = client.request(request)
8789

88-
if (response.code == 200)
90+
if response.code == "200"
8991
# puts 'request sent successfully'
9092
return SuccessResponse.new(response)
9193
else
@@ -94,6 +96,7 @@ def get_data(path, data_hash = nil)
9496
end
9597
rescue Exception => e
9698
puts "Problem with GET request: #{e.message}"
99+
e.backtrace.each {|line| puts "#{line}\n"}
97100
ensure
98101
@client_pool << client
99102
end
@@ -205,13 +208,8 @@ def append_workspace(data_hash)
205208
data_hash
206209
end
207210

208-
def build_request_opts(request_type, data_hash, path)
209-
request_opts = {
210-
'method' => request_type,
211-
'ctype' => 'application/json',
212-
'uri' => path
213-
}
214-
211+
def build_request(request, data_hash)
212+
request.content_type = 'application/json'
215213
if (!data_hash.nil? && !data_hash.empty?)
216214
data_hash.each do |k,v|
217215
if v.is_a?(Msf::Session)
@@ -223,25 +221,23 @@ def build_request_opts(request_type, data_hash, path)
223221
end
224222
end
225223
json_body = append_workspace(data_hash).to_json
226-
request_opts['data'] = json_body
224+
request.body = json_body
227225
end
228226

229227
if (!@headers.nil? && !@headers.empty?)
230-
request_opts['headers'] = @headers
228+
#TODO: This probably needs to be converted for the net/http client
229+
request['headers'] = @headers
231230
end
232231

233-
request_opts
232+
request
234233
end
235234

236235
def build_client_pool(size)
237236
@client_pool = Queue.new()
238237
(1..size).each {
239-
@client_pool << Rex::Proto::Http::Client.new(
240-
@endpoint.host,
241-
@endpoint.port,
242-
{},
243-
@endpoint.use_ssl,
244-
@endpoint.ssl_version)
238+
http = Net::HTTP.new(@endpoint.host, @endpoint.port)
239+
http.use_ssl = true if @endpoint.use_ssl
240+
@client_pool << http
245241
}
246242
end
247243

0 commit comments

Comments
 (0)