Skip to content

Commit 574c9bb

Browse files
committed
[init] first commit
0 parents  commit 574c9bb

File tree

18 files changed

+1120
-0
lines changed

18 files changed

+1120
-0
lines changed

.gitignore

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# If you prefer the allow list template instead of the deny list, see community template:
2+
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
3+
#
4+
# Binaries for programs and plugins
5+
*.exe
6+
*.exe~
7+
*.dll
8+
*.so
9+
*.dylib
10+
11+
# Test binary, built with `go test -c`
12+
*.test
13+
14+
# Output of the go coverage tool, specifically when used with LiteIDE
15+
*.out
16+
17+
# Dependency directories (remove the comment below to include it)
18+
# vendor/
19+
20+
# Go workspace file
21+
go.work
22+
go.work.sum
23+
24+
# env file
25+
.env
26+
27+
build/
28+
.idea
29+
.vscode
30+
31+
.DS_Store

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Siri
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# SSHProxy
2+
An SSH proxy command proxy program implemented using WebSocket.
3+
4+
```mermaid
5+
graph LR
6+
classDef startend fill:#F5EBFF,stroke:#BE8FED,stroke-width:2px
7+
classDef process fill:#E5F6FF,stroke:#73A6FF,stroke-width:2px
8+
9+
A([Client]):::startend -->|ssh proxycommand by sshproxy| B(sshproxy - server):::process
10+
B --> C([SSH Server]):::startend
11+
```
12+
13+
## Usage
14+
15+
1. Navigate to the release page to download the executable file corresponding to your system and then extract it.
16+
17+
2. Launch the sshproxy proxy server.
18+
19+
```shell
20+
sshproxy server
21+
```
22+
23+
3. Use SSH to access the target SSH server via the proxy server.
24+
25+
4. ```shell
26+
ssh -o ProxyCommand='sshproxy client --addr=%h:%p --ws=ws://localhost:8080/ --token=token' <user>@<host>:<port>
27+
```
28+
29+
Global commands:
30+
31+
```shell
32+
$ sshproxy -h
33+
34+
sshproxy is a WebSocket proxy for SSH.
35+
36+
Usage:
37+
sshproxy [flags]
38+
sshproxy [command]
39+
40+
Available Commands:
41+
client Run the sshproxy client.
42+
completion Generate the autocompletion script for the specified shell.
43+
help Get help about any command.
44+
server Run the sshproxy server.
45+
46+
Flags:
47+
-h, --help Get help for sshproxy.
48+
49+
Use "sshproxy [command] --help" for more information about a command.
50+
```
51+
52+
Client commands:
53+
54+
```shell
55+
$ sshproxy client -h
56+
57+
The sshproxy client is a WebSocket-based client for sshproxy. It connects to a WebSocket server and forwards data to the SSH server.
58+
For example: ssh -o ProxyCommand='sshproxy --addr=%h:%p --ws=ws://localhost:8080/' user@localhost:22
59+
60+
Usage:
61+
sshproxy client [flags]
62+
63+
Flags:
64+
--addr string The target SSH address, e.g., --addr=%h:%p
65+
-h, --help Get help for the client.
66+
--sid string The session ID. If not provided, a random one will be generated.
67+
--token string The token for authorization.
68+
--ws string The WebSocket URL (e.g., ws://localhost:8080/).
69+
```
70+
71+
Server commands:
72+
73+
```shell
74+
$ sshproxy server -h
75+
76+
The sshproxy server is a WebSocket-based server for sshproxy. It listens on a port and forwards data to the SSH server.
77+
78+
Usage:
79+
sshproxy server [flags]
80+
81+
Flags:
82+
-h, --help Get help for the server.
83+
--host string The host to listen on (default is "localhost").
84+
--port int The port to listen on (default is 8080).
85+
--prefix string The prefix path, e.g., /ssh.
86+
--token string The token for authorization.
87+
```
88+
89+
## Building
90+
The framework employed in the building process is: https://taskfile.dev/
91+
92+
The following command is used to build all binary packages:
93+
94+
```shell
95+
task build
96+
```
97+
98+
## Troubleshooting
99+
100+
If you find that the SSH connection fails, you can add `-v` after the SSH command to view detailed logs.

agent/agent.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package agent
2+
3+
import (
4+
"fmt"
5+
"log/slog"
6+
"net"
7+
)
8+
9+
type Agent struct {
10+
conn net.Conn
11+
log *slog.Logger
12+
}
13+
14+
func New(addr string, log *slog.Logger) (*Agent, error) {
15+
conn, err := net.Dial("tcp", addr)
16+
if err != nil {
17+
return nil, fmt.Errorf("failed to connect to SSH server: %v", err)
18+
}
19+
20+
return &Agent{
21+
conn: conn,
22+
log: log.With("module", "sshproxy/agent"),
23+
}, nil
24+
}
25+
26+
func (c *Agent) Read(p []byte) (int, error) {
27+
return c.conn.Read(p)
28+
}
29+
30+
func (c *Agent) Write(p []byte) (int, error) {
31+
return c.conn.Write(p)
32+
}
33+
34+
func (c *Agent) Close() error {
35+
return c.conn.Close()
36+
}

0 commit comments

Comments
 (0)