Advertisement
DOGGYWOOF

Boot check

Jun 30th, 2024 (edited)
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.46 KB | None | 0 0
  1. -- Doggy OS Security Error
  2.  
  3. -- Function to draw a border
  4. local function drawBorder()
  5. term.clear()
  6. local w, h = term.getSize()
  7. for y = 1, h do
  8. term.setCursorPos(1, y)
  9. term.write("|")
  10. term.setCursorPos(w, y)
  11. term.write("|")
  12. end
  13. for x = 1, w do
  14. term.setCursorPos(x, 1)
  15. term.write("-")
  16. term.setCursorPos(x, h)
  17. term.write("-")
  18. end
  19. term.setCursorPos(1, 1)
  20. term.write("+")
  21. term.setCursorPos(w, 1)
  22. term.write("+")
  23. term.setCursorPos(1, h)
  24. term.write("+")
  25. term.setCursorPos(w, h)
  26. term.write("+")
  27. end
  28.  
  29. -- Function to center text on the screen
  30. local function centerText(text, y)
  31. local w, _ = term.getSize()
  32. local x = math.floor((w - #text) / 2) + 1
  33. term.setCursorPos(x, y)
  34. term.write(text)
  35. end
  36.  
  37. -- Function to show an error message
  38. local function showError(message)
  39. drawBorder()
  40. local _, h = term.getSize()
  41. centerText("Doggy OS Security Error", math.floor(h / 2) - 2)
  42. centerText("Error:", math.floor(h / 2))
  43. centerText(message, math.floor(h / 2) + 1)
  44. -- No need to show additional instructions
  45. while true do
  46. os.pullEvent("key")
  47. end
  48. end
  49.  
  50. -- Check for boot.lock file
  51. if fs.exists("/boot.lock") then
  52. showError("System Disabled")
  53. end
  54.  
  55. -- Function to check if .settings file exists and contains shell.allow_disk_startup
  56. local function isSecureBootConfigured()
  57. local settingsPath = "/.settings"
  58. if fs.exists(settingsPath) then
  59. local file = fs.open(settingsPath, "r")
  60. if file then
  61. local contents = file.readAll()
  62. file.close()
  63. -- Check if .settings contains shell.allow_disk_startup
  64. if not string.find(contents, '["%s-]shell%.allow_disk_startup["%s-]') then
  65. return false -- shell.allow_disk_startup not found
  66. end
  67. end
  68. else
  69. -- .settings file doesn't exist
  70. return false -- Secure boot configuration file is missing
  71. end
  72. return true -- Secure boot is properly configured
  73. end
  74.  
  75. if not isSecureBootConfigured() then
  76. showError("Secure boot config file corrupted")
  77. end
  78.  
  79. -- Function to check for malicious paths in a file
  80. local function containsMaliciousPaths(filePath)
  81. if not fs.exists(filePath) then
  82. return false
  83. end
  84.  
  85. local file = fs.open(filePath, "r")
  86. if not file then
  87. return false
  88. end
  89.  
  90. local contents = file.readAll()
  91. file.close()
  92.  
  93. local maliciousPaths = {
  94. "/disk/os/", "/disk/boot/", "/disk/bootloader/", "/disk/security/", "/disk/users/", "/disk/",
  95. "disk/os", "disk/boot", "disk/bootloader", "disk/security", "disk/users", "disk"
  96. }
  97.  
  98. for _, path in ipairs(maliciousPaths) do
  99. if string.find(contents, path, 1, true) then
  100. return true
  101. end
  102. end
  103.  
  104. return false
  105. end
  106.  
  107. -- Check if /disk2/startup or /disk2/startup.lua includes malicious paths
  108. if containsMaliciousPaths("/disk2/startup") then
  109. showError("Malicious Boot Device: /disk2/startup")
  110. elseif containsMaliciousPaths("/disk2/startup.lua") then
  111. showError("Malicious Boot Device: /disk2/startup.lua")
  112. end
  113.  
  114. -- Check if /disk/users directory is empty
  115. local function isDiskUsersEmpty()
  116. local usersDir = "/disk/users"
  117. if fs.exists(usersDir) and fs.isDir(usersDir) then
  118. local files = fs.list(usersDir)
  119. return #files == 0
  120. end
  121. return true
  122. end
  123.  
  124. if isDiskUsersEmpty() then
  125. showError("No user data found")
  126. end
  127.  
  128. -- Check if /disk/boot/BIOS exists
  129. if not fs.exists("/disk/boot/BIOS") then
  130. showError("Critical boot files missing")
  131. end
  132.  
  133. -- Check if any user has admin.txt
  134. local function hasAdmin()
  135. local usersDir = "/disk/users"
  136. if fs.exists(usersDir) and fs.isDir(usersDir) then
  137. local users = fs.list(usersDir)
  138. for _, user in ipairs(users) do
  139. local adminPath = fs.combine(usersDir, user, "admin.txt")
  140. if fs.exists(adminPath) then
  141. return true
  142. end
  143. end
  144. end
  145. return false
  146. end
  147.  
  148. if not hasAdmin() then
  149. showError("No system administrators found")
  150. end
  151.  
  152. -- Check if no-os file exists
  153. if not fs.exists("/no-os") then
  154. showError("System Firmware corrupted")
  155. end
  156.  
  157. -- Continue with the normal boot process if no issues were found
  158. print("No issues detected. Continuing boot process...")
  159. -- Your normal boot code here
  160.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement