test.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import ctypes
  2. import os
  3. lib = ctypes.CDLL("/var/sandbox/sandbox-python/python.so")
  4. lib.DifySeccomp.argtypes = [ctypes.c_uint32, ctypes.c_uint32, ctypes.c_bool]
  5. lib.DifySeccomp.restype = None
  6. os.chdir("/var/sandbox/sandbox-python")
  7. lib.DifySeccomp(65537, 1000, 1)
  8. import sys
  9. import traceback
  10. # setup sys.excepthook
  11. def excepthook(type, value, tb):
  12. sys.stderr.write("".join(traceback.format_exception(type, value, tb)))
  13. sys.stderr.flush()
  14. sys.exit(-1)
  15. sys.excepthook = excepthook
  16. code = """
  17. import json
  18. # declare main function here
  19. def main() -> dict:
  20. import requests
  21. return {
  22. "result": requests.get("https://www.bilibili.com").text,
  23. }
  24. from json import loads, dumps
  25. from base64 import b64decode
  26. # execute main function, and return the result
  27. # inputs is a dict, and it
  28. inputs = b64decode('e30=').decode('utf-8')
  29. output = main(**json.loads(inputs))
  30. # convert output to json and print
  31. output = dumps(output, indent=4)
  32. result = f'''<<RESULT>>
  33. {output}
  34. <<RESULT>>'''
  35. print(result)
  36. """
  37. exec(code)