Skip to content

Commit 17ff546

Browse files
committed
Remove unnecessary calls to expand path
When using the Meterpreter Binaries gem to locate the path to the meterpreter DLLs, it's not necessary to use File.expand_path on the result because the gem's code does this already. This commit simple removes those unnecessary calls.
1 parent ff43fbd commit 17ff546

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

lib/rex/post/meterpreter/client_core.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,13 @@ def use(mod, opts = { })
159159
path = MeterpreterBinaries.path(modname, client.binary_suffix)
160160

161161
if opts['ExtensionPath']
162-
path = opts['ExtensionPath']
162+
path = ::File.expand_path(opts['ExtensionPath'])
163163
end
164164

165165
if path.nil?
166166
raise RuntimeError, "No module of the name #{modname}.#{client.binary_suffix} found", caller
167167
end
168168

169-
path = ::File.expand_path(path)
170-
171169
# Load the extension DLL
172170
commands = load_library(
173171
'LibraryFilePath' => path,

lib/rex/post/meterpreter/extensions/priv/priv.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ def getsystem( technique=0 )
5050
raise RuntimeError, "elevator.#{binary_suffix} not found", caller
5151
end
5252

53-
elevator_path = ::File.expand_path( elevator_path )
54-
5553
elevator_data = ""
5654

5755
::File.open( elevator_path, "rb" ) { |f|

lib/rex/post/meterpreter/extensions/stdapi/ui.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,37 +154,43 @@ def set_desktop( session=-1, station='WinSta0', name='Default', switch=false )
154154
def screenshot( quality=50 )
155155
request = Packet.create_request( 'stdapi_ui_desktop_screenshot' )
156156
request.add_tlv( TLV_TYPE_DESKTOP_SCREENSHOT_QUALITY, quality )
157+
157158
# include the x64 screenshot dll if the host OS is x64
158159
if( client.sys.config.sysinfo['Architecture'] =~ /^\S*x64\S*/ )
159160
screenshot_path = MeterpreterBinaries.path('screenshot','x64.dll')
160161
if screenshot_path.nil?
161162
raise RuntimeError, "screenshot.x64.dll not found", caller
162163
end
163-
screenshot_path = ::File.expand_path( screenshot_path )
164+
164165
screenshot_dll = ''
165166
::File.open( screenshot_path, 'rb' ) do |f|
166167
screenshot_dll += f.read( f.stat.size )
167168
end
169+
168170
request.add_tlv( TLV_TYPE_DESKTOP_SCREENSHOT_PE64DLL_BUFFER, screenshot_dll, false, true )
169171
request.add_tlv( TLV_TYPE_DESKTOP_SCREENSHOT_PE64DLL_LENGTH, screenshot_dll.length )
170172
end
173+
171174
# but always include the x86 screenshot dll as we can use it for wow64 processes if we are on x64
172175
screenshot_path = MeterpreterBinaries.path('screenshot','x86.dll')
173176
if screenshot_path.nil?
174177
raise RuntimeError, "screenshot.x86.dll not found", caller
175178
end
176-
screenshot_path = ::File.expand_path( screenshot_path )
179+
177180
screenshot_dll = ''
178181
::File.open( screenshot_path, 'rb' ) do |f|
179182
screenshot_dll += f.read( f.stat.size )
180183
end
184+
181185
request.add_tlv( TLV_TYPE_DESKTOP_SCREENSHOT_PE32DLL_BUFFER, screenshot_dll, false, true )
182186
request.add_tlv( TLV_TYPE_DESKTOP_SCREENSHOT_PE32DLL_LENGTH, screenshot_dll.length )
187+
183188
# send the request and return the jpeg image if successfull.
184189
response = client.send_request( request )
185190
if( response.result == 0 )
186191
return response.get_tlv_value( TLV_TYPE_DESKTOP_SCREENSHOT )
187192
end
193+
188194
return nil
189195
end
190196

0 commit comments

Comments
 (0)