The cronjob script bundled with ntp package on Ubuntu Wily is intended to perform cleanup on statistics files produced by NTP daemon running with statistics enabled. The script is run as root during the daily cronjobs all operations on the ntp-user controlled statistics directory without switching to user ntp. Thus all steps are performed with root permissions in place.
Due to multiple bugs in the script, a malicious ntp user can make the backup process to overwrite arbitrary files with content controlled by the attacker, thus gaining root privileges. The problematic parts in /etc/cron.daily/ntp are:
find "$statsdir" -type f -mtime +7 -exec rm {} \;
# compress whatever is left to save space
cd "$statsdir"
ls *stats.???????? > /dev/null 2>&1
if [ $? -eq 0 ]; then
# Note that gzip won't compress the file names that
# are hard links to the live/current files, so this
# compresses yesterday and previous, leaving the live
# log alone. We supress the warnings gzip issues
# about not compressing the linked file.
gzip --best --quiet *stats.????????
Relevant targets are:
find and rm invocation is racy, symlinks on rm
rm can be invoked with one attacker controlled option
ls can be invoked with arbitrary number of attacker controlled command line options
gzip can be invoked with arbitrary number of attacker controlled options
The cronjob script bundled with ntp package on Ubuntu Wily is intended to perform cleanup on statistics files produced by NTP daemon running with statistics enabled. The script is run as root during the daily cronjobs all operations on the ntp-user controlled statistics directory without switching to user ntp. Thus all steps are performed with root permissions in place.
Due to multiple bugs in the script, a malicious ntp user can make the backup process to overwrite arbitrary files with content controlled by the attacker, thus gaining root privileges. The problematic parts in /etc/cron.daily/ntp are:
find "$statsdir" -type f -mtime +7 -exec rm {} \;
# compress whatever is left to save space
cd "$statsdir"
ls *stats.???????? > /dev/null 2>&1
if [ $? -eq 0 ]; then
# Note that gzip won't compress the file names that
# are hard links to the live/current files, so this
# compresses yesterday and previous, leaving the live
# log alone. We supress the warnings gzip issues
# about not compressing the linked file.
gzip --best --quiet *stats.????????
Relevant targets are:
find and rm invocation is racy, symlinks on rm
rm can be invoked with one attacker controlled option
ls can be invoked with arbitrary number of attacker controlled command line options
gzip can be invoked with arbitrary number of attacker controlled options
See http:// www.halfdog. net/Security/ 2015/NtpCronjob UserNtpToRootPr ivilegeEscalati on/ for working user ntp to root privilege escalation exploit, sharing policy is attached to this issue.
# lsb_release -rd p5+dfsg- 3ubuntu8. 1 p5+dfsg- 3ubuntu8. 1 p5+dfsg- 3ubuntu8. 1 0 archive. ubuntu. com/ubuntu/ wily-updates/main amd64 Packages archive. ubuntu. com/ubuntu/ wily-security/main amd64 Packages dpkg/status 4.2.6.p5+ dfsg-3ubuntu8 0 archive. ubuntu. com/ubuntu/ wily/main amd64 Packages
Description: Ubuntu 15.10
Release: 15.10
# apt-cache policy ntp
ntp:
Installed: 1:4.2.6.
Candidate: 1:4.2.6.
Version table:
*** 1:4.2.6.
500 http://
500 http://
100 /var/lib/
1:
500 http://