Skip to content

Commit f6731f1

Browse files
author
HD Moore
committed
Lands rapid7#4991, fixes a potential backcompat issue w/meterpreter
2 parents 1869977 + 25dcfc7 commit f6731f1

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,12 @@ def generate_stageless_meterpreter(url = nil)
7777
# the URL might not be given, as it might be patched in some other way
7878
if url
7979
# Patch the URL using the patcher as this upports both ASCII and WCHAR.
80-
Rex::Payloads::Meterpreter::Patch.patch_string!(dll, "https://#{'X' * 512}", "s#{url}\x00")
80+
unless Rex::Payloads::Meterpreter::Patch.patch_string!(dll, "https://#{'X' * 512}", "s#{url}\x00")
81+
# If the patching failed this could mean that we are somehow
82+
# working with outdated binaries, so try to patch with the
83+
# old stuff.
84+
Rex::Payloads::Meterpreter::Patch.patch_string!(dll, "https://#{'X' * 256}", "s#{url}\x00")
85+
end
8186
end
8287

8388
# if a block is given then call that with the meterpreter dll

lib/rex/payloads/meterpreter/patch.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ def self.patch_transport!(blob, ssl)
1818

1919
# Replace the URL
2020
def self.patch_url!(blob, url)
21-
patch_string!(blob, "https://#{'X' * 512}", url)
21+
unless patch_string!(blob, "https://#{'X' * 512}", url)
22+
# If the patching failed this could mean that we are somehow
23+
# working with outdated binaries, so try to patch with the
24+
# old stuff.
25+
patch_string!(blob, "https://#{'X' * 256}", url)
26+
end
2227
end
2328

2429
# Replace the session expiration timeout
@@ -122,16 +127,22 @@ def self.patch_passive_service!(blob, options)
122127
# Patch an ASCII value in the given payload. If not found, try WCHAR instead.
123128
#
124129
def self.patch_string!(blob, search, replacement)
130+
result = false
131+
125132
i = blob.index(search)
126133
if i
127134
blob[i, replacement.length] = replacement
135+
result = true
128136
else
129137
i = blob.index(wchar(search))
130138
if i
131139
r = wchar(replacement)
132140
blob[i, r.length] = r
141+
result = true
133142
end
134143
end
144+
145+
result
135146
end
136147

137148
private

lib/rex/post/meterpreter/client_core.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,14 @@ def get_loaded_extension_commands(extension_name)
4848
request = Packet.create_request('core_enumextcmd')
4949
request.add_tlv(TLV_TYPE_STRING, extension_name)
5050

51-
response = self.client.send_packet_wait_response(request, self.client.response_timeout)
51+
begin
52+
response = self.client.send_packet_wait_response(request, self.client.response_timeout)
53+
rescue
54+
# In the case where orphaned shells call back with OLD copies of the meterpreter
55+
# binaries, we end up with a case where this fails. So here we just return the
56+
# empty list of supported commands.
57+
return []
58+
end
5259

5360
# No response?
5461
if response.nil?

0 commit comments

Comments
 (0)