Path: blob/master/modules/post/multi/manage/open.rb
19812 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post6def initialize(info = {})7super(8update_info(9info,10'Name' => 'Open a file or URL on the target computer',11'Description' => %q{12This module will open any file or URL specified with the URI format on the13target computer via the embedded commands such as 'open' or 'xdg-open'.14},15'License' => MSF_LICENSE,16'Author' => [ 'Eliott Teissonniere'],17'Platform' => [ 'osx', 'linux', 'win' ],18'SessionTypes' => [ 'shell', 'meterpreter' ],19'Notes' => {20'Stability' => [CRASH_SAFE],21'SideEffects' => [SCREEN_EFFECTS],22'Reliability' => []23}24)25)2627register_options(28[29OptString.new('URI', [true, 'URI path to open'])30]31)32end3334#35# Open a file on OSX using 'open'36#37def osx_open(uri)38cmd_exec("open #{uri}")39return true40rescue EOFError41return false42end4344#45# Open a file on Linux using 'xdg-open'46#47def linux_open(uri)48cmd_exec("xdg-open #{uri}")49return true50rescue EOFError51return false52end5354#55# Open a file on Windows using 'start'56#57def win_open(uri)58cmd_exec("cmd.exe /c start #{uri}")59return true60rescue EOFError61return false62end6364def open_uri(uri)65case session.platform66when 'osx'67return osx_open(uri)68when 'linux'69return linux_open(uri)70when 'windows'71return win_open(uri)72end73end7475def run76uri = datastore['URI']7778print_status("Opening #{uri}")79if open_uri(uri)80print_good('Success')81else82print_error('Command failed')83end84end85end868788