diff --git a/modules/post/linux/manage/xdg_open.rb b/modules/post/linux/manage/xdg_open.rb deleted file mode 100644 index dd280201d3..0000000000 --- a/modules/post/linux/manage/xdg_open.rb +++ /dev/null @@ -1,33 +0,0 @@ -## -# This module requires Metasploit: https://metasploit.com/download -# Current source: https://github.com/rapid7/metasploit-framework -## - -class MetasploitModule < Msf::Post - include Msf::Post::Linux::System - - def initialize(info={}) - super( update_info( info, - 'Name' => 'Linux Admin XDG open', - 'Description' => %q{ - This module will open any local resource in the target system via the 'xdg-open' command. - }, - 'License' => MSF_LICENSE, - 'Author' => ['DeveloppSoft'], - 'Platform' => ['linux'], - 'SessionTypes' => ['shell', 'meterpreter'] - )) - - register_options([ - OptString.new('RES', [true, 'Resource to open, URL or file.']) - ]) - end - - def run - unless command_exists? 'xdg-open' - print_error 'xdg-open is not available' - return - end - cmd_exec("xdg-open #{datastore['RES']} > /dev/null") - end -end diff --git a/modules/post/multi/manage/open.rb b/modules/post/multi/manage/open.rb new file mode 100644 index 0000000000..8cfadc51f6 --- /dev/null +++ b/modules/post/multi/manage/open.rb @@ -0,0 +1,73 @@ +## +# This module requires Metasploit: https://metasploit.com/download +# Current source: https://github.com/rapid7/metasploit-framework +## + +class MetasploitModule < Msf::Post + include Msf::Post::File + + def initialize(info={}) + super( update_info( info, + 'Name' => 'Open a file or URL on the target computer', + 'Description' => %q{ + This module will open any file or URL specified with the URI format on the + target computer via the embedded commands such as 'open' or 'xdg-open'. + }, + 'License' => MSF_LICENSE, + 'Author' => [ 'Eliott Teissonniere'], + 'Platform' => [ 'osx', 'linux' ], + 'SessionTypes' => [ 'shell', 'meterpreter' ] + )) + + register_options( + [ + OptString.new('URI', [true, 'URI path to open']) + ]) + end + + # + # The OSX version simply uses 'open' + # + def osx_open(uri) + begin + cmd_exec("open #{uri}") + rescue EOFError + return false + end + + true + end + + # + # The Linux version relies on 'xdg-open' + # + def linux_open(uri) + begin + cmd_exec("xdg-open #{uri}") + rescue EOFError + return false + end + + true + end + + def open(uri) + case session.platform + when 'osx' + return osx_open(uri) + when 'linux' + return linux_open(uri) + end + end + + def run + uri = datastore['URI'] + + print_status("Opening #{uri}") + if open(uri) + print_good('Success') + else + print_error('Command failed') + end + end +end