Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 02-22-2003, 12:14 PM   #1 (permalink)
anon
Guest
 
Posts: n/a
securing SUID0 programs?

I am wondering how it is possible to secure a program using the exec() function that SUID0 world. After playing around with HackersLab for a while I was thinking that doing:

exec("IFS=''; export IFS;/bin/ls");

would do, where /bin/ls is the full path to the program, but can someone not just change PATH to /tmp so that the command 'export' actually executes /bin/bash ? Would this work? Or is it possible to lock down a SUID0 world executable script?



/me is wondering this out of curiosity, I know it is better to have other ways then SUID0 scripts, I am just wondering.
  Reply With Quote
Old 02-22-2003, 01:07 PM   #2 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
i believe you are confusing the execve(2) function with the system(3) function. there is no unix "exec" (there is a shell function called exec).

system() calls the shell (sh -c) to execute the commandline given, and is not very safe. it is vulnerable to similar tricks as you described above.

execve() and the exec(3) family of calls (like execv() and execl()) are generally immune to stupid shell tricks (unless you explicitly call a shell program), and can be made safe with a little care.
joe_bruin is offline   Reply With Quote
Old 02-22-2003, 01:26 PM   #3 (permalink)
anon
Guest
 
Posts: n/a
I mean a C program using execl() and the exec() family can still be tricked into using the wrong file by modyfying the $IFS variable, no?
  Reply With Quote
Old 02-22-2003, 07:04 PM   #4 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
execl() and friends do not use the shell. they do not (for the most part) look at environment variables, and they do not perform wildcard expansions or alias interpretations (those are shell features). they pass their params directly to the kernel, and are safe from shell manipulations. IFS is entirely a shell thing.

these functions can be tricked by the use of chroot, although you must be root to chroot, so it's not a very big concern.

correction, i believe the execp* functions use the PWD environment variable to build an absolute path. and some others just read and pass the environment directly, but they do not use the environment variables for anything.
joe_bruin is offline   Reply With Quote
Old 02-22-2003, 09:29 PM   #5 (permalink)
anon
Guest
 
Posts: n/a
oh, ok, I was just wondering wether it was possible to secure a SUID0 world exec script, thanks!
  Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Are there any good Code highlight programs :S ? JeC PHP 19 05-09-2008 02:38 AM
Securing directories? Epsilon PHP 3 08-17-2004 09:04 AM
Running Programs From In C++ paul Standard C, C++ 5 03-23-2003 10:22 AM


All times are GMT -8. The time now is 05:11 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting