Skip to content

Commit fda2e8c

Browse files
author
Brent Cook
committed
Land rapid7#8523, Add support for session GUIDs
2 parents fad696e + c634931 commit fda2e8c

File tree

64 files changed

+585
-328
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+585
-328
lines changed

Gemfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ PATH
1515
metasploit-concern
1616
metasploit-credential
1717
metasploit-model
18-
metasploit-payloads (= 1.2.32)
18+
metasploit-payloads (= 1.2.33)
1919
metasploit_data_models
20-
metasploit_payloads-mettle (= 0.1.9)
20+
metasploit_payloads-mettle (= 0.1.10)
2121
msgpack
2222
nessus_rest
2323
net-ssh
@@ -196,7 +196,7 @@ GEM
196196
activemodel (~> 4.2.6)
197197
activesupport (~> 4.2.6)
198198
railties (~> 4.2.6)
199-
metasploit-payloads (1.2.32)
199+
metasploit-payloads (1.2.33)
200200
metasploit_data_models (2.0.14)
201201
activerecord (~> 4.2.6)
202202
activesupport (~> 4.2.6)
@@ -207,7 +207,7 @@ GEM
207207
postgres_ext
208208
railties (~> 4.2.6)
209209
recog (~> 2.0)
210-
metasploit_payloads-mettle (0.1.9)
210+
metasploit_payloads-mettle (0.1.10)
211211
method_source (0.8.2)
212212
mime-types (3.1)
213213
mime-types-data (~> 3.2015)

lib/msf/base/serializer/readable_text.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,6 @@ def self.dump_sessions_verbose(framework, opts={})
618618
sess_luri = session.exploit_datastore['LURI'] || ""
619619

620620
sess_checkin = "<none>"
621-
sess_machine_id = session.machine_id.to_s
622621
sess_registration = "No"
623622

624623
if session.respond_to? :platform
@@ -642,15 +641,12 @@ def self.dump_sessions_verbose(framework, opts={})
642641
out << " Tunnel: #{sess_tunnel}\n"
643642
out << " Via: #{sess_via}\n"
644643
out << " UUID: #{sess_uuid}\n"
645-
out << " MachineID: #{sess_machine_id}\n"
646644
out << " CheckIn: #{sess_checkin}\n"
647645
out << " Registered: #{sess_registration}\n"
648-
if !sess_luri.empty?
646+
unless sess_luri.empty?
649647
out << " LURI: #{sess_luri}\n"
650648
end
651649

652-
653-
654650
out << "\n"
655651
end
656652

lib/msf/base/sessions/meterpreter_options.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ def on_session(session)
5151
end
5252

5353
if valid
54+
# always make sure that the new session has a new guid if it's not already known
55+
guid = session.core.get_session_guid
56+
if guid == '00000000-0000-0000-0000-000000000000'
57+
guid = SecureRandom.uuid
58+
session.core.set_session_guid(guid)
59+
session.guid = guid
60+
# TODO: New statgeless session, do some account in the DB so we can track it later.
61+
else
62+
session.guid = guid
63+
# TODO: This session was either staged or previously known, and so we shold do some accounting here!
64+
end
5465

5566
if datastore['AutoLoadStdapi']
5667

@@ -71,7 +82,7 @@ def on_session(session)
7182
end
7283

7384
[ 'InitialAutoRunScript', 'AutoRunScript' ].each do |key|
74-
if !datastore[key].empty?
85+
unless datastore[key].empty?
7586
args = Shellwords.shellwords( datastore[key] )
7687
print_status("Session ID #{session.sid} (#{session.tunnel_to_s}) processing #{key} '#{datastore[key]}'")
7788
session.execute_script(args.shift, *args)

lib/msf/base/sessions/mettle_config.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require 'msf/core/payload/transport_config'
44
require 'msf/core/payload/uuid/options'
55
require 'base64'
6+
require 'securerandom'
67

78
module Msf
89
module Sessions
@@ -53,6 +54,7 @@ def generate_tcp_uri(opts)
5354

5455
def generate_config(opts={})
5556
opts[:uuid] ||= generate_payload_uuid
57+
5658
case opts[:scheme]
5759
when 'http'
5860
transport = transport_config_reverse_http(opts)
@@ -66,8 +68,15 @@ def generate_config(opts={})
6668
else
6769
raise ArgumentError, "Unknown scheme: #{opts[:scheme]}"
6870
end
71+
6972
opts[:uuid] = Base64.encode64(opts[:uuid].to_raw).strip
70-
opts.slice(:uuid, :uri, :debug, :log_file)
73+
guid = "\x00" * 16
74+
unless opts[:stageless] == true
75+
guid = [SecureRandom.uuid.gsub(/-/, '')].pack('H*')
76+
end
77+
opts[:session_guid] = Base64.encode64(guid)
78+
79+
opts.slice(:uuid, :session_guid, :uri, :debug, :log_file)
7180
end
7281

7382
end

lib/msf/core/payload/android.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ def generate_config(opts={})
5151
arch: opts[:uuid].arch,
5252
expiration: ds['SessionExpirationTimeout'].to_i,
5353
uuid: opts[:uuid],
54-
transports: opts[:transport_config] || [transport_config(opts)]
54+
transports: opts[:transport_config] || [transport_config(opts)],
55+
stageless: opts[:stageless] == true
5556
}
5657

5758
config = Rex::Payloads::Meterpreter::Config.new(config_opts).to_b

lib/msf/core/payload/java/meterpreter_loader.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ def generate_config(opts={})
6969
arch: opts[:uuid].arch,
7070
expiration: ds['SessionExpirationTimeout'].to_i,
7171
uuid: opts[:uuid],
72-
transports: opts[:transport_config] || [transport_config(opts)]
72+
transports: opts[:transport_config] || [transport_config(opts)],
73+
stageless: opts[:stageless] == true
7374
}
7475

7576
# create the configuration instance based off the parameters

lib/msf/core/payload/python/meterpreter_loader.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ def stage_meterpreter(opts={})
7474
uuid = Rex::Text.to_hex(uuid.to_raw, prefix = '')
7575
met.sub!("PAYLOAD_UUID = \'\'", "PAYLOAD_UUID = \'#{uuid}\'")
7676

77+
if opts[:stageless] == true
78+
session_guid = '\x00' * 16
79+
else
80+
session_guid = SecureRandom.uuid.gsub(/-/, '').gsub(/(..)/, '\\x\1')
81+
end
82+
met.sub!("SESSION_GUID = \'\'", "SESSION_GUID = \'#{session_guid}\'")
83+
7784
http_user_agent = opts[:http_user_agent] || ds['MeterpreterUserAgent']
7885
http_proxy_host = opts[:http_proxy_host] || ds['PayloadProxyHost'] || ds['PROXYHOST']
7986
http_proxy_port = opts[:http_proxy_port] || ds['PayloadProxyPort'] || ds['PROXYPORT']

lib/msf/core/payload/windows/meterpreter_loader.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ def generate_config(opts={})
8282
expiration: ds['SessionExpirationTimeout'].to_i,
8383
uuid: opts[:uuid],
8484
transports: opts[:transport_config] || [transport_config(opts)],
85-
extensions: []
85+
extensions: [],
86+
stageless: opts[:stageless] == true
8687
}
8788

8889
# create the configuration instance based off the parameters

lib/msf/core/payload/windows/x64/meterpreter_loader.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ def generate_config(opts={})
8484
expiration: ds['SessionExpirationTimeout'].to_i,
8585
uuid: opts[:uuid],
8686
transports: opts[:transport_config] || [transport_config(opts)],
87-
extensions: []
87+
extensions: [],
88+
stageless: opts[:stageless] == true
8889
}
8990

9091
# create the configuration instance based off the parameters

lib/msf/core/session.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,10 @@ def session_type
385385
#
386386
attr_accessor :machine_id
387387
#
388+
# The guid that identifies an active Meterpreter session
389+
#
390+
attr_accessor :guid
391+
#
388392
# The actual exploit module instance that created this session
389393
#
390394
attr_accessor :exploit

0 commit comments

Comments
 (0)