prescript.py 947 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. if __name__ == "__main__":
  2. import ctypes
  3. import os
  4. import sys
  5. import json
  6. import typing
  7. import time
  8. import traceback
  9. import jinja2
  10. import re
  11. if len(sys.argv) != 4:
  12. sys.exit(-1)
  13. lib = ctypes.CDLL("/tmp/sandbox-python/python.so")
  14. module = sys.argv[1]
  15. code = open(module).read()
  16. with open("/tmp/1.txt", "w") as f:
  17. f.write(code)
  18. def sandbox(uid, gid):
  19. lib.DifySeccomp.argtypes = [ctypes.c_uint32, ctypes.c_uint32]
  20. lib.DifySeccomp.restype = None
  21. lib.DifySeccomp(uid, gid)
  22. uid = int(sys.argv[2])
  23. gid = int(sys.argv[3])
  24. if not uid or not gid:
  25. sys.exit(-1)
  26. sandbox(uid, gid)
  27. # setup sys.excepthook
  28. def excepthook(type, value, tb):
  29. sys.stderr.write("".join(traceback.format_exception(type, value, tb)))
  30. sys.stderr.flush()
  31. sys.exit(-1)
  32. sys.excepthook = excepthook
  33. exec(code)