Skip to content

Commit 2fab62b

Browse files
authored
Update profinet_siemens.rb
Removed unnecessary rescue, gave "timeout" variable a better name.
1 parent 4484b6c commit 2fab62b

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

modules/auxiliary/scanner/scada/profinet_siemens.rb

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def initialize
2929
register_options(
3030
[
3131
OptString.new('INTERFACE', [ true, 'Set an interface', 'eth0' ]),
32-
OptInt.new('TIMEOUT', [ true, 'Seconds to wait, set longer on slower networks', 2 ])
32+
OptInt.new('ANSWERTIME', [ true, 'Seconds to wait for answers, set longer on slower networks', 2 ])
3333
], self.class
3434
)
3535
end
@@ -107,23 +107,19 @@ def parse_profinet(data)
107107
end
108108
end
109109

110-
def receive(iface, timeout)
110+
def receive(iface, answertime)
111111
capture = PacketFu::Capture.new(iface: iface, start: true, filter: 'ether proto 0x8892')
112-
sleep timeout
112+
sleep answertime
113113
capture.save
114114
i = 0
115115
capture.array.each do |packet|
116-
begin
117-
data = bin_to_hex(packet).downcase
118-
mac = data[12..13] + ':' + data[14..15] + ':' + data[16..17] + ':' + data[18..19] + ':' + data[20..21] + ':' + data[22..23]
119-
next unless data[28..31] == 'feff'
120-
print_good("Parsing packet from #{mac}")
121-
parse_profinet(data[28..-1])
122-
print_line('')
123-
i += 1
124-
rescue
125-
next
126-
end
116+
data = bin_to_hex(packet).downcase
117+
mac = data[12..13] + ':' + data[14..15] + ':' + data[16..17] + ':' + data[18..19] + ':' + data[20..21] + ':' + data[22..23]
118+
next unless data[28..31] == 'feff'
119+
print_good("Parsing packet from #{mac}")
120+
parse_profinet(data[28..-1])
121+
print_line('')
122+
i += 1
127123
end
128124
if i.zero?
129125
print_warning('No devices found, maybe you are running virtually?')
@@ -134,7 +130,7 @@ def receive(iface, timeout)
134130

135131
def run
136132
iface = datastore['INTERFACE']
137-
timeout = datastore['TIMEOUT']
133+
answertime = datastore['ANSWERTIME']
138134
packet = "\x00\x00\x88\x92\xfe\xfe\x05\x00\x04\x00\x00\x03\x00\x80\x00\x04\xff\xff\x00\x00\x00\x00"
139135
packet += "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
140136

@@ -151,6 +147,6 @@ def run
151147
print_status("Sending packet out to #{iface}")
152148
eth_pkt.to_w(iface)
153149

154-
receive(iface, timeout)
150+
receive(iface, answertime)
155151
end
156152
end

0 commit comments

Comments
 (0)