Skip to content

Commit 38a77c9

Browse files
committed
Land rapid7#5072 : Support and embed payload UUIDs
2 parents ee13c07 + 6811aeb commit 38a77c9

File tree

21 files changed

+690
-152
lines changed

21 files changed

+690
-152
lines changed

lib/msf/base/serializer/readable_text.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ def self.dump_sessions(framework, opts={})
536536
]
537537

538538
columns << 'Via' if verbose
539+
columns << 'PayloadId' if verbose
539540

540541
tbl = Rex::Ui::Text::Table.new(
541542
'Indent' => indent,
@@ -555,7 +556,11 @@ def self.dump_sessions(framework, opts={})
555556
if session.respond_to? :platform
556557
row[1] += " " + session.platform
557558
end
558-
row << session.via_exploit if verbose and session.via_exploit
559+
560+
if verbose
561+
row << session.via_exploit.to_s
562+
row << session.payload_uuid.to_s
563+
end
559564

560565
tbl << row
561566
}
@@ -566,7 +571,7 @@ def self.dump_sessions(framework, opts={})
566571
# Dumps the list of running jobs.
567572
#
568573
# @param framework [Msf::Framework] the framework.
569-
# @param verbose [Boolean] if true, also prints the payload, LPORT, URIPATH
574+
# @param verbose [Boolean] if true, also prints the payload, LPORT, URIPATH
570575
# and start time, if they exist, for each job.
571576
# @param indent [Integer] the indentation amount.
572577
# @param col [Integer] the column wrap width.

lib/msf/core/handler.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ def create_session(conn, opts={})
198198
# and any relevant information
199199
s.set_from_exploit(assoc_exploit)
200200

201+
# Pass along any associated payload uuid if specified
202+
s.payload_uuid = opts[:payload_uuid] if opts[:payload_uuid]
203+
201204
# If the session is valid, register it with the framework and
202205
# notify any waiters we may have.
203206
if (s)

lib/msf/core/handler/reverse_http.rb

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -215,17 +215,25 @@ def lookup_proxy_settings
215215
#
216216
def on_request(cli, req, obj)
217217
resp = Rex::Proto::Http::Response.new
218+
info = process_uri_resource(req.relative_resource)
219+
uuid = info[:uuid] || Msf::Payload::UUID.new
218220

219-
print_status("#{cli.peerhost}:#{cli.peerport} Request received for #{req.relative_resource}...")
221+
# Configure the UUID architecture and payload if necessary
222+
uuid.arch ||= obj.arch
223+
uuid.platform ||= obj.platform
220224

221-
uri_match = process_uri_resource(req.relative_resource)
225+
print_status "#{cli.peerhost}:#{cli.peerport} Request received for #{req.relative_resource}... (UUID:#{uuid.to_s})"
226+
227+
conn_id = nil
228+
if info[:mode] && info[:mode] != :connect
229+
conn_id = generate_uri_uuid(URI_CHECKSUM_CONN, uuid)
230+
end
222231

223232
self.pending_connections += 1
224233

225234
# Process the requested resource.
226-
case uri_match
227-
when /^\/INITPY/
228-
conn_id = generate_uri_checksum(URI_CHECKSUM_CONN) + "_" + Rex::Text.rand_text_alphanumeric(16)
235+
case info[:mode]
236+
when :init_python
229237
url = payload_uri(req) + conn_id + '/'
230238

231239
blob = ""
@@ -256,10 +264,10 @@ def on_request(cli, req, obj)
256264
:expiration => datastore['SessionExpirationTimeout'].to_i,
257265
:comm_timeout => datastore['SessionCommunicationTimeout'].to_i,
258266
:ssl => ssl?,
267+
:payload_uuid => uuid
259268
})
260269

261-
when /^\/INITJM/
262-
conn_id = generate_uri_checksum(URI_CHECKSUM_CONN) + "_" + Rex::Text.rand_text_alphanumeric(16)
270+
when :init_java
263271
url = payload_uri(req) + conn_id + "/\x00"
264272

265273
blob = ""
@@ -283,11 +291,11 @@ def on_request(cli, req, obj)
283291
:url => url,
284292
:expiration => datastore['SessionExpirationTimeout'].to_i,
285293
:comm_timeout => datastore['SessionCommunicationTimeout'].to_i,
286-
:ssl => ssl?
294+
:ssl => ssl?,
295+
:payload_uuid => uuid
287296
})
288297

289-
when /^\/A?INITM?/
290-
conn_id = generate_uri_checksum(URI_CHECKSUM_CONN) + "_" + Rex::Text.rand_text_alphanumeric(16)
298+
when :init_native
291299
url = payload_uri(req) + conn_id + "/\x00"
292300

293301
print_status("#{cli.peerhost}:#{cli.peerport} Staging connection for target #{req.relative_resource} received...")
@@ -323,13 +331,12 @@ def on_request(cli, req, obj)
323331
:expiration => datastore['SessionExpirationTimeout'].to_i,
324332
:comm_timeout => datastore['SessionCommunicationTimeout'].to_i,
325333
:ssl => ssl?,
334+
:payload_uuid => uuid
326335
})
327336

328-
when /^\/CONN_.*\//
337+
when :connect
329338
resp.body = ""
330-
# Grab the checksummed version of CONN from the payload's request.
331-
conn_id = req.relative_resource.gsub("/", "")
332-
339+
conn_id = req.relative_resource
333340
print_status("Incoming orphaned or stageless session #{conn_id}, attaching...")
334341

335342
# Short-circuit the payload's handle_connection processing for create_session
@@ -340,6 +347,7 @@ def on_request(cli, req, obj)
340347
:expiration => datastore['SessionExpirationTimeout'].to_i,
341348
:comm_timeout => datastore['SessionCommunicationTimeout'].to_i,
342349
:ssl => ssl?,
350+
:payload_uuid => uuid
343351
})
344352

345353
else

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
require 'msf/core'
77
require 'rex/parser/x509_certificate'
8-
require 'rex/payloads/meterpreter/uri_checksum'
8+
require 'msf/core/payload/uuid_options'
99

1010
module Msf
1111

@@ -18,7 +18,7 @@ module Msf
1818
module Handler::ReverseHttp::Stageless
1919

2020
include Msf::Payload::Windows::VerifySsl
21-
include Rex::Payloads::Meterpreter::UriChecksum
21+
include Msf::Payload::UUIDOptions
2222

2323
def initialize_stageless
2424
register_options([
@@ -27,9 +27,7 @@ def initialize_stageless
2727
end
2828

2929
def generate_stageless(&block)
30-
checksum = generate_uri_checksum(URI_CHECKSUM_CONN)
31-
rand = Rex::Text.rand_text_alphanumeric(16)
32-
url = "https://#{datastore['LHOST']}:#{datastore['LPORT']}/#{checksum}_#{rand}/"
30+
url = "https://#{datastore['LHOST']}:#{datastore['LPORT']}#{generate_uri_uuid_mode(:connect)}/"
3331

3432
unless block_given?
3533
raise ArgumentError, "Stageless generation requires a block argument"

0 commit comments

Comments
 (0)