Nmap ntp-monlist NSE Script


This page contains detailed information about how to use the ntp-monlist NSE script. For list of all NSE scripts, visit the Nmap NSE Library.

Select:
Overview
Error Messages

Script Overview


Script source code: https://github.com/nmap/nmap/tree/master/scripts/ntp-monlist.nse
Script categories: discovery, intrusive
Target service / protocol: ntp, udp
Target network port(s): 123
List of CVEs: -

Script Description


The ntp-monlist.nse script obtains and prints an NTP server's monitor data.

Monitor data is a list of the most recently used (MRU) having NTP associations with the target. Each record contains information about the most recent NTP packet sent by a host to the target including the source and destination addresses and the NTP version and mode of the packet. With this information it is possible to classify associated hosts as Servers, Peers, and Clients.

A Peers command is also sent to the target and the peers list in the response allows differentiation between configured Mode 1 Peers and clients which act like Peers (such as the Windows W32Time service).

Associated hosts are further classified as either public or private. Private hosts are those having IP addresses which are not routable on the public Internet and thus can help to form a picture about the topology of the private network on which the target resides.

Other information revealed by the monlist and peers commands are the host with which the target clock is synchronized and hosts which send Control Mode (6) and Private Mode (7) commands to the target and which may be used by admins for the NTP service.

It should be noted that the very nature of the NTP monitor data means that the Mode 7 commands sent by this script are recorded by the target (and will often appear in these results). Since the monitor data is a MRU list, it is probable that you can overwrite the record of the Mode 7 command by sending an innocuous looking Client Mode request. This can be achieved easily using Nmap: nmap -sU -pU:123 -Pn -n --max-retries=0 <target>

Notes:

  • The monitor list in response to the monlist command is limited to 600 associations.
  • The monitor capability may not be enabled on the target in which case you may receive an error number 4 (No Data Available).
  • There may be a restriction on who can perform Mode 7 commands (e.g. "restrict noquery" in ntp.conf) in which case you may not receive a reply.
  • This script does not handle authenticating and targets expecting auth info may respond with error number 3 (Format Error).

Ntp-monlist NSE Script Arguments


The ntp-monlist.nse script does not have any arguments.

Ntp-monlist NSE Script Example Usage


Here's an example of how to use the ntp-monlist.nse script:

nmap -sU -pU:123 -Pn -n --script=ntp-monlist <target>

Ntp-monlist NSE Script Example Output


Here's a sample output from the ntp-monlist.nse script:

PORT    STATE SERVICE REASON
123/udp open  ntp     udp-response
| ntp-monlist:
|   Target is synchronised with 127.127.38.0 (reference clock)
|   Alternative Target Interfaces:
|       10.17.4.20
|   Private Servers (0)
|   Public Servers (0)
|   Private Peers (0)
|   Public Peers (0)
|   Private Clients (2)
|       10.20.8.69      169.254.138.63
|   Public Clients (597)
|       4.79.17.248     68.70.72.194    74.247.37.194   99.190.119.152
|       ...
|       12.10.160.20    68.80.36.133    75.1.39.42      108.7.58.118
|       68.56.205.98
|       2001:1400:0:0:0:0:0:1 2001:16d8:dd00:38:0:0:0:2
|       2002:db5a:bccd:1:21d:e0ff:feb7:b96f 2002:b6ef:81c4:0:0:1145:59c5:3682
|   Other Associations (1)
|_      127.0.0.1 seen 1949869 times. last tx was unicast v2 mode 7

Ntp-monlist NSE Script Example XML Output


There is no sample XML output for this module. However, by providing the -oX <file> option, Nmap will produce a XML output and save it in the file.xml file.

Author


  • jah

References


See Also


Related NSE scripts to the ntp-monlist.nse script:

Visit Nmap NSE Library for more scripts.

The ntp-monlist.nse script may fail with the following error messages. Check for the possible causes by using the code snippets highlighted below found in the script source code. This can often times help in identifying the root cause of the problem.

Error establishing a UDP connection for %s - %s


Here is a relevant code snippet related to the "Error establishing a UDP connection for %s - %s" error message:

166:	  if not sock then
167:	    sock = nmap.new_socket()
168:	    sock:set_timeout(TIMEOUT)
169:	    local constatus, conerr = sock:connect(host, port)
170:	    if not constatus then
171:	      stdnse.debug1('Error establishing a UDP connection for %s - %s', target, conerr)
172:	      return nil
173:	    end
174:	  end
175:	
176:	  -- send

Error sending NTP request to %s:%d - %s


Here is a relevant code snippet related to the "Error sending NTP request to %s:%d - %s" error message:

176:	  -- send
177:	  stdnse.debug2('Sending NTPv2 Mode 7 Request %d Implementation %d to %s.', rcode, inum, target)
178:	  local ntpData = getPrivateMode(inum, rcode)
179:	  local sendstatus, senderr = sock:send(ntpData)
180:	  if not sendstatus then
181:	    stdnse.debug1('Error sending NTP request to %s:%d - %s', host.ip, port.number, senderr)
182:	    sock:close()
183:	    return nil
184:	  end
185:	
186:	  local track = {

Socket error while reading from %s - %s


Here is a relevant code snippet related to the "Socket error while reading from %s - %s" error message:

281:	  -- check for socket error
282:	  if not status then
283:	    track.errcond = true
284:	    track.rcv_again = false
285:	    if track.rcv_again then -- we were expecting more responses
286:	      stdnse.debug1('Socket error while reading from %s - %s', track.target, response)
287:	    end
288:	    return nil
289:	  end
290:	
291:	  -- reset flags

Failed to create a Packet object with response from %s


Here is a relevant code snippet related to the "Failed to create a Packet object with response from %s" error message:

295:	  -- create a packet object
296:	  local pkt = make_udp_packet(response)
297:	  if pkt == nil then
298:	    track.errcond = true
299:	    track.evil_pkts = track.evil_pkts+1
300:	    stdnse.debug1('Failed to create a Packet object with response from %s', track.target)
301:	    return nil
302:	  end
303:	
304:	  -- off is the start of udp payload i.e. NTP
305:	  local off = 28

Incompatible Implementation Number


Here is a relevant code snippet related to the "Incompatible Implementation Number" error message:

361:	  local err = (pkt:u8(off+4) >> 4) & 0x0f
362:	  if err == 0 then
363:	    -- NoOp
364:	  elseif err == 1 then
365:	    fail = true
366:	    msg = 'Incompatible Implementation Number'
367:	  elseif err == 2 then
368:	    fail = true
369:	    msg = 'Unimplemented Request Code'
370:	  elseif err == 3 then
371:	    fail = true

Format Error' -- could be that auth is required - we didn


Here is a relevant code snippet related to the "Format Error' -- could be that auth is required - we didn" error message:

367:	  elseif err == 2 then
368:	    fail = true
369:	    msg = 'Unimplemented Request Code'
370:	  elseif err == 3 then
371:	    fail = true
372:	    msg = 'Format Error' -- could be that auth is required - we didn't provide it.
373:	  elseif err == 4 then
374:	    fail = true
375:	    msg = 'No Data Available' -- monitor not enabled or nothing in mru list.
376:	  elseif err == 5 or err == 6 then
377:	    fail = true

Bogus Error Code!


Here is a relevant code snippet related to the "Bogus Error Code!" error message:

380:	    fail = true
381:	    msg = 'Authentication Failure'
382:	  elseif err > 7 then
383:	    fail = true
384:	    track.evil_pkts = track.evil_pkts+1
385:	    msg = 'Bogus Error Code!' -- should not happen...
386:	  end
387:	  if fail then
388:	    track.errcond = true
389:	    stdnse.debug1('Response from %s was NTP Error Code %d - "%s"', track.target, err, msg)
390:	    return nil

Response from %s was NTP Error Code %d - "%s"


Here is a relevant code snippet related to the "Response from %s was NTP Error Code %d - "%s"" error message:

384:	    track.evil_pkts = track.evil_pkts+1
385:	    msg = 'Bogus Error Code!' -- should not happen...
386:	  end
387:	  if fail then
388:	    track.errcond = true
389:	    stdnse.debug1('Response from %s was NTP Error Code %d - "%s"', track.target, err, msg)
390:	    return nil
391:	  end
392:	
393:	  -- length checks - the data (number of items * size of an item) should be
394:	  -- 8 <= data <= 500 and each data item should be of correct length for the

NTP Mode 7 response from %s has invalid count (%d) and/or size (%d) values.


Here is a relevant code snippet related to the "NTP Mode 7 response from %s has invalid count (%d) and/or size (%d) values." error message:

404:	    stdnse.debug1('Expected at least one record from %s.', track.target)
405:	    return nil
406:	  elseif icount*isize + 8 > response:len() then
407:	    track.errcond = true
408:	    track.evil_pkts = track.evil_pkts+1
409:	    stdnse.debug1('NTP Mode 7 response from %s has invalid count (%d) and/or size (%d) values.', track.target, icount, isize)
410:	    return nil
411:	  elseif icount*isize > 500 then
412:	    track.errcond = true
413:	    track.evil_pkts = track.evil_pkts+1
414:	    stdnse.debug1('NTP Mode 7 data section is larger than 500 bytes (%d) in response from %s.', icount*isize, track.target)

Version


This page has been created based on Nmap version 7.92.

Go back to menu.