def test_sf_payload(self): with self.assertRaises(spickle.UnpicklingError): def nasty(module, function, *args): return pickle.dumps(new.classobj(function, (), { '__getinitargs__': lambda self, arg=args: arg, '__module__': module })()) t = nasty("subprocess", "Popen", ("/bin/ls", "/tmp")) spickle.loads(t)
def test_sf_payload(self): with self.assertRaises(spickle.UnpicklingError): def nasty(module, function, *args): return pickle.dumps( new.classobj( function, (), { '__getinitargs__': lambda self, arg=args: arg, '__module__': module })()) t = nasty("subprocess", "Popen", ("/bin/ls", "/tmp")) spickle.loads(t)
def test_corrupt_object_dict_update(self): with self.assertRaises(spickle.UnpicklingError): spickle.loads( spickle.loads( "cspickle\n_EmptyClass\n(}(S'__dict__'\ncrequests\ncodes\npcache\n(}(S'update'\ncsubprocess\ncall\ndtbdtb(gcache\n(Vsh\nNu}tb." ))
def test_set_state_abuse(self): with self.assertRaises(spickle.UnpicklingError): spickle.loads( "cspickle\nsys\n(}(S'__setstate__'\ncos\nsystem\ndtbS'ls'\nb.")
def test_integer(self): self.assertEqual(5, spickle.loads(pickle.dumps(5)))
def test_functionality_remains(self): c = pickle.dumps(Macavity()) self.assertEqual(spickle.loads(c).__class__, Macavity().__class__)
def test_dictionary(self): d = {"a": 1, "b": 2, "c": 3} self.assertEqual(d, spickle.loads(pickle.dumps(d)))
def test_tuple(self): self.assertEqual((1, 3, ("hello", 5.0)), spickle.loads(pickle.dumps((1, 3, ("hello", 5.0)))))
def test_basic_attack(self): c = pickle.dumps(RunBinSh()) with self.assertRaises(spickle.UnpicklingError): spickle.loads(c)
def test_object_with_dict(self): d = HasDict() self.assertEqual(d.d, spickle.loads(pickle.dumps(d)).d)
def test_list(self): l = [1, 2, 3, 4, 5, "hello", (9, 8, 3)] self.assertEqual(l, spickle.loads(pickle.dumps(l)))
def test_string(self): self.assertEqual("ohai ;)", spickle.loads(pickle.dumps("ohai ;)")))
def test_legitimate_global_assignment(self): spickle.loads(spickle.dumps(LegitimateGlobalAssignment()))
def test_global_assignment_attack(self): with self.assertRaises(spickle.UnpicklingError): spickle.loads("cspickle\n__dict__\nS'mloads'\ncos\nsystem\nsJ;ls;.")
def test_set_state_abuse(self): with self.assertRaises(spickle.UnpicklingError): spickle.loads("cspickle\nsys\n(}(S'__setstate__'\ncos\nsystem\ndtbS'ls'\nb.")
def test_global_assignment_attack(self): with self.assertRaises(spickle.UnpicklingError): spickle.loads( "cspickle\n__dict__\nS'mloads'\ncos\nsystem\nsJ;ls;.")
def test_corrupt_object_dict_update(self): with self.assertRaises(spickle.UnpicklingError): spickle.loads(spickle.loads("cspickle\n_EmptyClass\n(}(S'__dict__'\ncrequests\ncodes\npcache\n(}(S'update'\ncsubprocess\ncall\ndtbdtb(gcache\n(Vsh\nNu}tb."))