pen-test
[Top] [All Lists]

Re: question on escalating privileges via suid vulnerabilities

To: pen-test@securityfocus.com
Subject: Re: question on escalating privileges via suid vulnerabilities
From: Marco Ivaldi <raptor@mediaservice.net>
Date: Mon, 26 Feb 2007 14:08:20 +0100 (ora solare Europa occidentale)
Delivered-to: sp-com-lists@consult.net
Delivered-to: pentest-list2@consult.net
Delivered-to: mailing list pen-test@securityfocus.com
Delivered-to: moderator for pen-test@securityfocus.com
In-reply-to: <7c488dd80702241052y225c158fn9b2c8372f10a6f3b@mail.gmail.com>
List-help: <mailto:pen-test-help@securityfocus.com>
List-id: <pen-test.list-id.securityfocus.com>
List-post: <mailto:pen-test@securityfocus.com>
List-subscribe: <mailto:pen-test-subscribe@securityfocus.com>
List-unsubscribe: <mailto:pen-test-unsubscribe@securityfocus.com>
Mailing-list: contact pen-test-help@securityfocus.com; run by ezmlm
References: <7c488dd80702241052y225c158fn9b2c8372f10a6f3b@mail.gmail.com>
Resent-date: Mon, 26 Feb 2007 13:29:59 -0700 (MST)
Resent-from: pen-test-return-1078483638@securityfocus.com
Resent-message-id: <20070226202959.0CDD223A7A0@outgoing3.securityfocus.com>
Resent-sender: listbounce@securityfocus.com
Sender: listbounce@securityfocus.com
John,

On Sat, 24 Feb 2007, John McGuire wrote:

I was curious if anyone knows if new protections have been put in place to prevent spawning root shells from vulnerable applications.

[snip]

When I run the app as a non-root user, I get a /bin/sh prompt with that users perms, not roots. I modified this program a bit to take an argument off the command line and passed it `whoami`. This returned root as the response. /bin/sh however belongs to the lower priv user.

Hrm, this is the expected behaviour. Take a look at the following example:

root@shaolin:/home/raptor# cat >vuln1.c
#include <stdio.h>
int main() {
      char *arr[2];
      arr[0] = "/bin/sh";
      arr[1] = NULL;
      execve (arr[0], arr, NULL);
}
root@shaolin:/home/raptor# gcc vuln1.c -o vuln1
root@shaolin:/home/raptor# chmod 4755 vuln1
root@shaolin:/home/raptor# su - raptor
raptor@shaolin:~$ ./vuln1
sh-3.1$ id
uid=1000(raptor) gid=100(users) groups=100(users)
sh-3.1$ exit
exit
raptor@shaolin:~$

root@shaolin:/home/raptor# cat > vuln2.c
#include <stdio.h>
int main() {
      char *arr[2];
      arr[0] = "/bin/sh";
      arr[1] = NULL;
      setuid(0); // HERE
      execve (arr[0], arr, NULL);
}
root@shaolin:/home/raptor# gcc vuln2.c -o vuln2
root@shaolin:/home/raptor# chmod 4755 vuln2
root@shaolin:/home/raptor# su - raptor
raptor@shaolin:~$ ./vuln2
sh-3.1# id
uid=0(root) gid=100(users) groups=100(users)
sh-3.1# exit
exit
raptor@shaolin:~$

In short, when you execute a file with the setuid bit set, the spawned process runs with privileges similar to the following:

uid=1000(raptor) gid=100(users) euid=0(root) groups=100(users)

Since as a "security measure" bash (and most modern shells, with some notable exceptions) checks if euid != uid and if that's the case drops privileges back to uid, you should explicitly do a setuid(0) before executing the shell.

This is _extremely_ basic knowledge. I encourage you to take a look at the following resources, in case you haven't already:

http://www.0xdeadbeef.info/code/linux-x86-exploits.tgz
http://www.0xdeadbeef.info/code/vulndev-exploits.tgz
http://www.0xdeadbeef.info/code/abo-exploits.tgz
http://www.0xdeadbeef.info/code/fs-exploits.tgz

Not very up to date, but still a good starting point for learning, IMHO. And of course man(1) and Google are your friends;)

--
Marco Ivaldi, OPST
Chief Security Officer    Data Security Division
@ Mediaservice.net Srl    http://mediaservice.net/


------------------------------------------------------------------------
This List Sponsored by: Cenzic

Need to secure your web apps?
Cenzic Hailstorm finds vulnerabilities fast.
Click the link to buy it, try it or download Hailstorm for FREE.

http://www.cenzic.com/products_services/download_hailstorm.php?camp=701600000008bOW
------------------------------------------------------------------------


<Prev in Thread] Current Thread [Next in Thread>