Advertisement
PaymentOption

ALLBIOS injection 1.2

Feb 22nd, 2013
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.89 KB | None | 0 0
  1. --[[
  2.     ALLBIOS Injection   Trystan Cannon
  3.                         22 February 2013
  4.                        
  5.     This is a test of a method that
  6.     I believe to have found which
  7.     can bypass ALLBIOS' protection
  8.     of OS functions.
  9.    
  10.     In this particular script,
  11.     I'll be injecting into os.shutdown.
  12.    
  13.     METHOD:
  14.         Grab script environment -> level 0
  15.         Use 'rawset' on ["os"]["shutdown"]
  16.         PROFIT???!!!
  17. ]]--
  18.  
  19.  
  20.  
  21. --=========================================
  22. -- Variables:
  23.  
  24. local RAW_DATA = { -- This table contains data that is necessary for operation after the BIOS exits.
  25.     ["read"]  = _G["read"],
  26.     ["write"] = _G["write"],
  27.     ["print"] = _G["print"],
  28.     ["os"]    = _G["os"],
  29.     ["sleep"] = _G["sleep"],
  30.     ["term"]  = _G["term"]
  31. }
  32.  
  33. local SCRIPT_LAYER       = 0
  34. local SCRIPT_ENVIRONMENT = getfenv (SCRIPT_LAYER)
  35.  
  36. local OS_SHUTDOWN       = SCRIPT_ENVIRONMENT["os"]["shutdown"]
  37. local INFECTED_SHUTDOWN = function()
  38. end
  39.  
  40. local threadStack = {
  41.     ["shell"] = coroutine.create (function()
  42.         os.run ({}, "rom/programs/shell")
  43.     end)
  44. }
  45. --=========================================
  46.  
  47.  
  48.  
  49. --=========================================
  50. -- Injection:
  51.  
  52. -- Returns the true size of a table using pairs().
  53. local function getTableSize (myTable)
  54.     local size = 0
  55.    
  56.     for _, __ in pairs (myTable) do
  57.         size = size + 1
  58.     end
  59.    
  60.     return size
  61. end
  62.  
  63. -- Returns the parent shell instance or nil.
  64. local function getParentShell()
  65.     for layer = 0, 5 do
  66.         local environment = getfenv (layer)
  67.        
  68.         if getTableSize (environment) == 1 then
  69.             local index, value = next (environment)
  70.            
  71.             if index == "shell" then
  72.                 return value
  73.             end
  74.         end
  75.     end
  76. end
  77.  
  78. -- Infects os.shutdown.
  79. local function infectShutdown()
  80.     rawset (SCRIPT_ENVIRONMENT["os"], "shutdown", INFECTED_SHUTDOWN)
  81. end
  82.  
  83. -- Executes the thread stack.
  84. local function executeThreadStack()
  85.     local deadThreadIndex = nil -- The index of a thread that must be killed after the next event.
  86.                                 -- We cannot kill threads during our use of pairs() because next() will be angry.
  87.    
  88.     -- Return os.shutdown to its previous state.
  89.     rawset (SCRIPT_ENVIRONMENT["os"], "shutdown", OS_SHUTDOWN)
  90.    
  91.     -- Init the thread stack by queueing a couple of empty events.
  92.     os.queueEvent ("char", '')
  93.     os.queueEvent ("char", '')
  94.    
  95.     -- Execute the thread stack.
  96.     while getTableSize (threadStack) > 0 do
  97.         if deadThreadIndex then
  98.             threadStack[deadThreadIndex] = nil
  99.             deadThreadIndex              = nil
  100.         end
  101.        
  102.         local eventData = { os.pullEvent() }
  103.        
  104.         if eventData[1] == "key" and eventData[2] == keys["end"] then
  105.             break
  106.         end
  107.        
  108.         for index, thread in pairs (threadStack) do
  109.             if coroutine.status (thread) ~= "dead" then
  110.                 coroutine.resume (thread, unpack (eventData))
  111.             else
  112.                 deadThreadIndex = index
  113.             end
  114.         end
  115.     end
  116.    
  117.     RAW_DATA.term.clear()
  118.     RAW_DATA.term.setCursorPos (1, 1)
  119.     RAW_DATA.term.write ("Bios has exited. Press any key to continue.")
  120.     RAW_DATA.term.setCursorBlink (false)
  121.     RAW_DATA.os.pullEvent ("key")
  122. end
  123. --=========================================
  124.  
  125.  
  126.  
  127. --=========================================
  128. -- Main:
  129.  
  130. -- Get the parent shell.
  131. local parentShell = getParentShell()
  132.  
  133. -- Make sure we actually have the parent shell before
  134. -- doing anything else.
  135. if not parentShell then
  136.     print ("Parent shell not retrieved.")
  137.     return
  138. end
  139.  
  140. -- Inject os.shutdown and kill the parent shell instance.
  141. -- This will trigger the execution of the thread stack.
  142. infectShutdown()
  143. parentShell.exit()
  144. executeThreadStack()
  145. --=========================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement