Skip to content

Commit 66fe8ad

Browse files
committed
Merge branch 'modbus-aux' of git://github.com/esmnemon/metasploit-framework into esmnemon-modbus-aux
2 parents 675e5c0 + 81e5666 commit 66fe8ad

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

modules/auxiliary/scanner/scada/modbusFindunitID.rb renamed to modules/auxiliary/scanner/scada/modbus_findunitid.rb

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
## MODBUS/TCP scanner to find correct Unit_ID/StationID
1010

1111
require 'msf/core'
12+
1213
class Metasploit3 < Msf::Auxiliary
1314
include Msf::Exploit::Remote::Tcp
1415
include Msf::Auxiliary::Fuzzer
1516

17+
1618
def initialize(info = {})
1719
super(update_info(info,
1820
'Name' => 'Modbus_findunitID',
@@ -49,49 +51,38 @@ def run
4951
start="\x21\x00\x00\x00\x00\x06"
5052
theend="\x04\x00\x01\x00\x00"
5153
noll="\x00"
52-
# between, \01..\0fe (1-254)
53-
if datastore['UNIT_ID_FROM'] < 1 then
54-
print_status("unit ID must be between 1 and 254 adjust to 1")
55-
datastore['UNIT_ID_FROM']=1
56-
end
57-
if datastore['UNIT_ID_FROM'] > 254 then
58-
print_status("unit ID must be between 1 and 254 adjust to 1")
54+
# between, \01..\0ff (1-255)
55+
unless (1..255).include? datastore['UNIT_ID_FROM']
56+
print_status("unit ID must be between 1 and 254 adjusting UNIT_ID_FROM to 1")
5957
datastore['UNIT_ID_FROM']=1
6058
end
61-
if datastore['UNIT_ID_TO'] < 1 then
62-
print_status("unit ID must be between 1 and 254, adjusing to #{datastore['UNIT_ID_FROM']+1} ")
63-
datastore['UNIT_ID_TO']=datastore['UNIT_ID_FROM'] + 1
64-
end
65-
if datastore['UNIT_ID_TO'] > 254 then
66-
print_status("unit ID must be between 1 and 254, adjusing to #{datastore['UNIT_ID_FROM']+1} ")
67-
datastore['UNIT_ID_TO']=datastore['UNIT_ID_FROM'] + 1
59+
unless (1..255).include? datastore['UNIT_ID_TO']
60+
print_status("unit ID must be between #{datastore['UNIT_ID_FROM']} and 255, adjusting UNIT_ID_TO to #{datastore['UNIT_ID_FROM']} ")
61+
datastore['UNIT_ID_TO']=datastore['UNIT_ID_FROM']
6862
end
6963
if datastore['UNIT_ID_FROM'] > datastore['UNIT_ID_TO'] then
7064
print_status("UNIT_ID_TO is less than UNIT_ID_FROM, setting them equal")
7165
datastore['UNIT_ID_TO']=datastore['UNIT_ID_FROM']
7266
end
7367

74-
counter=datastore['UNIT_ID_FROM']
75-
while counter <= datastore['UNIT_ID_TO']
68+
datastore['UNIT_ID_FROM'].upto(datastore['UNIT_ID_TO']) do |counter|
7669
sploit=start
7770
sploit+=[counter].pack("C")
7871
sploit+=theend
79-
#sleep(datastore['BENICE'])
8072
select(nil,nil,nil,datastore['BENICE'])
8173
connect()
8274
sock.put(sploit)
83-
#debug: print_status("sent to unit_id #{counter} ")
75+
#debug: print_status("sent to unit_id #{counter} ")
8476
data = sock.get_once(12, datastore['TIMEOUT'])
8577
if (data.nil?)
8678
data=noll+noll+noll+noll
8779
end
8880
if data[0,4] == "\x21\x00\x00\x00" #return of the same trans-id+proto-id
8981
print_good("Received: correct MODBUS/TCP from stationID #{counter}")
9082
else
91-
print_error("Received: incorrect/none data from stationID #{counter} (probably not in use)")
83+
print_status("Received: incorrect/none data from stationID #{counter} (probably not in use)")
9284
end
9385
disconnect()
94-
counter=counter + 1
9586
end
9687
end
9788
end

0 commit comments

Comments
 (0)