Browse Source

added a terminal server and bad netcat clone

XeonSquared 2 months ago
parent
commit
a29fc154a0
3 changed files with 57 additions and 1 deletions
  1. 16
    0
      exec/nc.lua
  2. 5
    1
      exec/shell.lua
  3. 36
    0
      service/termsrv.lua

+ 16
- 0
exec/nc.lua View File

@@ -0,0 +1,16 @@
1
+local minitel = require "minitel"
2
+local tA = {...}
3
+
4
+host, port = tA[1], tA[2]
5
+
6
+local socket = minitel.open(host,port)
7
+if not socket then return false end
8
+local b = ""
9
+repeat
10
+ io.write(socket:read("*a"))
11
+ coroutine.yield()
12
+ b = io.read(nil,true) or ""
13
+ if b:len() > 0 then
14
+  socket:write(b.."\n")
15
+ end
16
+until socket.state ~= "open"

+ 5
- 1
exec/shell.lua View File

@@ -1,7 +1,11 @@
1 1
 local shenv = {}
2
+function shenv.quit()
3
+ os.setenv("run",nil)
4
+end
2 5
 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})
3 6
 print(_VERSION)
4
-while true do
7
+os.setenv("run",true)
8
+while os.getenv("run") do
5 9
  io.write((os.getenv("PWD") or _VERSION).."> ")
6 10
  tResult = {pcall(load(io.read(),"shell","t",shenv))}
7 11
  if tResult[1] == true then table.remove(tResult,1) end

+ 36
- 0
service/termsrv.lua View File

@@ -0,0 +1,36 @@
1
+print(pcall(function()
2
+local minitel = require "minitel"
3
+local port = 22
4
+local logfile = "/boot/termsrv.log"
5
+
6
+if logfile then
7
+ local log = io.open(logfile,"a")
8
+ os.setenv("t",log.fd)
9
+end
10
+while true do
11
+ local sock = minitel.listen(port)
12
+ print(string.format("[%s] Connection from %s:%d",os.date("%Y-%m-%d %H:%M"),sock.addr,sock.port))
13
+ os.spawn(function() _G.worked = {pcall(function()
14
+  local fdi, fdo = io.newfd()
15
+  function fdo.read(d)
16
+    return sock:read(d)
17
+  end
18
+  function fdo.write(d)
19
+    return sock:write(d)
20
+  end
21
+  function fdo.close()
22
+   sock:close()
23
+  end
24
+  fd[fdi] = fdo
25
+  os.setenv("t",fdi)
26
+  sock:write(string.format("Connected to %s on port %d\n",computer.address():sub(1,8),sock.port))
27
+  local pid = spawnfile("/boot/exec/shell.lua",string.format("shell [%s:%d]",sock.addr,sock.port))
28
+  repeat
29
+   coroutine.yield()
30
+  until sock.state ~= "open" or not tTasks[pid]
31
+  fdo.close()
32
+  sock:close()
33
+  os.kill(pid)
34
+ end)} end,string.format("remote login [%s:%d]",sock.addr,sock.port))
35
+end
36
+end))

Loading…
Cancel
Save