From a29fc154a0f0a7b5f4b73ae8ab9abc1e66b120cd Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Wed, 9 Jan 2019 16:23:30 +1100 Subject: [PATCH] added a terminal server and bad netcat clone --- exec/nc.lua | 16 ++++++++++++++++ exec/shell.lua | 6 +++++- service/termsrv.lua | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 exec/nc.lua create mode 100644 service/termsrv.lua diff --git a/exec/nc.lua b/exec/nc.lua new file mode 100644 index 0000000..f4bd0ff --- /dev/null +++ b/exec/nc.lua @@ -0,0 +1,16 @@ +local minitel = require "minitel" +local tA = {...} + +host, port = tA[1], tA[2] + +local socket = minitel.open(host,port) +if not socket then return false end +local b = "" +repeat + io.write(socket:read("*a")) + coroutine.yield() + b = io.read(nil,true) or "" + if b:len() > 0 then + socket:write(b.."\n") + end +until socket.state ~= "open" diff --git a/exec/shell.lua b/exec/shell.lua index 1930b7b..4213cfb 100644 --- a/exec/shell.lua +++ b/exec/shell.lua @@ -1,7 +1,11 @@ local shenv = {} +function shenv.quit() + os.setenv("run",nil) +end setmetatable(shenv,{__index=function(_,k) if _G[k] then return _G[k] elseif fs.exists("/boot/exec/"..k..".lua") then return loadfile("/boot/exec/"..k..".lua") end end}) print(_VERSION) -while true do +os.setenv("run",true) +while os.getenv("run") do io.write((os.getenv("PWD") or _VERSION).."> ") tResult = {pcall(load(io.read(),"shell","t",shenv))} if tResult[1] == true then table.remove(tResult,1) end diff --git a/service/termsrv.lua b/service/termsrv.lua new file mode 100644 index 0000000..c5c55cf --- /dev/null +++ b/service/termsrv.lua @@ -0,0 +1,36 @@ +print(pcall(function() +local minitel = require "minitel" +local port = 22 +local logfile = "/boot/termsrv.log" + +if logfile then + local log = io.open(logfile,"a") + os.setenv("t",log.fd) +end +while true do + local sock = minitel.listen(port) + print(string.format("[%s] Connection from %s:%d",os.date("%Y-%m-%d %H:%M"),sock.addr,sock.port)) + os.spawn(function() _G.worked = {pcall(function() + local fdi, fdo = io.newfd() + function fdo.read(d) + return sock:read(d) + end + function fdo.write(d) + return sock:write(d) + end + function fdo.close() + sock:close() + end + fd[fdi] = fdo + os.setenv("t",fdi) + sock:write(string.format("Connected to %s on port %d\n",computer.address():sub(1,8),sock.port)) + local pid = spawnfile("/boot/exec/shell.lua",string.format("shell [%s:%d]",sock.addr,sock.port)) + repeat + coroutine.yield() + until sock.state ~= "open" or not tTasks[pid] + fdo.close() + sock:close() + os.kill(pid) + end)} end,string.format("remote login [%s:%d]",sock.addr,sock.port)) +end +end))