|
@@ -3,26 +3,28 @@ if __name__ == "__main__":
|
|
|
import os
|
|
|
import sys
|
|
|
import json
|
|
|
- import typing
|
|
|
import time
|
|
|
import traceback
|
|
|
- import jinja2
|
|
|
- import re
|
|
|
|
|
|
- if len(sys.argv) != 4:
|
|
|
+ # setup sys.excepthook
|
|
|
+ def excepthook(type, value, tb):
|
|
|
+ sys.stderr.write("".join(traceback.format_exception(type, value, tb)))
|
|
|
+ sys.stderr.flush()
|
|
|
+ sys.exit(-1)
|
|
|
+
|
|
|
+ sys.excepthook = excepthook
|
|
|
+
|
|
|
+ if len(sys.argv) != 5:
|
|
|
sys.exit(-1)
|
|
|
|
|
|
lib = ctypes.CDLL("/tmp/sandbox-python/python.so")
|
|
|
module = sys.argv[1]
|
|
|
code = open(module).read()
|
|
|
|
|
|
- with open("/tmp/1.txt", "w") as f:
|
|
|
- f.write(code)
|
|
|
-
|
|
|
- def sandbox(uid, gid):
|
|
|
- lib.DifySeccomp.argtypes = [ctypes.c_uint32, ctypes.c_uint32]
|
|
|
+ def sandbox(uid, gid, enable_network):
|
|
|
+ lib.DifySeccomp.argtypes = [ctypes.c_uint32, ctypes.c_uint32, ctypes.c_bool]
|
|
|
lib.DifySeccomp.restype = None
|
|
|
- lib.DifySeccomp(uid, gid)
|
|
|
+ lib.DifySeccomp(uid, gid, enable_network)
|
|
|
|
|
|
uid = int(sys.argv[2])
|
|
|
gid = int(sys.argv[3])
|
|
@@ -34,12 +36,4 @@ if __name__ == "__main__":
|
|
|
|
|
|
sandbox(uid, gid, options.get("enable_network", False))
|
|
|
|
|
|
- # setup sys.excepthook
|
|
|
- def excepthook(type, value, tb):
|
|
|
- sys.stderr.write("".join(traceback.format_exception(type, value, tb)))
|
|
|
- sys.stderr.flush()
|
|
|
- sys.exit(-1)
|
|
|
-
|
|
|
- sys.excepthook = excepthook
|
|
|
-
|
|
|
exec(code)
|