Skip to content

Commit

Permalink
Land #9586, fix #9112, improve android screenshot error message on fa…
Browse files Browse the repository at this point in the history
…ilure
  • Loading branch information
busterb authored and jmartin-tech committed Mar 27, 2018
1 parent c56e571 commit 106fbf8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 33 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ PATH
metasploit-concern
metasploit-credential (< 3.0.0)
metasploit-model
metasploit-payloads (= 1.3.31)
metasploit-payloads (= 1.3.32)
metasploit_data_models (< 3.0.0)
metasploit_payloads-mettle (= 0.3.7)
mqtt
Expand Down Expand Up @@ -180,7 +180,7 @@ GEM
activemodel (~> 4.2.6)
activesupport (~> 4.2.6)
railties (~> 4.2.6)
metasploit-payloads (1.3.31)
metasploit-payloads (1.3.32)
metasploit_data_models (2.0.16)
activerecord (~> 4.2.6)
activesupport (~> 4.2.6)
Expand Down
65 changes: 35 additions & 30 deletions lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/ui.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def cmd_uictl(*args)
#
# Grab a screenshot of the current interactive desktop.
#
def cmd_screenshot( *args )
def cmd_screenshot(*args)
path = Rex::Text.rand_text_alpha(8) + ".jpeg"
quality = 50
view = false
Expand All @@ -134,34 +134,39 @@ def cmd_screenshot( *args )
"-v" => [ true, "Automatically view the JPEG image (Default: '#{view}')" ]
)

screenshot_opts.parse( args ) { | opt, idx, val |
screenshot_opts.parse(args) { | opt, idx, val |
case opt
when "-h"
print_line( "Usage: screenshot [options]\n" )
print_line( "Grab a screenshot of the current interactive desktop." )
print_line( screenshot_opts.usage )
print_line("Usage: screenshot [options]\n")
print_line("Grab a screenshot of the current interactive desktop.")
print_line(screenshot_opts.usage)
return
when "-q"
quality = val.to_i
when "-p"
path = val
when "-v"
view = true if ( val =~ /^(t|y|1)/i )
view = true if (val =~ /^(t|y|1)/i)
end
}

data = client.ui.screenshot( quality )
data = client.ui.screenshot(quality)

if( data )
::File.open( path, 'wb' ) do |fd|
fd.write( data )
if data
::File.open(path, 'wb') do |fd|
fd.write(data)
end

path = ::File.expand_path( path )
path = ::File.expand_path(path)

print_line( "Screenshot saved to: #{path}" )
print_line("Screenshot saved to: #{path}")

Rex::Compat.open_file( path ) if view
Rex::Compat.open_file(path) if view
else
print_error("No screenshot data was returned.")
if client.platform == 'android'
print_error("With Android, the screenshot command can only capture the host application. If this payload is hosted in an app without a user interface (default behavior), it cannot take screenshots at all.")
end
end

return true
Expand All @@ -171,7 +176,7 @@ def cmd_screenshot( *args )
# Enumerate desktops
#
def cmd_enumdesktops(*args)
print_line( "Enumerating all accessible desktops" )
print_line("Enumerating all accessible desktops")

desktops = client.ui.enum_desktops

Expand All @@ -189,10 +194,10 @@ def cmd_enumdesktops(*args)
desktopstable << [ session, desktop['station'], desktop['name'] ]
}

if( desktops.length == 0 )
print_line( "No accessible desktops were found." )
if desktops.length == 0
print_line("No accessible desktops were found.")
else
print( "\n" + desktopstable.to_s + "\n" )
print("\n" + desktopstable.to_s + "\n")
end

return true
Expand All @@ -207,15 +212,15 @@ def cmd_getdesktop(*args)

session = desktop['session'] == 0xFFFFFFFF ? '' : "Session #{desktop['session'].to_s}\\"

print_line( "#{session}#{desktop['station']}\\#{desktop['name']}" )
print_line("#{session}#{desktop['station']}\\#{desktop['name']}")

return true
end

#
# Change the meterpreters current desktop.
#
def cmd_setdesktop( *args )
def cmd_setdesktop(*args)

switch = false
dsession = -1
Expand All @@ -230,12 +235,12 @@ def cmd_setdesktop( *args )
"-i" => [ true, "Set this desktop as the interactive desktop (Default: '#{switch}')" ]
)

setdesktop_opts.parse( args ) { | opt, idx, val |
setdesktop_opts.parse(args) { | opt, idx, val |
case opt
when "-h"
print_line( "Usage: setdesktop [options]\n" )
print_line( "Change the meterpreters current desktop." )
print_line( setdesktop_opts.usage )
print_line("Usage: setdesktop [options]\n")
print_line("Change the meterpreters current desktop.")
print_line(setdesktop_opts.usage)
return
#when "-s"
# dsession = val.to_i
Expand All @@ -244,14 +249,14 @@ def cmd_setdesktop( *args )
when "-n"
dname = val
when "-i"
switch = true if ( val =~ /^(t|y|1)/i )
switch = true if (val =~ /^(t|y|1)/i)
end
}

if( client.ui.set_desktop( dsession, dstation, dname, switch ) )
print_line( "#{ switch ? 'Switched' : 'Changed' } to desktop #{dstation}\\#{dname}" )
if client.ui.set_desktop(dsession, dstation, dname, switch)
print_line("#{ switch ? 'Switched' : 'Changed' } to desktop #{dstation}\\#{dname}")
else
print_line( "Failed to #{ switch ? 'switch' : 'change' } to desktop #{dstation}\\#{dname}" )
print_line("Failed to #{ switch ? 'switch' : 'change' } to desktop #{dstation}\\#{dname}")
end

return true
Expand All @@ -262,11 +267,11 @@ def cmd_setdesktop( *args )
#
def cmd_unlockdesktop(*args)
mode = 0
if(args.length > 0)
if args.length > 0
mode = args[0].to_i
end

if(mode == 0)
if mode == 0
print_line("Unlocking the workstation...")
client.ui.unlock_desktop(true)
else
Expand All @@ -288,7 +293,7 @@ def cmd_keyscan_start(*args)
"-v" => [ false, "Verbose logging: tracks the current active window in which keystrokes are occuring." ]
)

keyscan_opts.parse( args ) { | opt |
keyscan_opts.parse(args) { | opt |
case opt
when "-h"
print_line("Usage: keyscan_start <options>")
Expand Down
2 changes: 1 addition & 1 deletion metasploit-framework.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Gem::Specification.new do |spec|
# are needed when there's no database
spec.add_runtime_dependency 'metasploit-model'
# Needed for Meterpreter
spec.add_runtime_dependency 'metasploit-payloads', '1.3.31'
spec.add_runtime_dependency 'metasploit-payloads', '1.3.32'
# Needed for the next-generation POSIX Meterpreter
spec.add_runtime_dependency 'metasploit_payloads-mettle', '0.3.7'
# Needed by msfgui and other rpc components
Expand Down

0 comments on commit 106fbf8

Please sign in to comment.