Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Function to check if a file is within restricted directories
- local function isRestricted(path)
- local restrictedDirs = {"/", "/disk/os/", "/disk/packages/", "/disk/boot/", "/disk/bootloader/", "/disk/error/"}
- for _, dir in ipairs(restrictedDirs) do
- if path:sub(1, #dir) == dir then
- return true
- end
- end
- return false
- end
- -- Function to check for blocked actions in code
- local function checkCode(code)
- local blockedActions = {"delete", "cp", "copy", "edit"}
- for _, action in ipairs(blockedActions) do
- if code:find(action) then
- return true
- end
- end
- return false
- end
- -- Function to replace startup script with security error message and reboot
- local function securityError()
- local file = fs.open("startup", "w")
- file.writeLine("term.clear()")
- file.writeLine("term.setCursorPos(1,1)")
- file.writeLine("print('Security error: App security error')")
- file.writeLine("read()")
- file.writeLine("os.reboot()")
- file.close()
- end
- -- Main function to monitor files in /disk/packages
- local function monitorPackages()
- while true do
- local files = fs.list("/disk/packages")
- for _, file in ipairs(files) do
- local path = "/disk/packages/" .. file
- if fs.isDir(path) then
- -- Ignore directories
- goto continue
- end
- local code = fs.open(path, "r")
- local content = code.readAll()
- code.close()
- if checkCode(content) or isRestricted(path) then
- -- Detected suspicious activity, replace startup script and reboot
- securityError()
- os.reboot()
- end
- ::continue::
- end
- sleep(2) -- Check every 2 seconds
- end
- end
- -- Start monitoring
- parallel.waitForAny(monitorPackages)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement