Network Time Protocol ntpq Buffer Overflow Vulnerability
A buffer overflow in ntpq's nextvar() function allows a long argument to the addvar command to overflow a 256-byte name buffer. An attacker who can control variable names passed to ntpq via a script could potentially execute code or cause a crash.
Originally disclosed on Cisco Talos
ntpq contains a buffer overflow. nextvar() executes a memcpy() into the name buffer without a proper length check against its maximum length of 256 bytes.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Impact
A malicious user could exploit this if ntpq is run by another script that reads variable names from an untrusted source, potentially leading to code execution or a crash, though buffer overflow protections may affect whether an error is seen.
What the attacker needed
Ntpq run by a script; script reads variable names from untrusted source
How it was found
- Run ntpq with the addvar command and an argument consisting of a long string of characters (e.g., 500 'i's).
- The argument is truncated to 503 bytes, but the destination buffer is only 256 bytes.
- Because the argument contains no spaces, commas, equal signs, or carriage returns, the entire 503 bytes are copied into the name buffer via memcpy().
- This overflows the buffer, potentially causing a crash or code execution.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A buffer overflow happens when a program copies more data into a fixed-size memory area than it can hold, potentially overwriting nearby memory. Here, the ntpq tool copies a user-supplied name into a 256-byte buffer without checking its length, so a very long name can spill over and corrupt memory. This could let an attacker run their own code or crash the program, but only if they can get ntpq to process a malicious name, for example through a script that reads names from an untrusted source.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.