Skip to content

Commit 9db3dc7

Browse files
committed
Store peer data note in the same format as originally
1 parent 758c3fa commit 9db3dc7

File tree

1 file changed

+4
-49
lines changed

1 file changed

+4
-49
lines changed

modules/auxiliary/scanner/ntp/ntp_monlist.rb

Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ def scanner_postscan(batch)
102102
:proto => 'udp',
103103
:port => rport,
104104
:type => 'ntp.addresses',
105-
:data => {:addresses => peers.map { |p| p[1] }.sort.uniq }
105+
:data => {:addresses => peers.map { |p| p.last }.sort.uniq }
106106
)
107107

108108
if (datastore['StoreNTPClients'])
109109
print_status("#{peer} Storing #{peers.length} NTP client hosts in the database...")
110110
peers.each do |r|
111-
maddr,mserv,mport = r
111+
maddr,mport,mserv = r
112112
report_note(
113113
:host => maddr,
114114
:type => 'ntp.client.history',
@@ -140,6 +140,7 @@ def scanner_postscan(batch)
140140

141141
end
142142

143+
# Examine the monlist reponse +data+ and extract all peer tuples (saddd, dport, daddr)
143144
def extract_peer_tuples(data)
144145
return [] if data.length < 76
145146

@@ -162,55 +163,9 @@ def extract_peer_tuples(data)
162163

163164
_,_,_,_,saddr,daddr,_,dport = data[idx, 30].unpack("NNNNNNNn")
164165

165-
peer_tuples << [ Rex::Socket.addr_itoa(saddr), Rex::Socket.addr_itoa(daddr), dport ]
166+
peer_tuples << [ Rex::Socket.addr_itoa(saddr), dport, Rex::Socket.addr_itoa(daddr) ]
166167
idx += plen
167168
end
168169
peer_tuples
169170
end
170-
171-
# Fingerprint a single host
172-
def parse_reply(pkt)
173-
174-
# Ignore "empty" packets
175-
return if not pkt[1]
176-
177-
if(pkt[1] =~ /^::ffff:/)
178-
pkt[1] = pkt[1].sub(/^::ffff:/, '')
179-
end
180-
181-
data = pkt[0]
182-
host = pkt[1]
183-
port = pkt[2]
184-
185-
return if pkt[0].length < (72 + 16)
186-
187-
# NTP headers 8 bytes
188-
ntp_flags, ntp_auth, ntp_vers, ntp_code = data.slice!(0,4).unpack('C*')
189-
vprint_status("#{host}:#{port} - ntp_auth: #{ntp_auth}, ntp_vers: #{ntp_vers}")
190-
pcnt, plen = data.slice!(0,4).unpack('nn')
191-
return if plen != 72
192-
193-
idx = 0
194-
1.upto(pcnt) do
195-
#u_int32 firsttime; /* first time we received a packet */
196-
#u_int32 lasttime; /* last packet from this host */
197-
#u_int32 restr; /* restrict bits (was named lastdrop) */
198-
#u_int32 count; /* count of packets received */
199-
#u_int32 addr; /* host address V4 style */
200-
#u_int32 daddr; /* destination host address */
201-
#u_int32 flags; /* flags about destination */
202-
#u_short port; /* port number of last reception */
203-
204-
firsttime,lasttime,restr,count,saddr,daddr,flags,dport = data[idx, 30].unpack("NNNNNNNn")
205-
206-
@results[host] ||= []
207-
@aliases[host] ||= {}
208-
@results[host] << [ Rex::Socket.addr_itoa(daddr), dport, Rex::Socket.addr_itoa(saddr) ]
209-
@aliases[host][Rex::Socket.addr_itoa(saddr)] = true
210-
if datastore['SHOW_LIST']
211-
print_status("#{host}:#{port} #{Rex::Socket.addr_itoa(saddr)} (lst: #{lasttime}sec., cnt: #{count})")
212-
end
213-
idx += plen
214-
end
215-
end
216171
end

0 commit comments

Comments
 (0)