랭킹으로 돌아가기

tg123/sshpiper

Gosshpiper.com

The missing reverse proxy for ssh scp

sshssh-connectionreverse-proxytwo-factor-authenticationauditinggoogle-authenticatorazureadscpgolangbastionbastion-serverrecording
스타 성장
스타
1.3k
포크
162
주간 성장
이슈
10
5001k
2023년 1월2024년 3월2025년 5월2026년 7월
아티팩트Go Modulesgo get github.com/tg123/sshpiper
README

sshpiper 🖇

E2E Go Report Card Docker Image

sshpiper is the reverse proxy for sshd. all protocols, including ssh, scp, port forwarding, running on top of ssh are supported.

Note: this is v1 version, checkout legacy v0 here

Overview and Terminology

  • downstream: the client side, typically an ssh client.
  • upstream: the server side, typically an ssh server.
  • plugin: handles the routing from downstream to upstream. The plugin is also responsible for mapping authentication methods to the upstream server. For example, the downstream may use password authentication, but the upstream server may receive public key authentication mapped by sshpiper.
  • additional challenge: some plugins will not only perform routing but also add additional challenges to SSH authentication for the upstream server. For example, the downstream may be asked for two-factor authentication provided by the plugin.
+---------+                      +------------------+          +-----------------+
|         |                      |                  |          |                 |
|   Bob   +----ssh -l bob----+   |   sshpiper    +------------->   Bob' machine  |
|         |                  |   |               |  |          |                 |
+---------+                  |   |               |  |          +-----------------+
                             +---> pipe-by-name--+  |                             
+---------+                  |   |               |  |          +-----------------+
|         |                  |   |               |  |          |                 |
|  Alice  +----ssh -l alice--+   |               +------------->  Alice' machine |
|         |                      |                  |          |                 |
+---------+                      +------------------+          +-----------------+


 downstream                         sshpiper                        upstream                     

Quick start

Build

git clone https://github.com/tg123/sshpiper
cd sshpiper

mkdir out
go build -tags full -o out ./...
(cd cmd/sshpiperd && go build -o ../../out/ .)

Run simple demo

start dummy sshd server

docker run -d -e USER_NAME=user -e USER_PASSWORD=pass -e PASSWORD_ACCESS=true -p 127.0.0.1:5522:2222 lscr.io/linuxserver/openssh-server

start sshpiperd with fixed plugin targeting the dummy sshd server

./out/sshpiperd -i /tmp/sshpiperkey --server-key-generate-mode notexist --log-level=trace ./out/fixed --target 127.0.0.1:5522

test ssh connection (password: pass)

ssh 127.0.0.1 -l user -p 2222

➕ math before login?

Here illustrates the example of additional challenge before the fixed plugin.

./out/sshpiperd -i /tmp/sshpiperkey --server-key-generate-mode notexist --log-level=trace ./out/simplemath -- ./out/fixed --target 127.0.0.1:5522

More examples

For Docker Compose demos (including username routing and Lua publickey git routing), see examples/.

Admin UI (sshpiperd-webadmin)

sshpiperd can optionally expose a small admin gRPC API that lets external tools list live SSH sessions, view their terminal output in real time, and kill them. This API is off by default and is enabled by passing a non-zero --admin-grpc-port. By default the API requires TLS, so a server cert/key must be supplied:

./out/sshpiperd --admin-grpc-port 8222 \
  --admin-grpc-tls-cert server.crt \
  --admin-grpc-tls-key server.key \
  ... <plugin> ...

For mutual TLS (recommended for production), also pass --admin-grpc-tls-cacert ca.crt so clients must present a certificate signed by ca.crt. To opt out of TLS entirely on a trusted network, pass --admin-grpc-insecure.

A separate binary, sshpiperd-webadmin, aggregates one or more sshpiperd admin endpoints and serves a browser dashboard plus a JSON HTTP API:

./out/sshpiperd-webadmin \
  --sshpiperd 127.0.0.1:8222 \
  --sshpiperd piper-2.internal:8222 \
  --tls-cacert ca.crt --tls-cert client.crt --tls-key client.key \
  -l 127.0.0.1 -p 8080

Then open http://127.0.0.1:8080. Endpoints can also be supplied via the SSHPIPERD_WEBADMIN_ENDPOINTS env var (comma-separated). Pass --insecure on the webadmin side when sshpiperd is started with --admin-grpc-insecure. The same client library (libadmin/) is structured so a future CLI tool (sshpiperd-admin) can reuse the discovery + aggregator code.

Plugins

icons

  • 🔀: routing plugin
  • 🔒: additional challenge plugin
  • 📈: metrics plugin

Plugin list

  • workingdir 🔀: /home-like directory to managed upstreams routing by sshpiperd.
  • yaml 🔀: config routing with a single yaml file.
  • lua 🔀🔒: scriptable plugin for custom routing and auth challenges.
  • docker 🔀: pipe into docker containers.
  • kubernetes 🔀: manage pipes via Kubernetes CRD.
  • azdevicecode 🔒: ask user to enter azure device code before login
  • fixed 🔀: fixed targeting the dummy sshd server
  • username-router 🔀: route based on username, the username format is target+username, where target is the target host and username is the username to use for that target.
  • simplemath 🔒: ask for very simple math question before login, demo purpose
  • githubapp 🔀: login ssh with your github account
  • restful by @11notes 🔀🔒: The rest plugin for sshpiperd is a simple plugin that allows you to use a restful backend for authentication and challenge.
  • failtoban 🔒: ban ip after failed login attempts
  • openpubkey🔀🔒: integrate with openpubkey
  • metrics 📈: serve prometheus metrics on open connections and auth errors

Screen recording

asciicast

