Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
wsssh
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexlab
wsssh
Commits
797e3f15
Commit
797e3f15
authored
Sep 17, 2025
by
Stefy Lanza (nextime / spora )
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Send server SSH version immediately after forwarding client version to prevent timeout
parent
56dae178
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
21 deletions
+32
-21
tunnel.c
wssshtools/tunnel.c
+28
-2
wsssh.c
wssshtools/wsssh.c
+4
-19
No files found.
wssshtools/tunnel.c
View file @
797e3f15
...
@@ -349,6 +349,9 @@ void *forward_tcp_to_ws(void *arg) {
...
@@ -349,6 +349,9 @@ void *forward_tcp_to_ws(void *arg) {
fflush
(
stdout
);
fflush
(
stdout
);
}
}
// Check if this is the SSH client version string
int
is_client_version
=
(
bytes_read
>=
8
&&
strncmp
(
buffer
,
"SSH-2.0-"
,
8
)
==
0
);
// Convert to hex with bounds checking
// Convert to hex with bounds checking
size_t
hex_size
=
(
size_t
)
bytes_read
*
2
+
1
;
size_t
hex_size
=
(
size_t
)
bytes_read
*
2
+
1
;
if
(
hex_size
>
BUFFER_SIZE
)
{
if
(
hex_size
>
BUFFER_SIZE
)
{
...
@@ -377,6 +380,29 @@ void *forward_tcp_to_ws(void *arg) {
...
@@ -377,6 +380,29 @@ void *forward_tcp_to_ws(void *arg) {
}
}
break
;
break
;
}
}
// If this was the client SSH version, immediately send the server version to prevent timeout
if
(
is_client_version
)
{
const
char
*
server_version
=
"SSH-2.0-OpenSSH_10.0p2 Debian-8
\r\n
"
;
size_t
version_len
=
strlen
(
server_version
);
if
(
debug
)
{
printf
(
"[DEBUG - TCPConnection] Sending server version immediately after client version
\n
"
);
fflush
(
stdout
);
}
ssize_t
sent
=
send
(
client_sock
,
server_version
,
version_len
,
0
);
if
(
sent
>
0
)
{
if
(
debug
)
{
printf
(
"[DEBUG] Sent %zd bytes of server version
\n
"
,
sent
);
fflush
(
stdout
);
}
// Set flag to skip duplicate server version
pthread_mutex_lock
(
&
tunnel_mutex
);
if
(
active_tunnel
)
{
active_tunnel
->
server_version_sent
=
1
;
}
pthread_mutex_unlock
(
&
tunnel_mutex
);
}
}
}
}
}
}
...
...
wssshtools/wsssh.c
View file @
797e3f15
...
@@ -477,32 +477,17 @@ int main(int argc, char *argv[]) {
...
@@ -477,32 +477,17 @@ int main(int argc, char *argv[]) {
pthread_mutex_lock
(
&
tunnel_mutex
);
pthread_mutex_lock
(
&
tunnel_mutex
);
active_tunnel
->
local_sock
=
accepted_sock
;
active_tunnel
->
local_sock
=
accepted_sock
;
// Send server version immediately to prevent SSH client timeout
const
char
*
server_version
=
"SSH-2.0-OpenSSH_10.0p2 Debian-8
\r\n
"
;
size_t
version_len
=
strlen
(
server_version
);
if
(
config
.
debug
)
{
printf
(
"[DEBUG - Tunnel] Sending server version immediately to SSH client
\n
"
);
fflush
(
stdout
);
}
ssize_t
sent
=
send
(
accepted_sock
,
server_version
,
version_len
,
0
);
if
(
sent
>
0
)
{
if
(
config
.
debug
)
{
printf
(
"[DEBUG] Sent %zd bytes of server version to SSH client
\n
"
,
sent
);
fflush
(
stdout
);
}
}
// Send any buffered data to the SSH client immediately
// Send any buffered data to the SSH client immediately
if
(
active_tunnel
->
incoming_buffer
&&
active_tunnel
->
incoming_buffer
->
used
>
0
)
{
if
(
active_tunnel
->
incoming_buffer
&&
active_tunnel
->
incoming_buffer
->
used
>
0
)
{
if
(
config
.
debug
)
{
if
(
config
.
debug
)
{
printf
(
"[DEBUG - Tunnel] Sending %zu bytes of buffered server response to SSH client
\n
"
,
active_tunnel
->
incoming_buffer
->
used
);
printf
(
"[DEBUG - Tunnel] Sending %zu bytes of buffered server response to SSH client
\n
"
,
active_tunnel
->
incoming_buffer
->
used
);
fflush
(
stdout
);
fflush
(
stdout
);
}
}
ssize_t
sent
2
=
send
(
accepted_sock
,
active_tunnel
->
incoming_buffer
->
buffer
,
active_tunnel
->
incoming_buffer
->
used
,
0
);
ssize_t
sent
=
send
(
accepted_sock
,
active_tunnel
->
incoming_buffer
->
buffer
,
active_tunnel
->
incoming_buffer
->
used
,
0
);
if
(
sent
2
>
0
)
{
if
(
sent
>
0
)
{
frame_buffer_consume
(
active_tunnel
->
incoming_buffer
,
sent
2
);
frame_buffer_consume
(
active_tunnel
->
incoming_buffer
,
sent
);
if
(
config
.
debug
)
{
if
(
config
.
debug
)
{
printf
(
"[DEBUG] Sent %zd bytes of buffered server response to SSH client
\n
"
,
sent
2
);
printf
(
"[DEBUG] Sent %zd bytes of buffered server response to SSH client
\n
"
,
sent
);
fflush
(
stdout
);
fflush
(
stdout
);
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment