Skip to content

Commit

Permalink
Fix SSH failure due to .ssh/config owner (#1005)
Browse files Browse the repository at this point in the history
* use -F option, success configtest and scan

* add sshConfigPath in config.toml

* Use sshConfigPath in config.toml when using ssh -F

* change -ssh-config to deprecated

* fix typo

* add sshConfigPath in tomltemplate
  • Loading branch information
MaineK00n authored Jun 15, 2020
1 parent 996557c commit 59c7061
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 4 deletions.
14 changes: 12 additions & 2 deletions commands/configtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions commands/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 11 additions & 1 deletion commands/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
5 changes: 5 additions & 0 deletions config/tomlloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion scan/executil.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 59c7061

Please sign in to comment.