diff --git a/commands/configtest.go b/commands/configtest.go index f1686420..ce5c14ec 100644 --- a/commands/configtest.go +++ b/commands/configtest.go @@ -36,7 +36,7 @@ func (*ConfigtestCmd) Usage() string { [-log-dir=/path/to/log] [-ask-key-password] [-timeout=300] - [-ssh-external] + [-ssh-config] [-containers-only] [-http-proxy=http://192.168.0.1:8080] [-debug] @@ -69,7 +69,7 @@ func (p *ConfigtestCmd) SetFlags(f *flag.FlagSet) { "Use Native Go implementation of SSH. Default: Use the external command") f.BoolVar(&c.Conf.SSHConfig, "ssh-config", false, - "Use SSH options specified in ssh_config preferentially") + "[Deprecated] Use SSH options specified in ssh_config preferentially") f.BoolVar(&c.Conf.ContainersOnly, "containers-only", false, "Test containers only. Default: Test both of hosts and containers") @@ -108,6 +108,16 @@ func (p *ConfigtestCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interfa return subcommands.ExitUsageError } + if c.Conf.SSHConfig { + msg := []string{ + "-ssh-config is deprecated", + "If you update Vuls and get this error, there may be incompatible changes in config.toml", + "Please check config.toml template : https://vuls.io/docs/en/usage-settings.html", + } + util.Log.Errorf("%s", strings.Join(msg, "\n")) + return subcommands.ExitUsageError + } + var servernames []string if 0 < len(f.Args()) { servernames = f.Args() diff --git a/commands/discover.go b/commands/discover.go index f4d6c22d..48faa155 100644 --- a/commands/discover.go +++ b/commands/discover.go @@ -187,6 +187,7 @@ sqlite3Path = "/path/to/go-exploitdb.sqlite3" host = "{{$ip}}" #port = "22" #user = "root" +#sshConfigPath = "/home/username/.ssh/config" #keyPath = "/home/username/.ssh/id_rsa" #scanMode = ["fast", "fast-root", "deep", "offline"] #type = "pseudo" diff --git a/commands/scan.go b/commands/scan.go index 080f7694..d200b70e 100644 --- a/commands/scan.go +++ b/commands/scan.go @@ -80,7 +80,7 @@ func (p *ScanCmd) SetFlags(f *flag.FlagSet) { "Use Native Go implementation of SSH. Default: Use the external command") f.BoolVar(&c.Conf.SSHConfig, "ssh-config", false, - "Use SSH options specified in ssh_config preferentially") + "[Deprecated] Use SSH options specified in ssh_config preferentially") f.BoolVar(&c.Conf.ContainersOnly, "containers-only", false, "Scan running containers only. Default: Scan both of hosts and running containers") @@ -146,6 +146,16 @@ func (p *ScanCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) return subcommands.ExitUsageError } + if c.Conf.SSHConfig { + msg := []string{ + "-ssh-config is deprecated", + "If you update Vuls and get this error, there may be incompatible changes in config.toml", + "Please check config.toml template : https://vuls.io/docs/en/usage-settings.html", + } + util.Log.Errorf("%s", strings.Join(msg, "\n")) + return subcommands.ExitUsageError + } + util.Log.Info("Start scanning") util.Log.Infof("config: %s", p.configPath) diff --git a/config/config.go b/config/config.go index 2fee9fce..1475fa9e 100644 --- a/config/config.go +++ b/config/config.go @@ -1036,6 +1036,7 @@ type ServerInfo struct { User string `toml:"user,omitempty" json:"user,omitempty"` Host string `toml:"host,omitempty" json:"host,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"` KeyPassword string `json:"-,omitempty" toml:"-"` CpeNames []string `toml:"cpeNames,omitempty" json:"cpeNames,omitempty"` diff --git a/config/tomlloader.go b/config/tomlloader.go index 208847d4..955a1953 100644 --- a/config/tomlloader.go +++ b/config/tomlloader.go @@ -77,6 +77,11 @@ func (c TOMLLoader) Load(pathToToml, keyPass string) error { } } + s.SSHConfigPath = v.SSHConfigPath + if len(s.SSHConfigPath) == 0 { + s.SSHConfigPath = d.SSHConfigPath + } + s.KeyPath = v.KeyPath if len(s.KeyPath) == 0 { s.KeyPath = d.KeyPath diff --git a/scan/executil.go b/scan/executil.go index 9be26ad8..9cd79625 100644 --- a/scan/executil.go +++ b/scan/executil.go @@ -260,7 +260,9 @@ func sshExecExternal(c conf.ServerInfo, cmd string, sudo bool) (result execResul defaultSSHArgs := []string{"-tt"} - if !conf.Conf.SSHConfig { + if 0 < len(c.SSHConfigPath) { + defaultSSHArgs = append(defaultSSHArgs, "-F", c.SSHConfigPath) + } else { home, err := homedir.Dir() if err != nil { msg := fmt.Sprintf("Failed to get HOME directory: %s", err)