增加shell支持

This commit is contained in:
lwch
2021-09-27 17:02:56 +08:00
parent dbbd14fceb
commit 8742822a13
13 changed files with 560 additions and 63 deletions
+4 -1
View File
@@ -19,6 +19,7 @@ type Tunnel struct {
LocalPort uint16 `yaml:"local_port"`
RemoteAddr string `yaml:"remote_addr"`
RemotePort uint16 `yaml:"remote_port"`
Exec string `yaml:"exec"`
}
// Configure client configure
@@ -58,7 +59,9 @@ func LoadConf(dir string) *Configure {
defer f.Close()
runtime.Assert(yaml.NewDecoder(f).Decode(&cfg))
for i, t := range cfg.Tunnel {
if t.Type != "tcp" {
switch t.Type {
case "tcp", "shell":
default:
t.Type = "udp"
}
cfg.Tunnel[i] = t
+9 -2
View File
@@ -5,6 +5,7 @@ import (
"fmt"
"natpass/code/client/global"
"natpass/code/client/pool"
"natpass/code/client/shell"
"natpass/code/client/tunnel"
"natpass/code/network"
"net"
@@ -56,8 +57,14 @@ func (a *app) run() {
pl := pool.New(a.cfg)
for _, t := range a.cfg.Tunnels {
tn := tunnel.New(t)
go tn.Handle(pl)
switch t.Type {
case "tcp", "udp":
tn := tunnel.New(t)
go tn.Handle(pl)
case "shell":
sh := shell.New(t)
go sh.Handle(pl)
}
}
for i := 0; i < a.cfg.Links-pl.Size(); i++ {
+17
View File
@@ -113,3 +113,20 @@ func (conn *Conn) SendKeepalive() {
case <-time.After(conn.parent.cfg.WriteTimeout):
}
}
// SendShellCreate send shell create message
func (conn *Conn) SendShellCreate(to, id, exec string) {
var msg network.Msg
msg.To = to
msg.XType = network.Msg_shell_create
msg.LinkId = id
msg.Payload = &network.Msg_Screate{
Screate: &network.ShellCreate{
Exec: exec,
},
}
select {
case conn.write <- &msg:
case <-time.After(conn.parent.cfg.WriteTimeout):
}
}
+24
View File
@@ -0,0 +1,24 @@
package shell
import (
"fmt"
"natpass/code/client/pool"
"net/http"
"github.com/lwch/logging"
"github.com/lwch/runtime"
)
// New create shell
func (shell *Shell) New(pool *pool.Pool, w http.ResponseWriter, r *http.Request) {
id, err := runtime.UUID(16, "0123456789abcdef")
if err != nil {
logging.Error("failed to generate link_id for shell: %s, err=%v",
shell.Name, err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
conn := pool.Get(id)
conn.SendShellCreate(shell.cfg.Target, id, shell.cfg.Exec)
fmt.Fprint(w, id)
}
+45
View File
@@ -0,0 +1,45 @@
package shell
import (
"fmt"
"natpass/code/client/global"
"natpass/code/client/pool"
"net/http"
"github.com/lwch/logging"
"github.com/lwch/runtime"
)
type Shell struct {
Name string
cfg global.Tunnel
}
// New new shell
func New(cfg global.Tunnel) *Shell {
return &Shell{
Name: cfg.Name,
cfg: cfg,
}
}
// Handle handle shell
func (shell *Shell) Handle(pl *pool.Pool) {
defer func() {
if err := recover(); err != nil {
logging.Error("close shell tunnel: %s, err=%v", shell.Name, err)
}
}()
pf := func(cb func(*pool.Pool, http.ResponseWriter, *http.Request)) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
cb(pl, w, r)
}
}
mux := http.NewServeMux()
mux.HandleFunc("/new", pf(shell.New))
svr := &http.Server{
Addr: fmt.Sprintf("%s:%d", shell.cfg.LocalAddr, shell.cfg.LocalPort),
Handler: mux,
}
runtime.Assert(svr.ListenAndServe())
}
+1 -1
View File
@@ -1,6 +1,6 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc-gen-go v1.27.1
// protoc v3.12.4
// source: connect.proto
+1 -1
View File
@@ -1,6 +1,6 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc-gen-go v1.27.1
// protoc v3.12.4
// source: forward.proto
+134 -54
View File
@@ -1,6 +1,6 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc-gen-go v1.27.1
// protoc v3.12.4
// source: msg.proto
@@ -30,27 +30,40 @@ const (
Msg_connect_rep MsgType = 4
Msg_disconnect MsgType = 5
Msg_forward MsgType = 6
// shell
Msg_shell_create MsgType = 10
Msg_shell_resize MsgType = 11
Msg_shell_data MsgType = 12
Msg_shell_close MsgType = 13
)
// Enum value maps for MsgType.
var (
MsgType_name = map[int32]string{
0: "unknown",
1: "handshake",
2: "keepalive",
3: "connect_req",
4: "connect_rep",
5: "disconnect",
6: "forward",
0: "unknown",
1: "handshake",
2: "keepalive",
3: "connect_req",
4: "connect_rep",
5: "disconnect",
6: "forward",
10: "shell_create",
11: "shell_resize",
12: "shell_data",
13: "shell_close",
}
MsgType_value = map[string]int32{
"unknown": 0,
"handshake": 1,
"keepalive": 2,
"connect_req": 3,
"connect_rep": 4,
"disconnect": 5,
"forward": 6,
"unknown": 0,
"handshake": 1,
"keepalive": 2,
"connect_req": 3,
"connect_rep": 4,
"disconnect": 5,
"forward": 6,
"shell_create": 10,
"shell_resize": 11,
"shell_data": 12,
"shell_close": 13,
}
)
@@ -144,6 +157,9 @@ type Msg struct {
// *Msg_Creq
// *Msg_Crep
// *Msg_XData
// *Msg_Screate
// *Msg_Sresize
// *Msg_Sdata
Payload isMsg_Payload `protobuf_oneof:"payload"`
}
@@ -256,6 +272,27 @@ func (x *Msg) GetXData() *Data {
return nil
}
func (x *Msg) GetScreate() *ShellCreate {
if x, ok := x.GetPayload().(*Msg_Screate); ok {
return x.Screate
}
return nil
}
func (x *Msg) GetSresize() *ShellResize {
if x, ok := x.GetPayload().(*Msg_Sresize); ok {
return x.Sresize
}
return nil
}
func (x *Msg) GetSdata() *ShellData {
if x, ok := x.GetPayload().(*Msg_Sdata); ok {
return x.Sdata
}
return nil
}
type isMsg_Payload interface {
isMsg_Payload()
}
@@ -276,6 +313,19 @@ type Msg_XData struct {
XData *Data `protobuf:"bytes,13,opt,name=_data,json=Data,proto3,oneof"`
}
type Msg_Screate struct {
// shell
Screate *ShellCreate `protobuf:"bytes,20,opt,name=screate,proto3,oneof"`
}
type Msg_Sresize struct {
Sresize *ShellResize `protobuf:"bytes,21,opt,name=sresize,proto3,oneof"`
}
type Msg_Sdata struct {
Sdata *ShellData `protobuf:"bytes,22,opt,name=sdata,proto3,oneof"`
}
func (*Msg_Hsp) isMsg_Payload() {}
func (*Msg_Creq) isMsg_Payload() {}
@@ -284,46 +334,66 @@ func (*Msg_Crep) isMsg_Payload() {}
func (*Msg_XData) isMsg_Payload() {}
func (*Msg_Screate) isMsg_Payload() {}
func (*Msg_Sresize) isMsg_Payload() {}
func (*Msg_Sdata) isMsg_Payload() {}
var File_msg_proto protoreflect.FileDescriptor
var file_msg_proto_rawDesc = []byte{
0x0a, 0x09, 0x6d, 0x73, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x6e, 0x65, 0x74,
0x77, 0x6f, 0x72, 0x6b, 0x1a, 0x0d, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x2e, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x1a, 0x0d, 0x66, 0x6f, 0x72, 0x77, 0x61, 0x72, 0x64, 0x2e, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x22, 0x25, 0x0a, 0x11, 0x68, 0x61, 0x6e, 0x64, 0x73, 0x68, 0x61, 0x6b, 0x65, 0x5f,
0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x65, 0x6e, 0x63, 0x18, 0x01,
0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x65, 0x6e, 0x63, 0x22, 0xd0, 0x03, 0x0a, 0x03, 0x6d, 0x73,
0x67, 0x12, 0x26, 0x0a, 0x05, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e,
0x32, 0x11, 0x2e, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2e, 0x6d, 0x73, 0x67, 0x2e, 0x74,
0x79, 0x70, 0x65, 0x52, 0x04, 0x54, 0x79, 0x70, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x66, 0x72, 0x6f,
0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x66, 0x72, 0x6f, 0x6d, 0x12, 0x19, 0x0a,
0x08, 0x66, 0x72, 0x6f, 0x6d, 0x5f, 0x69, 0x64, 0x78, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52,
0x07, 0x66, 0x72, 0x6f, 0x6d, 0x49, 0x64, 0x78, 0x12, 0x0e, 0x0a, 0x02, 0x74, 0x6f, 0x18, 0x04,
0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x74, 0x6f, 0x12, 0x15, 0x0a, 0x06, 0x74, 0x6f, 0x5f, 0x69,
0x64, 0x78, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x74, 0x6f, 0x49, 0x64, 0x78, 0x12,
0x17, 0x0a, 0x07, 0x6c, 0x69, 0x6e, 0x6b, 0x5f, 0x69, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09,
0x52, 0x06, 0x6c, 0x69, 0x6e, 0x6b, 0x49, 0x64, 0x12, 0x2e, 0x0a, 0x03, 0x68, 0x73, 0x70, 0x18,
0x0a, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2e,
0x68, 0x61, 0x6e, 0x64, 0x73, 0x68, 0x61, 0x6b, 0x65, 0x5f, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61,
0x64, 0x48, 0x00, 0x52, 0x03, 0x68, 0x73, 0x70, 0x12, 0x2e, 0x0a, 0x04, 0x63, 0x72, 0x65, 0x71,
0x18, 0x0b, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b,
0x2e, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x5f, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
0x48, 0x00, 0x52, 0x04, 0x63, 0x72, 0x65, 0x71, 0x12, 0x2f, 0x0a, 0x04, 0x63, 0x72, 0x65, 0x70,
0x18, 0x0c, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b,
0x2e, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x5f, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
0x65, 0x48, 0x00, 0x52, 0x04, 0x63, 0x72, 0x65, 0x70, 0x12, 0x24, 0x0a, 0x05, 0x5f, 0x64, 0x61,
0x74, 0x61, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x6e, 0x65, 0x74, 0x77, 0x6f,
0x72, 0x6b, 0x2e, 0x64, 0x61, 0x74, 0x61, 0x48, 0x00, 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x22,
0x70, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x75, 0x6e, 0x6b, 0x6e, 0x6f,
0x77, 0x6e, 0x10, 0x00, 0x12, 0x0d, 0x0a, 0x09, 0x68, 0x61, 0x6e, 0x64, 0x73, 0x68, 0x61, 0x6b,
0x65, 0x10, 0x01, 0x12, 0x0d, 0x0a, 0x09, 0x6b, 0x65, 0x65, 0x70, 0x61, 0x6c, 0x69, 0x76, 0x65,
0x10, 0x02, 0x12, 0x0f, 0x0a, 0x0b, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x5f, 0x72, 0x65,
0x71, 0x10, 0x03, 0x12, 0x0f, 0x0a, 0x0b, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x5f, 0x72,
0x65, 0x70, 0x10, 0x04, 0x12, 0x0e, 0x0a, 0x0a, 0x64, 0x69, 0x73, 0x63, 0x6f, 0x6e, 0x6e, 0x65,
0x63, 0x74, 0x10, 0x05, 0x12, 0x0b, 0x0a, 0x07, 0x66, 0x6f, 0x72, 0x77, 0x61, 0x72, 0x64, 0x10,
0x06, 0x42, 0x09, 0x0a, 0x07, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x42, 0x0c, 0x5a, 0x0a,
0x2e, 0x2f, 0x3b, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x33,
0x74, 0x6f, 0x1a, 0x0b, 0x73, 0x68, 0x65, 0x6c, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22,
0x25, 0x0a, 0x11, 0x68, 0x61, 0x6e, 0x64, 0x73, 0x68, 0x61, 0x6b, 0x65, 0x5f, 0x70, 0x61, 0x79,
0x6c, 0x6f, 0x61, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x65, 0x6e, 0x63, 0x18, 0x01, 0x20, 0x01, 0x28,
0x0c, 0x52, 0x03, 0x65, 0x6e, 0x63, 0x22, 0xa9, 0x05, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x12, 0x26,
0x0a, 0x05, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x11, 0x2e,
0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2e, 0x6d, 0x73, 0x67, 0x2e, 0x74, 0x79, 0x70, 0x65,
0x52, 0x04, 0x54, 0x79, 0x70, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x66, 0x72, 0x6f, 0x6d, 0x18, 0x02,
0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x66, 0x72, 0x6f, 0x6d, 0x12, 0x19, 0x0a, 0x08, 0x66, 0x72,
0x6f, 0x6d, 0x5f, 0x69, 0x64, 0x78, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x07, 0x66, 0x72,
0x6f, 0x6d, 0x49, 0x64, 0x78, 0x12, 0x0e, 0x0a, 0x02, 0x74, 0x6f, 0x18, 0x04, 0x20, 0x01, 0x28,
0x09, 0x52, 0x02, 0x74, 0x6f, 0x12, 0x15, 0x0a, 0x06, 0x74, 0x6f, 0x5f, 0x69, 0x64, 0x78, 0x18,
0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x74, 0x6f, 0x49, 0x64, 0x78, 0x12, 0x17, 0x0a, 0x07,
0x6c, 0x69, 0x6e, 0x6b, 0x5f, 0x69, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6c,
0x69, 0x6e, 0x6b, 0x49, 0x64, 0x12, 0x2e, 0x0a, 0x03, 0x68, 0x73, 0x70, 0x18, 0x0a, 0x20, 0x01,
0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2e, 0x68, 0x61, 0x6e,
0x64, 0x73, 0x68, 0x61, 0x6b, 0x65, 0x5f, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x48, 0x00,
0x52, 0x03, 0x68, 0x73, 0x70, 0x12, 0x2e, 0x0a, 0x04, 0x63, 0x72, 0x65, 0x71, 0x18, 0x0b, 0x20,
0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2e, 0x63, 0x6f,
0x6e, 0x6e, 0x65, 0x63, 0x74, 0x5f, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x48, 0x00, 0x52,
0x04, 0x63, 0x72, 0x65, 0x71, 0x12, 0x2f, 0x0a, 0x04, 0x63, 0x72, 0x65, 0x70, 0x18, 0x0c, 0x20,
0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2e, 0x63, 0x6f,
0x6e, 0x6e, 0x65, 0x63, 0x74, 0x5f, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x48, 0x00,
0x52, 0x04, 0x63, 0x72, 0x65, 0x70, 0x12, 0x24, 0x0a, 0x05, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x18,
0x0d, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2e,
0x64, 0x61, 0x74, 0x61, 0x48, 0x00, 0x52, 0x04, 0x44, 0x61, 0x74, 0x61, 0x12, 0x31, 0x0a, 0x07,
0x73, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x18, 0x14, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e,
0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2e, 0x73, 0x68, 0x65, 0x6c, 0x6c, 0x5f, 0x63, 0x72,
0x65, 0x61, 0x74, 0x65, 0x48, 0x00, 0x52, 0x07, 0x73, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x12,
0x31, 0x0a, 0x07, 0x73, 0x72, 0x65, 0x73, 0x69, 0x7a, 0x65, 0x18, 0x15, 0x20, 0x01, 0x28, 0x0b,
0x32, 0x15, 0x2e, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2e, 0x73, 0x68, 0x65, 0x6c, 0x6c,
0x5f, 0x72, 0x65, 0x73, 0x69, 0x7a, 0x65, 0x48, 0x00, 0x52, 0x07, 0x73, 0x72, 0x65, 0x73, 0x69,
0x7a, 0x65, 0x12, 0x2b, 0x0a, 0x05, 0x73, 0x64, 0x61, 0x74, 0x61, 0x18, 0x16, 0x20, 0x01, 0x28,
0x0b, 0x32, 0x13, 0x2e, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2e, 0x73, 0x68, 0x65, 0x6c,
0x6c, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x48, 0x00, 0x52, 0x05, 0x73, 0x64, 0x61, 0x74, 0x61, 0x22,
0xb5, 0x01, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x75, 0x6e, 0x6b, 0x6e,
0x6f, 0x77, 0x6e, 0x10, 0x00, 0x12, 0x0d, 0x0a, 0x09, 0x68, 0x61, 0x6e, 0x64, 0x73, 0x68, 0x61,
0x6b, 0x65, 0x10, 0x01, 0x12, 0x0d, 0x0a, 0x09, 0x6b, 0x65, 0x65, 0x70, 0x61, 0x6c, 0x69, 0x76,
0x65, 0x10, 0x02, 0x12, 0x0f, 0x0a, 0x0b, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x5f, 0x72,
0x65, 0x71, 0x10, 0x03, 0x12, 0x0f, 0x0a, 0x0b, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x5f,
0x72, 0x65, 0x70, 0x10, 0x04, 0x12, 0x0e, 0x0a, 0x0a, 0x64, 0x69, 0x73, 0x63, 0x6f, 0x6e, 0x6e,
0x65, 0x63, 0x74, 0x10, 0x05, 0x12, 0x0b, 0x0a, 0x07, 0x66, 0x6f, 0x72, 0x77, 0x61, 0x72, 0x64,
0x10, 0x06, 0x12, 0x10, 0x0a, 0x0c, 0x73, 0x68, 0x65, 0x6c, 0x6c, 0x5f, 0x63, 0x72, 0x65, 0x61,
0x74, 0x65, 0x10, 0x0a, 0x12, 0x10, 0x0a, 0x0c, 0x73, 0x68, 0x65, 0x6c, 0x6c, 0x5f, 0x72, 0x65,
0x73, 0x69, 0x7a, 0x65, 0x10, 0x0b, 0x12, 0x0e, 0x0a, 0x0a, 0x73, 0x68, 0x65, 0x6c, 0x6c, 0x5f,
0x64, 0x61, 0x74, 0x61, 0x10, 0x0c, 0x12, 0x0f, 0x0a, 0x0b, 0x73, 0x68, 0x65, 0x6c, 0x6c, 0x5f,
0x63, 0x6c, 0x6f, 0x73, 0x65, 0x10, 0x0d, 0x42, 0x09, 0x0a, 0x07, 0x70, 0x61, 0x79, 0x6c, 0x6f,
0x61, 0x64, 0x42, 0x0c, 0x5a, 0x0a, 0x2e, 0x2f, 0x3b, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b,
0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@@ -347,6 +417,9 @@ var file_msg_proto_goTypes = []interface{}{
(*ConnectRequest)(nil), // 3: network.connect_request
(*ConnectResponse)(nil), // 4: network.connect_response
(*Data)(nil), // 5: network.data
(*ShellCreate)(nil), // 6: network.shell_create
(*ShellResize)(nil), // 7: network.shell_resize
(*ShellData)(nil), // 8: network.shell_data
}
var file_msg_proto_depIdxs = []int32{
0, // 0: network.msg._type:type_name -> network.msg.type
@@ -354,11 +427,14 @@ var file_msg_proto_depIdxs = []int32{
3, // 2: network.msg.creq:type_name -> network.connect_request
4, // 3: network.msg.crep:type_name -> network.connect_response
5, // 4: network.msg._data:type_name -> network.data
5, // [5:5] is the sub-list for method output_type
5, // [5:5] is the sub-list for method input_type
5, // [5:5] is the sub-list for extension type_name
5, // [5:5] is the sub-list for extension extendee
0, // [0:5] is the sub-list for field type_name
6, // 5: network.msg.screate:type_name -> network.shell_create
7, // 6: network.msg.sresize:type_name -> network.shell_resize
8, // 7: network.msg.sdata:type_name -> network.shell_data
8, // [8:8] is the sub-list for method output_type
8, // [8:8] is the sub-list for method input_type
8, // [8:8] is the sub-list for extension type_name
8, // [8:8] is the sub-list for extension extendee
0, // [0:8] is the sub-list for field type_name
}
func init() { file_msg_proto_init() }
@@ -368,6 +444,7 @@ func file_msg_proto_init() {
}
file_connect_proto_init()
file_forward_proto_init()
file_shell_proto_init()
if !protoimpl.UnsafeEnabled {
file_msg_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*HandshakePayload); i {
@@ -399,6 +476,9 @@ func file_msg_proto_init() {
(*Msg_Creq)(nil),
(*Msg_Crep)(nil),
(*Msg_XData)(nil),
(*Msg_Screate)(nil),
(*Msg_Sresize)(nil),
(*Msg_Sdata)(nil),
}
type x struct{}
out := protoimpl.TypeBuilder{
+10
View File
@@ -5,6 +5,7 @@ option go_package="./;network";
import "connect.proto";
import "forward.proto";
import "shell.proto";
message handshake_payload {
bytes enc = 1;
@@ -19,6 +20,11 @@ message msg {
connect_rep = 4;
disconnect = 5;
forward = 6;
// shell
shell_create = 10;
shell_resize = 11;
shell_data = 12;
shell_close = 13;
}
type _type = 1;
string from = 2;
@@ -31,5 +37,9 @@ message msg {
connect_request creq = 11;
connect_response crep = 12;
data _data = 13;
// shell
shell_create screate = 20;
shell_resize sresize = 21;
shell_data sdata = 22;
}
}
+275
View File
@@ -0,0 +1,275 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.27.1
// protoc v3.12.4
// source: shell.proto
package network
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type ShellCreate struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Exec string `protobuf:"bytes,1,opt,name=exec,proto3" json:"exec,omitempty"`
}
func (x *ShellCreate) Reset() {
*x = ShellCreate{}
if protoimpl.UnsafeEnabled {
mi := &file_shell_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *ShellCreate) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ShellCreate) ProtoMessage() {}
func (x *ShellCreate) ProtoReflect() protoreflect.Message {
mi := &file_shell_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use ShellCreate.ProtoReflect.Descriptor instead.
func (*ShellCreate) Descriptor() ([]byte, []int) {
return file_shell_proto_rawDescGZIP(), []int{0}
}
func (x *ShellCreate) GetExec() string {
if x != nil {
return x.Exec
}
return ""
}
type ShellResize struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Rows uint32 `protobuf:"varint,1,opt,name=rows,proto3" json:"rows,omitempty"`
Cols uint32 `protobuf:"varint,2,opt,name=cols,proto3" json:"cols,omitempty"`
}
func (x *ShellResize) Reset() {
*x = ShellResize{}
if protoimpl.UnsafeEnabled {
mi := &file_shell_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *ShellResize) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ShellResize) ProtoMessage() {}
func (x *ShellResize) ProtoReflect() protoreflect.Message {
mi := &file_shell_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use ShellResize.ProtoReflect.Descriptor instead.
func (*ShellResize) Descriptor() ([]byte, []int) {
return file_shell_proto_rawDescGZIP(), []int{1}
}
func (x *ShellResize) GetRows() uint32 {
if x != nil {
return x.Rows
}
return 0
}
func (x *ShellResize) GetCols() uint32 {
if x != nil {
return x.Cols
}
return 0
}
type ShellData struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Data []byte `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"`
}
func (x *ShellData) Reset() {
*x = ShellData{}
if protoimpl.UnsafeEnabled {
mi := &file_shell_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *ShellData) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ShellData) ProtoMessage() {}
func (x *ShellData) ProtoReflect() protoreflect.Message {
mi := &file_shell_proto_msgTypes[2]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use ShellData.ProtoReflect.Descriptor instead.
func (*ShellData) Descriptor() ([]byte, []int) {
return file_shell_proto_rawDescGZIP(), []int{2}
}
func (x *ShellData) GetData() []byte {
if x != nil {
return x.Data
}
return nil
}
var File_shell_proto protoreflect.FileDescriptor
var file_shell_proto_rawDesc = []byte{
0x0a, 0x0b, 0x73, 0x68, 0x65, 0x6c, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x6e,
0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x22, 0x22, 0x0a, 0x0c, 0x73, 0x68, 0x65, 0x6c, 0x6c, 0x5f,
0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x65, 0x78, 0x65, 0x63, 0x18, 0x01,
0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x65, 0x78, 0x65, 0x63, 0x22, 0x36, 0x0a, 0x0c, 0x73, 0x68,
0x65, 0x6c, 0x6c, 0x5f, 0x72, 0x65, 0x73, 0x69, 0x7a, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x72, 0x6f,
0x77, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x04, 0x72, 0x6f, 0x77, 0x73, 0x12, 0x12,
0x0a, 0x04, 0x63, 0x6f, 0x6c, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x04, 0x63, 0x6f,
0x6c, 0x73, 0x22, 0x20, 0x0a, 0x0a, 0x73, 0x68, 0x65, 0x6c, 0x6c, 0x5f, 0x64, 0x61, 0x74, 0x61,
0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04,
0x64, 0x61, 0x74, 0x61, 0x42, 0x0c, 0x5a, 0x0a, 0x2e, 0x2f, 0x3b, 0x6e, 0x65, 0x74, 0x77, 0x6f,
0x72, 0x6b, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_shell_proto_rawDescOnce sync.Once
file_shell_proto_rawDescData = file_shell_proto_rawDesc
)
func file_shell_proto_rawDescGZIP() []byte {
file_shell_proto_rawDescOnce.Do(func() {
file_shell_proto_rawDescData = protoimpl.X.CompressGZIP(file_shell_proto_rawDescData)
})
return file_shell_proto_rawDescData
}
var file_shell_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
var file_shell_proto_goTypes = []interface{}{
(*ShellCreate)(nil), // 0: network.shell_create
(*ShellResize)(nil), // 1: network.shell_resize
(*ShellData)(nil), // 2: network.shell_data
}
var file_shell_proto_depIdxs = []int32{
0, // [0:0] is the sub-list for method output_type
0, // [0:0] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_shell_proto_init() }
func file_shell_proto_init() {
if File_shell_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_shell_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ShellCreate); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_shell_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ShellResize); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_shell_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ShellData); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_shell_proto_rawDesc,
NumEnums: 0,
NumMessages: 3,
NumExtensions: 0,
NumServices: 0,
},
GoTypes: file_shell_proto_goTypes,
DependencyIndexes: file_shell_proto_depIdxs,
MessageInfos: file_shell_proto_msgTypes,
}.Build()
File_shell_proto = out.File
file_shell_proto_rawDesc = nil
file_shell_proto_goTypes = nil
file_shell_proto_depIdxs = nil
}
+17
View File
@@ -0,0 +1,17 @@
syntax = "proto3";
package network;
option go_package="./;network";
message shell_create {
string exec = 1;
}
message shell_resize {
uint32 rows = 1;
uint32 cols = 2;
}
message shell_data {
bytes data = 1;
}
+14 -3
View File
@@ -125,6 +125,9 @@ func (h *Handler) onMessage(from *client, conn *network.Conn, msg *network.Msg)
case network.Msg_connect_rep:
case network.Msg_disconnect:
case network.Msg_forward:
case network.Msg_shell_create:
case network.Msg_shell_resize:
case network.Msg_shell_data:
default:
return
}
@@ -140,7 +143,8 @@ func (h *Handler) onMessage(from *client, conn *network.Conn, msg *network.Msg)
// msgHook hook from on message
func (h *Handler) msgHook(msg *network.Msg, from, to *client) {
switch msg.GetXType() {
case network.Msg_connect_req:
case network.Msg_connect_req,
network.Msg_shell_create:
id := msg.GetLinkId()
var pair [2]*client
if from != nil {
@@ -165,11 +169,13 @@ func (h *Handler) msgHook(msg *network.Msg, from, to *client) {
logging.Info("link %s from %s-%d to %s-%d connect failed, %s",
msg.GetLinkId(), from.parent.id, from.idx, to.parent.id, to.idx, rep.GetMsg())
}
case network.Msg_forward:
case network.Msg_forward,
network.Msg_shell_data:
data := msg.GetXData()
logging.Debug("link %s forward %d bytes from %s-%d to %s-%d",
msg.GetLinkId(), len(data.GetData()), from.parent.id, from.idx, to.parent.id, to.idx)
case network.Msg_disconnect:
case network.Msg_disconnect,
network.Msg_shell_close:
id := msg.GetLinkId()
if from != nil {
from.removeLink(id)
@@ -182,6 +188,11 @@ func (h *Handler) msgHook(msg *network.Msg, from, to *client) {
h.lockLinks.Unlock()
logging.Info("link %s disconnect from %s-%d to %s-%d",
msg.GetLinkId(), from.parent.id, from.idx, to.parent.id, to.idx)
case network.Msg_shell_resize:
data := msg.GetSresize()
logging.Info("shell %s from %s-%d to %s-%d resize to (%d,%d)",
msg.GetLinkId(), from.parent.id, from.idx, to.parent.id, to.idx,
data.GetRows(), data.GetCols())
}
msg.From = from.parent.id
msg.FromIdx = from.idx
+9 -1
View File
@@ -16,4 +16,12 @@ tunnel: # 远端tunnel列表可为空
local_addr: 0.0.0.0 # 本地监听地址
local_port: 3389 # 本地监听端口号
remote_addr: 127.0.0.1 # 目标客户端连接地址
remote_port: 3389 # 目标客户端连接端口号
remote_port: 3389 # 目标客户端连接端口号
- name: shell # 链路名称
target: that # 目标客户端ID
type: shell # web shell
local_addr: 0.0.0.0 # 本地监听地址
local_port: 8080 # 本地监听端口号
#exec: /bin/bash # 运行命令
# windows默认powershell或cmd
# 其他系统bash或sh