Path: blob/master/modules/post/multi/manage/play_youtube.rb
19500 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post6include Msf::Post::File78def initialize(info = {})9super(10update_info(11info,12'Name' => 'Multi Manage YouTube Broadcast',13'Description' => %q{14This module will broadcast a YouTube video on specified compromised systems. It will play15the video in the target machine's native browser. The VID datastore option is the "v"16parameter in a YouTube video's URL.1718Enabling the EMBED option will play the video in full screen mode through a clean interface19but is not compatible with all videos.2021This module will create a custom profile for Firefox on Linux systems in the /tmp directory.22},23'License' => MSF_LICENSE,24'Author' => [ 'sinn3r' ],25'Platform' => [ 'win', 'osx', 'linux', 'android', 'unix' ],26'SessionTypes' => [ 'shell', 'meterpreter' ],27'Notes' => {28'Stability' => [CRASH_SAFE],29# ARTIFACTS_ON_DISK when the platform is linux30'SideEffects' => [ ARTIFACTS_ON_DISK, AUDIO_EFFECTS, SCREEN_EFFECTS ],31'Reliability' => []32},33'Compat' => {34'Meterpreter' => {35'Commands' => %w[36android_*37stdapi_sys_process_execute38]39}40}41)42)4344register_options(45[46OptBool.new('EMBED', [true, 'Use the embed version of the YouTube URL', true]),47OptString.new('VID', [true, 'The video ID to the YouTube video', 'kxopViU98Xo'])48]49)50end5152def youtube_url53if datastore['EMBED']54"https://youtube.com/embed/#{datastore['VID']}?autoplay=1&loop=1&disablekb=1&modestbranding=1&iv_load_policy=3&controls=0&showinfo=0&rel=0"55else56"https://youtube.com/watch?v=#{datastore['VID']}"57end58end5960#61# The OSX version uses an apple script to do this62#63def osx_start_video(_id)64script = ''65script << %(osascript -e 'tell application "Safari" to open location "#{youtube_url}"' )66script << %(-e 'activate application "Safari"' )67script << %(-e 'tell application "System Events" to key code {59, 55, 3}')6869begin70cmd_exec(script)71rescue EOFError72return false73end7475true76end7778#79# The Windows version uses the "embed" player to make sure IE won't download the SWF as an object80#81def win_start_video(_id)82iexplore_path = 'C:\\Program Files\\Internet Explorer\\iexplore.exe'83begin84session.sys.process.execute(iexplore_path, "-k #{youtube_url}")85rescue Rex::Post::Meterpreter::RequestError86return false87end8889true90end9192#93# The Linux version uses Firefox94# TODO: Try xdg-open?95#96def linux_start_video(_id)97begin98# Create a profile99profile_name = Rex::Text.rand_text_alpha(8)100display = get_env('DISPLAY') || ':0'101vprint_status("Creating profile #{profile_name} using display #{display}")102cmd_exec(%(firefox --display #{display} -CreateProfile "#{profile_name} /tmp/#{profile_name}"))103104# Add user-defined settings to profile105s = %|106user_pref("dom.disable_open_during_load", false);107user_pref("browser.shell.checkDefaultBrowser", false);108|109write_file("/tmp/#{profile_name}/prefs.js", s)110111# Start the video112data_js = %|"data:text/html,<script>window.open('#{youtube_url}','','width:100000px;height:100000px');</script>"|113joe = "firefox --display #{display} -p #{profile_name} #{data_js} &"114cmd_exec("/bin/sh -c #{joe.shellescape}")115rescue EOFError116return false117end118119true120end121122#123# The Android version is launched via an Intent124#125def android_start_video(id)126intenturl = "intent://youtube.com/watch?v=#{id}&autoplay=1#Intent;scheme=http;action=android.intent.action.VIEW;end"127begin128session.android.activity_start(intenturl)129rescue Rex::Post::Meterpreter::RequestError130return false131end132true133end134135# The generic Unix version calls xdg-open(1) or open(1)136def unix_start_video(_id)137cmd_exec("xdg-open '#{youtube_url}' || open '#{youtube_url}'")138true139rescue EOFError140false141end142143def start_video(id)144case session.platform145when 'osx'146osx_start_video(id)147when 'windows'148win_start_video(id)149when 'linux'150linux_start_video(id)151when 'android'152android_start_video(id)153when 'unix'154unix_start_video(id)155end156end157158def run159id = datastore['VID']160161print_status("#{peer} - Spawning video...")162if start_video(id)163print_good("#{peer} - The video has started")164else165print_error("#{peer} - Unable to start the video")166return167end168end169end170171172