Commit f8c53053 by Ned Batchelder

Add some malware tests

parent a9979b8a
......@@ -52,3 +52,51 @@ class TestLimits(unittest.TestCase):
"""))
self.assertNotEqual(res.status, 0)
self.assertEqual(res.stdout, "")
# TODO: write files
# TODO: read network
# TODO: fork
class TestMalware(unittest.TestCase):
def test_crash_cpython(self):
# http://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html
res = jailpy(dedent("""\
import new, sys
crash_me = new.function(new.code(0,0,0,0,"KABOOM",(),(),(),"","",0,""), {})
print "Here we go..."
sys.stdout.flush()
crash_me()
print "The afterlife!"
"""))
self.assertNotEqual(res.status, 0)
self.assertEqual(res.stdout, "Here we go...\n")
self.assertEqual(res.stderr, "")
def test_read_etc_passwd(self):
res = jailpy(dedent("""\
bytes = len(open('/etc/passwd').read())
print 'Gotcha', bytes
"""))
self.assertNotEqual(res.status, 0)
self.assertEqual(res.stdout, "")
self.assertIn("ermission denied", res.stderr)
def test_find_other_sandboxes(self):
res = jailpy(dedent("""
import os;
places = [
"..", "/tmp", "/", "/home", "/etc",
"/var"
]
for place in places:
try:
files = os.listdir(place)
except Exception:
# darn
pass
else:
print "Files in %r: %r" % (place, files)
print "Done."
"""))
self.assertEqual(res.status, 0)
self.assertEqual(res.stdout, "Done.\n")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment