networking, updated

NTP

The Network Time Protocol keeps clocks in sync to within milliseconds. Logs, Kerberos and TLS certificates all depend on correct time, and exposed NTP servers have powered some of the largest DDoS attacks.

OSI layer
7 Application
Carried in
UDP
Ports
123/udp, 4460/tcp (NTS key exchange)
Specs
RFC 5905, RFC 8915
Wireshark filter
ntp
Encrypted
no

Packet structure

NTPv4 packet48 bytes + variable

Select a field to see what it does.

RFC 5905. 48 bytes, optionally followed by extension fields and a MAC. Timestamps are 64 bits: seconds since 1900 plus a binary fraction.

Requests and replies use the same 48-byte format. Client requests are mostly zeros except mode, version and the transmit timestamp.

How it works

sequenceDiagram
    participant C as Client
    participant S as Server :123
    Note over C: T1 = transmit time
    C->>S: Mode 3 (client), Transmit = T1
    Note over S: T2 = receive time, T3 = transmit time
    S->>C: Mode 4 (server), Origin = T1, Receive = T2, Transmit = T3
    Note over C: T4 = arrival time

The client computes:

It polls several servers, throws out outliers and slowly adjusts its clock (slewing) instead of jumping. Servers form a hierarchy of strata: stratum 1 servers have a reference clock (GPS, radio, atomic), stratum 2 syncs from stratum 1, and so on.

In Active Directory, members sync from their domain controller, DCs from the PDC emulator, and the PDC from an external source. Windows uses the same packet format (W32Time).

In Wireshark

FilterShows
ntpAll NTP
ntp.flags.mode == 3Client requests
ntp.flags.mode == 4Server replies
ntp.flags.mode == 7Private mode (monlist): should not exist
ntp.flags.mode == 6Control queries (ntpq): reconnaissance from outside
ntp.stratum == 0Kiss-o’-Death (rate limiting, access denied)
ntp.flags.li == 3Unsynchronised servers
udp.srcport == 123 && frame.len > 200Large NTP replies: possible amplification
ntp && !(ip.dst == 10.0.0.0/8 || ip.dst == 172.16.0.0/12 || ip.dst == 192.168.0.0/16)NTP leaving the network

What normal looks like: clients talk to a few internal servers (or DCs) every 64 to 1024 seconds, 90-byte frames both ways. Large replies, mode 6/7 traffic from the internet, or many hosts querying random public NTP servers are worth a look. NTP to an unusual server with a regular beat can also be a covert channel, since few people check it.

Security notes

References

§ home
~/knubertus/home/
1,1 Top