File tree Expand file tree Collapse file tree 3 files changed +26
-3
lines changed Expand file tree Collapse file tree 3 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -77,7 +77,12 @@ def generate_stageless_meterpreter(url = nil)
77
77
# the URL might not be given, as it might be patched in some other way
78
78
if url
79
79
# 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
81
86
end
82
87
83
88
# if a block is given then call that with the meterpreter dll
Original file line number Diff line number Diff line change @@ -18,7 +18,12 @@ def self.patch_transport!(blob, ssl)
18
18
19
19
# Replace the URL
20
20
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
22
27
end
23
28
24
29
# Replace the session expiration timeout
@@ -122,16 +127,22 @@ def self.patch_passive_service!(blob, options)
122
127
# Patch an ASCII value in the given payload. If not found, try WCHAR instead.
123
128
#
124
129
def self . patch_string! ( blob , search , replacement )
130
+ result = false
131
+
125
132
i = blob . index ( search )
126
133
if i
127
134
blob [ i , replacement . length ] = replacement
135
+ result = true
128
136
else
129
137
i = blob . index ( wchar ( search ) )
130
138
if i
131
139
r = wchar ( replacement )
132
140
blob [ i , r . length ] = r
141
+ result = true
133
142
end
134
143
end
144
+
145
+ result
135
146
end
136
147
137
148
private
Original file line number Diff line number Diff line change @@ -48,7 +48,14 @@ def get_loaded_extension_commands(extension_name)
48
48
request = Packet . create_request ( 'core_enumextcmd' )
49
49
request . add_tlv ( TLV_TYPE_STRING , extension_name )
50
50
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
52
59
53
60
# No response?
54
61
if response . nil?
You can’t perform that action at this time.
0 commit comments