Skip to content

Commit b5cbfdb

Browse files
committed
Add version string setting closes #202, add e2e tests for generating via link command
1 parent 2325523 commit b5cbfdb

File tree

5 files changed

+48
-1
lines changed

5 files changed

+48
-1
lines changed

cmd/client/main.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ var (
4646
logLevel string
4747

4848
ntlmProxyCreds string
49+
50+
versionString string
4951
)
5052

5153
func printHelp() {
@@ -58,18 +60,21 @@ func printHelp() {
5860
fmt.Println("\t\t--process_name\tProcess name shown in tasklist/process list")
5961
fmt.Println("\t\t--sni\tWhen using TLS set the clients requested SNI to this value")
6062
fmt.Println("\t\t--log-level\tChange logging output levels, [INFO,WARNING,ERROR,FATAL,DISABLED]")
63+
fmt.Println("\t\t--version-string\tSSH version string to use, i.e SSH-VERSION, defaults to internal.Version-runtime.GOOS_runtime.GOARCH")
6164
if runtime.GOOS == "windows" {
6265
fmt.Println("\t\t--host-kerberos\tUse kerberos authentication on proxy server (if proxy server specified)")
6366
}
6467
}
6568

6669
func makeInitialSettings() (*client.Settings, error) {
70+
// set the initial settings from the embedded values first
6771
settings := &client.Settings{
6872
Fingerprint: fingerprint,
6973
ProxyAddr: proxy,
7074
Addr: destination,
7175
ProxyUseHostKerberos: useHostKerberos == "true",
7276
SNI: customSNI,
77+
VersionString: versionString,
7378
}
7479

7580
if ntlmProxyCreds != "" {
@@ -143,6 +148,11 @@ func main() {
143148
settings.ProxyUseHostKerberos = true
144149
}
145150

151+
versionString, err := line.GetArgString("version-string")
152+
if err == nil {
153+
settings.VersionString = versionString
154+
}
155+
146156
tempDestination, err := line.GetArgString("d")
147157
if err != nil {
148158
tempDestination, _ = line.GetArgString("destination")

e2e/link_tests.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package main
22

33
import (
4+
"bytes"
5+
"io"
46
"log"
57
"net/http"
68
)
@@ -14,6 +16,8 @@ func linkTests() {
1416
conditionExec("link --goos windows --name windowsbin", "windowsbin", 0, "", 0)
1517
conditionExec("link --goos windows --shared-object --name windowsdll", "windowsdll", 0, "", 0)
1618

19+
conditionExec("link --name versionbin --version-string nootnootnootnoot1", "", 0, "", 0)
20+
1721
resp, err := http.Get("http://" + listenAddr + "/linuxbin")
1822
if err != nil {
1923
log.Fatal("failed to fetch linuxbin: ", err)
@@ -32,6 +36,25 @@ func linkTests() {
3236
log.Fatal("should have returned 200 for created windowsdll, instead got: ", resp.Status)
3337
}
3438

39+
resp, err = http.Get("http://" + listenAddr + "/versionbin")
40+
if err != nil {
41+
log.Fatal("failed to fetch versionstring binary: ", err)
42+
}
43+
if resp.StatusCode != 200 {
44+
log.Fatal("should have returned 200 for created versionstring , instead got: ", resp.Status)
45+
}
46+
47+
wholeBinary, err := io.ReadAll(resp.Body)
48+
if err != nil {
49+
log.Fatal("failed to read binary: ", err)
50+
}
51+
52+
if !bytes.Contains(wholeBinary, []byte("nootnootnootnoot1")) {
53+
log.Fatal("the version string was not set within the binary")
54+
}
55+
56+
resp.Body.Close()
57+
3558
log.Println("Ending link tests")
3659

3760
}

internal/client/client.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,8 @@ type Settings struct {
308308

309309
ProxyUseHostKerberos bool
310310

311+
VersionString string
312+
311313
ntlm *ntlmssp.Client
312314
}
313315

@@ -380,6 +382,10 @@ func Run(settings *Settings) {
380382
ClientVersion: "SSH-" + internal.Version + "-" + runtime.GOOS + "_" + runtime.GOARCH,
381383
}
382384

385+
if settings.VersionString != "" {
386+
config.ClientVersion = "SSH-" + settings.VersionString
387+
}
388+
383389
realAddr, scheme := determineConnectionType(settings.Addr)
384390

385391
// fetch the environment variables, but the first proxy is done from the supplied proxyAddr arg

internal/server/commands/link.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func (l *link) ValidArgs() map[string]string {
5454
"use-kerberos": "Instruct client to try and use kerberos ticket when using a proxy",
5555
"log-level": "Set default output logging levels, [INFO,WARNING,ERROR,FATAL,DISABLED]",
5656
"ntlm-proxy-creds": "Set NTLM proxy credentials in format DOMAIN\\USER:PASS",
57+
"version-string": "Set the SSH version string the client uses, will always be prefixed with SSH-",
5758
}
5859

5960
// Add duplicate flags for owners
@@ -186,6 +187,11 @@ func (l *link) Run(user *users.User, tty io.ReadWriter, line terminal.ParsedLine
186187
return err
187188
}
188189

190+
buildConfig.VersionString, err = line.GetArgString("version-string")
191+
if err != nil && err != terminal.ErrFlagNotSet {
192+
return err
193+
}
194+
189195
buildConfig.Comment, err = line.GetArgString("C")
190196
if err != nil && err != terminal.ErrFlagNotSet {
191197
return err

internal/server/webserver/buildmanager.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ type BuildConfig struct {
5050
WorkingDirectory string
5151

5252
NTLMProxyCreds string
53+
54+
VersionString string
5355
}
5456

5557
func Build(config BuildConfig) (string, error) {
@@ -169,7 +171,7 @@ func Build(config BuildConfig) (string, error) {
169171
return "", err
170172
}
171173

172-
buildArguments = append(buildArguments, fmt.Sprintf("-ldflags=-s -w -X main.logLevel=%s -X main.destination=%s -X main.fingerprint=%s -X main.proxy=%s -X main.customSNI=%s -X main.useHostKerberos=%t -X main.ntlmProxyCreds=%s -X github.com/NHAS/reverse_ssh/internal.Version=%s", config.LogLevel, config.ConnectBackAdress, config.Fingerprint, config.Proxy, config.SNI, config.UseKerberosAuth, config.NTLMProxyCreds, strings.TrimSpace(f.Version)))
174+
buildArguments = append(buildArguments, fmt.Sprintf("-ldflags=-s -w -X main.logLevel=%s -X main.destination=%s -X main.fingerprint=%s -X main.proxy=%s -X main.customSNI=%s -X main.useHostKerberos=%t -X main.ntlmProxyCreds=%s -X main.versionString=%s -X github.com/NHAS/reverse_ssh/internal.Version=%s", config.LogLevel, config.ConnectBackAdress, config.Fingerprint, config.Proxy, config.SNI, config.UseKerberosAuth, config.NTLMProxyCreds, strings.TrimSpace(config.VersionString), strings.TrimSpace(f.Version)))
173175
buildArguments = append(buildArguments, "-o", f.FilePath, filepath.Join(projectRoot, "/cmd/client"))
174176

175177
cmd := exec.Command(buildTool, buildArguments...)

0 commit comments

Comments
 (0)