Skip to content

Commit 48b4513

Browse files
committed
add gost blog
1 parent e3a1c18 commit 48b4513

File tree

1 file changed

+150
-0
lines changed

1 file changed

+150
-0
lines changed
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
---
2+
title: "Tunnel SSH into an OMD server. Proof of Concept"
3+
date: 2025-07-31
4+
tags: ["OMD", "Apache"]
5+
categories: ["Networking"]
6+
draft: false
7+
---
8+
9+
# Tunneling SSH over WebSocket with GOST in an OMD server:
10+
11+
In this blog post, we'll walk through a proof-of-concept (POC) setup for tunneling SSH traffic over WebSocket using the GOST tool. This configuration runs inside an OMD (Open Monitoring Distribution) container, leveraging Apache as a reverse proxy for the WebSocket connection. The goal is to securely forward SSH requests from a local client to the container's SSH daemon (sshd) via an encrypted tunnel.
12+
13+
This setup is useful for scenarios where direct SSH access is restricted, but HTTP/HTTPS ports are open (e.g., behind firewalls or in cloud environments). We'll use Podman to manage the container, self-signed certificates for TLS, and GOST for the tunneling logic.
14+
15+
## Overview
16+
17+
The architecture involves:
18+
19+
- **Client-side (outside the container)**: An SSH client connects to a local GOST listener, which forwards the traffic over secure WebSocket (WSS) to the container's Apache server.
20+
- **Server-side (inside the container)**: Apache proxies the WebSocket connection to a GOST server instance, which then forwards the traffic to the local sshd on port 22.
21+
22+
Here's a high-level diagram of the flow:
23+
24+
```mermaid
25+
graph LR
26+
A[SSH Client<br>ssh -p 2222 localhost] --> B[Client GOST<br>tcp://:2222<br>forward+wss://localhost:8443?path=/ssh]
27+
B --> C[Apache httpd<br>ProxyPass ws://localhost:8080/ssh]
28+
C --> D[Server GOST<br>forward+ws://:8080?path=/ssh<br>tcp://127.0.0.1:22]
29+
D --> E[sshd<br>port 22]
30+
```
31+
32+
## Prerequisites
33+
34+
- Podman installed on the host machine.
35+
- GOST binary available both on the host and inside the container (download from [gost.run](https://gost.run/)).
36+
- Basic knowledge of container management, Apache configuration, and SSH.
37+
38+
## Step-by-Step Setup
39+
40+
### 1. Start the OMD Container
41+
42+
On the host machine, run the OMD container with Podman, mapping the external port 8443 to the container's internal HTTPS port 443:
43+
44+
```bash
45+
podman run -it -p 8443:443 --entrypoint bash docker.io/consol/omd-labs-rocky:nightly
46+
```
47+
48+
This drops you into a bash shell inside the container.
49+
50+
### 2. Configure Certificates and SSH Inside the Container
51+
52+
Generate a self-signed certificate for TLS using `sscg`:
53+
54+
```bash
55+
sscg -q \
56+
--cert-file /etc/pki/tls/certs/localhost.crt \
57+
--cert-key-file /etc/pki/tls/private/localhost.key \
58+
--ca-file /etc/pki/tls/certs/localhost.crt \
59+
--lifetime 365 \
60+
--hostname localhost \
61+
--email root@localhost
62+
```
63+
64+
Generate SSH host keys and start the SSH daemon:
65+
66+
```bash
67+
/usr/libexec/openssh/sshd-keygen rsa
68+
/usr/sbin/sshd
69+
```
70+
71+
Create a password for the user *demo*
72+
73+
```bash
74+
passwd demo
75+
```
76+
77+
78+
### 3. Configure Apache for WebSocket Proxying
79+
80+
Edit the Apache configuration file `/omd/apache/ssh.conf` to enable WebSocket proxying:
81+
82+
```apache
83+
<IfModule !mod_proxy.c>
84+
LoadModule proxy_module modules/mod_proxy.so
85+
</IfModule>
86+
87+
<IfModule !mod_proxy_http.c>
88+
LoadModule proxy_http_module modules/mod_proxy_http.so
89+
</IfModule>
90+
91+
<IfModule !mod_proxy_wstunnel.c>
92+
LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so
93+
</IfModule>
94+
95+
<IfModule !mod_rewrite.c>
96+
LoadModule rewrite_module modules/mod_rewrite.so
97+
</IfModule>
98+
99+
<Location "/ssh">
100+
RewriteEngine On
101+
RewriteCond %{HTTP:Upgrade} websocket [NC]
102+
RewriteCond %{HTTP:Connection} upgrade [NC]
103+
RewriteRule ^/ssh$ ws://localhost:8080/ssh [P,L]
104+
ProxyPass ws://localhost:8080/ssh retry=0 disablereuse=On
105+
ProxyPassReverse ws://localhost:8080/ssh
106+
</Location>
107+
```
108+
109+
Start Apache:
110+
111+
```bash
112+
httpd
113+
```
114+
115+
### 4. Run Server-Side GOST
116+
117+
Inside the container, start the GOST server to listen on WebSocket and forward to local SSH:
118+
119+
```bash
120+
gost -DD -L forward+ws://:8080?path=/ssh -F tcp://127.0.0.1:22
121+
```
122+
123+
### 5. Run Client-Side GOST and Test SSH
124+
125+
Back on the host machine (outside the container), start the client-side GOST:
126+
127+
```bash
128+
gost -DD -L tcp://:2222 -F forward+wss://localhost:8443?path=/ssh
129+
```
130+
131+
Now, connect via SSH to the tunneled port:
132+
133+
```bash
134+
ssh -p 2222 -l demo localhost
135+
```
136+
137+
You should be prompted for authentication and connected to the container's sshd as user 'demo'.
138+
139+
## Potential Issues and Troubleshooting
140+
141+
- **Self-Signed Certs**: Use `-k` in curl tests or add the cert to your trust store for production.
142+
- **Port Mapping**: Ensure Podman's port mapping (8443:443) is correct; adjust if using a different external port.
143+
- **Logs**: Check GOST logs with `-DD` for debug info, and Apache error logs for proxy issues.
144+
- **Security**: This POC uses no authentication on the WebSocket path—add Basic Auth or other mechanisms for real-world use.
145+
146+
## Conclusion
147+
148+
This setup demonstrates how to tunnel traditional protocols like SSH over modern web technologies, making it firewall-friendly and scalable. Experiment with adding authentication or multiple forwards for more advanced scenarios!
149+
150+
If you have questions or improvements, drop a comment below.

0 commit comments

Comments
 (0)