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/modules/auxiliary/admin/appletv/appletv_display_video.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45require 'uri'67class MetasploitModule < Msf::Auxiliary8include Msf::Exploit::Remote::HttpClient910def initialize(info = {})11super(update_info(info,12'Name' => 'Apple TV Video Remote Control',13'Description' => %q(14This module plays a video on an AppleTV device. Note that15AppleTV can be somewhat picky about the server that hosts the video.16Tested servers include default IIS, default Apache, and Ruby's WEBrick.17For WEBrick, the default MIME list may need to be updated, depending on18what media file is to be played. Python SimpleHTTPServer is not19recommended. Also, if you're playing a video, the URL must be an IP20address. Some AppleTV devices are actually password-protected; in that21case please set the PASSWORD datastore option. For password22brute forcing, please see the module auxiliary/scanner/http/appletv_login.23),24'Author' =>25[26'0a29406d9794e4f9b30b3c5d6702c708', # Original work27'sinn3r' # Make myself liable to mistakes since I made significant changes28],29'References' =>30[31['URL', 'http://nto.github.io/AirPlay.html']32],33'DefaultOptions' => { 'HttpUsername' => 'AirPlay' },34'License' => MSF_LICENSE35))3637register_options([38Opt::RPORT(7000),39OptInt.new('TIME', [true, 'Time in seconds to show the video', 60]),40OptString.new('URL', [true, 'URL of video to show. Must use an IP address']),41OptString.new('HttpPassword', [false, 'The password for AppleTV AirPlay'])42])4344# We're not actually using any of these against AppleTV in our Rex HTTP client init,45# so deregister them so we don't overwhelm the user with fake options.46deregister_options(47'HTTP::uri_encode_mode', 'HTTP::uri_full_url', 'HTTP::pad_method_uri_count',48'HTTP::pad_uri_version_count', 'HTTP::pad_method_uri_type', 'HTTP::pad_uri_version_type',49'HTTP::method_random_valid', 'HTTP::method_random_invalid', 'HTTP::method_random_case',50'HTTP::uri_dir_self_reference', 'HTTP::uri_dir_fake_relative', 'HTTP::uri_use_backslashes',51'HTTP::pad_fake_headers', 'HTTP::pad_fake_headers_count', 'HTTP::pad_get_params',52'HTTP::pad_get_params_count', 'HTTP::pad_post_params', 'HTTP::pad_post_params_count',53'HTTP::uri_fake_end', 'HTTP::uri_fake_params_start', 'HTTP::header_folding',54'NTLM::UseNTLM2_session', 'NTLM::UseNTLMv2', 'NTLM::SendLM', 'NTLM::SendNTLM',55'NTLM::SendSPN', 'NTLM::UseLMKey', 'DOMAIN', 'DigestAuthIIS', 'VHOST'56)57end585960#61# Sends a video request to AppleTV. HttpClient isn't used because we actually need to keep62# the connection alive so that the video can keep playing.63#64def send_video_request(opts)65http = nil6667http = Rex::Proto::Http::Client.new(68rhost,69rport.to_i,70{71'Msf' => framework,72'MsfExploit' => self73},74ssl,75ssl_version,76proxies,77datastore['HttpUsername'],78datastore['HttpPassword']79)80add_socket(http)8182http.set_config('agent' => datastore['UserAgent'])8384req = http.request_raw(opts)85res = http.send_recv(req)86Rex.sleep(datastore['TIME']) if res.code == 20087http.close8889res90end919293#94# Checks the URI datastore option. AppleTV is sort of picky about the URI. It's better to95# always supply an IP instead of a domain.96#97def validate_source!(uri)98unless Rex::Socket.is_ipv4?(URI(uri).host) # Same trick in target_uri form HttpClient99raise Msf::OptionValidateError.new(['URL'])100end101end102103104#105# Plays a video as a new thread106#107def play_video_uri108uri = datastore['URL']109validate_source!(uri)110111body = "Content-Location: #{uri}\n"112body << "Start-Position: 0.0\n"113114opts = {115'method' => 'POST',116'uri' => '/play',117'headers' => {118'Content-Length' => body.length.to_s,119'Content-Type' => 'text/parameters'120},121'data' => body122}123124res = send_video_request(opts)125126if !res127print_status("The connection timed out")128elsif res.code == 200129print_status("Received HTTP 200")130else131print_error("The request failed due to an unknown reason")132end133end134135136#137# Maybe it's just me not understanding the /stop API correctly, but when I send a request to138# /stop, it doesn't actually do anything. It is sort of possible to stop my video by looking139# through framework.threads.each {|t| puts t[:tm_name]}, and then kill the right thread. But140# if there are multiple appletv_display_video running, we don't seem to have a good way to141# kill the right thread we want. We could kill them all, but we shouldn't do that. So I'll142# just leave this method here, and then we'll think about how to do it later.143#144def stop_play145raise NotImplementedError146end147148149def run150print_status("Video request sent. Duration set: #{datastore['TIME']} seconds")151play_video_uri152end153end154155156