chkrootkit local privilege escalation (CVE-2014-0476)
CVE-2014-0476 is a flaw in chkrootkit up to version 0.49, the tool many administrators leave running from cron to hunt for rootkits. The irony is complete: the program watching the machine is the one that hands over root.
The mechanism. Inside chkrootkit, the slapper() function runs ./update unquoted and without validating anything. Since the script is launched from a directory the attacker effectively controls, if /tmp/update exists with execute permission, chkrootkit runs it with the privileges of whoever launched it. And whoever launches it, when it sits in the system cron, is root.
No exploit is needed: drop the file and wait. The usual payload is not a reverse shell but marking bash as SUID, which survives the cron moment and does not depend on the attacker listening at the right second:
cat > /tmp/update <<'EOF'
#!/bin/bash
chmod u+s /bin/bash
EOF
chmod +x /tmp/updateWhen cron fires, /bin/bash becomes -rwsr-xr-x and bash -p (which keeps the effective UID instead of dropping it) gives the root shell.
ls -l /bin/bash
bash -pRequirements. chkrootkit 0.49 or earlier, launched periodically by root, and write access to /tmp, which is normal. What to confirm before wasting time is both halves: the version (cat /usr/sbin/chkrootkit tells you) and that root really runs it, which pspy shows without reading /etc/crontab.
How to detect it. The cleanest signature is /tmp/update appearing with execute permission, a file that does not exist on a healthy machine: an auditd rule on executable creation under /tmp catches it. Then chmod u+s on a system binary is the event that really matters and the one always worth alerting on, wherever it comes from: a /bin/bash with the SUID bit is an indicator of compromise on its own, and a periodic find / -perm -4000 sweep finds it. In the cron log, chkrootkit running and a /tmp file executing immediately after closes the correlation.
Defence. Update chkrootkit (fixed since 0.50) and, in the meantime, do not run it from root's cron. As a general measure, mounting /tmp with noexec breaks this whole class of escalations, and it is worth remembering that the pattern is the same as the cron over a writable script: a privileged task running something an unprivileged user can place there. The way to spot it is the usual one, from the version to the exploit.
Machines where it's used
- SickOs 1.2VulnHub