Advertisement
DOGGYWOOF

Untitled

Jan 20th, 2025 (edited)
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.36 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. -- ASCII art for fatal error screen
  19. local fatalArt = {
  20. " |\\_/| ",
  21. " | X X FATAL ERROR ",
  22. " | <> _ ",
  23. " | _/\\------____ ((| |))",
  24. " | `--' | ",
  25. " _____|_ ___| |___. ",
  26. "/_/_____/____/_______| "
  27. }
  28.  
  29. -- ASCII art for warning screen
  30. local warningArt = {
  31. " |\\_/| ",
  32. " | ? ? SECURITY ERROR ",
  33. " | <> _ ",
  34. " | _/\\------____ ((| |))",
  35. " | `--' | ",
  36. " _____|_ ___| |___. ",
  37. "/_/_____/____/_______| "
  38. }
  39.  
  40. -- Function to prompt for admin credentials
  41. local function authenticateAdmin()
  42. term.clear()
  43. centerText(height / 2 - 1, "Admin Authentication Required", colors.yellow)
  44. centerText(height / 2, "Enter Username:", colors.white)
  45. term.setCursorPos((width - 20) / 2, height / 2 + 1)
  46. local username = read()
  47.  
  48. local passwordPath = "/disk/users/" .. username .. "/password.txt"
  49. local adminPath = "/disk/users/" .. username .. "/admin.txt"
  50.  
  51. if fs.exists(adminPath) and fs.exists(passwordPath) then
  52. centerText(height / 2 + 2, "Enter Password:", colors.white)
  53. term.setCursorPos((width - 20) / 2, height / 2 + 3)
  54. local enteredPassword = read("*")
  55.  
  56. local file = fs.open(passwordPath, "r")
  57. local storedPassword = file.readAll()
  58. file.close()
  59.  
  60. if enteredPassword == storedPassword then
  61. return true -- Authentication successful
  62. end
  63. end
  64.  
  65. centerText(height / 2 + 4, "Authentication Failed", colors.red)
  66. sleep(2)
  67. return false -- Authentication failed
  68. end
  69.  
  70. -- Function to show an error message with ASCII art
  71. local function showError(message, isFatal)
  72. term.clear()
  73.  
  74. -- Determine ASCII art and color based on error type
  75. local artColor = isFatal and colors.red or colors.yellow
  76. local art = isFatal and fatalArt or warningArt
  77.  
  78. -- Display the ASCII art
  79. local startLine = math.floor((height - #art) / 2) - 2
  80. term.setTextColor(artColor)
  81. for i, line in ipairs(art) do
  82. centerText(startLine + i, line, artColor)
  83. end
  84.  
  85. -- Display error message below the ASCII art
  86. term.setTextColor(colors.white)
  87. centerText(startLine + #art + 2, "Error:", colors.white)
  88. centerText(startLine + #art + 3, message, colors.white)
  89.  
  90. -- Move "Please contact support." to the bottom in white
  91. centerText(height - 2, "Press DEL for Admin Override", colors.white)
  92.  
  93. -- Wait for DEL key or keep the screen static
  94. while true do
  95. local event, key = os.pullEvent("key")
  96. if key == keys.delete then
  97. if authenticateAdmin() then
  98. return -- Exit the error screen if authentication succeeds
  99. end
  100. end
  101. sleep(0.1)
  102. end
  103. end
  104.  
  105. -- Function to check for boot.lock file
  106. local function checkBootLock()
  107. if fs.exists("/boot.lock") then
  108. showError("System Disabled", false) -- Warning
  109. end
  110. end
  111.  
  112. -- Function to check if .settings file exists and contains shell.allow_disk_startup
  113. local function isSecureBootConfigured()
  114. local settingsPath = "/.settings"
  115. if fs.exists(settingsPath) then
  116. local file = fs.open(settingsPath, "r")
  117. if file then
  118. local contents = file.readAll()
  119. file.close()
  120. -- Check if .settings contains shell.allow_disk_startup
  121. if not string.find(contents, 'shell%.allow_disk_startup') then
  122. return false -- shell.allow_disk_startup not found
  123. end
  124. end
  125. else
  126. -- .settings file doesn't exist
  127. return false -- Secure boot configuration file is missing
  128. end
  129. return true -- Secure boot is properly configured
  130. end
  131.  
  132. -- Function to check for malicious paths in a file
  133. local function containsMaliciousPaths(filePath)
  134. if not fs.exists(filePath) then
  135. return false
  136. end
  137.  
  138. local file = fs.open(filePath, "r")
  139. if not file then
  140. return false
  141. end
  142.  
  143. local contents = file.readAll()
  144. file.close()
  145.  
  146. local maliciousPaths = {
  147. "/disk/os/", "/disk/boot/", "/disk/bootloader/", "/disk/security/", "/disk/users/", "/disk/",
  148. "disk/os", "disk/boot", "disk/bootloader", "disk/security", "disk/users", "disk"
  149. }
  150.  
  151. for _, path in ipairs(maliciousPaths) do
  152. if string.find(contents, path, 1, true) then
  153. return true
  154. end
  155. end
  156.  
  157. return false
  158. end
  159.  
  160. -- Function to check if /disk2/startup or /disk2/startup.lua includes malicious paths
  161. local function checkMaliciousBoot()
  162. if containsMaliciousPaths("/disk2/startup") then
  163. showError("Malicious Boot Device: /disk2/startup", false) -- Warning
  164. elseif containsMaliciousPaths("/disk2/startup.lua") then
  165. showError("Malicious Boot Device: /disk2/startup.lua", false) -- Warning
  166. end
  167. end
  168.  
  169. -- Function to check if /disk/users directory is empty
  170. local function checkEmptyUsers()
  171. local usersDir = "/disk/users"
  172. if fs.exists(usersDir) and fs.isDir(usersDir) then
  173. local files = fs.list(usersDir)
  174. if #files == 0 then
  175. showError("No user data found", false) -- Warning
  176. end
  177. else
  178. showError("No user data found", false) -- Warning
  179. end
  180. end
  181.  
  182. -- Function to check if /disk/boot/BIOS exists
  183. local function checkCriticalBootFiles()
  184. if not fs.exists("/disk/boot/boot-animation") then
  185. showError("/disk/boot/BIOS Cannot be loaded", true) -- Fatal
  186. end
  187. end
  188.  
  189. -- Function to check if any user has admin.txt
  190. local function checkAdmin()
  191. local usersDir = "/disk/users"
  192. if fs.exists(usersDir) and fs.isDir(usersDir) then
  193. local users = fs.list(usersDir)
  194. for _, user in ipairs(users) do
  195. local adminPath = fs.combine(usersDir, user, "admin.txt")
  196. if fs.exists(adminPath) then
  197. return true
  198. end
  199. end
  200. end
  201. return false
  202. end
  203.  
  204. -- Function to check if no-os file exists
  205. local function checkFirmware()
  206. if not fs.exists("/no-os") then
  207. showError("System Firmware Corrupted", true) -- Fatal
  208. end
  209. end
  210.  
  211. -- Main function to initiate checks and continue boot process
  212. local function main()
  213. checkBootLock()
  214. if not isSecureBootConfigured() then
  215. showError("Secure Boot Service Unavailable", true) -- Fatal
  216. end
  217. checkMaliciousBoot()
  218. checkEmptyUsers()
  219. checkCriticalBootFiles()
  220. if not checkAdmin() then
  221. showError("No system administrators found", false) -- Warning
  222. end
  223. checkFirmware()
  224.  
  225. -- If no issues found, continue with normal boot process
  226. shell.run("/disk/boot/BIOS")
  227. print("No issues detected. Continuing boot process...")
  228. shell.run("/disk/error/crash")
  229. -- Your normal boot code here
  230. end
  231.  
  232. -- Start the main function
  233. main()
  234.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement