goshs SSH Tunnel Vulnerable to MITM via Insecure Host Key Handling
The goshs application disables SSH host key verification when using the --tunnel flag, making it vulnerable to man-in-the-middle attacks that expose plaintext HTTP traffic.
The goshs application, prior to version 2.0.7, is vulnerable to a man-in-the-middle (MITM) attack when using the --tunnel or -t flag. The application opens an outbound SSH connection to localhost.run:22 with host key verification disabled via ssh.InsecureIgnoreHostKey(). This insecure configuration allows an attacker positioned on the network path to intercept the TCP connection, present their own SSH host key, and proxy the connection. Because localhost.run performs TLS termination, the attacker can read and rewrite all HTTP request and response content in plaintext. This vulnerability allows for the exfiltration of sensitive data and modification of served content.
Attack Chain
- A user executes
goshs --tunnelto create a tunnel. tunnel.Start()initiates an SSH connection tolocalhost.run:22withInsecureIgnoreHostKey().- An attacker, positioned on the network path, intercepts the TCP connection to
localhost.run:22and responds with a malicious SSH server. - The malicious SSH server presents a fake SSH host key, which the goshs client accepts due to the disabled host key verification.
- The attacker proxies the SSH session onward to the real
localhost.run:22to retrieve the public URL. - All subsequent HTTP requests to the public URL are routed through the attacker’s proxy.
- The attacker intercepts all HTTP requests and responses, reading sensitive data such as URLs, headers, authentication credentials, and file contents.
- The attacker can modify HTTP responses, inject malicious content, or redirect requests.
Impact
The vulnerability can lead to significant data breaches and compromise of system integrity. All HTTP request and response content, including sensitive information such as URLs, headers, basic authentication credentials, file contents, and share-link tokens, can be read by the attacker. Furthermore, attackers can modify responses in transit, replacing served files, injecting malicious scripts, or substituting binaries with backdoored versions. This poses a high risk to both the confidentiality and integrity of the data being transmitted through the goshs tunnel.
Recommendation
- Upgrade to goshs version 2.0.7 or later to benefit from the fix that replaces
ssh.InsecureIgnoreHostKey()with a TOFU host key verification mechanism. - Monitor network traffic for connections to
localhost.run:22originating from goshs processes to detect potential MITM attempts, using the provided Sigma rule. - Regularly inspect the
~/.config/goshs/known_hostsfile to ensure the host key forlocalhost.run:22has not been tampered with (after upgrading).
Detection coverage 2
Detect goshs SSH Connection to localhost.run with Tunnel Flag
mediumDetects goshs process initiating an SSH connection to localhost.run on port 22 when the --tunnel flag is present.
Detect goshs SSH Connection to localhost.run with Tunnel Flag (Linux)
mediumDetects goshs process initiating an SSH connection to localhost.run on port 22 when the --tunnel flag is present.
Detection queries are available on the platform. Get full rules →