Advertisement
DOGGYWOOF

Untitled

Aug 28th, 2024 (edited)
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.15 KB | None | 0 0
  1. -- Clear the screen and set up colors
  2. term.clear()
  3. term.setBackgroundColor(colors.black)
  4. term.setTextColor(colors.white)
  5. term.clear()
  6.  
  7. -- Define the width and height of the screen
  8. local width, height = term.getSize()
  9.  
  10. -- Function to center text on the screen
  11. local function centerText(y, text, textColor)
  12. local x = math.floor((width - #text) / 2)
  13. term.setCursorPos(x, y)
  14. term.setTextColor(textColor)
  15. term.write(text)
  16. end
  17.  
  18. -- Display the initial message "Doggy OS Security Error!" at the top in white
  19. centerText(3, "Doggy OS Security Error!", colors.white)
  20.  
  21. -- Function to show an error message with ASCII art
  22. local function showError(message)
  23. term.clear()
  24.  
  25. -- ASCII art with yellow dog and ? eyes
  26. local dogArt = {
  27. " |\\_/| ",
  28. " | ? ? ",
  29. " | <> _ ",
  30. " | _/\\------____ ((| |))",
  31. " | `--' | ",
  32. " _____|_ ___| |___. ",
  33. "/_/_____/____/_______| "
  34. }
  35.  
  36. local startLine = math.floor((height - #dogArt) / 2) - 2
  37.  
  38. -- Display the dog ASCII art with yellow color and ? eyes
  39. term.setTextColor(colors.yellow)
  40. for i, line in ipairs(dogArt) do
  41. centerText(startLine + i, line, colors.yellow)
  42. end
  43.  
  44. -- Display error message below the dog ASCII art in white
  45. term.setTextColor(colors.white)
  46. centerText(startLine + #dogArt + 2, "Error:", colors.white)
  47. centerText(startLine + #dogArt + 3, message, colors.white)
  48.  
  49. -- Move "Please contact support." to the bottom in white
  50. centerText(height - 2, "Please contact support.", colors.white)
  51.  
  52. -- Keep the screen static with the error message
  53. while true do
  54. sleep(1)
  55. end
  56. end
  57.  
  58. -- Safe file reading function
  59. local function safeReadFile(filePath)
  60. local file, err = fs.open(filePath, "r")
  61. if not file then
  62. return nil, err
  63. end
  64.  
  65. local contents = file.readAll()
  66. file.close()
  67. return contents
  68. end
  69.  
  70. -- Function to check for boot.lock file
  71. local function checkBootLock()
  72. if fs.exists("/boot.lock") then
  73. showError("System Disabled")
  74. end
  75. end
  76.  
  77. -- Function to check if .settings file exists and contains shell.allow_disk_startup
  78. local function isSecureBootConfigured()
  79. local settingsPath = "/.settings"
  80. if fs.exists(settingsPath) then
  81. local contents, err = safeReadFile(settingsPath)
  82. if not contents then
  83. showError("Error reading .settings file: " .. err)
  84. return false
  85. end
  86. -- Check if .settings contains shell.allow_disk_startup
  87. if not string.find(contents, '["%s-]shell%.allow_disk_startup["%s-]') then
  88. return false -- shell.allow_disk_startup not found
  89. end
  90. else
  91. -- .settings file doesn't exist
  92. return false -- Secure boot configuration file is missing
  93. end
  94. return true -- Secure boot is properly configured
  95. end
  96.  
  97. -- Function to check for malicious paths in a file
  98. local function containsMaliciousPaths(filePath)
  99. if not fs.exists(filePath) then
  100. return false
  101. end
  102.  
  103. local contents, err = safeReadFile(filePath)
  104. if not contents then
  105. showError("Error reading file: " .. err)
  106. return false
  107. end
  108.  
  109. local maliciousPaths = {
  110. "/disk/os/", "/disk/boot/", "/disk/bootloader/", "/disk/security/", "/disk/users/", "/disk/",
  111. "disk/os", "disk/boot", "disk/bootloader", "disk/security", "disk/users", "disk"
  112. }
  113.  
  114. for _, path in ipairs(maliciousPaths) do
  115. if string.find(contents, path, 1, true) then
  116. return true
  117. end
  118. end
  119.  
  120. return false
  121. end
  122.  
  123. -- Function to check if /disk2/startup or /disk2/startup.lua includes malicious paths
  124. local function checkMaliciousBoot()
  125. if containsMaliciousPaths("/disk2/startup") then
  126. showError("Malicious Boot Device: /disk2/startup")
  127. elseif containsMaliciousPaths("/disk2/startup.lua") then
  128. showError("Malicious Boot Device: /disk2/startup.lua")
  129. end
  130. end
  131.  
  132. -- Function to check if /disk/users directory is empty
  133. local function checkEmptyUsers()
  134. local usersDir = "/disk/users"
  135. if fs.exists(usersDir) and fs.isDir(usersDir) then
  136. local files = fs.list(usersDir)
  137. if #files == 0 then
  138. showError("No user data found")
  139. end
  140. else
  141. showError("No user data found")
  142. end
  143. end
  144.  
  145. -- Function to check if /disk/boot/BIOS exists
  146. local function checkCriticalBootFiles()
  147. if not fs.exists("/disk/boot/BIOS") then
  148. showError("Critical boot files missing")
  149. end
  150. end
  151.  
  152. -- Function to check if any user has admin.txt
  153. local function checkAdmin()
  154. local usersDir = "/disk/users"
  155. if fs.exists(usersDir) and fs.isDir(usersDir) then
  156. local users = fs.list(usersDir)
  157. for _, user in ipairs(users) do
  158. local adminPath = fs.combine(usersDir, user, "admin.txt")
  159. if fs.exists(adminPath) then
  160. return true
  161. end
  162. end
  163. end
  164. return false
  165. end
  166.  
  167. -- Function to check if no-os file exists
  168. local function checkFirmware()
  169. if not fs.exists("/no-os") then
  170. showError("System Firmware corrupted")
  171. end
  172. end
  173.  
  174. -- Function to catch and handle errors
  175. local function safeRun(func, ...)
  176. local success, result = pcall(func, ...)
  177. if not success then
  178. showError("Runtime error: " .. result)
  179. end
  180. return result
  181. end
  182.  
  183. -- Main function to initiate checks and continue boot process
  184. local function main()
  185. safeRun(checkBootLock)
  186. if not safeRun(isSecureBootConfigured) then
  187. showError("Secure boot config file corrupted")
  188. end
  189. safeRun(checkMaliciousBoot)
  190. safeRun(checkEmptyUsers)
  191. safeRun(checkCriticalBootFiles)
  192. if not safeRun(checkAdmin) then
  193. showError("No system administrators found")
  194. end
  195. safeRun(checkFirmware)
  196.  
  197. -- If no issues found, continue with normal boot process
  198. safeRun(shell.run, "/disk/boot/BIOS")
  199. print("No issues detected. Continuing boot process...")
  200. -- Your normal boot code here
  201. end
  202.  
  203. -- Start the main function
  204. main()
  205.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement