通过本地 Unix socket 通过 http 连接访问远程 shell

我需要通过服务器 Unix socket 的 http 连接让远程主机访问 shell。

我知道如何不使用http直接实现它:

  1. 服务器监听 TCP-PORT 并将其映射到 UNIX-SOCKET:

server# socat TCP-LISTEN:12345 UNIX-LISTEN:/tmp/12345.sock

  1. 远程主机将 shell 映射到初始化的 TCP 连接:

remote# socat EXEC:sh,pty,stderr,setsid,sigint,sane TCP:my.server.com:12345

  1. 要连接远程 shell,我可以这样做:

server# socat FILE:`tty`,raw,echo=0 UNIX-CONNECT:/tmp/12345.sock

上述三个步骤的图例:

remote [shell] -> tcp:my.server.com:12345 :: server :: unix:/tmp/12345.sock <- server [tty]

接下来我需要在 remoteserver 之间建立 HTTPS 连接。那么第一步会怎么做?我想要的图例如下:

remote [shell] -> https://my.server.com:443/ shell :: server [ _在请求 /shell 上打开 unix:/tmp/12345.sock_] :: unix:/tmp/12345.sock <- server [tty]

我使用 nginx,并且知道 LUA 可以在其中运行。但我没有足够的 LUA 知识来实现这个计划。

UPD 2020.02.12

我发现必须使用 WebSocket。因此,图例如下:

remote [shell] -> WebSocket 代理客户端 -> https://my.server.com:443/shell :: Web 服务器 -> WebSocket 服务器 [开始监听 unix:/tmp/12345.sock] :: unix:/tmp/12345.sock <- server [tty]

如何制作 WebSocket 代理客户端WebSocket 服务器

点赞