recording the screen in asciicast format https://docs.asciinema.org/manual/asciicast/v2/

To use it, start sshpiperd with --screen-recording-format asciicast and --screen-recording-dir /path/to/recordingdir

Example:

```
ssh user_name@
... do some commands
exit

asciinema play /path/to/recordingdir/<conn_guid>/shell-channel-0.cast

```

typescript

recording the screen in typescript format (not the lang). The format is compatible with scriptreplay(1)

To use it, start sshpiperd with --screen-recording-format typescript and --screen-recording-dir /path/to/recordingdir

Example:

```
ssh user_name@127.0.0.1 -p 2222
... do some commands
exit


$ cd /path/to/recordingdir/<conn_guid>
$ ls *.timing *.typescript
1472847798.timing 1472847798.typescript

$ scriptreplay -t 1472847798.timing 1472847798.typescript # will replay the ssh session
```

Public key authentication when using sshpiper (Private key remapping)

During SSH publickey auth, RFC 4252 Section 7, ssh client sign session_id and some other data using private key into a signature sig. This is for server to verify that the connection is from the client not the man in the middle.

However, sshpiper actually holds two ssh connection, and it is doing what the man in the middle does. the two ssh connections' session_id will never be the same, because they are hash of the shared secret. RFC 4253 Section 7.2.

To support publickey auth, sshpiper routing plugin must provide a new private key for the upstream to sign the session_id. This new private key is called mapping key.

How this work

+------------+        +------------------------+                       
|            |        |                        |                       
|   client   |        |   sshpiper             |                       
|   PK_X     +-------->      |                 |                       
|            |        |      v                 |                       
|            |        |   Check Permission     |                       
+------------+        |      |                 |                       
                      |      |                 |                       
                      |      |                 |     +----------------+
                      |      v                 |     |                |
                      |   sign again           |     |   server       |
                      |   using PK_Y  +-------------->   check PK_Y   |
                      |                        |     |                |
                      |                        |     |                |
                      +------------------------+     +----------------+

Ports to other platforms

Migrating from v0

What's the major change in v1

  • low level sshpiper api is fully redesigned to support more routing protocols.
  • plugins system totally redesigned to be more flexible and extensible.
    • plugins are now separated from main process and no longer a single big binary, this allow user to write their own plugins without touching sshpiperd code.
  • grpc is first class now, the plugins are built on top of it

For plugins already in v1, you need change params to new params. However, not all plugins are migrated to v1 yet, they are being migrated gradually. you can still use the old plugins in v0 branch

Contributing

see CONTRIBUTING.md

License

MIT

관련 저장소
jaywcjlove/linux-command

Linux命令大全搜索工具,内容包含Linux命令手册、详解、学习、搜集。https://git.io/linux

MarkdownMIT Licenselinuxlinux-command
jaywcjlove.github.io/linux-command
36.5k6.6k
ehang-io/nps

一款轻量级、高性能、功能强大的内网穿透代理服务器。支持tcp、udp、socks5、http等几乎所有流量转发,可用来访问内网网站、本地支付接口调试、ssh访问、远程桌面,内网dns解析、内网socks5代理等等……,并带有功能强大的web管理端。a lightweight, high-performance, powerful intranet penetration proxy server, with a powerful web management terminal.

GoGo ModulesGNU General Public License v3.0sockstcp
ehang.io/nps/documents
34.1k6.1k
kingToolbox/WindTerm

A professional cross-platform SSH/Sftp/Shell/Telnet/Tmux/Serial terminal.

Cterminaltelnet
kingtoolbox.github.io
31.7k2.4k
hiddify/hiddify-app

Multi-platform auto-proxy client, supporting Sing-box, X-ray, TUIC, Hysteria, Reality, Trojan, SSH etc. It’s an open-source, secure and ad-free.

DartOtherproxysingbox
hiddify.com
31.6k2.9k
StreisandEffect/streisand

Streisand sets up a new server running your choice of WireGuard, OpenConnect, OpenSSH, OpenVPN, Shadowsocks, sslh, Stunnel, or a Tor bridge. It also generates custom instructions for all of these services. At the end of the run you are given an HTML file with instructions that can be shared with friends, family members, and fellow activists.

ShellOthervpnansible
twitter.com/streisandvpn
23.5k2k
mikeroyal/Self-Hosting-Guide

Self-Hosting Guide. Learn all about locally hosting (on premises & private web servers) and managing software applications by yourself or your organization. Including Cloud, LLMs, WireGuard, Automation, Home Assistant, and Networking.

Dockerfileself-hostedselfhosted
22k1.1k
fosrl/pangolin

Identity-aware VPN and tunneled reverse proxy for remote access based on WireGuard®.

TypeScriptnpmOtheridentity-managementreverse-proxy
pangolin.net
21.8k739
anderspitman/awesome-tunneling

List of ngrok, Cloudflare Tunnel, Tailscale, and ZeroTier alternatives and other tunneling software and services. Focus on self-hosting.

ngroktunneling
21.5k1.1k
xtermjs/xterm.js

A terminal for the web

TypeScriptnpmMIT Licensextermterminal
xtermjs.org
20.9k1.9k
gravitational/teleport

The easiest, and most secure way to access and protect all of your infrastructure.

GoGo ModulesGNU Affero General Public License v3.0sshgo
goteleport.com
20.7k2.1k
browsh-org/browsh

A fully-modern text-based browser, rendering to TTY and browsers

JavaScriptnpmGNU Lesser General Public License v2.1ttyssh
brow.sh
18.9k478
ginuerzh/gost

GO Simple Tunnel - a simple tunnel written in golang

GoGo ModulesMIT Licensegotunnel
18.1k2.6k