Clean a little response parsing
parent
1f3466a3a3
commit
25f13eac37
|
@ -28,8 +28,9 @@ class Metasploit3 < Msf::Auxiliary
|
||||||
['READ_COIL', { 'Description' => 'Read one bit from a coil' } ],
|
['READ_COIL', { 'Description' => 'Read one bit from a coil' } ],
|
||||||
['WRITE_COIL', { 'Description' => 'Write one bit to a coil' } ],
|
['WRITE_COIL', { 'Description' => 'Write one bit to a coil' } ],
|
||||||
['READ_REGISTER', { 'Description' => 'Read one word from a register' } ],
|
['READ_REGISTER', { 'Description' => 'Read one word from a register' } ],
|
||||||
['WRITE_REGISTER', { 'Description' => 'Write one word to a register' } ],
|
['WRITE_REGISTER', { 'Description' => 'Write one word to a register' } ]
|
||||||
]
|
],
|
||||||
|
'DefaultAction' => 'READ_REGISTER'
|
||||||
))
|
))
|
||||||
|
|
||||||
register_options(
|
register_options(
|
||||||
|
@ -112,16 +113,19 @@ class Metasploit3 < Msf::Auxiliary
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_coil
|
def read_coil
|
||||||
@function_code = 1
|
@function_code = 0x1
|
||||||
print_status("Sending READ COIL...")
|
print_status("Sending READ COIL...")
|
||||||
response = send_frame(make_read_payload)
|
response = send_frame(make_read_payload)
|
||||||
if response.nil?
|
if response.nil?
|
||||||
print_error("No answer for the READ COIL")
|
print_error("No answer for the READ COIL")
|
||||||
return
|
return
|
||||||
elsif response.unpack("C*")[-2] == 129
|
elsif response.unpack("C*")[7] == (0x80 | @function_code)
|
||||||
handle_error(response)
|
handle_error(response)
|
||||||
|
elsif response.unpack("C*")[7] == @function_code
|
||||||
|
value = response[9].unpack("c")[0]
|
||||||
|
print_good("Coil value at address #{datastore['DATA_ADDRESS']} : #{value}")
|
||||||
else
|
else
|
||||||
print_good("Coil value at address #{datastore['DATA_ADDRESS']} : " + response.reverse.unpack("c").to_s.gsub('[', '').gsub(']', ''))
|
print_error("Unknown answer")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -131,12 +135,13 @@ class Metasploit3 < Msf::Auxiliary
|
||||||
response = send_frame(make_read_payload)
|
response = send_frame(make_read_payload)
|
||||||
if response.nil?
|
if response.nil?
|
||||||
print_error("No answer for the READ REGISTER")
|
print_error("No answer for the READ REGISTER")
|
||||||
return
|
elsif response.unpack("C*")[7] == (0x80 | @function_code)
|
||||||
elsif response.unpack("C*")[-2] == 131
|
|
||||||
handle_error(response)
|
handle_error(response)
|
||||||
|
elsif response.unpack("C*")[7] == @function_code
|
||||||
|
value = response[9..10].unpack("n")[0]
|
||||||
|
print_good("Register value at address #{datastore['DATA_ADDRESS']} : #{value}")
|
||||||
else
|
else
|
||||||
value = response.split[0][9..10].to_s.unpack("n").to_s.gsub('[', '').gsub(']','')
|
print_error("Unknown answer")
|
||||||
print_good("Register value at address #{datastore['DATA_ADDRESS']} : " + value)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -154,11 +159,12 @@ class Metasploit3 < Msf::Auxiliary
|
||||||
response = send_frame(make_write_coil_payload(data))
|
response = send_frame(make_write_coil_payload(data))
|
||||||
if response.nil?
|
if response.nil?
|
||||||
print_error("No answer for the WRITE COIL")
|
print_error("No answer for the WRITE COIL")
|
||||||
return
|
elsif response.unpack("C*")[7] == (0x80 | @function_code)
|
||||||
elsif response.unpack("C*")[-2] == 133
|
|
||||||
handle_error(response)
|
handle_error(response)
|
||||||
else
|
elsif response.unpack("C*")[7] == @function_code
|
||||||
print_good("Value #{datastore['DATA']} successfully written at coil address #{datastore['DATA_ADDRESS']}")
|
print_good("Value #{datastore['DATA']} successfully written at coil address #{datastore['DATA_ADDRESS']}")
|
||||||
|
else
|
||||||
|
print_error("Unknown answer")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -172,18 +178,19 @@ class Metasploit3 < Msf::Auxiliary
|
||||||
response = send_frame(make_write_register_payload(datastore['DATA']))
|
response = send_frame(make_write_register_payload(datastore['DATA']))
|
||||||
if response.nil?
|
if response.nil?
|
||||||
print_error("No answer for the WRITE REGISTER")
|
print_error("No answer for the WRITE REGISTER")
|
||||||
return
|
elsif response.unpack("C*")[7] == (0x80 | @function_code)
|
||||||
elsif response.unpack("C*")[-2] == 134
|
|
||||||
handle_error(response)
|
handle_error(response)
|
||||||
else
|
elsif response.unpack("C*")[7] == @function_code
|
||||||
print_good("Value #{datastore['DATA']} successfully written at registry address #{datastore['DATA_ADDRESS']}")
|
print_good("Value #{datastore['DATA']} successfully written at registry address #{datastore['DATA_ADDRESS']}")
|
||||||
|
else
|
||||||
|
print_error("Unknown answer")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def run
|
def run
|
||||||
@modbus_counter = 0x0000 # used for modbus frames
|
@modbus_counter = 0x0000 # used for modbus frames
|
||||||
connect
|
connect
|
||||||
case datastore['ACTION']
|
case action.name
|
||||||
when "READ_COIL"
|
when "READ_COIL"
|
||||||
read_coil
|
read_coil
|
||||||
when "READ_REGISTER"
|
when "READ_REGISTER"
|
||||||
|
|
Loading…
Reference in New Issue