Skip to content

Commit 378e867

Browse files
author
HD Moore
committed
Refactor Msf::Payload::UUID, use this in reverse_http
1 parent 0d1fe37 commit 378e867

File tree

3 files changed

+218
-56
lines changed

3 files changed

+218
-56
lines changed

lib/msf/core/handler/reverse_http.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,18 @@ def lookup_proxy_settings
212212
#
213213
def on_request(cli, req, obj)
214214
resp = Rex::Proto::Http::Response.new
215+
info = process_uri_resource(req.relative_resource)
216+
uuid = info[:uuid] || Msf::Payload::UUID.new
215217

216-
print_status("#{cli.peerhost}:#{cli.peerport} Request received for #{req.relative_resource}...")
218+
# Configure the UUID architecture and payload if necessary
219+
uuid.arch = obj.arch if uuid.arch.nil?
220+
uuid.platform = obj.platform if uuid.platform.nil?
217221

218-
info = process_uri_resource(req.relative_resource)
222+
print_status "#{cli.peerhost}:#{cli.peerport} Request received for #{req.relative_resource}... (UUID:#{uuid.to_s})"
219223

220224
conn_id = nil
221225
if info[:mode] && info[:mode] != :connect
222-
conn_id = generate_uri_connect_uuid(info[:uuid], obj.arch, obj.platform)
226+
conn_id = generate_uri_connect_uuid(uuid)
223227
end
224228

225229
# Process the requested resource.
@@ -255,6 +259,7 @@ def on_request(cli, req, obj)
255259
:expiration => datastore['SessionExpirationTimeout'].to_i,
256260
:comm_timeout => datastore['SessionCommunicationTimeout'].to_i,
257261
:ssl => ssl?,
262+
:uuid => uuid
258263
})
259264
self.pending_connections += 1
260265

@@ -282,7 +287,8 @@ def on_request(cli, req, obj)
282287
:url => url,
283288
:expiration => datastore['SessionExpirationTimeout'].to_i,
284289
:comm_timeout => datastore['SessionCommunicationTimeout'].to_i,
285-
:ssl => ssl?
290+
:ssl => ssl?,
291+
:uuid => uuid
286292
})
287293

288294
when :init_native
@@ -318,6 +324,7 @@ def on_request(cli, req, obj)
318324
:expiration => datastore['SessionExpirationTimeout'].to_i,
319325
:comm_timeout => datastore['SessionCommunicationTimeout'].to_i,
320326
:ssl => ssl?,
327+
:uuid => uuid
321328
})
322329

323330
when :connect
@@ -333,6 +340,7 @@ def on_request(cli, req, obj)
333340
:expiration => datastore['SessionExpirationTimeout'].to_i,
334341
:comm_timeout => datastore['SessionCommunicationTimeout'].to_i,
335342
:ssl => ssl?,
343+
:uuid => uuid
336344
})
337345

338346
else

lib/msf/core/handler/reverse_http/uri_checksum.rb

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -46,48 +46,25 @@ def process_uri_resource(uri)
4646
# Figure out the mode based on the checksum
4747
uri_csum = Rex::Text.checksum8(uri_bare)
4848

49+
# Extract the UUID if the URI is long enough
4950
uri_uuid = nil
50-
5151
if uri_bare.length >= URI_CHECKSUM_UUID_MIN_LEN
52-
uri_uuid =
53-
Msf::Payload::UUID.payload_uuid_parse_raw(
54-
Rex::Text.decode_base64url(
55-
uri_bare[0, Msf::Payload::UUID::UriLength]))
56-
57-
# Verify the uri_uuid fields and unset everything but
58-
# the unique ID itself unless it looks wonky.
59-
if uri_uuid[:timestamp] > (Time.now.utc.to_i + (24*3600*365)) ||
60-
uri_uuid[:timestamp] < (Time.now.utc.to_i - (24*3600*365)) ||
61-
(uri_uuid[:arch].nil? && uri_uuid[:platform].nil?)
62-
uri_uuid = { puid: uri_uuid[:puid] }
63-
end
52+
uri_uuid = Msf::Payload::UUID.new(uri: uri_bare)
6453
end
6554

6655
uri_mode = URI_CHECKSUM_MODES[uri_csum]
6756

68-
# Return a hash of URI attributes to the caller
69-
{
70-
uri: uri_bare,
71-
sum: uri_csum,
72-
uuid: uri_uuid,
73-
mode: uri_mode
74-
}
57+
# Return a hash of URI attributes
58+
{ uri: uri_bare, sum: uri_csum, uuid: uri_uuid, mode: uri_mode }
7559
end
7660

7761
# Create a URI that matches the :connect mode with optional UUID, Arch, and Platform
7862
#
79-
# @param uuid [Hash] An optional hash with the UUID parameters
80-
# @param arch [String] An optional architecture name to use if no UUID is provided
81-
# @param platform [String] An optional platform name to use if no UUID is provided
82-
# @return [String] The URI string that checksums to the given value
83-
def generate_uri_connect_uuid(uuid=nil, arch=nil, platform=nil)
63+
# @param uuid [Msf::Payload::UUID] A valid UUID object
64+
# @return [String] The URI string for connections
65+
def generate_uri_connect_uuid(uuid)
8466
curl_uri_len = URI_CHECKSUM_UUID_MIN_LEN+rand(URI_CHECKSUM_CONN_MAX_LEN-URI_CHECKSUM_UUID_MIN_LEN)
85-
curl_prefix = Rex::Text.encode_base64url(
86-
Msf::Payload::UUID.payload_uuid_generate_raw(
87-
uuid: uuid[:puid],
88-
arch: uuid[:arch] || arch,
89-
platform: uuid[:platform] || platform,
90-
timestamp: uuid[:timestamp] ))
67+
curl_prefix = uuid.to_uri
9168

9269
# Pad out the URI and make the checksum match :connect
9370
"/" + generate_uri_checksum(URI_CHECKSUM_CONN, curl_uri_len, curl_prefix)

0 commit comments

Comments
 (0)