|
9 | 9 | ## MODBUS/TCP scanner to find correct Unit_ID/StationID
|
10 | 10 |
|
11 | 11 | require 'msf/core'
|
| 12 | + |
12 | 13 | class Metasploit3 < Msf::Auxiliary
|
13 | 14 | include Msf::Exploit::Remote::Tcp
|
14 | 15 | include Msf::Auxiliary::Fuzzer
|
15 | 16 |
|
| 17 | + |
16 | 18 | def initialize(info = {})
|
17 | 19 | super(update_info(info,
|
18 | 20 | 'Name' => 'Modbus_findunitID',
|
@@ -49,49 +51,38 @@ def run
|
49 | 51 | start="\x21\x00\x00\x00\x00\x06"
|
50 | 52 | theend="\x04\x00\x01\x00\x00"
|
51 | 53 | 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") |
59 | 57 | datastore['UNIT_ID_FROM']=1
|
60 | 58 | 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'] |
68 | 62 | end
|
69 | 63 | if datastore['UNIT_ID_FROM'] > datastore['UNIT_ID_TO'] then
|
70 | 64 | print_status("UNIT_ID_TO is less than UNIT_ID_FROM, setting them equal")
|
71 | 65 | datastore['UNIT_ID_TO']=datastore['UNIT_ID_FROM']
|
72 | 66 | end
|
73 | 67 |
|
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| |
76 | 69 | sploit=start
|
77 | 70 | sploit+=[counter].pack("C")
|
78 | 71 | sploit+=theend
|
79 |
| - #sleep(datastore['BENICE']) |
80 | 72 | select(nil,nil,nil,datastore['BENICE'])
|
81 | 73 | connect()
|
82 | 74 | sock.put(sploit)
|
83 |
| - #debug: print_status("sent to unit_id #{counter} ") |
| 75 | + #debug: print_status("sent to unit_id #{counter} ") |
84 | 76 | data = sock.get_once(12, datastore['TIMEOUT'])
|
85 | 77 | if (data.nil?)
|
86 | 78 | data=noll+noll+noll+noll
|
87 | 79 | end
|
88 | 80 | if data[0,4] == "\x21\x00\x00\x00" #return of the same trans-id+proto-id
|
89 | 81 | print_good("Received: correct MODBUS/TCP from stationID #{counter}")
|
90 | 82 | 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)") |
92 | 84 | end
|
93 | 85 | disconnect()
|
94 |
| - counter=counter + 1 |
95 | 86 | end
|
96 | 87 | end
|
97 | 88 | end
|
|
0 commit comments