Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Doggy OS Security Error
- -- Function to draw a border
- local function drawBorder()
- term.clear()
- local w, h = term.getSize()
- for y = 1, h do
- term.setCursorPos(1, y)
- term.write("|")
- term.setCursorPos(w, y)
- term.write("|")
- end
- for x = 1, w do
- term.setCursorPos(x, 1)
- term.write("-")
- term.setCursorPos(x, h)
- term.write("-")
- end
- term.setCursorPos(1, 1)
- term.write("+")
- term.setCursorPos(w, 1)
- term.write("+")
- term.setCursorPos(1, h)
- term.write("+")
- term.setCursorPos(w, h)
- term.write("+")
- end
- -- Function to center text on the screen
- local function centerText(text, y)
- local w, _ = term.getSize()
- local x = math.floor((w - #text) / 2) + 1
- term.setCursorPos(x, y)
- term.write(text)
- end
- -- Function to show an error message
- local function showError(message)
- drawBorder()
- local _, h = term.getSize()
- centerText("Doggy OS Security Error", math.floor(h / 2) - 2)
- centerText("Error:", math.floor(h / 2))
- centerText(message, math.floor(h / 2) + 1)
- -- No need to show additional instructions
- while true do
- os.pullEvent("key")
- end
- end
- -- Check for boot.lock file
- if fs.exists("/boot.lock") then
- showError("System Disabled")
- end
- -- Function to check if .settings file exists and contains shell.allow_disk_startup
- local function isSecureBootConfigured()
- local settingsPath = "/.settings"
- if fs.exists(settingsPath) then
- local file = fs.open(settingsPath, "r")
- if file then
- local contents = file.readAll()
- file.close()
- -- Check if .settings contains shell.allow_disk_startup
- if not string.find(contents, '["%s-]shell%.allow_disk_startup["%s-]') then
- return false -- shell.allow_disk_startup not found
- end
- end
- else
- -- .settings file doesn't exist
- return false -- Secure boot configuration file is missing
- end
- return true -- Secure boot is properly configured
- end
- if not isSecureBootConfigured() then
- showError("Secure boot config file corrupted")
- end
- -- Function to check for malicious paths in a file
- local function containsMaliciousPaths(filePath)
- if not fs.exists(filePath) then
- return false
- end
- local file = fs.open(filePath, "r")
- if not file then
- return false
- end
- local contents = file.readAll()
- file.close()
- local maliciousPaths = {
- "/disk/os/", "/disk/boot/", "/disk/bootloader/", "/disk/security/", "/disk/users/", "/disk/",
- "disk/os", "disk/boot", "disk/bootloader", "disk/security", "disk/users", "disk"
- }
- for _, path in ipairs(maliciousPaths) do
- if string.find(contents, path, 1, true) then
- return true
- end
- end
- return false
- end
- -- Check if /disk2/startup or /disk2/startup.lua includes malicious paths
- if containsMaliciousPaths("/disk2/startup") then
- showError("Malicious Boot Device: /disk2/startup")
- elseif containsMaliciousPaths("/disk2/startup.lua") then
- showError("Malicious Boot Device: /disk2/startup.lua")
- end
- -- Check if /disk/users directory is empty
- local function isDiskUsersEmpty()
- local usersDir = "/disk/users"
- if fs.exists(usersDir) and fs.isDir(usersDir) then
- local files = fs.list(usersDir)
- return #files == 0
- end
- return true
- end
- if isDiskUsersEmpty() then
- showError("No user data found")
- end
- -- Check if /disk/boot/BIOS exists
- if not fs.exists("/disk/boot/BIOS") then
- showError("Critical boot files missing")
- end
- -- Check if any user has admin.txt
- local function hasAdmin()
- local usersDir = "/disk/users"
- if fs.exists(usersDir) and fs.isDir(usersDir) then
- local users = fs.list(usersDir)
- for _, user in ipairs(users) do
- local adminPath = fs.combine(usersDir, user, "admin.txt")
- if fs.exists(adminPath) then
- return true
- end
- end
- end
- return false
- end
- if not hasAdmin() then
- showError("No system administrators found")
- end
- -- Check if no-os file exists
- if not fs.exists("/no-os") then
- showError("System Firmware corrupted")
- end
- -- Continue with the normal boot process if no issues were found
- print("No issues detected. Continuing boot process...")
- -- Your normal boot code here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement