Skip to content

Commit 5cb51f5

Browse files
committed
Fix misordered channel open message resulting in broken remote forwards
1 parent f15a925 commit 5cb51f5

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

internal/client/handlers/remoteforward.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,11 @@ func StopRemoteForward(rf internal.RemoteForwardRequest) error {
5454
func StartRemoteForward(user *internal.User, r *ssh.Request, sshConn ssh.Conn) {
5555

5656
var rf internal.RemoteForwardRequest
57-
5857
err := ssh.Unmarshal(r.Payload, &rf)
5958
if err != nil {
6059
r.Reply(false, []byte(fmt.Sprintf("Unable to open remote forward: %s", err.Error())))
6160
return
6261
}
63-
6462
l, err := net.Listen("tcp", fmt.Sprintf("%s:%d", rf.BindAddr, rf.BindPort))
6563
if err != nil {
6664
r.Reply(false, []byte(fmt.Sprintf("Unable to open remote forward: %s", err.Error())))
@@ -110,7 +108,7 @@ func handleData(proxyCon net.Conn, sshConn ssh.Conn) error {
110108

111109
log.Println("Accepted new connection: ", proxyCon.RemoteAddr())
112110

113-
lHost, strPort, err := net.SplitHostPort(proxyCon.LocalAddr().String())
111+
lHost, strPort, err := net.SplitHostPort(proxyCon.RemoteAddr().String())
114112
if err != nil {
115113
return err
116114
}
@@ -120,7 +118,7 @@ func handleData(proxyCon net.Conn, sshConn ssh.Conn) error {
120118
return err
121119
}
122120

123-
rHost, strPort, err := net.SplitHostPort(proxyCon.RemoteAddr().String())
121+
rHost, strPort, err := net.SplitHostPort(proxyCon.LocalAddr().String())
124122
if err != nil {
125123
return err
126124
}
@@ -131,11 +129,11 @@ func handleData(proxyCon net.Conn, sshConn ssh.Conn) error {
131129
}
132130

133131
drtMsg := internal.ChannelOpenDirectMsg{
134-
Raddr: rHost,
135-
Rport: uint32(rPort),
136-
137132
Laddr: lHost,
138133
Lport: uint32(lPort),
134+
135+
Raddr: rHost,
136+
Rport: uint32(rPort),
139137
}
140138

141139
b := ssh.Marshal(&drtMsg)

0 commit comments

Comments
 (0)