Advertisement
DOGGYWOOF

E

Mar 15th, 2024
3
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. -- Function to check if a file is within restricted directories
  2. local function isRestricted(path)
  3. local restrictedDirs = {"/", "/disk/os/", "/disk/packages/", "/disk/boot/", "/disk/bootloader/", "/disk/error/"}
  4. for _, dir in ipairs(restrictedDirs) do
  5. if path:sub(1, #dir) == dir then
  6. return true
  7. end
  8. end
  9. return false
  10. end
  11.  
  12. -- Function to check for blocked actions in code
  13. local function checkCode(code)
  14. local blockedActions = {"delete", "cp", "copy", "edit"}
  15. for _, action in ipairs(blockedActions) do
  16. if code:find(action) then
  17. return true
  18. end
  19. end
  20. return false
  21. end
  22.  
  23. -- Function to replace startup script with security error message and reboot
  24. local function securityError()
  25. local file = fs.open("startup", "w")
  26. file.writeLine("term.clear()")
  27. file.writeLine("term.setCursorPos(1,1)")
  28. file.writeLine("print('Security error: App security error')")
  29. file.writeLine("read()")
  30. file.writeLine("os.reboot()")
  31. file.close()
  32. end
  33.  
  34. -- Main function to monitor files in /disk/packages
  35. local function monitorPackages()
  36. while true do
  37. local files = fs.list("/disk/packages")
  38. for _, file in ipairs(files) do
  39. local path = "/disk/packages/" .. file
  40. if fs.isDir(path) then
  41. -- Ignore directories
  42. goto continue
  43. end
  44.  
  45. local code = fs.open(path, "r")
  46. local content = code.readAll()
  47. code.close()
  48.  
  49. if checkCode(content) or isRestricted(path) then
  50. -- Detected suspicious activity, replace startup script and reboot
  51. securityError()
  52. os.reboot()
  53. end
  54.  
  55. ::continue::
  56. end
  57. sleep(2) -- Check every 2 seconds
  58. end
  59. end
  60.  
  61. -- Start monitoring
  62. parallel.waitForAny(monitorPackages)
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement