Advertisement
DOGGYWOOF

Untitled

Aug 7th, 2024 (edited)
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.91 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. -- Function to show an error message with ASCII art
  19. local function showError(message)
  20. term.clear()
  21.  
  22. -- ASCII art with yellow dog and ? eyes
  23. local dogArt = {
  24. " |\\_/| ",
  25. " | ? ? ",
  26. " | <> _ ",
  27. " | _/\\------____ ((| |))",
  28. " | `--' | ",
  29. " _____|_ ___| |___. ",
  30. "/_/_____/____/_______| "
  31. }
  32.  
  33. local startLine = math.floor((height - #dogArt) / 2) - 2
  34.  
  35. -- Display the dog ASCII art with yellow color and X eyes
  36. term.setTextColor(colors.yellow)
  37. for i, line in ipairs(dogArt) do
  38. centerText(startLine + i, line, colors.yellow)
  39. end
  40.  
  41. -- Display error message below the dog ASCII art in white
  42. term.setTextColor(colors.white)
  43. centerText(startLine + #dogArt + 2, "Error:", colors.white)
  44. centerText(startLine + #dogArt + 3, message, colors.white)
  45.  
  46. -- Move "Please contact support." to the bottom in white
  47. centerText(height - 2, "Please contact support.", colors.white)
  48.  
  49. -- Keep the screen static with the error message
  50. while true do
  51. sleep(1)
  52. end
  53. end
  54.  
  55. -- Function to show the developer mode screen with red dog ASCII art
  56. local function showDeveloperModeScreen()
  57. term.clear()
  58.  
  59. -- ASCII art with red dog
  60. local dogArt = {
  61. " |\\_/| ",
  62. " | X X ",
  63. " | <> _ ",
  64. " | _/\\------____ ((| |))",
  65. " | `--' | ",
  66. " _____|_ ___| |___. ",
  67. "/_/_____/____/_______| "
  68. }
  69.  
  70. local startLine = math.floor((height - #dogArt) / 2) - 2
  71.  
  72. -- Display "Developer Mode Enabled" message in red above the dog
  73. term.setTextColor(colors.red)
  74. centerText(startLine, "Developer Mode Enabled", colors.red)
  75.  
  76. -- Display the dog ASCII art with red color
  77. term.setTextColor(colors.red)
  78. for i, line in ipairs(dogArt) do
  79. centerText(startLine + 2 + i, line, colors.red)
  80. end
  81.  
  82. -- Display other messages below in white
  83. term.setTextColor(colors.white)
  84. centerText(height - 4, "Press F1 to continue boot...", colors.white)
  85. centerText(height - 2, "Press F8 to disable developer mode", colors.white)
  86.  
  87. while true do
  88. local event, key = os.pullEvent("key")
  89. if key == keys.f1 then
  90. -- Continue to boot into developer mode
  91. shell.run("/disk/boot/BIOS")
  92. print("Booting into developer mode...")
  93. return true -- Indicates that developer mode is active
  94. elseif key == keys.f8 then
  95. -- Disable developer mode
  96. local devCfgPath = "/dev.cfg"
  97. if fs.exists(devCfgPath) then
  98. fs.delete(devCfgPath)
  99. centerText(height - 2, "Developer mode disabled. Restarting...", colors.white)
  100. sleep(2) -- Wait for a moment to show the message
  101. term.clear()
  102. -- Restart the script to check the new state
  103. shell.run(shell.getRunningProgram())
  104. return false
  105. end
  106. end
  107. end
  108. end
  109.  
  110. -- Function to check for boot.lock file
  111. local function checkBootLock()
  112. if fs.exists("/boot.lock") then
  113. showError("System Disabled")
  114. end
  115. end
  116.  
  117. -- Function to check if .settings file exists and contains shell.allow_disk_startup
  118. local function isSecureBootConfigured()
  119. local settingsPath = "/.settings"
  120. if fs.exists(settingsPath) then
  121. local file = fs.open(settingsPath, "r")
  122. if file then
  123. local contents = file.readAll()
  124. file.close()
  125. -- Check if .settings contains shell.allow_disk_startup
  126. if not string.find(contents, '["%s-]shell%.allow_disk_startup["%s-]') then
  127. return false -- shell.allow_disk_startup not found
  128. end
  129. end
  130. else
  131. -- .settings file doesn't exist
  132. return false -- Secure boot configuration file is missing
  133. end
  134. return true -- Secure boot is properly configured
  135. end
  136.  
  137. -- Function to check for malicious paths in a file
  138. local function containsMaliciousPaths(filePath)
  139. if not fs.exists(filePath) then
  140. return false
  141. end
  142.  
  143. local file = fs.open(filePath, "r")
  144. if not file then
  145. return false
  146. end
  147.  
  148. local contents = file.readAll()
  149. file.close()
  150.  
  151. local maliciousPaths = {
  152. "/disk/os/", "/disk/boot/", "/disk/bootloader/", "/disk/security/", "/disk/users/", "/disk/",
  153. "disk/os", "disk/boot", "disk/bootloader", "disk/security", "disk/users", "disk"
  154. }
  155.  
  156. for _, path in ipairs(maliciousPaths) do
  157. if string.find(contents, path, 1, true) then
  158. return true
  159. end
  160. end
  161.  
  162. return false
  163. end
  164.  
  165. -- Function to check if /disk2/startup or /disk2/startup.lua includes malicious paths
  166. local function checkMaliciousBoot()
  167. if containsMaliciousPaths("/disk2/startup") then
  168. showError("Malicious Boot Device: /disk2/startup")
  169. elseif containsMaliciousPaths("/disk2/startup.lua") then
  170. showError("Malicious Boot Device: /disk2/startup.lua")
  171. end
  172. end
  173.  
  174. -- Function to check if /disk/users directory is empty
  175. local function checkEmptyUsers()
  176. local usersDir = "/disk/users"
  177. if fs.exists(usersDir) and fs.isDir(usersDir) then
  178. local files = fs.list(usersDir)
  179. if #files == 0 then
  180. showError("No user data found")
  181. end
  182. else
  183. showError("No user data found")
  184. end
  185. end
  186.  
  187. -- Function to check if /disk/boot/BIOS exists
  188. local function checkCriticalBootFiles()
  189. if not fs.exists("/disk/boot/BIOS") then
  190. showError("Critical boot files missing")
  191. end
  192. end
  193.  
  194. -- Function to check if any user has admin.txt
  195. local function checkAdmin()
  196. local usersDir = "/disk/users"
  197. if fs.exists(usersDir) and fs.isDir(usersDir) then
  198. local users = fs.list(usersDir)
  199. for _, user in ipairs(users) do
  200. local adminPath = fs.combine(usersDir, user, "admin.txt")
  201. if fs.exists(adminPath) then
  202. return true
  203. end
  204. end
  205. end
  206. return false
  207. end
  208.  
  209. -- Function to check if no-os file exists
  210. local function checkFirmware()
  211. if not fs.exists("/no-os") then
  212. showError("System Firmware corrupted")
  213. end
  214. end
  215.  
  216. -- Function to check if dev.cfg file exists and handle developer mode
  217. local function checkDeveloperMode()
  218. local devCfgPath = "/dev.cfg"
  219. if fs.exists(devCfgPath) then
  220. return showDeveloperModeScreen() -- Handles developer mode or deletion
  221. end
  222. return false -- Developer mode not active
  223. end
  224.  
  225. -- Main function to initiate checks and continue boot process
  226. local function main()
  227. if not checkDeveloperMode() then
  228. checkBootLock()
  229. if not isSecureBootConfigured() then
  230. showError("Secure boot config file corrupted")
  231. end
  232. checkMaliciousBoot()
  233. checkEmptyUsers()
  234. checkCriticalBootFiles()
  235. if not checkAdmin() then
  236. showError("No system administrators found")
  237. end
  238. checkFirmware()
  239.  
  240. -- If no issues found, continue with normal boot process
  241. shell.run("/disk/boot/BIOS")
  242. print("No issues detected. Continuing boot process...")
  243. -- Your normal boot code here
  244. end
  245. end
  246.  
  247. -- Start the main function
  248. main()
  249.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement