From d9d5e612ff5b1298ad58ed5422eb25996f93ec6a Mon Sep 17 00:00:00 2001 From: shopper <39241071+DaikiYamakawa@users.noreply.github.com> Date: Wed, 17 Jun 2020 12:15:12 +0900 Subject: [PATCH] Support ProxyJump option when using ssh command (#1004) * Add proxyjump func * Run go mod tidy * Run make fmt --- config/config.go | 1 + config/tomlloader.go | 5 +++++ scan/executil.go | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/config/config.go b/config/config.go index 1475fa9e..46d70f60 100644 --- a/config/config.go +++ b/config/config.go @@ -1035,6 +1035,7 @@ type ServerInfo struct { ServerName string `toml:"-" json:"serverName,omitempty"` User string `toml:"user,omitempty" json:"user,omitempty"` Host string `toml:"host,omitempty" json:"host,omitempty"` + JumpServer []string `toml:"jumpServer,omitempty" json:"jumpServer,omitempty"` Port string `toml:"port,omitempty" json:"port,omitempty"` SSHConfigPath string `toml:"sshConfigPath,omitempty" json:"sshConfigPath,omitempty"` KeyPath string `toml:"keyPath,omitempty" json:"keyPath,omitempty"` diff --git a/config/tomlloader.go b/config/tomlloader.go index 955a1953..14c82171 100644 --- a/config/tomlloader.go +++ b/config/tomlloader.go @@ -57,6 +57,11 @@ func (c TOMLLoader) Load(pathToToml, keyPass string) error { return xerrors.Errorf("%s is invalid. host is empty", serverName) } + s.JumpServer = v.JumpServer + if len(s.JumpServer) == 0 { + s.JumpServer = d.JumpServer + } + switch { case v.Port != "": s.Port = v.Port diff --git a/scan/executil.go b/scan/executil.go index 9cd79625..9f695383 100644 --- a/scan/executil.go +++ b/scan/executil.go @@ -287,6 +287,10 @@ func sshExecExternal(c conf.ServerInfo, cmd string, sudo bool) (result execResul defaultSSHArgs = append(defaultSSHArgs, "-vvv") } + if len(c.JumpServer) != 0 { + defaultSSHArgs = append(defaultSSHArgs, "-J", strings.Join(c.JumpServer, ",")) + } + args := append(defaultSSHArgs, fmt.Sprintf("%s@%s", c.User, c.Host)) args = append(args, "-p", c.Port) if 0 < len(c.KeyPath) {