Advertisement
timmie140

Idea

Nov 25th, 2024 (edited)
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. -- Place your loadstring here for testing
  2. local loadstringInput = [[
  3. -- Example loadstring (replace this with your own)
  4. print("Hello from the sandbox!")
  5. ]]
  6.  
  7. -- Sandbox Script
  8. local function sandboxedLoader(input)
  9. -- Create a sandbox environment
  10. local sandboxEnv = {
  11. print = print, -- Allow harmless functions
  12. pairs = pairs,
  13. ipairs = ipairs,
  14. tonumber = tonumber,
  15. tostring = tostring,
  16. math = math,
  17. string = string,
  18. table = table,
  19. }
  20.  
  21. -- Restrict sensitive functions
  22. setmetatable(sandboxEnv, { __index = function(_, key)
  23. error("Access to " .. tostring(key) .. " is restricted in this sandbox!", 0)
  24. end })
  25.  
  26. -- Load the input in the sandbox
  27. local func, loadError = loadstring(input)
  28. if not func then
  29. return false, "Error loading script: " .. loadError
  30. end
  31.  
  32. setfenv(func, sandboxEnv) -- Set the environment to the sandbox
  33. local success, result = pcall(func)
  34. if not success then
  35. return false, "Error executing script: " .. result
  36. end
  37.  
  38. -- Analyze the result for suspicious behavior
  39. -- Add custom checks here if needed (e.g., scanning script content)
  40.  
  41. return true, "Script executed safely!"
  42. end
  43.  
  44. -- Run the sandbox
  45. local status, message = sandboxedLoader(loadstringInput)
  46. if status then
  47. print("Result: Safe - " .. message)
  48. else
  49. print("Result: Suspicious - " .. message)
  50. end
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement