Advertisement
1lann

virus-detector

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