ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-list
python-list
Re: How do I add users using Python scripts on a Linux machine
by Piet van Oostrum other posts by this author
Jan 4 2007 6:10AM messages near this date
Re: How do I add users using Python scripts on a Linux machine | Re: How do I add users using Python scripts on a Linux machine
> >>>> Sebastian 'lunar' Wiesner <basti.wiesner@[...].net> (SW) wrote:

> SW> I don't see a problem with SUID on scripts. If you restrict write access
> SW> to the owner, modification is hardly possible. 
> SW> However, if you allow world-wide write access to your binaries and
> SW> scripts, both can easily be modified...

The scenario is as follows: Suppose the script starts with the line:
#!/usr/bin/python

(using #!/usr/bin/env python would be disastrous because the user could
supply his own `python interpreter' in his PATH.)

Now a malicious user can make a link to this file in his own directory,
e.g. to /Users/eve/myscript1. Because permissions are part of the file
(inode), not of the file name, this one is also suid.

Now she execs /Users/eve/myscript1. The kernel, when honoring suid scripts,
would startup python with effective uid root with the command line:
/usr/bin/env /Users/eve/myscript1

Now in another process eve changes the link /Users/eve/myscript1 to
point to another script /Users/eve/myscript2. If she manages to change the
link between the startup of the python executable and the interpreter
opening the file /Users/eve/myscript1, she has her own script running as
root.

Of course the timing is a bit critical but if you try often enough some
time it will succeed. The problem is the time window between starting the
executable and opening the script. There is no guarantee that the file will
be the same. It can only be made safe if interpreters can be passed inodes
or opened files by the kernel, but that is not how most interpreters work.
At least not python.
-- 
Piet van Oostrum <piet@[...].nl> 
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: piet@[...].org
-- 
http://mail.python.org/mailman/listinfo/python-list
Thread:
Piet van Oostrum
Lawrence D'Oliveiro
Piet van Oostrum
Lawrence D'Oliveiro
Piet van Oostrum
Garylinux@Gmail.Com
Sebastian 'lunar' Wiesner
Ivan Voras
Sebastian 'lunar' Wiesner
Tim Roberts

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved