Advertisement
1lann

antivirus core

Aug 1st, 2015
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.14 KB | None | 0 0
  1. -- This is a comment
  2. -- to help deter certain viruses
  3. -- which hide their code in the header of programs
  4.  
  5. local function helpInstructions()
  6.     if term.isColor() then
  7.         term.setTextColor(colors.yellow)
  8.     end
  9.     print("Reinstallation instructions:")
  10.     print("Find an uninfected computer, turn on the computer, " ..
  11.         "insert this disk, and run:")
  12.     print("\"pastebin run qhvYyj6N\".")
  13.     print("")
  14.     if term.isColor() then
  15.         term.setTextColor(colors.white)
  16.     end
  17.     print("Press any key to attempt shutdown...")
  18.     os.pullEvent("key")
  19.     os.shutdown()
  20. end
  21.  
  22. local function labelInfected(unknown)
  23.     local side = nil
  24.     for _, v in pairs(peripheral.getNames()) do
  25.         if peripheral.getType(v) == "drive" and
  26.             peripheral.call(v, "hasData") then
  27.             if peripheral.call(v, "getMountPath") == "disk" or unknown then
  28.                 side = v
  29.                 break
  30.             end
  31.         end
  32.     end
  33.  
  34.     if side then
  35.         peripheral.call(side, "setDiskLabel", "[INFECTED] Rescue Boot Disk")
  36.     end
  37. end
  38.  
  39. if term.isColor() then
  40.     term.setTextColor(colors.lightBlue)
  41. end
  42.  
  43. term.clear()
  44. term.setCursorPos(1, 1)
  45. print("Running 1lann's Rescue Boot Disk v1.0")
  46. print("")
  47.  
  48. if os.clock() > 1 then
  49.     if term.isColor() then
  50.         term.setTextColor(colors.red)
  51.     end
  52.     print("This boot disk did not run on boot!")
  53.     print("It may now be infected.")
  54.     print("")
  55.     helpInstructions()
  56. end
  57.  
  58. if not shell or shell.getRunningProgram() ~= "disk/startup" then
  59.     if #(shell.getRunningProgram()) > 4 then
  60.         if (shell.getRunningProgram()):sub(1, 4) == "disk" then
  61.             if fs.exists("/disk") then
  62.                 pcall(fs.delete, "/disk")
  63.             else
  64.                 if term.isColor() then
  65.                     term.setTextColor(colors.yellow)
  66.                 end
  67.                 pcall(fs.delete, shell.getRunningProgram())
  68.                 print("The boot disk is infected!")
  69.                 print("")
  70.                 print("Reason: Program is running on /diskN rather " ..
  71.                     "than /disk, and /disk does not exist.")
  72.                 print("")
  73.                 pcall(labelInfected, true)
  74.                 helpInstructions()
  75.             end
  76.  
  77.             if term.isColor() then
  78.                 term.setTextColor(colors.yellow)
  79.             end
  80.             print("The boot disk is potentially infected. Try rebooting " ..
  81.                 "this computer, and if you see this message again, the boot " ..
  82.                 "disk is (probably) infected.")
  83.             print("")
  84.             print("Reason: Program is running on /diskN rather than /disk.")
  85.             print("")
  86.             helpInstructions()
  87.         end
  88.     end
  89.  
  90.     if term.isColor() then
  91.         term.setTextColor(colors.red)
  92.     end
  93.     pcall(fs.delete, shell.getRunningProgram())
  94.     print("This boot disk is (probably) infected!")
  95.     print("")
  96.     print("Reason: This program is not running on /disk/startup.")
  97.     print("As a result, this program will self-destruct.")
  98.     print("")
  99.     helpInstructions()
  100. end
  101.  
  102. local contents = http.get("http://pastebin.com/raw.php?i=BvvkvEp4")
  103. if not contents then
  104.     if term.isColor() then
  105.         term.setTextColor(colors.red)
  106.     end
  107.     print("Could not connect to pastebin! If pastebin works on an " ..
  108.         "uninfected computer, this disk may be infected.")
  109.     print("")
  110.     pcall(labelInfected)
  111.     helpInstructions()
  112. end
  113.  
  114. local f = io.open(shell.getRunningProgram(), "r")
  115. local thisFile = f:read("*a")
  116. f:close()
  117.  
  118. if contents.readAll() ~= thisFile then
  119.     if term.isColor() then
  120.         term.setTextColor(colors.red)
  121.     end
  122.     print("This boot disk is infected!")
  123.     print("")
  124.     print("Reason: Program contents does not match pastebin version.")
  125.     print("")
  126.     pcall(labelInfected)
  127.     helpInstructions()
  128. end
  129.  
  130. local _, err = pcall(error, "", 17)
  131. if #err > 0 then
  132.     if term.isColor() then
  133.         term.setTextColor(colors.red)
  134.     end
  135.     print("This boot disk is infected!")
  136.     print("")
  137.     print("Reason: Stack trace signature does not match expected signature.")
  138.     print("")
  139.     pcall(labelInfected)
  140.     helpInstructions()
  141. end
  142.  
  143. if term.isColor() then
  144.     term.setTextColor(colors.lime)
  145. end
  146. print("Boot verification successful!")
  147. if term.isColor() then
  148.     term.setTextColor(colors.yellow)
  149. end
  150. print("Scanning and cleaning...")
  151. print("")
  152.  
  153. local systemNames  = fs.list("/rom/programs")
  154. local names = {"cp", "dir", "ls", "mv", "rm", "gps", "help", "adventure", "hello", "worm", "pastebin", "dance", "excavate", "go", "tunnel", "turn", "list"}
  155. for i = 1, #names do table.insert(systemNames, names[i]) end
  156.  
  157. local function isSystemName(name)
  158.     for _, v in pairs(systemNames) do
  159.         if v == name and v ~= "startup" then
  160.             return true
  161.         end
  162.     end
  163.     return false
  164. end
  165.  
  166. if fs.exists("/infected") and not fs.isDir("/infected") then
  167.     fs.delete("/infected")
  168. end
  169.  
  170. if not fs.exists("/infected") then
  171.     fs.makeDir("/infected")
  172. end
  173.  
  174. local hidden = {}
  175. local traps = {}
  176. for k,v in pairs(fs.list("/")) do
  177.     if isSystemName(v) then
  178.         table.insert(traps, v)
  179.         if fs.exists("/infected/infected_" .. v) then
  180.             pcall(fs.delete, "/infected/infected_" .. v)
  181.         end
  182.         pcall(fs.move, "/" .. v, "/infected/infected_" .. v)
  183.     end
  184.  
  185.     if v:sub(1, 1) == "." then
  186.         table.insert(hidden, v)
  187.     end
  188. end
  189.  
  190. local problems = false
  191.  
  192. if #traps > 0 then
  193.     problems = true
  194.     if term.isColor() then
  195.         term.setTextColor(colors.yellow)
  196.     end
  197.     print("The following traps were found:")
  198.     for _, v in pairs(traps) do
  199.         write(v .. ", ")
  200.     end
  201.     print("")
  202.     print("These traps have been moved to /infected")
  203.     print("")
  204. end
  205.  
  206. if #hidden > 0 then
  207.     if term.isColor() then
  208.         term.setTextColor(colors.yellow)
  209.     end
  210.     print("The following hidden files were found:")
  211.     for _, v in pairs(hidden) do
  212.         write(v .. ", ")
  213.     end
  214.     print("")
  215.     print("")
  216. end
  217.  
  218. if fs.exists("/startup") then
  219.     problems = true
  220.     if fs.exists("/infected/infected_startup") then
  221.         pcall(fs.delete, "/infected/infected_startup")
  222.     end
  223.     pcall(fs.move, "/startup", "/infected/infected_startup")
  224.  
  225.     if term.isColor() then
  226.         term.setTextColor(colors.yellow)
  227.     end
  228.     print("The computer's startup file has been moved to /infected")
  229.     print("")
  230. end
  231.  
  232. if term.isColor() then
  233.     term.setTextColor(colors.lime)
  234. end
  235.  
  236. if problems then
  237.     print("Scan and clean complete! This computer should now be disinfected.")
  238.     if term.isColor() then
  239.         term.setTextColor(colors.red)
  240.     end
  241.     print("Non-critical files left on the computer may be infected! Please " ..
  242.         "check them before running them.")
  243. else
  244.     print("Scan completed! No significant problems found.")
  245. end
  246.  
  247. -- This is a comment
  248. -- to help deter certain viruses
  249. -- which hide their code in the footer of programs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement